diff --git a/AMBuilder b/AMBuilder index f9b6f51a9..cf0f46588 100644 --- a/AMBuilder +++ b/AMBuilder @@ -80,6 +80,7 @@ for sdk_target in MMSPlugin.sdk_targets: os.path.join(builder.sourcePath, 'src', 'utils', 'detours.cpp'), os.path.join(builder.sourcePath, 'src', 'utils', 'schema.cpp'), os.path.join(builder.sourcePath, 'src', 'utils', 'simplecmds.cpp'), + os.path.join(builder.sourcePath, 'src', 'utils', 'mempatch.cpp'), os.path.join(builder.sourcePath, 'src', 'movement', 'mv_hooks.cpp'), os.path.join(builder.sourcePath, 'src', 'movement', 'mv_manager.cpp'), diff --git a/src/utils/addresses.h b/src/utils/addresses.h index 42f940c1b..aa4bd9101 100644 --- a/src/utils/addresses.h +++ b/src/utils/addresses.h @@ -99,7 +99,9 @@ namespace sigs // Find handler for setang console command DECLARE_SIG(SnapViewAngles, "\x48\x89\x5C\x24\x20\x55\x56\x57\x41\x56\x41\x57\x48\x8D\x6C\x24\xC9\x48\x81\xEC\xD0\x00\x00\x00\xBF\xFF\xFF\xFF\xFF"); - + // bot_add + DECLARE_SIG(CreateBotPatch, "\x0F\x84\x2A\x2A\x2A\x2A\x80\xB8\x08\x01\x00\x00\x00\x0F\x84\x2A\x2A\x2A\x2A\x80\x3D\x2A\x2A\x2A\x2A\x00\x74"); + /* Trace related stuff */ // TODO diff --git a/src/utils/mempatch.cpp b/src/utils/mempatch.cpp new file mode 100644 index 000000000..8cd2a0b76 --- /dev/null +++ b/src/utils/mempatch.cpp @@ -0,0 +1,41 @@ +#include "mempatch.h" +#include "plat.h" + +#include "tier0/memdbgon.h" + +MemPatch::MemPatch(Signature sig, CModule *module, u32 patchLength) : sig(sig), module(module), patchLength(patchLength) +{ + if (!this->address) + { + this->address = (void*)this->module->FindSignature((const byte *)this->sig.data, this->sig.length); + if (!this->address) + { + return; + } + } + this->oldBytes = new byte[this->patchLength]; + V_memcpy(this->oldBytes, this->address, this->patchLength); +} + +bool MemPatch::Patch() +{ + if (!this->address) + { + return false; + } + + byte *patchBytes = new byte[this->patchLength]; + for (u32 i = 0; i < this->patchLength; i++) + { + patchBytes[i] = 0x90; + } + Plat_WriteMemory(this->address, patchBytes, this->patchLength); + delete patchBytes; + return true; +} + + +void MemPatch::Unpatch() +{ + Plat_WriteMemory(this->address, this->oldBytes, this->patchLength); +} \ No newline at end of file diff --git a/src/utils/mempatch.h b/src/utils/mempatch.h new file mode 100644 index 000000000..70de326ff --- /dev/null +++ b/src/utils/mempatch.h @@ -0,0 +1,18 @@ +#include "common.h" +#include "module.h" +#include "addresses.h" + +class MemPatch +{ +public: + MemPatch(Signature sig, CModule *module, u32 patchLength); + + bool Patch(); + void Unpatch(); +private: + Signature sig; + u32 patchLength; + CModule *module; + void *address{}; + byte *oldBytes{}; +}; \ No newline at end of file diff --git a/src/utils/plat_win.h b/src/utils/plat_win.h deleted file mode 100644 index 6f70f09be..000000000 --- a/src/utils/plat_win.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index d4b3c8565..96a5d2584 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -12,6 +12,7 @@ #include "module.h" #include "detours.h" #include "virtual.h" +#include "mempatch.h" #include "tier0/memdbgon.h" @@ -27,7 +28,7 @@ SnapViewAngles_t *utils::SnapViewAngles = NULL; EmitSoundFunc_t *utils::EmitSound = NULL; TracePlayerBBox_t *utils::TracePlayerBBox = NULL; FindEntityByClassname_t *FindEntityByClassnameFunc = NULL; - +MemPatch *botAddPatch = NULL; void modules::Initialize() { @@ -79,12 +80,15 @@ bool utils::Initialize(ISmmAPI *ismm, char *error, size_t maxlen) RESOLVE_SIG(modules::server, sigs::EmitSound, utils::EmitSound); RESOLVE_SIG(modules::server, sigs::FindEntityByClassname, FindEntityByClassnameFunc); + botAddPatch = new MemPatch(sigs::CreateBotPatch, modules::server, 19); + botAddPatch->Patch(); InitDetours(); return true; } void utils::Cleanup() { + botAddPatch->Unpatch(); FlushAllDetours(); } diff --git a/vendor/protobuf-3.21.8 b/vendor/protobuf-3.21.8 new file mode 160000 index 000000000..dab4d24d4 --- /dev/null +++ b/vendor/protobuf-3.21.8 @@ -0,0 +1 @@ +Subproject commit dab4d24d44eea0f21d6a21a548ee2b8c22b37f4f