Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
obfuscation_shims.c File Reference

Go to the source code of this file.

Functions

void create_audio_system_obfuscated (void)
 
void load_engine_data_obfuscated (void)
 
void general_heap_create_obfuscated (void)
 
void battle_heap_create_obfuscated (void)
 
void shim_create_audio_system_obfuscated (void)
 
void shim_load_engine_data_obfuscated (void)
 
void shim_general_heap_create_obfuscated (void)
 
void shim_battle_heap_create_obfuscated (void)
 

Function Documentation

◆ create_audio_system_obfuscated()

void create_audio_system_obfuscated ( void )

Definition at line 11 of file create_audio_system_obfuscated.c.

11 {
12 u32 t0 = 0xAC29007B;
13 u32 t1 = 0xB00006A8;
14 void (*create_audio_system)(void) = (void (*)(void)) obfuscated_create_audio_system;
15
16 while (IO_READ(PI_STATUS_REG) & 3);
17
18 t0 -= IO_READ(t1 - 0x1C8);
21}
void create_audio_system(void)
u8 obfuscated_create_audio_system[]

Referenced by shim_create_audio_system_obfuscated().

◆ load_engine_data_obfuscated()

void load_engine_data_obfuscated ( void )

Definition at line 13 of file load_engine_data_obfuscated.c.

13 {
14 s32 seed = 0x3C01A775;
15 u32 thisInsn = 0xB0018FFC;
16 HeapNode*(*load_engine_data)(void) = (HeapNode* (*)(void)) obfuscated_load_engine_data; // load_engine_data - ????????
17 s32 hash = 0;
18 u32 prevInsn;
19 u32* it;
20
21 while (IO_READ(PI_STATUS_REG) & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY));
22 seed -= IO_READ(thisInsn + 0xFFFE7508);
23
24 prevInsn = 0;
25
26 for (it = (u32*) create_audio_system_obfuscated_ROM_START; it < (u32*) create_audio_system_obfuscated_ROM_END; it++) {
27 while (IO_READ(PI_STATUS_REG) & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY));
28 thisInsn = IO_READ(it + 0x4000000); // ???
29
30 hash += LOWER(thisInsn) + UPPER(thisInsn);
31
32 if (OPCODE(prevInsn) == LUI &&
33 OPCODE(thisInsn) == ADDIU &&
34 GET_RS(thisInsn) == GET_RT(prevInsn) &&
35 GET_RS(thisInsn) == GET_RT(thisInsn))
36 {
37 hash -= LOWER(thisInsn);
38 hash -= LOWER(prevInsn);
39 }
40
41 if (OPCODE(thisInsn) == JAL) {
42 hash -= LOWER(thisInsn) + (UPPER(thisInsn) & 0xFC00);
43 }
44
45 prevInsn = thisInsn;
46 }
47
48 load_engine_data += seed + 0xDDD20 - hash;
50}
u8 obfuscated_load_engine_data[]
void load_engine_data(void)
Definition main_loop.c:285
#define ADDIU
Definition mips.h:5
#define LOWER(x)
Definition mips.h:8
#define GET_RS(x)
Definition mips.h:11
#define UPPER(x)
Definition mips.h:9
#define JAL
Definition mips.h:4
#define GET_RT(x)
Definition mips.h:12
#define OPCODE(x)
Definition mips.h:10
#define LUI
Definition mips.h:6

Referenced by shim_load_engine_data_obfuscated().

◆ general_heap_create_obfuscated()

void general_heap_create_obfuscated ( void )

Definition at line 13 of file general_heap_create_obfuscated.c.

