Solved Need a help in my first memory hack

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Galhali

Newbie
Full Member
Dec 9, 2012
17
463
1
Hello it is my first memmory hack so sry for all stupid questions or something like that. I have one problem probably i writes bad pointer or something, becouse when i put all offsets in cheat engine all is fine. I read about memory hack at this forum but my english is not so awesome so i can miss something.

Here is code:

C++:
#include <iostream>
#include <Windows.h>
#include <string>
#include <ctime>
#include <TlHelp32.h>
#include <tchar.h>

using namespace std;

DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress);
DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *szModuleName);
void WriteToMemory(HANDLE hProcHandle,DWORD BaseAddress);

string GameName = "Civilization V";
LPCSTR LGameWindow = "Sid Meier's Civilization V (DX11)";
string GameStatus;

bool IsGameAvail;



//DWORD BaseAddress = {0x06F835C8};
DWORD GoldOffsets[] = {0x8, 0xF374};

int main()
{
    HWND hGameWindow = NULL;
    DWORD dwProcID = NULL;
    HANDLE hProcHandle = NULL;

            hGameWindow = FindWindow(NULL, LGameWindow);
            if(hGameWindow)
            {
                GetWindowThreadProcessId( hGameWindow, &dwProcID);
                if(dwProcID !=0)
                {
                    hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE,  dwProcID);
                    if(hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
                    {
                        GameStatus = "Failed to open process for valid handle";
                    }
                    else
                    {
                             system("cls");
                            cout<<"-----------------------------------------------"<<endl;
                            cout<<"            Civilization V memory hack" <<endl;
                            cout<<"-----------------------------------------------"<<endl<<endl;
                            cout<<"             We are ready to hack !!           "<<endl;
                            IsGameAvail = 1;



                    }
                }
                else
                {
                    GameStatus = "Failed to Get process ID";
                }
            }
            else
            {
             GameStatus = "Civilization V NOT FOUND";
            }
    if(IsGameAvail)
    {
        DWORD baseAddress = dwGetModuleBaseAddress(dwProcID, "CvGameCoreDLLFinal Release.dll");
        DWORD staticOffset = 0x2335C8;

        DWORD BaseAddress = baseAddress + staticOffset;

        WriteToMemory(hProcHandle,BaseAddress);
    }

    CloseHandle(hProcHandle);
    CloseHandle(hGameWindow);

    return ERROR_SUCCESS;
}

DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress)
{

 DWORD pointer = BaseAddress;
 DWORD pTemp = 0;

 DWORD pointerAddr;
 for(int c=0; c< PointerLevel; c++)
 {
     if(c==0)
     {
         ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, sizeof(pTemp), NULL);
     }
     pointerAddr = pTemp + Offsets[c];
     ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, sizeof(pTemp), NULL);
 }
 return pointerAddr;
}

void WriteToMemory(HANDLE hProcHandle,DWORD BaseAddress)
{
    DWORD AddresToWrite;

        int moregold = 99900;
        DWORD AddressToWrite = FindDmaAddy(2, hProcHandle, GoldOffsets, BaseAddress);
        WriteProcessMemory(hProcHandle,(void*)AddressToWrite, &moregold, sizeof(moregold), NULL );
}


DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *szModuleName)
{
   DWORD_PTR dwModuleBaseAddress = 0;
   HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE , dwProcessIdentifier);
   if (hSnapshot != INVALID_HANDLE_VALUE)
   {
      MODULEENTRY32 ModuleEntry32;
      ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
      if (Module32First(hSnapshot, &ModuleEntry32))
      {
         do
         {
            if (_tcscmp(ModuleEntry32.szModule, szModuleName) == 0)
            {
               dwModuleBaseAddress = (DWORD_PTR)ModuleEntry32.modBaseAddr;
               break;
            }
         }
         while (Module32Next(hSnapshot, &ModuleEntry32));
      }
      CloseHandle(hSnapshot);
   }
   return dwModuleBaseAddress;
}

and here i have screen from Cheat Engine v. 6.2:
Cheat_Engine.png

Offsets:
8
F374

And final value from Cheat Engine :

"CvGameCoreDLLFinal Release.dll"+2335C8
 

Galhali

Newbie
Full Member
Dec 9, 2012
17
463
1
Hello. Thx all for help i have change a bit my code for less functions and i have found one nice working code at multi pointers with modular last one. About question of order i have checked it and is no matter in what way we write offsets in both cases is work fine.

here is my final code maybe someone will find in this one some answers:

C++:
#include <iostream>
#include <Windows.h>
#include <string>
#include <ctime>
#include <TlHelp32.h>
#include <tchar.h>

using namespace std;


DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *szModuleName);


string GameName = "Civilization V";
LPCSTR LGameWindow = "Sid Meier's Civilization V (DX11)";
string GameStatus;

bool IsGameAvail;


DWORD GoldOffsets[] = {0x8, 0xF374};

