From 1b9a77e8fea348bf67728ab2647354a317ca154f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 Dec 2020 12:14:38 +1000 Subject: [PATCH] Attempt to decompile chopperFireRocket --- src/game/bondhead.c | 44 ++++++++++++++++---------------- src/game/chr/chraction.c | 4 +-- src/game/game_00c490.c | 6 ++--- src/game/game_167ae0.c | 4 +-- src/game/propobj.c | 50 ++++++++++++++++++++++++++++++++----- src/include/game/propobj.h | 4 +-- src/include/lib/lib_159b0.h | 2 +- src/include/lib/lib_16110.h | 2 +- src/include/types.h | 27 +++----------------- 9 files changed, 81 insertions(+), 62 deletions(-) diff --git a/src/game/bondhead.c b/src/game/bondhead.c index 436e6218a..6f12ea264 100644 --- a/src/game/bondhead.c +++ b/src/game/bondhead.c @@ -163,7 +163,7 @@ void currentPlayerUpdateHead(f32 arg0, f32 arg1) func000159b0(&sp40); sp80.matrix = &sp40; - sp80.model0c = &g_Vars.currentplayer->unk0510; + sp80.unk10 = &g_Vars.currentplayer->unk0510; func0001cebc(&sp80, &g_Vars.currentplayer->model); g_Vars.currentplayer->headbodyoffset.x = g_Vars.currentplayer->standbodyoffset.x; @@ -172,35 +172,35 @@ void currentPlayerUpdateHead(f32 arg0, f32 arg1) modelGetRootPosition(&g_Vars.currentplayer->model, &modelpos); - modelpos.x -= g_Vars.currentplayer->unk0510.unk30; - modelpos.z -= g_Vars.currentplayer->unk0510.unk38; + modelpos.x -= g_Vars.currentplayer->unk0510.m[3][0]; + modelpos.z -= g_Vars.currentplayer->unk0510.m[3][2]; modelSetRootPosition(&g_Vars.currentplayer->model, &modelpos); } } if (animspeed > 0) { - g_Vars.currentplayer->unk0510.unk30 += arg1; - g_Vars.currentplayer->unk0510.unk38 *= arg0; + g_Vars.currentplayer->unk0510.m[3][0] += arg1; + g_Vars.currentplayer->unk0510.m[3][2] *= arg0; if (g_Vars.lvupdate240 > 0) { - g_Vars.currentplayer->unk0510.unk30 /= g_Vars.lvupdate240freal; - g_Vars.currentplayer->unk0510.unk38 /= g_Vars.lvupdate240freal; + g_Vars.currentplayer->unk0510.m[3][0] /= g_Vars.lvupdate240freal; + g_Vars.currentplayer->unk0510.m[3][2] /= g_Vars.lvupdate240freal; } - headpos.x = g_Vars.currentplayer->unk0510.unk30 * g_Vars.currentplayer->headamplitude; - headpos.y = (g_Vars.currentplayer->unk0510.unk34 - g_Vars.currentplayer->standheight) * + headpos.x = g_Vars.currentplayer->unk0510.m[3][0] * g_Vars.currentplayer->headamplitude; + headpos.y = (g_Vars.currentplayer->unk0510.m[3][1] - g_Vars.currentplayer->standheight) * g_Vars.currentplayer->headamplitude + g_Vars.currentplayer->standheight; - headpos.z = g_Vars.currentplayer->unk0510.unk38 * g_Vars.currentplayer->headamplitude; + headpos.z = g_Vars.currentplayer->unk0510.m[3][2] * g_Vars.currentplayer->headamplitude; if (g_Vars.currentplayer->headanim >= 0) { - lookvel.x = g_Vars.currentplayer->unk0510.unk20 * g_Vars.currentplayer->sideamplitude; - lookvel.y = g_Vars.currentplayer->unk0510.unk24 * g_Vars.currentplayer->headamplitude; - lookvel.z = (g_Vars.currentplayer->unk0510.unk28 - 1.0f) * g_Vars.currentplayer->headamplitude + 1.0f; + lookvel.x = g_Vars.currentplayer->unk0510.m[2][0] * g_Vars.currentplayer->sideamplitude; + lookvel.y = g_Vars.currentplayer->unk0510.m[2][1] * g_Vars.currentplayer->headamplitude; + lookvel.z = (g_Vars.currentplayer->unk0510.m[2][2] - 1.0f) * g_Vars.currentplayer->headamplitude + 1.0f; - upvel.x = g_Vars.currentplayer->unk0510.unk10 * g_Vars.currentplayer->headamplitude; - upvel.y = (g_Vars.currentplayer->unk0510.unk14 - 1.0f) * g_Vars.currentplayer->headamplitude + 1.0f; - upvel.z = g_Vars.currentplayer->unk0510.unk18 * g_Vars.currentplayer->headamplitude; + upvel.x = g_Vars.currentplayer->unk0510.m[1][0] * g_Vars.currentplayer->headamplitude; + upvel.y = (g_Vars.currentplayer->unk0510.m[1][1] - 1.0f) * g_Vars.currentplayer->headamplitude + 1.0f; + upvel.z = g_Vars.currentplayer->unk0510.m[1][2] * g_Vars.currentplayer->headamplitude; g_Vars.currentplayer->headwalkingtime60 += g_Vars.lvupdate240_60; @@ -210,13 +210,13 @@ void currentPlayerUpdateHead(f32 arg0, f32 arg1) currentPlayerSetHeadDamp(0.99748998880386f); } } else { - lookvel.x = g_Vars.currentplayer->unk0510.unk20; - lookvel.y = g_Vars.currentplayer->unk0510.unk24; - lookvel.z = g_Vars.currentplayer->unk0510.unk28; + lookvel.x = g_Vars.currentplayer->unk0510.m[2][0]; + lookvel.y = g_Vars.currentplayer->unk0510.m[2][1]; + lookvel.z = g_Vars.currentplayer->unk0510.m[2][2]; - upvel.x = g_Vars.currentplayer->unk0510.unk10; - upvel.y = g_Vars.currentplayer->unk0510.unk14; - upvel.z = g_Vars.currentplayer->unk0510.unk18; + upvel.x = g_Vars.currentplayer->unk0510.m[1][0]; + upvel.y = g_Vars.currentplayer->unk0510.m[1][1]; + upvel.z = g_Vars.currentplayer->unk0510.m[1][2]; currentPlayerSetHeadDamp(0.96f); } diff --git a/src/game/chr/chraction.c b/src/game/chr/chraction.c index a3ea96966..40de0fba8 100644 --- a/src/game/chr/chraction.c +++ b/src/game/chr/chraction.c @@ -17547,7 +17547,7 @@ glabel func0f041a74 /* f041ac8: afa20014 */ sw $v0,0x14($sp) /* f041acc: 2606002c */ addiu $a2,$s0,0x2c /* f041ad0: 26070044 */ addiu $a3,$s0,0x44 -/* f041ad4: 0fc244b7 */ jal func0f0912dc +/* f041ad4: 0fc244b7 */ jal projectileCreate /* f041ad8: afaa0010 */ sw $t2,0x10($sp) /* f041adc: 3c0b800a */ lui $t3,%hi(g_Vars+0x8) /* f041ae0: 8d6b9fc8 */ lw $t3,%lo(g_Vars+0x8)($t3) @@ -17580,7 +17580,7 @@ glabel func0f041a74 /* f041b44: afa20014 */ sw $v0,0x14($sp) /* f041b48: 26060038 */ addiu $a2,$s0,0x38 /* f041b4c: 26070050 */ addiu $a3,$s0,0x50 -/* f041b50: 0fc244b7 */ jal func0f0912dc +/* f041b50: 0fc244b7 */ jal projectileCreate /* f041b54: afac0010 */ sw $t4,0x10($sp) /* f041b58: 8e0d034c */ lw $t5,0x34c($s0) /* f041b5c: 8e0e0348 */ lw $t6,0x348($s0) diff --git a/src/game/game_00c490.c b/src/game/game_00c490.c index d63058064..f92372d36 100644 --- a/src/game/game_00c490.c +++ b/src/game/game_00c490.c @@ -1461,7 +1461,7 @@ void setupSingleMonitor(struct singlemonitorobj *monitor, s32 cmdindex) f32 scale; struct coord spa4; Mtxf sp64; - f32 sp24[16]; + Mtxf sp24; propLoad(modelnum); @@ -1498,8 +1498,8 @@ void setupSingleMonitor(struct singlemonitorobj *monitor, s32 cmdindex) spa4.y = -spa4.y; spa4.z = -spa4.z; - func000166dc(&spa4, sp24); - func00015be4(&sp64, (struct model0c *)sp24, (Mtxf *)&monitor->base.unk48->unk004); + func000166dc(&spa4, &sp24); + func00015be4(&sp64, &sp24, (Mtxf *)&monitor->base.unk48->unk004); } } else { setupGenericObject(&monitor->base, cmdindex); diff --git a/src/game/game_167ae0.c b/src/game/game_167ae0.c index 077d60365..98e6b5b28 100644 --- a/src/game/game_167ae0.c +++ b/src/game/game_167ae0.c @@ -1680,8 +1680,8 @@ Gfx *renderFrame(Gfx *gdl) direction.y = g_Vars.currentplayer->eyespy->look.y; direction.z = g_Vars.currentplayer->eyespy->look.z; - func0f0912dc(g_Vars.currentplayer->eyespy->prop, 0, - &g_Vars.currentplayer->eyespy->prop->pos, &direction, WEAPON_TRANQUILIZER, 0); + projectileCreate(g_Vars.currentplayer->eyespy->prop, 0, + &g_Vars.currentplayer->eyespy->prop->pos, &direction, WEAPON_TRANQUILIZER, NULL); } else { // No dart ammo audioStart(var80095200, 0x8052, 0, -1, -1, -1, -1, -1); diff --git a/src/game/propobj.c b/src/game/propobj.c index 8693982df..334de9e3e 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -24283,7 +24283,7 @@ glabel var7f1aa5d0 /* f07b3c8: 00002825 */ or $a1,$zero,$zero /* f07b3cc: 27a600b8 */ addiu $a2,$sp,0xb8 /* f07b3d0: 27a700c4 */ addiu $a3,$sp,0xc4 -/* f07b3d4: 0fc244b7 */ jal func0f0912dc +/* f07b3d4: 0fc244b7 */ jal projectileCreate /* f07b3d8: afb10014 */ sw $s1,0x14($sp) /* f07b3dc: 8fbf0024 */ lw $ra,0x24($sp) .L0f07b3e0: @@ -24293,6 +24293,44 @@ glabel var7f1aa5d0 /* f07b3ec: 27bd00d0 */ addiu $sp,$sp,0xd0 ); +// Mismatch: Regalloc and swapped lwc1 instructions for second pos calculations +//void chopperFireRocket(struct chopperobj *chopper, bool side) +//{ +// if (chopper->ontarget) { +// struct coord direction; // c4 +// struct coord pos; // b8 +// struct prop *targetprop = chopperGetTargetProp(chopper); +// struct prop *chopperprop = chopper->base.prop; +// u32 stack; +// Mtxf sp6c; +// Mtxf sp2c; +// +// pos.x = side ? -754 : 754; +// pos.y = -400; +// pos.z = -400; +// +// func00015d54(chopper->base.realrot, &sp2c); +// func000166dc(&pos, &sp6c); +// func000159fc(&sp2c, &sp6c); +// +// pos.x = sp6c.m[3][0] + chopperprop->pos.x; +// pos.y = sp6c.m[3][1] + chopperprop->pos.y; +// pos.z = sp6c.m[3][2] + chopperprop->pos.z; +// +// if (1); +// +// direction.x = targetprop->pos.x - pos.x; +// direction.y = targetprop->pos.y - pos.y + (s32)(random() % 100); +// direction.z = targetprop->pos.z - pos.z; +// +// scaleTo1(&direction.x, &direction.y, &direction.z); +// +// smokeCreateSimple(&pos, chopperprop->rooms, SMOKETYPE_3); +// +// projectileCreate(chopperprop, 0, &pos, &direction, WEAPON_ROCKETLAUNCHER, targetprop); +// } +//} + GLOBAL_ASM( glabel func0f07b3f0 .late_rodata @@ -24729,7 +24767,7 @@ glabel var7f1aa610 /* f07b9dc: e7a80104 */ swc1 $f8,0x104($sp) /* f07b9e0: 8e0500e0 */ lw $a1,0xe0($s0) /* f07b9e4: afab0010 */ sw $t3,0x10($sp) -/* f07b9e8: 0fc244b7 */ jal func0f0912dc +/* f07b9e8: 0fc244b7 */ jal projectileCreate /* f07b9ec: afac0014 */ sw $t4,0x14($sp) /* f07b9f0: 8fad00d4 */ lw $t5,0xd4($sp) /* f07b9f4: 240e0001 */ addiu $t6,$zero,0x1 @@ -28295,7 +28333,7 @@ s32 objTick(struct prop *prop) } sp556 = true; - sp476.model0c = gfxAllocate(model->unk08->unk0e * 64); + sp476.unk10 = gfxAllocate(model->unk08->unk0e * sizeof(Mtxf)); sp476.matrix = currentPlayerGetMatrix1740(); func0001cebc(&sp476, model); @@ -28393,7 +28431,7 @@ s32 objTick(struct prop *prop) func00015a00(currentPlayerGetMatrix1740(), &sp248, &sp152); sp556 = true; - sp312.model0c = gfxAllocate(model->unk08->unk0e * 64); + sp312.unk10 = gfxAllocate(model->unk08->unk0e * sizeof(Mtxf)); sp312.matrix = &sp152; func0001cebc(&sp312, model); @@ -28551,7 +28589,7 @@ s32 objTick(struct prop *prop) func0001cb0c(model, model->unk08->rootnode); } - prop->z = -model->unk0c->unk38; + prop->z = -model->unk0c->m[3][2]; func0f07063c(prop, sp572); child = prop->child; @@ -47818,7 +47856,7 @@ glabel func0f091250 ); GLOBAL_ASM( -glabel func0f0912dc +glabel projectileCreate .late_rodata glabel var7f1ab20c .word 0x481c4000 diff --git a/src/include/game/propobj.h b/src/include/game/propobj.h index 8984742ea..0317088f5 100644 --- a/src/include/game/propobj.h +++ b/src/include/game/propobj.h @@ -178,7 +178,7 @@ void chopperRestartTimer(struct chopperobj *obj); f32 chopperGetTimer(struct chopperobj *heli); void chopperSetMaxDamage(struct chopperobj *obj, u16 health); u32 func0f07b164(void); -u32 chopperFireRocket(struct chopperobj *obj, u32 arg1); +void chopperFireRocket(struct chopperobj *chopper, bool side); u32 func0f07b3f0(void); void func0f07ba38(struct prop *prop, f32 roty, f32 rotx, struct coord *coord, u32 arg4); void chopperTickAttackMode2(struct prop *chopper); @@ -343,7 +343,7 @@ void alarmTick(void); u32 func0f091030(void); void func0f0910ac(void); u32 func0f091250(void); -void func0f0912dc(struct prop *prop, u32 arg1, struct coord *source, struct coord *direction, u32 arg4, u32 arg5); +void projectileCreate(struct prop *fromprop, u32 arg1, struct coord *pos, struct coord *direction, s32 weaponnum, struct prop *targetprop); void objSetModelPartVisible(struct defaultobj *obj, s32 partnum, bool visible); #endif diff --git a/src/include/lib/lib_159b0.h b/src/include/lib/lib_159b0.h index 31a2b267c..6579a4583 100644 --- a/src/include/lib/lib_159b0.h +++ b/src/include/lib/lib_159b0.h @@ -11,7 +11,7 @@ void func00015b14(Mtxf *matrix, f32 *coord, struct coord *arg2); void func00015b64(Mtxf *arg0, struct coord *coord); void func00015b68(Mtxf *matrix, struct coord *arg1, struct coord *arg2); void func00015be0(Mtxf *matrix1, Mtxf *matrix2); -void func00015be4(Mtxf *arg0, struct model0c *model0c, Mtxf *arg2); +void func00015be4(Mtxf *arg0, Mtxf *arg1, Mtxf *arg2); void func00015cd8(f32 *arg0, f32 *realrot); u32 func00015d18(void); void func00015d54(f32 *realrot, Mtxf *matrix); diff --git a/src/include/lib/lib_16110.h b/src/include/lib/lib_16110.h index aba265ce4..fe0de2736 100644 --- a/src/include/lib/lib_16110.h +++ b/src/include/lib/lib_16110.h @@ -15,7 +15,7 @@ void func00016400(f32 angle, Mtxf *matrix); void func0001648c(struct coord *coord, Mtxf *dest); u32 func000165d8(void); u32 func000166a4(void); -void func000166dc(struct coord *pos, f32 *matrix); +void func000166dc(struct coord *pos, Mtxf *matrix); u32 func00016710(void); void func00016748(f32 arg0); u32 func00016760(void); diff --git a/src/include/types.h b/src/include/types.h index 4d34e175a..6543ef75e 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -285,31 +285,12 @@ struct model08 { // raw model file data f32 unk10; }; -struct model0c { // matrix - /*0x00*/ u32 unk00; - /*0x04*/ u32 unk04; - /*0x08*/ u32 unk08; - /*0x0c*/ u32 unk0c; - /*0x10*/ f32 unk10; - /*0x14*/ f32 unk14; - /*0x18*/ f32 unk18; - /*0x1c*/ u32 unk1c; - /*0x20*/ f32 unk20; - /*0x24*/ f32 unk24; - /*0x28*/ f32 unk28; - /*0x2c*/ u32 unk2c; - /*0x30*/ f32 unk30; - /*0x34*/ f32 unk34; - /*0x38*/ f32 unk38; - /*0x3c*/ u32 unk3c; -}; - struct model { /*0x00*/ u8 unk00; /*0x01*/ u8 unk01; /*0x04*/ struct chrdata *chr; /*0x08*/ struct model08 *unk08; - /*0x0c*/ struct model0c *unk0c; // matrix + /*0x0c*/ Mtxf *unk0c; /*0x10*/ void *datas; // array of pointers to modeldata structs /*0x14*/ f32 unk14; /*0x18*/ struct model *attachedto; @@ -1582,7 +1563,7 @@ struct chopperobj { // objtype 0x39 /*0x88*/ struct path *path; /*0x8c*/ s32 nextstep; /*0x90*/ s16 weaponsarmed; - /*0x92*/ u16 ontarget; + /*0x92*/ s16 ontarget; /*0x94*/ s16 target; /*0x96*/ u8 attackmode; /*0x97*/ u8 cw; @@ -2436,7 +2417,7 @@ struct player { /*0x0504*/ u32 unk0504; /*0x0508*/ u32 unk0508; /*0x050c*/ u32 unk050c; - /*0x0510*/ struct model0c unk0510; + /*0x0510*/ Mtxf unk0510; /*0x0550*/ u32 unk0550; /*0x0554*/ u32 unk0554; /*0x0558*/ u32 unk0558; @@ -5932,7 +5913,7 @@ struct objticksp476 { /*0x04*/ u32 unk04; /*0x08*/ u32 unk08; /*0x0c*/ u32 unk0c; - /*0x10*/ struct model0c *model0c; + /*0x10*/ Mtxf *unk10; /*0x14*/ u32 unk14; /*0x18*/ u32 unk18; /*0x1c*/ u32 unk1c;