PMem.h:
Code:
#ifndef PMEM_H
#define PMEM_H
#include <iostream>
#include <Windows.h>
#include <cmath>
#include <string>
#include <TlHelp32.h>
#include <stdint.h>
class PMem {
protected:
HANDLE hProcess;
DWORD dwPID, dwProtection, dwCaveAddress;
BOOL bPOn, bIOn, bProt;
public:
PMem();
~PMem();
bool Attached;
/* Read Template! */
template <class cData>
cData Read(DWORD dwAddress)
{
cData cRead;
ReadProcessMemory(hProcess, (LPVOID)dwAddress, &cRead, sizeof(cData), NULL);
return cRead;
}
virtual bool Process(char* ProcessName);
virtual DWORD Module(LPSTR ModuleName);
/* WriteProcessMemory */
template <class T>
void Write(DWORD addr, T val) {
WriteProcessMemory(hProcess, (LPVOID)addr, &val, sizeof(T), NULL);
}
};
#endif
PMem.cpp:
Code:
#include "PMem.h"
#pragma region Misc functions
PMem::PMem() { }
PMem::~PMem() {
CloseHandle(hProcess);
}
bool PMem::Process(char* ProcessName) {
HANDLE hPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
PROCESSENTRY32 ProcEntry;
ProcEntry.dwSize = sizeof(ProcEntry);
do
if (!strcmp(ProcEntry.szExeFile, ProcessName))
{
dwPID = ProcEntry.th32ProcessID;
CloseHandle(hPID);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);
this->Attached = true;
return true;
}
while (Process32Next(hPID, &ProcEntry));
return false;
}
DWORD PMem::Module(LPSTR ModuleName){
HANDLE hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID);
MODULEENTRY32 mEntry;
mEntry.dwSize = sizeof(mEntry);
do
if (!strcmp(mEntry.szModule, ModuleName))
{
CloseHandle(hModule);
return (DWORD)mEntry.modBaseAddr;
}
while (Module32Next(hModule, &mEntry));
std::cout << "\nMODULE: Process Platform Invalid\n";
return 0;
}
Player Classes (Entity and player is in same header/source)
CBaseEntity.h:
Code:
/************************************************
* Author: Psychobitch
* File Purpose: Class defintions and members
* Creation date: 2015-05-17
*************************************************/
#pragma once // Header guard
#include <Windows.h>
#include "PMem.h"
class CLocalPlayer // Class
{
public: // Public Members
PMem Mem; // Memory object
DWORD dwClient; // Client dll
DWORD m_pLocal; // M stands for member (This is the player in question)
int m_iTeam; // Team of player in question (Your player)
int m_iHealth; // Health of player in question (Your health)
int m_iCHID; // Crosshair id, aka the entity in crosshair
int AttackState; // attack state..
public: // Public methods
DWORD GetPLocal();
int GetTeam();
bool isAlive();
int GetCHID();
bool CanAttack();
void SetAttack(int, int);
};
class CBaseEntity // Class
{
public: // Public Members
PMem Mem; // Memory object
DWORD dwClient;
DWORD m_pEnt; // Entity in question (ent in crosshair)
int m_iTeam;
int m_iHealth;
public: // Public Methods
DWORD GetEntity(int);
int GetTeam();
bool IsAlive();
};
CBaseEntity.cpp:
Code:
/************************************************
* Author: Psychobitch
* File Purpose: Methods & Members of Classes
* Creation date: 2015-05-17
*************************************************/
#include "CLocalPlayer.h"
#include "Globals.h"
#pragma region CLocalPlayer
DWORD CLocalPlayer::GetPLocal()
{
this->m_pLocal = Mem.Read<DWORD>(dwClient + Globals::localPlayer);
return this->m_pLocal;
}
int CLocalPlayer::GetTeam()
{
this->m_iTeam = Mem.Read<int>(this->m_pLocal + 0xF0); // 0xF0 m_iTeamNum Offset
return this->m_iTeam;
}
bool CLocalPlayer::isAlive()
{
this->m_iHealth = Mem.Read<int>(this->m_pLocal + 0xFC); // 0xFc m_iHealth offset
if (this->m_iHealth > 0) return true;
else return false;
}
int CLocalPlayer::GetCHID()
{
this->m_iCHID = Mem.Read<int>(this->m_pLocal + Globals::CHIndex);
return this->m_iCHID;
}
bool CLocalPlayer::CanAttack()
{
this->AttackState = Mem.Read<int>(dwClient + Globals::Attack);
if (this->AttackState == 5) return true;
else return false;
}
void CLocalPlayer::SetAttack(int _val, int _dur)
{
Mem.Write<int>(this->dwClient + Globals::Attack, _val);
Sleep(_dur);
}
#pragma endregion CLocalPlayer
#pragma region CBaseEntity
DWORD CBaseEntity::GetEntity(int _id)
{
this->m_pEnt = Mem.Read<DWORD>(dwClient + Globals::entityList + (_id * 0x10)); // Each entity is 0x10 bytes away from eachother inside the entityList
return this->m_pEnt;
}
int CBaseEntity::GetTeam()
{
this->m_iTeam = Mem.Read<int>(this->m_pEnt + 0xF0);
return this->m_iTeam;
}
bool CBaseEntity::IsAlive()
{
this->m_iHealth = Mem.Read<int>(this->m_pEnt + 0xFC);
if (this->m_iHealth > 0) return true;
else return false;
}
#pragma endregion CBaseEntity
thxn 4 red me post plez +rep