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";
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.
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.
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, ¤tScore, sizeof(currentScore), NULL);
// Increase by 750
currentScore += 750;
// Write back to memory
WriteProcessMemory(hProcess, (LPVOID)0x018EF124, ¤tScore, sizeof(currentScore), NULL);