Skip to content

Commit 0630eb1

Browse files
committed
Fix ASAN errors
1 parent c793a76 commit 0630eb1

File tree

5 files changed

+64
-59
lines changed

5 files changed

+64
-59
lines changed

src/autobattle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ void SelectAutoBattleAction(Game_Actor& source,
300300
}
301301
}
302302
}
303-
DebugLog("AUTOBATTLE: Actor {} Best Skill Rank : {}({}): {}", source.GetName(), skill->name, skill->ID, skill_rank);
303+
DebugLog("AUTOBATTLE: Actor {} Best Skill Rank : {}({}): {}", source.GetName(), skill ? skill->name : "None", skill ? skill->ID : 0, skill_rank);
304304
}
305305

306306
double normal_attack_rank = CalcNormalAttackAutoBattleRank(source, weapon, cond, attack_variance, emulate_bugs);

src/game_battle.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ void Game_Battle::UpdateAtbGauges() {
234234
}
235235

236236
bool Game_Battle::ManiacBattleHook(Game_Interpreter_Battle::ManiacBattleHookType hook_type, int var1, int var2, int var3, int var4, int var5, int var6) {
237-
return interpreter->ManiacBattleHook(hook_type, var1, var2, var3, var4, var5, var6);
237+
if (Player::IsPatchManiac() && interpreter) {
238+
return interpreter->ManiacBattleHook(hook_type, var1, var2, var3, var4, var5, var6);
239+
} else {
240+
return false;
241+
}
238242
}
239243

240244
bool Game_Battle::ManiacProcessSubEvents() {

src/game_battle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ namespace Game_Battle {
114114
* Convenience function to call a maniacs battle hook, which processes sub-events at any time.
115115
*/
116116
bool ManiacBattleHook(Game_Interpreter_Battle::ManiacBattleHookType hook_type, int var1, int var2, int var3, int var4 = 0, int var5 = 0, int var6 = 0);
117+
117118
/**
118119
* Convenience function to process all maniacs sub-events, and return whether they're currently running
119120
*/

src/game_battlealgorithm.cpp

Lines changed: 45 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplySpEffect() {
195195
source->ChangeSp(-sp);
196196
}
197197

198-
if (Player::IsPatchManiac()) {
199-
Game_Battle::ManiacBattleHook(
200-
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
201-
target->GetType() == Game_Battler::Type_Enemy,
202-
target->GetPartyIndex(),
203-
target->GetDisplayX(),
204-
target->GetDisplayY(),
205-
3,
206-
sp
207-
);
208-
}
198+
Game_Battle::ManiacBattleHook(
199+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
200+
target->GetType() == Game_Battler::Type_Enemy,
201+
target->GetPartyIndex(),
202+
target->GetDisplayX(),
203+
target->GetDisplayY(),
204+
3,
205+
sp
206+
);
209207
}
210208

211209
return sp;
@@ -221,17 +219,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyAtkEffect() {
221219
source->ChangeAtkModifier(-atk);
222220
}
223221

224-
if (Player::IsPatchManiac()) {
225-
Game_Battle::ManiacBattleHook(
226-
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
227-
target->GetType() == Game_Battler::Type_Enemy,
228-
target->GetPartyIndex(),
229-
target->GetDisplayX(),
230-
target->GetDisplayY(),
231-
4,
232-
atk
233-
);
234-
}
222+
Game_Battle::ManiacBattleHook(
223+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
224+
target->GetType() == Game_Battler::Type_Enemy,
225+
target->GetPartyIndex(),
226+
target->GetDisplayX(),
227+
target->GetDisplayY(),
228+
4,
229+
atk
230+
);
235231
}
236232
return atk;
237233
}
@@ -246,17 +242,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyDefEffect() {
246242
source->ChangeDefModifier(-def);
247243
}
248244

249-
if (Player::IsPatchManiac()) {
250-
Game_Battle::ManiacBattleHook(
251-
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
252-
target->GetType() == Game_Battler::Type_Enemy,
253-
target->GetPartyIndex(),
254-
target->GetDisplayX(),
255-
target->GetDisplayY(),
256-
5,
257-
def
258-
);
259-
}
245+
Game_Battle::ManiacBattleHook(
246+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
247+
target->GetType() == Game_Battler::Type_Enemy,
248+
target->GetPartyIndex(),
249+
target->GetDisplayX(),
250+
target->GetDisplayY(),
251+
5,
252+
def
253+
);
260254
}
261255
return def;
262256
}
@@ -271,17 +265,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplySpiEffect() {
271265
source->ChangeSpiModifier(-spi);
272266
}
273267

274-
if (Player::IsPatchManiac()) {
275-
Game_Battle::ManiacBattleHook(
276-
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
277-
target->GetType() == Game_Battler::Type_Enemy,
278-
target->GetPartyIndex(),
279-
target->GetDisplayX(),
280-
target->GetDisplayY(),
281-
6,
282-
spi
283-
);
284-
}
268+
Game_Battle::ManiacBattleHook(
269+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
270+
target->GetType() == Game_Battler::Type_Enemy,
271+
target->GetPartyIndex(),
272+
target->GetDisplayX(),
273+
target->GetDisplayY(),
274+
6,
275+
spi
276+
);
285277
}
286278
return spi;
287279
}
@@ -296,17 +288,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyAgiEffect() {
296288
source->ChangeAgiModifier(-agi);
297289
}
298290

299-
if (Player::IsPatchManiac()) {
300-
Game_Battle::ManiacBattleHook(
301-
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
302-
target->GetType() == Game_Battler::Type_Enemy,
303-
target->GetPartyIndex(),
304-
target->GetDisplayX(),
305-
target->GetDisplayY(),
306-
7,
307-
agi
308-
);
309-
}
291+
Game_Battle::ManiacBattleHook(
292+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
293+
target->GetType() == Game_Battler::Type_Enemy,
294+
target->GetPartyIndex(),
295+
target->GetDisplayX(),
296+
target->GetDisplayY(),
297+
7,
298+
agi
299+
);
310300
}
311301
return agi;
312302
}

src/game_battler.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,22 @@ int Game_Battler::GetAgi(Weapon weapon) const {
576576
}
577577

578578
int Game_Battler::GetDisplayX() const {
579-
int shake_pos = Main_Data::game_screen->GetShakeOffsetX() + shake.position;
579+
int shake_x = 0;
580+
if (Main_Data::game_screen) {
581+
shake_x = Main_Data::game_screen->GetShakeOffsetX();
582+
}
583+
584+
int shake_pos = shake_x + shake.position;
580585
return Player::menu_offset_x + ((GetBattlePosition().x + shake_pos) * MENU_WIDTH / MENU_WIDTH);
581586
}
582587

583588
int Game_Battler::GetDisplayY() const {
584-
int shake_pos = Main_Data::game_screen->GetShakeOffsetY();
589+
int shake_y = 0;
590+
if (Main_Data::game_screen) {
591+
shake_y = Main_Data::game_screen->GetShakeOffsetY();
592+
}
593+
594+
int shake_pos = shake_y;
585595
return Player::menu_offset_y + ((GetBattlePosition().y + GetFlyingOffset() + shake_pos) * MENU_HEIGHT / MENU_HEIGHT);
586596
}
587597

0 commit comments

Comments
 (0)