13 {
14 s32(*readFunc)(OSPiHandle*, u32, u32*) = osEPiReadIo;
15 s32 seed = 0x3C016C07 + 0xFEFEFEF;
16 HeapNode*(*general_heap_create)(void) = (HeapNode* (*)(void)) obfuscated_general_heap_create; // general_heap_create - 0xFEFEFEF
17 u32 hash = 0;
18 u32 thisInsn;
19 u32* it;
20 u32 prevInsn;
21
22 readFunc(nuPiCartHandle, 0xB0000574, &thisInsn);
23 seed -= thisInsn; // thisInsn = 0x3C016C07 here, so seed becomes 0xFEFEFEF
24
25 prevInsn = 0;
26
27 for (it = (u32*) load_engine_data_obfuscated_ROM_START; it < (u32*) load_engine_data_obfuscated_ROM_END; it++) {
28 readFunc(nuPiCartHandle, (u32) it, &thisInsn);
29 hash += LOWER(thisInsn) + UPPER(thisInsn);
30
31 if (OPCODE(prevInsn) == LUI && (OPCODE(thisInsn) == ADDIU || OPCODE(thisInsn) == LW)) {
32 if (GET_RS(thisInsn) == GET_RT(prevInsn) && GET_RS(thisInsn) == GET_RT(thisInsn)) {
33 hash -= LOWER(thisInsn);
34 hash -= LOWER(prevInsn);
35 }
36 }
37
38 if (OPCODE(thisInsn) == JAL) {
39 hash -= LOWER(thisInsn) + (UPPER(thisInsn) & 0xFC00);
40 }
41
42 prevInsn = thisInsn;
43 }
44
45 // 0x2499BF - hash == 0, so we add back 0xFEFEFEF (seed) and we end up with the address of general_heap_create!
46 general_heap_create += seed + 0x2499BF - hash;
47
48 // If the function's address is 0x8XXXXXXX
49 if (((u32)general_heap_create >> 0x1C) == 8) {
50 // Call the function that ends up being general_heap_create
52 }
53}
HeapNode * general_heap_create(void)
Definition heap.c:6
u8 obfuscated_general_heap_create[]
#define LW
Definition mips.h:7

Referenced by shim_general_heap_create_obfuscated().

◆ battle_heap_create_obfuscated()

void battle_heap_create_obfuscated ( void )

Definition at line 13 of file battle_heap_create_obfuscated.c.

13 {
14 s32(*readFunc)(OSPiHandle*, u32, u32*) = osEPiReadIo;
15 s32 seed = 0x33F50000;
16 s32 (*battle_heap_create)(void) = (s32 (*) (void)) obfuscated_battle_heap_create;
17 u32 hash = 0;
18 u32 thisInsn;
19 u32* it;
20 u32 prevInsn;
21
22 readFunc(nuPiCartHandle, 0xB0000800, &thisInsn);
23 seed -= thisInsn;
24
25 prevInsn = 0;
26
27 for (it = (u32*) general_heap_create_obfuscated_ROM_START; it < (u32*) general_heap_create_obfuscated_ROM_END; it++) {
28 readFunc(nuPiCartHandle, (u32) it, &thisInsn);
29 hash += LOWER(thisInsn) + UPPER(thisInsn);
30
31 if (OPCODE(prevInsn) == LUI && (OPCODE(thisInsn) == ADDIU || OPCODE(thisInsn) == LW)) {
32 if (GET_RS(thisInsn) == GET_RT(prevInsn) && GET_RS(thisInsn) == GET_RT(thisInsn)) {
33 hash -= LOWER(thisInsn);
34 hash -= LOWER(prevInsn);
35 }
36 }
37
38 if (OPCODE(thisInsn) == JAL) {
39 hash -= LOWER(thisInsn) + (UPPER(thisInsn) & 0xFC00);
40 }
41
42 prevInsn = thisInsn;
43 }
44
45 battle_heap_create += seed + 0x291993 - hash;
46
47 // If the function's address is 0x8XXXXXXX
48 if (((u32)battle_heap_create >> 0x1C) == 8) {
50 } else {
52 }
53}
s32 obfuscated_battle_heap_create[]
s32 battle_heap_create(void)
Definition heap.c:22
HeapNode * _heap_create(HeapNode *addr, u32 size)
Definition 43F0.c:63
HeapNode heap_battleHead

Referenced by shim_battle_heap_create_obfuscated().

◆ shim_create_audio_system_obfuscated()

void shim_create_audio_system_obfuscated ( void )

Definition at line 9 of file obfuscation_shims.c.

9 {
12}
void create_audio_system_obfuscated(void)
#define DMA_COPY_SEGMENT(segment)
Definition macros.h:525

Referenced by boot_main().

◆ shim_load_engine_data_obfuscated()

void shim_load_engine_data_obfuscated ( void )

Definition at line 14 of file obfuscation_shims.c.

Referenced by boot_main().

◆ shim_general_heap_create_obfuscated()

void shim_general_heap_create_obfuscated ( void )

Definition at line 19 of file obfuscation_shims.c.

Referenced by load_map_by_IDs().

◆ shim_battle_heap_create_obfuscated()

void shim_battle_heap_create_obfuscated ( void )

Definition at line 24 of file obfuscation_shims.c.

Referenced by state_step_battle().