I need help with a certain bit of code. I was making my own memory class and in theory it seemed to work. It got the adress of the client DLL module just fine. But when I tried to use a read function written as this:
```
template <class ret>
ret Read(DWORD offSet){
ret trueVal;
ReadProcessMemory(hProcess, (LPVOID)offSet, &trueVal, sizeof(ret), NULL); //reads the adress and stores the value in the 2nd argument passed in
return trueVal;
}
```
I tried to read the client dll base + the local player offset and output it to the screen like this:
```
DWORD localPlayer = 0;
DWORD readLocalPlayer = cDLL + dwLocalPlayer;
localPlayer = mem.Read<DWORD>(cDLL + dwLocalPlayer);
cout << "local player is " << localPlayer << endl;
```
When I do this, localPlayer just has a value of 3435973836 and so does anything else I try to read. I googled what the value means and it says that it means variable not initialized. But I don't see a problem in the code? Can someone help me.
This is how I get process ID:
```
void Memory::ProcID(){
HWND hwnd = FindWindowA(NULL, "Counter-Strike: Global Offensive"); //finding the csgo window
GetWindowThreadProcessId(hwnd, &pID); //Getting the process ID from the window and setting the value to the adress of the private variable pID
if (hwnd == NULL){ //if hwnd is null that means the window wasnt found
cout << "Error finding window" << endl;
}
}
```
This is how i make a handle:
```
void Memory::Handle(DWORD proID){ //creating the handle
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, proID); //making a handle that opens the process with read acess rights and with the process ID we got from pID
if (hProcess == NULL){ //just in case
cout << "Error getting handle " << endl;
}
}
```
and this is how I got my module
```
DWORD Memory::module(DWORD procID, TCHAR* modName ){
HANDLE modHandle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, procID); //creating a handle which takes a snapshot of all running modules inside of our process
//the theory here is that a module name is passed in and we iterate through all modules till we find our desired one. When we find it then we return it as a DWORD pointer because we are looking for the adress
//since we are dealing with offsets
MODULEENTRY32 moduleEntry32;
moduleEntry32.dwSize = sizeof(moduleEntry32);
if (modHandle == INVALID_HANDLE_VALUE){ //if for some reason the handle couldnt be created
std::cout << "Invalid Handle Value";//we display an error
exit(-1);// and exit
}
if (!Module32First(modHandle, &moduleEntry32)){ //module32first is true if first entry has been copied to the memory so if it is false then there has been a problem
cout << "Module32first is false" << endl;
return NULL;
}
do{
if (strcmp(moduleEntry32.szModule, modName)==0){ //strcmp is used to compare two *chars. //the .szModule simply gives the name of the module
//if the moduleEntrey32 is not the module we are looking for then the strcmp returns false and we go in this loop
CloseHandle(modHandle);
return (DWORD)moduleEntry32.modBaseAddr;
}
} while (Module32Next(modHandle, &moduleEntry32));
}
```
I've been trying to figure out what I'm doing wrong for hours please someone help