int main()
{
    int moregold = 99999900;
    HWND hGameWindow = NULL;
    DWORD dwProcID = NULL;
    HANDLE hProcHandle = NULL;

    hGameWindow = FindWindow(NULL, LGameWindow);
    if(hGameWindow)
    {
        GetWindowThreadProcessId( hGameWindow, &dwProcID);
        if(dwProcID !=0)
        {
            hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE,  dwProcID);
            if(hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
            {
                GameStatus = "Failed to open process for valid handle";
            }
            else
            {
                system("cls");

                cout<<"-----------------------------------------------"<<endl;
                cout<<"            Civilization V memory hack         "<<endl;
                cout<<"-----------------------------------------------"<<endl;
                cout<<"             We are ready to hack !!           "<<endl;
                cout<<"-----------------------------------------------"<<endl;
                IsGameAvail = 1;

            }
        }
        else
        {
            GameStatus = "Failed to Get process ID";
        }
    }
    else
    {
        GameStatus = "Civilization V NOT FOUND";
    }
    if(IsGameAvail)
    {
        DWORD baseAddress = dwGetModuleBaseAddress( dwProcID, _T("CvGameCoreDLLFinal Release.dll") );
        DWORD staticOffset = { 0x2335C8 };
        DWORD GoldOffset[] = { 0xF374, 0x8 };

        DWORD pointer = baseAddress;
        DWORD pTemp =0;
        DWORD pointerAddr;

        for( int c = 0; c < 2; c++ )
        {
            if( c == 0 )
            {
                if( !ReadProcessMemory( hProcHandle, (LPCVOID)(pointer+staticOffset), &pTemp, sizeof(DWORD), NULL ) )
                    cout << "FAILED READ 1" << endl;
            }
            pointerAddr = pTemp + GoldOffset[c];
            if( !ReadProcessMemory( hProcHandle, (LPCVOID)pointerAddr, &pTemp, sizeof(DWORD), NULL ) )
                cout << "FAILED READ 2" << endl;
        }

        if ( !WriteProcessMemory(hProcHandle, (BYTE*)pointerAddr, &moregold, sizeof(moregold), NULL) )
            cout << "FAILED WRITE" << endl;
        else
            cout << "WORKS" << endl;
    }

    CloseHandle(hProcHandle);
    CloseHandle(hGameWindow);

    return ERROR_SUCCESS;
}


DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *szModuleName)
{
    DWORD_PTR dwModuleBaseAddress = 0;
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE , dwProcessIdentifier);
    if (hSnapshot != INVALID_HANDLE_VALUE)
    {
        MODULEENTRY32 ModuleEntry32;
        ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
        if (Module32First(hSnapshot, &ModuleEntry32))
        {
            do
            {
                if (_tcscmp(ModuleEntry32.szModule, szModuleName) == 0)
                {
                    dwModuleBaseAddress = (DWORD_PTR)ModuleEntry32.modBaseAddr;
                    break;
                }
            }
            while (Module32Next(hSnapshot, &ModuleEntry32));
        }
        CloseHandle(hSnapshot);
    }
    return dwModuleBaseAddress;
}
 
Last edited:

velreine

Newbie
Full Member
Aug 27, 2012
36
504
0
When Cheat Engine puts [ & ] brackets around an address it's because that it's the value of that address that holds the next address. In your example:

FE351900 + 8 = FE351908
[1EEC0024+F374] = FE351900

So basicly:

Your first "static address" is 1EEC0024, then you add your first offset "F374" to that. Which then gives you the address: 1EECF398 which actually holds the address FE351900. Then you just have to add your last offset which was 8.

But an easy fix would be to reverse the order of offsets in your call to FindDmaAddy

Change this line of code:
DWORD GoldOffsets[] = {0x8, 0xF374};
To this:
DWORD GoldOffsets[] = {0xF374, 0x8};
 

Galhali

Newbie
Full Member
Dec 9, 2012
17
463
1
Hello. I have done what u suggest but it doasn't help. I have made some check for this and i see the AddressToWrite have bad value but all time dont know where is mistake. maybe something is wrong with function what change modular base adress. I have 64 bit systemand maybe this function have some problems tu return right value.
 
Last edited:

Chuck E

Coder
Dank Tier Donator
Nobleman
Jan 2, 2013
122
588
1
Okay, I'm a noob at this moment, but looking at your code you have set the BaseAddress to be the start of the program itself. That is not right :(

BaseAddress should be the static address (06F835C8). I assume that 06F835C8 is the final address in your trace through the pointers and is green in colour (green in CE)?

That's why it works in CE, but not in your program.

I don't think it matters which order you have the Offsets in, as they are added to the static address in order to locate the current address of the value you wish to hack. (anyone, feel free to correct me :) )

Also, be sure that the address does not change every time you start a new game. That one got me the first time I tried this, lol
 
Last edited:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods