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 


C++ ReadProcessMemory

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
DeadlySoul
Newbie cheater
Reputation: 0

Joined: 16 Sep 2012
Posts: 11

PostPosted: Sun Sep 16, 2012 9:03 am    Post subject: C++ ReadProcessMemory Reply with quote

Hey guys, I know this has been posted before but i'm having problems Embarassed

I'm trying to read the "Cards Left:" from FreeCell and output it in the console but its not showing the right value - it outputs 704

I found another topic where someone was doing the same thing but with the score from Solitaire: (can't post urls yet - remove spaces)
Quote:
http ://forum .cheatengine. org/viewtopic.php?t=545149&sid=98cd1ab276dcccd51e20b392f1bd293d

he even posted his end-result (kudos to him) so I could just copy it and replace the name and offsets (since I don't know much about c++)

I did a bunch of pointer scans and ended up with a pointer-count of 8787. it wont drop anymore and if it does then only by 1 every 2-3 scans.

I also searched for the address manually but the result doesn't match with the pointer-scan and I'm sure I did it the right way, so I'm kinda confused.

On the left is the pointerscan result and on the right the manually result
Quote:
http: //i1108 .photobucket. com/albums/h419/Cyb2k10/CEResults.png


The values keep changing after restarting the game.

Anyway here's my c++ code that I use:
Code:
#include "stdafx.h"
#include <windows.h>
#include <TlHelp32.h>
#include <iostream>
#include <tchar.h>

using namespace std;

DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *szModuleName)
{
   DWORD_PTR dwModuleBaseAddress = 0;
   HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, 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;
}

int main()
{
   HWND window = FindWindow(0, _T("FreeCell"));
   if( window == 0 ){
      printf("Window not found!\n");
      char f;
      cin >> f;
      return 0;
   }

   DWORD pID = 0;
   GetWindowThreadProcessId(window, &pID);
   
   DWORD baseAddr = dwGetModuleBaseAddress(pID, _T("FreeCell.exe"));
   DWORD staticOffset = 0xB10D8;

   
   
   HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
   
   
   DWORD value;
   DWORD numBytesRead;

while(1) {
   ReadProcessMemory(handle, (LPCVOID)(baseAddr+staticOffset), &value, sizeof(DWORD), &numBytesRead);
   value+=0x8;
   ReadProcessMemory(handle, (LPCVOID)value, &value, sizeof(DWORD), &numBytesRead);
   value+=0x78;
   ReadProcessMemory(handle, (LPCVOID)value, &value, sizeof(DWORD), &numBytesRead);
   value+=0xd8;
   ReadProcessMemory(handle, (LPCVOID)value, &value, sizeof(DWORD), &numBytesRead);
   value+=0x8;
   ReadProcessMemory(handle, (LPCVOID)value, &value, sizeof(DWORD), &numBytesRead);
   value+=0x160;
   ReadProcessMemory(handle, (LPCVOID)value, &value, sizeof(DWORD), &numBytesRead);
   
   cout << "Cards Left: " << value;
            cout.flush();
            Sleep(200);
            cout << '\r';

            Sleep(100);
}
   CloseHandle(handle);
   char f;
   cin >> f;
   return 0;
}


Appreciate it if someone can help me out.
Thx

EDIT 1:~~~~~~~~~~
Finally figured out what the problem was! Had to go to BUILD>Configuration Manager> And add x64 to the list Laughing But now I have a different problem..

Sometimes when it counts down a big batch - i.e. game -3 where you just have to move 1 card to win the game, it starts out fine but then at the end it jumps up a few times to a bigger number for a second and then always stops at 02.

Is there a way to output the number 1:1 without the jumping and stopping at 02? I'd like it to stop at 0.

EDIT 2:~~~~~~~~~~
Figured out that the problem was..
Code:
cout << "Cards Left: " << value;
            cout.flush();
            Sleep(200);
            cout << '\r';


..changed it to..
Code:
 if ( value < 10){
  cout << "Cards Left: " << value << "  ";
  cout << "\r" ;
  Sleep(100);
   }else{

  cout << "Cards Left: " << value;
  cout << '\r';
  Sleep(100);
  }


..and now its working but was wondering if there is another (easier) way to clear a line/screen other than using \r \b ?

Would appreciate if someone could show an example
Thx
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 programming 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