FigmaFan / IL2CPP-Resolver

unity il2cpp game hacking library
MIT License
5 stars 1 forks source link

Crashes When Calling Function w/ Class Arg #2

Open Zaclin-GIT opened 4 months ago

Zaclin-GIT commented 4 months ago

I am attempting to call a method called "SendMessage" from the class "SocketManager".

public void SendMessage(DCBCCBKEIHN KLEHEMPPMPP)
{
}

DCBCCBKEIHN is the base packet class and each of the packet classes derive from this.

Example of one of the packet classes:

public class IKFIMIBKGEP : DCBCCBKEIHN
{
    // Token: 0x0600254C RID: 9548 RVA: 0x00002050 File Offset: 0x00000250
    [Token(Token = "0x600254C")]
    [Address(RVA = "0x8B4D10", Offset = "0x8B3F10", VA = "0x1808B4D10")]
    public IKFIMIBKGEP()
    {
    }

    // Token: 0x0600254D RID: 9549 RVA: 0x00002050 File Offset: 0x00000250
    [Token(Token = "0x600254D")]
    [Address(RVA = "0x1050790", Offset = "0x104F990", VA = "0x181050790", Slot = "9")]
    public override void KBODKJFAGBE()
    {
    }

    // Token: 0x0600254E RID: 9550 RVA: 0x00002050 File Offset: 0x00000250
    [Token(Token = "0x600254E")]
    [Address(RVA = "0x1050820", Offset = "0x104FA20", VA = "0x181050820", Slot = "13")]
    protected override void PGHAGLDAKMH()
    {
    }
}

When attempting to call this method and pass one of the packet classes as an argument, I crash. I've tried multiple different ways of casting the packet to the base class in hopes it would accept it as an arg, but I'm having no luck. I was able to get another much simpler hook working.

Example of what I believe the call should look like: il2cpp::call_function<void>(il2cpp::get_method("DecaGames.RotMG.Managers.Net", "SocketManager", "SendMessage"), LocalSocketManager, new IKFIMIBKGEP_o(), 0);

Can anyone please explain why this doesnt work.

Also, if anyone could explain the difference between IKFIMIBKGEP_o & IKFIMIBKGEP_c, that would be much appreciated.

Thanks.

FigmaFan commented 4 months ago

did you check if get_method actually returns a valid result? And instead of doing new IKFIMIBKGEP_o(), try to create the object by calling its constructor (method name should be .ctor). IKFIMIBKGEP_o is an instance of the IKFIMIBKGEP class (_o = object), while IKFIMIBKGEP_c is the class itself (_c = class)

Zaclin-GIT commented 4 months ago

Thank you for explain the difference between _c & _o. I assumed that's what they meant but wasn't sure. As for calling the SendMessage method, I tried to call the constructor method of the IKFIMIBKGEP class, but it doesn't have a namespace (https://imgur.com/a/EWNRLqk) and I don't have a local version of the class because it doesn't appear to have been initialized yet. I did try to initialize it myself prior to using the call function but that didn't work either.

il2cpp::call_function<IKFIMIBKGEP_c>(il2cpp::get_method("", "IKFIMIBKGEP", ".ctor"), packet);

This just results in a crash. Let me know if this is what you meant by calling the constructor.

I've tried so many different methods at this point that I cant even remember what I have tried.

I appreciate your help.

FigmaFan commented 4 months ago

you probably crash when using il2cpp::call_function<IKFIMIBKGEP_c>(il2cpp::get_method("", "IKFIMIBKGEP", ".ctor"), packet); because get_method returns a nullptr. Make sure that it returns a valid result first (you might need to remove the _namespace.empty() check inside of get_method to be able to find methods without namespace)