sneakyevil / IL2CPP_Resolver

A run-time API resolver for IL2CPP Unity.
https://sneakyevil.gitbook.io/il2cpp-resolver/
The Unlicense
323 stars 65 forks source link

(Question) About private fields. #19

Closed kashiwazaki2 closed 2 years ago

kashiwazaki2 commented 2 years ago

Hi is there any way to get a private field from a class with IL2CPP Resolver? I am able to see it on DnSpy and Cheat Engine via .Net Info but after trying to get the class variables with IL2CPP Resolver via IL2CPP::Class::GetFields it dones't find any field m_uMaxLength is always zero. Thanks in advance.

kashiwazaki2 commented 2 years ago

image

sneakyevil commented 2 years ago

Are you sure you're checking correct class or component? Because I never had problem fetching public/private/protected field.

extremeblackliu commented 2 years ago

hi , at first i assume you are new user , what game you are trying to using with IL2CPPResolver? did you looked our API document or quick example? https://github.com/sneakyevilSK/IL2CPP_Resolver/blob/main/README.md.

kashiwazaki2 commented 2 years ago

Thank you to both for your answer and time, yes i am new to unity i used ILL2CPP Resolver from start and it works well i got almost all the things i wanted except the Private Fields thats why i asked. The game i am working on is NARAKA BLADEPOINT anyways i got the private field i wanted from a pointer since i wans't able to get it from the IL2CPP::GetField. Anyways i have another problem that is confusing me from start, see the image bellow. image The error is pretty descritive hoewer i ve created a threads with IL2CPP::Thread::Create and it does still crash my game (the only fix i could find is to bytepatch the GC jne to jmp to prevent it crash but i can't do that with the game anticheat active for obvius reasons) so my best way is the thread way. This is how my code looks, i hope you guys can help me!

BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        naraka_hooks::Run();
        break;
    }
    return TRUE;
}

void naraka_hooks::initialize()
{   
    AllocConsole();
    FILE* pFile = nullptr;
    freopen_s(&pFile, xorstr_("CONOUT$"), xorstr_("w"), stdout);
    printf("Starting...\r\n");

    MemoryMgr::Initialize();
    naraka_hooks::_returns::oPresent = MemoryMgr::SwapPointer<naraka_hooks::tPresent>(offsets::ISwapChainGameOverlay, (uintptr_t)naraka_hooks::hkPresent);

    while (true)
    {
        Sleep(1500);
    }
}

void naraka_hooks::Run()
{
    static bool il2cpp_initialized = IL2CPP::Initialize();

    if (il2cpp_initialized)
        IL2CPP::Thread::Create(naraka_hooks::initialize);
}

PS: I do my render stuff on present hook, i ve also saw that many other projects do it this way, the only difference is that i am using the steam overlay and not kiero.

extremeblackliu commented 2 years ago

il2cppthread issue is a unresolved bug here:https://github.com/sneakyevilSK/IL2CPP_Resolver/issues/9 . is your private field from your ss is from static class?

kashiwazaki2 commented 2 years ago

Its not an static class but the class is valid i ve checked it on cheat engine and says the correct name of the class, class name by the way is AntiCheatSDK idk if it have something to do? btw you can access to the class via instance. image

extremeblackliu commented 2 years ago

yes, access via instance ,problem sovled.

kashiwazaki2 commented 2 years ago

Is not there are any way to solve the crash issue? it does happends with any function you call dones't matter w2s, transform, custom it does happends with all xd i feel like that bug cap the library i ve tried to fix my self by trying many things but it does always happends uhmmm

sneakyevil commented 2 years ago

Hook any function and run your stuff there.

kashiwazaki2 commented 2 years ago

Hook any function and run your stuff there.

i ve thinked about it, but as far i know that way i won't be able to render with imgui or other guis, right?

kashiwazaki2 commented 2 years ago

Also i know this is a bit offtopic but i don't know how t find the OnUpdate Function, i can't even find it on DnSpy or ida :(

extremeblackliu commented 2 years ago

Also i know this is a bit offtopic but i don't know how t find the OnUpdate Function, i can't even find it on DnSpy or ida :(

i had cheat on the game like 6 months ago, i looked up my old source, there are multiple OnUpdate function, the gameassembly.dll is packed by vmprotect ,you need manually find and check it. you cant call unity functions in il2cpp thread, is still a bug,maybe it get fix in future

kashiwazaki2 commented 2 years ago

Also i know this is a bit offtopic but i don't know how t find the OnUpdate Function, i can't even find it on DnSpy or ida :(

i had cheat on the game like 6 months ago, i looked up my old source, there are multiple OnUpdate function, the gameassembly.dll is packed by vmprotect ,you need manually find and check it. you cant call unity functions in il2cpp thread, is still a bug,maybe it get fix in future

Well i do not think that VMProtect has something to do, i have dumped all dlls and i can see its code clearly on dnspy and ida pro for all functions, what i can't find is a OnUpdate function to hook, i only found functions like this public extern void <>iFixBaseProxy_onUpdateItems(); wich does nothing when hooked even with the correct address i ve also tried to hook others function like combo etc and these works but they aren't called every frame just when you attack etc, can you give me some function name that is called every frame?

sneakyevil commented 2 years ago

Your issue was about private fields, we are not gonna discuss here about you having problem finding function to hook as it is not related to library itself. If you having problem to find function that will get called every frame you shouldn't even consider doing something related to that game. You can easily check Unity docs and find out there are multiple predefined function that are not called "OnUpdate" and you can easily hook that aswell. Besides that you could reverse yourself unityplayer.dll and find out there is function that is called every frame that you could hook.

kashiwazaki2 commented 2 years ago

Okay so after a while trying i ve successfully hooked a function inside camera that execute everyframe and i ve did my stuff here with a cache system so i do my loging stuff on camera hook and i can render on present, thx you guys sorry for hijacking the topic lol ^^

sneakyevil commented 2 years ago

You can check my last issue post at https://github.com/sneakyevilSK/IL2CPP_Resolver/issues/9#issuecomment-1126806016 and try run you code in present hook, gl.

kashiwazaki2 commented 2 years ago

You can check my last issue post at #9 (comment) and try run you code in present hook, gl.

thx for the hint, ill try it out today, anyway i am trying to get around their caller check, i din't expected that they check from where is the function being called like others anticheat hehehe