Usage of field offsets

// Global variable saving
namespace Global
{
    int m_iExtraGravityOffset = 0;
}

// Call it somewhere in ur project once
void Init()
{
    Global::m_iExtraGravityOffset = IL2CPP::Class::Utils::GetFieldOffset("PlayerMovement", "extraGravity");
}

// IL2CPP Thread in forever loop
void Thread()
{
    while (1)
    {
        Sleep(1);
    
        Unity::CGameObject* m_pPlayer = Unity::GameObject::Find("Player");
        if (!m_pPlayer)
            continue;
        
        Unity::CComponent* m_pPlayerManager = m_pPlayer->GetComponent("PlayerManager");
        if (!m_pPlayerManager)
            continue;
            
        // Here you use the actual stored offset that you fetched in init function.
        *reinterpret_cast<float*>(reinterpret_cast<uintptr_t>(m_pPlayerManager) + Global::m_iExtraGravityOffset) = 1000.f;
    }
}

Last updated