Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How can I use this in C++ ?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
B14CKS1D3
Cheater
Reputation: 0

Joined: 30 Jul 2014
Posts: 26

PostPosted: Sat Aug 01, 2015 7:49 pm    Post subject: How can I use this in C++ ? Reply with quote

I got a cheat engine offset that looks like this:
"Process.exe"+0296E678 + offset

I tried getting the address doing "int address = (DWORD)GetModuleHandle(0) + Pointer + offset;" and it dosen't return the right address(Comparing the result to the address in CE)

How can I get the right address?
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Aug 01, 2015 9:27 pm    Post subject: Reply with quote

You want to use ReadProcessMemory to get the pointer from the address: "Process.exe" + 0296E678
You then want to add your offset to the returned value and utilize it as the variable you're expecting.
Back to top
View user's profile Send private message
B14CKS1D3
Cheater
Reputation: 0

Joined: 30 Jul 2014
Posts: 26

PostPosted: Sat Aug 01, 2015 9:33 pm    Post subject: Reply with quote

Would something like this work?

Code:
int Address = *(int*)CEPointerAddress + CEPointerAddress + offset;
*(int*)Address = value;
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Aug 01, 2015 9:33 pm    Post subject: Reply with quote

Just for reference, GetModuleHandle is only useful if you are injected into the target process.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
B14CKS1D3
Cheater
Reputation: 0

Joined: 30 Jul 2014
Posts: 26

PostPosted: Sat Aug 01, 2015 9:34 pm    Post subject: Reply with quote

I got a dll injected into the process
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Aug 01, 2015 9:39 pm    Post subject: Reply with quote

davidp027 wrote:
I got a dll injected into the process


Alright, then if you are injected then you will need to do casting to read the addresses and such like this:

Code:

int addr = *(DWORD*)((DWORD)::GetModuleHandle(0) + 0x12345);


This will read the pointer you are attempting to get. Then you can do the offset like:
Code:
int value = *(DWORD*)(addr + offset);


All depending on how you need to handle the value.

DWORD = unsigned long = 4 bytes

So you may need to use a different cast on the read/write of the value.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
B14CKS1D3
Cheater
Reputation: 0

Joined: 30 Jul 2014
Posts: 26

PostPosted: Sat Aug 01, 2015 9:49 pm    Post subject: Reply with quote

I tried this, but it crashes the program:

Here's my function code:
Code:

void SetIndex(int index, int value){
                int offset = index + 25;
      int addr = *(DWORD*)((DWORD)::GetModuleHandle(0) + 0x12345);
      *(DWORD*)(addr + offset);
                *(DWORD*)pointer = value;
}
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Aug 01, 2015 10:02 pm    Post subject: Reply with quote

You should have used the correct offset 0x0296E678, not the example 0x12345.
And I'm not sure about that index + 25 code you've got there...
Back to top
View user's profile Send private message
B14CKS1D3
Cheater
Reputation: 0

Joined: 30 Jul 2014
Posts: 26

PostPosted: Sat Aug 01, 2015 10:09 pm    Post subject: Reply with quote

index + 25 was just a demo,
And I used the correct offset, just changed it while writing it here.
The offset for is (idOfSomething * 8 ) + 8, I know it's right cause I got the pointer working it cheat engine
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Aug 01, 2015 11:11 pm    Post subject: Reply with quote

Have you tossed in some debugging to find out what values your code is receiving?
Is this a 64-bit game and you shouldn't be using an INT?
Kind of hard to help you debug your code if you don't show what you're actually coding. Smile
Back to top
View user's profile Send private message
B14CKS1D3
Cheater
Reputation: 0

Joined: 30 Jul 2014
Posts: 26

PostPosted: Sat Aug 01, 2015 11:22 pm    Post subject: Reply with quote

Tried posting it but for some reason forums said I can't post links xD. Yes, the game is 64 bits. What should I use ? __int64 ?

This
Code:
DWORD  Pointer = ((DWORD64)GetModuleHandle(0) + 0x02A701E8) + offset;


returns 0x141d398f0 and in cheat engine, the pointer points to 0x49389708




------------------------
Thanks to both of you, got it fixed. I didn't think about 64 bit...
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Aug 02, 2015 7:05 am    Post subject: Reply with quote

Now don't quote me on this one, but I think it should be:
Code:
int offset = index * 8 + 8;
long addr = *(QWORD*)((QWORD)::GetModuleHandle(0) + 0x0296E678);
*(DWORD*)(addr + offset) = value;

Oh, just noticed your signature looking edit that you got it working.
You want to post the corrected code in case someone stumbles upon this thread?
Back to top
View user's profile Send private message
B14CKS1D3
Cheater
Reputation: 0

Joined: 30 Jul 2014
Posts: 26

PostPosted: Sun Aug 02, 2015 8:49 pm    Post subject: Reply with quote

This is working for me:

Code:

DWORD64 GetModuleBase(HANDLE hProc, std::string &sModuleName)
{
   HMODULE *hModules;
   hModules = 0;
   char szBuf[50];
   DWORD cModules = 0;
   DWORD64 dwBase = 0;
   EnumProcessModules(hProc, hModules, 0, &cModules);
   hModules = new HMODULE[cModules / sizeof(HMODULE)];
   if (EnumProcessModules(hProc, hModules, cModules / sizeof(HMODULE), &cModules)) {
      for (int i = 0; i < cModules / sizeof(HMODULE); i++) {
         if (GetModuleBaseName(hProc, hModules[i], szBuf, sizeof(szBuf))) {
            if (sModuleName.compare(szBuf) == 0) {
               dwBase = (DWORD64)hModules[i];
               break;
            }
         }
      }
   }
   delete[] hModules;
   return dwBase;
}

   void SetIndex(INT index, INT value)
   {
      INT offset = (index * 8) + 8;
      INT Pointer = 0x12345;//Put pointer here
      INT addr = *(DWORD64*)(GetModuleBase(GetCurrentProcess(), string("Process.exe")) + Pointer) + offset;
      *(DWORD64*)addr = value;
   }


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites