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

Go to the source code of this file.

Functions

void load_obfuscation_shims (void)
 

Variables

s8 obfuscated_obfuscation_shims_ROM_START []
 
s8 obfuscated_obfuscation_shims_VRAM []
 

Function Documentation

◆ load_obfuscation_shims()

void load_obfuscation_shims ( void )

Definition at line 22 of file load_obfuscation_shims.c.

22 {
23 s32 (*readFunc)(OSPiHandle*, u32, u32*);
24 s32 (*readFunc2)(OSPiHandle*, u32, u32*);
27 s32 seed;
28 u32 hash;
29 u32 thisInsn;
30 u32 thisInsn2;
31 u32 prevInsn;
32 u8* it;
33
34 // vramDest
35 readFunc = osEPiReadIo;
36 seed = 0x0B112D28;
37 hash = 0;
38 readFunc(nuPiCartHandle, 0xB0000D10, &thisInsn);
39 seed -= thisInsn;
40 prevInsn = 0;
41
42 for (it = battle_heap_create_obfuscated_ROM_START; it < battle_heap_create_obfuscated_ROM_END; it += 4) {
43 readFunc(nuPiCartHandle, (u32)it, &thisInsn);
44 hash += LOWER(thisInsn) + UPPER(thisInsn);
45
46 if (OPCODE(prevInsn) == LUI && (OPCODE(thisInsn) == ADDIU || OPCODE(thisInsn) == LW)) {
47 if (GET_RS(thisInsn) == GET_RT(prevInsn) && GET_RS(thisInsn) == GET_RT(thisInsn)) {
48 hash -= LOWER(thisInsn);
49 hash -= LOWER(prevInsn);
50 }
51 }
52
53 if (OPCODE(thisInsn) == JAL) {
54 hash -= LOWER(thisInsn) + (UPPER(thisInsn) & 0xFC00);
55 }
56
57 prevInsn = thisInsn;
58 }
59 vramDest += seed + 0x2A4EB6 - hash;
60
61 // romStart
62 readFunc2 = osEPiReadIo;
63 seed = 0x18F414AB;
64 hash = 0;
65 readFunc2(nuPiCartHandle, 0xB0000E38, &thisInsn2);
66 seed -= thisInsn2;
67 prevInsn = 0;
68
69 for (it = obfuscation_shims_ROM_START; it < obfuscation_shims_ROM_END; it += 4) {
70 readFunc2(nuPiCartHandle, (u32)it, &thisInsn2);
71 hash += LOWER(thisInsn2) + UPPER(thisInsn2);
72
73 if (OPCODE(prevInsn) == LUI && (OPCODE(thisInsn2) == ADDIU || OPCODE(thisInsn2) == LW)) {
74 if (GET_RS(thisInsn2) == GET_RT(prevInsn) && GET_RS(thisInsn2) == GET_RT(thisInsn2)) {
75 hash -= LOWER(thisInsn2);
76 hash -= LOWER(prevInsn);
77 }
78 }
79
80 if (OPCODE(thisInsn2) == JAL) {
81 hash -= LOWER(thisInsn2) + (UPPER(thisInsn2) & 0xFC00);
82 }
83 prevInsn = thisInsn2;
84 }
85 romStart += seed + 0xED41C - hash;
86
87 dma_copy(romStart, obfuscation_shims_ROM_END, vramDest);
88}
u32 dma_copy(Addr romStart, Addr romEnd, void *vramDest)
Definition 43F0.c:444
s8 obfuscated_obfuscation_shims_VRAM[]
s8 obfuscated_obfuscation_shims_ROM_START[]
#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 LW
Definition mips.h:7
#define OPCODE(x)
Definition mips.h:10
#define LUI
Definition mips.h:6

Referenced by boot_main(), load_map_by_IDs(), and state_step_battle().

Variable Documentation

◆ obfuscated_obfuscation_shims_ROM_START

s8 obfuscated_obfuscation_shims_ROM_START[]
extern

Referenced by load_obfuscation_shims().

◆ obfuscated_obfuscation_shims_VRAM

s8 obfuscated_obfuscation_shims_VRAM[]
extern

Referenced by load_obfuscation_shims().