From f5bd7c9b954f3c206074e21faa724aff9b277e95 Mon Sep 17 00:00:00 2001 From: Allusive <154700875+AllusiveWheat@users.noreply.github.com> Date: Sat, 8 Nov 2025 18:12:57 -0800 Subject: [PATCH] Add model reloading (#872) * Make async call does not cause a crash if the script vm gets deleted before call finishes. * also fix in call since it still tries to call even if sqvm is invalid. * Update log string to account for not crashing anymore * small formatting things * fix formatting * Replace sprintf usage with sprintf_s in version.cpp * Actually check for size of version. * fix format * Add model reloading * fix formatting * fix cmake format * update the help string * Update location in cmake file * add changes from review * small update --- primedev/Northstar.cmake | 1 + primedev/engine/models.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 primedev/engine/models.cpp diff --git a/primedev/Northstar.cmake b/primedev/Northstar.cmake index c64b0bc7..bc73a700 100644 --- a/primedev/Northstar.cmake +++ b/primedev/Northstar.cmake @@ -65,6 +65,7 @@ add_library( "engine/host.cpp" "engine/hoststate.cpp" "engine/hoststate.h" + "engine/models.cpp" "engine/r2engine.cpp" "engine/r2engine.h" "engine/runframe.cpp" diff --git a/primedev/engine/models.cpp b/primedev/engine/models.cpp new file mode 100644 index 00000000..51141381 --- /dev/null +++ b/primedev/engine/models.cpp @@ -0,0 +1,24 @@ +static void (*Studio_ReloadModels)(__int64 a1, unsigned int a2) = nullptr; +static uintptr_t model_loader; +static uint8_t* g_VpkMode; + +void ConCommand_reload_models(const CCommand& args) +{ + uint8_t prevVpkMode = *g_VpkMode; + *g_VpkMode = 0; // need to set to zero to disable file cache temporarily + Studio_ReloadModels(model_loader, 2); + *g_VpkMode = prevVpkMode; +}; + +ON_DLL_LOAD("filesystem_stdio.dll", FileSystemModels, (CModule module)) +{ + g_VpkMode = module.Offset(0xe5aa9).RCast(); +} + +ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", EngineModels, ConCommand, (CModule module)) +{ + model_loader = module.Offset(0x7c4c20); + module.Offset(0xCF024).Patch({0xEB, 0x0E}); + Studio_ReloadModels = module.Offset(0xCEEF0).RCast(); + RegisterConCommand("reload_models", ConCommand_reload_models, "reload all models", FCVAR_CLIENTDLL); +}