Adds assertf for incorrect usage of ends, return, call and selection script commands (#9018)

This commit is contained in:
PhallenTree 2026-01-25 18:49:08 +00:00 committed by GitHub
parent eda40c3798
commit c0be19647f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 15 deletions

View File

@ -4530,10 +4530,12 @@ static void HandleTurnActionSelectionState(void)
case STATE_SELECTION_SCRIPT:
if (gBattleStruct->battlerState[battler].selectionScriptFinished)
{
gSelectionBattleScripts[battler] = NULL;
gBattleCommunication[battler] = gBattleStruct->stateIdAfterSelScript[battler];
}
else
{
assertf(gSelectionBattleScripts[battler] != NULL, "selection script set to run, but pointer is null");
gBattlerAttacker = battler;
gBattlescriptCurrInstr = gSelectionBattleScripts[battler];
if (!IsBattleControllerActiveOrPendingSyncAnywhere(battler))
@ -4552,6 +4554,7 @@ static void HandleTurnActionSelectionState(void)
case STATE_SELECTION_SCRIPT_MAY_RUN:
if (gBattleStruct->battlerState[battler].selectionScriptFinished)
{
gSelectionBattleScripts[battler] = NULL;
if (gBattleResources->bufferB[battler][1] == B_ACTION_NOTHING_FAINTED)
{
gHitMarker |= HITMARKER_RUN;
@ -4566,6 +4569,7 @@ static void HandleTurnActionSelectionState(void)
}
else
{
assertf(gSelectionBattleScripts[battler] != NULL, "selection script set to run, but pointer is null");
gBattlerAttacker = battler;
gBattlescriptCurrInstr = gSelectionBattleScripts[battler];
if (!IsBattleControllerActiveOrPendingSyncAnywhere(battler))

View File

@ -1238,6 +1238,8 @@ static void Cmd_printselectionstringfromtable(void)
{
CMD_ARGS(const u16 *ptr);
assertf(gSelectionBattleScripts[gBattlerAttacker] != NULL, "wrong use of printselectionstringfromtable");
if (gBattleControllerExecFlags == 0)
{
const u16 *ptr = cmd->ptr;
@ -2137,6 +2139,8 @@ static void Cmd_printselectionstring(void)
{
CMD_ARGS(u16 id);
assertf(gSelectionBattleScripts[gBattlerAttacker] != NULL, "wrong use of printselectionstring");
BtlController_EmitPrintSelectionString(gBattlerAttacker, B_COMM_TO_CONTROLLER, cmd->id);
MarkBattlerForControllerExec(gBattlerAttacker);
@ -4832,6 +4836,8 @@ static void Cmd_isdmgblockedbydisguise(void)
static void Cmd_return(void)
{
assertf(gBattleResources->battleScriptsStack->size != 0, "return used with nothing to return to, did you mean end/end2/end3?");
BattleScriptPop();
}
@ -4839,6 +4845,9 @@ static void Cmd_end(void)
{
CMD_ARGS();
assertf(gSelectionBattleScripts[gBattlerAttacker] == NULL, "incorrect use of end in selection script, did you mean endselectionscript?");
assertf(gBattleMainFunc != RunBattleScriptCommands, "incorrect use of end in battle script, did you mean end3?");
if (gBattleTypeFlags & BATTLE_TYPE_ARENA)
BattleArena_AddSkillPoints(gBattlerAttacker);
@ -4849,6 +4858,9 @@ static void Cmd_end2(void)
{
CMD_ARGS();
assertf(gSelectionBattleScripts[gBattlerAttacker] == NULL, "incorrect use of end2 in selection script, did you mean endselectionscript?");
assertf(gBattleMainFunc != RunBattleScriptCommands, "incorrect use of end2 in battle script, did you mean end3?");
gCurrentActionFuncId = B_ACTION_TRY_FINISH;
}
@ -4857,9 +4869,14 @@ static void Cmd_end3(void)
{
CMD_ARGS();
assertf(gSelectionBattleScripts[gBattlerAttacker] == NULL, "incorrect use of end3 in selection script, did you mean endselectionscript?");
BattleScriptPop();
if (gBattleResources->battleCallbackStack->size != 0)
gBattleResources->battleCallbackStack->size--;
else // nothing to callback to
assertf(gBattleMainFunc != RunBattleScriptCommands_PopCallbacksStack, "incorrect use of end3 in battle script, did you mean end/end2?");
gBattleMainFunc = gBattleResources->battleCallbackStack->function[gBattleResources->battleCallbackStack->size];
}
@ -4867,6 +4884,8 @@ static void Cmd_call(void)
{
CMD_ARGS(const u8 *instr);
assertf(gBattleResources->battleScriptsStack->size < UINT8_MAX, "call used, but battleScriptsStack is full!");
BattleScriptPush(cmd->nextInstr);
gBattlescriptCurrInstr = cmd->instr;
}
@ -4899,6 +4918,8 @@ static void Cmd_jumpifabilitypresent(void)
static void Cmd_endselectionscript(void)
{
CMD_ARGS();
assertf(gSelectionBattleScripts[gBattlerAttacker] != NULL, "wrong use of endselectionscript");
gBattleStruct->battlerState[gBattlerAttacker].selectionScriptFinished = TRUE;
}

View File

@ -1403,11 +1403,13 @@ void UpdateSentPokesToOpponentValue(u32 battler)
void BattleScriptPush(const u8 *bsPtr)
{
assertf(gBattleResources->battleScriptsStack->size < UINT8_MAX, "attempted to push a battle script, but battleScriptsStack is full!");
gBattleResources->battleScriptsStack->ptr[gBattleResources->battleScriptsStack->size++] = bsPtr;
}
void BattleScriptPushCursor(void)
{
assertf(gBattleResources->battleScriptsStack->size < UINT8_MAX, "attempted to push cursor, but battleScriptsStack is full!");
gBattleResources->battleScriptsStack->ptr[gBattleResources->battleScriptsStack->size++] = gBattlescriptCurrInstr;
}
@ -1423,6 +1425,21 @@ void BattleScriptPop(void)
gBattlescriptCurrInstr = gBattleResources->battleScriptsStack->ptr[--gBattleResources->battleScriptsStack->size];
}
void BattleScriptExecute(const u8 *BS_ptr)
{
gBattlescriptCurrInstr = BS_ptr;
gBattleResources->battleCallbackStack->function[gBattleResources->battleCallbackStack->size++] = gBattleMainFunc;
gBattleMainFunc = RunBattleScriptCommands_PopCallbacksStack;
gCurrentActionFuncId = 0;
}
void BattleScriptPushCursorAndCallback(const u8 *BS_ptr)
{
BattleScriptCall(BS_ptr);
gBattleResources->battleCallbackStack->function[gBattleResources->battleCallbackStack->size++] = gBattleMainFunc;
gBattleMainFunc = RunBattleScriptCommands;
}
bool32 IsGravityPreventingMove(enum Move move)
{
if (!(gFieldStatuses & STATUS_FIELD_GRAVITY))
@ -5118,21 +5135,6 @@ bool32 CanBattlerEscape(u32 battler) // no ability check
return TRUE;
}
void BattleScriptExecute(const u8 *BS_ptr)
{
gBattlescriptCurrInstr = BS_ptr;
gBattleResources->battleCallbackStack->function[gBattleResources->battleCallbackStack->size++] = gBattleMainFunc;
gBattleMainFunc = RunBattleScriptCommands_PopCallbacksStack;
gCurrentActionFuncId = 0;
}
void BattleScriptPushCursorAndCallback(const u8 *BS_ptr)
{
BattleScriptCall(BS_ptr);
gBattleResources->battleCallbackStack->function[gBattleResources->battleCallbackStack->size++] = gBattleMainFunc;
gBattleMainFunc = RunBattleScriptCommands;
}
bool32 IsPsychicTerrainAffected(u32 battler, enum Ability ability, enum HoldEffect holdEffect, u32 fieldStatuses)
{
return IsBattlerTerrainAffected(battler, ability, holdEffect, fieldStatuses, STATUS_FIELD_PSYCHIC_TERRAIN);