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 


Mono: How to get enums with correct Index

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

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

PostPosted: Tue Aug 31, 2021 12:44 am    Post subject: Mono: How to get enums with correct Index Reply with quote

How can I get enum (public enum NAME {}) name and correct ID in lua?

CE's dotNet view treats it as a class and the definitions as static fields, but their definitions are clearly visible in dnSpy:

dnSpy:

CE:


I tried this code:
Code:
function getStaticFieldData(namespace,class)
      return mono_class_enumFields(mono_findClass(namespace, class))
end
field = getStaticFieldData('Assembly-CSharp','TechType')
return field


but the offset it returns is 0 for everything

How can I get the right definition offset same as visible from dnSpy in lua?
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Tue Aug 31, 2021 1:23 am    Post subject: Reply with quote

try this one :
Code:
function enumStaticFields(dll,class)
local path = mono_findClass(dll,class)
local id = mono_class_getStaticFieldAddress(mono_enumDomains()[5],class)
return id
end --Must be solved, since i've recently used this method

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
MMM-304
Expert Cheater
Reputation: 0

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

PostPosted: Tue Aug 31, 2021 1:56 am    Post subject: Reply with quote

i think you did not read my question. I DO NOT want the adderss, I want the definition index and name of each entry in enum just like how dnSpy show when hover over:

Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Tue Aug 31, 2021 3:52 am    Post subject: Reply with quote

dnSpy is using reflection to create those tooltips. C# offers a few ways to pull the index of an enum value, such as:

Casting the enum value to its integer representation:
Code:
var val = (int)TechType.BreakableLead


Obtaining all of the enums values and doing a direct lookup and indexing it:
Code:

var val = TechType.BreakableLead;
var idx = Array.IndexOf(Enum.GetValues(val.GetType()), val);

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
MMM-304
Expert Cheater
Reputation: 0

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

PostPosted: Tue Aug 31, 2021 6:09 am    Post subject: Reply with quote

how do I get that through lua?

Additional question: How do I use CS Compiler in CE 7.3
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Tue Aug 31, 2021 7:12 am    Post subject: Reply with quote

To use cs compiler you need to create aa script and inside of it type:
Code:
{$c}
//Insert your code here
{$asm}


EDIT:
Maybe this topic will help you[/url]

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
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