Skip to content

Commit 8c38b81

Browse files
author
slaw-22
committed
Decomp SaveScriptVariableValueBytes and ScriptVariablesEqual
1 parent 3e51dd9 commit 8c38b81

File tree

5 files changed

+43
-75
lines changed

5 files changed

+43
-75
lines changed
File renamed without changes.

asm/main_0204BBCC.s renamed to asm/main_0204BCAC.s

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,8 @@
11
.include "asm/macros.inc"
2-
.include "main_0204BBCC.inc"
2+
.include "main_0204BCAC.inc"
33

44
.text
55

6-
arm_func_start SaveScriptVariableValueBytes
7-
SaveScriptVariableValueBytes: ; 0x0204BBCC
8-
stmdb sp!, {r3, r4, r5, lr}
9-
sub sp, sp, #8
10-
mov r3, r0
11-
mov r5, r1
12-
mov r4, r2
13-
add r0, sp, #0
14-
mov r2, r3
15-
mov r1, #0
16-
bl LoadScriptVariableRaw
17-
ldr r2, [sp, #4]
18-
mov r1, #0
19-
b _0204BC08
20-
_0204BBFC:
21-
ldrb r0, [r5], #1
22-
add r1, r1, #1
23-
strb r0, [r2], #1
24-
_0204BC08:
25-
cmp r1, r4
26-
blt _0204BBFC
27-
add sp, sp, #8
28-
ldmia sp!, {r3, r4, r5, pc}
29-
arm_func_end SaveScriptVariableValueBytes
30-
31-
arm_func_start ScriptVariablesEqual
32-
ScriptVariablesEqual: ; 0x0204BC18
33-
stmdb sp!, {r3, r4, r5, r6, r7, r8, sb, lr}
34-
sub sp, sp, #0x10
35-
mov r8, r0
36-
mov r7, r1
37-
mov r6, r2
38-
add r0, sp, #8
39-
mov r1, r8
40-
mov r2, r7
41-
bl LoadScriptVariableRaw
42-
add r0, sp, #0
43-
mov r1, r8
44-
mov r2, r6
45-
bl LoadScriptVariableRaw
46-
ldr r0, [sp, #8]
47-
mov r5, #0
48-
ldrsh r4, [r0, #8]
49-
b _0204BC98
50-
_0204BC5C:
51-
mov r2, r5, lsl #0x10
52-
mov r0, r8
53-
mov r1, r7
54-
mov r2, r2, lsr #0x10
55-
bl LoadScriptVariableValueAtIndex
56-
mov r2, r5, lsl #0x10
57-
mov sb, r0
58-
mov r0, r8
59-
mov r1, r6
60-
mov r2, r2, lsr #0x10
61-
bl LoadScriptVariableValueAtIndex
62-
cmp sb, r0
63-
movne r0, #0
64-
bne _0204BCA4
65-
add r5, r5, #1
66-
_0204BC98:
67-
cmp r5, r4
68-
blt _0204BC5C
69-
mov r0, #1
70-
_0204BCA4:
71-
add sp, sp, #0x10
72-
ldmia sp!, {r3, r4, r5, r6, r7, r8, sb, pc}
73-
arm_func_end ScriptVariablesEqual
74-
756
arm_func_start sub_0204BCAC
767
sub_0204BCAC: ; 0x0204BCAC
778
stmdb sp!, {r3, lr}

include/scripting.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct script_var_def {
1010
// 0x4: value's offset into struct script_var_value_table, if type != VARTYPE_SPECIAL
1111
s16 mem_offset;
1212
s16 bitshift; // 0x6: bit position if type == VARTYPE_BIT
13-
u16 n_values; // 0x8: number of values (>1 means this variable is an array)
13+
s16 n_values; // 0x8: number of values (>1 means this variable is an array)
1414
// 0xA: 0 for every variable except VAR_VERSION, which has a default value of 1.
1515
s16 default_val;
1616
char* name; // 0xC: variable name
@@ -33,11 +33,13 @@ extern const short LOCAL_SCRIPT_VAR_OFFSET;
3333

3434
void LoadScriptVariableRaw(struct script_var_raw* sv_raw, union script_var_value sv_val_local[], const enum script_var_id sv_id);
3535
s32 LoadScriptVariableValue(union script_var_value sv_local[], enum script_var_id sv_id);
36-
s32 LoadScriptVariableValueAtIndex(union script_var_value sv_local[], enum script_var_id id, int idx);
36+
s32 LoadScriptVariableValueAtIndex(union script_var_value sv_local[], enum script_var_id id, u16 idx);
3737
void SaveScriptVariableValue(union script_var_value sv_locals[], const enum script_var_id script_var_id, u32 new_val);
3838
void SaveScriptVariableValueAtIndex(union script_var_value sv_locals[], const enum script_var_id script_var_id, int idx, s32 new_val);
3939
s32 LoadScriptVariableValueSum(union script_var_value sv_local[], const enum script_var_id sv_id);
4040
void LoadScriptVariableValueBytes(const enum script_var_id sv_id, u8* result, s32 num_bytes);
4141
void LoadScriptVariableValueString(const enum script_var_id sv_id, u8* result, u8 num_bytes);
42+
void SaveScriptVariableValueBytes(const enum script_var_id sv_id, u8* result, s32 num_bytes);
43+
s32 ScriptVariablesEqual(union script_var_value sv_val_ptr_local[], enum script_var_id sv_id_1, enum script_var_id sv_id_2);
4244

4345
#endif //PMDSKY_SCRIPTING_H

main.lsf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Static main
8181
Object src/main_0204AFF8.o
8282
Object asm/main_0204B018.o
8383
Object src/scripting.o
84-
Object asm/main_0204BBCC.o
84+
Object asm/main_0204BCAC.o
8585
Object src/main_0204C938.o
8686
Object asm/main_0204C94C.o
8787
Object src/dungeon_recruitment_3.o

src/scripting.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ s32 LoadScriptVariableValue(union script_var_value sv_local[], enum script_var_i
9797
return 0;
9898
}
9999

100-
s32 LoadScriptVariableValueAtIndex(union script_var_value sv_local[], enum script_var_id id, int idx)
100+
s32 LoadScriptVariableValueAtIndex(union script_var_value sv_local[], enum script_var_id id, u16 idx)
101101
{
102102
struct script_var_raw result;
103103
LoadScriptVariableRaw(&result, sv_local, id);
@@ -309,7 +309,7 @@ void LoadScriptVariableValueBytes(const enum script_var_id sv_id, u8* result, s3
309309

310310
s32 i = 0;
311311
u8* val_ptr = (u8*) sv_raw.value;
312-
312+
313313
for(i = 0; i < num_bytes; i++) {
314314
u8 val = *val_ptr;
315315
*result = val;
@@ -323,3 +323,38 @@ void LoadScriptVariableValueString(const enum script_var_id sv_id, u8* result, u
323323
LoadScriptVariableValueBytes(sv_id, result, num_bytes);
324324
result[num_bytes] = 0;
325325
}
326+
327+
void SaveScriptVariableValueBytes(const enum script_var_id sv_id, u8* result, s32 num_bytes)
328+
{
329+
struct script_var_raw sv_raw;
330+
LoadScriptVariableRaw(&sv_raw, 0, sv_id);
331+
332+
s32 i = 0;
333+
u8* val_ptr = (u8*) sv_raw.value;
334+
335+
for(i = 0; i < num_bytes; i++) {
336+
u8 val = *result;
337+
*val_ptr = val;
338+
val_ptr += 1;
339+
result += 1;
340+
}
341+
}
342+
343+
s32 ScriptVariablesEqual(union script_var_value sv_val_ptr_local[], enum script_var_id sv_id_1, enum script_var_id sv_id_2)
344+
{
345+
struct script_var_raw script_var_raw_1, script_var_raw_2;
346+
347+
LoadScriptVariableRaw(&script_var_raw_1, sv_val_ptr_local, sv_id_1);
348+
LoadScriptVariableRaw(&script_var_raw_2, sv_val_ptr_local, sv_id_2);
349+
350+
s32 n_values = script_var_raw_1.def->n_values;
351+
352+
for(int idx = 0; idx < n_values; idx++) {
353+
if (LoadScriptVariableValueAtIndex(sv_val_ptr_local, sv_id_1, idx) !=
354+
LoadScriptVariableValueAtIndex(sv_val_ptr_local, sv_id_2, idx)) {
355+
return 0;
356+
}
357+
}
358+
359+
return 1;
360+
}

0 commit comments

Comments
 (0)