From 032c5166f49a3d8b129a565df3555a08bfc48b25 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 19 Aug 2023 19:01:00 +1000 Subject: [PATCH] Fix improper casting of model rwdata --- src/game/bondgun.c | 4 +- src/game/menu.c | 6 +- src/game/modelmgr.c | 2 +- src/game/player.c | 4 +- src/game/vtxstore.c | 6 +- src/include/game/vtxstore.h | 2 +- src/include/lib/model.h | 2 +- src/include/types.h | 261 +----------------------------------- src/lib/model.c | 4 +- src/lib/modelasm_c.c | 4 +- 10 files changed, 20 insertions(+), 275 deletions(-) diff --git a/src/game/bondgun.c b/src/game/bondgun.c index 45bd3626d..6a733f5f5 100644 --- a/src/game/bondgun.c +++ b/src/game/bondgun.c @@ -4149,10 +4149,10 @@ void bgunTickMasterLoad(void) for (i = 0; i < 2; i++) { hand = &player->hands[i]; - modelInit(&hand->gunmodel, player->gunctrl.gunmodeldef, (union modelrwdata **)hand->unk0a6c, 0); + modelInit(&hand->gunmodel, player->gunctrl.gunmodeldef, hand->unk0a6c, 0); if (player->gunctrl.handmodeldef != 0) { - modelInit(&hand->handmodel, player->gunctrl.handmodeldef, (union modelrwdata **)hand->handsavedata, false); + modelInit(&hand->handmodel, player->gunctrl.handmodeldef, hand->handsavedata, false); } hand->unk0dcc = (s32 *) player->gunctrl.memloadptr; diff --git a/src/game/menu.c b/src/game/menu.c index 29371444f..7840aabb9 100644 --- a/src/game/menu.c +++ b/src/game/menu.c @@ -1825,7 +1825,7 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) modelAllocateRwData(thing->headmodeldef); } - modelInit(&thing->bodymodel, thing->bodymodeldef, &thing->unk110, true); + modelInit(&thing->bodymodel, thing->bodymodeldef, thing->unk110, true); animInit(&thing->bodyanim); thing->bodymodel.rwdatalen = 256; @@ -1844,7 +1844,7 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) fileGetLoadedSize(thing->unk00c); modelAllocateRwData(thing->bodymodeldef); - modelInit(&thing->bodymodel, thing->bodymodeldef, &thing->unk110, true); + modelInit(&thing->bodymodel, thing->bodymodeldef, thing->unk110, true); animInit(&thing->bodyanim); thing->bodymodel.rwdatalen = 256; @@ -2247,7 +2247,6 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) renderdata.unk00 = &thing->unk014; renderdata.unk10 = thing->bodymodel.matrices; - modelSetMatricesWithAnim(&renderdata, &thing->bodymodel); if (thing->bodymodeldef->skel == &g_SkelHudPiece) { @@ -2321,6 +2320,7 @@ Gfx *menuRenderModels(Gfx *gdl, struct menu840 *thing, s32 arg2) renderdata.gdl = gdl; renderdata.zbufferenabled = true; modelRender(&renderdata, &thing->bodymodel); + gdl = renderdata.gdl; mtx00016760(); diff --git a/src/game/modelmgr.c b/src/game/modelmgr.c index 0c57dc8c4..5251e8d58 100644 --- a/src/game/modelmgr.c +++ b/src/game/modelmgr.c @@ -105,7 +105,7 @@ void modelmgrPrintCounts(void) struct model *modelmgrInstantiateModel(struct modeldef *modeldef, bool withanim) { struct model *model = NULL; - union modelrwdata **rwdatas = NULL; + u32 *rwdatas = NULL; s16 datalen = -1; s32 i; diff --git a/src/game/player.c b/src/game/player.c index 76eb9b6bf..fcb9be6b8 100644 --- a/src/game/player.c +++ b/src/game/player.c @@ -1324,7 +1324,7 @@ void playerTickChrBody(void) s32 headnum = HEAD_DARK_COMBAT; bool sp60 = false; struct model *model = NULL; - union modelrwdata **rwdatas; + u32 *rwdatas; u32 stack3[2]; g_Vars.currentplayer->haschrbody = true; @@ -1372,7 +1372,7 @@ void playerTickChrBody(void) offset1 += sizeof(struct anim); offset1 = ALIGN64(offset1); - rwdatas = (union modelrwdata **)(allocation + offset1); + rwdatas = (u32 *)(allocation + offset1); osSyncPrintf("Gunmem: savedata 0x%08x\n", (uintptr_t)rwdatas); offset1 += 0x400; offset1 = ALIGN64(offset1); diff --git a/src/game/vtxstore.c b/src/game/vtxstore.c index 442ebc9f0..de494845e 100644 --- a/src/game/vtxstore.c +++ b/src/game/vtxstore.c @@ -46,7 +46,7 @@ struct vtxstoretype g_VtxstoreTypes[] = { * Search all props and their model data for something, and replace it with * something else. */ -void vtxstoreFixRefs(union modelrwdata *find, union modelrwdata *replacement) +void vtxstoreFixRefs(void *find, void *replacement) { u32 stack; struct prop *prop = g_Vars.activeprops; @@ -64,8 +64,8 @@ void vtxstoreFixRefs(union modelrwdata *find, union modelrwdata *replacement) case MODELNODETYPE_DL: rodata = &node->rodata->dl; - if (model->rwdatas[rodata->rwdataindex] == find) { - model->rwdatas[rodata->rwdataindex] = replacement; + if (model->rwdatas[rodata->rwdataindex] == (u32) find) { + model->rwdatas[rodata->rwdataindex] = (u32) replacement; } break; case MODELNODETYPE_DISTANCE: diff --git a/src/include/game/vtxstore.h b/src/include/game/vtxstore.h index 096003887..450fea2aa 100644 --- a/src/include/game/vtxstore.h +++ b/src/include/game/vtxstore.h @@ -6,7 +6,7 @@ void vtxstoreReset(void); -void vtxstoreFixRefs(union modelrwdata *find, union modelrwdata *replacement); +void vtxstoreFixRefs(void *find, void *replacement); void vtxstoreTick(void); void *vtxstoreAllocate(s32 count, s32 index, struct modelnode *node, s32 level); void vtxstoreFree(s32 type, void *arg1); diff --git a/src/include/lib/model.h b/src/include/lib/model.h index 271b70bfa..7994a2a36 100644 --- a/src/include/lib/model.h +++ b/src/include/lib/model.h @@ -101,7 +101,7 @@ void modelPromoteOffsetsToPointers(struct modeldef *modeldef, u32 arg1, uintptr_ s32 modelCalculateRwDataIndexes(struct modelnode *node); void modelAllocateRwData(struct modeldef *modeldef); void modelInitRwData(struct model *model, struct modelnode *node); -void modelInit(struct model *model, struct modeldef *modeldef, union modelrwdata **rwdatas, bool resetanim); +void modelInit(struct model *model, struct modeldef *modeldef, u32 *rwdatas, bool resetanim); void animInit(struct anim *anim); void modelAttachHead(struct model *model, struct modeldef *arg1, struct modelnode *node, struct modeldef *arg3); void modelIterateDisplayLists(struct modeldef *modeldef, struct modelnode **nodeptr, Gfx **gdlptr); diff --git a/src/include/types.h b/src/include/types.h index 24b6f1d56..74acdd7bf 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -607,7 +607,7 @@ struct model { }; /*0x08*/ struct modeldef *definition; /*0x0c*/ Mtxf *matrices; - /*0x10*/ union modelrwdata **rwdatas; + /*0x10*/ u32 *rwdatas; /*0x14*/ f32 scale; /*0x18*/ struct model *attachedtomodel; /*0x1c*/ struct modelnode *attachedtonode; @@ -2538,7 +2538,7 @@ struct player { /*0x0488*/ u8 *unk0488; // pointer to vtx buffer? /*0x048c*/ bool aborted; /*0x0490*/ s32 eyespydarts; - /*0x0494*/ union modelrwdata *bondheadsave[30]; + /*0x0494*/ u32 bondheadsave[30]; /*0x050c*/ u32 unk050c; /*0x0510*/ Mtxf bondheadmatrices[4]; /*0x0610*/ Vp viewport[NUM_FRAMEBUFFERS]; @@ -3830,262 +3830,7 @@ struct menu840 { /*0x05e*/ s16 unk05e; /*0x060*/ struct model bodymodel; /*0x084*/ struct anim bodyanim; - /*0x110*/ union modelrwdata *unk110; - /*0x114*/ u32 unk114; - /*0x118*/ u32 unk118; - /*0x11c*/ u32 unk11c; - /*0x120*/ u32 unk120; - /*0x124*/ u32 unk124; - /*0x128*/ u32 unk128; - /*0x12c*/ u32 unk12c; - /*0x130*/ u32 unk130; - /*0x134*/ u32 unk134; - /*0x138*/ u32 unk138; - /*0x13c*/ u32 unk13c; - /*0x140*/ u32 unk140; - /*0x144*/ u32 unk144; - /*0x148*/ u32 unk148; - /*0x14c*/ u32 unk14c; - /*0x150*/ u32 unk150; - /*0x154*/ u32 unk154; - /*0x158*/ u32 unk158; - /*0x15c*/ u32 unk15c; - /*0x160*/ u32 unk160; - /*0x164*/ u32 unk164; - /*0x168*/ u32 unk168; - /*0x16c*/ u32 unk16c; - /*0x170*/ u32 unk170; - /*0x174*/ u32 unk174; - /*0x178*/ u32 unk178; - /*0x17c*/ u32 unk17c; - /*0x180*/ u32 unk180; - /*0x184*/ u32 unk184; - /*0x188*/ u32 unk188; - /*0x18c*/ u32 unk18c; - /*0x190*/ u32 unk190; - /*0x194*/ u32 unk194; - /*0x198*/ u32 unk198; - /*0x19c*/ u32 unk19c; - /*0x1a0*/ u32 unk1a0; - /*0x1a4*/ u32 unk1a4; - /*0x1a8*/ u32 unk1a8; - /*0x1ac*/ u32 unk1ac; - /*0x1b0*/ u32 unk1b0; - /*0x1b4*/ u32 unk1b4; - /*0x1b8*/ u32 unk1b8; - /*0x1bc*/ u32 unk1bc; - /*0x1c0*/ u32 unk1c0; - /*0x1c4*/ u32 unk1c4; - /*0x1c8*/ u32 unk1c8; - /*0x1cc*/ u32 unk1cc; - /*0x1d0*/ u32 unk1d0; - /*0x1d4*/ u32 unk1d4; - /*0x1d8*/ u32 unk1d8; - /*0x1dc*/ u32 unk1dc; - /*0x1e0*/ u32 unk1e0; - /*0x1e4*/ u32 unk1e4; - /*0x1e8*/ u32 unk1e8; - /*0x1ec*/ u32 unk1ec; - /*0x1f0*/ u32 unk1f0; - /*0x1f4*/ u32 unk1f4; - /*0x1f8*/ u32 unk1f8; - /*0x1fc*/ u32 unk1fc; - /*0x200*/ u32 unk200; - /*0x204*/ u32 unk204; - /*0x208*/ u32 unk208; - /*0x20c*/ u32 unk20c; - /*0x210*/ u32 unk210; - /*0x214*/ u32 unk214; - /*0x218*/ u32 unk218; - /*0x21c*/ u32 unk21c; - /*0x220*/ u32 unk220; - /*0x224*/ u32 unk224; - /*0x228*/ u32 unk228; - /*0x22c*/ u32 unk22c; - /*0x230*/ u32 unk230; - /*0x234*/ u32 unk234; - /*0x238*/ u32 unk238; - /*0x23c*/ u32 unk23c; - /*0x240*/ u32 unk240; - /*0x244*/ u32 unk244; - /*0x248*/ u32 unk248; - /*0x24c*/ u32 unk24c; - /*0x250*/ u32 unk250; - /*0x254*/ u32 unk254; - /*0x258*/ u32 unk258; - /*0x25c*/ u32 unk25c; - /*0x260*/ u32 unk260; - /*0x264*/ u32 unk264; - /*0x268*/ u32 unk268; - /*0x26c*/ u32 unk26c; - /*0x270*/ u32 unk270; - /*0x274*/ u32 unk274; - /*0x278*/ u32 unk278; - /*0x27c*/ u32 unk27c; - /*0x280*/ u32 unk280; - /*0x284*/ u32 unk284; - /*0x288*/ u32 unk288; - /*0x28c*/ u32 unk28c; - /*0x290*/ u32 unk290; - /*0x294*/ u32 unk294; - /*0x298*/ u32 unk298; - /*0x29c*/ u32 unk29c; - /*0x2a0*/ u32 unk2a0; - /*0x2a4*/ u32 unk2a4; - /*0x2a8*/ u32 unk2a8; - /*0x2ac*/ u32 unk2ac; - /*0x2b0*/ u32 unk2b0; - /*0x2b4*/ u32 unk2b4; - /*0x2b8*/ u32 unk2b8; - /*0x2bc*/ u32 unk2bc; - /*0x2c0*/ u32 unk2c0; - /*0x2c4*/ u32 unk2c4; - /*0x2c8*/ u32 unk2c8; - /*0x2cc*/ u32 unk2cc; - /*0x2d0*/ u32 unk2d0; - /*0x2d4*/ u32 unk2d4; - /*0x2d8*/ u32 unk2d8; - /*0x2dc*/ u32 unk2dc; - /*0x2e0*/ u32 unk2e0; - /*0x2e4*/ u32 unk2e4; - /*0x2e8*/ u32 unk2e8; - /*0x2ec*/ u32 unk2ec; - /*0x2f0*/ u32 unk2f0; - /*0x2f4*/ u32 unk2f4; - /*0x2f8*/ u32 unk2f8; - /*0x2fc*/ u32 unk2fc; - /*0x300*/ u32 unk300; - /*0x304*/ u32 unk304; - /*0x308*/ u32 unk308; - /*0x30c*/ u32 unk30c; - /*0x310*/ u32 unk310; - /*0x314*/ u32 unk314; - /*0x318*/ u32 unk318; - /*0x31c*/ u32 unk31c; - /*0x320*/ u32 unk320; - /*0x324*/ u32 unk324; - /*0x328*/ u32 unk328; - /*0x32c*/ u32 unk32c; - /*0x330*/ u32 unk330; - /*0x334*/ u32 unk334; - /*0x338*/ u32 unk338; - /*0x33c*/ u32 unk33c; - /*0x340*/ u32 unk340; - /*0x344*/ u32 unk344; - /*0x348*/ u32 unk348; - /*0x34c*/ u32 unk34c; - /*0x350*/ u32 unk350; - /*0x354*/ u32 unk354; - /*0x358*/ u32 unk358; - /*0x35c*/ u32 unk35c; - /*0x360*/ u32 unk360; - /*0x364*/ u32 unk364; - /*0x368*/ u32 unk368; - /*0x36c*/ u32 unk36c; - /*0x370*/ u32 unk370; - /*0x374*/ u32 unk374; - /*0x378*/ u32 unk378; - /*0x37c*/ u32 unk37c; - /*0x380*/ u32 unk380; - /*0x384*/ u32 unk384; - /*0x388*/ u32 unk388; - /*0x38c*/ u32 unk38c; - /*0x390*/ u32 unk390; - /*0x394*/ u32 unk394; - /*0x398*/ u32 unk398; - /*0x39c*/ u32 unk39c; - /*0x3a0*/ u32 unk3a0; - /*0x3a4*/ u32 unk3a4; - /*0x3a8*/ u32 unk3a8; - /*0x3ac*/ u32 unk3ac; - /*0x3b0*/ u32 unk3b0; - /*0x3b4*/ u32 unk3b4; - /*0x3b8*/ u32 unk3b8; - /*0x3bc*/ u32 unk3bc; - /*0x3c0*/ u32 unk3c0; - /*0x3c4*/ u32 unk3c4; - /*0x3c8*/ u32 unk3c8; - /*0x3cc*/ u32 unk3cc; - /*0x3d0*/ u32 unk3d0; - /*0x3d4*/ u32 unk3d4; - /*0x3d8*/ u32 unk3d8; - /*0x3dc*/ u32 unk3dc; - /*0x3e0*/ u32 unk3e0; - /*0x3e4*/ u32 unk3e4; - /*0x3e8*/ u32 unk3e8; - /*0x3ec*/ u32 unk3ec; - /*0x3f0*/ u32 unk3f0; - /*0x3f4*/ u32 unk3f4; - /*0x3f8*/ u32 unk3f8; - /*0x3fc*/ u32 unk3fc; - /*0x400*/ u32 unk400; - /*0x404*/ u32 unk404; - /*0x408*/ u32 unk408; - /*0x40c*/ u32 unk40c; - /*0x410*/ u32 unk410; - /*0x414*/ u32 unk414; - /*0x418*/ u32 unk418; - /*0x41c*/ u32 unk41c; - /*0x420*/ u32 unk420; - /*0x424*/ u32 unk424; - /*0x428*/ u32 unk428; - /*0x42c*/ u32 unk42c; - /*0x430*/ u32 unk430; - /*0x434*/ u32 unk434; - /*0x438*/ u32 unk438; - /*0x43c*/ u32 unk43c; - /*0x440*/ u32 unk440; - /*0x444*/ u32 unk444; - /*0x448*/ u32 unk448; - /*0x44c*/ u32 unk44c; - /*0x450*/ u32 unk450; - /*0x454*/ u32 unk454; - /*0x458*/ u32 unk458; - /*0x45c*/ u32 unk45c; - /*0x460*/ u32 unk460; - /*0x464*/ u32 unk464; - /*0x468*/ u32 unk468; - /*0x46c*/ u32 unk46c; - /*0x470*/ u32 unk470; - /*0x474*/ u32 unk474; - /*0x478*/ u32 unk478; - /*0x47c*/ u32 unk47c; - /*0x480*/ u32 unk480; - /*0x484*/ u32 unk484; - /*0x488*/ u32 unk488; - /*0x48c*/ u32 unk48c; - /*0x490*/ u32 unk490; - /*0x494*/ u32 unk494; - /*0x498*/ u32 unk498; - /*0x49c*/ u32 unk49c; - /*0x4a0*/ u32 unk4a0; - /*0x4a4*/ u32 unk4a4; - /*0x4a8*/ u32 unk4a8; - /*0x4ac*/ u32 unk4ac; - /*0x4b0*/ u32 unk4b0; - /*0x4b4*/ u32 unk4b4; - /*0x4b8*/ u32 unk4b8; - /*0x4bc*/ u32 unk4bc; - /*0x4c0*/ u32 unk4c0; - /*0x4c4*/ u32 unk4c4; - /*0x4c8*/ u32 unk4c8; - /*0x4cc*/ u32 unk4cc; - /*0x4d0*/ u32 unk4d0; - /*0x4d4*/ u32 unk4d4; - /*0x4d8*/ u32 unk4d8; - /*0x4dc*/ u32 unk4dc; - /*0x4e0*/ u32 unk4e0; - /*0x4e4*/ u32 unk4e4; - /*0x4e8*/ u32 unk4e8; - /*0x4ec*/ u32 unk4ec; - /*0x4f0*/ u32 unk4f0; - /*0x4f4*/ u32 unk4f4; - /*0x4f8*/ u32 unk4f8; - /*0x4fc*/ u32 unk4fc; - /*0x500*/ u32 unk500; - /*0x504*/ u32 unk504; - /*0x508*/ u32 unk508; - /*0x50c*/ u32 unk50c; + /*0x110*/ u32 unk110[256]; /*0x510*/ f32 unk510; /*0x514*/ f32 unk514; /*0x518*/ f32 unk518; diff --git a/src/lib/model.c b/src/lib/model.c index 152dd52bb..f9a2a42ef 100644 --- a/src/lib/model.c +++ b/src/lib/model.c @@ -383,7 +383,7 @@ f32 modelGetScreenDistance(struct model *model) void *modelGetNodeRwData(struct model *model, struct modelnode *node) { u32 index = 0; - union modelrwdata **rwdatas = model->rwdatas; + u32 *rwdatas = model->rwdatas; switch (node->type & 0xff) { case MODELNODETYPE_CHRINFO: @@ -4181,7 +4181,7 @@ void modelInitRwData(struct model *model, struct modelnode *startnode) } } -void modelInit(struct model *model, struct modeldef *modeldef, union modelrwdata **rwdatas, bool resetanim) +void modelInit(struct model *model, struct modeldef *modeldef, u32 *rwdatas, bool resetanim) { struct modelnode *node; diff --git a/src/lib/modelasm_c.c b/src/lib/modelasm_c.c index a85a4952f..d0e9f3f82 100644 --- a/src/lib/modelasm_c.c +++ b/src/lib/modelasm_c.c @@ -1166,7 +1166,7 @@ u8 var8005ef90[] = { static union modelrwdata *modelasmGetNodeRwData(struct model *model, struct modelnode *node, bool is_head) { u32 index = 0; - union modelrwdata **rwdatas = model->rwdatas; + u32 *rwdatas = model->rwdatas; u8 type = node->type & 0xff; if (type < ARRAYCOUNT(var8005ef90)) { @@ -1194,7 +1194,7 @@ static union modelrwdata *modelasmGetNodeRwData(struct model *model, struct mode void *modelGetNodeRwData(struct model *model, struct modelnode *node) { u32 index = 0; - union modelrwdata **rwdatas = model->rwdatas; + u32 *rwdatas = model->rwdatas; u8 type = node->type & 0xff; if (type < ARRAYCOUNT(var8005ef90)) {