diff options
-rw-r--r-- | NorthstarDLL/mods/modmanager.cpp | 8 | ||||
-rw-r--r-- | NorthstarDLL/mods/reload/reloadmodweapons.cpp | 52 |
2 files changed, 28 insertions, 32 deletions
diff --git a/NorthstarDLL/mods/modmanager.cpp b/NorthstarDLL/mods/modmanager.cpp index 10c351ba..6fc64f4f 100644 --- a/NorthstarDLL/mods/modmanager.cpp +++ b/NorthstarDLL/mods/modmanager.cpp @@ -915,13 +915,6 @@ void ModManager::CheckModFilesForChanges() // could also check this but no point as it should only be changed from mod keyvalues // if (!m_AssetTypesToReload.bPlaylists && !pChangedFile->m_Path.compare("playlists_v2.txt")) - // we also check these on change of mod keyvalues - if (!m_AssetTypesToReload.bWeaponSettings && !pChangedFile->m_Path.parent_path().compare("scripts/weapons/")) - { - m_AssetTypesToReload.bWeaponSettings = true; - continue; - } - if (!m_AssetTypesToReload.bPlayerSettings && !pChangedFile->m_Path.parent_path().compare("scripts/players/")) { m_AssetTypesToReload.bPlayerSettings = true; @@ -1081,7 +1074,6 @@ void ModManager::UnloadMods() m_AssetTypesToReload.bAimAssistSettings = false; m_AssetTypesToReload.bMaterials = false; m_AssetTypesToReload.bRPaks = false; - m_AssetTypesToReload.bWeaponSettings = false; m_AssetTypesToReload.bPlayerSettings = false; m_AssetTypesToReload.bAiSettings = false; m_AssetTypesToReload.bDamageDefs = false; diff --git a/NorthstarDLL/mods/reload/reloadmodweapons.cpp b/NorthstarDLL/mods/reload/reloadmodweapons.cpp index 297c3d48..ce661493 100644 --- a/NorthstarDLL/mods/reload/reloadmodweapons.cpp +++ b/NorthstarDLL/mods/reload/reloadmodweapons.cpp @@ -4,7 +4,7 @@ AUTOHOOK_INIT() OFFSET_STRUCT(WeaponDefinition) { - FIELD(5, bool bUnk); // this controls whether we reload script funcs + FIELD(5, bool bReloadScriptFuncs); FIELD(6, char pWeaponName[]); // this probably has a max length but i do not know what it is }; @@ -21,19 +21,17 @@ OFFSET_STRUCT(GlobalWeaponDefs) FIELD(16, WeaponDefContainer m_Weapons[]); }; -uint16_t* g_pnClientWeaponsLoaded; -GlobalWeaponDefs** g_ppClientWeaponDefs; +VAR_AT(client.dll + 0xB33A02, uint16_t*, g_pnClientWeaponsLoaded); +VAR_AT(client.dll + 0xB339E8, GlobalWeaponDefs**, g_ppClientWeaponDefs); -void (*ClientReparseWeapon)(WeaponDefinition* pWeapon); -void (*ClientReloadWeaponCallbacks)(int nWeaponIndex); -int (*ClientWeaponIndexByName)(const char* pWeaponName); +FUNCTION_AT(client.dll + 0x3D2FB0, void,, ClientReparseWeapon, (WeaponDefinition* pWeapon)); +FUNCTION_AT(client.dll + 0x3CE270, void,, ClientReloadWeaponCallbacks, (int nWeaponIndex)); -uint16_t* g_pnServerWeaponsLoaded; +/* uint16_t* g_pnServerWeaponsLoaded; GlobalWeaponDefs** g_ppServerWeaponDefs; void (*ServerReparseWeapon)(WeaponDefinition* pWeapon); -void (*ServerReloadWeaponCallbacks)(int nWeaponIndex); -int (*ServerWeaponIndexByName)(const char* pWeaponName); +void (*ServerReloadWeaponCallbacks)(int nWeaponIndex);*/ // used for passing client/server funcs/data/pointers to TryReloadWeapon struct SidedWeaponReloadPointers @@ -45,37 +43,47 @@ struct SidedWeaponReloadPointers // funcs void (*m_fnReparseWeapon)(WeaponDefinition* pWeapon); void (*m_fnReloadWeaponCallbacks)(int nWeaponIndex); - int (*m_fnWeaponIndexByName)(const char* pWeaponName); SidedWeaponReloadPointers( uint16_t* pnWeaponsLoaded, GlobalWeaponDefs** ppWeaponDefs, void (*fnReparseWeapon)(WeaponDefinition*), - void (*fnReloadWeaponCallbacks)(int), - int (*fnWeaponIndexByName)(const char*)) + void (*fnReloadWeaponCallbacks)(int)) { m_pnWeaponsLoaded = pnWeaponsLoaded; m_ppWeaponDefs = ppWeaponDefs; m_fnReparseWeapon = fnReparseWeapon; m_fnReloadWeaponCallbacks = fnReloadWeaponCallbacks; - m_fnWeaponIndexByName = fnWeaponIndexByName; } }; +int WeaponIndexByName(const char* pWeaponName, const SidedWeaponReloadPointers* pReloadPointers) +{ + for (int i = 0; i < *pReloadPointers->m_pnWeaponsLoaded; i++) + { + const WeaponDefinition* pWeapon = (*pReloadPointers->m_ppWeaponDefs)->m_Weapons[i].pWeaponDef; + if (!strcmp(pWeapon->pWeaponName, pWeaponName)) + return i; + } + + return -1; +} + bool ModManager::TryReloadWeapon(const char* pWeaponName, const SidedWeaponReloadPointers* pReloadPointers) { if (!m_AssetTypesToReload.setsWeaponSettings.contains(pWeaponName)) return false; // don't reload - int nWeaponIndex = pReloadPointers->m_fnWeaponIndexByName(pWeaponName); + int nWeaponIndex = WeaponIndexByName(pWeaponName, pReloadPointers); if (nWeaponIndex == -1) // weapon isn't loaded at all, no need to reload! return false; spdlog::info("ModManager::TryReloadWeapon reloading weapon {}", pWeaponName); - WeaponDefinition* pWeapon = (*pReloadPointers->m_ppWeaponDefs)->m_Weapons->pWeaponDef; + WeaponDefinition* pWeapon = (*pReloadPointers->m_ppWeaponDefs)->m_Weapons[nWeaponIndex].pWeaponDef; + bool bReloadScriptFuncs = pWeapon->bReloadScriptFuncs; // this is reset after reparse pReloadPointers->m_fnReparseWeapon(pWeapon); - if (pWeapon->bUnk) + if (bReloadScriptFuncs) // always false in testing? pReloadPointers->m_fnReloadWeaponCallbacks(nWeaponIndex); m_AssetTypesToReload.setsWeaponSettings.erase(pWeaponName); @@ -83,11 +91,13 @@ bool ModManager::TryReloadWeapon(const char* pWeaponName, const SidedWeaponReloa } // TODO: server implementation for this? +// clang-format off AUTOHOOK(ClientPrecacheWeaponFromStringtable, client.dll + 0x195A60, bool, __fastcall, (void* a1, void* a2, void* a3, const char* pWeaponName)) +// clang-format on { static SidedWeaponReloadPointers clientReloadPointers( - g_pnClientWeaponsLoaded, g_ppClientWeaponDefs, ClientReparseWeapon, ClientReloadWeaponCallbacks, ClientWeaponIndexByName); + g_pnClientWeaponsLoaded, g_ppClientWeaponDefs, ClientReparseWeapon, ClientReloadWeaponCallbacks); if (g_pModManager->TryReloadWeapon(pWeaponName, &clientReloadPointers)) return true; @@ -98,11 +108,5 @@ bool, __fastcall, (void* a1, void* a2, void* a3, const char* pWeaponName)) ON_DLL_LOAD_CLIENT("client.dll", ModReloadWeaponsClient, (CModule module)) { - AUTOHOOK_DISPATCH() - - g_pnClientWeaponsLoaded = module.Offset(0xB33A02).As<uint16_t*>(); - g_ppClientWeaponDefs = module.Offset(0xB339E8).As<GlobalWeaponDefs**>(); - - ClientReparseWeapon = module.Offset(0x3D2FB0).As<void(*)(WeaponDefinition*)>(); - ClientReloadWeaponCallbacks = module.Offset(0x3CE270).As<void(*)(int)>(); + AUTOHOOK_DISPATCH_MODULE(server.dll) } |