From cf7d4bc8d26f7d53dbace9e1dc259845f06e5a9e Mon Sep 17 00:00:00 2001 From: MysterD Date: Thu, 18 May 2023 21:29:57 -0700 Subject: [PATCH] Prevent deduplication of area models - it would overwrite the areaIndex --- data/dynos.c.h | 2 +- data/dynos.cpp.h | 2 +- data/dynos_c.cpp | 4 ++-- data/dynos_mgr_actor.cpp | 4 ++-- data/dynos_mgr_models.cpp | 12 ++++++------ data/dynos_mgr_pack.cpp | 2 +- src/engine/level_script.c | 4 ++-- src/pc/lua/utils/smlua_model_utils.c | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/data/dynos.c.h b/data/dynos.c.h index 5524a766..7bbb015c 100644 --- a/data/dynos.c.h +++ b/data/dynos.c.h @@ -72,7 +72,7 @@ const char *dynos_behavior_get_token(BehaviorScript *bhvScript, u32 index); void dynos_behavior_hook_all_custom_behaviors(void); // -- models -- // -struct GraphNode* dynos_model_load_geo(u32* aId, enum ModelPool aModelPool, void* aAsset); +struct GraphNode* dynos_model_load_geo(u32* aId, enum ModelPool aModelPool, void* aAsset, bool aDeDuplicate); struct GraphNode* dynos_model_load_dl(u32* aId, enum ModelPool aModelPool, u8 aLayer, void* aAsset); struct GraphNode* dynos_model_store_geo(u32* aId, enum ModelPool aModelPool, void* aAsset, struct GraphNode* aGraphNode); struct GraphNode* dynos_model_get_geo(u32 aId); diff --git a/data/dynos.cpp.h b/data/dynos.cpp.h index e95a3f4c..70525223 100644 --- a/data/dynos.cpp.h +++ b/data/dynos.cpp.h @@ -963,7 +963,7 @@ void DynOS_MovtexQC_ModShutdown(); // Model Manager // -struct GraphNode* DynOS_Model_LoadGeo(u32* aId, enum ModelPool aModelPool, void* aAsset); +struct GraphNode* DynOS_Model_LoadGeo(u32* aId, enum ModelPool aModelPool, void* aAsset, bool aDeDuplicate); struct GraphNode* DynOS_Model_LoadDl(u32* aId, enum ModelPool aModelPool, u8 aLayer, void* aAsset); struct GraphNode* DynOS_Model_StoreGeo(u32* aId, enum ModelPool aModelPool, void* aAsset, struct GraphNode* aGraphNode); struct GraphNode* DynOS_Model_GetGeo(u32 aId); diff --git a/data/dynos_c.cpp b/data/dynos_c.cpp index 069b02de..c223b033 100644 --- a/data/dynos_c.cpp +++ b/data/dynos_c.cpp @@ -225,8 +225,8 @@ void dynos_behavior_hook_all_custom_behaviors(void) { // -- models -- // -struct GraphNode* dynos_model_load_geo(u32* aId, enum ModelPool aModelPool, void* aAsset) { - return DynOS_Model_LoadGeo(aId, aModelPool, aAsset); +struct GraphNode* dynos_model_load_geo(u32* aId, enum ModelPool aModelPool, void* aAsset, bool aDeDuplicate) { + return DynOS_Model_LoadGeo(aId, aModelPool, aAsset, aDeDuplicate); } struct GraphNode* dynos_model_load_dl(u32* aId, enum ModelPool aModelPool, u8 aLayer, void* aAsset) { diff --git a/data/dynos_mgr_actor.cpp b/data/dynos_mgr_actor.cpp index 890e5b06..d00d5128 100644 --- a/data/dynos_mgr_actor.cpp +++ b/data/dynos_mgr_actor.cpp @@ -50,7 +50,7 @@ void DynOS_Actor_AddCustom(const SysPath &aFilename, const char *aActorName) { ActorGfx actorGfx = { }; actorGfx.mGfxData = _GfxData; actorGfx.mPackIndex = MOD_PACK_INDEX; - actorGfx.mGraphNode = (GraphNode *) DynOS_Model_LoadGeo(&id, MODEL_POOL_SESSION, geoLayout); + actorGfx.mGraphNode = (GraphNode *) DynOS_Model_LoadGeo(&id, MODEL_POOL_SESSION, geoLayout, true); if (!actorGfx.mGraphNode) { Print(" ERROR: Couldn't load graph node for \"%s\"", actorName); free(actorName); @@ -170,7 +170,7 @@ void DynOS_Actor_Override_All(void) { if (_Object->header.gfx.sharedChild != NULL && _Object->header.gfx.sharedChild->georef != NULL) { GraphNode* georef = (GraphNode*)_Object->header.gfx.sharedChild->georef; u32 id = 0; - _Object->header.gfx.sharedChild = DynOS_Model_LoadGeo(&id, MODEL_POOL_PERMANENT, georef); + _Object->header.gfx.sharedChild = DynOS_Model_LoadGeo(&id, MODEL_POOL_PERMANENT, georef, true); } DynOS_Actor_Override((void**)&_Object->header.gfx.sharedChild); } diff --git a/data/dynos_mgr_models.cpp b/data/dynos_mgr_models.cpp index 52fefbf4..53ba9578 100644 --- a/data/dynos_mgr_models.cpp +++ b/data/dynos_mgr_models.cpp @@ -53,7 +53,7 @@ void DynOS_Model_Dump() { } } -struct GraphNode* DynOS_Model_LoadCommon(u32* aId, enum ModelPool aModelPool, void* aAsset, u8 aLayer, struct GraphNode* aGraphNode, enum ModelLoadType mlt) { +struct GraphNode* DynOS_Model_LoadCommon(u32* aId, enum ModelPool aModelPool, void* aAsset, u8 aLayer, struct GraphNode* aGraphNode, bool aDeDuplicate, enum ModelLoadType mlt) { // sanity check pool if (aModelPool >= MODEL_POOL_MAX) { return NULL; } @@ -64,7 +64,7 @@ struct GraphNode* DynOS_Model_LoadCommon(u32* aId, enum ModelPool aModelPool, vo // check map auto& map = sAssetMap[aModelPool]; - if (map.count(aAsset)) { + if (aDeDuplicate && map.count(aAsset)) { auto& found = map[aAsset]; if (*aId && *aId != found.id) { sOverwriteMap[*aId] = found.id; @@ -106,16 +106,16 @@ struct GraphNode* DynOS_Model_LoadCommon(u32* aId, enum ModelPool aModelPool, vo return node; } -struct GraphNode* DynOS_Model_LoadGeo(u32* aId, enum ModelPool aModelPool, void* aAsset) { - return DynOS_Model_LoadCommon(aId, aModelPool, aAsset, 0, NULL, MLT_GEO); +struct GraphNode* DynOS_Model_LoadGeo(u32* aId, enum ModelPool aModelPool, void* aAsset, bool aDeDuplicate) { + return DynOS_Model_LoadCommon(aId, aModelPool, aAsset, 0, NULL, aDeDuplicate, MLT_GEO); } struct GraphNode* DynOS_Model_LoadDl(u32* aId, enum ModelPool aModelPool, u8 aLayer, void* aAsset) { - return DynOS_Model_LoadCommon(aId, aModelPool, aAsset, aLayer, NULL, MLT_DL); + return DynOS_Model_LoadCommon(aId, aModelPool, aAsset, aLayer, NULL, true, MLT_DL); } struct GraphNode* DynOS_Model_StoreGeo(u32* aId, enum ModelPool aModelPool, void* aAsset, struct GraphNode* aGraphNode) { - return DynOS_Model_LoadCommon(aId, aModelPool, aAsset, 0, aGraphNode, MLT_STORE); + return DynOS_Model_LoadCommon(aId, aModelPool, aAsset, 0, aGraphNode, true, MLT_STORE); } struct GraphNode* DynOS_Model_GetErrorGeo() { diff --git a/data/dynos_mgr_pack.cpp b/data/dynos_mgr_pack.cpp index fa30be75..a9715a7c 100644 --- a/data/dynos_mgr_pack.cpp +++ b/data/dynos_mgr_pack.cpp @@ -43,7 +43,7 @@ static void DynOS_Pack_ActivateActor(s32 aPackIndex, PairmGeoLayouts.end() - 1); u32 id = 0; - GraphNode* graphNode = DynOS_Model_LoadGeo(&id, MODEL_POOL_PERMANENT, geoNode->mData); + GraphNode* graphNode = DynOS_Model_LoadGeo(&id, MODEL_POOL_PERMANENT, geoNode->mData, true); if (graphNode == NULL) { return; } const void* georef = DynOS_Builtin_Actor_GetFromName(aActorName); diff --git a/src/engine/level_script.c b/src/engine/level_script.c index 1f24f0e2..4f351d18 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -423,7 +423,7 @@ static void level_cmd_begin_area(void) { if (areaIndex < 8) { u32 id = 0; - struct GraphNodeRoot *screenArea = (struct GraphNodeRoot *) dynos_model_load_geo(&id, MODEL_POOL_LEVEL, geoLayoutAddr); + struct GraphNodeRoot *screenArea = (struct GraphNodeRoot *) dynos_model_load_geo(&id, MODEL_POOL_LEVEL, geoLayoutAddr, false); struct GraphNodeCamera *node = (struct GraphNodeCamera *) screenArea->views[0]; sCurrAreaIndex = areaIndex; @@ -464,7 +464,7 @@ static void level_cmd_load_model_from_geo(void) { void *arg1 = CMD_GET(void *, 4); u32 id = arg0; - dynos_model_load_geo(&id, sFinishedLoadingPerm ? MODEL_POOL_LEVEL : MODEL_POOL_PERMANENT, arg1); + dynos_model_load_geo(&id, sFinishedLoadingPerm ? MODEL_POOL_LEVEL : MODEL_POOL_PERMANENT, arg1, true); sCurrentCmd = CMD_NEXT; } diff --git a/src/pc/lua/utils/smlua_model_utils.c b/src/pc/lua/utils/smlua_model_utils.c index 794bf5ad..f27839a5 100644 --- a/src/pc/lua/utils/smlua_model_utils.c +++ b/src/pc/lua/utils/smlua_model_utils.c @@ -488,7 +488,7 @@ u16 smlua_model_util_load(enum ModelExtendedId extId) { if (info->isDisplayList) { dynos_model_load_dl(&id, MODEL_POOL_SESSION, info->layer, (void*)info->asset); } else { - dynos_model_load_geo(&id, MODEL_POOL_SESSION, (void*)info->asset); + dynos_model_load_geo(&id, MODEL_POOL_SESSION, (void*)info->asset, true); } return (u16)id; }