From 2143bef1df7eaa8e179ade9761d9b7d78b554b87 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 30 Oct 2021 10:16:13 +1000 Subject: [PATCH] Decompile memaFree --- docs/piracychecks.md | 2 +- src/game/bg.c | 4 ++-- src/game/camdraw.c | 2 +- src/game/filelist.c | 4 ++-- src/game/filemgr.c | 4 ++-- src/game/game_02cde0.c | 2 +- src/game/game_129210.c | 4 ++-- src/include/lib/lib_126b0.h | 6 +++--- src/lib/lib_126b0.c | 19 ++++++------------- 9 files changed, 20 insertions(+), 27 deletions(-) diff --git a/docs/piracychecks.md b/docs/piracychecks.md index ec1e13ff3..6c47f36e2 100644 --- a/docs/piracychecks.md +++ b/docs/piracychecks.md @@ -92,7 +92,7 @@ The decomp project wraps all decompiled piracy checks in `#if PIRACYCHECKS` stat **What It Checks:** Checksums `lvInit` to make sure it hasn't been modified. -**Payload:** Nops `func00012914` entirely. Unsure what effect this has. This means any time that function is called it'll flow into the following function, which just returns. +**Payload:** Nops `_memaFree` entirely, so any time that function is called it'll flow into the following function, which just returns. The effect this has is that the system is unable to free individual mema allocations which makes it more likely to run out of memory. --- diff --git a/src/game/bg.c b/src/game/bg.c index e934e7a41..9fb1a3f16 100644 --- a/src/game/bg.c +++ b/src/game/bg.c @@ -10806,13 +10806,13 @@ void func0f15e474(s32 roomnum) if (g_Rooms[roomnum].unk44) { thing = ((g_Rooms[roomnum].unk40 << 5) + 0xf) & ~0xf; - func00012cb4(g_Rooms[roomnum].unk44, thing); + memaFree(g_Rooms[roomnum].unk44, thing); g_Rooms[roomnum].unk44 = NULL; } if (g_Rooms[roomnum].unk80 > 0) { thing = g_Rooms[roomnum].unk80; - func00012cb4(g_Rooms[roomnum].unk14, thing); + memaFree(g_Rooms[roomnum].unk14, thing); g_Rooms[roomnum].unk14 = 0; } diff --git a/src/game/camdraw.c b/src/game/camdraw.c index 0b111208a..616450630 100644 --- a/src/game/camdraw.c +++ b/src/game/camdraw.c @@ -340,7 +340,7 @@ void func0f149e58(u8 *arg0, u32 size) for (i = 0; i < var800a45a0->unk37c; i++) { if (arg0 == NULL || arg0 == var800a45a0->unk380[i]) { - func00012cb4(var800a45a0->unk380[i], var800a45a0->unk3f8[i]); + memaFree(var800a45a0->unk380[i], var800a45a0->unk3f8[i]); var800a45a0->unk380[i] = 0; } } diff --git a/src/game/filelist.c b/src/game/filelist.c index 2d7d63843..0b9344bb2 100644 --- a/src/game/filelist.c +++ b/src/game/filelist.c @@ -39,7 +39,7 @@ void func0f110bf8(void) for (i = 0; i < 4; i++) { if (g_FileLists[i] != NULL) { - func00012cb4(g_FileLists[i], align16(sizeof(struct filelist))); + memaFree(g_FileLists[i], align16(sizeof(struct filelist))); g_FileLists[i] = NULL; } } @@ -537,7 +537,7 @@ void pheadFreeTextures(s32 playernum) { if (g_Menus[playernum].fm.headtextures != NULL) { if (g_Menus[playernum].fm.unke40_01) { - func00012cb4(g_Menus[playernum].fm.headtextures, align16(sizeof(struct perfectheadtexturelist))); + memaFree(g_Menus[playernum].fm.headtextures, align16(sizeof(struct perfectheadtexturelist))); } g_Menus[playernum].fm.headtextures = NULL; diff --git a/src/game/filemgr.c b/src/game/filemgr.c index 4b350ee4e..752241f0f 100644 --- a/src/game/filemgr.c +++ b/src/game/filemgr.c @@ -460,7 +460,7 @@ void func0f10898c(void) case FILEOP_READ_GAME: case FILEOP_READ_MPSETUP: case FILEOP_READ_MPPLAYER: - func00012cb4(g_Menus[g_MpPlayerNum].fm.unke44, align16(g_FileTypeSizes[g_Menus[g_MpPlayerNum].fm.filetypeplusone - 1])); + memaFree(g_Menus[g_MpPlayerNum].fm.unke44, align16(g_FileTypeSizes[g_Menus[g_MpPlayerNum].fm.filetypeplusone - 1])); break; case FILEOP_LOAD_GAME: case FILEOP_LOAD_MPPLAYER: @@ -484,7 +484,7 @@ void filemgrHandleSuccess(void) case FILEOP_WRITE_GAME: case FILEOP_WRITE_MPSETUP: case FILEOP_WRITE_MPPLAYER: - func00012cb4(g_Menus[g_MpPlayerNum].fm.unke44, + memaFree(g_Menus[g_MpPlayerNum].fm.unke44, align16(g_FileTypeSizes[g_Menus[g_MpPlayerNum].fm.filetypeplusone - 1])); break; case FILEOP_LOAD_GAME: diff --git a/src/game/game_02cde0.c b/src/game/game_02cde0.c index e11aa889d..007e3a34b 100644 --- a/src/game/game_02cde0.c +++ b/src/game/game_02cde0.c @@ -898,7 +898,7 @@ struct prop *propAllocateEyespy(struct pad *pad, s16 room) } if (checksum != CHECKSUM_PLACEHOLDER) { - s32 *ptr2 = (s32 *)func00012914; + s32 *ptr2 = (s32 *)_memaFree; s32 *end2 = (s32 *)memaInit; while (ptr2 < end2) { diff --git a/src/game/game_129210.c b/src/game/game_129210.c index 89c90e33f..42a14647b 100644 --- a/src/game/game_129210.c +++ b/src/game/game_129210.c @@ -111,7 +111,7 @@ void func0f12939c(void) s32 size = ALIGN16(var8007e3d0[1].unk24[j].unk0c * 0x0c); func0f129210(var8007e3d0[1].unk24[j].unk00, var8007e3d0[1].unk24[i].unk00); var8007e3d0[1].unk24[i].unk0e += var8007e3d0[1].unk24[j].unk0e; - func00012cb4(var8007e3d0[1].unk24[j].unk00, size); + memaFree(var8007e3d0[1].unk24[j].unk00, size); var8007e3d0[1].unk24[j].unk0e = 0; var8007e3d0[1].val2 += var8007e3d0[1].unk24[j].unk0c; } @@ -419,7 +419,7 @@ void func0f129818(s32 arg0, void *arg1) return; } - func00012cb4(var8007e3d0[arg0].unk24[i].unk00, ALIGN16(var8007e3d0[arg0].unk24[i].unk0c * 0xc)); + memaFree(var8007e3d0[arg0].unk24[i].unk00, ALIGN16(var8007e3d0[arg0].unk24[i].unk0c * 0xc)); var8007e3d0[arg0].val2 += var8007e3d0[arg0].unk24[i].unk0c; return; diff --git a/src/include/lib/lib_126b0.h b/src/include/lib/lib_126b0.h index 25643da3a..b7873372e 100644 --- a/src/include/lib/lib_126b0.h +++ b/src/include/lib/lib_126b0.h @@ -6,13 +6,13 @@ void memaDefrag(void); u32 func00012800(void); -u32 func00012914(void); +void _memaFree(u32 addr, u32 size); void memaInit(void); -void memaHeapInit(void *ptr, u32 arg1); +void memaHeapInit(void *ptr, u32 size); void memaPrint(void); void *memaAlloc(u32 size); u32 func00012c3c(void); -void func00012cb4(void *arg0, s32 arg1); +void memaFree(void *addr, s32 size); s32 memaGetLongestFree(void); u32 func00012d48(void); diff --git a/src/lib/lib_126b0.c b/src/lib/lib_126b0.c index 28d4afbb0..ec9b2cda9 100644 --- a/src/lib/lib_126b0.c +++ b/src/lib/lib_126b0.c @@ -157,7 +157,7 @@ glabel func00012800 ); GLOBAL_ASM( -glabel func00012914 +glabel _memaFree /* 12914: 3c0f800a */ lui $t7,%hi(var80099470) /* 12918: 8def9470 */ lw $t7,%lo(var80099470)($t7) /* 1291c: 3c09800a */ lui $t1,%hi(var80099474) @@ -720,17 +720,10 @@ glabel func00012c3c /* 12cb0: 00000000 */ nop ); -GLOBAL_ASM( -glabel func00012cb4 -/* 12cb4: 27bdffe8 */ addiu $sp,$sp,-24 -/* 12cb8: afbf0014 */ sw $ra,0x14($sp) -/* 12cbc: 0c004a45 */ jal func00012914 -/* 12cc0: 00000000 */ nop -/* 12cc4: 8fbf0014 */ lw $ra,0x14($sp) -/* 12cc8: 27bd0018 */ addiu $sp,$sp,0x18 -/* 12ccc: 03e00008 */ jr $ra -/* 12cd0: 00000000 */ nop -); +void memaFree(void *addr, s32 size) +{ + _memaFree((u32)addr, size); +} void mema00012cd4(void) { @@ -785,7 +778,7 @@ glabel func00012d48 /* 12d80: 10200004 */ beqz $at,.L00012d94 /* 12d84: 8faf0018 */ lw $t7,0x18($sp) /* 12d88: 01e62021 */ addu $a0,$t7,$a2 -/* 12d8c: 0c004b2d */ jal func00012cb4 +/* 12d8c: 0c004b2d */ jal memaFree /* 12d90: 00e62823 */ subu $a1,$a3,$a2 .L00012d94: /* 12d94: 24020001 */ addiu $v0,$zero,0x1