Solved FindWindowA <unable to read memory>

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Teuvin

now I am become Death
Dank Tier VIP
Trump Tier Donator
Dec 8, 2016
403
10,388
65
Just trying to make a bunnyhop out of fleep's tutorials but when I arrived at running the code nothing happened I ran the debugger and found out FindWindowA is giving a error <Unable to read Memory> and I have no ideia how to solve it as it has never happened to me before any help helps.
C++:
// ConsoleApplication26.cpp : Defines the entry point for the console
// application.
//
#include <Windows.h>
#include <iostream>
#include <string>
#include <vector>
#include <tlhelp32.h>
#include <tchar.h>

const DWORD player_Base = 0x4C6708; //004E3934 4C6708
const DWORD m_dwForceJump = 0x4F3B3C;
const DWORD m_jumpOff = 0x340;  // 348
#define onground 257
bool b_true = true;
bool b_false = false;
bool Bunnyhopstatus = false;
DWORD c_baseadress = 0;

DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcID, TCHAR *szModuleName)
{
	DWORD_PTR dwModuleBaseAddress = 0;
	HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, dwProcID);
	if (hSnapshot != INVALID_HANDLE_VALUE)
	{
		MODULEENTRY32 ModuleEntry32;
		ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
		if (Module32First(hSnapshot, &ModuleEntry32))
		{
			do
			{
				if (_tcsicmp(ModuleEntry32.szModule, szModuleName) == 0)
				{
					dwModuleBaseAddress = (DWORD_PTR)ModuleEntry32.modBaseAddr;
					break;
				}
			} while (Module32Next(hSnapshot, &ModuleEntry32));
		}
		CloseHandle(hSnapshot);
	}
	return dwModuleBaseAddress;
}
	
struct MyPlayer_t {
	UINT32 ClocalPlayer;
	int m_fFlags;
	void ReadInformation() {
		HWND hwnd = FindWindowA(NULL, "Counter-Strike Source");
		DWORD procid;
		GetWindowThreadProcessId(hwnd, &procid);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, NULL, procid);
		ReadProcessMemory(handle, (PBYTE*)(c_baseadress + player_Base), &ClocalPlayer,
			sizeof(ClocalPlayer), 0);
		ReadProcessMemory(handle, (PBYTE*)(ClocalPlayer + m_jumpOff), &m_fFlags,
			sizeof(int), 0);
	}
} MyPlayer;
void bunnyhop() {
	if (GetAsyncKeyState(0x20))
	{
		Bunnyhopstatus = !Bunnyhopstatus;
		Sleep(250);
	}
	if (!Bunnyhopstatus) {
		return;
	}
	if (MyPlayer.m_fFlags == 257) {
		HWND hwnd = FindWindowA(NULL, "Counter-Strike Source");
		DWORD procid;
		GetWindowThreadProcessId(hwnd, &procid);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, NULL, procid);
		WriteProcessMemory(handle, (PBYTE*)(c_baseadress +m_dwForceJump),&b_true,sizeof(b_true),0);
	}
	else if(MyPlayer.m_fFlags =! 257) {
		HWND hwnd = FindWindowA(NULL, "Counter-Strike Source");
		DWORD procid;
		GetWindowThreadProcessId(hwnd, &procid);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, NULL, procid);
		WriteProcessMemory(handle, (PBYTE*)(c_baseadress + m_dwForceJump), &b_false, sizeof(b_true), 0);
	}
}






int main() {
	HWND hwnd = FindWindowA(NULL, "Counter-Strike Source");
		DWORD procid;
		GetWindowThreadProcessId(hwnd, &procid);
		c_baseadress = dwGetModuleBaseAddress(procid, _T("client.dll"));
		std::cout << "CSGO found" << std::endl;
		std::cout << "Running bunnyhop" << std::endl;
		while (!GetAsyncKeyState(0x75))
		{
			MyPlayer.ReadInformation();
			bunnyhop();
		}
		return 0;
}
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,153
78,998
2,396
I just compiled and executed your code and it worked fine for me. Please provide more information on your proiblem
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,746
40,528
316
Another important thing:
On each MyPlayer.ReadInformation call you create a new handle to the process. That really affects the performance and since you aren't closing the handles you can technically get a bluescreen when too many handles have been created.
Either use CloseHandle in ReadInformation (which still would be extremely inefficient) or open the process before starting the loop and close handle after exiting the loop.
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,153
78,998
2,396
FindWindowA(NULL, "Counter-Strike Source");

But you're using it on CS:GO, see the problem?
 

Teuvin

now I am become Death
Dank Tier VIP
Trump Tier Donator
Dec 8, 2016
403
10,388
65
Rake;46914 said:
FindWindowA(NULL, "Counter-Strike Source");

But you're using it on CS:GO, see the problem?
I just forgot to change from csgo to CSS I was originally going to make it for csgo but then I decided CSS would be the best.
 
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