Cvars: Hook Cvar_DirectSet from engine library
This commit is contained in:
parent
5ca0e5617d
commit
34d91789c4
@ -96,6 +96,9 @@ binary.sources = [
|
||||
'stackstructs.cpp',
|
||||
'CTextParsers.cpp',
|
||||
'textparse.cpp',
|
||||
'cvars.cpp',
|
||||
'../public/memtools/CDetour/detours.cpp',
|
||||
'../public/memtools/CDetour/asm/asm.c',
|
||||
]
|
||||
|
||||
if builder.target_platform == 'windows':
|
||||
|
70
amxmodx/cvars.cpp
Normal file
70
amxmodx/cvars.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
// vim: set ts=4 sw=4 tw=99 noet:
|
||||
//
|
||||
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
||||
// Copyright (C) The AMX Mod X Development Team.
|
||||
//
|
||||
// This software is licensed under the GNU General Public License, version 3 or higher.
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://alliedmods.net/amxmodx-license
|
||||
|
||||
#include "cvars.h"
|
||||
#include "amxmodx.h"
|
||||
#include <CDetour/detours.h>
|
||||
|
||||
CDetour *Cvar_DirectSetDetour;
|
||||
|
||||
DETOUR_DECL_STATIC2(Cvar_DirectSet, void, struct cvar_s*, var, const char*, value)
|
||||
{
|
||||
printf("Cvar_DirectSet - %s -> %s\n", var->name, value);
|
||||
|
||||
DETOUR_STATIC_CALL(Cvar_DirectSet)(var, value);
|
||||
}
|
||||
|
||||
void CreateCvarHook(void)
|
||||
{
|
||||
// void PF_Cvar_DirectSet(struct cvar_s *var, const char *value) // = pfnCvar_DirectSet
|
||||
// {
|
||||
// Cvar_DirectSet(var, value); // <- We want to hook this.
|
||||
// }
|
||||
|
||||
byte *baseAddress = (byte *)g_engfuncs.pfnCvar_DirectSet;
|
||||
uintptr_t *functionAddress = nullptr;
|
||||
|
||||
#if defined(WIN32)
|
||||
// 55 push ebp
|
||||
// 8B EC mov ebp, esp
|
||||
// 8B 45 0C mov eax, [ebp+arg_4]
|
||||
// 8B 4D 08 mov ecx, [ebp+arg_0]
|
||||
// 50 push eax
|
||||
// 51 push ecx
|
||||
// E8 XX XX XX XX call Cvar_DirectSet
|
||||
const byte opcodeJump = 0xE8;
|
||||
#else
|
||||
// E9 XX XX XX XX jmp Cvar_DirectSet
|
||||
const byte opcodeJump = 0xE9;
|
||||
#endif
|
||||
|
||||
const byte opcodeJumpSize = 5;
|
||||
const byte opcodeJumpByteSize = 1;
|
||||
|
||||
const int maxBytesLimit = 20;
|
||||
|
||||
for (size_t i = 0; i < maxBytesLimit; ++i, ++baseAddress)
|
||||
{
|
||||
if (*baseAddress == opcodeJump)
|
||||
{
|
||||
functionAddress = (uintptr_t *)(&baseAddress[opcodeJumpSize] + *(uintptr_t *)&baseAddress[opcodeJumpByteSize]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (functionAddress)
|
||||
{
|
||||
CDetour *Cvar_DirectSetDetour = DETOUR_CREATE_STATIC_FIXED(Cvar_DirectSet, (void *)functionAddress);
|
||||
|
||||
if (Cvar_DirectSetDetour)
|
||||
{
|
||||
Cvar_DirectSetDetour->EnableDetour();
|
||||
}
|
||||
}
|
||||
}
|
19
amxmodx/cvars.h
Normal file
19
amxmodx/cvars.h
Normal file
@ -0,0 +1,19 @@
|
||||
// vim: set ts=4 sw=4 tw=99 noet:
|
||||
//
|
||||
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
||||
// Copyright (C) The AMX Mod X Development Team.
|
||||
//
|
||||
// This software is licensed under the GNU General Public License, version 3 or higher.
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://alliedmods.net/amxmodx-license
|
||||
|
||||
#ifndef CVARS_H
|
||||
#define CVARS_H
|
||||
|
||||
class CDetour;
|
||||
|
||||
void CreateCvarHook(void);
|
||||
|
||||
extern CDetour *Cvar_DirectSetDetour;
|
||||
|
||||
#endif // CVARS_H
|
@ -31,6 +31,7 @@
|
||||
#include "trie_natives.h"
|
||||
#include "CDataPack.h"
|
||||
#include "textparse.h"
|
||||
#include "cvars.h"
|
||||
|
||||
plugin_info_t Plugin_info =
|
||||
{
|
||||
@ -1488,6 +1489,8 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
|
||||
GET_HOOK_TABLES(PLID, &g_pEngTable, NULL, NULL);
|
||||
|
||||
FlagMan.SetFile("cmdaccess.ini");
|
||||
|
||||
CreateCvarHook();
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@
|
||||
</Midl>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\;..\..\public;..\..\public\sdk;..\..\public\amtl;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\;..\..\public;..\..\public\memtools;..\..\public\sdk;..\..\public\amtl;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;amxmodx_EXPORTS;PAWN_CELL_SIZE=32;ASM32;JIT;_CRT_SECURE_NO_DEPRECATE;HAVE_STDINT_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
@ -149,7 +149,7 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<AdditionalIncludeDirectories>..\;..\..\public;..\..\public\sdk;..\..\public\amtl;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\;..\..\public;..\..\public\memtools;..\..\public\sdk;..\..\public\amtl;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;amxmodx_EXPORTS;JIT;ASM32;PAWN_CELL_SIZE=32;_CRT_SECURE_NO_DEPRECATE;HAVE_STDINT_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
|
||||
<StringPooling>true</StringPooling>
|
||||
@ -200,7 +200,7 @@
|
||||
</Midl>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\;..\..\public;..\..\public\sdk;..\..\public\amtl;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\;..\..\public;..\..\public\memtools;..\..\public\sdk;..\..\public\amtl;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;amxmodx_EXPORTS;PAWN_CELL_SIZE=32;ASM32;JIT;BINLOG_ENABLED;_CRT_SECURE_NO_DEPRECATE;HAVE_STDINT_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
@ -252,7 +252,7 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<AdditionalIncludeDirectories>..\;..\..\public;..\..\public\sdk;..\..\public\amtl;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\;..\..\public;..\..\public\memtools;..\..\public\sdk;..\..\public\amtl;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;HAVE_STDINT_H;_USRDLL;amxmodx_EXPORTS;JIT;ASM32;PAWN_CELL_SIZE=32;BINLOG_ENABLED;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
|
||||
<StringPooling>true</StringPooling>
|
||||
@ -292,6 +292,8 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\public\memtools\CDetour\asm\asm.c" />
|
||||
<ClCompile Include="..\..\public\memtools\CDetour\detours.cpp" />
|
||||
<ClCompile Include="..\amx.cpp" />
|
||||
<ClCompile Include="..\amxcore.cpp" />
|
||||
<ClCompile Include="..\amxdbg.cpp" />
|
||||
@ -317,6 +319,7 @@
|
||||
<ClCompile Include="..\CPlugin.cpp" />
|
||||
<ClCompile Include="..\CTask.cpp" />
|
||||
<ClCompile Include="..\CTextParsers.cpp" />
|
||||
<ClCompile Include="..\cvars.cpp" />
|
||||
<ClCompile Include="..\CVault.cpp" />
|
||||
<ClCompile Include="..\datapacks.cpp" />
|
||||
<ClCompile Include="..\debugger.cpp" />
|
||||
@ -360,6 +363,9 @@
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\public\memtools\CDetour\asm\asm.h" />
|
||||
<ClInclude Include="..\..\public\memtools\CDetour\detourhelpers.h" />
|
||||
<ClInclude Include="..\..\public\memtools\CDetour\detours.h" />
|
||||
<ClInclude Include="..\amx.h" />
|
||||
<ClInclude Include="..\amxdbg.h" />
|
||||
<ClInclude Include="..\amxmodx.h" />
|
||||
@ -383,6 +389,7 @@
|
||||
<ClInclude Include="..\CString.h" />
|
||||
<ClInclude Include="..\CTask.h" />
|
||||
<ClInclude Include="..\CTextParsers.h" />
|
||||
<ClInclude Include="..\cvars.h" />
|
||||
<ClInclude Include="..\CVault.h" />
|
||||
<ClInclude Include="..\CVector.h" />
|
||||
<ClInclude Include="..\datastructs.h" />
|
||||
|
@ -25,6 +25,15 @@
|
||||
<Filter Include="Pawn Includes">
|
||||
<UniqueIdentifier>{4022451d-eb5f-4f14-b8d8-2ce23fec6e59}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Memtools">
|
||||
<UniqueIdentifier>{a1f7babf-acb1-4a06-92e9-e8a411e1f02a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Memtools\CDetour">
|
||||
<UniqueIdentifier>{8b35d490-2b01-4997-ba02-5e2cfd9c9017}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Memtools\CDetour\asm">
|
||||
<UniqueIdentifier>{64a22cd4-3715-45de-8af2-e54017733be6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\amx.cpp">
|
||||
@ -183,6 +192,15 @@
|
||||
<ClCompile Include="..\..\public\sdk\amxxmodule.cpp">
|
||||
<Filter>SDK</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cvars.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\public\memtools\CDetour\detours.cpp">
|
||||
<Filter>Memtools\CDetour</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\public\memtools\CDetour\asm\asm.c">
|
||||
<Filter>Memtools\CDetour\asm</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\amx.h">
|
||||
@ -329,6 +347,18 @@
|
||||
<ClInclude Include="..\..\public\sdk\moduleconfig.h">
|
||||
<Filter>SDK</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cvars.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\public\memtools\CDetour\detourhelpers.h">
|
||||
<Filter>Memtools\CDetour</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\public\memtools\CDetour\detours.h">
|
||||
<Filter>Memtools\CDetour</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\public\memtools\CDetour\asm\asm.h">
|
||||
<Filter>Memtools\CDetour\asm</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="..\version.rc">
|
||||
|
@ -32,10 +32,12 @@
|
||||
#ifndef _INCLUDE_SOURCEMOD_DETOURS_H_
|
||||
#define _INCLUDE_SOURCEMOD_DETOURS_H_
|
||||
|
||||
#include "amxxmodule.h"
|
||||
//#include <jit/jit_helpers.h>
|
||||
//#include <jit/x86/x86_macros.h>
|
||||
#include "detourhelpers.h"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int32_t cell;
|
||||
|
||||
/**
|
||||
* CDetours class for SourceMod Extensions by pRED*
|
||||
|
Loading…
Reference in New Issue
Block a user