HelpBackend work

Posts 1–8 of 8 · Page 1 of 1
Backend work
Is this good for like actually hooking and handling the game?

Code:
#pragma once

#include <Windows.h>
#include <TlHelp32.h>

class CHackProcess
{
public:

	PROCESSENTRY32 __gameProcess;
	HANDLE __HandleProcess;
	HWND __HWNDCss;
	DWORD __dwordClient;
	DWORD __dwordEngine;
	DWORD __dwordOverlay;
	DWORD __dwordVGui;
	DWORD __dwordLibCef;
	DWORD __dwordSteam;
	DWORD FindProcessName(const char *__ProcessName, PROCESSENTRY32 *pEntry)
	{
		PROCESSENTRY32 __ProcessEntry;
		__ProcessEntry.dwSize = sizeof(PROCESSENTRY32);
		HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
		if (hSnapshot == INVALID_HANDLE_VALUE)
			return 0;
		if (!Process32First(hSnapshot, &__ProcessEntry))
		{
			CloseHandle(hSnapshot);
			return 0;
		}
		do {
			if (!_strcmpi(__ProcessEntry.szExeFile, __ProcessName))
			{
				memcpy((void *)pEntry, (void *)&__ProcessEntry, sizeof(PROCESSENTRY32));
				CloseHandle(hSnapshot);
				return __ProcessEntry.th32ProcessID;
			}
		} while (Process32Next(hSnapshot, &__ProcessEntry));
		CloseHandle(hSnapshot);
		return 0;
	}


	DWORD getThreadByProcess(DWORD __DwordProcess)
	{
		THREADENTRY32 __ThreadEntry;
		__ThreadEntry.dwSize = sizeof(THREADENTRY32);
		HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
		if (hSnapshot == INVALID_HANDLE_VALUE) return 0;

		if (!Thread32First(hSnapshot, &__ThreadEntry)) { CloseHandle(hSnapshot); return 0; }

		do {
			if (__ThreadEntry.th32OwnerProcessID == __DwordProcess)
			{
				CloseHandle(hSnapshot);
				return __ThreadEntry.th32ThreadID;
			}
		} while (Thread32Next(hSnapshot, &__ThreadEntry));
		CloseHandle(hSnapshot);
		return 0;
	}

	DWORD GetModuleNamePointer(LPSTR LPSTRModuleName, DWORD __DwordProcessId)
	{
		MODULEENTRY32 lpModuleEntry = { 0 };
		HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, __DwordProcessId);
		if (!hSnapShot)
			return NULL;
		lpModuleEntry.dwSize = sizeof(lpModuleEntry);
		BOOL __RunModule = Module32First(hSnapShot, &lpModuleEntry);
		while (__RunModule)
		{
			if (!strcmp(lpModuleEntry.szModule, LPSTRModuleName))
			{
				CloseHandle(hSnapShot);
				return (DWORD)lpModuleEntry.modBaseAddr;
			}
			__RunModule = Module32Next(hSnapShot, &lpModuleEntry);
		}
		CloseHandle(hSnapShot);
		return NULL;
	}


	void runSetDebugPrivs()
	{
		HANDLE __HandleProcess = GetCurrentProcess(), __HandleToken;
		TOKEN_PRIVILEGES priv;
		LUID __LUID;
		OpenProcessToken(__HandleProcess, TOKEN_ADJUST_PRIVILEGES, &__HandleToken);
		LookupPrivilegeValue(0, "seDebugPrivilege", &__LUID);
		priv.PrivilegeCount = 1;
		priv.Privileges[0].Luid = __LUID;
		priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
		AdjustTokenPrivileges(__HandleToken, false, &priv, 0, 0, 0);
		CloseHandle(__HandleToken);
		CloseHandle(__HandleProcess);
	}



	void RunProcess()
	{
		runSetDebugPrivs();
		while (!FindProcessName("csgo.exe", &__gameProcess)) Sleep(12);
		while (!(getThreadByProcess(__gameProcess.th32ProcessID))) Sleep(12);
		__HandleProcess = OpenProcess(PROCESS_ALL_ACCESS, false, __gameProcess.th32ProcessID);
		while (__dwordClient == 0x0) __dwordClient = GetModuleNamePointer("client.dll", __gameProcess.th32ProcessID);
		while (__dwordEngine == 0x0) __dwordEngine = GetModuleNamePointer("engine.dll", __gameProcess.th32ProcessID);
		while (__dwordVGui == 0x0) __dwordVGui = GetModuleNamePointer("vguimatsurface.dll", __gameProcess.th32ProcessID);
		__HWNDCss = FindWindow(NULL, "Counter-Strike: Global Offensive");
	}
};

extern CHackProcess fProcess;
There is an error, like when you are comparing a module with a char. A WCHAR* cant be compared with a CHAR*. Like in here.
Code:
if (!strcmp(lpModuleEntry.szModule, LPSTRModuleName))
Oh okay. See I used this for CSS and it worked there so I tried changing some bits like
Code:
while (!FindProcessName("csgo.exe", &__gameProcess)) Sleep(12);
and
Code:
__HWNDCss = FindWindow(NULL, "Counter-Strike: Global Offensive");
I didn't have time to fully debug it so I don't know what wasn't working when I compiled.
You are not "hooking" the game, you are manipulating it's memory.
You also don't need SeDebugPriviledge for PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, which is all you need to read / write memory from / to the game.

