From 9b25f63c5592d5d894e76a4995d0af40a7504b27 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 20 Oct 2019 22:37:00 +1000 Subject: [PATCH] Attempt decompile of aiShuffleInvestigationTerminals --- src/game/chr/chraicommands.c | 79 +++++++++++++++++++++++++++- src/include/game/chr/chraicommands.h | 2 +- src/include/types.h | 2 +- src/setup/setup_000000.c | 2 +- 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/game/chr/chraicommands.c b/src/game/chr/chraicommands.c index 5335ae67b..af33a4e5a 100644 --- a/src/game/chr/chraicommands.c +++ b/src/game/chr/chraicommands.c @@ -13753,7 +13753,7 @@ bool ai0140(void) * @cmd 0141 */ GLOBAL_ASM( -glabel ai0141 +glabel aiShuffleInvestigationTerminals /* f05bac0: 3c02800a */ lui $v0,0x800a /* f05bac4: 24429fc0 */ addiu $v0,$v0,-24640 /* f05bac8: 8c4e0434 */ lw $t6,0x434($v0) @@ -13913,6 +13913,83 @@ glabel ai0141 /* f05bd08: 00001025 */ or $v0,$zero,$zero ); +// Mismatch due to stack pointers misaligned +//bool aiShuffleInvestigationTerminals(void) +//{ +// // 2 = dst1 +// // 3 = dst2 +// // 4 = src1 +// // 5 = src2 +// // 6 = src3 +// // 7 = src4 +// // 8 = always 00 +// +// u8 *cmd = g_Vars.ailist + g_Vars.aioffset; +// struct tag *goodpc = tagFindById(cmd[2]); +// struct tag *badpc = tagFindById(cmd[3]); +// +// /** +// * @bug: These should be using modulus 4. Because it's 1 short, the final +// * else conditions are unreachable so only 3 of the 4 terminals can be +// * selected as the destination. +// */ +// u8 rand1 = random() % 3U; +// u8 rand2 = random() % 3U; +// +// if (cmd[8] == 0) { +// struct tag *dst; +// +// // Place the good terminal +// if (rand1 == 0) { +// dst = tagFindById(cmd[4]); +// goodpc->unk06 = dst->unk06; +// goodpc->obj = dst->obj; +// } else if (rand1 == 1) { +// dst = tagFindById(cmd[5]); +// goodpc->unk06 = dst->unk06; +// goodpc->obj = dst->obj; +// } else if (rand1 == 2) { +// dst = tagFindById(cmd[6]); +// goodpc->unk06 = dst->unk06; +// goodpc->obj = dst->obj; +// } else { +// dst = tagFindById(cmd[7]); +// goodpc->unk06 = dst->unk06; +// goodpc->obj = dst->obj; +// } +// +// // Handle both good and alarm terminals having the same destination +// if (rand2 == rand1 && rand2 > 0) { +// rand2--; +// } else if (rand2 == rand1 && rand2 < 3) { +// rand2++; +// } +// +// // Place the alarm terminal +// if (rand2 == 0) { +// dst = tagFindById(cmd[4]); +// badpc->unk06 = dst->unk06; +// badpc->obj = dst->obj; +// } else if (rand2 == 1) { +// dst = tagFindById(cmd[5]); +// badpc->unk06 = dst->unk06; +// badpc->obj = dst->obj; +// } else if (rand2 == 2) { +// dst = tagFindById(cmd[6]); +// badpc->unk06 = dst->unk06; +// badpc->obj = dst->obj; +// } else { +// dst = tagFindById(cmd[7]); +// badpc->unk06 = dst->unk06; +// badpc->obj = dst->obj; +// } +// } +// +// g_Vars.aioffset += 9; +// +// return false; +//} + /** * @cmd 0142 */ diff --git a/src/include/game/chr/chraicommands.h b/src/include/game/chr/chraicommands.h index d4e6b974b..b6ef6e556 100644 --- a/src/include/game/chr/chraicommands.h +++ b/src/include/game/chr/chraicommands.h @@ -319,7 +319,7 @@ /*0x013e*/ bool ai013e(void); /*0x013f*/ bool ai013f(void); /*0x0140*/ bool ai0140(void); -/*0x0141*/ bool ai0141(void); +/*0x0141*/ bool aiShuffleInvestigationTerminals(void); /*0x0142*/ bool ai0142(void); /*0x0143*/ bool ai0143(void); /*0x0144*/ bool ai0144(void); diff --git a/src/include/types.h b/src/include/types.h index 8d20105cf..bdf851f52 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -249,7 +249,7 @@ struct defaultobj { /*0x02*/ u8 hidden2; /*0x03*/ u8 type; /*0x04*/ u16 obj; - /*0x06*/ u16 pad; + /*0x06*/ s16 pad; /*0x08*/ u32 flags; /*0x0c*/ u32 flags2; /*0x10*/ u32 flags3; diff --git a/src/setup/setup_000000.c b/src/setup/setup_000000.c index 043bd7747..50146b5e1 100644 --- a/src/setup/setup_000000.c +++ b/src/setup/setup_000000.c @@ -14274,7 +14274,7 @@ bool (*command_pointers[])(void) = { /*0x013e*/ ai013e, /*0x013f*/ ai013f, /*0x0140*/ ai0140, - /*0x0141*/ ai0141, + /*0x0141*/ aiShuffleInvestigationTerminals, /*0x0142*/ ai0142, /*0x0143*/ ai0143, /*0x0144*/ ai0144,