Skip to content

Commit 7d78303

Browse files
committed
Fix ASAN errors
1 parent f9f1350 commit 7d78303

File tree

4 files changed

+63
-58
lines changed

4 files changed

+63
-58
lines changed

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
@@ -197,17 +197,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplySpEffect() {
197197
source->ChangeSp(-sp);
198198
}
199199

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

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

226-
if (Player::IsPatchManiac()) {
227-
Game_Battle::ManiacBattleHook(
228-
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
229-
target->GetType() == Game_Battler::Type_Enemy,
230-
target->GetPartyIndex(),
231-
target->GetDisplayX(),
232-
target->GetDisplayY(),
233-
4,
234-
atk
235-
);
236-
}
224+
Game_Battle::ManiacBattleHook(
225+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
226+
target->GetType() == Game_Battler::Type_Enemy,
227+
target->GetPartyIndex(),
228+
target->GetDisplayX(),
229+
target->GetDisplayY(),
230+
4,
231+
atk
232+
);
237233
}
238234
return atk;
239235
}
@@ -248,17 +244,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyDefEffect() {
248244
source->ChangeDefModifier(-def);
249245
}
250246

251-
if (Player::IsPatchManiac()) {
252-
Game_Battle::ManiacBattleHook(
253-
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
254-
target->GetType() == Game_Battler::Type_Enemy,
255-
target->GetPartyIndex(),
256-
target->GetDisplayX(),
257-
target->GetDisplayY(),
258-
5,
259-
def
260-
);
261-
}
247+
Game_Battle::ManiacBattleHook(
248+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
249+
target->GetType() == Game_Battler::Type_Enemy,
250+
target->GetPartyIndex(),
251+
target->GetDisplayX(),
252+
target->GetDisplayY(),
253+
5,
254+
def
255+
);
262256
}
263257
return def;
264258
}
@@ -273,17 +267,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplySpiEffect() {
273267
source->ChangeSpiModifier(-spi);
274268
}
275269

276-
if (Player::IsPatchManiac()) {
277-
Game_Battle::ManiacBattleHook(
278-
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
279-
target->GetType() == Game_Battler::Type_Enemy,
280-
target->GetPartyIndex(),
281-
target->GetDisplayX(),
282-
target->GetDisplayY(),
283-
6,
284-
spi
285-
);
286-
}
270+
Game_Battle::ManiacBattleHook(
271+
Game_Interpreter_Battle::ManiacBattleHookType::StatChange,
272+
target->GetType() == Game_Battler::Type_Enemy,
273+
target->GetPartyIndex(),
274+
target->GetDisplayX(),
275+
target->GetDisplayY(),
276+
6,
277+
spi
278+
);
287279
}
288280
return spi;
289281
}
@@ -298,17 +290,15 @@ int Game_BattleAlgorithm::AlgorithmBase::ApplyAgiEffect() {
298290
source->ChangeAgiModifier(-agi);
299291
}
300292

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

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)