PostWhat is wrong with my code???

Posts 1–2 of 2 · Page 1 of 1
What is wrong with my code???
This is suppose to give ammo when the user reaches less than 3 bullets left, both of my addresses work in cheat engine... so what's wrong... is it just a simple error???

Code:
#include <Windows.h>
#include <iostream>

class LocalPlayer
{
public:
	DWORD                      Pid;
	DWORD       PAmmo = 0x02370FDC;
	DWORD       SAmmo = 0x02370FD8;
	int                      PData;
	int                      SData;
	int                     NPData;
	int                     NSData;
	void ReadP()
	{
		HWND HWnd = FindWindowA(0, ("Call of Duty®: Black Ops II"));
		GetWindowThreadProcessId(HWnd, &Pid);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
		ReadProcessMemory(handle, (LPCVOID)PAmmo, &PData, sizeof(PData), 0);
	}
	void WriteP()
	{
		NPData = PData += 1000;
		HWND HWnd = FindWindowA(0, ("Call of Duty®: Black Ops II"));
		GetWindowThreadProcessId(HWnd, &Pid);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
		WriteProcessMemory(handle, (LPVOID)PAmmo, &NPData, sizeof(NPData), 0);
	}
	void ReadS()
	{
		HWND HWnd = FindWindowA(0, ("Call of Duty®: Black Ops II"));
		GetWindowThreadProcessId(HWnd, &Pid);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
		ReadProcessMemory(handle, (LPCVOID)SAmmo, &SData, sizeof(SData), 0);
	}
	void WriteS()
	{
		NSData = SData += 1000;
		HWND HWnd = FindWindowA(0, ("Call of Duty®: Black Ops II"));
		GetWindowThreadProcessId(HWnd, &Pid);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
		WriteProcessMemory(handle, (LPVOID)SAmmo, &NSData, sizeof(NSData), 0);
	}
}; LocalPlayer localPlayer;
int main()
{
	while (true)
	{
		Sleep(1);
		localPlayer.ReadP();
		localPlayer.ReadS();
		if (localPlayer.PData < 3)
		{
			localPlayer.WriteP();
		} else 
		if (localPlayer.SData < 3)
		{
			localPlayer.WriteS();
		}
	}
	return 0;
}
I'm using Windows 10 if that matters.
Quote Originally Posted by Remote Access Memory View Post
This is suppose to give ammo when the user reaches less than 3 bullets left, both of my addresses work in cheat engine... so what's wrong... is it just a simple error???

Code:
#include <Windows.h>
#include <iostream>

class LocalPlayer
{
public:
	DWORD                      Pid;
	DWORD       PAmmo = 0x02370FDC;
	DWORD       SAmmo = 0x02370FD8;
	int                      PData;
	int                      SData;
	int                     NPData;
	int                     NSData;
	void ReadP()
	{
		HWND HWnd = FindWindowA(0, ("Call of Duty®: Black Ops II"));
		GetWindowThreadProcessId(HWnd, &Pid);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
		ReadProcessMemory(handle, (LPCVOID)PAmmo, &PData, sizeof(PData), 0);
	}
	void WriteP()
	{
		NPData = PData += 1000;
		HWND HWnd = FindWindowA(0, ("Call of Duty®: Black Ops II"));
		GetWindowThreadProcessId(HWnd, &Pid);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
		WriteProcessMemory(handle, (LPVOID)PAmmo, &NPData, sizeof(NPData), 0);
	}
	void ReadS()
	{
		HWND HWnd = FindWindowA(0, ("Call of Duty®: Black Ops II"));
		GetWindowThreadProcessId(HWnd, &Pid);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
		ReadProcessMemory(handle, (LPCVOID)SAmmo, &SData, sizeof(SData), 0);
	}
	void WriteS()
	{
		NSData = SData += 1000;
		HWND HWnd = FindWindowA(0, ("Call of Duty®: Black Ops II"));
		GetWindowThreadProcessId(HWnd, &Pid);
		HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Pid);
		WriteProcessMemory(handle, (LPVOID)SAmmo, &NSData, sizeof(NSData), 0);
	}
}; LocalPlayer localPlayer;
int main()
{
	while (true)
	{
		Sleep(1);
		localPlayer.ReadP();
		localPlayer.ReadS();
		if (localPlayer.PData < 3)
		{
			localPlayer.WriteP();
		} else 
		if (localPlayer.SData < 3)
		{
			localPlayer.WriteS();
		}
	}
	return 0;
}
I'm using Windows 10 if that matters.
You don't have to declare HWnd, GetWindowThreadProcessId, and handle each time. lmao. Just declare it once at the top of the class.
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?