need help, how to add to a value

closed account (9i3hURfi)
what im trying to do is, in my game lets say i have 1000 points, im trying to have it so i can add 750 points everytime i press a key, im having a few issues doing so. heres one of my attempts, ive tried everything i can think of within my know how so far.
This one works the first time i open the program when my points ingame are less than 750
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
while (true)
	{
		{ cout << "press F3 to add 750 points\n";

		{int value;

		if (GetAsyncKeyState(VK_F3)){
			DWORD newdatasize = (value) += 750;																				// line 36
			(WriteProcessMemory(hProcess, (LPVOID)0x018EF124, &value, newdatasize, NULL));
			cout << "Points have been added \n";
			cout << " \n";
		}
		}
		}
		system("pause");
		cout << " \n";
	}

and i tried this, this one crashes my game once i press F3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
while (true)
	{
		{ cout << "press F3 to add 750 points\n";

		{int value = 0;

		if (GetAsyncKeyState(VK_F3)){
			DWORD newdatasize = (value) += 750;																				// line 36
			(WriteProcessMemory(hProcess, (LPVOID)0x018EF124, &value, newdatasize, NULL));
			cout << "Points have been added \n";
			cout << " \n";
		}
		}
		}
		system("pause");
		cout << " \n";
Complete stab in the dark here, but what if you changed it to =+ ?
Well, first of all, I would double-check to make sure you're actually writing to the correct address (and that that address doesn't change every time you run the game).

First of all, you don't seem to be getting the previous value of your points.
So in your second code, you'll always end up trying to set your score to 750 0, since you try to write the value of value, not newdatasize.

Second of all, you're not calling WriteProcessMemory correctly.
The fourth parameter is how many bytes of data you're trying to write, not the value you're trying to write.
Plus, the third parameter should probably be &newdatasize, not &value (which, in your second code, will always be 0).

Try
WriteProcessMemory(hProcess, (LPVOID)0x018EF124, &newdatasize, sizeof(newdatasize), NULL);
and see if that does anything.
closed account (9i3hURfi)
im writing to the correct address and its static. i will try that.
closed account (9i3hURfi)
heres what i tried and it did not work properly, same as before. im not sure how to get the previous value of my points and add to them

1
2
3
4
5
6
7
8
9
10
11
12
{ cout << "press F3 to add 750 points\n";

		{int value = 0;
		
		if (GetAsyncKeyState(VK_F3)){
			DWORD newdatasize = (value) =+ 750;
			WriteProcessMemory(hProcess, (LPVOID)0x018EF124, &newdatasize, sizeof(newdatasize), NULL);
			cout << "Points have been added \n";
			cout << " \n";
		}
		}
		}
It's += not =+ as DGdud mentioned. Also it will be reset each time. unless that is not the actual loop you are using but right now. You can try declaring value outside of the loop.
closed account (9i3hURfi)
heres my whole source code, im stuck on this, I dont know how to find the value of points and add 750 to the current number.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <string>

using namespace std;


void Points()
{
	

}


int main()
{
	int value = 0;

	string response;
	cout << "		     gogogokitty199's   Point   Modifier\n";			//title at the top of program
	cout << " \n";
	cout << " \n";

	LPCWSTR Waw = L"Call of Duty®";
	HWND hwnd = FindWindow(0, Waw);
	DWORD process_ID;
	GetWindowThreadProcessId(hwnd, &process_ID);
	HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_ID);

	while (true)
	{
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
		{ cout << "press F3 to add 750 points\n";

		
		if (GetAsyncKeyState(VK_F3)){
			DWORD newdatasize = (value) += 750;
			WriteProcessMemory(hProcess, (LPVOID)0x018EF124, &newdatasize, sizeof(newdatasize), NULL);
			cout << "Points have been added \n";
			cout << " \n";
		}
		}
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0);
		system("pause");
		cout << " \n";
	}
}
I would guess that, if you're going to use WriteProcessMemory to write a new score into memory, you should probably use ReadProcessMemory to get the current value first.

Maybe something like this (untested, I don't know if this actually works):
1
2
3
4
5
6
7
8
int currentScore;
ReadProcessMemory(hProcess, (LPVOID)0x018EF124, &currentScore, sizeof(currentScore), NULL);

// Increase by 750
currentScore += 750;

// Write back to memory
WriteProcessMemory(hProcess, (LPVOID)0x018EF124, &currentScore, sizeof(currentScore), NULL);

closed account (9i3hURfi)
thanks for the help guys. i got one on one help from another guy, everything works now.
Topic archived. No new replies allowed.