Paper Mario DX
Paper Mario (N64) modding
Loading...
Searching...
No Matches
load_obfuscation_shims.c
Go to the documentation of this file.
1
#include "common.h"
2
#include "nu/nusys.h"
3
#include "ld_addrs.h"
4
#include "
mips.h
"
5
6
extern
s8
obfuscated_obfuscation_shims_ROM_START
[];
7
extern
s8
obfuscated_obfuscation_shims_VRAM
[];
8
9
#if VERSION_JP
10
// TODO: split these segments
11
extern
Addr
battle_heap_create_obfuscated_ROM_START
;
12
extern
Addr
battle_heap_create_obfuscated_ROM_END
;
13
extern
Addr
obfuscation_shims_ROM_START
;
14
extern
Addr
obfuscation_shims_ROM_END
;
15
#endif
16
17
#ifdef SHIFT
18
void
load_obfuscation_shims
(
void
) {
19
// no-op since in shiftable builds, we bypass the obfuscation
20
}
21
#else
22
void
load_obfuscation_shims
(
void
) {
23
s32 (*
readFunc
)(
OSPiHandle
*,
u32
,
u32
*);
24
s32 (*
readFunc2
)(
OSPiHandle
*,
u32
,
u32
*);
25
s8
*
vramDest
=
obfuscated_obfuscation_shims_VRAM
;
26
s8
* romStart =
obfuscated_obfuscation_shims_ROM_START
;
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
}
89
#endif
PopupMenu_SelectedIndex
BSS s32 PopupMenu_SelectedIndex
Definition
8a860_len_3f30.c:84
dma_copy
u32 dma_copy(Addr romStart, Addr romEnd, void *vramDest)
Definition
43F0.c:443
load_obfuscation_shims
void load_obfuscation_shims(void)
Definition
load_obfuscation_shims.c:22
obfuscated_obfuscation_shims_VRAM
s8 obfuscated_obfuscation_shims_VRAM[]
obfuscated_obfuscation_shims_ROM_START
s8 obfuscated_obfuscation_shims_ROM_START[]
mips.h
ADDIU
#define ADDIU
Definition
mips.h:5
LOWER
#define LOWER(x)
Definition
mips.h:8
GET_RS
#define GET_RS(x)
Definition
mips.h:11
UPPER
#define UPPER(x)
Definition
mips.h:9
JAL
#define JAL
Definition
mips.h:4
GET_RT
#define GET_RT(x)
Definition
mips.h:12
LW
#define LW
Definition
mips.h:7
OPCODE
#define OPCODE(x)
Definition
mips.h:10
LUI
#define LUI
Definition
mips.h:6
Addr
u8 Addr[]
Linker symbol address, as in ld_addrs.h.
Definition
types.h:16
src
load_obfuscation_shims.c
Generated by
1.10.0