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 


Getting class instance address in script

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

Joined: 18 Jul 2018
Posts: 8

PostPosted: Wed Mar 16, 2022 3:20 pm    Post subject: Getting class instance address in script Reply with quote

I'm trying to simulate the button "Lookup Instances" in the .NET Info window in a Lua script to no success. Not really sure what functions I need to be using. I have my full class name and everything, and I can manually get the address of the class by clicking the button on the .NET Info window, but I'd like to be able to just enable my script and have the address of the class popped into a variable. How would I do this?

Edit 1:
I have this so far:

Code:

if syntaxcheck then return end
LaunchMonoDataCollector()
GetLuaEngine().MenuItem5.doClick()
mono_initialize()
local assems = mono_enumAssemblies()
for i in pairs(assems) do
    local imageID = mono_getImageFromAssembly(assems[i])
    local imageName = mono_image_get_name(imageID)
    if imageName == "RoR2" then
       print("RoR2 classes:")
       local classTable = mono_image_enumClasses(imageID)
       for j in pairs(classTable) do
           local className = mono_class_getName(classTable[j])
           print(className)
       end
    end
end


However, the printing of class names doesn't do anything - my lua console is printing empty strings. I'd guess the table of classIds returned by enumClasses() is empty but I don't know why, because the RoR2 image has a *lot* of classes in the .NET window.

_________________
im kinda edgy
Back to top
View user's profile Send private message
Frouk
Grandmaster Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 510

PostPosted: Thu Mar 17, 2022 1:50 am    Post subject: Reply with quote

idk if that wiil help:
Code:
function playerStatusInit()
   local class = mono_findClass('Assembly-CSharp','PlayerStatus')
   local id = mono_class_getStaticFieldAddress('Instance',class)
   PlayerStatus = getAddress(id)
end

playerStatusInit()

that's example of getting address from mono
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Thu Mar 17, 2022 9:15 am    Post subject: This post has 1 review(s) Reply with quote

The return of mono_image_enumClasses is an array (say cs) if success.
The index of the array run from 1 to #cs, and its element has fields like,
cs[i] = {classname = 'simple class name(no namespace)' , namespace='..some name space..', class = <some number>}
What the mono_class_getName need is the number cs[i].class, ie.
Code:

 local className = mono_class_getName(classTable[j].class)

but mono_class_getName should just return the cs[i].className.
You probably want mono_class_getFullName, which should include namespace and may return nested class (eg. namespace.aClass+aNestedClass).

Please check monoscript.lua in autorun directory to see how these mono function use.

btw, CE's lua only print number and string directly, table or boolean values etc need to convert to string (tostring) or use format or it only show like empty string, so you might think it's 'empty'.

_________________
- Retarded.
Back to top
View user's profile Send private message
Vortexian
How do I cheat?
Reputation: 0

Joined: 18 Jul 2018
Posts: 8

PostPosted: Thu Mar 17, 2022 12:30 pm    Post subject: Reply with quote

This is close to what I want, but not exactly. I've attached an image to this with what I'm trying to get. The .NET info screen has a "Lookup Instances" button that returns an address in the text field. I want that address it comes up with.


Screenshot 2022-03-17 132843.png
 Description:
what i need
 Filesize:  7.92 KB
 Viewed:  3340 Time(s)

Screenshot 2022-03-17 132843.png



_________________
im kinda edgy
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