Paper Mario DX
Paper Mario (N64) modding
Loading...
Searching...
No Matches
general_heap_create_obfuscated.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
u8
obfuscated_general_heap_create
[];
7
8
#ifdef SHIFT
9
void
general_heap_create_obfuscated
(
void
) {
10
general_heap_create
();
11
}
12
#else
13
void
general_heap_create_obfuscated
(
void
) {
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
51
general_heap_create
();
52
}
53
}
54
#endif
PopupMenu_SelectedIndex
BSS s32 PopupMenu_SelectedIndex
Definition
8a860_len_3f30.c:84
HeapNode
Definition
common_structs.h:154
general_heap_create
HeapNode * general_heap_create(void)
Definition
heap.c:6
general_heap_create_obfuscated
void general_heap_create_obfuscated(void)
Definition
general_heap_create_obfuscated.c:13
obfuscated_general_heap_create
u8 obfuscated_general_heap_create[]
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
src
general_heap_create_obfuscated.c
Generated by
1.10.0