mirror of
https://gitlab.com/ryandwyer/perfect-dark
synced 2026-09-04 18:21:26 -04:00
ntsc-beta: Decompile mainLoop
This commit is contained in:
+5
-1
@@ -59,7 +59,11 @@ int main(int argc, char **argv)
|
||||
|
||||
// Compute piracy checksums if requested
|
||||
if (state.piracychecks) {
|
||||
piracy_patch();
|
||||
piracy_patch_checksums();
|
||||
}
|
||||
|
||||
if (state.is_ntscbeta) {
|
||||
piracy_patch_mainloop();
|
||||
}
|
||||
|
||||
// Slice the game segment into chunks and zip each of them to create the
|
||||
|
||||
+2
-1
@@ -77,7 +77,8 @@ void pack_lib(void);
|
||||
void pack_data(void);
|
||||
void pack_game(void);
|
||||
|
||||
void piracy_patch(void);
|
||||
void piracy_patch_checksums(void);
|
||||
void piracy_patch_mainloop(void);
|
||||
|
||||
void rarezip(uint8_t *outbuffer, size_t *outlen, uint8_t *inbuffer, size_t inlen, uint32_t magic);
|
||||
|
||||
|
||||
+48
-1
@@ -160,7 +160,7 @@ static void patch(Algo algo, char *patchfunc, char *sumfunc)
|
||||
/**
|
||||
* Patch all the piracy functions in the game.
|
||||
*/
|
||||
void piracy_patch(void)
|
||||
void piracy_patch_checksums(void)
|
||||
{
|
||||
// algorithm, patch function, sum function
|
||||
patch(algo01, "__scHandleTasks", "bootPhase1");
|
||||
@@ -176,3 +176,50 @@ void piracy_patch(void)
|
||||
patch(algo11, "menuTickTimers", "mtxGetObfuscatedRomBase");
|
||||
patch(algo12, "func0f15c920", "menuTickTimers");
|
||||
}
|
||||
|
||||
/**
|
||||
* NTSC Beta's original mainLoop function reads from a hardware device and
|
||||
* refuses to run if it doesn't exist. Because of this, the reads must be
|
||||
* patched to allow a ROM to work without this hardware.
|
||||
*
|
||||
* Decomp's target ROM is the patched one, so we apply the patch here.
|
||||
*/
|
||||
void piracy_patch_mainloop(void)
|
||||
{
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
uint32_t offset;
|
||||
bool done_first = false;
|
||||
|
||||
if (!map_get_function_rompos("mainLoop", &start, &end)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (offset = start; offset < end; offset += 4) {
|
||||
uint32_t word = 0;
|
||||
word |= state.rom[offset] << 24;
|
||||
word |= state.rom[offset + 1] << 16;
|
||||
word |= state.rom[offset + 2] << 8;
|
||||
word |= state.rom[offset + 3];
|
||||
|
||||
if (!done_first) {
|
||||
if (word == 0x84820000) { // lh $v0, 0($a0)
|
||||
// Replace with: li $v0, 0x4f4a
|
||||
state.rom[offset + 0] = 0x24;
|
||||
state.rom[offset + 1] = 0x02;
|
||||
state.rom[offset + 2] = 0x4f;
|
||||
state.rom[offset + 3] = 0x4a;
|
||||
done_first = true;
|
||||
}
|
||||
} else {
|
||||
if (word == 0x84820002) { // lh $v0, 2($a0)
|
||||
// Replace with: li $v0, 0x4653
|
||||
state.rom[offset + 0] = 0x24;
|
||||
state.rom[offset + 1] = 0x02;
|
||||
state.rom[offset + 2] = 0x46;
|
||||
state.rom[offset + 3] = 0x53;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user