Skip to content

Commit 5d9fa19

Browse files
committed
Improve Pokémon HGSS AP-fix apply code to account for some ROM hacks
1 parent d8987b9 commit 5d9fa19

File tree

4 files changed

+78
-124
lines changed

4 files changed

+78
-124
lines changed

retail/bootloader/source/arm7/asm_apfix.s

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
.arm
44
.global ie3OgreOverlayApFix
55
.global hgssJpnOverlayApFix
6-
.global hgssEngOverlayApFix
7-
.global hgFreOverlayApFix
8-
.global ssFreOverlayApFix
6+
.global hgssIntOverlayApFix
97
.global hgssKorOverlayApFix
108
.global saga2OverlayApFix
119
@---------------------------------------------------------------------------------
@@ -68,9 +66,16 @@ hgssJpnOverlayApFix: @ overlay9_1 + overlay9_122
6866
mov r2, #0x53
6967
cmp r2, r1
7068
bne hgssJpnOverlayApFix_check122
71-
ldrb r1, [r0, #3]
69+
ldrb r1, [r0, #2]
7270
mov r2, #0xD1
7371
cmp r2, r1
72+
bne hgssJpnOverlayApFix_check3
73+
mov r2, #0xE0
74+
strb r2, [r0, #2]
75+
b hgssJpnOverlayApFix_check122
76+
hgssJpnOverlayApFix_check3:
77+
ldrb r1, [r0, #3]
78+
cmp r2, r1
7479
bne hgssJpnOverlayApFix_check122
7580
mov r2, #0xE0
7681
strb r2, [r0, #3]
@@ -91,59 +96,43 @@ hgssJpnOverlayApFix_check122:
9196
bx lr
9297
.pool
9398
@---------------------------------------------------------------------------------
94-
hgssEngOverlayApFix: @ overlay9_1
95-
ldr r0, =0x021E5900+0x219
99+
hgssIntOverlayApFix: @ overlay9_1
100+
ldr r0, =0x021E5900+0x219 @ Offset varies by language
96101
ldrb r1, [r0]
97102
mov r2, #0x28
98103
cmp r2, r1
99104
bxne lr
100105
ldrb r1, [r0, #2]
101106
mov r2, #0xD1
102107
cmp r2, r1
103-
bxne lr
108+
bne hgssIntOverlayApFix_check3
104109
mov r2, #0xE0
105110
strb r2, [r0, #2]
106111
bx lr
107-
.pool
108-
@---------------------------------------------------------------------------------
109-
hgFreOverlayApFix: @ overlay9_1
110-
ldr r0, =0x021E5920+0x217
111-
ldrb r1, [r0]
112-
mov r2, #0x28
113-
cmp r2, r1
114-
bxne lr
112+
hgssIntOverlayApFix_check3:
115113
ldrb r1, [r0, #3]
116-
mov r2, #0xD1
117114
cmp r2, r1
118115
bxne lr
119116
mov r2, #0xE0
120117
strb r2, [r0, #3]
121118
bx lr
122119
.pool
123120
@---------------------------------------------------------------------------------
124-
ssFreOverlayApFix: @ overlay9_1
125-
ldr r0, =0x021E5920+0x218
121+
hgssKorOverlayApFix: @ overlay9_1
122+
ldr r0, =0x021E6300+0x213 @ add 3 for SS
126123
ldrb r1, [r0]
127-
mov r2, #0x28
124+
mov r2, #0x5B
128125
cmp r2, r1
129126
bxne lr
130127
ldrb r1, [r0, #2]
131128
mov r2, #0xD1
132129
cmp r2, r1
133-
bxne lr
130+
bne hgssKorOverlayApFix_check3
134131
mov r2, #0xE0
135132
strb r2, [r0, #2]
136133
bx lr
137-
.pool
138-
@---------------------------------------------------------------------------------
139-
hgssKorOverlayApFix: @ overlay9_1
140-
ldr r0, =0x021E6300+0x213 @ add 3 for SS
141-
ldrb r1, [r0]
142-
mov r2, #0x5B
143-
cmp r2, r1
144-
bxne lr
134+
hgssKorOverlayApFix_check3:
145135
ldrb r1, [r0, #3]
146-
mov r2, #0xD1
147136
cmp r2, r1
148137
bxne lr
149138
mov r2, #0xE0

retail/bootloader/source/arm7/patch_arm9.c

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -174,44 +174,32 @@ static bool patchCardRead(cardengineArm9* ce9, const tNDSHeader* ndsHeader, cons
174174

175175
if (romTid[3] == 'J') {
176176
extern u32 hgssJpnOverlayApFix[];
177-
tonccpy(postCardReadCode, hgssJpnOverlayApFix, 29*4);
178-
} else if (romTid[3] == 'E') {
179-
extern u32 hgssEngOverlayApFix[];
180-
tonccpy(postCardReadCode, hgssEngOverlayApFix, 13*4);
181-
} else if (romTid[3] == 'F') {
182-
if (romTid[2] == 'K') {
183-
extern u32 hgFreOverlayApFix[];
184-
tonccpy(postCardReadCode, hgFreOverlayApFix, 13*4);
185-
} else {
186-
extern u32 ssFreOverlayApFix[];
187-
tonccpy(postCardReadCode, ssFreOverlayApFix, 13*4);
188-
}
189-
} else if (romTid[3] == 'D') {
190-
extern u32 ssFreOverlayApFix[];
191-
tonccpy(postCardReadCode, ssFreOverlayApFix, 13*4);
192-
postCardReadCode[12] -= 0x40;
193-
} else if (romTid[3] == 'I') {
194-
extern u32 ssFreOverlayApFix[];
195-
tonccpy(postCardReadCode, ssFreOverlayApFix, 13*4);
196-
postCardReadCode[12] -= 0x80;
197-
} else if (romTid[3] == 'S') {
198-
if (romTid[2] == 'K') {
199-
extern u32 hgFreOverlayApFix[];
200-
tonccpy(postCardReadCode, hgFreOverlayApFix, 13*4);
201-
postCardReadCode[12]++;
202-
} else {
203-
extern u32 ssFreOverlayApFix[];
204-
tonccpy(postCardReadCode, ssFreOverlayApFix, 13*4);
205-
postCardReadCode[12] += 0x20;
206-
}
177+
tonccpy(postCardReadCode, hgssJpnOverlayApFix, 35*4);
207178
} else if (romTid[3] == 'K') {
208179
extern u32 hgssKorOverlayApFix[];
209-
tonccpy(postCardReadCode, hgssKorOverlayApFix, 13*4);
180+
tonccpy(postCardReadCode, hgssKorOverlayApFix, 19*4);
210181
if (romTid[2] == 'G') {
211-
postCardReadCode[12] += 3;
182+
postCardReadCode[18] += 3;
212183
}
213184
} else {
214-
postCardReadCodeOffset = 0;
185+
extern u32 hgssIntOverlayApFix[];
186+
tonccpy(postCardReadCode, hgssIntOverlayApFix, 19*4);
187+
if (romTid[3] == 'F') {
188+
postCardReadCode[18] = 0x021E5920+0x217;
189+
if (romTid[2] == 'G') {
190+
postCardReadCode[18]++;
191+
}
192+
} else if (romTid[3] == 'D') {
193+
postCardReadCode[18] = 0x021E58E0+0x218;
194+
} else if (romTid[3] == 'I') {
195+
postCardReadCode[18] = 0x021E58A0+0x219;
196+
} else if (romTid[3] == 'S') {
197+
if (romTid[2] == 'K') {
198+
postCardReadCode[18] = 0x021E5920+0x218;
199+
} else {
200+
postCardReadCode[18] = 0x021E5940+0x218;
201+
}
202+
}
215203
}
216204
} else if (strcmp(romTid, "CSGJ") == 0) {
217205
extern u32 saga2OverlayApFix[];

retail/bootloaderi/source/arm7/asm_apfix.s

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
.arm
44
.global ie3OgreOverlayApFix
55
.global hgssJpnOverlayApFix
6-
.global hgssEngOverlayApFix
7-
.global hgFreOverlayApFix
8-
.global ssFreOverlayApFix
6+
.global hgssIntOverlayApFix
97
.global hgssKorOverlayApFix
108
.global saga2OverlayApFix
119
@---------------------------------------------------------------------------------
@@ -68,9 +66,16 @@ hgssJpnOverlayApFix: @ overlay9_1 + overlay9_122
6866
mov r2, #0x53
6967
cmp r2, r1
7068
bne hgssJpnOverlayApFix_check122
71-
ldrb r1, [r0, #3]
69+
ldrb r1, [r0, #2]
7270
mov r2, #0xD1
7371
cmp r2, r1
72+
bne hgssJpnOverlayApFix_check3
73+
mov r2, #0xE0
74+
strb r2, [r0, #2]
75+
b hgssJpnOverlayApFix_check122
76+
hgssJpnOverlayApFix_check3:
77+
ldrb r1, [r0, #3]
78+
cmp r2, r1
7479
bne hgssJpnOverlayApFix_check122
7580
mov r2, #0xE0
7681
strb r2, [r0, #3]
@@ -91,59 +96,43 @@ hgssJpnOverlayApFix_check122:
9196
bx lr
9297
.pool
9398
@---------------------------------------------------------------------------------
94-
hgssEngOverlayApFix: @ overlay9_1
95-
ldr r0, =0x021E5900+0x219
99+
hgssIntOverlayApFix: @ overlay9_1
100+
ldr r0, =0x021E5900+0x219 @ Offset varies by language
96101
ldrb r1, [r0]
97102
mov r2, #0x28
98103
cmp r2, r1
99104
bxne lr
100105
ldrb r1, [r0, #2]
101106
mov r2, #0xD1
102107
cmp r2, r1
103-
bxne lr
108+
bne hgssIntOverlayApFix_check3
104109
mov r2, #0xE0
105110
strb r2, [r0, #2]
106111
bx lr
107-
.pool
108-
@---------------------------------------------------------------------------------
109-
hgFreOverlayApFix: @ overlay9_1
110-
ldr r0, =0x021E5920+0x217
111-
ldrb r1, [r0]
112-
mov r2, #0x28
113-
cmp r2, r1
114-
bxne lr
112+
hgssIntOverlayApFix_check3:
115113
ldrb r1, [r0, #3]
116-
mov r2, #0xD1
117114
cmp r2, r1
118115
bxne lr
119116
mov r2, #0xE0
120117
strb r2, [r0, #3]
121118
bx lr
122119
.pool
123120
@---------------------------------------------------------------------------------
124-
ssFreOverlayApFix: @ overlay9_1
125-
ldr r0, =0x021E5920+0x218
121+
hgssKorOverlayApFix: @ overlay9_1
122+
ldr r0, =0x021E6300+0x213 @ add 3 for SS
126123
ldrb r1, [r0]
127-
mov r2, #0x28
124+
mov r2, #0x5B
128125
cmp r2, r1
129126
bxne lr
130127
ldrb r1, [r0, #2]
131128
mov r2, #0xD1
132129
cmp r2, r1
133-
bxne lr
130+
bne hgssKorOverlayApFix_check3
134131
mov r2, #0xE0
135132
strb r2, [r0, #2]
136133
bx lr
137-
.pool
138-
@---------------------------------------------------------------------------------
139-
hgssKorOverlayApFix: @ overlay9_1
140-
ldr r0, =0x021E6300+0x213 @ add 3 for SS
141-
ldrb r1, [r0]
142-
mov r2, #0x5B
143-
cmp r2, r1
144-
bxne lr
134+
hgssKorOverlayApFix_check3:
145135
ldrb r1, [r0, #3]
146-
mov r2, #0xD1
147136
cmp r2, r1
148137
bxne lr
149138
mov r2, #0xE0

retail/bootloaderi/source/arm7/patch_arm9.c

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -313,44 +313,32 @@ static bool patchCardRead(cardengineArm9* ce9, const tNDSHeader* ndsHeader, cons
313313

314314
if (romTid[3] == 'J') {
315315
extern u32 hgssJpnOverlayApFix[];
316-
tonccpy(postCardReadCode, hgssJpnOverlayApFix, 29*4);
317-
} else if (romTid[3] == 'E') {
318-
extern u32 hgssEngOverlayApFix[];
319-
tonccpy(postCardReadCode, hgssEngOverlayApFix, 13*4);
320-
} else if (romTid[3] == 'F') {
321-
if (romTid[2] == 'K') {
322-
extern u32 hgFreOverlayApFix[];
323-
tonccpy(postCardReadCode, hgFreOverlayApFix, 13*4);
324-
} else {
325-
extern u32 ssFreOverlayApFix[];
326-
tonccpy(postCardReadCode, ssFreOverlayApFix, 13*4);
327-
}
328-
} else if (romTid[3] == 'D') {
329-
extern u32 ssFreOverlayApFix[];
330-
tonccpy(postCardReadCode, ssFreOverlayApFix, 13*4);
331-
postCardReadCode[12] -= 0x40;
332-
} else if (romTid[3] == 'I') {
333-
extern u32 ssFreOverlayApFix[];
334-
tonccpy(postCardReadCode, ssFreOverlayApFix, 13*4);
335-
postCardReadCode[12] -= 0x80;
336-
} else if (romTid[3] == 'S') {
337-
if (romTid[2] == 'K') {
338-
extern u32 hgFreOverlayApFix[];
339-
tonccpy(postCardReadCode, hgFreOverlayApFix, 13*4);
340-
postCardReadCode[12]++;
341-
} else {
342-
extern u32 ssFreOverlayApFix[];
343-
tonccpy(postCardReadCode, ssFreOverlayApFix, 13*4);
344-
postCardReadCode[12] += 0x20;
345-
}
316+
tonccpy(postCardReadCode, hgssJpnOverlayApFix, 35*4);
346317
} else if (romTid[3] == 'K') {
347318
extern u32 hgssKorOverlayApFix[];
348-
tonccpy(postCardReadCode, hgssKorOverlayApFix, 13*4);
319+
tonccpy(postCardReadCode, hgssKorOverlayApFix, 19*4);
349320
if (romTid[2] == 'G') {
350-
postCardReadCode[12] += 3;
321+
postCardReadCode[18] += 3;
351322
}
352323
} else {
353-
postCardReadCodeOffset = 0;
324+
extern u32 hgssIntOverlayApFix[];
325+
tonccpy(postCardReadCode, hgssIntOverlayApFix, 19*4);
326+
if (romTid[3] == 'F') {
327+
postCardReadCode[18] = 0x021E5920+0x217;
328+
if (romTid[2] == 'G') {
329+
postCardReadCode[18]++;
330+
}
331+
} else if (romTid[3] == 'D') {
332+
postCardReadCode[18] = 0x021E58E0+0x218;
333+
} else if (romTid[3] == 'I') {
334+
postCardReadCode[18] = 0x021E58A0+0x219;
335+
} else if (romTid[3] == 'S') {
336+
if (romTid[2] == 'K') {
337+
postCardReadCode[18] = 0x021E5920+0x218;
338+
} else {
339+
postCardReadCode[18] = 0x021E5940+0x218;
340+
}
341+
}
354342
}
355343
} else if (strcmp(romTid, "CSGJ") == 0) {
356344
extern u32 saga2OverlayApFix[];

0 commit comments

Comments
 (0)