From 453a4e344b286640fbfa8449656624efba02db8f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 19 Sep 2021 13:48:11 +1000 Subject: [PATCH] Document PAKFILETYPE_TERMINATOR and related piracy check --- src/game/lv.c | 4 ++++ src/game/pak/pak.c | 8 ++++---- src/include/constants.h | 18 +++++++++--------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/game/lv.c b/src/game/lv.c index 271266d52..6e7057bce 100644 --- a/src/game/lv.c +++ b/src/game/lv.c @@ -564,6 +564,10 @@ void lvInit(s32 stagenum) } if (checksum != CHECKSUM_PLACEHOLDER) { + // This is writing a file to the start of the EEPROM data. + // The file is PAKFILETYPE_TERMINATOR, which is used internally to + // mark the end of the usable space. This effectively deletes all + // save data on the game pak and makes it permanently unusable. u32 address = 0; u32 buffer[4]; buffer[0] = 0xbb8b80bd; diff --git a/src/game/pak/pak.c b/src/game/pak/pak.c index c8cf3e324..1b525bb55 100644 --- a/src/game/pak/pak.c +++ b/src/game/pak/pak.c @@ -563,7 +563,7 @@ s32 pakGetBodyLenByType(s8 device, u32 filetype) case PAKFILETYPE_001: case PAKFILETYPE_002: break; - case PAKFILETYPE_004: + case PAKFILETYPE_TERMINATOR: len = pak0f11706c(device) - 0x10; break; case PAKFILETYPE_BOSS: @@ -8864,7 +8864,7 @@ s32 pakScrub(s8 device) data[i] = random() & 0xff; } - address = pakGetAlignedFileLenByBodyLen(device, pakGetBodyLenByType(device, PAKFILETYPE_004)); + address = pakGetAlignedFileLenByBodyLen(device, pakGetBodyLenByType(device, PAKFILETYPE_TERMINATOR)); g_Paks[device].unk25c = 0x10; #if VERSION >= VERSION_NTSC_1_0 @@ -8874,7 +8874,7 @@ s32 pakScrub(s8 device) #endif g_Paks[device].headercachecount = 0; - pak0f11bc54(device, 0, PAKFILETYPE_004, 0, 0, 0, 0, 0, 1); + pak0f11bc54(device, 0, PAKFILETYPE_TERMINATOR, 0, 0, 0, 0, 0, 1); result = pak0f11a504(device, PFS(device), g_Paks[device].noteindex, PFS_WRITE, address, pakGetAlignment(device), data); @@ -8922,7 +8922,7 @@ bool pak0f11b75c(s8 device, u32 *arg1) } #endif - if (PAKFILETYPE_004 == header.filetype) { + if (PAKFILETYPE_TERMINATOR == header.filetype) { *arg1 = offset; return false; } diff --git a/src/include/constants.h b/src/include/constants.h index aac201dac..f7b9017c7 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -3072,15 +3072,15 @@ #define PAKERROR_EEPROM_INVALIDOP 0x83 #define PAKERROR_EEPROM_INVALIDARG 0x84 -#define PAKFILETYPE_001 0x001 -#define PAKFILETYPE_002 0x002 -#define PAKFILETYPE_004 0x004 -#define PAKFILETYPE_008 0x008 // suspected to be PerfectHead -#define PAKFILETYPE_BOSS 0x010 -#define PAKFILETYPE_MPPLAYER 0x020 -#define PAKFILETYPE_MPSETUP 0x040 -#define PAKFILETYPE_GAME 0x080 -#define PAKFILETYPE_100 0x100 +#define PAKFILETYPE_001 0x001 +#define PAKFILETYPE_002 0x002 +#define PAKFILETYPE_TERMINATOR 0x004 +#define PAKFILETYPE_008 0x008 // suspected to be PerfectHead +#define PAKFILETYPE_BOSS 0x010 +#define PAKFILETYPE_MPPLAYER 0x020 +#define PAKFILETYPE_MPSETUP 0x040 +#define PAKFILETYPE_GAME 0x080 +#define PAKFILETYPE_100 0x100 #define PATHFLAG_CIRCULAR 1 #define PATHFLAG_FLYING 2