Domanda

I'm trying to create my own functions for ReadProcessMemory and WriteProcessMemory in VisualC++ so I don't have to keep inputting all the info for every time I create a new function call. This project is Windows Form. Here's the problem

void Read(DWORD Add, int Value);

private: System::Void btnP1Money_Click_1(System::Object^  sender, System::EventArgs^e) 
{   
int BigMoney = 100000;
int GetMoneyValue;
DWORD MonAddr = 0x180A6C8;

Read(MonAddr, GetMoneyValue);
}


void Read(DWORD Add, int Value)
{
HWND window = FindWindow(0, _T("Process Window Name"));
DWORD pID = NULL;
DWORD base = dwGetModuleBaseAddress(pID, _T("Game.exe"));
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
GetWindowThreadProcessId(window, &pID);

ReadProcessMemory(handle, (LPCVOID)(base+Add), &Value, 4, NULL);
}

The value in game is 500, yet the value returned from Read() is 0. Not sure what I'm doing wrong. I just don't want to have to define everything in my Read() function everytime on each button click and checkbox tick ect.

Thanks

È stato utile?

Soluzione

You should modify the Read header to

void Read(DWORD Add, int& Value)

I've written small example which works. Make sure that you check the content of the variable, not it's address

void Read(int& Value)
{
    Value++;
}

int main(array<System::String ^> ^args)
{
    int GetMoneyValue = 5;
    Read(GetMoneyValue);

    Console::WriteLine(GetMoneyValue);
    //6;
    return 0;
}

Altri suggerimenti

You need to pass by reference, otherwise the function gets its own copy of the int:

void Read(DWORD Add, int& Value);

Alternatively, you could return the value:

int Read(DWORD Add, int Value)
{
  ....
  return Value;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top