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
This commit is contained in:
Allusive 2025-11-08 18:12:57 -08:00 committed by GitHub
parent cf2fcdd459
commit f5bd7c9b95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View file

@ -65,6 +65,7 @@ add_library(
"engine/host.cpp" "engine/host.cpp"
"engine/hoststate.cpp" "engine/hoststate.cpp"
"engine/hoststate.h" "engine/hoststate.h"
"engine/models.cpp"
"engine/r2engine.cpp" "engine/r2engine.cpp"
"engine/r2engine.h" "engine/r2engine.h"
"engine/runframe.cpp" "engine/runframe.cpp"

View file

@ -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<uint8_t*>();
}
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<decltype(Studio_ReloadModels)>();
RegisterConCommand("reload_models", ConCommand_reload_models, "reload all models", FCVAR_CLIENTDLL);
}