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 


How to address different Mono methods with the same name?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3327

PostPosted: Thu Oct 23, 2025 4:20 am    Post subject: Reply with quote

2024 bugfix
Code:
<?xml version="1.0" encoding="utf-8"?>
<CheatTable CheatEngineTableVersion="46">
  <CheatEntries>
    <CheatEntry>
      <ID>0</ID>
      <Description>"one-liner and test"</Description>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>{$lua}

-- assume LaunchMonoDataCollector has been called

-- one liner (including the *2024 bug*)
-- function reEscape(a)local b=[[().%+-*?[^]]a=a:gsub('.',function(c)if b:find(c,1,true)then return'%'..c end end)return a end;function findMethodAddrBySignature(d,e,f,g,h)local i=findMethodBySignature(d,e,f,g,h)if i~=nil and i&gt;0 then return mono_compile_method(i)end end;function findMethodBySignature(d,e,f,g,h)assert(type(g)=='string',"invalid signature")g="^"..reEscape(g:gsub(";",","))local j=mono_findClass(d,e)if type(j)~='number'or j==0 then return nil end;local k=mono_class_enumMethods(j)if type(k)~='table'or#k&lt;1 then return nil end;if h then print('check:'..f..": &lt;"..g.."&gt; vs ")end;for l=1,#k do if f==k[l].name then local m=mono_method_getSignature(k[l].method)if h then print("  &gt;&gt; &lt;"..m..'&gt;')end;if m:match(g)then return k[l].method end end end end;function tohex(n)return string.format('%X',n or 0)end

-- one liner (including the *2024 bugfix*)
---- panraven's one-liner - all credits and thanks to panraven!
---- For more info, please refer to https://forum.cheatengine.org/viewtopic.php?p=5659670#5659670
function reEscape(a)local b=[[().%+-*?[^]]a=a:gsub('.',function(c)if b:find(c,1,true)then return'%'..c end end)return a end;function findMethodAddrBySignature(d,e,f,g,h)local i=findMethodBySignature(d,e,f,g,h)if i~=nil and i&gt;0 then return mono_compile_method(i) end end;function findMethodBySignature(d,e,f,g,h)assert(type(g)=='string',"invalid signature")local j=mono_findClass(d,e)if type(j)~='number'or j==0 then return nil end;local k=mono_class_enumMethods(j)if type(k)~='table'or#k&lt;1 then return nil end;if h then print('check:'..f..": &lt;"..g.."&gt; vs ")end;for l=1,#k do if f==k[l].name then local m=mono_method_getSignature(k[l].method) if h then print("  &gt;&gt; &lt;"..m..'&gt;')end;if m == g then return k[l].method end end end end;function tohex(n)return string.format('%X',n or 0)end

{$asm}
/* This is the expanded version of the original.
function reEscape(a)
  local b=[[().%+-*?[^]]
  a=a:gsub('.',function(c)if b:find(c,1,true)then return'%'..c end end)
  return a
end;
function findMethodAddrBySignature(d,e,f,g,h)
  local i=findMethodBySignature(d,e,f,g,h)
  if i~=nil and i&gt;0 then
    return mono_compile_method(i)
  end
end;
function findMethodBySignature(d,e,f,g,h)
  assert(type(g)=='string',"invalid signature")
  g="^"..reEscape(g:gsub(";",","))
  local j=mono_findClass(d,e)
  if type(j)~='number'or j==0 then return nil end;
  local k=mono_class_enumMethods(j)
  if type(k)~='table'or#k&lt;1 then return nil end;
  if h then print('check:'..f..": &lt;"..g.."&gt; vs ")end;
  for l=1,#k do
    if f==k[l].name then
      local m=mono_method_getSignature(k[l].method)
      if h then print("  &gt;&gt; &lt;"..m..'&gt;')end;
      if m:match(g)then
        return k[l].method
      end
    end
  end
end;
function tohex(n)return string.format('%X',n or 0)end
*/

/* This is the expanded version of the 2024 bugfixed one.
function reEscape(a)
  local b=[[().%+-*?[^]]
  a=a:gsub('.',function(c)if b:find(c,1,true)then return'%'..c end end)
  return a
end;
function findMethodAddrBySignature(d,e,f,g,h)
  local i=findMethodBySignature(d,e,f,g,h)
  if i~=nil and i&gt;0 then
    return mono_compile_method(i)
  end
end;
function findMethodBySignature(d,e,f,g,h)
  assert(type(g)=='string',"invalid signature")
  -- g="^"..reEscape(g:gsub(";",",")) -- *2024 bugfix* &lt;=== REMOVE this line
  local j=mono_findClass(d,e)
  if type(j)~='number'or j==0 then return nil end;
  local k=mono_class_enumMethods(j)
  if type(k)~='table'or#k&lt;1 then return nil end;
  if h then print('check:'..f..": &lt;"..g.."&gt; vs ")end;
  for l=1,#k do
    if f==k[l].name then
      local m=mono_method_getSignature(k[l].method)
      if h then print("  &gt;&gt; &lt;"..m..'&gt;')end;
      if m == g then       -- *2024 bugfix* &lt;=== ADD this line
      --if m:match(g)then  -- *2024 bugfix* &lt;=== REMOVE this line
        return k[l].method
      end
    end
  end
end;
function tohex(n)return string.format('%X',n or 0)end
*/

{$asm}

{$lua}
-- test
print('--') -- test to show/print all signature of a given function name
print(tohex(findMethodAddrBySignature('UnityEngine','Texture2D','.ctor','?',true)))
print('--') -- test to match a specific (third) signature of a function name
print(tohex(findMethodAddrBySignature('UnityEngine','Texture2D','.ctor','int,int,UnityEngine.TextureFormat,bool,bool$',true)))
-- the last '$' is lua match end-of-string, wthout this, the match MAY succeed on fourth one.
-- all other character should be compare as is, including upper/lower cases.
{$asm}


{$lua}
--define a lua Global INTEGER type variable for use in AA script, ce 6.5 feature

LUAVAR = findMethodAddrBySignature('UnityEngine','Texture2D','.ctor','int,int,UnityEngine.TextureFormat,bool,bool$')

{$asm}

[ENABLE]

globalalloc(testarea,$10)

testarea:
dq $LUAVAR     // using the Lua Variable in AA Script by prefixing a '$' symbol, Lua variable is case-sensitive.
dq $LUAVAR+111111
 
[DISABLE]

</AssemblerScript>
    </CheatEntry>
    <CheatEntry>
      <ID>1</ID>
      <Description>"full function defintion"</Description>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>{$lua}

-- assume LaunchMonoDataCollector has been called

function reEscape(s)
  local escPatChars = [[().%+-*?[^]]
  s = s:gsub('.',function(c) if escPatChars:find(c,1,true) then return '%'..c end end)
  return s
end
function findMethodAddrBySignature(namespace,classname,methodname,signature,check)
  local meth = findMethodBySignature(namespace,classname,methodname,signature,check)
  if meth~=nil and meth&gt;0 then
    return mono_compile_method(meth)
  end
end
function findMethodBySignature(namespace,classname,methodname,signature,check)
  assert(type(signature)=='string',"invalid signature")
  --signature="^"..reEscape(signature:gsub(";",",")) -- *2024 bugfix* &lt;=== REMOVE this line
  local class = mono_findClass(namespace,classname)
  if type(class)~='number' or class==0 then return nil end
  local methods=mono_class_enumMethods(class)
  if type(methods)~='table' or #methods&lt;1 then return nil end
  if check then print('check:'..methodname..": &lt;"..signature.."&gt; vs ") end
  for i=1,#methods do
   if methodname == methods[i].name then
     local sign = mono_method_getSignature(methods[i].method)
     if check then  print("  &gt;&gt; &lt;"..sign..'&gt;') end
      if sign == signature then     -- *2024 bugfix* &lt;=== ADD this line
--     if sign:match(signature) then -- *2024 bugfix* &lt;=== REMOVE this line
       return methods[i].method
     end
   end
  end
end
-- Test
function tohex(n)return string.format('%X',n or 0)end
{$asm}

[ENABLE]

 
 
[DISABLE]

</AssemblerScript>
    </CheatEntry>
  </CheatEntries>
</CheatTable>
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
Goto page Previous  1, 2
Page 2 of 2

 
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