Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow bot_add to be used without nav meshes #68

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
4 changes: 3 additions & 1 deletion src/utils/addresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions src/utils/mempatch.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
18 changes: 18 additions & 0 deletions src/utils/mempatch.h
Original file line number Diff line number Diff line change
@@ -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{};
};
1 change: 0 additions & 1 deletion src/utils/plat_win.h

This file was deleted.

6 changes: 5 additions & 1 deletion src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "module.h"
#include "detours.h"
#include "virtual.h"
#include "mempatch.h"

#include "tier0/memdbgon.h"

Expand All @@ -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()
{
Expand Down Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions vendor/protobuf-3.21.8
Submodule protobuf-3.21.8 added at dab4d2
Loading