Solved Issues with my first dll hack

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

TooManyColor

Newbie
Full Member
Oct 5, 2015
17
108
0
Hey guys, I just started making my own dll and I used the same code as the .exe trainer I've made, but it is not working and I can't find why... ;s

C++:
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <float.h>
using namespace std;

DWORD WINAPI LoopFunction(LPVOID lpParam)
{
	DWORD playerBase = 0x50F4F4;
	DWORD health = playerBase + 0xF8;
	DWORD rifleAmmo = playerBase + 0x150;
	DWORD pistolAmmo = playerBase + 0x13C;

	int healthAmount = 1000;
	int rifleAmmoAmount = 100;
	int pistolAmmoAmount = 100;

	bool healthState = true;
	bool rifleState = true;
	bool pistolState = true;

	HANDLE ac = GetCurrentProcess();

	while (1){
		if (healthState == true) {
			WriteProcessMemory(ac, (LPVOID*)(health), &healthAmount, sizeof(healthAmount), 0);
		}

		if (rifleState == true) {
			WriteProcessMemory(ac, (void*)(rifleAmmo), &rifleAmmoAmount, sizeof(rifleAmmoAmount), 0);
		}

		if (pistolState == true) {
			WriteProcessMemory(ac, (void*)(pistolAmmo), &pistolAmmoAmount, sizeof(pistolAmmoAmount), 0);
		}

		if (GetAsyncKeyState(VK_F1)&0x80000) {
			if (healthState == true) {
				healthState = false;
			}
			else {
				healthState = true;
			}
		}

		if (GetAsyncKeyState(VK_F2)&0x80000) {
			if (rifleState == true) {
				rifleState = false;
			}
			else {
				rifleState = true;
			}
		}

		if (GetAsyncKeyState(VK_F3)&0x80000) {
			if (pistolState == true) {
				pistolState = false;
			}
			else {
				pistolState = true;
			}
		}
		Sleep(100);
	}
	return 0;
}



BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwAttached, LPVOID lpvReserved)
{
	if (dwAttached == DLL_PROCESS_ATTACH) {
		CreateThread(NULL, 0, &LoopFunction, NULL, 0, NULL);
	}
	return 1;
}
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,745
40,528
316
C++:
#include <Windows.h>

DWORD __stdcall Thread(void* pParam)
{
	DWORD dwBase = 0x50F4F4;
	DWORD ofHealth		= 0xF8;
	DWORD ofPistolAmmo	= 0x13C;
	DWORD ofRifleAmmo	= 0x150;

	bool bHealth		= true;
	bool bPistolAmmo	= true;
	bool bRifleAmmo		= true;

	while (true)
	{
		if (GetAsyncKeyState(VK_F1) & 1)
			bHealth = !bHealth;

		if (GetAsyncKeyState(VK_F2) & 1)
			bPistolAmmo = !bPistolAmmo;
		
		if (GetAsyncKeyState(VK_F3) & 1)
			bRifleAmmo = !bRifleAmmo;

		DWORD dwBuffer = *(DWORD*)dwBase;
		if (dwBuffer)
		{
			if(bHealth)
				*(DWORD*)(dwBuffer + ofHealth) = 1337;

			if(bPistolAmmo)
				*(DWORD*)(dwBuffer + ofPistolAmmo) = 1337;

			if (bRifleAmmo)
				*(DWORD*)(dwBuffer + ofRifleAmmo) = 1337;
		}
	}
}

BOOL __stdcall DllMain(HINSTANCE hDll, DWORD dwReason, void* pReserved)
{
	if (dwReason == DLL_PROCESS_ATTACH)
	{
		CreateThread(nullptr, 0, Thread, nullptr, 0, nullptr);
	}
	return TRUE;
}
 

mambda

headass
Escobar Tier VIP
Trump Tier Donator
Jun 25, 2014
2,294
37,938
269
1. Dont use read/write process memory in an internal.

2. Im pretty sure that playerbase should be ac_client.exe+Offset, then everything else would work fine

3. dont use namespace std

4. why so many useless includes?
 

TooManyColor

Newbie
Full Member
Oct 5, 2015
17
108
0
What should I use to write/read memory process ?
I use a default header to my code, that's why there's a lot of useless includes.
 

TooManyColor

Newbie
Full Member
Oct 5, 2015
17
108
0
Worked perfectly! Thx man, and double thx for showing me that i'm a retarted using 'if' to change the bool state :)
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,745
40,528
316
Worked perfectly! Thx man, and double thx for showing me that i'm a retarted using 'if' to change the bool state :)
Np, the important part is the pointer stuff. You first have to read the base address and then add the offset (since those pointers all only have one offset) to get the "full" address.
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods