Skip to content

Commit

Permalink
Add limitation: do NOT change unit level directly in ASM
Browse files Browse the repository at this point in the history
  • Loading branch information
MokhaLeee committed Dec 25, 2024
1 parent 35fe694 commit e5fad8c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Preload/Reloc.event
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,6 @@ gpJobGrowthList: POIN gJobGrowthList
gpPrepItemEffectFunc: POIN gPrepItemEffectFunc
gpPrepItemUsabilityFuncs: POIN gPrepItemUsabilityFuncs

prWriteUnitLevelSafe: POIN WriteUnitLevelSafe

KERNEL_RELOC_END:
10 changes: 10 additions & 0 deletions Wizardry/Common/BwlRework/source/BwlHiddenLevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,13 @@ void UnitHiddenLevelPreLoad(struct Unit *unit)

bwl->levelGain = GetUnitStaticHiddenLevel(unit);
}

void WriteUnitLevelSafe(struct Unit *unit, int new_level)
{
struct NewBwl *bwl = GetNewBwl(UNIT_CHAR_ID(unit));

if (bwl)
bwl->levelGain += new_level - unit->level;

unit->level = new_level;
}
13 changes: 12 additions & 1 deletion docs/Limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,15 @@
- staff
- ring
- skills
- save data
- save data

5. Do **NOT** directly change the unit level in ASM.

As unit lvup history is stored in BWL table, and directly change the unit level may not affect the unit recorded level, thus the lvup skill-learning process may not act in exception. For more info, see section: **Learn skills** in [SkillSys](./SkillSys.md).

As an alternative, kernel offered an API if you want to change unit level in ASM:

```c
// bwl.h
void WriteUnitLevelSafe(struct Unit *unit, int new_level);
```
4 changes: 4 additions & 0 deletions include/bwl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ extern s8 const *const gpClassPreLoadHiddenLevel;
void NewBwlRecordHiddenLevel(struct Unit *unit);
int GetUnitHiddenLevel(struct Unit *unit);
void UnitHiddenLevelPreLoad(struct Unit *unit);

// see limition rule 5
void WriteUnitLevelSafe(struct Unit *unit, int new_level);
extern const void (*prWriteUnitLevelSafe)(struct Unit *unit, int new_level);

0 comments on commit e5fad8c

Please sign in to comment.