diff --git a/configure.py b/configure.py index 45007aa6..c820da69 100644 --- a/configure.py +++ b/configure.py @@ -344,7 +344,7 @@ def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]: Object(NonMatching, "SB/Game/zCutsceneMgr.cpp"), Object(NonMatching, "SB/Game/zDispatcher.cpp"), Object(NonMatching, "SB/Game/zEGenerator.cpp"), - Object(NonMatching, "SB/Game/zEnt.cpp"), + Object(Equivalent, "SB/Game/zEnt.cpp"), Object(Equivalent, "SB/Game/zEntButton.cpp"), Object(NonMatching, "SB/Game/zEntCruiseBubble.cpp"), Object(NonMatching, "SB/Game/zEntDestructObj.cpp"), diff --git a/src/SB/Game/zEnt.cpp b/src/SB/Game/zEnt.cpp index 0c20077e..e22bb316 100644 --- a/src/SB/Game/zEnt.cpp +++ b/src/SB/Game/zEnt.cpp @@ -16,26 +16,6 @@ #include #include -extern _ShadowParams gShadowParams[5]; -extern U32 g_hash_xentanim[5]; -extern char* g_strz_xentanim[5]; - -extern xVec3 _1228; -extern char zEnt_strings[]; - -extern F32 _839_zEnt; -extern F32 _840_zEnt; -extern F32 _852_zEnt; -extern F32 _853_zEnt; -extern F32 _854_zEnt; -extern F32 _1032_zEnt; -extern F32 _1033_zEnt; -extern F32 _1039_zEnt; -extern F32 _1267_zEnt; -extern F32 _1268_zEnt; -extern F32 _1269_zEnt; -extern F32 _1270_zEnt; - void zEntInit(zEnt* ent, xEntAsset* asset, U32 type) { xEntInit(ent, asset); @@ -193,13 +173,13 @@ void zEntInit(zEnt* ent, xEntAsset* asset, U32 type) { ent->atbl = zAnimListGetTable(asset->animListID); xAnimPoolAlloc(&globals.sceneCur->mempool, ent, ent->atbl, ent->model); - xAnimState* ast = xAnimTableGetState(ent->atbl, zEnt_strings); + xAnimState* ast = xAnimTableGetState(ent->atbl, "idle"); if (ast != NULL) { xAnimSingle* single = ent->model->Anim->Single; single->State = ast; - single->Time = _839_zEnt; - single->CurrentSpeed = _840_zEnt; + single->Time = 0.0f; + single->CurrentSpeed = 1.0f; xModelEval(ent->model); } } @@ -222,18 +202,13 @@ void zEntSetup(zEnt* ent) checkpoint_collision_hack(ent); } -#ifdef NON_MATCHING -// This can't OK right now because it has static locals that are in zDispatcher.s +// Equivalent. Local static name mangling on model_id is unlike anything else seen in the project so far. +// It is reminiscent of namespace mangling. There is also a simple instruction swap involving setting the +// autogenerated init variable, which may be solved if this mangling thing is figured out. void checkpoint_collision_hack(zEnt* ent) { - static signed char init; - static U32 model_id; + static U32 model_id = xStrHash("checkpoint_bind"); - if (init == 0) - { - model_id = xStrHash(zEnt_strings + 5); - init = 1; - } if (ent->asset->modelInfoID == model_id) { ent->bound.type = 0x2; @@ -241,12 +216,12 @@ void checkpoint_collision_hack(zEnt* ent) xVec3* upper = &ent->bound.box.box.upper; *lower = *upper = xEntGetFrame(ent)->pos; - lower->x = lower->x + _852_zEnt; - lower->z = lower->z + _852_zEnt; + lower->x += -0.5f; + lower->z += -0.5f; - upper->x = upper->x + _853_zEnt; - upper->y = upper->y + _854_zEnt; - upper->z = upper->z + _853_zEnt; + upper->x += 0.5f; + upper->y += 5.0f; + upper->z += 0.5f; xEntDefaultBoundUpdate(ent, &xEntGetFrame(ent)->pos); @@ -261,7 +236,6 @@ void checkpoint_collision_hack(zEnt* ent) ent->asset->baseFlags = ent->asset->baseFlags & 0xffef; } } -#endif void zEntSave(zEnt* ent, xSerial* s) { @@ -279,23 +253,23 @@ void zEntReset(zEnt* ent) if (ent->asset->animListID != 0 && ent->atbl != NULL) { - xAnimState* ast = xAnimTableGetState(ent->atbl, zEnt_strings); + xAnimState* ast = xAnimTableGetState(ent->atbl, "idle"); if (ast != NULL) { xAnimSingle* single = ent->model->Anim->Single; single->State = ast; - single->Time = _839_zEnt; - single->CurrentSpeed = _840_zEnt; + single->Time = 0.0f; + single->CurrentSpeed = 1.0f; xModelEval(ent->model); } } if (!(ent->miscflags & 1) && ent->asset->modelInfoID != 0 && ent->model != NULL && ent->model->Anim != NULL && ent->model->Anim->Table != NULL && - strcmp(zEnt_strings + 21, ent->model->Anim->Table->Name) == 0) + strcmp("xEntAutoEventSimple", ent->model->Anim->Table->Name) == 0) { ent->model->Anim = ent->model->Anim; - xAnimPlaySetState(ent->model->Anim->Single, ent->model->Anim->Table->StateList, _839_zEnt); + xAnimPlaySetState(ent->model->Anim->Single, ent->model->Anim->Table->StateList, 0.0f); ent->miscflags = ent->miscflags | 1; } checkpoint_collision_hack(ent); @@ -315,8 +289,7 @@ void zEntEventAll(xBase* from, U32 fromEvent, U32 toEvent, F32* toParam) } } -void zEntEventAllOfType(xBase* from, U32 fromEvent, U32 toEvent, F32* toParam, - U32 type) +void zEntEventAllOfType(xBase* from, U32 fromEvent, U32 toEvent, F32* toParam, U32 type) { zScene* s = globals.sceneCur; if (s == NULL) @@ -339,8 +312,6 @@ void zEntEventAllOfType(U32 toEvent, U32 type) zEntEventAllOfType(NULL, 0, toEvent, NULL, type); } -#ifdef NON_MATCHING -// regalloc xModelInstance* zEntRecurseModelInfo(void* info, xEnt* ent) { xModelAssetInfo* zinfo = (xModelAssetInfo*)info; @@ -365,9 +336,8 @@ xModelInstance* zEntRecurseModelInfo(void* info, xEnt* ent) { if (i == 0) { - // tempInst[i] (r30) gets stored in r4 here temporarily instead of being accessed directly. - tempInst[i]->Next = xModelInstanceAlloc(imodel, ent, 0, 0, 0); - tempInst[i]->Next->modelID = zinst[i].ModelID; + tempInst[i] = xModelInstanceAlloc(imodel, ent, 0, 0, 0); + tempInst[i]->modelID = zinst[i].ModelID; while (imodel = iModelFile_RWMultiAtomic(imodel), imodel != NULL) { xModelInstanceAttach(xModelInstanceAlloc(imodel, ent, 0x2000, 0, NULL), @@ -394,7 +364,6 @@ xModelInstance* zEntRecurseModelInfo(void* info, xEnt* ent) } return tempInst[0]; } -#endif void zEntParseModelInfo(xEnt* ent, U32 assetID) { @@ -411,7 +380,6 @@ void zEntParseModelInfo(xEnt* ent, U32 assetID) } } -#ifdef NON_MATCHING // This function suffers from a couple floating point memes // Additionally it has a jumptable that needs to be generated in the correct place. void zEntAnimEvent(zEnt* ent, U32 animEvent, const F32* animParam) @@ -452,11 +420,11 @@ void zEntAnimEvent(zEnt* ent, U32 animEvent, const F32* animParam) char name[12]; if (animEvent == 0xc4) { - sprintf(name, zEnt_strings + 41, anum); + sprintf(name, "loop%d", anum); } else { - sprintf(name, zEnt_strings + 48, anum); + sprintf(name, "stop%d", anum); } xAnimState* ast = xAnimTableGetState(ent->atbl, name); @@ -470,17 +438,18 @@ void zEntAnimEvent(zEnt* ent, U32 animEvent, const F32* animParam) xAnimPlayUpdate(play, 0.0f); xAnimPlayEval(play); - if (ent->asset->modelInfoID != 0x8d398d0 || animEvent != 0xc3) + if (ent->asset->modelInfoID != 0x8D398D0C /*is this an address???*/ || + animEvent != 0xc3) { break; } - xSndPlay3D(xStrHash(zEnt_strings + 55), 0.77f, 0.0f, 0x80, 0, - (xVec3*)&ent->model->Mat->pos, 0.0f, SND_CAT_GAME, 0.0f); + xSndPlay3D(xStrHash("Check1"), 0.77f, 0.0f, 0x80, 0, (xVec3*)&ent->model->Mat->pos, + 0.0f, SND_CAT_GAME, 0.0f); break; case 0xc5: - if (strcmp(single->State->Name, zEnt_strings) == 0) + if (strcmp(single->State->Name, "idle") == 0) { break; } @@ -498,7 +467,7 @@ void zEntAnimEvent(zEnt* ent, U32 animEvent, const F32* animParam) single->CurrentSpeed = 1.0f; break; case 200: - if (single->CurrentSpeed != 0.0f) + if (single->CurrentSpeed) { single->CurrentSpeed = 0.0f; } @@ -525,7 +494,7 @@ void zEntAnimEvent(zEnt* ent, U32 animEvent, const F32* animParam) anum4 %= anum3; char name3[12]; - sprintf(name3, zEnt_strings + 48, anum2 + anum4); + sprintf(name3, "stop%d", anum2 + anum4); xAnimState* ast2 = xAnimTableGetState(ent->atbl, name3); if (ast2 == NULL) @@ -545,7 +514,7 @@ void zEntAnimEvent(zEnt* ent, U32 animEvent, const F32* animParam) } S32 anum5 = (int)*animParam - 1; - F32 prob = _1033_zEnt * animParam[1]; + F32 prob = 0.01f * animParam[1]; if (anum5 < 0 || anum5 >= 10) { break; @@ -555,7 +524,7 @@ void zEntAnimEvent(zEnt* ent, U32 animEvent, const F32* animParam) if (xurand() < prob && ent->atbl != NULL) { char name4[12]; - sprintf(name4, zEnt_strings + 41, anum5); + sprintf(name4, "stop%d", anum5); xAnimState* ast3 = xAnimTableGetState(ent->atbl, name4); if (ast3 == NULL) { @@ -571,9 +540,11 @@ void zEntAnimEvent(zEnt* ent, U32 animEvent, const F32* animParam) } } } -#endif -#ifdef NON_MATCHING +U32 g_hash_xentanim[5] = { 0 }; +char* g_strz_xentanim[5] = { + "Idle01", "Anim02", "Anim03", "Anim04", "Anim05", +}; // Thank you floating point memes. Very cool. xAnimTable* xEnt_AnimTable_AutoEventSmall() { @@ -588,19 +559,19 @@ xAnimTable* xEnt_AnimTable_AutoEventSmall() } } - xAnimTable* table = xAnimTableNew(zEnt_strings + 0x15, NULL, 0); + xAnimTable* table = xAnimTableNew("xEntAutoEventSimple", NULL, 0); for (S32 i = 0; i < 5; i++) { if (i == 0) { - xAnimTableNewState(table, names[i], 0x10, 1, _840_zEnt, NULL, NULL, _839_zEnt, NULL, - NULL, xAnimDefaultBeforeEnter, NULL, NULL); + xAnimTableNewState(table, names[i], 0x10, 1, 1.0f, NULL, NULL, 0.0f, NULL, NULL, + xAnimDefaultBeforeEnter, NULL, NULL); } else { - xAnimTableNewState(table, names[i], 0x20, 1, _840_zEnt, NULL, NULL, _839_zEnt, NULL, - NULL, xAnimDefaultBeforeEnter, NULL, NULL); + xAnimTableNewState(table, names[i], 0x20, 1, 1.0f, NULL, NULL, 0.0f, NULL, NULL, + xAnimDefaultBeforeEnter, NULL, NULL); } if (deftran != NULL) { @@ -610,16 +581,14 @@ xAnimTable* xEnt_AnimTable_AutoEventSmall() { if (i != 0) { - deftran = xAnimTableNewTransition(table, names[i], names[0], 0, 0, 0x10, 0, - _839_zEnt, _839_zEnt, 1, 0, _1039_zEnt, 0); + deftran = xAnimTableNewTransition(table, names[i], names[0], 0, 0, 0x10, 0, 0.0f, + 0.0f, 1, 0, 0.25f, 0); } } } return table; } -#endif -#ifdef NON_MATCHING // This function needs the floats to be replaced with literals // and the jumptable to be generated in the right spot. void zEntAnimEvent_AutoAnim(zEnt* ent, U32 animEvent, const F32* animParam) @@ -667,9 +636,9 @@ void zEntAnimEvent_AutoAnim(zEnt* ent, U32 animEvent, const F32* animParam) ast->Flags = ast->Flags & 0xffffffef; } } - xAnimPlaySetState(single, ast, _839_zEnt); - single->CurrentSpeed = _840_zEnt; - xAnimPlayUpdate(play, _839_zEnt); + xAnimPlaySetState(single, ast, 0.0f); + single->CurrentSpeed = 1.0f; + xAnimPlayUpdate(play, 0.0f); xAnimPlayEval(play); break; case 0xc5: @@ -682,26 +651,26 @@ void zEntAnimEvent_AutoAnim(zEnt* ent, U32 animEvent, const F32* animParam) xAnimState* ast2 = xAnimTableGetStateID(tab2, g_hash_xentanim[0]); if (ast2 != 0) { - xAnimPlaySetState(single, ast2, _839_zEnt); - single->CurrentSpeed = _839_zEnt; - xAnimPlayUpdate(play, _839_zEnt); + xAnimPlaySetState(single, ast2, 0.0f); + single->CurrentSpeed = 0.0f; + xAnimPlayUpdate(play, 0.0f); xAnimPlayEval(play); } break; case 0xc6: - single->CurrentSpeed = _839_zEnt; + single->CurrentSpeed = 0.0f; break; case 199: - single->CurrentSpeed = _840_zEnt; + single->CurrentSpeed = 1.0f; break; case 200: - if (single->CurrentSpeed > _839_zEnt) + if (single->CurrentSpeed > 0.0f) { - single->CurrentSpeed = _839_zEnt; + single->CurrentSpeed = 0.0f; } else { - single->CurrentSpeed = _840_zEnt; + single->CurrentSpeed = 1.0f; } break; case 0xc9: @@ -739,20 +708,19 @@ void zEntAnimEvent_AutoAnim(zEnt* ent, U32 animEvent, const F32* animParam) ast3->Flags = ast3->Flags | 0x20; ast3->Flags = ast3->Flags & 0xffffffef; } - xAnimPlaySetState(single, ast3, _839_zEnt); - single->CurrentSpeed = _840_zEnt; - xAnimPlayUpdate(play, _839_zEnt); + xAnimPlaySetState(single, ast3, 0.0f); + single->CurrentSpeed = 1.0f; + xAnimPlayUpdate(play, 0.0f); xAnimPlayEval(play); break; case 0xca: - if (xUtil_yesno(_1033_zEnt * animParam[1]) != 0) + if (xUtil_yesno(0.01f * animParam[1]) != 0) { zEntAnimEvent_AutoAnim(ent, 0xc3, animParam); } break; } } -#endif xModelAssetParam* zEntGetModelParams(U32 assetID, U32* size) { @@ -824,14 +792,14 @@ F32 zParamGetFloat(xModelAssetParam* param, U32 size, char* tok, F32 def) return def; } -S32 zParamGetFloatList(xModelAssetParam* param, U32 size, const char* tok, S32 count, - F32* def, F32* result) +S32 zParamGetFloatList(xModelAssetParam* param, U32 size, const char* tok, S32 count, F32* def, + F32* result) { return zParamGetFloatList(param, size, (char*)tok, count, def, result); } S32 zParamGetFloatList(xModelAssetParam* param, U32 size, char* tok, S32 count, F32* def, - F32* result) + F32* result) { char* str = zParamGetString(param, size, tok, NULL); S32 act = 0; @@ -851,8 +819,7 @@ S32 zParamGetFloatList(xModelAssetParam* param, U32 size, char* tok, S32 count, return act; } -S32 zParamGetVector(xModelAssetParam* param, U32 size, const char* tok, xVec3 vec1, - xVec3* vec2) +S32 zParamGetVector(xModelAssetParam* param, U32 size, const char* tok, xVec3 vec1, xVec3* vec2) { return zParamGetVector(param, size, (char*)tok, vec1, vec2); } @@ -862,10 +829,7 @@ S32 zParamGetVector(xModelAssetParam* param, U32 size, char* tok, xVec3 vec1, xV char* str = zParamGetString(param, size, tok, NULL); S32 list = 0; - xVec3 vec; - *(S32*)&vec.x = *(S32*)&_1228.x; - *(S32*)&vec.y = *(S32*)&_1228.y; - *(S32*)&vec.z = *(S32*)&_1228.z; + xVec3 vec = { 0 }; xVec3Copy(vec2, &vec1); if (str != NULL) @@ -889,6 +853,16 @@ S32 zParamGetVector(xModelAssetParam* param, U32 size, char* tok, xVec3 vec1, xV return list; } +// clang-format off +_ShadowParams gShadowParams[] = { + {'NTR0', 0.33f, 2.0f}, + {'NTR3', 0.0f, 1.25f}, + {'NTFA', -0.25f, 0.75f}, + {'NTR5', 0.5f, 1.0f}, + {'NTB0', 1.0f, 2.0f}, +}; +// clang-format on + void zEntGetShadowParams(xEnt* ent, xVec3* center, F32* radius, xEntShadow::radius_enum rtype) { *center = *xBoundCenter(&ent->bound); @@ -896,7 +870,7 @@ void zEntGetShadowParams(xEnt* ent, xVec3* center, F32* radius, xEntShadow::radi if (ent->entShadow != NULL) { r = ent->entShadow->radius[rtype]; - if (r > _839_zEnt) + if (r > 0.0f) { *radius = r; return; @@ -911,14 +885,14 @@ void zEntGetShadowParams(xEnt* ent, xVec3* center, F32* radius, xEntShadow::radi { xVec3* lower = &ent->bound.box.box.lower; xVec3* upper = &ent->bound.box.box.upper; - r = _1267_zEnt * (upper->x + upper->y + upper->z - lower->x - lower->y - lower->z); + r = 0.167f * (upper->x + upper->y + upper->z - lower->x - lower->y - lower->z); } - *radius = r < _1033_zEnt ? _1268_zEnt : _1269_zEnt * r; + *radius = r < 0.01f ? 2.0f : 2.4f * r; if (ent == &globals.player.ent) { - *radius = *radius * _1270_zEnt; + *radius *= 1.5f; } else if (ent->baseType == 0x2b) { @@ -948,10 +922,12 @@ xMat4x3* xEntGetFrame(const xEnt* ent) return xModelGetFrame(ent->model); } -void xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, - const xVec3* pos, F32 radius, sound_category category, F32 delay) +void xSndPlay3D(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, const xVec3* pos, F32 radius, + sound_category category, F32 delay) { - xSndPlay3D(id, vol, pitch, priority, flags, pos, radius * _1039_zEnt, radius, category, delay); + // This is UB to assign radius in the function call like this, but the assembly matches a *= + // so maybe HI made a mistake here. + xSndPlay3D(id, vol, pitch, priority, flags, pos, radius *= 0.25f, radius, category, delay); } S32 xNPCBasic::SelfType() const