增加OnClientConnected事件
This commit is contained in:
37
csgo2/VTHook.cpp
Normal file
37
csgo2/VTHook.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "vmthook.h"
|
||||
|
||||
VMTHook::VMTHook(void* vmt_addy)
|
||||
{
|
||||
vmt = (void**)vmt_addy;
|
||||
LOG("vmt: %p \n", vmt);
|
||||
}
|
||||
|
||||
void* VMTHook::Hook(int index, void* hk)
|
||||
{
|
||||
// Store the index and original function address
|
||||
hooked_funcs.insert(std::make_pair(index, vmt[index]));
|
||||
LOG("%s vmt[index]: %p \n", __FUNCTION__ ,vmt[index]);
|
||||
|
||||
// Change the memory's access rights, patch the address to our hook, restore original rights
|
||||
DWORD old;
|
||||
VirtualProtect(&vmt[index], sizeof(void*), PAGE_EXECUTE_READWRITE, &old);
|
||||
vmt[index] = hk;
|
||||
VirtualProtect(&vmt[index], sizeof(void*), old, NULL);
|
||||
|
||||
return hooked_funcs[index];
|
||||
}
|
||||
|
||||
void VMTHook::ClearHooks()
|
||||
{
|
||||
for (func_iterator = hooked_funcs.begin(); func_iterator != hooked_funcs.end(); func_iterator++)
|
||||
{
|
||||
DWORD old;
|
||||
VirtualProtect(&vmt[func_iterator->first], sizeof(void*), PAGE_EXECUTE_READWRITE, &old);
|
||||
vmt[func_iterator->first] = func_iterator->second;
|
||||
VirtualProtect(&vmt[func_iterator->first], sizeof(void*), old, NULL);
|
||||
}
|
||||
hooked_funcs.clear();
|
||||
vmt = nullptr;
|
||||
}
|
||||
|
||||
VMTHook::~VMTHook() {}
|
||||
100
csgo2/VTHook.h
100
csgo2/VTHook.h
@@ -1,100 +0,0 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
class VTHook
|
||||
{
|
||||
public:
|
||||
VTHook()
|
||||
{
|
||||
memset( this, 0, sizeof( VTHook) );
|
||||
}
|
||||
|
||||
VTHook( PDWORD64* ppdwClassBase )
|
||||
{
|
||||
bInitialize( ppdwClassBase );
|
||||
}
|
||||
|
||||
~VTHook()
|
||||
{
|
||||
UnHook();
|
||||
}
|
||||
void ClearClassBase()
|
||||
{
|
||||
m_ClassBase = NULL;
|
||||
}
|
||||
bool bInitialize( PDWORD64* ppdwClassBase )
|
||||
{
|
||||
m_ClassBase = ppdwClassBase;
|
||||
m_OldVT = *ppdwClassBase;
|
||||
m_VTSize = GetVTCount( *ppdwClassBase );
|
||||
m_NewVT = new DWORD64[ m_VTSize ];
|
||||
memcpy( m_NewVT, m_OldVT, sizeof( DWORD64) * m_VTSize );
|
||||
*ppdwClassBase = m_NewVT;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bInitialize( PDWORD64** pppdwClassBase ) // fix for pp
|
||||
{
|
||||
return bInitialize( *pppdwClassBase );
|
||||
}
|
||||
|
||||
void UnHook()
|
||||
{
|
||||
if( m_ClassBase )
|
||||
{
|
||||
*m_ClassBase = m_OldVT;
|
||||
}
|
||||
}
|
||||
|
||||
void ReHook()
|
||||
{
|
||||
if( m_ClassBase )
|
||||
{
|
||||
*m_ClassBase = m_NewVT;
|
||||
}
|
||||
}
|
||||
|
||||
int iGetFuncCount()
|
||||
{
|
||||
return ( int )m_VTSize;
|
||||
}
|
||||
|
||||
DWORD64 GetFuncAddress( int Index )
|
||||
{
|
||||
if( Index >= 0 && Index <= ( int )m_VTSize && m_OldVT != NULL )
|
||||
{
|
||||
return m_OldVT[ Index ];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PDWORD64 GetOldVT()
|
||||
{
|
||||
return m_OldVT;
|
||||
}
|
||||
|
||||
DWORD64 HookFunction( DWORD64 dwNewFunc, unsigned int iIndex )
|
||||
{
|
||||
if( m_NewVT && m_OldVT && iIndex <= m_VTSize && iIndex >= 0 )
|
||||
{
|
||||
m_NewVT[ iIndex ] = dwNewFunc;
|
||||
return m_OldVT[ iIndex ];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
DWORD64 GetVTCount( PDWORD64 pdwVMT )
|
||||
{
|
||||
DWORD64 dwIndex = 0;
|
||||
|
||||
while (IsBadCodePtr((FARPROC)pdwVMT[dwIndex]) == false) {
|
||||
dwIndex++;
|
||||
}
|
||||
return dwIndex;
|
||||
}
|
||||
|
||||
PDWORD64* m_ClassBase;
|
||||
PDWORD64 m_NewVT, m_OldVT;
|
||||
DWORD64 m_VTSize;
|
||||
};
|
||||
@@ -195,7 +195,7 @@
|
||||
<ClInclude Include="sdk\tier1\UtlVector.hpp" />
|
||||
<ClInclude Include="stb.hh" />
|
||||
<ClInclude Include="vmt.h" />
|
||||
<ClInclude Include="VTHook.h" />
|
||||
<ClInclude Include="vmthook.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp" />
|
||||
@@ -223,7 +223,7 @@
|
||||
<ClCompile Include="schema.cpp" />
|
||||
<ClCompile Include="sdk\convar\convar.cpp" />
|
||||
<ClCompile Include="sdk\tier1\UtlString.cpp" />
|
||||
<ClCompile Include="vmt.cpp" />
|
||||
<ClCompile Include="VTHook.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="cpp.hint" />
|
||||
|
||||
@@ -174,7 +174,7 @@
|
||||
<ClInclude Include="native_sdk\entity\cbaseentity.h">
|
||||
<Filter>头文件\native_sdk\entity</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="VTHook.h">
|
||||
<ClInclude Include="vmthook.h">
|
||||
<Filter>头文件\memory</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="native_sdk\entity\cbaseplayercontroller.h">
|
||||
@@ -254,7 +254,7 @@
|
||||
<ClCompile Include="schema.cpp">
|
||||
<Filter>源文件\native_sdk\interfaces</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="vmt.cpp">
|
||||
<ClCompile Include="VTHook.cpp">
|
||||
<Filter>源文件\memory</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="native_sdk\cschemasystem.cpp">
|
||||
|
||||
@@ -9,9 +9,11 @@ namespace events {
|
||||
const auto victim = reinterpret_cast<CCSPlayerController*>(event->GetPlayerPawn(&userIdNameParams));
|
||||
const auto attacker = reinterpret_cast<CCSPlayerController*>(event->GetPlayerPawn(&attackerNameParams));
|
||||
auto victimName = &victim->m_iszPlayerName();
|
||||
auto attackerName = &attacker->m_iszPlayerName();
|
||||
|
||||
//victimBasePlayer->ForceRespawn();
|
||||
printf("victim %s\n", victimName);
|
||||
printf("attacker %s\n", attacker->m_iszPlayerName());
|
||||
printf("attacker %s\n", attackerName);
|
||||
|
||||
}
|
||||
auto OnPlayerChat(IGameEvent* event) -> void
|
||||
|
||||
@@ -6,11 +6,12 @@ OnClientConnect_t original_OnClientConnected = NULL;
|
||||
Host_Say_t original_Host_Say = NULL;
|
||||
|
||||
namespace hooks {
|
||||
VTHook* HIServerGameClient;
|
||||
bool __fastcall hook_OnClientConnected(CPlayerSlot slot, const char* pszName, uint64_t xuid, const char* pszNetworkID, bool unk1, CBufferString* pRejectReason)
|
||||
// "player_connect"
|
||||
VMTHook* VMT_IServerGameClient;
|
||||
void __fastcall hook_OnClientConnected(void* rcx, CPlayerSlot slot, const char* pszName, uint64_t xuid, const char* pszNetworkID, const char* pszAddress, bool bFakePlayer)
|
||||
{
|
||||
LOG("Hook_OnClientConnected(%d, \"%s\", %d, \"%s\")\n", slot, pszName, xuid, pszNetworkID);
|
||||
return original_OnClientConnected(slot, pszName, xuid, pszNetworkID, unk1, pRejectReason);
|
||||
LOG("OnClientConnected(%d, \"%s\", %d, \"%s\", \"%s\" \"%d\")\n", slot.Get(), pszName, xuid, pszNetworkID, pszAddress, bFakePlayer);
|
||||
return original_OnClientConnected(rcx, slot, pszName, xuid, pszNetworkID, pszAddress, bFakePlayer);
|
||||
}
|
||||
void __fastcall hook_Host_Say(void* pEntity, void* args, bool teamonly, int unk1, const char* unk2)
|
||||
{
|
||||
@@ -101,9 +102,10 @@ namespace hooks {
|
||||
|
||||
}
|
||||
auto initVmtHook() -> bool {
|
||||
VMT_IServerGameClient = new VMTHook(Memory::read<void*>(reinterpret_cast<uint64_t>(Offset::InterFaces::IServerGameClient)));
|
||||
original_OnClientConnected = reinterpret_cast<OnClientConnect_t>(VMT_IServerGameClient->Hook(11, hook_OnClientConnected));
|
||||
|
||||
HIServerGameClient = new VTHook((DWORD64**)Offset::InterFaces::IServerGameClient);
|
||||
original_OnClientConnected = (OnClientConnect_t)HIServerGameClient->HookFunction((DWORD64)hook_OnClientConnected, 1);
|
||||
LOG("%s original_OnClientConnected: %p \n", __FUNCTION__, original_OnClientConnected);
|
||||
return original_OnClientConnected != nullptr;
|
||||
}
|
||||
auto init() -> bool {
|
||||
@@ -113,6 +115,10 @@ namespace hooks {
|
||||
}
|
||||
auto unload() -> void
|
||||
{
|
||||
VMT_IServerGameClient->ClearHooks();
|
||||
|
||||
delete VMT_IServerGameClient;
|
||||
|
||||
MH_DisableHook(MH_ALL_HOOKS);
|
||||
MH_RemoveHook(MH_ALL_HOOKS);
|
||||
MH_Uninitialize();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
#include "pch.h"
|
||||
#include "sdk/gameevent/IGameEvent.h"
|
||||
|
||||
#include "sdk/tier1/bufferstring.h"
|
||||
|
||||
typedef bool(__fastcall* FireEventServerSide_t)(CGameEventManager*, IGameEvent*, bool);
|
||||
typedef void(__fastcall* Host_Say_t)(void*, void*, bool, int, const char*);
|
||||
typedef bool(__fastcall* OnClientConnect_t)(CPlayerSlot, const char*, uint64_t, const char*, bool unk1, CBufferString*);
|
||||
typedef void(__fastcall* OnClientConnect_t)(void*, CPlayerSlot, const char*, uint64_t, const char*, const char*, bool);
|
||||
|
||||
extern FireEventServerSide_t original_FireEventServerSide;
|
||||
extern Host_Say_t original_Host_Say;
|
||||
|
||||
@@ -30,10 +30,10 @@ auto Init() -> bool {
|
||||
InterFaces::SchemaSystem = reinterpret_cast<CSchemaSystem*>(schemasystem.FindInterface("SchemaSystem_001").Get());
|
||||
// engine.dll
|
||||
InterFaces::GameEventManager = reinterpret_cast<IGameEventManager2*>(engine.FindInterface("GameEventSystemServerV001").Get());
|
||||
InterFaces::GameResourceServiceServer = reinterpret_cast<CGameResourceService*>(engine.FindInterface("Source2GameClients001").Get());
|
||||
InterFaces::GameResourceServiceServer = reinterpret_cast<CGameResourceService*>(engine.FindInterface("GameResourceServiceServerV001").Get());
|
||||
|
||||
// server.dll
|
||||
InterFaces::IServerGameClient = reinterpret_cast<IServerGameClients*>(server.FindInterface("GameResourceServiceServerV001").Get());
|
||||
InterFaces::IServerGameClient = reinterpret_cast<IServerGameClients*>(server.FindInterface("Source2GameClients001").Get());
|
||||
// only init in console server
|
||||
InterFaces::CGameEventManger = reinterpret_cast<CGameEventManager*>(CGameEventManagerPtr);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <Psapi.h>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
#include "framework.h"
|
||||
#include "stb.hh"
|
||||
@@ -31,4 +32,4 @@ extern void DebugPrintA(const char* format, ...);
|
||||
#include "offset.h"
|
||||
#include "events.h"
|
||||
#include "hooks.h"
|
||||
#include "VTHook.h"
|
||||
#include "vmthook.h"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include "../sdk.h"
|
||||
#include "../tier1/UtlVector.hpp"
|
||||
struct characterset_t
|
||||
|
||||
@@ -7,7 +7,7 @@ struct vis_info_t;
|
||||
class IHLTVServer;
|
||||
class IHLTVDirector;
|
||||
class CSteamID;
|
||||
|
||||
class CCommand;
|
||||
struct CEntityIndex
|
||||
{
|
||||
CEntityIndex(int index)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#include "vmt.h"
|
||||
21
csgo2/vmthook.h
Normal file
21
csgo2/vmthook.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
//form https://www.unknowncheats.me/forum/c-and-c-/188449-vmt-hooking-class.html
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
class VMTHook
|
||||
{
|
||||
public:
|
||||
|
||||
void** vmt = nullptr; // Pointer to the VMT, we're using it more as an array of void*
|
||||
|
||||
VMTHook(void* vmt); // Hook original VMT by it's address
|
||||
VMTHook(DWORD64* vmt_ptr); // Create Shadow VMT from VMT pointer ( Not implemented here )
|
||||
~VMTHook(); // Destructor, removes all hooks
|
||||
|
||||
void* Hook(int index, void* hk);
|
||||
void ClearHooks();
|
||||
private:
|
||||
std::map<int, void*>::iterator func_iterator; // Iterator so we can iterate the map below
|
||||
std::map<int, void*> hooked_funcs; // std::map which holds the index hooked and the original function's address
|
||||
};
|
||||
Reference in New Issue
Block a user