From 04ae492e8be762e0efa45cabe01f7298e78d20ee Mon Sep 17 00:00:00 2001 From: PeachyPeach <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Sun, 27 Apr 2025 23:22:58 +0200 Subject: [PATCH] Fix obj_get_model_id_extended returning wrong model ids (#757) --- src/pc/lua/utils/smlua_model_utils.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/pc/lua/utils/smlua_model_utils.c b/src/pc/lua/utils/smlua_model_utils.c index 759f4d227..1437c00d7 100644 --- a/src/pc/lua/utils/smlua_model_utils.c +++ b/src/pc/lua/utils/smlua_model_utils.c @@ -504,12 +504,22 @@ u16 smlua_model_util_load(enum ModelExtendedId extId) { return (u16)id; } +static void smlua_model_util_unregister_model_id(u32 id, struct ModelUtilsInfo *models, u32 count) { + for (u32 i = 0; i < count; i++) { + struct ModelUtilsInfo *m = &models[i]; + if (m->loadedId == id) { + m->loadedId = UNLOADED_ID; + } + } +} + // Links the regular model id created by DynOS to our models list void smlua_model_util_register_model_id(u32 id, const void *asset) { if (id < VANILLA_ID_END) { for (u32 i = 0; i < E_MODEL_MAX; i++) { struct ModelUtilsInfo* m = &sModels[i]; if (m->asset == asset) { + smlua_model_util_unregister_model_id(id, sModels, E_MODEL_MAX); m->loadedId = id; return; } @@ -518,6 +528,7 @@ void smlua_model_util_register_model_id(u32 id, const void *asset) { for (u32 i = 0; i < sCustomModelsCount; i++) { struct ModelUtilsInfo* m = &sCustomModels[i]; if (m->asset == asset) { + smlua_model_util_unregister_model_id(id, sCustomModels, sCustomModelsCount); m->loadedId = id; return; }