Skip to content

Commit 0a33b81

Browse files
Add some missing Savemap fields, introduce fix_structs script (#15)
This PR does several things: 1. Renames `_work` to `Savemap` and fills in some missing fields in the struct 2. Adds a `--fix-structs` optional flag (can make it enabled by default later if you see value in it) that will automatically fix references to Savemap in the decompiled code I've tested this on two world functions as a demonstraction of the above flag. This is what the script outputs (no manual adjustment necessary) ```c void func_800B77F4(s32 arg0) { Savemap.countdown_timer_seconds = arg0; D_80116278 = 1; Savemap.memory_bank_1[95] = 1; } void func_800B7820(void) { D_80116278 = 0; Savemap.memory_bank_1[95] = 0; } ``` I've tried to bundle this with this PR but the build was failing with checksum errors, I don't know how to fix it though 🙂
1 parent 9716fca commit 0a33b81

13 files changed

Lines changed: 239 additions & 55 deletions

File tree

config/sym_extern.us.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
D_8009A000 = 0x8009A000;
22
D_8009A004 = 0x8009A004;
33
D_8009A008 = 0x8009A008;
4-
_work = 0x8009C6E4;
4+
Savemap = 0x8009C6E4;
55
func_800A0000 = 0x800A0000;
66
func_800A0030 = 0x800A0030;
77
func_800A00BC = 0x800A00BC;

config/sym_ovl_export.us.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,7 @@ func_801D3668 = 0x801d3668;
20312031
func_801D3698 = 0x801d3698;
20322032
func_801D370C = 0x801d370c;
20332033
func_801D4CC0 = 0x801d4cc0;
2034+
g_MenuStartMode = 0x801e2cf8;
20342035
menus = 0x801e379c;
20352036
func_800A0B48 = 0x800a0b48;
20362037
func_800A0BE4 = 0x800a0be4;

include/game.h

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,14 @@ typedef union {
7474
typedef struct {
7575
u32 checksum;
7676
u8 leader_level;
77-
u8 party[3];
77+
u8 leader_portrait;
78+
u8 portrait2;
79+
u8 portrait3;
7880
s8 leader_name[0x10];
79-
s32 unk18;
80-
s32 unk1C;
81+
u16 leader_hp;
82+
u16 leader_hp_max;
83+
u16 leader_mp;
84+
u16 leader_mp_max;
8185
s32 gil;
8286
s32 time;
8387
s8 place_name[0x20];
@@ -132,23 +136,32 @@ typedef struct {
132136
/* 0x4F8 */ u8 partyID[4];
133137
/* 0x4FC */ u16 inventory[MAX_INVENTORY_COUNT];
134138
/* 0x77C */ s32 materia[MAX_MATERIA_COUNT];
135-
/* 0xA9C */ u8 unkA9C[0xE0];
139+
/* 0xA9C */ s32 yuffie_stolen_materia[48];
140+
/* 0xB5C */ u8 unk_b5c[32];
136141
/* 0xB7C */ s32 gil;
137142
/* 0xB80 */ s32 time;
138-
/* 0xB84 */ u8 D_8009D268[0x20];
139-
/* 0xBA4 */ u8 D_8009D288[0x18];
140-
/* 0xBBC */ u16 D_8009D2A0;
141-
/* 0xBBE */ u8 D_8009D2A2;
142-
/* 0xBBF */ u8 D_8009D2A3;
143-
/* 0xBC0 */ u8 unkBC0[0x10];
144-
/* 0xBD0 */ u8 unkBD0[0x10];
145-
/* 0xBE0 */ u8 unkBE0[15];
146-
/* 0xBEF */ u8 unkBEF;
147-
/* 0xBF0 */ u8 unkBF0[0x420];
148-
/* 0x1010 */ u16 unk1010;
149-
/* 0x1012 */ u8 unk1012;
150-
/* 0x1013 */ u8 unk1013;
151-
/* 0x1014 */ u8 unk1014[0xC4];
143+
/* 0xB84 */ s32 countdown_timer_seconds;
144+
/* 0xB88 */ s32 game_timer_fraction;
145+
/* 0xB8C */ s32 countdown_timer_fraction;
146+
/* 0xB90 */ s32 worldmap_exit_action;
147+
/* 0xB94 */ u16 current_module;
148+
/* 0xB96 */ u16 current_location_id;
149+
/* 0xB98 */ u16 padding2;
150+
/* 0xB9A */ s16 field_x;
151+
/* 0xB9C */ s16 field_y;
152+
/* 0xB9E */ u16 field_triangle;
153+
/* 0xBA0 */ u8 field_direction;
154+
/* 0xBA1 */ u8 step_id;
155+
/* 0xBA2 */ u8 step_offset;
156+
/* 0xBA3 */ u8 padding3;
157+
/* 0xBA4 */ u8 memory_bank_1[256];
158+
/* 0xCA4 */ u8 memory_bank_2[256];
159+
/* 0xDA4 */ u8 memory_bank_3[256];
160+
/* 0xEA4 */ u8 memory_bank_4[256];
161+
/* 0xFA4 */ u8 memory_bank_5[256];
162+
/* 0x10A4 */ u16 phs_locking_mask;
163+
/* 0x10A6 */ u16 phs_visibility_mask;
164+
/* 0x10A8 */ u8 unk_10a8[48];
152165
/* 0x10D8 */ u8 battle_speed;
153166
/* 0x10D9 */ u8 battle_msg_speed;
154167
/* 0x10DA */ u16 config;
@@ -299,7 +312,7 @@ extern s16 D_8009A000;
299312
extern s32 D_8009A004;
300313
extern s32 D_8009A008;
301314
extern s32 D_8009A024[8];
302-
extern SaveWork _work; // 0x8009C6E4
315+
extern SaveWork Savemap; // 0x8009C6E4
303316
extern u8 D_8009CBDC[];
304317
extern u8 D_8009D684;
305318
extern u8 D_8009D686;

src/battle/battle.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,8 @@ void func_800AE078(void) {}
766766
INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800AE080);
767767

768768
void func_800AE234(void) {
769-
D_80063014->unk214 = _work.D_8009D2A2 + _work.D_8009D2A3 * 256;
769+
D_80063014->unk214 =
770+
Savemap.memory_bank_1[26] + Savemap.memory_bank_1[27] * 256;
770771
}
771772

772773
INCLUDE_ASM("asm/us/battle/nonmatchings/battle", func_800AE25C);
@@ -962,10 +963,10 @@ s32 func_800B2C60(s32 arg0) {
962963
static void func_800B2CAC(s32 arg0, s32 arg1) {
963964
switch (arg0) {
964965
case 0:
965-
D_800F83A6 = _work.D_8009D288[arg1];
966+
D_800F83A6 = Savemap.memory_bank_1[arg1];
966967
return;
967968
case 1:
968-
_work.D_8009D288[arg1] = D_800F83A6;
969+
Savemap.memory_bank_1[arg1] = D_800F83A6;
969970
return;
970971
}
971972
}

src/battle/battle1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800C5CC0);
390390

391391
INCLUDE_ASM("asm/us/battle/nonmatchings/battle1", func_800C5E94);
392392

393-
s32 func_800C60F4(void) { return _work.battle_msg_speed / 4 + 4; }
393+
s32 func_800C60F4(void) { return Savemap.battle_msg_speed / 4 + 4; }
394394

395395
static void func_800C610C(void) {
396396
while (D_801518DC) {

src/main/18B8.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,13 +1409,13 @@ INCLUDE_ASM("asm/us/main/nonmatchings/18B8", func_80025380);
14091409
s32 func_8002542C(s32 arg0) {
14101410
s32 i;
14111411
for (i = 0; i < MAX_MATERIA_COUNT; i++) {
1412-
if (_work.materia[i] == -1) {
1413-
_work.materia[i] = arg0;
1412+
if (Savemap.materia[i] == -1) {
1413+
Savemap.materia[i] = arg0;
14141414
if (func_8002603C(arg0 & 0xFF) == 10) {
1415-
_work.unkBEF |= 1;
1415+
Savemap.memory_bank_1[75] |= 1;
14161416
}
14171417
if ((arg0 & 0xFF) == 44) {
1418-
_work.unkBEF |= 2;
1418+
Savemap.memory_bank_1[75] |= 2;
14191419
}
14201420
return -1;
14211421
}
@@ -1451,7 +1451,7 @@ Unk8009D84C* func_80025788(s32 arg0) {
14511451
Unk8009D84C* partyMember;
14521452

14531453
partyMember = (Unk8009D84C*)0xFF;
1454-
if (_work.partyID[arg0] != 0xFF) {
1454+
if (Savemap.partyID[arg0] != 0xFF) {
14551455
return &D_8009D84C[arg0];
14561456
}
14571457
return 0xFF;
@@ -1474,7 +1474,7 @@ INCLUDE_ASM("asm/us/main/nonmatchings/18B8", func_80025B10);
14741474

14751475
INCLUDE_ASM("asm/us/main/nonmatchings/18B8", func_80025B48);
14761476

1477-
s32 SYS_gil(void) { return _work.gil; }
1477+
s32 SYS_gil(void) { return Savemap.gil; }
14781478

14791479
void func_80025B8C(u_long* image) {
14801480
RECT rect;

src/menu/bginmenu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ static void func_801D01BC(void) {}
5252
INCLUDE_ASM("asm/us/menu/nonmatchings/bginmenu", func_801D01C4);
5353
#else
5454
// -O1
55-
extern u8 D_8009C778[]; // _work.party
56-
extern u8 D_8009C798[]; // _work.party
55+
extern u8 D_8009C778[]; // Savemap.party
56+
extern u8 D_8009C798[]; // Savemap.party
5757
s32 func_801D01C4(s32 arg0) {
5858
s32 var_a1;
5959
s32 var_a2;
@@ -103,7 +103,7 @@ INCLUDE_ASM("asm/us/menu/nonmatchings/bginmenu", func_801D0500);
103103
void func_801D05C4(s32 arg0) {
104104
s32 i;
105105

106-
_work.unk1013 = 0;
106+
Savemap.memory_bank_5[111] = 0;
107107
switch (arg0) {
108108
case 0:
109109
for (i = 0; i < 21; i++) {
@@ -134,7 +134,7 @@ void func_801D05C4(s32 arg0) {
134134
}
135135
break;
136136
}
137-
_work.unk1013 = 1;
137+
Savemap.memory_bank_5[111] = 1;
138138
}
139139

140140
void func_801D0704(s32 arg0) {

src/menu/cnfgmenu.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,31 +172,31 @@ static void func_801D01C8(void) {
172172
func_80026F44(40, y + (i - 1) * 18, D_801D1AE8[33], 5);
173173
for (i = 0; i < 2; i++) {
174174
func_80026F44(165 + i * 65, y, D_801D1AE8[15 + i],
175-
-((_work.config & 3) == i) & 7);
175+
-((Savemap.config & 3) == i) & 7);
176176
}
177177
for (i = 0; i < 2; i++) {
178178
func_80026F44(165 + i * 65, y + 18, D_801D1E48[i],
179-
-(((_work.config >> 2) & 3) == i) & 7);
179+
-(((Savemap.config >> 2) & 3) == i) & 7);
180180
}
181181
for (i = 0; i < 2; i++) {
182182
func_80026F44(165 + i * 65, y + 0x24, D_801D1EA8[i],
183-
-(((_work.config >> 4) & 3) == i) & 7);
183+
-(((Savemap.config >> 4) & 3) == i) & 7);
184184
}
185185
temp_s4 = y + 54;
186186
func_80026F44(
187-
165, temp_s4, D_801D1F08[0], -(((_work.config >> 6) & 3) == 0) & 7);
187+
165, temp_s4, D_801D1F08[0], -(((Savemap.config >> 6) & 3) == 0) & 7);
188188
x = func_80026B70(D_801D1F08[0]);
189-
func_80026F44(
190-
x + 175, temp_s4, D_801D1F08[1], -(((_work.config >> 6) & 3) == 1) & 7);
189+
func_80026F44(x + 175, temp_s4, D_801D1F08[1],
190+
-(((Savemap.config >> 6) & 3) == 1) & 7);
191191
func_80026F44(x + func_80026B70(D_801D1F08[1]) + 185, temp_s4,
192-
D_801D1F08[2], -(((_work.config >> 6) & 3) == 2) & 7);
192+
D_801D1F08[2], -(((Savemap.config >> 6) & 3) == 2) & 7);
193193
for (i = 0; i < 2; i++) {
194194
func_80026F44(165 + i * 65, y + 126, D_801D1F08[3 + i],
195-
-(((_work.config >> 8) & 3) == i) & 7);
195+
-(((Savemap.config >> 8) & 3) == i) & 7);
196196
}
197197
for (i = 0; i < 3; i++) {
198-
_setting = D_801D248C[((_work.config >> 10) & 7) * 3 + i];
199-
setting = &D_801D248C[((_work.config >> 10) & 7) * 3];
198+
_setting = D_801D248C[((Savemap.config >> 10) & 7) * 3 + i];
199+
setting = &D_801D248C[((Savemap.config >> 10) & 7) * 3];
200200
func_80026F44(189 + i * 52, y + 0x90, D_801D1F08[12 + setting[i]], 7);
201201
}
202202
func_80026F44(149, y + 0x90, D_801D1F08[16], 7);
@@ -205,21 +205,21 @@ static void func_801D01C8(void) {
205205
rect.y = y + 72;
206206
rect.w = 8;
207207
rect.h = 11;
208-
rect.x = (_work.battle_speed >> 1) + 184;
208+
rect.x = (Savemap.battle_speed >> 1) + 184;
209209
func_80028030(&rect);
210210

211211
// battle message speed value
212212
rect.y = y + 0x5A;
213213
rect.w = 8;
214214
rect.h = 11;
215-
rect.x = (_work.battle_msg_speed >> 1) + 184;
215+
rect.x = (Savemap.battle_msg_speed >> 1) + 184;
216216
func_80028030(&rect);
217217

218218
// field message speed value
219219
rect.y = y + 108;
220220
rect.w = 8;
221221
rect.h = 11;
222-
rect.x = (_work.field_msg_speed >> 1) + 184;
222+
rect.x = (Savemap.field_msg_speed >> 1) + 184;
223223
func_80028030(&rect);
224224

225225
// speed values
@@ -238,7 +238,7 @@ static void func_801D01C8(void) {
238238
}
239239

240240
// magic order ID
241-
func_80029114(173, y + 146, ((_work.config >> 0xA) & 7) + 1, 1, 7);
241+
func_80029114(173, y + 146, ((Savemap.config >> 0xA) & 7) + 1, 1, 7);
242242

243243
rect.x = 0;
244244
rect.y = 0;

src/menu/savemenu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ INCLUDE_ASM("asm/us/menu/nonmatchings/savemenu", func_801D224C);
602602

603603
INCLUDE_ASM("asm/us/menu/nonmatchings/savemenu", func_801D2408);
604604

605-
static const char* D_801E2CB8[] = {
605+
const char* D_801E2CB8[] = {
606606
"FF7/SAVE01/00:00", "FF7/SAVE02/00:00",
607607
"FF7/SAVE03/00:00", "FF7/SAVE04/00:00",
608608
"FF7/SAVE05/00:00", "FF7/SAVE06/00:00",
@@ -627,7 +627,7 @@ static s16 func_801D2A34(s32 save_id) {
627627
D_801E3D50 = slot;
628628
ret = func_801D2408(&sp10, D_801E2CB8[slot]);
629629
if (!(s16)ret) {
630-
memcpy(&D_801E3864[slot], &_work.header, sizeof(SaveHeader));
630+
memcpy(&D_801E3864[slot], &Savemap.header, sizeof(SaveHeader));
631631
}
632632
return ret;
633633
}

src/menu/title.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,16 +499,16 @@ static s32 func_801D3AB0(s32 arg0) {
499499
}
500500
var_s1 = (s16)func_801D1F40(var_a0_3);
501501
if (var_s1 == 0) {
502-
if (_work.header.checksum !=
502+
if (Savemap.header.checksum !=
503503
(u16)func_801D1950(
504-
sizeof(SaveWork) - 4, &_work.header.leader_level)) {
504+
sizeof(SaveWork) - 4, &Savemap.header.leader_level)) {
505505
g_MenuStartMode = START_MENU_MODE_SELECT_FILE;
506506
func_801D2B58(3);
507507
func_8001F6C0(D_801E2CFC[31], 0);
508508
} else {
509509
func_801D2B58(0xD0);
510510
D_801E3D54 = 2;
511-
func_801D2D10(_work.config & 3);
511+
func_801D2D10(Savemap.config & 3);
512512
}
513513
} else {
514514
g_MenuStartMode = START_MENU_MODE_SELECT_FILE;
@@ -615,7 +615,7 @@ s32 func_801D4CC0(void) {
615615
PutDispEnv(&D_801E3EEC[1]);
616616
PutDrawEnv(&D_801E3E34[1]);
617617
for (i = 0; i < 3; i++) {
618-
if (_work.partyID[i] != 0xFF) {
618+
if (Savemap.partyID[i] != 0xFF) {
619619
func_80020058(i);
620620
func_8001786C((u8)i);
621621
}

0 commit comments

Comments
 (0)