Merge pull request #214 from slaw-22/Scripting5

Decomp more script variable functions
This commit is contained in:
AnonymousRandomPerson 2025-11-29 12:13:06 -06:00 committed by GitHub
commit 8a64882ffb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 139 additions and 253 deletions

View File

@ -4,7 +4,7 @@
.public Debug_Print0
.public GAME_MODE
.public InitDungeonListScriptVars
.public InitScenarioScriptVars
.public InitProgress
.public InitWorldMapScriptVars
.public SaveScriptVariableValue
.public SaveScriptVariableValueAtIndex

View File

@ -10,4 +10,4 @@
.public SaveScriptVariableValue
.public SaveScriptVariableValueAtIndex
.public ZinitScriptVariable
.public _0209DFA0
.public SCENARIO_CALC_DEBUG_MSG

View File

@ -360,7 +360,7 @@
.public SetCollectionMenuField0x1B2
.public SetPokemonJoined
.public SetQuestionMarks
.public SetScenarioScriptVar
.public UpdateProgress
.public SetSpecialEpisodeType
.public SetSpriteIdForAnimationControl
.public ShowPortraitInPortraitBox

View File

@ -244,7 +244,7 @@
.public SetAnimationForAnimationControl
.public SetIrqFlag
.public SetMainTeamName
.public SetScenarioScriptVar
.public UpdateProgress
.public SetSpriteIdForAnimationControl
.public ShowKeyboard
.public ShowStringIdInDialogueBox

View File

@ -490,7 +490,7 @@
.public SetPortraitEmotion
.public SetPortraitLayout
.public SetPortraitOffset
.public SetScenarioScriptVar
.public UpdateProgress
.public SetTeamSetupHeroAndPartnerOnly
.public SetTeamSetupHeroOnly
.public SetupAndShowKeyboard
@ -632,7 +632,7 @@
.public CompareScriptVariablesVeneer
.public CompareScriptVarWithParam
.public LoadAndCompareScriptVars
.public sub_0204C5DC
.public LoadScriptVarValuePair
.public sub_0204C6C8
.public sub_0204C734
.public sub_0204C7AC

View File

@ -42,7 +42,7 @@
.public sub_02046740
.public sub_0204677C
.public sub_0204AFD0
.public sub_0204C5DC
.public LoadScriptVarValuePair
.public sub_0204E770
.public sub_0204E780
.public sub_0204F0A0

View File

@ -219,7 +219,7 @@ _0204B118:
mov r0, #0
mov r1, #0x4d
bl ZinitScriptVariable
bl InitScenarioScriptVars
bl InitProgress
bl InitWorldMapScriptVars
bl InitDungeonListScriptVars
ldmia sp!, {r3, r4, r5, r6, r7, r8, sb, sl, fp, pc}

View File

