Skip to content

Commit

Permalink
Fix ASAN errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Jan 8, 2025
1 parent 2ad27fc commit 4b4366f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 58 deletions.
6 changes: 5 additions & 1 deletion src/game_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ void Game_Battle::UpdateAtbGauges() {
}

bool Game_Battle::ManiacBattleHook(Game_Interpreter_Battle::ManiacBattleHookType hook_type, int var1, int var2, int var3, int var4, int var5, int var6) {
return interpreter->ManiacBattleHook(hook_type, var1, var2, var3, var4, var5, var6);
if (Player::IsPatchManiac() && interpreter) {
return interpreter->ManiacBattleHook(hook_type, var1, var2, var3, var4, var5, var6);
} else {
return false;
}
}

bool Game_Battle::ManiacProcessSubEvents() {
Expand Down
1 change: 1 addition & 0 deletions src/game_battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ namespace Game_Battle {
* Convenience function to call a maniacs battle hook, which processes sub-events at any time.
*/
bool ManiacBattleHook(Game_Interpreter_Battle::ManiacBattleHookType hook_type, int var1, int var2, int var3, int var4 = 0, int var5 = 0, int var6 = 0);

/**
* Convenience function to process all maniacs sub-events, and return whether they're currently running
*/
Expand Down
100 changes: 45 additions & 55 deletions src/game_battlealgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplySpEffect() {
source->ChangeSp(-sp);
}

if (Player::IsPatchManiac()) {
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
target->GetDisplayY(),
3,
sp
);
}
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
target->GetDisplayY(),
3,
sp
);
}

return sp;
Expand All @@ -223,17 +221,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyAtkEffect() {
source->ChangeAtkModifier(-atk);
}

if (Player::IsPatchManiac()) {
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
target->GetDisplayY(),
4,
atk
);
}
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
target->GetDisplayY(),
4,
atk
);
}
return atk;
}
Expand All @@ -248,17 +244,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyDefEffect() {
source->ChangeDefModifier(-def);
}

if (Player::IsPatchManiac()) {
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
target->GetDisplayY(),
5,
def
);
}
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
target->GetDisplayY(),
5,
def
);
}
return def;
}
Expand All @@ -273,17 +267,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplySpiEffect() {
source->ChangeSpiModifier(-spi);
}

if (Player::IsPatchManiac()) {
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
target->GetDisplayY(),
6,
spi
);
}
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
target->GetDisplayY(),
6,
spi
);
}
return spi;
}
Expand All @@ -298,17 +290,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyAgiEffect() {
source->ChangeAgiModifier(-agi);
}

if (Player::IsPatchManiac()) {
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
target->GetDisplayY(),
7,
agi
);
}
Game_Battle::ManiacBattleHook(
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
target->GetType() == Game_Battler::Type_Enemy,
target->GetPartyIndex(),
target->GetDisplayX(),
target->GetDisplayY(),
7,
agi
);
}
return agi;
}
Expand Down
14 changes: 12 additions & 2 deletions src/game_battler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,22 @@ int Game_Battler::GetAgi(Weapon weapon) const {
}

int Game_Battler::GetDisplayX() const {
int shake_pos = Main_Data::game_screen->GetShakeOffsetX() + shake.position;
int shake_x = 0;
if (Main_Data::game_screen) {
shake_x = Main_Data::game_screen->GetShakeOffsetX();
}

int shake_pos = shake_x + shake.position;
return Player::menu_offset_x + ((GetBattlePosition().x + shake_pos) * MENU_WIDTH / MENU_WIDTH);
}

int Game_Battler::GetDisplayY() const {
int shake_pos = Main_Data::game_screen->GetShakeOffsetY();
int shake_y = 0;
if (Main_Data::game_screen) {
shake_y = Main_Data::game_screen->GetShakeOffsetY();
}

int shake_pos = shake_y;
return Player::menu_offset_y + ((GetBattlePosition().y + GetFlyingOffset() + shake_pos) * MENU_HEIGHT / MENU_HEIGHT);
}

Expand Down

0 comments on commit 4b4366f

Please sign in to comment.