2021-04-13 09:47:52 +02:00
|
|
|
#include "common.h"
|
2021-08-13 19:27:57 +02:00
|
|
|
#include "nu/nusys.h"
|
|
|
|
#include "ld_addrs.h"
|
|
|
|
#include "mips.h"
|
2021-04-13 09:47:52 +02:00
|
|
|
|
2022-06-12 17:33:32 +02:00
|
|
|
extern s32 obfuscated_battle_heap_create[];
|
2021-08-13 19:27:57 +02:00
|
|
|
|
2023-01-28 11:47:26 +01:00
|
|
|
#ifdef SHIFT
|
2023-02-02 12:23:17 +01:00
|
|
|
void battle_heap_create_obfuscated(void) {
|
2023-01-28 11:47:26 +01:00
|
|
|
battle_heap_create();
|
|
|
|
}
|
|
|
|
#else
|
2023-02-02 12:23:17 +01:00
|
|
|
void battle_heap_create_obfuscated(void) {
|
2021-10-03 17:44:16 +02:00
|
|
|
s32(*readFunc)(OSPiHandle*, u32, u32*) = osEPiReadIo;
|
|
|
|
s32 seed = 0x33F50000;
|
2022-10-16 16:22:18 +02:00
|
|
|
s32 (*battle_heap_create)(void) = (s32 (*) (void)) obfuscated_battle_heap_create;
|
2021-10-03 17:44:16 +02:00
|
|
|
u32 hash = 0;
|
2021-08-13 19:27:57 +02:00
|
|
|
u32 thisInsn;
|
|
|
|
u32* it;
|
|
|
|
u32 prevInsn;
|
|
|
|
|
|
|
|
readFunc(nuPiCartHandle, 0xB0000800, &thisInsn);
|
|
|
|
seed -= thisInsn;
|
|
|
|
|
|
|
|
prevInsn = 0;
|
|
|
|
|
2023-02-02 12:23:17 +01:00
|
|
|
for (it = (u32*) general_heap_create_obfuscated_ROM_START; it < (u32*) general_heap_create_obfuscated_ROM_END; it++) {
|
2022-10-16 16:22:18 +02:00
|
|
|
readFunc(nuPiCartHandle, (u32) it, &thisInsn);
|
2021-08-13 19:27:57 +02:00
|
|
|
hash += LOWER(thisInsn) + UPPER(thisInsn);
|
|
|
|
|
|
|
|
if (OPCODE(prevInsn) == LUI && (OPCODE(thisInsn) == ADDIU || OPCODE(thisInsn) == LW)) {
|
|
|
|
if (GET_RS(thisInsn) == GET_RT(prevInsn) && GET_RS(thisInsn) == GET_RT(thisInsn)) {
|
|
|
|
hash -= LOWER(thisInsn);
|
|
|
|
hash -= LOWER(prevInsn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OPCODE(thisInsn) == JAL) {
|
|
|
|
hash -= LOWER(thisInsn) + (UPPER(thisInsn) & 0xFC00);
|
|
|
|
}
|
|
|
|
|
|
|
|
prevInsn = thisInsn;
|
|
|
|
}
|
|
|
|
|
2021-10-03 17:44:16 +02:00
|
|
|
battle_heap_create += seed + 0x291993 - hash;
|
2021-08-13 19:27:57 +02:00
|
|
|
|
|
|
|
// If the function's address is 0x8XXXXXXX
|
2021-10-03 17:44:16 +02:00
|
|
|
if (((u32)battle_heap_create >> 0x1C) == 8) {
|
2023-01-28 11:47:26 +01:00
|
|
|
battle_heap_create();
|
2021-08-13 19:27:57 +02:00
|
|
|
} else {
|
2021-11-07 17:58:57 +01:00
|
|
|
_heap_create(&heap_battleHead, 0x10000);
|
2021-08-13 19:27:57 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-28 11:47:26 +01:00
|
|
|
#endif
|