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 


Calling a game function from Cheat Engine

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
noobidydoobedy
How do I cheat?
Reputation: 0

Joined: 05 Aug 2023
Posts: 2

PostPosted: Sat Aug 05, 2023 8:38 am    Post subject: Calling a game function from Cheat Engine Reply with quote

There are many posts with this topic, but I didn't really understand much of the responses, and I think my question is a little bit different.

I made a small C++ program so I can show you in a more simple way what I'm trying to do with a game:

[code]#include <iostream>
#include <windows.h>

using namespace std;

int val;

void func() {
val++;
cout << val << "\n";
}

int main()
{
func();
while(1) {
if(GetKeyState('A') & 0x8000)
{
func();
Sleep(3000);
}
}
return 0;
} [/code]


Basically it's just a console application, and if we press the 'A' key then that variable will be incremented by one and displayed on the screen.

Now, I found the call to the function in memory, it's:
[code]app.exe+3C14: call app.exe+1470[/code]
So, when the 'A' key is pressed, this instruction happens. If I NOP it, then pressing 'A' won't do anything.

Now my question is: can I call this instruction FROM Cheat Engine, whenever I want to?

There are different post that use AOB Injection / Code Injection / etc., but I tried to use them and what I can do only is modify the behaviour of that function, for example I can add a different value to the variable than 1 when 'A' is pressed.

What I want to do though, is have the program as it is, and just call that function which increments the value and prints it whenever I want to, with a Cheat Engine script.

In the actual game I am trying to do this because some features are hidden in some contexts, and I want to press a button in Cheat Engine to call the game function which makes them displayed.

If I try to make this small example work, I would probably understand how to do it with the actual game.

I am pretty new to this, so maybe my question is dumb, or maybe this is not even possible, I don't know. Any help will be appreciated!

Edit: sorry, I can't make the code format work
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Sat Aug 05, 2023 9:30 am    Post subject: Reply with quote

lua: executeCodeEx(1,nil,"app.exe+1470")

docs:
Code:

executeCodeEx(callmethod, timeout, address,{type=x,value=param1} or param1,{type=x,value=param2} or param2,...)
callmethod: 0=stdcall, 1=cdecl
  timeout: Number of milliseconds to wait for a result. nil or -1, infitely. 0 is no wait (will not free the call memory, so beware of it's memory leak)
  address: Address to execute
  {type,value} : Table containing the value type, and the value
    {
    type: 0=integer (32/64bit) can also be a pointer
          1=float (32-bit float)
          2=double (64-bit float)
          3=ascii string (will get converted to a pointer to that string)
          4=wide string (will get converted to a pointer to that string)
     
    value: anything base type that lua can interpret
    }
  if just param is provided CE will guess the type based on the provided type

executeMethod(callmethod, timeout, address, {regnr=0..15,classinstance=xxxxxxxx} or classinstance, {type=x,value=param1} or param1, {type=x,value=param2} or param2,...) - Executes a method.
  regnr can be:
    0: R/EAX
    1: R/ECX
    2: R/EDX
    3: R/EBX
    4: R/ESP
    5: R/EBP
    6: R/ESI
    7: R/EDI
    8: R8
    9: R9
    10: R10
    11: R11
    12: R12
    13: R13
    14: R14
    15: R15
 

  If no register number is provided then ECX(1) is picked
  If instance is nil it is the same as executeCodeEx


_________________
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
noobidydoobedy
How do I cheat?
Reputation: 0

Joined: 05 Aug 2023
Posts: 2

PostPosted: Sat Aug 05, 2023 9:45 am    Post subject: Reply with quote

[quote="Dark Byte"]lua: executeCodeEx(1,nil,"app.exe+1470")

docs:
[code]
executeCodeEx(callmethod, timeout, address,{type=x,value=param1} or param1,{type=x,value=param2} or param2,...)
callmethod: 0=stdcall, 1=cdecl
timeout: Number of milliseconds to wait for a result. nil or -1, infitely. 0 is no wait (will not free the call memory, so beware of it's memory leak)
address: Address to execute
{type,value} : Table containing the value type, and the value
{
type: 0=integer (32/64bit) can also be a pointer
1=float (32-bit float)
2=double (64-bit float)
3=ascii string (will get converted to a pointer to that string)
4=wide string (will get converted to a pointer to that string)

value: anything base type that lua can interpret
}
if just param is provided CE will guess the type based on the provided type

executeMethod(callmethod, timeout, address, {regnr=0..15,classinstance=xxxxxxxx} or classinstance, {type=x,value=param1} or param1, {type=x,value=param2} or param2,...) - Executes a method.
regnr can be:
0: R/EAX
1: R/ECX
2: R/EDX
3: R/EBX
4: R/ESP
5: R/EBP
6: R/ESI
7: R/EDI
8: R8
9: R9
10: R10
11: R11
12: R12
13: R13
14: R14
15: R15


If no register number is provided then ECX(1) is picked
If instance is nil it is the same as executeCodeEx

[/code][/quote]

Thank you very much, this was what I was looking for.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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