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
|
|
|
|
2021-08-13 19:27:57 +02:00
|
|
|
extern s32 D_7012ACA1[];
|
|
|
|
|
|
|
|
void func_802AE000(void) {
|
2021-10-03 17:44:16 +02:00
|
|
|
s32(*readFunc)(OSPiHandle*, u32, u32*) = osEPiReadIo;
|
|
|
|
s32 seed = 0x33F50000;
|
|
|
|
UNK_FUN_PTR(battle_heap_create) = D_7012ACA1;
|
|
|
|
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;
|
|
|
|
|
|
|
|
for (it = _316C00_ROM_START; it < _316C00_ROM_END; it++) {
|
|
|
|
readFunc(nuPiCartHandle, it, &thisInsn);
|
|
|
|
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) {
|
|
|
|
(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
|
|
|
}
|
|
|
|
}
|