Skip to content

Commit

Permalink
Open Source files
Browse files Browse the repository at this point in the history
  • Loading branch information
xvorost authored Nov 19, 2023
1 parent ad9ba1e commit b7f4710
Show file tree
Hide file tree
Showing 17 changed files with 1,208 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Entity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "Entity.h"

template <typename T>
bool GetDataAddressWithOffset(const DWORD64& Address, DWORD Offset, T& Data)
{
if (Address == 0)
return false;

if (!ProcessMgr.ReadMemory<T>(Address + Offset, Data))
return false;

return true;
}

bool CEntity::UpdateController(const DWORD64& PlayerControllerAddress)
{
if (PlayerControllerAddress == 0)
return false;
this->Controller.Address = PlayerControllerAddress;

this->Pawn.Address = this->Controller.GetPlayerPawnAddress();

return true;
}

bool CEntity::UpdatePawn(const DWORD64& PlayerPawnAddress)
{
if (PlayerPawnAddress == 0)
return false;
this->Pawn.Address = PlayerPawnAddress;

return true;
}

DWORD64 PlayerController::GetPlayerPawnAddress()
{
DWORD64 EntityPawnListEntry = 0;
DWORD64 EntityPawnAddress = 0;

if (!GetDataAddressWithOffset<DWORD>(Address, Offset::Entity.PlayerPawn, this->Pawn))
return 0;

if (!ProcessMgr.ReadMemory<DWORD64>(gGame.GetEntityListAddress(), EntityPawnListEntry))
return 0;

if (!ProcessMgr.ReadMemory<DWORD64>(EntityPawnListEntry + 0x10 + 8 * ((Pawn & 0x7FFF) >> 9), EntityPawnListEntry))
return 0;

if (!ProcessMgr.ReadMemory<DWORD64>(EntityPawnListEntry + 0x78 * (Pawn & 0x1FF), EntityPawnAddress))
return 0;

return EntityPawnAddress;
}
34 changes: 34 additions & 0 deletions Entity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once
#include "Game.h"

struct C_UTL_VECTOR
{
DWORD64 Count = 0;
DWORD64 Data = 0;
};

class PlayerController
{
public:
DWORD64 Address = 0;
DWORD Pawn = 0;
public:
DWORD64 GetPlayerPawnAddress();
};

class PlayerPawn
{
public:

DWORD64 Address = 0;
};

class CEntity
{
public:
PlayerController Controller;
PlayerPawn Pawn;
public:
bool UpdateController(const DWORD64& PlayerControllerAddress);
bool UpdatePawn(const DWORD64& PlayerPawnAddress);
};
50 changes: 50 additions & 0 deletions Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "Game.h"

bool CGame::InitAddress()
{
this->Address.ClientDLL = reinterpret_cast<DWORD64>(ProcessMgr.GetProcessModuleHandle("client.dll"));

this->Address.EntityList = GetClientDLLAddress() + Offset::EntityList;
this->Address.LocalController = GetClientDLLAddress() + Offset::LocalPlayerController;
this->Address.LocalPawn = GetClientDLLAddress() + Offset::LocalPlayerPawn;

return this->Address.ClientDLL != 0;
}

DWORD64 CGame::GetClientDLLAddress()
{
return this->Address.ClientDLL;
}

DWORD64 CGame::GetEntityListAddress()
{
return this->Address.EntityList;
}

DWORD64 CGame::GetEntityListEntry()
{
return this->Address.EntityListEntry;
}

DWORD64 CGame::GetLocalControllerAddress()
{
return this->Address.LocalController;
}

DWORD64 CGame::GetLocalPawnAddress()
{
return this->Address.LocalPawn;
}

bool CGame::UpdateEntityListEntry()
{
DWORD64 EntityListEntry = 0;
if (!ProcessMgr.ReadMemory<DWORD64>(gGame.GetEntityListAddress(), EntityListEntry))
return false;
if (!ProcessMgr.ReadMemory<DWORD64>(EntityListEntry + 0x10, EntityListEntry))
return false;

this->Address.EntityListEntry = EntityListEntry;

return this->Address.EntityListEntry != 0;
}
38 changes: 38 additions & 0 deletions Game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once
#include <optional>
#include "ProcessManager.hpp"
#include "Offsets.h"

class CGame
{
private:
struct
{
DWORD64 ClientDLL;
DWORD64 EntityList;
DWORD64 Matrix;
DWORD64 ViewAngle;
DWORD64 EntityListEntry;
DWORD64 LocalController;
DWORD64 LocalPawn;
DWORD64 ForceJump;
}Address;

public:

bool InitAddress();

DWORD64 GetClientDLLAddress();

DWORD64 GetEntityListAddress();

DWORD64 GetEntityListEntry();

DWORD64 GetLocalControllerAddress();

DWORD64 GetLocalPawnAddress();

bool UpdateEntityListEntry();
};

inline CGame gGame;
105 changes: 105 additions & 0 deletions MemorySearch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include "ProcessManager.hpp"

#define BLOCKMAXSIZE 409600
BYTE* MemoryData;
short Next[260];

WORD GetSignatureArray(std::string Signature, WORD* SignatureArray)
{
int len = 0;
WORD Length = Signature.length() / 3 + 1;

for (int i = 0; i < Signature.length(); )
{
char num[2];
num[0] = Signature[i++];
num[1] = Signature[i++];
i++;
if (num[0] != '?' && num[1] != '?')
{
int sum = 0;
WORD a[2];
for (int i = 0; i < 2; i++)
{
if (num[i] >= '0' && num[i] <= '9')
a[i] = num[i] - '0';
else if (num[i] >= 'a' && num[i] <= 'z')
a[i] = num[i] - 87;
else if (num[i] >= 'A' && num[i] <= 'Z')
a[i] = num[i] - 55;
}
sum = a[0] * 16 + a[1];
SignatureArray[len++] = sum;
}
else
SignatureArray[len++] = 256;
}
return Length;
}

