Skip to content

Commit

Permalink
ChaosMod: Add Model Spawn Bypass (#3620)
Browse files Browse the repository at this point in the history
Allows all models to be spawned (e.g. LOD models).
  • Loading branch information
MoneyWasted authored Oct 19, 2023
1 parent 690c323 commit f504863
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChaosMod/ChaosMod.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
<ClCompile Include="Main.cpp" />
<ClCompile Include="Memory\Hooks\AudioClearnessHook.cpp" />
<ClCompile Include="Memory\Hooks\ApplyChangeSetEntryHook.cpp" />
<ClCompile Include="Memory\Hooks\ModelSpawnBypass.cpp" />
<ClCompile Include="Memory\Hooks\PresentHook.cpp" />
<ClCompile Include="Memory\Hooks\ScriptThreadRunHook.cpp" />
<ClCompile Include="Memory\Hooks\HandleToEntityStructHook.cpp" />
Expand Down
40 changes: 40 additions & 0 deletions ChaosMod/Memory/Hooks/ModelSpawnBypass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdafx.h>

#include "Memory/Hooks/Hook.h"

static DWORD64 ms_ModelSpawnPatchAddr = 0;
static std::array<BYTE, 24> ms_ModelSpawnPatchOrigBytes;

static bool OnHook()
{
Handle handle = Memory::FindPattern("48 85 C0 0F 84 ? ? ? ? 8B 48 50");
if (!handle.IsValid())
{
LOG("ModelSpawnBypass: Failed to patch model spawn bypass!");

return false;
}
else
{
ms_ModelSpawnPatchAddr = handle.Addr();
memcpy_s(ms_ModelSpawnPatchOrigBytes.data(), ms_ModelSpawnPatchOrigBytes.size(),
reinterpret_cast<void *>(ms_ModelSpawnPatchAddr), 24);

Memory::Write<BYTE>(reinterpret_cast<BYTE *>(ms_ModelSpawnPatchAddr), 0x90, 24);

LOG("ModelSpawnBypass: Applied model spawn bypass patch!");

return true;
}
}

static void OnCleanup()
{
if (ms_ModelSpawnPatchAddr)
{
memcpy_s(reinterpret_cast<void *>(ms_ModelSpawnPatchAddr), 24, ms_ModelSpawnPatchOrigBytes.data(),
ms_ModelSpawnPatchOrigBytes.size());
}
}

static RegisterHook registerHookBypass(OnHook, OnCleanup, "_ModelSpawnBypass");

0 comments on commit f504863

Please sign in to comment.