Skip to content

Conversation

@oscar-wos
Copy link

Refactor CreateVirtualFunction to include caching and hashing.

AddCommand("css_teleport", "", (player, info) =>
{
    if (player is null)
    {
        return;
    }

    Console.WriteLine($"teleporting {player.PlayerPawn}");
    player.PlayerPawn.Value?.Teleport(new Vector3(0, 0, 0));
});
image

Refactor CreateVirtualFunction to include caching and hashing.
@oscar-wos oscar-wos requested a review from roflmuffin as a code owner October 25, 2025 22:12
@2vg
Copy link

2vg commented Oct 27, 2025

This can be also possible on the C++ side, now the vf will not leak.
I have this modification in my private fork one, and it has been running for over a week on a 64person ZE server without a single reboot or crash.
Well, its possible that a destructor isnt necessary.
cache code e.g.)

    // destructor
    - ValveFunction::~ValveFunction() {}
    + ValveFunction::~ValveFunction() {
    +     if (m_precallback) {
    +         globals::callbackManager.ReleaseCallback(m_precallback);
    +         m_precallback = nullptr;
    +     }
    +     if (m_postcallback) {
    +         globals::callbackManager.ReleaseCallback(m_postcallback);
    +         m_postcallback = nullptr;
    +     }
    + }

    // cache
    auto it = std::find_if(m_managed_ptrs.begin(), m_managed_ptrs.end(), [&](ValveFunction* vf) {
        return vf && vf->m_ulAddr == function_addr &&
               vf->m_eCallingConvention == CONV_THISCALL &&
               vf->m_Args == args &&
               vf->m_eReturnType == return_type &&
               vf->m_offset == vtable_offset;
    });

    if (it != m_managed_ptrs.end())
    {
        return *it;
    }

@roflmuffin
Copy link
Owner

I think this is a useful feature, but I believe it would be better implemented on the native side rather than on the C# side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants