Code:
#if _MSC_VER > 1000
#pragma once
#endif
#ifndef __MEMREADER_H
#define __MEMREADER_H
#include <string>
class MemHandler
{
private:
unsigned long m_bytesRead;
unsigned long m_bytesWritten;
public:
//Static addresses
const static unsigned int ADR_CLIENT_CON_BASE = 0x11CB310;
const static unsigned int ADR_PLAYER_BASE = 0x127F13C;
const static unsigned int ADR_MOUSE_OVER_TARGET = 0x10A68D0;
const static unsigned int ADR_ZONE = 0x010A68B4;//010A68B4
const static unsigned int ADR_SUB_ZONE = 0x010A68B8;
//Static offsets
const static unsigned int OFFSET_TYPE = 0x14;
const static unsigned int OFFSET_DESC = 0x8;
const static unsigned int OFFSET_LEVEL = 0x35 * 4;
const static unsigned int OFFSET_CURR_HEALTH = 0x17 * 4;
//Dynamic addresses
unsigned int CLIENT_CON_BASE; //[0x11CB310]
unsigned int PLAYER_BASE; //[[[0x127F13C] + 0x30] + 0x28]
unsigned int OBJ_MGR_BASE;//[[CLIENT_CON_BASE] + 0x28A4]
unsigned int FIRST_OBJ_BASE;
//object types
const static int OBJ_ITEM = 1;
const static int OBJ_CONT = 2;
const static int OBJ_NPCS = 3;
const static int OBJ_PLAY = 4;
const static int OBJ_GAME = 5;
const static int OBJ_DYNA = 6;
const static int OBJ_CORP = 7;
//globals
HWND g_hWnd;
HANDLE g_hProcess;
unsigned long g_pID;
bool setDebugPrivileges();
int init(const char * wndName);
int initBaseAddresses();
MemHandler();
unsigned long read(unsigned long address, unsigned long size, LPVOID lpVal);
unsigned long readChars(unsigned long address, char * &pszVal);
short readShortValue(unsigned int address);
int readString(unsigned int address, char * buf, int length);
long readLongValue(unsigned int address);
unsigned int readUnsignedIntValue(unsigned int address);
unsigned long readUnsignedLongValue(unsigned int address);
int readIntValue(unsigned int address);
INT64 readIntValue64(unsigned int address);
float readFloatValue(unsigned int address);
DWORD readDwordValue(unsigned int address);
};
#endif
MemHandler.cpp
Code:
#include <cstdlib>
#include <iostream>
#include <Windows.h>
#include "MemHandler.h"
bool debug = false;
MemHandler::MemHandler(){
}
short MemHandler::readShortValue(unsigned int address){
short s;
ReadProcessMemory(g_hProcess, (LPVOID) address, &s, sizeof(s), NULL);
if(debug) std::cout << "Short: " << address << " = " << s << "\n";
return s;
}
float MemHandler::readFloatValue(unsigned int address){
float f;
ReadProcessMemory(g_hProcess, (LPVOID) address, &f, sizeof(f), NULL);
if(debug) std::cout << "Float: " << address << " = " << f << "\n";
return f;
}
long MemHandler::readLongValue(unsigned int address)
{
long l;
ReadProcessMemory(g_hProcess, (LPVOID) address, &l, sizeof(l), NULL);
if(debug)
std::cout << "readLongValue for:" << address << " = " << l << "\n";
return l;
}
int MemHandler::readIntValue(unsigned int address)
{
int i;
ReadProcessMemory(g_hProcess, (LPVOID) address, &i, sizeof(i), NULL);
if(debug)
std::cout << "readIntValue for:" << address << " = " << i << "\n";
return i;
}
unsigned int MemHandler::readUnsignedIntValue(unsigned int address)
{
unsigned int ui;
ReadProcessMemory(g_hProcess, (LPVOID) address, &ui, sizeof(ui), NULL);
if(debug)
std::cout << "readUnsignedIntValue for:" << address << " = " << ui << "\n";
return ui;
}
unsigned long MemHandler::readUnsignedLongValue(unsigned int address)
{
unsigned long ul;
ReadProcessMemory(g_hProcess, (LPVOID) address, &ul, sizeof(ul), NULL);
if(debug)
std::cout << "ULong:" << address << " = " << ul << "\n";
return ul;
}
DWORD MemHandler::readDwordValue(unsigned int address)
{
DWORD dw;
ReadProcessMemory(g_hProcess, (LPVOID) address, &dw, sizeof(dw), NULL);
if(debug)
std::cout << "readDwordValue for:" << address << " = " << dw << "\n";
return dw;
}
unsigned long MemHandler::read(unsigned long address, unsigned long size, LPVOID lpVal)
{
m_bytesRead = 0;
ReadProcessMemory( g_hProcess, (LPVOID)address, lpVal, size, &m_bytesRead );
return m_bytesRead;
}
unsigned long MemHandler::readChars(unsigned long address, char * &pszVal)
{
return read(address, sizeof(char *), (LPVOID)&pszVal);
}
int MemHandler::readString(unsigned int address, char * buf, int length)
{
m_bytesRead = 0;
ReadProcessMemory(g_hProcess, (LPVOID) address, buf, length, &m_bytesRead);
if(debug)
std::cout << "readString for:" << address << " = " << buf << "\n";
return m_bytesRead;
}
INT64 MemHandler::readIntValue64(unsigned int address)
{
INT64 i;
ReadProcessMemory(g_hProcess, (LPVOID) address, &i, sizeof(i), NULL);
if(debug)
std::cout << "readStrValue32 for:" << address << " = " << i << "\n";
return i;
}
int MemHandler::init(const char * wndName)
{
g_hWnd = FindWindow(NULL, wndName);
GetWindowThreadProcessId(g_hWnd, &g_pID);
g_hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, g_pID);
if(g_hProcess)
return 1;
else
return 0;
}
int MemHandler::initBaseAddresses()
{
CLIENT_CON_BASE = this->readUnsignedIntValue(ADR_CLIENT_CON_BASE);
OBJ_MGR_BASE = this->readUnsignedIntValue(CLIENT_CON_BASE + 0x28A4);
FIRST_OBJ_BASE = this->readUnsignedIntValue(OBJ_MGR_BASE + 0xAC);
PLAYER_BASE = this->readUnsignedIntValue(ADR_PLAYER_BASE);
PLAYER_BASE = this->readUnsignedIntValue((PLAYER_BASE+0x30));
PLAYER_BASE = this->readUnsignedIntValue((PLAYER_BASE+0x28));
return 1;
}
bool MemHandler::setDebugPrivileges()
{
bool bRET = false;
TOKEN_PRIVILEGES tp;
HANDLE hToken;
if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid))
{
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
{
if (hToken != INVALID_HANDLE_VALUE)
{
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
tp.PrivilegeCount = 1;
if (AdjustTokenPrivileges(hToken, FALSE, &tp, 0, 0, 0))
bRET = TRUE;
CloseHandle(hToken);
}
}
}
return bRET;
}
If I do not get too much flaming for this I will post my class for input (sendinput/postmessage)