void GetNext(short* next, WORD* Signature, WORD SignatureLength)
{
for (int i = 0; i < 260; i++)
next[i] = -1;
for (int i = 0; i < SignatureLength; i++)
next[Signature[i]] = i;
}

void SearchMemoryBlock(HANDLE hProcess, WORD* Signature, WORD SignatureLength, DWORD64 StartAddress, DWORD size, std::vector<DWORD64>& ResultArray)
{
if (!ReadProcessMemory(hProcess, (LPCVOID)StartAddress, MemoryData, size, NULL))
return;

for (int i = 0, j, k; i < size;)
{
j = i; k = 0;

for (; k < SignatureLength && j < size && (Signature[k] == MemoryData[j] || Signature[k] == 256); k++, j++);

if (k == SignatureLength)
ResultArray.push_back(StartAddress + i);

if ((i + SignatureLength) >= size)
return;

int num = Next[MemoryData[i + SignatureLength]];
if (num == -1)
i += (SignatureLength - Next[256]);
else
i += (SignatureLength - num);
}
}


std::vector<DWORD64> ProcessManager::SearchMemory(std::string Signature, DWORD64 StartAddress, DWORD64 EndAddress)
{
MemoryData = new BYTE[BLOCKMAXSIZE];
int i = 0;
unsigned long BlockSize;
MEMORY_BASIC_INFORMATION mbi;
WORD SignatureLength = Signature.length() / 3 + 1;
WORD* SignatureArray = new WORD[SignatureLength];
std::vector<DWORD64>ResultArray;
GetSignatureArray(Signature, SignatureArray);
GetNext(Next, SignatureArray, SignatureLength);

while (VirtualQueryEx(hProcess, (LPCVOID)StartAddress, &mbi, sizeof(mbi)) != 0)
{
i = 0;
BlockSize = mbi.RegionSize;
while (BlockSize >= BLOCKMAXSIZE)
{
SearchMemoryBlock(hProcess, SignatureArray, SignatureLength, StartAddress + (BLOCKMAXSIZE * i), BLOCKMAXSIZE, ResultArray);
BlockSize -= BLOCKMAXSIZE; i++;
}
SearchMemoryBlock(hProcess, SignatureArray, SignatureLength, StartAddress + (BLOCKMAXSIZE * i), BlockSize, ResultArray);

StartAddress += mbi.RegionSize;

if (EndAddress != 0 && StartAddress > EndAddress)
return ResultArray;
}
delete[] MemoryData;
delete[] SignatureArray;
return ResultArray;
}
48 changes: 48 additions & 0 deletions Offsets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "Offsets.h"

DWORD64 SearchOffsets(std::string Signature, DWORD64 ModuleAddress)
{
std::vector<DWORD64> TempAddressList;
DWORD64 Address = 0;
DWORD Offsets = 0;

TempAddressList = ProcessMgr.SearchMemory(Signature, ModuleAddress, ModuleAddress + 0x4000000);

if (TempAddressList.size() <= 0)
return 0;

if (!ProcessMgr.ReadMemory<DWORD>(TempAddressList.at(0) + 3, Offsets))
return 0;

Address = TempAddressList.at(0) + Offsets + 7;
return Address;
}

bool Offset::UpdateOffsets()
{
DWORD64 ClientDLL = reinterpret_cast<DWORD64>(ProcessMgr.GetProcessModuleHandle("client.dll"));
if (ClientDLL == 0)
return false;

DWORD64 TempAddress = 0;

TempAddress = SearchOffsets(Offset::Signatures::EntityList, ClientDLL);
if (TempAddress == 0)
return false;

Offset::EntityList = TempAddress - ClientDLL;

TempAddress = SearchOffsets(Offset::Signatures::LocalPlayerController, ClientDLL);
if (TempAddress == 0)
return false;

Offset::LocalPlayerController = TempAddress - ClientDLL;

TempAddress = SearchOffsets(Offset::Signatures::LocalPlayerPawn, ClientDLL);
if (TempAddress == 0)
return false;

Offset::LocalPlayerPawn = TempAddress + 0x138 - ClientDLL;

return true;
}
27 changes: 27 additions & 0 deletions Offsets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <Windows.h>
#include "ProcessManager.hpp"

namespace Offset
{
inline DWORD EntityList;
inline DWORD LocalPlayerController;
inline DWORD LocalPlayerPawn;

// https://github.com/a2x/cs2-dumper/blob/main/generated/client.dll.hpp
struct
{
DWORD PlayerPawn = 0x60C; // CBasePlayerController -> m_hPawn
DWORD EnemySensor = 0x13DC; // m_flDetectedByEnemySensorTime
} Entity;

// https://github.com/a2x/cs2-dumper/blob/main/config.json
namespace Signatures
{
const std::string EntityList = "48 8B 0D ?? ?? ?? ?? 48 89 7C 24 ?? 8B FA C1";
const std::string LocalPlayerController = "48 8B 05 ?? ?? ?? ?? 48 85 C0 74 4F";
const std::string LocalPlayerPawn = "48 8D 05 ?? ?? ?? ?? C3 CC CC CC CC CC CC CC CC 48 83 EC ?? 8B 0D";
}

bool UpdateOffsets();
}
Loading

0 comments on commit b7f4710

Please sign in to comment.