Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: set IN_JUMP for m_afButtonPressed in CBasePlayer::Jump to fix the incorrect behavior of bxt_autojump #496

Open
SmileyAG opened this issue Feb 1, 2024 · 0 comments
Assignees

Comments

@SmileyAG
Copy link
Collaborator

SmileyAG commented Feb 1, 2024

Current behaviour with bxt_autojump:

This happens because of this check in the CBasePlayer::Jump code: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/player.cpp#L1619-L1621

Proposed fix:

    int *m_afButtonPressed;
    bool is_buttonpressed_jump_set = false;

    if (offm_afButtonPressed)
    {
        m_afButtonPressed = reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(thisptr) + offm_afButtonPressed);
        if (!(*m_afButtonPressed & IN_JUMP))
        {
            if (CVars::bxt_autojump.GetBool())
            {
              *m_afButtonPressed |= IN_JUMP;
              is_buttonpressed_jump_set = true;
            }
        }
    }

    insideCBasePlayerJump = true;
    ORIG_CBasePlayer__Jump(thisptr);
    insideCBasePlayerJump = false;
    
    if (is_buttonpressed_jump_set)
        *m_afButtonPressed &= ~IN_JUMP;

At the same time, this will also add the ability to use bxt_autojump in pre-HLSDK 2.0 game versions (where the movement code was accessed only for server-side)

I had previously done byte patching for CoF to fix that behavior in BXT code:

} else { // CoF-Mod
if ((*reinterpret_cast<byte*>(pCBasePlayer__Jump_OldButtons_Check_Byte) == 0x75) && CVars::bxt_autojump.GetBool())
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCBasePlayer__Jump_OldButtons_Check_Byte), 1, reinterpret_cast<const byte*>("\xEB"));
else if ((*reinterpret_cast<byte*>(pCBasePlayer__Jump_OldButtons_Check_Byte) == 0xEB) && !CVars::bxt_autojump.GetBool())
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCBasePlayer__Jump_OldButtons_Check_Byte), 1, reinterpret_cast<const byte*>("\x75"));

But looking back I understand that it was a completely bad decision to fix it in that way, so that byte patching code can be removed as soon as the m_afButtonPressed set solution would be added

@SmileyAG SmileyAG self-assigned this Feb 1, 2024
@SmileyAG SmileyAG changed the title Set IN_JUMP for m_afButtonPressed in CBasePlayer::Jump to fix the incorrect behavior of bxt_autojump feature: set IN_JUMP for m_afButtonPressed in CBasePlayer::Jump to fix the incorrect behavior of bxt_autojump Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant