Skip to content

Instantly share code, notes, and snippets.

@cchinchole
Created December 15, 2017 23:22
Show Gist options
  • Select an option

  • Save cchinchole/89b66e7246dae3cf3f108097d631e5d2 to your computer and use it in GitHub Desktop.

Select an option

Save cchinchole/89b66e7246dae3cf3f108097d631e5d2 to your computer and use it in GitHub Desktop.
Assaultcube
#ifndef AIMBOT_H
#define AIMBOT_H
#include "Math.h"
void doAimbot();
#endif
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include <iostream>
#include <detours.h>
#include <gl\gl.h>
#include <strsafe.h>
#include "Draw.h";
#include "Offsets.h"
#include "ProcessMemoryWriter.h";
#include "Entity.h"
#include "Esp.h"
#include "Aimbot.h"
#pragma comment( lib, "Ws2_32.lib" )
#pragma comment( lib, "detours.lib" )
#pragma comment(lib, "user32.lib")
Draw drawClass;
MemoryWriter memoryWriter;
int version = 2;
int EntArrPtr;
int* pCount = NULL;
int width = NULL;
int height = NULL;
bool isMenu = false;
int smoothbot = 14;
int scalebox = 10;
extern bool isRage;
extern bool isEsp;
extern bool isTrigger;
extern bool isAimbot;
extern void DrawMenu();
extern void KeyMenu();
extern int oldID;
extern vec oldAngle;
Player pList[32];
playerent* localPlayer;
bool isRunning = true;
void ReadVariables()
{
pCount = (int*)Offsets::PlayerCount;
width = *(DWORD*)Offsets::SCRWidth;
height = *(DWORD*)Offsets::SCHeight;
localPlayer = (playerent*)*(int*)(Offsets::ACBase);
EntArrPtr = *(int*)Offsets::EntityArray;
for (int i = 0; i < (*pCount); i++)
{
pList[i].setID(i);
pList[i].setPlayerEnt((playerent*)*(int*)(EntArrPtr + 0x4 * i));
if(i == oldID)
{
if(pList[i].getPlayerEnt())
if(pList[i].getPlayerEnt()->state == CS_DEAD) {
oldID = -1;
localPlayer->vViewAngle = oldAngle;
}
}
}
}
using namespace std;
typedef BOOL(WINAPI * twglSwapBuffers) (_In_ HDC hDc);
//Original
twglSwapBuffers owglSwapBuffers;
//Hooked
BOOL __stdcall hwglSwapBuffers(_In_ HDC hDc)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (isEsp)
DoEsp();
if (isMenu)
DrawMenu();
return owglSwapBuffers(hDc);
}
HMODULE hMod;
void HookSwapBuffers()
{
hMod = GetModuleHandle("opengl32.dll");
if (hMod)
{
owglSwapBuffers = (twglSwapBuffers)(DWORD)GetProcAddress(hMod, "wglSwapBuffers");
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID &)owglSwapBuffers, hwglSwapBuffers);
DetourTransactionCommit();
}
HDC currentHDC = wglGetCurrentDC();
if (!drawClass.bFontBuilt || currentHDC != drawClass.fontHDC)
{
drawClass.BuildFonts();
}
}
DWORD WINAPI readvars(__in LPVOID lpParam)
{
while (isRunning)
{
ReadVariables();
Sleep(10);
}
return 0;
}
DWORD WINAPI trigger(__in LPVOID lpParam)
{
while (isRunning)
{
if (isTrigger)
{
if (*(DWORD*)Offsets::CrosshairName > 0)
{
/* This trigger is best with single shot rifles*/
playerent* a = (playerent*)(Offsets::CrosshairName);
if (!checkTeam(localPlayer, a))
{
localPlayer->bAttacking = 1;
*(DWORD*)Offsets::CrosshairName = 0;
}
}
else
localPlayer->bAttacking = 0;
}
Sleep(10);
}
return 0;
}
extern void setFunctionToggle(string check);
DWORD WINAPI aimloop(__in LPVOID lpParam)
{
while (isRunning)
{
if (isAimbot)
{
if (isRage)
{
if (!isTrigger) {
isTrigger = true;
setFunctionToggle("Trigger");
}
}
doAimbot();
}
Sleep(10);
}
return 0;
}
DWORD WINAPI mainloop(__in LPVOID lpParam)
{
while (isRunning)
{
KeyMenu();
Sleep(100);
}
return 0;
}
extern "C" __declspec(dllexport) void start_thread()
{
DWORD MainThreadID;
HANDLE MainThread;
MainThread = CreateThread(NULL, 0, mainloop, 0, 0, &MainThreadID);
if (!(MainThread == NULL))
CloseHandle(MainThread);
}
DWORD healthab;
BOOL WINAPI DllMain(HMODULE hModule, DWORD reason, LPVOID)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
MessageBoxA(NULL, "Loaded!", "Loaded!", MB_OK);
memoryWriter.setupWindowHandles("AssaultCube");
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)HookSwapBuffers, 0, 0, 0);
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)readvars, 0, 0, 0);
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)trigger, 0, 0, 0);
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)aimloop, 0, 0, 0);
start_thread();
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
memoryWriter.closeHandles();
isRunning = false;
break;
}
return TRUE;
}
#include "stdafx.h"
#include <stdio.h>
#include <gl/GLU.h>
#include "Draw.h"
#include <glut.h>
void Draw::StringSizable(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b, float size, char const * const pFmtText, ...)
{
int newLineDist = size-1;
//Allocate memory for a temporary result string. You could probably do much less
char *const pTemp = new char[5000];
//Put all of the text into pTemp
va_list vaList;
va_start(vaList, pFmtText);
int const TextLen = vsprintf(pTemp, pFmtText, vaList);
va_end(vaList);
glPushMatrix();
glTranslatef(x, y, 0);
glScalef(1 / 152.38, 1 / 152.38, 1 / 152.38);
//Draw the string
for (unsigned int Counter = 0; Counter < TextLen; ++Counter)
{
if (pTemp[Counter] == '\n')
{
y += newLineDist;
glRasterPos2i(x, y);
continue;
}
glScalef(0.005, 0.005, 1);
glutStrokeCharacter(GLUT_STROKE_ROMAN, pTemp[Counter]);
}
glPopMatrix();
//Prevent memory leaks
delete[] pTemp;
}
void Draw::stringD(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b, void * font, char const * const pFmtText, ...)
{
int newLineDist;
//Set the distance dynamically for new lines
switch ((int)font)
{
case (int)GLUT_BITMAP_9_BY_15:
newLineDist = 16;
break;
case (int)GLUT_BITMAP_8_BY_13:
newLineDist = 14;
break;
case (int)GLUT_BITMAP_TIMES_ROMAN_10:
newLineDist = 11;
break;
case (int)GLUT_BITMAP_TIMES_ROMAN_24:
newLineDist = 25;
break;
case (int)GLUT_BITMAP_HELVETICA_10:
newLineDist = 11;
break;
case (int)GLUT_BITMAP_HELVETICA_12:
newLineDist = 13;
break;
case (int)GLUT_BITMAP_HELVETICA_18:
newLineDist = 19;
break;
default:
newLineDist = 19;
break;
}
//Set our attributes
glColor3ub(r, g, b);
glRasterPos2i(x, y);
//Allocate memory for a temporary result string. You could probably do much less
char *const pTemp = new char[5000];
//Put all of the text into pTemp
va_list vaList;
va_start(vaList, pFmtText);
int const TextLen = vsprintf(pTemp, pFmtText, vaList);
va_end(vaList);
//Draw the string
for (unsigned int Counter = 0; Counter < TextLen; ++Counter)
{
if (pTemp[Counter] == '\n')
{
y += newLineDist;
glRasterPos2i(x, y);
continue;
}
glutBitmapCharacter(font, pTemp[Counter]);
}
//Prevent memory leaks
delete[] pTemp;
}
void Draw::box(GLfloat x, GLfloat y, GLfloat xLen, GLfloat yLen, GLfloat r, GLfloat g, GLfloat b)
{
//Set our attributes
glColor3ub(r, g, b);
//Draw our box
glBegin(GL_QUADS);
glVertex2f(x, y);
glVertex2f(x + xLen, y);
glVertex2f(x + xLen, y + yLen);
glVertex2f(x, y + yLen);
glEnd();
}
void Draw::box(GLfloat x, GLfloat y, GLfloat xLen, GLfloat yLen, GLfloat r, GLfloat g, GLfloat b, GLfloat a)
{
//Set our attributes
glColor4ub(r, g, b, a);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Draw our box
glBegin(GL_QUADS);
glVertex2f(x, y);
glVertex2f(x + xLen, y);
glVertex2f(x + xLen, y + yLen);
glVertex2f(x, y + yLen);
glEnd();
glDisable(GL_BLEND);
}
void Draw::boxLine(GLfloat width, GLfloat x, GLfloat y, GLfloat xLen, GLfloat yLen, GLfloat r, GLfloat g, GLfloat b)
{
//Grab the current line width to prevent clashes
GLfloat glTemp[1];
glGetFloatv(GL_LINE_WIDTH, glTemp);
//Set our attributes
glColor3ub(r, g, b);
glLineWidth(width);
//Draw out box
glBegin(GL_LINE_LOOP);
glVertex2f(x, y);
glVertex2f(x + xLen, y);
glVertex2f(x + xLen, y + yLen);
glVertex2f(x, y + yLen);
glEnd();
//Restore the line width
glLineWidth(glTemp[0]);
}
void Draw::line(GLfloat width, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat r, GLfloat g, GLfloat b)
{
//Grab the current line width to prevent clashes
GLfloat glTemp[1];
glGetFloatv(GL_LINE_WIDTH, glTemp);
//Set our attributes
glColor3ub(r, g, b);
glLineWidth(width);
//Draw our line
glBegin(GL_LINES);
glVertex2f(x1, y1);
glVertex2f(x2, y2);
glEnd();
//Restore the line width
glLineWidth(glTemp[0]);
}
void Draw::dot(GLfloat size, GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b)
{
//Grab the current line width to prevent clashes
GLfloat glTemp[1];
glGetFloatv(GL_POINT_SIZE, glTemp);
//Set our attributes
glColor3ub(r, g, b);
glPointSize(size);
//Draw our point
glBegin(GL_POINTS);
glVertex2f(x, y);
glEnd();
//Restore to prevent clashing
glPointSize(glTemp[0]);
}
void Draw::BuildFonts()
{
fontHDC = wglGetCurrentDC();
hackFont = glGenLists(96);
HFONT hFont = CreateFontA(-15, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_DONTCARE | DEFAULT_PITCH, "Consolas");
HFONT hOldFont = (HFONT)SelectObject(fontHDC, hFont);
wglUseFontBitmaps(fontHDC, 32, 96, hackFont);
SelectObject(fontHDC, hOldFont);
DeleteObject(hFont);
bFontBuilt = true;
}
void Draw::Print(float x, float y, const unsigned char color[3], const char *format, ...)
{
glColor3ub(color[0], color[1], color[2]);
glRasterPos2f(x, y);
char text[100] = "test string";
va_list args;
va_start(args, format);
vsprintf_s(text, 100, format, args);
va_end(args);
glPushAttrib(GL_LIST_BIT);
glListBase(hackFont - 32);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
glPopAttrib();
}
float Draw::centerText(float x, float width, float textWidth)
{
if (width > textWidth)
{
float difference = width - textWidth;
return (x + (difference / 2));
}
else
{
float difference = textWidth - width;
return (x - (difference / 2));
}
}
#pragma once
#include <windows.h>
#include <stdio.h>
#include <gl\GL.h>
class Draw
{
public:
unsigned int hackFont;
bool bFontBuilt = false;
HDC fontHDC = nullptr;
//r, g, b is the same in all functions. It's Red, Green Blue. The color ranges from 0.0f - 1.0f
//I can add separate functions if you want me to make a version for color ranges from 0 - 255
//Draws a string onto the screen. Font is a font (ex: GLUT_BITMAP_HELVETICA_18). Use the end of the funct
//like printf
void stringD(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b, void * font, char const*const pFmtText, ...);
//Draws a filled box. xLen is the length of the left and right sides, yLen is the length of the top and bottom
void box(GLfloat x, GLfloat y, GLfloat xLen, GLfloat yLen, GLfloat r, GLfloat g, GLfloat b);
void box(GLfloat x, GLfloat y, GLfloat xLen, GLfloat yLen, GLfloat r, GLfloat g, GLfloat b, GLfloat a);
//Same as box, though it draws just the outline. Width is how thick you want the line to be
void boxLine(GLfloat width, GLfloat x, GLfloat y, GLfloat xLen, GLfloat yLen, GLfloat r, GLfloat g, GLfloat b);
//Draws a normal line. x1/y1 and x2/y2 are to beginning and ending coords of the line
void line(GLfloat width, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat r, GLfloat g, GLfloat b);
//Draws a dot. Size is how large the dot is
void dot(GLfloat size, GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b);
void BuildFonts();
void Print(float x, float y, const unsigned char color[3], const char *format, ...);
void StringSizable(GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b, float size, char const * const pFmtText, ...);
//center on X and Y axes
//vec3_t centerText(float x, float y, float width, float height, float textWidth, float textHeight);
//center on X axis only
float centerText(float x, float width, float textWidth);
};
#include "stdafx.h"
#include "Entity.h"
#include "Offsets.h"
bool checkTeam(playerent* a, playerent* b)
{
int * gameMode = (int*)Offsets::GameMode;
if (*gameMode == 0 || *gameMode == 4 || *gameMode == 5 || *gameMode == 7 || *gameMode == 13 || *gameMode == 11 || *gameMode == 14 || *gameMode == 17 || *gameMode == 16 || *gameMode == 20 || *gameMode == 21) {
if (a->team == b->team)
return true;
else
return false;
}
else
{
return false;
}
};
#include "Math.h"
enum State{
CS_ALIVE = 0,
CS_DEAD,
};
class weapon {
public:
char _0x0000[4];
BYTE ID; //0x0004
char _0x0005[59];
};
class playerent
{
public:
char _0x0000[4];
vec vLocationHead; //0x0004
char _0x0010[36];
vec vLocation; //0x0034
vec vViewAngle; //0x0040
char _0x004C[37];
BYTE bScoping; //0x0071
char _0x0072[134];
__int32 health; //0x00F8
__int32 armor; //0x00FC
char _0x0100[292];
BYTE bAttacking; //0x0224
char name[16]; //0x0225
char _0x0235[247];
BYTE team; //0x032C
char _0x032D[11];
BYTE state; //0x0338
char _0x0339[59];
weapon* currentWeapon; //0x0374
char _0x0378[520];
};
class Player {
private:
int id;
playerent* play;
vec angles;
public:
vec getAngles()
{
return angles;
}
playerent* getPlayerEnt()
{
return play;
}
int getID()
{
return id;
}
void setAngles(vec angle)
{
angles = angle;
}
void setID(int num)
{
id = num;
}
void setPlayerEnt(playerent* playerent)
{
play = playerent;
}
};
bool checkTeam(playerent* a, playerent* b);
#include "stdafx.h"
#include "Esp.h"
#include "Math.h"
#include "Offsets.h"
#include "glut.h"
#include "Draw.h"
#include "Entity.h"
extern Draw drawClass;
extern int* pCount;
extern int EntArrPtr;
extern Player pList[32];
extern playerent* localPlayer;
extern float getDistance(vec to, vec from);
extern bool IsVisible(vec from, vec to, float* tracer);
glmatrixf* GetViewMatrix() {
return (glmatrixf*)0x00501AE8;
};
vec W2S(glmatrixf *mvpmatrix, vec vPlayerLoc)
{
//GuidedHacking.com : AnomanderRake
//Matrix-Vector Product, multiplying world(eye) coordinates by projection matrix = clipCoords
vec4 clipCoords;
clipCoords.x = vPlayerLoc.x*mvpmatrix->v[0] + vPlayerLoc.y*mvpmatrix->v[4] + vPlayerLoc.z*mvpmatrix->v[8] + mvpmatrix->v[12];
clipCoords.y= vPlayerLoc.x*mvpmatrix->v[1] + vPlayerLoc.y*mvpmatrix->v[5] + vPlayerLoc.z*mvpmatrix->v[9] + mvpmatrix->v[13];
clipCoords.z = vPlayerLoc.x*mvpmatrix->v[2] + vPlayerLoc.y*mvpmatrix->v[6] + vPlayerLoc.z*mvpmatrix->v[10] + mvpmatrix->v[14];
clipCoords.w = vPlayerLoc.x*mvpmatrix->v[3] + vPlayerLoc.y*mvpmatrix->v[7] + vPlayerLoc.z*mvpmatrix->v[11] + mvpmatrix->v[15];
if (clipCoords.w < 0) return vec(-1, -1, -1);
//perspective division, dividing by clip.W = NDC
vec normalizedDeviceCoordinates;
normalizedDeviceCoordinates.x = clipCoords.x / clipCoords.w;
normalizedDeviceCoordinates.y = clipCoords.y / clipCoords.w;
normalizedDeviceCoordinates.z = clipCoords.z / clipCoords.w;
//viewport tranform to screenCooords
int viewport[4] = { 0, 0 , *(int*)0x510c94, *(int*)0x510c98 };
vec playerScreenCoords;
playerScreenCoords.x = (viewport[2] / 2 * normalizedDeviceCoordinates.x) + (normalizedDeviceCoordinates.x + viewport[2] / 2);
playerScreenCoords.y = -(viewport[3] / 2 * normalizedDeviceCoordinates.y) + (normalizedDeviceCoordinates.y + viewport[3] / 2);
playerScreenCoords.z = 0;
return playerScreenCoords;
};
void RenderESP(playerent* ent, char name[16], int heal, vec DrawPos, float dist, int r, int g, int b)
{
int width = *(DWORD*)Offsets::SCRWidth;
int height = *(DWORD*)Offsets::SCHeight;
drawClass.stringD(DrawPos.x - (width / 2.5) / dist, (DrawPos.y - (height / 2) / dist), 255, 255, 255, GLUT_BITMAP_TIMES_ROMAN_10, "%s", name);
glmatrixf * glmvpmatrix = (glmatrixf*)(Offsets::GLMatrix);
vec footPos = W2S(glmvpmatrix, ent->vLocation);
vec headPosistion = W2S(glmvpmatrix, ent->vLocationHead);
int heightesp = footPos.y - (headPosistion.y);
int widthesp = heightesp / 2;
heightesp *= 1.17;
widthesp *= 1.17;
int x = headPosistion.x - widthesp / 2;
int y = headPosistion.y;
if (heal > 100)
heal = 100;
if (heal < 1)
heal = 1;
drawClass.stringD(x, y-15, 255, 255, 255, GLUT_BITMAP_HELVETICA_12, "%s", name);
int strHeal = (int)heightesp - heal * (int)heightesp / 100;
drawClass.boxLine(2.0f, x - 12, y - 16, 6, heightesp + 4, 0, 0, 0);
drawClass.box(x - 10, y + strHeal - 15, 4, heightesp - strHeal + 2, 153, 255, 0);
drawClass.boxLine(1.0f, x, y-15, widthesp, heightesp, r, g, b);
glPopMatrix();
}
void DoEsp()
{
for (int i = 0; i < (*pCount); i++)
{
if (!pList[i].getPlayerEnt()) continue;
glmatrixf * glmvpmatrix = (glmatrixf*)(Offsets::GLMatrix);
pList[i].setPlayerEnt( (playerent*)*(int*)(EntArrPtr + (0x4 * i)));
if (!pList[i].getPlayerEnt() || !localPlayer) continue;
vec DrawPos;
if (pList[i].getPlayerEnt()->state != CS_DEAD)
{
vec footPos = W2S(glmvpmatrix, pList[i].getPlayerEnt()->vLocation);
vec headPosistion = W2S(glmvpmatrix, pList[i].getPlayerEnt()->vLocationHead);
if (footPos.x > 0 && headPosistion.x > 0)
{
float dist = getDistance(pList[i].getPlayerEnt()->vLocationHead, localPlayer->vLocationHead);
float r = 0, g = 0, b = 0;
if (IsVisible(localPlayer->vLocationHead, pList[i].getPlayerEnt()->vLocationHead))
{
r = 0; g = 255; b = 0;
}
else {
r = 255; g = 0; b = 0;
}
if (checkTeam(localPlayer, pList[i].getPlayerEnt())) {
r = 0; g = 0; b = 255;
}
RenderESP(pList[i].getPlayerEnt(), pList[i].getPlayerEnt()->name, pList[i].getPlayerEnt()->health, DrawPos, dist, r, g, b);
}
}
}
}
#ifndef ESP_H
#define ESP_H
#include "Math.h"
void DoEsp();
#endif
#include "stdafx.h"
#include "Math.h"
#include "Offsets.h"
#include "Entity.h"
extern playerent* localPlayer;
float getDistance(vec to, vec from)
{
return (float)
(sqrt(
powf(to.x - from.x, 2.0) +
powf(to.y - from.y, 2.0) +
powf(to.z - from.z, 2.0)
));
}
bool IsVisible(vec from, vec to, float* tracer)
{
DWORD traceLine = Offsets::TraceLine;
traceresult_s traceresult;
traceresult.collided = false;
from.z -= 0.2f; //weaponBelowEye
__asm
{
push 0; bSkipTags //try with 1
push 0; bCheckPlayers
push localPlayer
push to.z
push to.y
push to.x
push from.z
push from.y
push from.x
lea eax, [traceresult]
call traceLine;
add esp, 36
}
return !traceresult.collided;
};
#ifndef MATH_H /* Include guard */
#define MATH_H
#include <math.h>
#define UFINVSQRT(x) union { int d; float f; } u; u.f = x; u.d = 0x5f3759df - (u.d >> 1)
inline float ufInvSqrt(float x) { UFINVSQRT(x); return u.f; } // about 3.5% of error
inline float fInvSqrt(float x) { UFINVSQRT(x); return 0.5f * u.f * (3.00175f - x * u.f * u.f); } // about 0.1% of error
inline float fSqrt(float x) { return x * fInvSqrt(x); }
inline float ufSqrt(float x) { return x * ufInvSqrt(x); }
struct vec
{
union
{
struct { float x, y, z; };
float v[3];
int i[3];
};
vec() { x = y = z = 0; }
vec(float a, float b, float c) : x(a), y(b), z(c) {}
vec(float *v) : x(v[0]), y(v[1]), z(v[2]) {}
float &operator[](int i) { return v[i]; }
float operator[](int i) const { return v[i]; }
bool iszero() const { return x == 0 && y == 0 && z == 0; }
bool operator==(const vec &o) const { return x == o.x && y == o.y && z == o.z; }
bool operator!=(const vec &o) const { return x != o.x || y != o.y || z != o.z; }
vec operator-() const { return vec(-x, -y, -z); }
vec &mul(float f) { x *= f; y *= f; z *= f; return *this; }
vec &div(float f) { x /= f; y /= f; z /= f; return *this; }
vec &add(float f) { x += f; y += f; z += f; return *this; }
vec &sub(float f) { x -= f; y -= f; z -= f; return *this; }
vec &add(const vec &o) { x += o.x; y += o.y; z += o.z; return *this; }
vec &sub(const vec &o) { x -= o.x; y -= o.y; z -= o.z; return *this; }
float squaredlen() const { return x*x + y*y + z*z; }
float sqrxy() const { return x*x + y*y; }
float dot(const vec &o) const { return x*o.x + y*o.y + z*o.z; }
float dotxy(const vec &o) const { return x*o.x + y*o.y; }
float magnitude() const { return sqrtf(squaredlen()); }
vec &normalize() { div(magnitude()); return *this; }
// should NOT be used
float fmag() const { return fSqrt(squaredlen()); }
float ufmag() const { return ufSqrt(squaredlen()); }
float fmagxy() const { return fSqrt(x*x + y*y); }
float ufmagxy() const { return ufSqrt(x*x + y*y); }
float dist(const vec &e) const { vec t; return dist(e, t); }
float dist(const vec &e, vec &t) const { t = *this; t.sub(e); return t.magnitude(); }
float distxy(const vec &e) const { float dx = e.x - x, dy = e.y - y; return sqrtf(dx*dx + dy*dy); }
float magnitudexy() const { return sqrtf(x*x + y*y); }
bool reject(const vec &o, float max) const { return x>o.x + max || x<o.x - max || y>o.y + max || y<o.y - max; }
vec &cross(const vec &a, const vec &b) { x = a.y*b.z - a.z*b.y; y = a.z*b.x - a.x*b.z; z = a.x*b.y - a.y*b.x; return *this; }
float cxy(const vec &a) { return x*a.y - y*a.x; }
void rotate_around_z(float angle) { *this = vec(cosf(angle)*x - sinf(angle)*y, cosf(angle)*y + sinf(angle)*x, z); }
void rotate_around_x(float angle) { *this = vec(x, cosf(angle)*y - sinf(angle)*z, cosf(angle)*z + sinf(angle)*y); }
void rotate_around_y(float angle) { *this = vec(cosf(angle)*x - sinf(angle)*z, y, cosf(angle)*z + sinf(angle)*x); }
vec &rotate(float angle, const vec &d)
{
float c = cosf(angle), s = sinf(angle);
return rotate(c, s, d);
}
vec &rotate(float c, float s, const vec &d)
{
*this = vec(x*(d.x*d.x*(1 - c) + c) + y*(d.x*d.y*(1 - c) - d.z*s) + z*(d.x*d.z*(1 - c) + d.y*s),
x*(d.y*d.x*(1 - c) + d.z*s) + y*(d.y*d.y*(1 - c) + c) + z*(d.y*d.z*(1 - c) - d.x*s),
x*(d.x*d.z*(1 - c) - d.y*s) + y*(d.y*d.z*(1 - c) + d.x*s) + z*(d.z*d.z*(1 - c) + c));
return *this;
}
void orthogonal(const vec &d)
{
int i = fabs(d.x) > fabs(d.y) ? (fabs(d.x) > fabs(d.z) ? 0 : 2) : (fabs(d.y) > fabs(d.z) ? 1 : 2);
v[i] = d[(i + 1) % 3];
v[(i + 1) % 3] = -d[i];
v[(i + 2) % 3] = 0;
}
};
static inline bool htcmp(const vec &x, const vec &y)
{
return x == y;
}
static inline unsigned int hthash(const vec &k)
{
return k.i[0] ^ k.i[1] ^ k.i[2];
}
struct vec4
{
union
{
struct { float x, y, z, w; };
float v[4];
};
vec4() {}
explicit vec4(const vec &p, float w = 0) : x(p.x), y(p.y), z(p.z), w(w) {}
vec4(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
float &operator[](int i) { return v[i]; }
float operator[](int i) const { return v[i]; }
};
struct ivec
{
union
{
struct { int x, y, z; };
int v[3];
};
ivec() {}
ivec(const vec &v) : x(int(v.x)), y(int(v.y)), z(int(v.z)) {}
ivec(int a, int b, int c) : x(a), y(b), z(c) {}
vec tovec() const { return vec(x, y, z); }
int &operator[](int i) { return v[i]; }
int operator[](int i) const { return v[i]; }
bool operator==(const ivec &v) const { return x == v.x && y == v.y && z == v.z; }
bool operator!=(const ivec &v) const { return x != v.x || y != v.y || z != v.z; }
ivec &mul(int n) { x *= n; y *= n; z *= n; return *this; }
ivec &div(int n) { x /= n; y /= n; z /= n; return *this; }
ivec &add(int n) { x += n; y += n; z += n; return *this; }
ivec &sub(int n) { x -= n; y -= n; z -= n; return *this; }
ivec &add(const ivec &v) { x += v.x; y += v.y; z += v.z; return *this; }
ivec &sub(const ivec &v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
ivec &mask(int n) { x &= n; y &= n; z &= n; return *this; }
ivec &cross(const ivec &a, const ivec &b) { x = a.y*b.z - a.z*b.y; y = a.z*b.x - a.x*b.z; z = a.x*b.y - a.y*b.x; return *this; }
int dot(const ivec &o) const { return x*o.x + y*o.y + z*o.z; }
};
static inline bool htcmp(const ivec &x, const ivec &y)
{
return x == y;
}
static inline unsigned int hthash(const ivec &k)
{
return k.x^k.y^k.z;
}
struct bvec
{
union
{
struct { unsigned char x, y, z; };
unsigned char v[3];
};
bvec() {}
bvec(unsigned char x, unsigned char y, unsigned char z) : x(x), y(y), z(z) {}
bvec(const vec &v) : x((unsigned char)((v.x + 1) * 255 / 2)), y((unsigned char)((v.y + 1) * 255 / 2)), z((unsigned char)((v.z + 1) * 255 / 2)) {}
unsigned char &operator[](int i) { return v[i]; }
unsigned char operator[](int i) const { return v[i]; }
bool operator==(const bvec &v) const { return x == v.x && y == v.y && z == v.z; }
bool operator!=(const bvec &v) const { return x != v.x || y != v.y || z != v.z; }
bool iszero() const { return x == 0 && y == 0 && z == 0; }
vec tovec() const { return vec(x*(2.0f / 255.0f) - 1.0f, y*(2.0f / 255.0f) - 1.0f, z*(2.0f / 255.0f) - 1.0f); }
};
struct glmatrixf
{
float v[16];
float operator[](int i) const { return v[i]; }
float &operator[](int i) { return v[i]; }
#define ROTVEC(A, B) \
{ \
float a = A, b = B; \
A = a*c + b*s; \
B = b*c - a*s; \
}
void rotate_around_x(float angle)
{
float c = cosf(angle), s = sinf(angle);
ROTVEC(v[4], v[8]);
ROTVEC(v[5], v[9]);
ROTVEC(v[6], v[10]);
}
void rotate_around_y(float angle)
{
float c = cosf(angle), s = sinf(angle);
ROTVEC(v[8], v[0]);
ROTVEC(v[9], v[1]);
ROTVEC(v[10], v[2]);
}
void rotate_around_z(float angle)
{
float c = cosf(angle), s = sinf(angle);
ROTVEC(v[0], v[4]);
ROTVEC(v[1], v[5]);
ROTVEC(v[2], v[6]);
}
#undef ROTVEC
#define MULMAT(row, col) \
v[col + row] = x[row]*y[col] + x[row + 4]*y[col + 1] + x[row + 8]*y[col + 2] + x[row + 12]*y[col + 3];
template<class XT, class YT>
void mul(const XT x[16], const YT y[16])
{
MULMAT(0, 0); MULMAT(1, 0); MULMAT(2, 0); MULMAT(3, 0);
MULMAT(0, 4); MULMAT(1, 4); MULMAT(2, 4); MULMAT(3, 4);
MULMAT(0, 8); MULMAT(1, 8); MULMAT(2, 8); MULMAT(3, 8);
MULMAT(0, 12); MULMAT(1, 12); MULMAT(2, 12); MULMAT(3, 12);
}
#undef MULMAT
void mul(const glmatrixf &x, const glmatrixf &y)
{
mul(x.v, y.v);
}
void identity()
{
static const float m[16] =
{
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
memcpy(v, m, sizeof(v));
}
void translate(float x, float y, float z)
{
v[12] += x;
v[13] += y;
v[14] += z;
}
void translate(const vec &o)
{
translate(o.x, o.y, o.z);
}
void scale(float x, float y, float z)
{
v[0] *= x; v[1] *= x; v[2] *= x; v[3] *= x;
v[4] *= y; v[5] *= y; v[6] *= y; v[7] *= y;
v[8] *= z; v[9] *= z; v[10] *= z; v[11] *= z;
}
void projective()
{
//loopi(2) loopj(4) v[i + j * 4] = 0.5f*(v[i + j * 4] + v[3 + j * 4]);
}
void invertnormal(vec &dir) const
{
vec n(dir);
dir.x = n.x*v[0] + n.y*v[1] + n.z*v[2];
dir.y = n.x*v[4] + n.y*v[5] + n.z*v[6];
dir.z = n.x*v[8] + n.y*v[9] + n.z*v[10];
}
void invertvertex(vec &pos) const
{
vec p(pos);
p.x -= v[12];
p.y -= v[13];
p.z -= v[14];
pos.x = p.x*v[0] + p.y*v[1] + p.z*v[2];
pos.y = p.x*v[4] + p.y*v[5] + p.z*v[6];
pos.z = p.x*v[8] + p.y*v[9] + p.z*v[10];
}
float transformx(const vec &p) const
{
return p.x*v[0] + p.y*v[4] + p.z*v[8] + v[12];
}
float transformy(const vec &p) const
{
return p.x*v[1] + p.y*v[5] + p.z*v[9] + v[13];
}
float transformz(const vec &p) const
{
return p.x*v[2] + p.y*v[6] + p.z*v[10] + v[14];
}
float transformw(const vec &p) const
{
return p.x*v[3] + p.y*v[7] + p.z*v[11] + v[15];
}
void transform(const vec &in, vec &out) const
{
out.x = transformx(in);
out.y = transformy(in);
out.z = transformz(in);
//out.w = transformw(in);
}
vec Transform(const vec &in, vec &out) const
{
out.x = transformx(in);
out.y = transformy(in);
out.z = transformz(in);
//out.w = transformw(in);
return vec(out.x, out.y, out.z);
}
vec gettranslation() const
{
return vec(v[12], v[13], v[14]);
}
float determinant() const;
void adjoint(const glmatrixf &m);
bool invert(const glmatrixf &m, float mindet = 1.0e-10f);
};
struct traceresult_s
{
vec end;
bool collided;
};
bool IsVisible(vec from, vec to, float* tracer = NULL);
float getDistance(vec to, vec from);
#endif
#include "stdafx.h"
#include "Menu.h"
#include "Draw.h"
#include "glut.h"
#include <string>
extern bool isMenu;
extern int scalebox;
extern Draw drawClass;
extern int version;
extern int height;
extern int width;
float menu_height, menu_width, scroll_width, scroll_height, scroll_distance, scrollX, scrollY;
int scrollIndex, menuIndex;
extern void toggleRapidFire();
extern void toggleRecoil();
extern void toggleGrenade();
extern void toggleAuto();
extern void toggleESP();
extern void toggleTrigger();
extern void toggleRage();
extern void toggleAmmo();
extern void toggleAimbot();
void setFunctionToggle(string check)
{
for(int i = 0; i < menuPages; i++)
for (int x = 0; x < maxScroll[i]; x++)
{
if (menuOptions[i][x] == (check))
{
menuOn[i][x] = !menuOn[i][x];
}
}
}
void DrawMenu()
{
int propX = 1920+675;
int propY = 1080;
menu_width = (400*width)/propX;
menu_height = (800 * height) / propY;
scroll_width = (320 * width) / propX;
scroll_height = (40 * height) / propY;
scroll_distance = (menu_height / ((6.666 * height) / propY));
scrollX = ((90 * width) / propX);
drawClass.stringD(((220 * width) / propX), ((70 * height) / propY), 255, 0, 0, GLUT_BITMAP_9_BY_15, "%s%d", "Maverick V", version);
drawClass.stringD(((220 * width) / propX), ((100 * height) / propY), 255, 255, 255, GLUT_BITMAP_9_BY_15, "%s", menus[menuIndex].c_str());
for (int i = 0; i <= maxScroll[menuIndex]; i++)
{
if (menuOn[menuIndex][i])
{
if(scrollIndex == i)
drawClass.stringD((menu_width / ((3.4 * width) / propX)), (menu_height / ((4.2 * height) / propY)) + (scroll_distance * (i)), 0, 255, 0, GLUT_BITMAP_HELVETICA_18, "%s", menuOptions[menuIndex][i].c_str());
else
drawClass.stringD((menu_width / ((3.4 * width) / propX)), (menu_height / ((4.2 * height) / propY)) + (scroll_distance * (i)), 0, 255, 0, GLUT_BITMAP_HELVETICA_12, "%s", menuOptions[menuIndex][i].c_str());
}
else
{
if(scrollIndex == i)
drawClass.stringD((menu_width / ((3.4 * width) / propX)), (menu_height / ((4.2 * height) / propY)) + (scroll_distance * (i)), 255, 0, 0, GLUT_BITMAP_HELVETICA_18, "%s", menuOptions[menuIndex][i].c_str());
else
drawClass.stringD((menu_width / ((3.4 * width) / propX)), (menu_height / ((4.2 * height) / propY)) + (scroll_distance * (i)), 255, 0, 0, GLUT_BITMAP_HELVETICA_12, "%s", menuOptions[menuIndex][i].c_str());
}
}
scrollY = (height / ((7*(height))/propY) ) + ((scrollIndex)* scroll_distance);
//Scroll Bar
//drawClass.box(scrollX, scrollY, scroll_width, scroll_height, 255, 255, 255);
drawClass.line(1.0f, scrollX, scrollY, scrollX + (15*width)/propX, scrollY+(15*height)/propY, 255, 255, 255);
drawClass.line(1.0f, scrollX, scrollY, scrollX, scrollY + (30*height)/propY, 255, 255, 255);
drawClass.line(1.0f, scrollX, scrollY+(30*height)/propY, scrollX + (15*width)/propX, scrollY + (15*height)/propY, 255, 255, 255);
//Menu Border
drawClass.boxLine(((4 * width) / propX), ((50 * width) / propX), ((50 * height) / propY), menu_width, menu_height, 255, 0, 0);
//Menu Title Center
drawClass.line(((4 * width) / propX), ((90 * width) / propX), ((80 * height) / propY), (((50 * width) / propX) + menu_width) - ((40 * width) / propX), ((80 * height) / propY), 255, 0, 0);
//Menu Title Angle
drawClass.line(((4 * width) / propX), ((50 * width) / propX) + menu_width, (50 * height) / propY, (((50 * width) / propX) + menu_width) - ((40 * width) / propX), (80 * height) / propY, 255, 0, 0);
//Menu Title Angle
drawClass.line(((4 * width) / propX), ((50 * width) / propX), ((50 * height) / propY), ((90 * width) / propX), ((80 * height) / propY), 255, 0, 0);
//Menu Background
drawClass.box((50 * width) / propX, (50 * height) / propY, menu_width, menu_height, 0, 0, 0, 200);
}
void KeyMenu()
{
if (GetAsyncKeyState(VK_RSHIFT))
{
isMenu = !isMenu;
if (!isMenu)
{
menuIndex = 0;
scrollIndex = 0;
}
}
if (GetAsyncKeyState(VK_INSERT))
{
((void(__thiscall*)(const char* string))0x408E80)(("Aimbot distance level is now : " + std::to_string(scalebox) + " !").c_str());
scalebox += 2;
}
if (GetAsyncKeyState(VK_DELETE)) {
((void(__thiscall*)(const char* string))0x408E80)(("Aimbot distance level is now : " + std::to_string(scalebox) + " !").c_str());
scalebox -= 2;
}
if (GetAsyncKeyState(VK_CONTROL) && isMenu)
{
menuOn[menuIndex][scrollIndex] = !menuOn[menuIndex][scrollIndex];
switch (menuIndex)
{
case 0:
switch (scrollIndex)
{
case 0:
toggleRecoil();
break;
case 1:
toggleGrenade();
break;
case 2:
toggleAuto();
break;
case 3:
toggleESP();
break;
case 4:
toggleTrigger();
break;
case 5:
toggleAimbot();
break;
case 6:
toggleRage();
break;
}
break;
case 1:
switch (scrollIndex)
{
case 0:
toggleRapidFire();
break;
case 1:
toggleAmmo();
break;
}
break;
}
}
if (GetAsyncKeyState(VK_UP))
{
scrollIndex--;
if (scrollIndex < 0)
{
scrollIndex = maxScroll[menuIndex];
}
}
if (GetAsyncKeyState(VK_DOWN))
{
scrollIndex++;
if (scrollIndex > maxScroll[menuIndex])
{
scrollIndex = 0;
}
}
if (GetAsyncKeyState(VK_LEFT))
{
scrollIndex = 0;
menuIndex--;
if (menuIndex < 0)
{
menuIndex = menuPages-1;
}
}
if (GetAsyncKeyState(VK_RIGHT))
{
scrollIndex = 0;
menuIndex++;
if (menuIndex > menuPages-1)
{
menuIndex = 0;
}
}
}
#ifndef MENU_H
#define MENU_H
#include <iostream>
using namespace std;
const int menuPages = 2;
string menus[menuPages] = {"Online", "Offline", };
string menuOptions[menuPages][8] = { { "Recoil", "Grenade", "AutoFire", "Esp", "Trigger", "Aimbot", "Rage + Trigger" },
{ "Rapid Fire", "Unlimited Ammo", "AutoFire", "Esp", "Trigger", "Aimbot", "Rage + Trigger" } };
bool menuOn[menuPages][8] = {
0, 0, 0, 0,0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
int maxScroll[menuPages] = {6, 1,};
void DrawMenu();
void KeyMenu();
#endif
#include "stdafx.h"
#include "Mod.h"
#include "Offsets.h"
#include "ProcessMemoryWriter.h"
#include <string>
#include "Entity.h"
extern MemoryWriter memoryWriter;
using namespace std;
DWORD ammoAddress = Offsets::AmmoModifier;
char ammoBinNew[] = "\xFF\x06";
char ammoBinDef[] = "\xFF\x0E";
DWORD autoAddress = Offsets::AutoWeaponModifier;
char autoBinNew[] = "\xEB\x09";
char autoBinDef[] = "\x75\x09";
DWORD rapidAddress = Offsets::RapidFireModifier;
DWORD rapidAddress2 = Offsets::RapidFireModifier2;
char rapidBinNew[] = "\x90\x90";
char rapidBinDef[] = "\x89\x0A";
DWORD grenAddress = Offsets::GrenadeModifier;
char grenBinDef[] = "\xFF\x08";
char grenNewDef[] = "\xFF\x00";
DWORD baseOffsets[] = { 0x30 };
DWORD baseAddress = Offsets::ACBase;
extern playerent* localPlayer;
DWORD recoilAdresses[] = { 0x463781, 0x463783, 0x463786, 0x463787, 0x46378B, 0x46378C, 0x46378E };
std::string recoilBinNew[] = {
"\x90\x90",
"\x90\x90\x90",
"\x90",
"\x90\x90\x90\x90",
"\x90",
"\x90\x90",
"\x90\x90",
};
std::string recoilBinDef[] = {
"\x8B\x16",
"\x8B\x52\x14",
"\x50",
"\x8D\x4C\x24\x1C",
"\x51",
"\x8B\xCE",
"\xFF\xD2",
};
int recoilOpBytes[] = {
2,
3,
1,
4,
1,
2,
2,
};
void toggleAimbot()
{
isAimbot = !isAimbot;
}
void toggleRecoil()
{
if (isRecoil)
{
for (int i = 0; i < 7; i++)
{
memoryWriter.writeMemory(recoilAdresses[i], recoilBinDef[i], recoilOpBytes[i]);
}
}
else
{
for (int i = 0; i < 7; i++)
{
memoryWriter.writeMemory(recoilAdresses[i], recoilBinNew[i], recoilOpBytes[i]);
}
}
isRecoil = !isRecoil;
}
void toggleGrenade()
{
if (isGrenade)
memoryWriter.writeMemory(grenAddress, grenBinDef, 2);
else
memoryWriter.writeMemory(grenAddress, grenNewDef, 2);
isGrenade = !isGrenade;
}
void toggleAuto()
{
if (!isAutoFire)
memoryWriter.writeMemory(autoAddress, autoBinNew, 2);
else
memoryWriter.writeMemory(autoAddress, autoBinDef, 2);
}
void toggleRapidFire()
{
if (!isRapid)
{
memoryWriter.writeMemory(rapidAddress, rapidBinNew, 2);
memoryWriter.writeMemory(rapidAddress2, rapidBinNew, 2);
}
else
{
memoryWriter.writeMemory(rapidAddress, rapidBinDef, 2);
memoryWriter.writeMemory(rapidAddress2, rapidBinDef, 2);
}
}
void toggleESP()
{
isEsp = !isEsp;
}
void toggleRage()
{
toggleAimbot();
isRage = !isRage;
localPlayer->vViewAngle = vec(0, -180, 0);
}
void toggleTrigger()
{
isTrigger = !isTrigger;
}
void toggleAmmo()
{
if (!isAmmo)
memoryWriter.writeMemory(ammoAddress, ammoBinNew, 2);
else
memoryWriter.writeMemory(ammoAddress, ammoBinDef, 2);
}
#ifndef MOD_H /* Include guard */
#define MOD_H
bool isRecoil = false;
bool isGrenade = false;
bool isAutoFire = false;
bool isEsp = false;
bool isAimbot = false;
bool isRage = false;
bool isRapid = false;
bool isAmmo = false;
bool isTrigger = false;
void toggleAimbot();
void toggleRecoil();
void toggleGrenade();
void toggleAuto();
void toggleRapidFire();
void toggleESP();
void toggleRage();
void toggleTrigger();
void toggleAmmo();
#endif
enum Offsets {
ACBase = 0x50F4F4,
EntityArray = 0x50F4F8,
CrosshairName = 0x501C38,
SCRWidth = 0x510C94,
SCHeight = 0x510C98,
GLMatrix = 0x501AE8,
AmmoModifier = 0x4637E9,
AutoWeaponModifier = 0x463716,
RapidFireModifier = 0x4637E4,
RapidFireModifier2 = 0x463387,
GrenadeModifier = 0x463378,
GameMode = 0x50F49C,
TraceLine = 0x048a310,
PlayerCount = 0x50F500,
};
#pragma once
#include "stdafx.h"
#include "ProcessMemoryWriter.h"
char *MemoryWriter::stringToChar(std::string str)
{
char *character = new char[str.length() + 1];
std::strcpy(character, str.c_str());
return character;
}
HWND window;
DWORD pid;
HANDLE windowHandle;
int MemoryWriter::setupWindowHandles(char* processName)
{
window = FindWindow(0, processName);
GetWindowThreadProcessId(window, &pid);
windowHandle = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
//GetWindowThreadProcessId(window, &pid); //Get the process id and place it in pid
//windowHandle = OpenProcess(PROCESS_VM_READ, 0, pid);
return 1;
}
int MemoryWriter::closeHandles()
{
CloseHandle(windowHandle);
window = NULL;
return 1;
}
DWORD MemoryWriter::getProcessBaseAddress(char* processName)
{
const char* processName_ = processName;
DWORD processID_ = NULL;
DWORD processBaseAddress_ = 0;
PROCESSENTRY32 processEntry_; // Entry into process you wish to inject to
HANDLE hProcSnapshot_ = NULL;
/* Takes a snapshot of the system's processes */
hProcSnapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //?
/* While process has not been found, keep looking for it */
while (!processID_)
{
/* If a process on the system exists */
if (Process32First(hProcSnapshot_, &processEntry_)) //?
{
/* Check all processes in the system's processes snapshot */
do
{
/* Compare the name of the process to the one we want */
if (!strcmp(processEntry_.szExeFile, processName_)) //?
{
/* Save the processID and break out */
processID_ = processEntry_.th32ProcessID;
break;
}
} while (Process32Next(hProcSnapshot_, &processEntry_));
}
/* Didnt find process, sleep for a bit */
if (!processID_)
{
system("CLS");
std::cout << "Make sure " << processName_ << " is running." << std::endl;
Sleep(200);
}
}
/* Process found */
std::cout << "Found Process: " << processName_ << std::endl;
/* Find Base Address of process */
HANDLE moduleSnapshotHandle_ = INVALID_HANDLE_VALUE;
MODULEENTRY32 moduleEntry_;
/* Take snapshot of all the modules in the process */
moduleSnapshotHandle_ = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processID_);
/* Snapshot failed */
if (moduleSnapshotHandle_ == INVALID_HANDLE_VALUE)
{
std::cout << "Module Snapshot error" << std::endl;
MessageBoxA(0, "Module snapshot error", "", 0);
return 0;
}
/* Size the structure before usage */
moduleEntry_.dwSize = sizeof(MODULEENTRY32);
/* Retrieve information about the first module */
if (!Module32First(moduleSnapshotHandle_, &moduleEntry_))
{
std::cout << "First module not found" << std::endl;
MessageBoxA(0, "Module not found", "", 0);
CloseHandle(moduleSnapshotHandle_);
return 0;
}
/* Find base address */
while (!processBaseAddress_)
{
/* Find module of the executable */
do
{
/* Compare the name of the process to the one we want */
if (!strcmp(moduleEntry_.szModule, processName_)) //?
{
/* Save the processID and break out */
processBaseAddress_ = (unsigned int)moduleEntry_.modBaseAddr;
break;
}
} while (Module32Next(moduleSnapshotHandle_, &moduleEntry_));
if (!processBaseAddress_)
{
system("CLS");
std::cout << "Failed to find module" << processName_ << std::endl;
MessageBoxA(0, "Module !_!_!", "", 0);
Sleep(200);
}
}
/* Found module and base address successfully */
std::cout << "Base Address: " << std::hex << processBaseAddress_ << std::dec << std::endl;
CloseHandle(moduleSnapshotHandle_);
return processBaseAddress_;
}
DWORD MemoryWriter::FindDmaAddy(int PointerLevel, DWORD Offsets[], DWORD BaseAddress)
{
//DECLARE BASE ADDRESS
DWORD pointer = BaseAddress; // Declare a pointer of DWORD
//USED TO output the contents in the pointer
DWORD pTemp;
DWORD pointerAddr;
for (int i = 0; i < PointerLevel; i++)
{
if (i == 0)
{
ReadProcessMemory(windowHandle, (LPCVOID)pointer, &pTemp, 4, NULL);
}
//add first offset to that address
pointerAddr = pTemp + Offsets[i]; // Set p1 to content of p + offset
//Read memory one more time and exit the loop
ReadProcessMemory(windowHandle, (LPCVOID)pointerAddr, &pTemp, 4, NULL);
}
return pointerAddr;
}
void MemoryWriter::writeMemory(DWORD address, char* value, int bytes)
{
unsigned long Oldprotection;
VirtualProtect((LPVOID)address, bytes, PAGE_EXECUTE_READWRITE, &Oldprotection);
memcpy((LPVOID)address, value, bytes);
VirtualProtect((LPVOID)address, bytes, Oldprotection, NULL);
}
void MemoryWriter::writeMemory(DWORD address, std::string value, int bytes)
{
unsigned long Oldprotection;
VirtualProtect((LPVOID)address, bytes, PAGE_EXECUTE_READWRITE, &Oldprotection);
memcpy((LPVOID)address, stringToChar(value), bytes);
VirtualProtect((LPVOID)address, bytes, Oldprotection, NULL);
}
HANDLE MemoryWriter::getHandle()
{
return windowHandle;
}
HWND MemoryWriter::getWindow()
{
return window;
}
int MemoryWriter::writeProcessMemory(DWORD address, int value)
{
return WriteProcessMemory(windowHandle, (void*)address, &value, sizeof(value), 0);
}
int MemoryWriter::writeProcessMemory(DWORD address, float value)
{
return WriteProcessMemory(windowHandle, (void*)address, &value, sizeof(value), 0);
}
int MemoryWriter::readProcessMemory(DWORD address, int *value)
{
return ReadProcessMemory(windowHandle, (void*)address, value, sizeof(value), 0);
}
int MemoryWriter::readProcessMemory(DWORD address, float *value)
{
return ReadProcessMemory(windowHandle, (void*)address, value, sizeof(value), 0);
}
int MemoryWriter::readProcessMemory(DWORD address, float **value)
{
return ReadProcessMemory(windowHandle, (void*)address, value, sizeof(value), 0);
}
int MemoryWriter::readProcessMemory(DWORD address, DWORD* value)
{
return ReadProcessMemory(windowHandle, (void*)address, value, sizeof(value), NULL);
}
int MemoryWriter::readViewMatrix(float* value[])
{
return ReadProcessMemory(windowHandle, (void*)0x501AE8, value, sizeof(value), NULL);
}
#pragma once
#include "stdafx.h"
#include <Windows.h>
#include <conio.h>
#include <TlHelp32.h>
#include <stdio.h>
#include <iostream>
class MemoryWriter {
public:
HANDLE getHandle();
HWND getWindow();
int writeProcessMemory(DWORD address, int value);
int writeProcessMemory(DWORD address, float value);
int readProcessMemory(DWORD address, int *value);
int readProcessMemory(DWORD address, float *value);
int readProcessMemory(DWORD address, float **value);
int readProcessMemory(DWORD address, DWORD* value);
int readViewMatrix(float* value[]);
int setupWindowHandles(char* processName);
DWORD getProcessBaseAddress(char* processName);
DWORD FindDmaAddy(int PointerLevel, DWORD Offsets[], DWORD BaseAddress);
void writeMemory(DWORD address, char* value, int bytes);
void writeMemory(DWORD address, std::string value, int bytes);
int closeHandles();
private:
char * stringToChar(std::string str);
};
// stdafx.cpp : source file that includes just the standard includes
// assaultCubeDLL.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
// TODO: reference additional headers your program requires here
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment