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 


Help with invoking functions

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

Joined: 27 Jun 2022
Posts: 4

PostPosted: Mon Jun 27, 2022 5:25 pm    Post subject: Help with invoking functions Reply with quote

Hi,
I am not 100% sure if my question belongs here as my question covers a few topics but
I am trying to write a script for the game star renegades which adds a piece of equipment to the player's inventory. I am using the mono dissector and found the method
AddEquipmentIntoPlayerInventory. The first issue I am having is that the function is overloaded so if I use the mono_findMethod Lua function I get the incorrect function returning.
Is there a way in Lua or in Asm to get the exact function I want? Secondly, The function takes 2 arguments. The 1st argument is called Mdi.SRRW.Engine.Equipment is a structure which contains fields which contain other structures and types. Using the mono dissector I can see several instances of these structures already exist. How can I pass these already existing structures as an argument? I would assume you would pass the address of the structure to the method but I am not having much success. How could I do this in Lua and or Asm? Also, How could I pass the argument to the method when using the invoke function in the mono dissector? Any help would be much appreciated. If I was not clear or you need more info or screenshots. I can provide them.
Thanks
Back to top
View user's profile Send private message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Mon Jun 27, 2022 10:28 pm    Post subject: Reply with quote

With MonoDissector you already have a pretty big head start because you know what goes where in explicit detail. Usually what is passed are values and addresses and the dissector tells you which is which up front. Usually all of these exist somewhere already so pass the address. If it doesnt, then build a dummy one with realistic values and pass the address to the dummy structure.

If you are struggling, there are a few possibilities to consider:

If you are having trouble setting up the call correctly, break and trace the real call and verify what each step is truly passing (break and trace, step line by line and look in real time to see what resides at each address)

If you can't find the function, you already have the information that is being passed to it, just find what accesses those addresses and one of them leads to the function call.

If you can't find any of those addresses, then instance search each and every aspect of the call one at a time until you do.

If even that fails, then find the memory addresses manually, at least one of them likely has something in their structure that you can find with traditional memory searching. Then repeat the find what accesses that address step.
Back to top
View user's profile Send private message
Dan_Lyle
How do I cheat?
Reputation: 0

Joined: 27 Jun 2022
Posts: 4

PostPosted: Tue Jun 28, 2022 10:31 am    Post subject: Reply with quote

I know what the method is called and when I put a breakpoint on the instruction and then add equipment to my inventory it does stop the execution of the method. The issue I am having is that I want to script adding equipment onto my inventory at will and the function is overloaded so I need to be able to get the correct method via a script. When I invoke the method via the mono dissector I need to pass the arguments how do I pass an argument of a struct type? Each time I pass a pointer to one I get a Lua error. Ultimately I would like to script everything and not use the mono dissector to invoke the function.
I have added images which should illustrate what I mean, I hope.



Capture2.JPG
 Description:
Lua error
 Filesize:  72.69 KB
 Viewed:  1677 Time(s)

Capture2.JPG



Capture.JPG
 Description:
when invoking the command via mono dissector
 Filesize:  192.08 KB
 Viewed:  1677 Time(s)

Capture.JPG



kor7ovhrair81.jpg
 Description:
overloaded functions
 Filesize:  25.22 KB
 Viewed:  1677 Time(s)

kor7ovhrair81.jpg


Back to top
View user's profile Send private message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Tue Jun 28, 2022 4:37 pm    Post subject: Reply with quote

To run a thread without using the dissector, follow the directions here:
https://forum.cheatengine.org/viewtopic.php?p=5716269#5716269

You keep asking what the inputs to the function should be and the best way to figure that out is by reviewing an actual example of how the game uses it.

Quote:
When I invoke the method via the mono dissector I need to pass the arguments how do I pass an argument of a struct type?


There is a lot more you need to call the function appropriately. I strongly advocate you step through the function and look at each and every instruction used to set it up, call it, and then dispose of it.

For example:

onReceiveItem():
.Lines of assembly to recognize equipment is being added to inventory.
.Fetch up inventory structure
.Perform other unknowns that set registers
.Call AddEquipmentIntoPlayerInventory...
.Perform other stuff
ret

You know where the function resides in memory. Break and trace it. When you add an item to the inventory, it should generate a trace. Find what calls it (Its where the return leads)

From here you can scroll up to the insertion point of that function and do a second break and trace. Hopefully, it only executes when you add the item to the inventory, if it doesn't then you will need to limit it's break to some register being equal to a value.

When the break and trace activates only when you add the item, you now get to see exactly what gets placed where to prep the call. That is what you need to replicate to make a successful call and will resolve your question about how to properly format the call, even from the dissector.

Then you create a thread with the proper prep and disposal to call the function on your own.
Back to top
View user's profile Send private message
Dan_Lyle
How do I cheat?
Reputation: 0

Joined: 27 Jun 2022
Posts: 4

PostPosted: Tue Jun 28, 2022 5:19 pm    Post subject: Reply with quote

That is fine. I have looked at what the assembly does and I know that when the method is legitimately called a pointer is passed and an int is passed. I know that the AddEquipmentIntoPlayerInventory is called by other methods or the game can call it directly based on the context. The method itself just places a pointer to the equipment in the player inventory at a slot number based on the int argument.

I could write the script in ASM like what is shown in that link but the issue now is how do I get the address of the function? as I have said the function is overloaded and I would need to use the correct one and the address of the function does change so I cannot just hardcode the call.
Back to top
View user's profile Send private message
Dan_Lyle
How do I cheat?
Reputation: 0

Joined: 27 Jun 2022
Posts: 4

PostPosted: Wed Jun 29, 2022 11:35 am    Post subject: Reply with quote

I think I can find the correct function by using a couple of lua functions so I think I could write a script in lua which can do what I want. I will report back once I have wrote a script
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