From ea2b92e6e9cb2e5414166fb41d7f451ed4fdbda3 Mon Sep 17 00:00:00 2001 From: Caner Karaca Date: Wed, 7 Oct 2026 03:03:31 +0300 Subject: [PATCH] fix(api): route ME_SetRemapIndex and ME_GetRemapIndex through Remap feature --- src/ModelExtrasAPI.cpp | 4 +-- src/features/remap.cpp | 75 ++++++++++++++++++++++++++++++++++-------- src/features/remap.h | 5 +++ xmake.lua | 4 ++- 4 files changed, 72 insertions(+), 16 deletions(-) diff --git a/src/ModelExtrasAPI.cpp b/src/ModelExtrasAPI.cpp index 8135a801..d602d689 100755 --- a/src/ModelExtrasAPI.cpp +++ b/src/ModelExtrasAPI.cpp @@ -364,11 +364,11 @@ void ME_SetDirtLevel(CVehicle *pVeh, float dirtLevel) { // Remap API int ME_GetRemapIndex(CVehicle *pVeh) { - return pVeh ? pVeh->GetRemapIndex() : -1; + return pVeh ? Remap::GetRemapIndex(pVeh) : -1; } void ME_SetRemapIndex(CVehicle *pVeh, int remapIndex) { - if (pVeh) pVeh->SetRemap(remapIndex); + if (pVeh) Remap::SetRemapIndex(pVeh, remapIndex); } // Spoilers & Convertible Roof API diff --git a/src/features/remap.cpp b/src/features/remap.cpp index d78ef8fe..8b11945c 100755 --- a/src/features/remap.cpp +++ b/src/features/remap.cpp @@ -18,9 +18,13 @@ void Remap::Init() ReloadConfig(); } -void Remap::LoadRemaps(CVehicle* vehicle) +void Remap::EnsureRemapsLoaded(int modelIndex) { - CBaseModelInfo *pModelInfo = CModelInfo::GetModelInfo(vehicle->m_nModelIndex); + if (modelIndex < 0 || modelIndex >= 20000) return; + auto itModel = xRemaps.find(modelIndex); + if (itModel != xRemaps.end() && itModel->second.bRemapsLoaded) return; + + CBaseModelInfo *pModelInfo = CModelInfo::GetModelInfo(modelIndex); if (!pModelInfo) return; CTxdStore::PushCurrentTxd(); @@ -45,8 +49,8 @@ void Remap::LoadRemaps(CVehicle* vehicle) return; } - int model = vehicle->m_nModelIndex; - RemapData &data = xRemaps[model]; + RemapData &data = xRemaps[modelIndex]; + data.bRemapsLoaded = true; // Collect all textures in the TXD by lowercase name std::unordered_map allTextures; @@ -89,6 +93,57 @@ void Remap::LoadRemaps(CVehicle* vehicle) CTxdStore::PopCurrentTxd(); } +void Remap::LoadRemaps(CVehicle* vehicle) +{ + if (!vehicle) return; + EnsureRemapsLoaded(vehicle->m_nModelIndex); +} + +bool Remap::HasRemaps(int modelIndex) +{ + if (modelIndex < 0 || modelIndex >= 20000) return false; + EnsureRemapsLoaded(modelIndex); + auto it = xRemaps.find(modelIndex); + return it != xRemaps.end() && !it->second.pTextures.empty(); +} + +int Remap::GetRemapCount(int modelIndex) +{ + if (modelIndex < 0 || modelIndex >= 20000) return 0; + EnsureRemapsLoaded(modelIndex); + auto it = xRemaps.find(modelIndex); + if (it == xRemaps.end() || it->second.pTextures.empty()) return 0; + return static_cast(it->second.pTextures.begin()->second.size()); +} + +int Remap::GetRemapIndex(CVehicle *pVeh) +{ + if (!pVeh) return -1; + if (HasRemaps(pVeh->m_nModelIndex)) + { + int count = GetRemapCount(pVeh->m_nModelIndex); + if (count <= 0) return -1; + RemapVehData &vehData = m_VehData.Get(pVeh); + if (vehData.randomId == -1) + { + vehData.randomId = RandomNumberInRange(0, count - 1); + } + return ((vehData.randomId % count) + count) % count; + } + return pVeh->GetRemapIndex(); +} + +void Remap::SetRemapIndex(CVehicle *pVeh, int remapIndex) +{ + if (!pVeh) return; + if (HasRemaps(pVeh->m_nModelIndex)) + { + RemapVehData &vehData = m_VehData.Get(pVeh); + vehData.randomId = remapIndex; + } + pVeh->SetRemap(remapIndex); +} + void Remap::ProcessTextures(CVehicle *pVeh, RpMaterial *pMat) { if (!m_bEnabled || !pVeh || !pMat || !pMat->texture || !pMat->texture->name) @@ -97,15 +152,9 @@ void Remap::ProcessTextures(CVehicle *pVeh, RpMaterial *pMat) } int model = pVeh->m_nModelIndex; - auto itModel = xRemaps.find(model); - if (itModel == xRemaps.end() || !itModel->second.bRemapsLoaded) - { - RemapData &newData = xRemaps[model]; - LoadRemaps(pVeh); - newData.bRemapsLoaded = true; - itModel = xRemaps.find(model); - } + EnsureRemapsLoaded(model); + auto itModel = xRemaps.find(model); if (itModel == xRemaps.end() || itModel->second.pTextures.empty()) { return; @@ -138,7 +187,7 @@ void Remap::ProcessTextures(CVehicle *pVeh, RpMaterial *pMat) vehData.randomId = RandomNumberInRange(0, sz - 1); } - int chosen = vehData.randomId % sz; + int chosen = ((vehData.randomId % sz) + sz) % sz; if (pMat->texture != it->second[chosen]) { ModelInfoMgr::RegisterRestore(&pMat->texture, pMat->texture); diff --git a/src/features/remap.h b/src/features/remap.h index 3c7709de..a243dcaa 100755 --- a/src/features/remap.h +++ b/src/features/remap.h @@ -32,4 +32,9 @@ class Remap : public CVehFeature public: Remap() : CVehFeature("TextureRemapper", "FEATURES", eFeatureMatrix::TextureRemapper) {} static void ProcessTextures(CVehicle *pVeh, RpMaterial *pMat); + static void EnsureRemapsLoaded(int modelIndex); + static bool HasRemaps(int modelIndex); + static int GetRemapCount(int modelIndex); + static int GetRemapIndex(CVehicle *pVeh); + static void SetRemapIndex(CVehicle *pVeh, int remapIndex); }; \ No newline at end of file diff --git a/xmake.lua b/xmake.lua index 2c25e21d..f2165b4b 100755 --- a/xmake.lua +++ b/xmake.lua @@ -5,7 +5,9 @@ set_defaultmode("release") local PLUGIN_SDK_DIR = os.getenv("PLUGIN_SDK_DIR") if not PLUGIN_SDK_DIR or not os.isdir(PLUGIN_SDK_DIR) then - if os.isdir("D:/Dev/plugin-sdk") then + if os.isdir("plugin-sdk") then + PLUGIN_SDK_DIR = "plugin-sdk" + elseif os.isdir("D:/Dev/plugin-sdk") then PLUGIN_SDK_DIR = "D:/Dev/plugin-sdk" end end