@ -3,207 +3,6 @@
.text
arm_func_start DumpScriptVariableValues
DumpScriptVariableValues: ; 0x0204C408
stmdb sp!, {r4, lr}
mov r4, r0
bl EventFlagBackup
ldr r1, _0204C42C ; =SCRIPT_VARS_VALUES
mov r0, r4
mov r2, #0x400
bl MemcpySimple
mov r0, #1
ldmia sp!, {r4, pc}
.align 2, 0
_0204C42C: .word SCRIPT_VARS_VALUES
arm_func_end DumpScriptVariableValues
arm_func_start RestoreScriptVariableValues
RestoreScriptVariableValues: ; 0x0204C430
stmdb sp!, {r4, lr}
sub sp, sp, #8
mov r1, #0
mov r4, r0
add r0, sp, #0
mov r2, r1
bl LoadScriptVariableRaw
ldr r0, _0204C484 ; =SCRIPT_VARS_VALUES
mov r1, r4
mov r2, #0x400
bl MemcpySimple
ldr r1, [sp]
ldr r0, [sp, #4]
ldrsh r1, [r1, #0xa]
ldr r0, [r0]
cmp r1, r0
moveq r0, #1
movne r0, #0
and r0, r0, #0xff
add sp, sp, #8
ldmia sp!, {r4, pc}
.align 2, 0
_0204C484: .word SCRIPT_VARS_VALUES
arm_func_end RestoreScriptVariableValues
arm_func_start InitScenarioScriptVars
InitScenarioScriptVars: ; 0x0204C488
stmdb sp!, {r4, r5, r6, r7, r8, lr}
mov r1, #0
mov r2, r1
mov r0, #2
bl SetScenarioScriptVar
mov r1, #0
mov r2, r1
mov r0, #3
bl SetScenarioScriptVar
mov r1, #0
mov r2, r1
mov r0, #4
bl SetScenarioScriptVar
mov r1, #0
mov r2, r1
mov r0, #5
bl SetScenarioScriptVar
mov r1, #0
mov r2, r1
mov r0, #6
bl SetScenarioScriptVar
mov r1, #0
mov r0, #7
mov r2, r1
bl SetScenarioScriptVar
mov r1, #0
mov r0, #8
mov r2, r1
bl SetScenarioScriptVar
mov r1, #0
mov r0, #9
mov r2, r1
bl SetScenarioScriptVar
mov r1, #0
mov r0, #0xa
mov r2, r1
bl SetScenarioScriptVar
mov r1, #0
mov r0, #0xb
mov r2, r1
bl SetScenarioScriptVar
mov r1, #0
mov r0, #0xc
mov r2, r1
bl SetScenarioScriptVar
mov r0, #0
mov r1, #0x11
bl ZinitScriptVariable
mov r0, #0
mov r1, #0x1b
bl ZinitScriptVariable
mov r8, #0
mov r6, #0x1a
mov r7, r8
mov r5, r8
mov r4, r6
_0204C568:
mov r2, r8, lsl #0x10
mov r0, r7
mov r1, r6
mov r3, r7
mov r2, r2, lsr #0x10
bl SaveScriptVariableValueAtIndex
add r0, r8, #4
mov r2, r0, lsl #0x10
mov r0, r5
mov r1, r4
mov r3, r5
mov r2, r2, lsr #0x10
bl SaveScriptVariableValueAtIndex
add r8, r8, #1
cmp r8, #4
blt _0204C568
mov r0, #0
mov r2, r0
mov r1, #0x13
bl SaveScriptVariableValue
mov r1, #0x14
sub r2, r1, #0x15
mov r0, #0
bl SaveScriptVariableValue
mov r0, #0
mov r2, r0
mov r1, #0x6f
bl SaveScriptVariableValue
ldmia sp!, {r4, r5, r6, r7, r8, pc}
arm_func_end InitScenarioScriptVars
arm_func_start sub_0204C5DC
sub_0204C5DC: ; 0x0204C5DC
stmdb sp!, {r4, r5, r6, lr}
mov r6, r0
mov r5, r1
mov r0, #0
mov r4, r2
mov r1, r6
mov r2, r0
bl LoadScriptVariableValueAtIndex
str r0, [r5]
mov r1, r6
mov r0, #0
mov r2, #1
bl LoadScriptVariableValueAtIndex
str r0, [r4]
ldmia sp!, {r4, r5, r6, pc}
arm_func_end sub_0204C5DC
arm_func_start SetScenarioScriptVar
SetScenarioScriptVar: ; 0x0204C618
stmdb sp!, {r3, r4, r5, r6, r7, r8, lr}
sub sp, sp, #0xc
mov r8, r0
mov r7, r1
mov r0, #0
mov r6, r2
mov r1, r8
mov r2, r0
bl LoadScriptVariableValueAtIndex
mov r5, r0
mov r1, r8
mov r0, #0
mov r2, #1
bl LoadScriptVariableValueAtIndex
mov r4, r0
stmia sp, {r4, r7}
ldr r1, _0204C6C4 ; =_0209DFA0
mov r0, #9
mov r2, r8
mov r3, r5
str r6, [sp, #8]
bl Debug_Print
cmp r8, #3
bne _0204C694
cmp r7, r5
cmpeq r6, r4
beq _0204C694
mov r0, #0
mov r2, r0
mov r1, #0x33
bl SaveScriptVariableValue
_0204C694:
mov r0, #0
mov r1, r8
mov r2, r0
mov r3, r7
bl SaveScriptVariableValueAtIndex
mov r1, r8
mov r3, r6
mov r0, #0
mov r2, #1
bl SaveScriptVariableValueAtIndex
add sp, sp, #0xc
ldmia sp!, {r3, r4, r5, r6, r7, r8, pc}
.align 2, 0
_0204C6C4: .word _0209DFA0
arm_func_end SetScenarioScriptVar
arm_func_start sub_0204C6C8
sub_0204C6C8: ; 0x0204C6C8
stmdb sp!, {r3, r4, r5, r6, r7, lr}

View File

@ -16155,7 +16155,7 @@ _020661B0:
mov r0, #2
mov r1, #0x36
mov r2, #0
bl SetScenarioScriptVar
bl UpdateProgress
mov r0, #2
bl LoadOverlay
mov r0, #0
@ -16225,7 +16225,7 @@ _020662BC:
mov r0, #2
mov r1, #0x33
mov r2, #0
bl SetScenarioScriptVar
bl UpdateProgress
mov r0, #2
bl LoadOverlay
mov r0, #1
@ -16256,7 +16256,7 @@ _02066330:
mov r0, #2
mov r1, #0x34
mov r2, #0
bl SetScenarioScriptVar
bl UpdateProgress
mov r0, #2
bl LoadOverlay
mov r0, #1

View File

@ -860,8 +860,8 @@ _0209DF70:
.byte 0x00, 0x00, 0x00, 0x00
.byte 0xB4, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.word _0209CFA4
.global _0209DFA0
_0209DFA0:
.global SCENARIO_CALC_DEBUG_MSG
SCENARIO_CALC_DEBUG_MSG:
.byte 0x53, 0x43, 0x45, 0x4E
.byte 0x41, 0x52, 0x49, 0x4F, 0x20, 0x43, 0x41, 0x4C, 0x43, 0x20, 0x5B, 0x25, 0x33, 0x64, 0x5D, 0x20
.byte 0x25, 0x34, 0x64, 0x20, 0x25, 0x34, 0x64, 0x20, 0x2D, 0x3E, 0x20, 0x25, 0x34, 0x64, 0x20, 0x25

View File

@ -13063,7 +13063,7 @@ _02333DA4:
mov r0, #3
mov r1, #0x1c
mov r2, #0
bl SetScenarioScriptVar
bl UpdateProgress
mov r0, #2
mov r1, #6
mov r2, #1

View File

@ -3246,7 +3246,7 @@ _022DEE84: ; 0x022DEE84
mov r2, r0
mov r1, r4
mov r0, r3, asr #0x10
bl SetScenarioScriptVar
bl UpdateProgress
b _022E2474
_022DEEBC: ; 0x022DEEBC
ldrh r0, [r6]
@ -3255,7 +3255,7 @@ _022DEEBC: ; 0x022DEEBC
mov r1, #0
mov r2, r1
mov r0, r0, asr #0x10
bl SetScenarioScriptVar
bl UpdateProgress
b _022E2474
_022DEEDC: ; 0x022DEEDC
ldrh r0, [r6]
@ -11763,7 +11763,7 @@ _022E6474:
add r1, sp, #0x50
add r2, sp, #0x4c
mov r0, #2
bl sub_0204C5DC
bl LoadScriptVarValuePair
ldr r0, [sp, #0x4c]
mov r0, r0, lsl #0x18
mov r0, r0, asr #0x18
@ -11814,7 +11814,7 @@ _022E652C:
add r1, sp, #0x40
add r2, sp, #0x3c
mov r0, #2
bl sub_0204C5DC
bl LoadScriptVarValuePair
ldrb r1, [sp, #0x11]
ldr r2, [sp, #0x3c]
ldr r0, _022E68D4 ; =ov11_0231993C
@ -11863,7 +11863,7 @@ _022E657C:
ldr r1, [sp, #0x40]
ldr r2, [sp, #0x3c]
mov r0, #2
bl SetScenarioScriptVar
bl UpdateProgress
ldrsh r0, [sp, #0x36]
ldrsh r1, [sp, #0x38]
bl sub_02065B80
@ -11891,7 +11891,7 @@ _022E6644:
mov r1, #0
mov r2, r1
mov r0, #2
bl SetScenarioScriptVar
bl UpdateProgress
mov r0, #0
b _022E68BC
_022E6678:
@ -11902,7 +11902,7 @@ _022E6678:
add r1, sp, #0x30
add r2, sp, #0x2c
mov r0, #2
bl sub_0204C5DC
bl LoadScriptVarValuePair
ldr r0, [sp, #0x2c]
mov r0, r0, lsl #0x18
mov r0, r0, asr #0x18
@ -12408,7 +12408,7 @@ _022E6D70:
add r1, sp, #0x14
add r2, sp, #0x10
mov r0, #2
bl sub_0204C5DC
bl LoadScriptVarValuePair
ldr r0, [sp, #0x10]
mov r0, r0, lsl #0x18
mov r0, r0, asr #0x18
@ -12418,7 +12418,7 @@ _022E6D70:
ldr r1, [sp, #0x14]
add r2, r0, #1
mov r0, #2
bl SetScenarioScriptVar
bl UpdateProgress
mov r0, #1
b _022E6E58
_022E6DB0:

View File

@ -15,7 +15,7 @@ ov26_0238A140: ; 0x0238A140
add r1, sp, #0xc
add r2, sp, #8
mov r0, #2
bl sub_0204C5DC
bl LoadScriptVarValuePair
ldr r0, [sp, #8]
mov r0, r0, lsl #0x18
mov r0, r0, asr #0x18

View File

@ -29,8 +29,6 @@ struct script_var_raw {
union script_var_value *value;
};
extern const short LOCAL_SCRIPT_VAR_OFFSET;
void LoadScriptVariableRaw(struct script_var_raw* sv_raw, union script_var_value sv_val_local[], const enum script_var_id sv_id);
s32 LoadScriptVariableValue(union script_var_value sv_local[], enum script_var_id sv_id);
s32 LoadScriptVariableValueAtIndex(union script_var_value sv_local[], enum script_var_id id, u16 idx);
@ -51,5 +49,10 @@ s32 CompareScriptVarWithParam(union script_var_value sv_local[], enum script_var
s32 LoadAndCompareScriptVars(union script_var_value sv_local[], enum script_var_id sv_id_1, enum script_var_id sv_id_2, enum compare_operation op);
void EventFlagResume();
void EventFlagBackup();
bool8 DumpScriptVariableValues(u8* dest);
bool8 RestoreScriptVariableValues(u8* src);
void InitProgress();
void LoadScriptVarValuePair(enum script_var_id script_var_id, s32* val_1, s32* val_2);
void UpdateProgress(enum script_var_id script_var_id, s32 progress, s32 sub_progress);
#endif //PMDSKY_SCRIPTING_H

View File

@ -82,7 +82,7 @@ Static main
Object asm/main_0204B018.o
Object src/script_variable.o
Object asm/main_rodata_0209CECC.o
Object asm/main_0204C408.o
Object asm/main_0204C6C8.o
Object src/main_0204C938.o
Object asm/main_0204C94C.o
Object src/dungeon_recruitment_3.o

View File

@ -3,12 +3,28 @@
#include "main_0200224C.h"
#include "script_variable.h"
#define LOCAL_SCRIPT_VAR_OFFSET 0x400
// Global script variable definitions
extern struct script_var_def SCRIPT_VARS[];
// Local script variable definitions
extern struct script_var_def SCRIPT_VARS_LOCALS[];
// Global script variable values
extern u8 SCRIPT_VARS_VALUES[];
extern u8 EVENT_FLAG_EXPANSION_ERROR;
extern u8 EVENT_FLAG_RULE_ERROR;
extern const u8 EVENT_FLAG_GAME_MODE_DEBUG_MSG;
extern const u8 EVENT_FLAG_BACKUP_DEBUG_MSG;
const u8 EVENT_FLAG_FILE_NAME[] = "event_flag.c";
const struct prog_pos_info EVENT_FLAG_PROG_POS_INFO_LINE_1011 = {
(u8*) EVENT_FLAG_FILE_NAME,
1001
};
const struct prog_pos_info EVENT_FLAG_PROG_POS_INFO_LINE_1044 = {
(u8*) EVENT_FLAG_FILE_NAME,
1044
};
extern const u8 SCENARIO_CALC_DEBUG_MSG;
extern s32 GetPartyMembers(s32 param1);
extern s32 GetMoneyCarried();
@ -23,32 +39,16 @@ extern s32 SetMoneyCarried(s32 arg0);
extern s32 SetMoneyStored(s32 arg0);
extern s32 SetNotifyNote(s32 arg0);
extern s32 sub_0204C928(s32 arg0);
void sub_0204CBE8();
void ScenarioFlagBackup();
extern u8 EVENT_FLAG_EXPANSION_ERROR;
extern u8 EVENT_FLAG_RULE_ERROR;
extern const u8 EVENT_FLAG_GAME_MODE_DEBUG_MSG;
extern const u8 EVENT_FLAG_BACKUP_DEBUG_MSG;
const u8 EVENT_FLAG_FILE_NAME[] = "event_flag.c";
const struct prog_pos_info EVENT_FLAG_PROG_POS_INFO_LINE_1011 = {
(u8*) EVENT_FLAG_FILE_NAME,
1001
};
const struct prog_pos_info EVENT_FLAG_PROG_POS_INFO_LINE_1044 = {
(u8*) EVENT_FLAG_FILE_NAME,
1044
};
extern void sub_0204CBE8();
extern void ScenarioFlagBackup();
void MemcpySimple(u8* dest, u8* src, s32 n);
extern void ZinitScriptVariable(u32 param_1, u32 param_2);
void LoadScriptVariableRaw(struct script_var_raw* sv_raw,
union script_var_value sv_val_local[],
const enum script_var_id sv_id) {
short LOCAL_SCRIPT_VAR_OFFSET = 0x400;
if (sv_id < LOCAL_SCRIPT_VAR_OFFSET) {
if (sv_id < (s16) LOCAL_SCRIPT_VAR_OFFSET) {
// global script var
sv_raw->def = &SCRIPT_VARS[sv_id];
sv_raw->value = (union script_var_value*)
@ -486,7 +486,8 @@ s32 LoadAndCompareScriptVars(union script_var_value sv_local[], enum script_var_
}
// This inline allows EventFlagResume to match
static inline s32 LoadScriptVariableValueAtIndexInline(enum script_var_id sv_id, u32 idx) {
static inline s32 LoadScriptVariableValueAtIndexInline(enum script_var_id sv_id, u32 idx)
{
return LoadScriptVariableValueAtIndex(0, sv_id, idx);
}
@ -518,11 +519,13 @@ void EventFlagResume()
}
// This inline allows EventFlagBackup to match
static inline s32 SaveScriptVariableValueAtIndexInline(enum script_var_id sv_id, u32 idx, u32 new_val) {
static inline s32 SaveScriptVariableValueAtIndexInline(enum script_var_id sv_id, u32 idx, u32 new_val)
{
SaveScriptVariableValueAtIndex(0, sv_id, idx, new_val);
}
void EventFlagBackup() {
void EventFlagBackup()
{
u32 game_mode;
u32 idx;
@ -550,3 +553,84 @@ void EventFlagBackup() {
ScenarioFlagBackup();
}
// This dumps the global script variables (up to 0x400 bytes),
// but doesn't dump the local script variables (0x400 onwards).
bool8 DumpScriptVariableValues(u8* dest)
{
EventFlagBackup();
MemcpySimple(dest, &SCRIPT_VARS_VALUES[0], LOCAL_SCRIPT_VAR_OFFSET);
return TRUE;
}
// This restores the global script variables (up to 0x400 bytes),
// but doesn't restore the local script variables (0x400 onwards).
bool8 RestoreScriptVariableValues(u8* src)
{
struct script_var_raw sv_raw;
u8 ret_val;
LoadScriptVariableRaw(&sv_raw, 0, VAR_VERSION);
MemcpySimple(&SCRIPT_VARS_VALUES[0], src, 0x400);
// If these values are not equal, then the save file
// will be treated as corrupted, which thus gets deleted.
if (sv_raw.def->default_val == sv_raw.value->u32) {
ret_val = TRUE;
} else {
ret_val = FALSE;
}
return ret_val;
}
void InitProgress()
{
UpdateProgress(VAR_SCENARIO_SELECT, 0, 0);
UpdateProgress(VAR_SCENARIO_MAIN, 0, 0);
UpdateProgress(VAR_SCENARIO_SIDE, 0, 0);
UpdateProgress(VAR_SCENARIO_SUB1, 0, 0);
UpdateProgress(VAR_SCENARIO_SUB2, 0, 0);
UpdateProgress(VAR_SCENARIO_SUB3, 0, 0);
UpdateProgress(VAR_SCENARIO_SUB4, 0, 0);
UpdateProgress(VAR_SCENARIO_SUB5, 0, 0);
UpdateProgress(VAR_SCENARIO_SUB6, 0, 0);
UpdateProgress(VAR_SCENARIO_SUB7, 0, 0);
UpdateProgress(VAR_SCENARIO_SUB8, 0, 0);
ZinitScriptVariable(0, VAR_SCENARIO_MAIN_BIT_FLAG);
ZinitScriptVariable(0, VAR_SCENARIO_MAIN_BIT_FLAG_BACKUP);
s32 idx = 0;
do {
SaveScriptVariableValueAtIndex(0, VAR_SCENARIO_SELECT_BACKUP, idx, 0);
SaveScriptVariableValueAtIndex(0, VAR_SCENARIO_SELECT_BACKUP, (u16) (idx + 4), 0);
idx += 1;
} while (idx < 4);
SaveScriptVariableValue(0, VAR_SCENARIO_BALANCE_FLAG, 0);
SaveScriptVariableValue(0, VAR_SCENARIO_BALANCE_DEBUG, -1);
SaveScriptVariableValue(0, VAR_PLAY_OLD_GAME, 0);
}
void LoadScriptVarValuePair(enum script_var_id script_var_id, s32* val_1, s32* val_2)
{
*val_1 = LoadScriptVariableValueAtIndex(0, script_var_id, 0);
*val_2 = LoadScriptVariableValueAtIndex(0, script_var_id, 1);
}
void UpdateProgress(enum script_var_id script_var_id, s32 progress, s32 sub_progress)
{
s32 old_progress = LoadScriptVariableValueAtIndex(0, script_var_id, 0);
s32 old_sub_prog = LoadScriptVariableValueAtIndex(0, script_var_id, 1);
Debug_Print(9, &SCENARIO_CALC_DEBUG_MSG, script_var_id, old_progress, old_sub_prog,
progress, sub_progress);
// VAR_SCENARIO_MAIN stores maingame story progression
if (script_var_id == VAR_SCENARIO_MAIN) {
if ((progress!= old_progress) || (sub_progress != old_sub_prog)) {
// Reset Job Requests cleared in a single day when the maingame story progresses.
SaveScriptVariableValue(0, VAR_REQUEST_CLEAR_COUNT, 0);
}
}
SaveScriptVariableValueAtIndex(0, script_var_id, 0, progress);
SaveScriptVariableValueAtIndex(0, script_var_id, 1, sub_progress);
}