Addressing or Jump to Method that shared same name.

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
TheByteSize
Expert Cheater
Expert Cheater
Posts: 293
Joined: Sat Mar 04, 2017 7:28 am
Reputation: 232

Addressing or Jump to Method that shared same name.

Post by TheByteSize »

I got 2 methods that has same name but difference in number of variable inputs.
For example got these 2.

Code: Select all

dothing:init(a,b,c,d)
dothing:init(e)
then if I use

Code: Select all

mono_compile_method(mono_getJitInfo(getAddress('dothing:init')).method)
CE will compile both.
now if I try to jump to dothing:init, it will always jump to whichever compiled first.
So, how do I get address for each of these methods?
Last edited by TheByteSize on Sat Oct 09, 2021 10:13 pm, edited 2 times in total.

GreenHouse
Expert Cheater
Expert Cheater
Posts: 857
Joined: Fri Oct 12, 2018 10:25 pm
Reputation: 889

Re: Addressing or Jump to Method that shared same name.

Post by GreenHouse »

You could do this, might not be the best, but if you can see any way to improve it, go ahead.
Gets class, enumerates methods inside, then iterates between all methods and checks if the name and the parameters are the same. If so, then print.

Code: Select all

local methods = mono_class_enumMethods(mono_findClass('','Player'))

for i = 1,#methods do
if methods[i].name == 'UnlockSticker' and mono_method_getSignature(methods[i].method) == 'string,bool' then
print(mono_method_getSignature(methods[i].method)) --Do Compile Here
end end

User avatar
DhaosCollider
Table Makers
Table Makers
Posts: 97
Joined: Sat Mar 23, 2019 6:59 pm
Reputation: 711

Re: Addressing or Jump to Method that shared same name.

Post by DhaosCollider »

TheByteSize wrote:
Sat Oct 09, 2021 9:44 am
...
If getAddress('doing:init') is true, it means that the JIT compilation has already been executed, right?
Do you need mono_compile_method?

Anyway, I think it's C# method overloading.
Since the array of bytes should be different, I think it's easiest to use Auto Assembler:aobScanRegion to get the address.
TheByteSize wrote:
Sat Oct 09, 2021 10:05 pm
unfortunately, aobscanregion(x,dothing:init,dothing:init+aaa,0xf) will jump which ever method get compiled first.
Can't methods with the same name be separated by the 0xf part (signature)?
If you can't do that, if I were you, I would consider other places to hook. Good luck.
Last edited by DhaosCollider on Sat Oct 09, 2021 11:09 pm, edited 1 time in total.

TheByteSize
Expert Cheater
Expert Cheater
Posts: 293
Joined: Sat Mar 04, 2017 7:28 am
Reputation: 232

Re: Addressing or Jump to Method that shared same name.

Post by TheByteSize »

GreenHouse wrote:
Sat Oct 09, 2021 12:19 pm
thanks for the idea.
DhaosCollider wrote:
Sat Oct 09, 2021 1:15 pm
If getAddress('doing:init') is true, it means that the JIT compilation has already been executed, right?
Do you need mono_compile_method?

Anyway, I think it's C# method overloading.
Since the array of bytes should be different, I think it's easiest to use Auto Assembler:aobScanRegion to get the address.
unfortunately, aobscanregion(x,dothing:init,dothing:init+aaa,0xf) will jump which ever method get compiled first.

I'm currently word around this problem by giving the end of region address to be have stupid large address.

aSwedishMagyar
Table Makers
Table Makers
Posts: 670
Joined: Mon Jul 06, 2020 3:19 am
Reputation: 1190

Re: Addressing or Jump to Method that shared same name.

Post by aSwedishMagyar »

I asked the same question some time ago here

I have since simplified the functions in that post and you can use this:

The findMethodBySignature function:

Code: Select all

function findMethodBySignature(nameSpace,className,methodName,signature)
    local classId = mono_findClass(nameSpace,className)
    local methodTable = mono_class_enumMethods(classId)
    for i = 1,#methodTable do
        local currentMethod = methodTable[i]
        if currentMethod.name == methodName then
            local sig = mono_method_getSignature(currentMethod.method)
            if sig:match(signature) then return currentMethod.method end
        end
    end
    return nil
end
And how to use it:

Code: Select all

local nameSpace = ''
local className = ''
local methodName = ''
local signature = ''
local methId = findMethodBySignature(nameSpace,className,methodName,signature)
if methId ~= nil then
    local methAddr = mono_compile_method(methId)
    unregisterSymbol('myMethod')
    registerSymbol('myMethod',methAddr)
end

TheByteSize
Expert Cheater
Expert Cheater
Posts: 293
Joined: Sat Mar 04, 2017 7:28 am
Reputation: 232

Re: Addressing or Jump to Method that shared same name.

Post by TheByteSize »

I got it working but now ....
aSwedishMagyar wrote:
Sat Oct 09, 2021 11:17 pm
I'll use that clean structured code. Thank you all.

Post Reply

Who is online

Users browsing this forum: No registered users