From 165367128cb17a609ece9f74c7064062ed3ff7d1 Mon Sep 17 00:00:00 2001 From: Niko Date: Fri, 21 Feb 2025 01:08:36 -0500 Subject: [PATCH] save 300 bytes --- decompile/General/233/233_20_CS_LoadBoss.c | 6 +++--- decompile/General/LOAD/LOAD_21_ReadFile.c | 6 +++++- decompile/General/LOAD/LOAD_34_AppendQueue.c | 10 ++++++++-- include/decomp_functions.h | 20 ++++++++++++++++++-- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/decompile/General/233/233_20_CS_LoadBoss.c b/decompile/General/233/233_20_CS_LoadBoss.c index 904a7022c..04edf4373 100644 --- a/decompile/General/233/233_20_CS_LoadBoss.c +++ b/decompile/General/233/233_20_CS_LoadBoss.c @@ -33,7 +33,7 @@ void DECOMP_CS_LoadBoss(struct BossCutsceneData* bcd) if (bcd->vrmFile != 0) { // CTR vram file (body and head) - LOAD_AppendQueue(sdata->ptrBigfileCdPos_2, LT_VRAM, bcd->vrmFile+index, 0, 0); + DECOMP_LOAD_AppendQueue(sdata->ptrBigfileCdPos_2, LT_VRAM, bcd->vrmFile+index, 0, 0); } #endif @@ -41,9 +41,9 @@ void DECOMP_CS_LoadBoss(struct BossCutsceneData* bcd) //if (bcd->bodyFile != 0) { // CTR Model File (body) - LOAD_AppendQueue(sdata->ptrBigfileCdPos_2, LT_DRAM, bcd->bodyFile+index, ptrDestination, 0); + DECOMP_LOAD_AppendQueue(sdata->ptrBigfileCdPos_2, LT_DRAM, bcd->bodyFile+index, ptrDestination, 0); } // CTR Model File (head) - LOAD_AppendQueue(sdata->ptrBigfileCdPos_2, LT_DRAM, bcd->headFile+index, 0, DECOMP_CS_LoadBossCallback); + DECOMP_LOAD_AppendQueue(sdata->ptrBigfileCdPos_2, LT_DRAM, bcd->headFile+index, 0, DECOMP_CS_LoadBossCallback); } \ No newline at end of file diff --git a/decompile/General/LOAD/LOAD_21_ReadFile.c b/decompile/General/LOAD/LOAD_21_ReadFile.c index f0e93cfd6..4247a1c2e 100644 --- a/decompile/General/LOAD/LOAD_21_ReadFile.c +++ b/decompile/General/LOAD/LOAD_21_ReadFile.c @@ -1,6 +1,9 @@ #include -void* DECOMP_LOAD_ReadFile(struct BigHeader* bigfile, /*u_int loadType,*/ int subfileIndex, void *ptrDst, void * callback) +// same hack as AppendQueue, see notes there +#define DECOMP_LOAD_ReadFile(a,b,c,d) DECOMP_LOAD_ReadFile_ex(b,c,d) + +void* DECOMP_LOAD_ReadFile_ex(/*struct BigHeader* bigfile, u_int loadType,*/ int subfileIndex, void *ptrDst, void * callback) { // param1 is the Pointer to CD position of BIGFILE @@ -11,6 +14,7 @@ void* DECOMP_LOAD_ReadFile(struct BigHeader* bigfile, /*u_int loadType,*/ int su DECOMP_CDSYS_SetMode_StreamData(); // get size and offset of subfile + struct BigHeader* bigfile = sdata->ptrBigfile1; struct BigEntry* entry = BIG_GETENTRY(bigfile); int eSize = entry[subfileIndex].size; int eOffs = entry[subfileIndex].offset; diff --git a/decompile/General/LOAD/LOAD_34_AppendQueue.c b/decompile/General/LOAD/LOAD_34_AppendQueue.c index 0c3350109..dbcd44988 100644 --- a/decompile/General/LOAD/LOAD_34_AppendQueue.c +++ b/decompile/General/LOAD/LOAD_34_AppendQueue.c @@ -1,6 +1,12 @@ #include -void DECOMP_LOAD_AppendQueue(int bigfile, int type, int fileIndex, void* destinationPtr, void (*callback)(struct LoadQueueSlot*)) +// This is a wonderful hack that removes an unused parameter, +// which saves bytes everywhere, without needing to alter the game code, +// We need the 'bigfile' parameter to stay in the C code, just to keep +// the front-end looking similar to ghidra, for easy comparison purposes +#define DECOMP_LOAD_AppendQueue(a,b,c,d,e) DECOMP_LOAD_AppendQueue_ex(b,c,d,e) + +void DECOMP_LOAD_AppendQueue_ex(/*int bigfile,*/ int type, int fileIndex, void* destinationPtr, void (*callback)(struct LoadQueueSlot*)) { struct LoadQueueSlot* lqs; @@ -10,7 +16,7 @@ void DECOMP_LOAD_AppendQueue(int bigfile, int type, int fileIndex, void* destina #endif lqs = &sdata->queueSlots[sdata->queueLength]; - lqs->ptrBigfileCdPos = (struct BigHeader*)bigfile; + //lqs->ptrBigfileCdPos = (struct BigHeader*)bigfile; lqs->flags = 0; lqs->type = type; lqs->subfileIndex = fileIndex; diff --git a/include/decomp_functions.h b/include/decomp_functions.h index d190dd21c..5ade8a220 100644 --- a/include/decomp_functions.h +++ b/include/decomp_functions.h @@ -281,7 +281,13 @@ void DECOMP_LOAD_Callback_Overlay_231(void); void DECOMP_LOAD_Callback_Overlay_232(void); void DECOMP_LOAD_Callback_Overlay_233(void); void DECOMP_LOAD_ReadFileASyncCallback(CdlIntrResult result, uint8_t* unk); -void* DECOMP_LOAD_ReadFile(struct BigHeader* bigfile, /*u_int loadType,*/ int subfileIndex, void* destination, /*int *size,*/ void * callback); + +// same hack as AppendQueue, see notes there +#define DECOMP_LOAD_ReadFile(a,b,c,d) DECOMP_LOAD_ReadFile_ex(b,c,d) +void* DECOMP_LOAD_ReadFile_ex(/*struct BigHeader* bigfile, u_int loadType,*/ int subfileIndex, void *ptrDst, void * callback); +// void* DECOMP_LOAD_ReadFile(struct BigHeader* bigfile, /*u_int loadType,*/ int subfileIndex, void* destination, /*int *size,*/ void * callback); + + void* DECOMP_LOAD_VramFile(void* bigfilePtr, int subfileIndex /*, int* ptrDestination, int* size, int callbackOrFlags*/); //void* DECOMP_LOAD_DramFile(void* bigfilePtr, int subfileIndex, int* ptrDestination, /*int* size,*/ int callbackOrFlags); void* DECOMP_LOAD_ReadDirectory(char* filename); @@ -296,7 +302,17 @@ int DECOMP_LOAD_HowlSectorChainEnd(void); void DECOMP_LOAD_InitCD(void); void DECOMP_LOAD_RunPtrMap(int origin, int* patchArr, int numPtrs); //1st param might be `struct Level*`, 2nd param might be `char*` void DECOMP_LOAD_LangFile(int bigfilePtr, int lang); -void DECOMP_LOAD_AppendQueue(int bigfile, int type, int fileIndex, void* destinationPtr, void (*callback)(struct LoadQueueSlot*)); + + +// This is a wonderful hack that removes an unused parameter, +// which saves bytes everywhere, without needing to alter the game code, +// We need the 'bigfile' parameter to stay in the C code, just to keep +// the front-end looking similar to ghidra, for easy comparison purposes +#define DECOMP_LOAD_AppendQueue(a,b,c,d,e) DECOMP_LOAD_AppendQueue_ex(b,c,d,e) +void DECOMP_LOAD_AppendQueue_ex(/*int bigfile,*/ int type, int fileIndex, void* destinationPtr, void (*callback)(struct LoadQueueSlot*)); +// void DECOMP_LOAD_AppendQueue(int bigfile, int type, int fileIndex, void* destinationPtr, void (*callback)(struct LoadQueueSlot*)); + + void DECOMP_LOAD_NextQueuedFile(void); void DECOMP_MainDB_OTMem(struct OTMem* otMem, u_int size);