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 


Need Help: How To Edit Double Values With C++ With Pointers

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

Joined: 16 Aug 2022
Posts: 17

PostPosted: Wed Aug 31, 2022 6:07 am    Post subject: Need Help: How To Edit Double Values With C++ With Pointers Reply with quote

Hi, I have found pointers for values I want to change and all those are double values. For some specific reasons changing these values with Cheatengine script is not an option, so I want to change them with C++ in Visual Studio. I have found a lot of guides how to change int values like this, but I have not found a single guide for changing double values. Could you please write C++ script which changes a double value by using pointers with offsets?

So far this is a code I came up with in visual studio, but it doesn't work for double values:

Code:

#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>


DWORD GetPID(const char* ProcessName) {
   PROCESSENTRY32 processInfo;
   processInfo.dwSize = sizeof(processInfo);


   HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
   if (processesSnapshot == INVALID_HANDLE_VALUE)
      return 0;

   Process32First(processesSnapshot, &processInfo);
   if (!strcmp(processInfo.szExeFile, ProcessName))
   {
      CloseHandle(processesSnapshot);
   }

   while (Process32Next(processesSnapshot, &processInfo))
   {
      if (!strcmp(processInfo.szExeFile, ProcessName))
      {
         CloseHandle(processesSnapshot);
         return processInfo.th32ProcessID;
      }
   }
   CloseHandle(processesSnapshot);
   return processInfo.th32ProcessID;
}

DWORD GetModule(const char* moduleName, unsigned long ProcessID)
{
   DWORD modEntry = { 0 };

   HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, ProcessID);

   if (hSnapshot != INVALID_HANDLE_VALUE)
   {
      DWORD curr = { 0 };

      curr.dwSize = sizeof(MODULEENTRY32);
      if (Module32First(hSnapshot, &curr))
      {
         do
         {
            if (!strcmp(curr.szModule, moduleName))
            {
               modEntry = curr;
               break;
            }
         } while (Module32Next(hSnapshot, &curr));
      }
      CloseHandle(hSnapshot);
   }
   return modEntry;
}

int main()
{


   DWORD pid = getPID("InstanceServerG.exe");
   DWORD base = getModule("InstanceServerG.exe", pid);
   unsigned long long pid = GetPID("InstanceServerG.exe");
   MODULEENTRY32 module = GetModule("InstanceServerG.exe", pid);
   HANDLE phandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);

   unsigned double result;
   //These are modified values (new):
   double ChanneledBuildupAOE = 112.5; //channeled buildup AOE value
    double ChanneledBuildupRange = 2000; //channeled BuildupRange value
   int SiphonCountProduction = 2; //Siphon Production Counter


   //ChanneledBuildupAOE changer:
   ReadProcessMemory(phandle, (void*)((unsigned long long)module.modBaseAddr + 0x01041DD0), &result, sizeof(result), 0);
   ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0xA4), &result, sizeof(result), 0);
   ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0x4DC), &result, sizeof(result), 0);
   ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0x24), &result, sizeof(result), 0);
   ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0x4), &result, sizeof(result), 0);
   ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0x18), &result, sizeof(result), 0);
   ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0x4), &result, sizeof(result), 0);
   WriteProcessMemory(phandle, (void*)((unsigned long long)result + 0xF0), &ChanneledBuildupAOE, sizeof(ChanneledBuildupAOE), 0);



   //ChanneledBuildupRange changer:
   ReadProcessMemory(phandle, (void*)((unsigned long long)module.modBaseAddr + 0x01041DD0), &result, sizeof(result), 0);
   ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0xA4), &result, sizeof(result), 0);
   ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0xB1C), &result, sizeof(result), 0);
   ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0x24), &result, sizeof(result), 0);
   ReadProcessMemory(phandle, (void*)((unsigned long long)result + 0x4), &result, sizeof(result), 0);
   WriteProcessMemory(phandle, (void*)((unsigned long long)result + 0xC80), &ChanneledBuildupRange, sizeof(ChanneledBuildupRange), 0);
   std::cout << "Grey Goo has been Modded successfully";

   system("pause");
}
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 460

Joined: 09 May 2003
Posts: 25368
Location: The netherlands

PostPosted: Wed Aug 31, 2022 6:19 am    Post subject: Reply with quote

result must be the pointersize type the target uses, not double
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
VORP
Newbie cheater
Reputation: 0

Joined: 16 Aug 2022
Posts: 17

PostPosted: Wed Aug 31, 2022 6:29 am    Post subject: Reply with quote

Dark Byte wrote:
result must be the pointersize type the target uses, not double


How do I declare that?

pointersize result; ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 460

Joined: 09 May 2003
Posts: 25368
Location: The netherlands

PostPosted: Wed Aug 31, 2022 8:38 am    Post subject: Reply with quote

is the target process 32 bit? Then use DWORD result
Is the target process 64 bit? Then use QWORD result

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
VORP
Newbie cheater
Reputation: 0

Joined: 16 Aug 2022
Posts: 17

PostPosted: Wed Aug 31, 2022 10:39 am    Post subject: Reply with quote

Dark Byte wrote:
is the target process 32 bit? Then use DWORD result
Is the target process 64 bit? Then use QWORD result


Target process is 32bit.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 200

Joined: 25 Jan 2006
Posts: 8526
Location: 127.0.0.1

PostPosted: Wed Aug 31, 2022 2:02 pm    Post subject: Reply with quote

If your target is 32bit then your pointer type is most likely not 'unsigned long long' (which is 8 bytes).

Also, since you aren't doing any error checking, it is a high chance you are going to fail to even get a handle by using 'PROCESS_ALL_ACCESS' if you are not running as administrator. You should avoid just blindly requesting full access like that and instead specifically mark which things you want when opening a handle.

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

Joined: 16 Aug 2022
Posts: 17

PostPosted: Thu Sep 01, 2022 7:58 am    Post subject: Reply with quote

Yes, it has worked! Thanks a lot!
Back to top
View user's profile Send private message
VORP
Newbie cheater
Reputation: 0

Joined: 16 Aug 2022
Posts: 17

PostPosted: Fri Sep 09, 2022 5:54 am    Post subject: Reply with quote

I have a new question: can I somehow print out changed value into console window? I tried to print out result, but it just always says 0.
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