Decomp ZinitScriptVariable. Organise funcs.

This commit is contained in:
slaw-22 2025-12-06 21:13:15 +00:00 committed by slaw-22
parent 0c7f2fefcf
commit 37c592b01d
14 changed files with 57 additions and 97 deletions

View File

@ -11,3 +11,4 @@
.public SCRIPT_VARS
.public SCRIPT_VARS_LOCALS
.public SCRIPT_VARS_VALUES
.public ZinitScriptVariable

View File

@ -336,36 +336,4 @@ _0204B41C:
_0204B42C: .word SCRIPT_VARS
_0204B430: .word SCRIPT_VARS_LOCALS
arm_func_end sub_0204B3D0
arm_func_start ZinitScriptVariable
ZinitScriptVariable: ; 0x0204B434
stmdb sp!, {r4, r5, r6, r7, r8, lr}
mov r5, r1
cmp r5, #0x400
mov r6, r0
ldrlt r0, _0204B494 ; =SCRIPT_VARS
mov r8, #0
addlt r4, r0, r5, lsl #4
ldrge r1, _0204B498 ; =SCRIPT_VARS_LOCALS
subge r0, r5, #0x400
addge r4, r1, r0, lsl #4
mov r7, r8
b _0204B484
_0204B464:
mov r0, r6
mov r1, r5
mov r2, r8
mov r3, r7
bl SaveScriptVariableValueAtIndex
add r0, r8, #1
mov r0, r0, lsl #0x10
mov r8, r0, lsr #0x10
_0204B484:
ldrsh r0, [r4, #8]
cmp r8, r0
blt _0204B464
ldmia sp!, {r4, r5, r6, r7, r8, pc}
.align 2, 0
_0204B494: .word SCRIPT_VARS
_0204B498: .word SCRIPT_VARS_LOCALS
arm_func_end ZinitScriptVariable

View File

@ -1,8 +0,0 @@
#ifndef PMDSKY_HAS_PLAYED_OLD_GAME_H
#define PMDSKY_HAS_PLAYED_OLD_GAME_H
#include "util.h"
bool8 HasPlayedOldGame();
#endif //PMDSKY_HAS_PLAYED_OLD_GAME_H

View File

@ -1,9 +0,0 @@
#ifndef PMDSKY_PERFORMANCE_PROGRESS_H
#define PMDSKY_PERFORMANCE_PROGRESS_H
#include "util.h"
bool8 GetResolvedPerformanceProgressFlag(u32 idx);
void SetResolvedPerformanceProgressFlag(u32 idx, s32 value);
#endif //PMDSKY_PERFORMANCE_PROGRESS_H

View File

@ -1,6 +1,11 @@
#ifndef PMDSKY_MAIN_0204CB94_H
#define PMDSKY_MAIN_0204CB94_H
#ifndef PMDSKY_PROGRESSION_H
#define PMDSKY_PROGRESSION_H
#include "util.h"
bool8 HasPlayedOldGame();
bool8 GetResolvedPerformanceProgressFlag(u32 idx);
void SetResolvedPerformanceProgressFlag(u32 idx, s32 value);
// Returns the current SCENARIO_BALANCE value.
// The exact value returned depends on multiple factors:
// - If the first special episode is active, returns 1
@ -9,4 +14,4 @@
// - In all other cases, the value of the SCENARIO_BALANCE_FLAG variable is returned
u8 GetScenarioBalance();
#endif //PMDSKY_MAIN_0204CB94_H
#endif //PMDSKY_PROGRESSION_H

View File

@ -29,6 +29,7 @@ struct script_var_raw {
union script_var_value *value;
};
void ZinitScriptVariable(union script_var_value sv_locals[], enum script_var_id sv_id);
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);

View File

@ -88,9 +88,7 @@ Static main
Object asm/main_rodata_020A18BC.o
Object src/story_progress.o
Object src/special_episode.o
Object src/has_played_old_game.o
Object src/performance_progress.o
Object src/main_0204CB94.o
Object src/progression.o
Object src/scenario_flag.o
Object asm/main_0204CD88.o
Object src/main_0204DA2C.o

View File

