Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MokhaLeee committed Jan 25, 2023
1 parent 43ca602 commit e42af24
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 114 deletions.
6 changes: 4 additions & 2 deletions include/configs/fe6_chax_defconfig.h
Expand Up @@ -28,13 +28,15 @@


/**
* Free RAM Space in SRAM
* Free SRAM Space
* Note that these data can only be accessed via function:
* WriteAndVerifySramFast() & ReadSramFast()
*/
#define FreeSRAMSpace 0x0E008000
#define DebugTextSramSt_ptr 0x0E008000
#define DebugTextSramSt_End 0x0E00A028

#define FreeSRAMSpace_cur 0x0E00A028


/**
* Enable debug log with function FailScreen() etc.
Expand Down
8 changes: 5 additions & 3 deletions include/skill-system.h
Expand Up @@ -10,7 +10,7 @@ struct SkillInfo {
u16 name;
u16 desc;
const u8 *icon;
u32 priv;
u32 priv;
};
extern const struct SkillInfo * const SkillInfoTable[MAX_SKILL_NUM];

Expand All @@ -25,8 +25,10 @@ struct SkillRomTable {
};
extern const struct SkillRomTable Skills_PData[], Skills_JData[];

extern bool (*const SkillTester)(struct Unit *unit, const u8 skill);
extern bool (*const SkillTester_Extern)(struct Unit *unit, const u8 skill);
typedef bool (*const skill_test_func_t)(struct Unit *unit, const u8 skill);

extern skill_test_func_t SkillTester;
extern skill_test_func_t SkillTester_Extern[];

const void* GetSkillIconGfx(unsigned id);
u16 GetSkillName(const u8 skill);
Expand Down
6 changes: 3 additions & 3 deletions wizardry/battle-system/src/battle-can-counter.c
Expand Up @@ -71,14 +71,14 @@ void SetBattleUnitWeapon(struct BattleUnit *bu, int item_slot)
LYN_REPLACE_CHECK(BattleInitTargetCanCounter);
void BattleInitTargetCanCounter(void)
{
int i = 0;
mcc_func *it;

*gBuWpnBackUp = gBattleUnitB.weapon;
*gHasInventoryWpnBackUp = gBattleUnitB.has_inventory_weapon;

/* External modular */
while (BattleCheckNullCounterCalculator[i]) {
switch (BattleCheckNullCounterCalculator[i]()) {
for (it = BattleCheckNullCounterCalculator; *it; it++) {
switch ((*it)()) {
case NULL_COUNTER:
case FORCE_COUNTER:
return;
Expand Down
73 changes: 48 additions & 25 deletions wizardry/battle-system/src/pre-battle-calc.c
Expand Up @@ -38,19 +38,21 @@ void InitBattleUnitStatus(struct BattleUnit *bu)
LYN_REPLACE_CHECK(ComputeBattleUnitDefense);
void ComputeBattleUnitDefense(struct BattleUnit *attacker, struct BattleUnit *defender)
{
int status, i = 0;
int status;
pbc_func *it;

status = GetItemAttributes(defender->weapon) & ITEM_ATTR_MAGIC
? attacker->unit.res
: attacker->unit.def;

/* Internal modular */
status += GetItemAttributes(defender->weapon) & ITEM_ATTR_MAGIC
? attacker->terrain_resistance
: attacker->terrain_defense;

/* External modular */
while (ModularBuDefGetter[i])
status = ModularBuDefGetter[i++](attacker, defender, status);
for (it = ModularBuDefGetter; *it; it++)
status = (*it)(attacker, defender, status);

LIMIT_AREA(status, 0, BATTLE_MAX_STATUS);
attacker->battle_defense = status;
Expand All @@ -59,14 +61,17 @@ void ComputeBattleUnitDefense(struct BattleUnit *attacker, struct BattleUnit *de
LYN_REPLACE_CHECK(ComputeBattleUnitBaseDefense);
void ComputeBattleUnitBaseDefense(struct BattleUnit *bu)
{
int status, i = 0;
int status;
pbc_func *it;

status = bu->unit.def;

/* Internal modular */
status = status + bu->terrain_defense;

/* External modular */
while (ModularBuDefGetter[i])
status = ModularBuDefGetter[i++](bu, NULL, status);
for (it = ModularBuDefGetter; *it; it++)
status = (*it)(bu, NULL, status);

LIMIT_AREA(status, 0, BATTLE_MAX_STATUS);
bu->battle_defense = status;
Expand All @@ -75,13 +80,17 @@ void ComputeBattleUnitBaseDefense(struct BattleUnit *bu)
LYN_REPLACE_CHECK(ComputeBattleUnitAttack);
void ComputeBattleUnitAttack(struct BattleUnit *attacker, struct BattleUnit *defender)
{
int status, i = 0;
int status;
pbc_func *it;

status = GetItemMight(attacker->weapon);

status = GetItemMight(attacker->weapon) + attacker->advantage_bonus_damage;
/* Internal modular */
status = status + attacker->advantage_bonus_damage;

/* External modular */
while (ModularBuAtkGetter[i])
status = ModularBuAtkGetter[i++](attacker, defender, status);
for (it = ModularBuAtkGetter; *it; it++)
status = (*it)(attacker, defender, status);

if (IsItemEffectiveAgainst(attacker->weapon, &defender->unit) == TRUE)
status *= 3;
Expand All @@ -95,19 +104,21 @@ void ComputeBattleUnitAttack(struct BattleUnit *attacker, struct BattleUnit *def
LYN_REPLACE_CHECK(ComputeBattleUnitSpeed);
void ComputeBattleUnitSpeed(struct BattleUnit *attacker)
{
int status, weight, i = 0;
int status, weight;
pbc_func *it;

status = attacker->unit.spd;

/* Internal modular */
weight = GetItemWeight(attacker->weapon_before) - attacker->unit.bonus_con;
if (weight < 0)
weight = 0;

status = status - weight;

/* External modular */
while (ModularBuSpdGetter[i])
status = ModularBuSpdGetter[i++](attacker, NULL, status);
for (it = ModularBuSpdGetter; *it; it++)
status = (*it)(attacker, NULL, status);

LIMIT_AREA(status, 0, BATTLE_MAX_STATUS);
attacker->battle_speed = status;
Expand All @@ -116,16 +127,19 @@ void ComputeBattleUnitSpeed(struct BattleUnit *attacker)
LYN_REPLACE_CHECK(ComputeBattleUnitHitRate);
void ComputeBattleUnitHitRate(struct BattleUnit *attacker)
{
int status, i = 0;
int status;
pbc_func *it;

status = attacker->unit.skl * 2;

/* Internal modular */
status = status + GetItemHit(attacker->weapon);
status = status + attacker->unit.lck / 2;
status = status + attacker->advantage_bonus_hit;

/* External modular */
while (ModularBuHitGetter[i])
status = ModularBuHitGetter[i++](attacker, NULL, status);
for (it = ModularBuHitGetter; *it; it++)
status = (*it)(attacker, NULL, status);

LIMIT_AREA(status, 0, BATTLE_MAX_STATUS);
attacker->battle_hit = status;
Expand All @@ -134,15 +148,18 @@ void ComputeBattleUnitHitRate(struct BattleUnit *attacker)
LYN_REPLACE_CHECK(ComputeBattleUnitAvoidRate);
void ComputeBattleUnitAvoidRate(struct BattleUnit * attacker)
{
int status, i = 0;
int status;
pbc_func *it;

status = attacker->battle_speed * 2;

/* Internal modular */
status = status + attacker->terrain_avoid;
status = status + attacker->unit.lck;

/* External modular */
while (ModularBuAvoGetter[i])
status = ModularBuAvoGetter[i++](attacker, NULL, status);
for (it = ModularBuAvoGetter; *it; it++)
status = (*it)(attacker, NULL, status);

LIMIT_AREA(status, 0, BATTLE_MAX_STATUS);
attacker->battle_avoid = status;
Expand All @@ -151,17 +168,20 @@ void ComputeBattleUnitAvoidRate(struct BattleUnit * attacker)
LYN_REPLACE_CHECK(ComputeBattleUnitCritRate);
void ComputeBattleUnitCritRate(struct BattleUnit *attacker)
{
int status, i = 0;
int status;
pbc_func *it;

status = GetItemCrit(attacker->weapon);

/* Internal modular */
status = status + attacker->unit.skl / 2;

if (UNIT_ATTRIBUTES(&attacker->unit) & UNIT_ATTR_CRITBONUS)
status += 30;

/* External modular */
while (ModularBuCrtGetter[i])
status = ModularBuCrtGetter[i++](attacker, NULL, status);
for (it = ModularBuCrtGetter; *it; it++)
status = (*it)(attacker, NULL, status);

LIMIT_AREA(status, 0, BATTLE_MAX_STATUS);
attacker->battle_crit = status;
Expand All @@ -170,13 +190,16 @@ void ComputeBattleUnitCritRate(struct BattleUnit *attacker)
/* No enough space for lyn-jump ... */
void _ComputeBattleUnitDodgeRate(struct BattleUnit *attacker)
{
int status, i = 0;
int status;
pbc_func *it;

status = attacker->unit.lck;

/* Internal modular */

/* External modular */
while (ModularBuDgeGetter[i])
status = ModularBuDgeGetter[i++](attacker, NULL, status);
for (it = ModularBuDgeGetter; *it; it++)
status = (*it)(attacker, NULL, status);

LIMIT_AREA(status, 0, BATTLE_MAX_STATUS);
attacker->battle_dodge = status;
Expand Down
14 changes: 7 additions & 7 deletions wizardry/battle-unit-hook/src/b2u-hook.c
Expand Up @@ -11,7 +11,7 @@ extern B2U_func Battle2UnitFuncList[];

void InitBattleUnit(struct BattleUnit *bu, struct Unit *unit)
{
U2B_func *it = Unit2BattleFuncList;
U2B_func *it;

if (!unit)
return;
Expand Down Expand Up @@ -57,14 +57,14 @@ void InitBattleUnit(struct BattleUnit *bu, struct Unit *unit)
gBattleUnitA.exp_gain = 0;
gBattleUnitB.exp_gain = 0;

while (*it)
(*it++)(bu, unit);
for (it = Unit2BattleFuncList; *it; it++)
(*it)(bu, unit);
}

void UpdateUnitFromBattle(struct Unit * unit, struct BattleUnit * bu)
{
int tmp;
B2U_func *it = Battle2UnitFuncList;
B2U_func *it;

unit->level = bu->unit.level;
unit->exp = bu->unit.exp;
Expand Down Expand Up @@ -96,7 +96,7 @@ void UpdateUnitFromBattle(struct Unit * unit, struct BattleUnit * bu)

if (bu->exp_gain)
PidStatsAddExpGained(unit->pinfo->id, bu->exp_gain);
while (*it)
(*it++)(unit, bu);

for (it = Battle2UnitFuncList; *it; it++)
(*it)(unit, bu);
}
6 changes: 3 additions & 3 deletions wizardry/chapter-init-hook/src/chapter-init-hook.c
Expand Up @@ -12,7 +12,7 @@ extern cih_func ChapterInitHooks[];

void PrepPhase_Init(ProcPtr proc)
{
int i = 0;
cih_func *it;

if (!GetChapterInfo(gPlaySt.chapter)->has_prep) {
Proc_End(proc);
Expand All @@ -35,8 +35,8 @@ void PrepPhase_Init(ProcPtr proc)
#endif

/* External modular */
while (ChapterInitHooks[i])
ChapterInitHooks[i++](proc);
for (it = ChapterInitHooks; *it; it++)
(*it)(proc);

RefreshEntityMaps();
RenderMap();
Expand Down
12 changes: 0 additions & 12 deletions wizardry/eabi2agbcc/eabi-2-agbcc.c

This file was deleted.

6 changes: 3 additions & 3 deletions wizardry/load-unit-hook/src/load-u-hook.c
Expand Up @@ -12,7 +12,7 @@ void _SetUnitLeaderPid(struct Unit * unit, int pid);
struct Unit *CreateUnit(struct UnitInfo const *info)
{
struct Unit *unit = NULL;
lu_func *it = OnLoadUnitFuncList;
lu_func *it;

switch (info->faction_id) {
case FACTION_ID_BLUE:
Expand Down Expand Up @@ -57,8 +57,8 @@ struct Unit *CreateUnit(struct UnitInfo const *info)

unit->hp = GetUnitMaxHp(unit);

while (*it)
(*it++)(unit);
for (it = OnLoadUnitFuncList; *it; it++)
(*it)(unit);

return unit;
}
Expand Down
10 changes: 5 additions & 5 deletions wizardry/rng-ext/src/rng-ext.c
Expand Up @@ -34,10 +34,10 @@ void RandInitExt()
int i;

for(i = 0; i < 20; i++)
NextRN();
NextRN();

for( int i = 0; i < 3; i++ )
gRandStC[i] = sRandStA[i];
for( int i = 0; i < 3; i++ )
gRandStC[i] = sRandStA[i];
}

int NextRNExts(int time)
Expand Down Expand Up @@ -66,15 +66,15 @@ int RandNextExts(int max, int time)
{
// take the next rn (range 0-0xFFFF) and convert it to a range 0-(max-1) value
// NOTE: bugged due to rounding
return NextRNExts(time) / (UINT16_MAX / max);
return Div(NextRNExts(time), Div(UINT16_MAX, max));
}


int RandNextExts_100(int time)
{
// take the next rn (range 0-0xFFFF) and convert it to a range 0-(max-1) value
// NOTE: bugged due to rounding
return NextRNExts(time) / (UINT16_MAX / 100);
return Div(NextRNExts(time), UINT16_MAX / 100);
}

bool RandExtRoll2Rn(int threshold, int time)
Expand Down
4 changes: 2 additions & 2 deletions wizardry/save-data/save-data.event
Expand Up @@ -12,8 +12,8 @@
* save2 0x3D6C 0x14A8 0xDF0 0x6B8
* save3 0x5214 0x14A8 0xDF0 0x6B8
* link_arena 0x66BC 0x93C 0x93C 0x0
* block_6 0x6FF8 0x1000 0x1000 0x0
* _PAD_ 0x7FF8 0x8 ----- -----
* _PAD_ 0x6FF8 0x8 ----- -----
* block_6 0x7000 0x1000 0x1000 0x0
*/

#define EmsChunk(aOffset, aSize, apSaver, apLoader) "SHORT (aOffset) (aSize); POIN (apSaver | 1) (apLoader | 1)"
Expand Down
4 changes: 2 additions & 2 deletions wizardry/save-data/src/modular-save.h
Expand Up @@ -31,8 +31,8 @@ enum EMS_SRAM_block_sizes {
EMS_SRAM_SIZE_SUS = 0x2830,
EMS_SRAM_SIZE_SAV = 0x14A8,
EMS_SRAM_SIZE_ARENA = 0x093C,
EMS_SRAM_SIZE_PAD = 0x8,
EMS_SRAM_SIZE_6 = 0x1000,
EMS_SRAM_SIZE_RSV = 0x8,
};

enum EMS_SRAM_block_memmap {
Expand All @@ -42,7 +42,7 @@ enum EMS_SRAM_block_memmap {
EMS_SRAM_MEMMAP_SAV1 = EMS_SRAM_MEMMAP_SAV0 + EMS_SRAM_SIZE_SAV,
EMS_SRAM_MEMMAP_SAV2 = EMS_SRAM_MEMMAP_SAV1 + EMS_SRAM_SIZE_SAV,
EMS_SRAM_MEMMAP_5 = EMS_SRAM_MEMMAP_SAV2 + EMS_SRAM_SIZE_SAV,
EMS_SRAM_MEMMAP_6 = EMS_SRAM_MEMMAP_5 + EMS_SRAM_SIZE_ARENA,
EMS_SRAM_MEMMAP_6 = 0x7000,
};

struct EmsChunk {
Expand Down

0 comments on commit e42af24

Please sign in to comment.