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

Trying to get value from field #18

Closed kashiwazaki2 closed 2 years ago

kashiwazaki2 commented 2 years ago

Hey, first of all thank you for the library it is really good and easy to expand for your needs. Hoewer i am having an issue and i am not sure if it related to library or i am missing something, So i am trying to get the value from a Field of the game i am working on.

Here is the field i want to get, it is a member of ActorModel class (dnspy view) hp

Here is how i am trying to retreive it on my proyect:

int GetHp()
        {
            if (!MemoryMgr::IsValidPtr(this))
                return 0;

            auto m_pFieldOffset = IL2CPP::Class::Utils::GetFieldOffset(xorstr_("ActorModel"), xorstr_("get_Hp"));
            printf("Hp Offset %i || ptr %p\r\n", *reinterpret_cast<int8_t*>(reinterpret_cast<uintptr_t>(this + m_pFieldOffset), reinterpret_cast<uintptr_t>(this) + m_pFieldOffset);
            return *reinterpret_cast<int8_t*>(this + m_pFieldOffset);
        }

        int GetHpMax()
        {
            if (!MemoryMgr::IsValidPtr(this))
                return 0;

            auto m_pFieldOffset = IL2CPP::Class::Utils::GetFieldOffset(xorstr_("ActorModel"), xorstr_("get_HpMax"));
            printf("Hp Offset %i || ptr %p\r\n", *reinterpret_cast<int8_t*>(reinterpret_cast<uintptr_t>(this + m_pFieldOffset), reinterpret_cast<uintptr_t>(this) + m_pFieldOffset);
            return *reinterpret_cast<int8_t*>(this + m_pFieldOffset);
        }

Once i call it from any ActorModel it dones't make any exception, it just give me an invalid value like this:

Output

Any help is appreciated, thank you!

sneakyevil commented 2 years ago

You're trying to get field offset, but you're using method name instead the field name which is "HpMax" and not "get_HpMax".

kashiwazaki2 commented 2 years ago

Well i tried both methods, but i tried it again after your reply just in case and it dones't work either, return the same weird value.

sneakyevil commented 2 years ago

Maybe it is not field but it is property, otherwise you could fetch all fields and check if it even exist there otherwise it must be property.

kashiwazaki2 commented 2 years ago

Maybe it is not field but it is property, otherwise you could fetch all fields and check if it even exist there otherwise it must be property.

You are right bro i solved it thank you for your help, it was property as you said ^^