HenryEx

getMonoFields

Aug 18th, 2026
4,532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.66 KB | Source Code | 0 0
  1. -- Function to return a table of fields and their offsets for the specified class name
  2. -- params:
  3. --    className: name of the class to get a structure definition for
  4. --    namespace (OPTIONAL): namespace of the class to get a structure definition for
  5. --    img (OPTIONAL): mono image in which to search for class, speeds up the process
  6. --    static (OPTIONAL): set to true if you want static fields
  7. -- Returns table setup like this:
  8. -- k: 'field name', v: { offset, CE vartype, mono vartype }
  9. -- Get values like: fields["fieldName"][1] for offset
  10.  
  11. function getMonoFields(className, nameSpace, img, static)
  12.   nameSpace = type(nameSpace) == 'string' and nameSpace or ''
  13.   img = type(img) == 'number' and img or nil
  14.   static = static and true or false
  15.   local searchslow = className:find("+") ~= nil
  16.   local classId
  17.  
  18.   if img then
  19.     if searchslow then
  20.       classId = mono_image_findClassSlow(img, nameSpace, className)
  21.     else
  22.       classId = mono_image_findClass(img, nameSpace, className)
  23.     end
  24.   else
  25.     classId = mono_findClass(nameSpace, className)
  26.   end
  27.   if classId==nil or classId==0 then return nil end
  28.  
  29.   local fields=mono_class_enumFields(classId,true,true)
  30.   local tFields = {}
  31.  
  32.   for i=1, #fields do
  33.     if fields[i].isStatic == static and not fields[i].isConst then
  34.       local fname = fields[i].name
  35.       local foffset = fields[i].offset
  36.       local fmonotype = fields[i].monotype
  37.       local fvartype
  38.       if _G.libmono then  -- new functions in CE 7.6+
  39.         fvartype = mono_class_isEnum(mono_field_getClass( fields[i].field )) and vtDword or monoTypeToVarType(fmonotype)
  40.       else
  41.         fvartype = monoTypeToVarType(fmonotype)
  42.       end
  43.       tFields[fname] = {foffset, fvartype, fmonotype}
  44.     end
  45.   end
  46.  
  47.   if next(tFields) == nil then tFields = nil end  -- nil on empty table
  48.   return tFields
  49. end
  50.  
  51. -- ORIGINAL FUNCTION:
  52. --function to return a table of fields and their offsets for the specified class name
  53. --params:
  54. --    namespace: namespace of the class to get a structure definition for
  55. --    className: name of the class to get a structure definition for
  56. -- Get values like: fields["fieldName"]
  57. -- from: https://www.cheatengine.org/forum/viewtopic.php?t=608935
  58. --function getMonoFields(namespace, className)
  59. --   local classId = mono_findClass(namespace, className)
  60. --   local struct = monoform_exportStructInternal(createStructure(''), classId,
  61. --      true --[[recursive]], false --[[not static]], {'some struct map thing'}, false --[[not global]])
  62. --
  63. --   local fields = {}
  64. --   for i=0, struct.Count-1 do
  65. --      local e = struct.getElement(i)
  66. --      fields[e.name] = e.offset
  67. --   end
  68. --   return fields
  69. --end
  70.  
Advertisement
Add Comment
Please, Sign In to add comment