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 


Get Static Fields in DotNet game

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
MMM-304
Expert Cheater
Reputation: 0

Joined: 17 Aug 2020
Posts: 166
Location: Milkey Way

PostPosted: Wed Oct 06, 2021 12:11 am    Post subject: Get Static Fields in DotNet game Reply with quote

How do I get Static Fields in dotnet game?

I have done this:
Code:
dn = getDotNetDataCollector()
  cl = dn.enumDomains()
  x = cl[1]
  mod = dn.enumModuleList(x.DomainHandle)
  c = mod[1]
  tyd = dn.enumTypeDefs(c.ModuleHandle)
  for i=1,#tyd do
   z = tyd[i]
   if z.Name == 'StardewValley.Game1' then
      methods = dn.getTypeDefData(c.ModuleHandle,z.TypeDefToken)
      for k,v in pairs(methods.Fields) do
          if v.Name == '_player' then return v end
      end
   end
  end


and got following data:

Quote:
1:table
[
IsStatic = true
FieldTypeClassName =
Name = _player
Token = 67109262
FieldType = 1
Offset = 0
]

but I cannot find any example anywhere on how to get the actual address of that field. (Also the offset is 0 for some reason). I have seen this field is used in a lot of places in the actual code, and I want to get the actual address via lua.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Wed Oct 06, 2021 2:07 am    Post subject: Reply with quote

for static in dotnet applications you'll have to use the forced data collector instead of the passive one

first inject the used .net assembly to query information about the game
Code:

LaunchDotNetInterface()


then use
Code:

dotnet_getFieldValue(moduleid, fielddef, 0)

moduleid is a unique id for the forced collector.

you can use dotnet_getModuleID(extractFileName(module.Name)) to get that

the fielddef is the token value, 67109262

so in your case
Code:

return dotnet_getFieldValue(dotnet_getModuleID(extractFileName(c.Name)), v.Token, 0)


the return value may be a pointer to the object, or a pointer to the pointer of the object, you'll have to check that out yourself

(look at dotnetinterface.lua in ce's autorun for other info/functions)

_________________
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
MMM-304
Expert Cheater
Reputation: 0

Joined: 17 Aug 2020
Posts: 166
Location: Milkey Way

PostPosted: Wed Oct 06, 2021 5:46 am    Post subject: Reply with quote

thanks a lot, DB, if only this forum allowed multiple upvotes to the same person Smile

anyway this code returns the value of that static field, not the actual address, I mean it would be better to have the address than the value as it may change if the object is destroyed and a new one takes its place

It would've been much helpful to have these methods in celua.txt with descriptions, I mean all celua.txt has is DotNetDataCollector class, it should also include other class/methods too.
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