Also, you do not describe any errors if you have any.
Quote Originally Posted by WasserEsser View Post
Also, you do not describe any errors if you have any.
The problem is, there are no compile errors, the code just won't work. I'm also really bad at debugging.
I'm not sure if the problem is in here or in my code, but I've double checked my offsets.
Quote Originally Posted by KappaMang View Post
The problem is, there are no compile errors, the code just won't work. I'm also really bad at debugging.
I'm not sure if the problem is in here or in my code, but I've double checked my offsets.
You are still not saying what your problem is.

"The problem is, there are no compile errors, the code just won't work."

Yea, what doesn't work?

The code above gets the base address of those modules, nothing else, you are not saying what it's supposed to do nor what it actually does.

The code above, assuming you are calling RunProcess( ) is only getting the base addresses.
Here's the rest.
 
Long code
Code:
#include <Windows.h>
#include <iostream>
#include "HackProcess.h"

CHackProcess fProcess;
using namespace std;

const DWORD Player_Base = 0xA7D4CC;
const DWORD dw_jumpOffset = 0x100;
const DWORD dw_jump = 0x4F2CE08;

#define FL_ONGROUND 257
#define SPACE_BAR 0x20
#define F5_Key 0x74
#define F10_Key 0x79

bool b_hopEnabled = false;
bool b_true = true;
bool b_false = false; 
bool BunnyHopStatus = false;

struct MyPlayer_t
{
	DWORD ClocalPlayer;
	int m_fFlags;

	void ReadInformation()
	{
		ReadProcessMemory(fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + Player_Base), &ClocalPlayer, sizeof(DWORD), 0);
		ReadProcessMemory(fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + dw_jumpOffset), &m_fFlags, sizeof(int), 0);
	}
}MyPlayer;

void BunnyHop()
{
	if (!b_hopEnabled)
		return;
	BunnyHopStatus = !BunnyHopStatus;
	if (!BunnyHopStatus)
		return;
	
	while (GetAsyncKeyState(SPACE_BAR))
	{
		if (MyPlayer.m_fFlags == 257)
		{
			keybd_event(SPACE_BAR, 0x39, KEYEVENTF_EXTENDEDKEY | 0, 0);
			keybd_event(SPACE_BAR, 0x39, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
		}
		else
			return;
	}
}

void main()
{
	fProcess.RunProcess();
	cout << "Running MultiHack" << endl;

	while (!GetAsyncKeyState(F5_Key))
	{
		MyPlayer.ReadInformation();
		if (GetAsyncKeyState(F10_Key))
		{
			b_hopEnabled = !b_hopEnabled;
			Sleep(250);

			if (b_hopEnabled)
				cout << "Bunnyhop toggled ON" << endl;
			else
				cout << "Bunnyhop toggled OFF" << endl;
		}
		BunnyHop();
	}
}

It runs... it says "Running Multihack"... and I can make it say "Bunnyhop toggled OFF"... but I can't get the bhop to work.

- - - Updated - - -

**EDIT**
I found my... silly mistake. Anyway, the point of this thread was I was wondering if the code was good or optimized, not if it had errors. Also, how should I make it less CPU extensive?
Quote Originally Posted by KappaMang View Post
Here's the rest.
 
Long code
Code:
#include <Windows.h>
#include <iostream>
#include "HackProcess.h"

CHackProcess fProcess;
using namespace std;

const DWORD Player_Base = 0xA7D4CC;
const DWORD dw_jumpOffset = 0x100;
const DWORD dw_jump = 0x4F2CE08;

#define FL_ONGROUND 257
#define SPACE_BAR 0x20
#define F5_Key 0x74
#define F10_Key 0x79

bool b_hopEnabled = false;
bool b_true = true;
bool b_false = false; 
bool BunnyHopStatus = false;

struct MyPlayer_t
{
	DWORD ClocalPlayer;
	int m_fFlags;

	void ReadInformation()
	{
		ReadProcessMemory(fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + Player_Base), &ClocalPlayer, sizeof(DWORD), 0);
		ReadProcessMemory(fProcess.__HandleProcess, (PBYTE*)(fProcess.__dwordClient + dw_jumpOffset), &m_fFlags, sizeof(int), 0);
	}
}MyPlayer;

void BunnyHop()
{
	if (!b_hopEnabled)
		return;
	BunnyHopStatus = !BunnyHopStatus;
	if (!BunnyHopStatus)
		return;
	
	while (GetAsyncKeyState(SPACE_BAR))
	{
		if (MyPlayer.m_fFlags == 257)
		{
			keybd_event(SPACE_BAR, 0x39, KEYEVENTF_EXTENDEDKEY | 0, 0);
			keybd_event(SPACE_BAR, 0x39, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
		}
		else
			return;
	}
}

void main()
{
	fProcess.RunProcess();
	cout << "Running MultiHack" << endl;

	while (!GetAsyncKeyState(F5_Key))
	{
		MyPlayer.ReadInformation();
		if (GetAsyncKeyState(F10_Key))
		{
			b_hopEnabled = !b_hopEnabled;
			Sleep(250);

			if (b_hopEnabled)
				cout << "Bunnyhop toggled ON" << endl;
			else
				cout << "Bunnyhop toggled OFF" << endl;
		}
		BunnyHop();
	}
}

It runs... it says "Running Multihack"... and I can make it say "Bunnyhop toggled OFF"... but I can't get the bhop to work.

- - - Updated - - -

**EDIT**
I found my... silly mistake. Anyway, the point of this thread was I was wondering if the code was good or optimized, not if it had errors. Also, how should I make it less CPU extensive?
The OP found the answer to his original question and try using Sleep(1) to make it less CPU intensive //Solved & Closed
Posts 1–8 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us