@ -8,11 +8,9 @@
#include "main_02058E68.h"
#include "overlay_29_022FF898.h"
#include "overlay_29_023000E4.h"
#include "performance_progress.h"
#include "progression.h"
#include "pokemon.h"
extern bool8 GetPerformanceFlagWithChecks(s32 flag_id);
bool8 CanSeeInvisibleMonsters(struct entity *entity)
{
if (GetEntInfo(entity)->blinker_class_status.blinded == STATUS_BLINKER_EYEDROPS)

View File

@ -5,7 +5,6 @@
#include "dungeon_pokemon_attributes_1.h"
#include "dungeon_recruitment.h"
#include "dungeon_recruitment_2.h"
#include "has_played_old_game.h"
#include "dg_random.h"
#include "dungeon_visibility.h"
#include "enums.h"
@ -14,6 +13,7 @@
#include "main_0208655C.h"
#include "math.h"
#include "overlay_29_0230E578.h" // ItemIsActive__0230E578
#include "progression.h"
extern bool8 IsLegendaryChallengeFloor(void);
extern bool8 IsCurrentMissionTypeExact(u32 mission_type, u32 mission_subtype);

View File

@ -1,13 +0,0 @@
#include "has_played_old_game.h"
#include "enums.h"
#include "script_variable.h"
#include "util.h"
bool8 HasPlayedOldGame()
{
if(LoadScriptVariableValue(0, VAR_PLAY_OLD_GAME)) {
return TRUE;
} else {
return FALSE;
}
}

View File

@ -1,8 +1,7 @@
#include "main_0200EDC0.h"
#include "item.h"
#include "main_0204CB94.h"
#include "main_020517D4.h"
#include "performance_progress.h"
#include "progression.h"
#include "script_variable.h"
#include "special_episode.h"

View File

@ -1,19 +0,0 @@
#include "main_0204CB94.h"
#include "script_variable.h"
u8 GetScenarioBalance()
{
s32 special_episode_type = LoadScriptVariableValue(0, VAR_EXECUTE_SPECIAL_EPISODE_TYPE);
if (special_episode_type == EPISODE_NONE)
{
s32 scenario_balance = LoadScriptVariableValue(0, VAR_SCENARIO_BALANCE_DEBUG);
if (scenario_balance < 0)
scenario_balance = LoadScriptVariableValue(0, VAR_SCENARIO_BALANCE_FLAG);
return scenario_balance;
}
if (special_episode_type == EPISODE_BIDOOFS_WISH)
return 1;
return 3;
}

View File

@ -1,9 +1,18 @@
#include "enums.h"
#include "performance_progress.h"
#include "progression.h"
#include "script_variable.h"
extern enum game_mode GetGameMode();
bool8 HasPlayedOldGame()
{
if(LoadScriptVariableValue(0, VAR_PLAY_OLD_GAME)) {
return TRUE;
} else {
return FALSE;
}
}
bool8 GetResolvedPerformanceProgressFlag(u32 idx) {
switch (idx) {
case 0:
@ -55,3 +64,20 @@ void SetResolvedPerformanceProgressFlag(u32 idx, s32 value) {
return;
}
}
u8 GetScenarioBalance()
{
s32 special_episode_type = LoadScriptVariableValue(0, VAR_EXECUTE_SPECIAL_EPISODE_TYPE);
if (special_episode_type == EPISODE_NONE)
{
s32 scenario_balance = LoadScriptVariableValue(0, VAR_SCENARIO_BALANCE_DEBUG);
if (scenario_balance < 0)
scenario_balance = LoadScriptVariableValue(0, VAR_SCENARIO_BALANCE_FLAG);
return scenario_balance;
}
if (special_episode_type == EPISODE_BIDOOFS_WISH)
return 1;
return 3;
}

View File

@ -8,7 +8,7 @@
#include "special_episode.h"
#include "story_progress.h"
#define LOCAL_SCRIPT_VAR_OFFSET 0x400
#define LOCAL_SCRIPT_VAR_OFFSET (s16) 0x400
// Global script variable definitions
extern struct script_var_def SCRIPT_VARS[];
@ -39,7 +39,20 @@ extern s32 AddMoneyCarried(s32 arg0);
extern s32 SetMoneyCarried(s32 arg0);
extern s32 SetMoneyStored(s32 arg0);
extern s32 SetNotifyNote(s32 arg0);
extern void ZinitScriptVariable(u32 param_1, u32 param_2);
void ZinitScriptVariable(union script_var_value sv_locals[], enum script_var_id sv_id) {
struct script_var_def* def;
if (sv_id < LOCAL_SCRIPT_VAR_OFFSET) {
def = &SCRIPT_VARS[sv_id];
} else {
def = &SCRIPT_VARS_LOCALS[sv_id - LOCAL_SCRIPT_VAR_OFFSET];
}
for(u16 idx = 0; idx < def->n_values; idx++) {
SaveScriptVariableValueAtIndex(sv_locals, sv_id, idx, 0);
}
}
void LoadScriptVariableRaw(struct script_var_raw* sv_raw,
union script_var_value sv_val_local[],