Skip to content

Commit 0d5cb8c

Browse files
ujicosDivity
andcommitted
fix(input): simplify delta usercmd hook to post-decode unpack
creds to @Divity for the original C hook, non-functional atm so component disabled until we get it working. use older build to get (bad) controller support Co-Authored-By: Kenneth Skeens <73408742+divity@users.noreply.github.com>
1 parent 65f0d79 commit 0d5cb8c

1 file changed

Lines changed: 27 additions & 28 deletions

File tree

src/component/gamepad/xinput.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ namespace xinput
6666
bool cursor_hidden_for_gamepad = false;
6767
DWORD last_analog_update_time = 0;
6868
float analog_frame_seconds = 1.0f / 60.0f;
69+
void apply_native_gamepad_to_cmd(game::usercmd_t* cmd);
6970
void set_bool_dvar(game::dvar_s* dvar, bool value);
7071
float get_view_sensitivity();
7172
float get_turn_rate(const char* normal_name, const char* ads_name, float normal_default, float ads_default, bool ads_active);
@@ -812,8 +813,8 @@ namespace xinput
812813
int value = 0;
813814
__asm
814815
{
815-
mov edx, msg
816816
xor ecx, ecx
817+
mov edx, msg
817818
mov eax, 0x103EEDE0
818819
call eax
819820
mov value, eax
@@ -839,45 +840,43 @@ namespace xinput
839840
return value;
840841
}
841842

842-
void ApplyMovement(game::msg_t* msg, int key, game::usercmd_t* from, game::usercmd_t* to)
843+
void CL_Gamepad_ReadHighPrecision(game::msg_t* msg, int key, game::usercmd_t* to)
843844
{
844-
if (msg_read_bit(msg))
845+
if (!msg || !to)
845846
{
846-
const auto movement_bits = static_cast<std::int16_t>(key ^ msg_read_bits(msg, 16));
847-
to->forwardmove = static_cast<std::int8_t>(movement_bits);
848-
to->rightmove = static_cast<std::int8_t>(movement_bits >> 8);
849847
return;
850848
}
851849

852-
to->forwardmove = from->forwardmove;
853-
to->rightmove = from->rightmove;
850+
if (!msg_read_bit(msg))
851+
{
852+
return;
853+
}
854+
855+
const auto packed = static_cast<std::uint16_t>(msg_read_bits(msg, 16));
856+
to->forwardmove = static_cast<std::int8_t>(packed & 0xFF);
857+
to->rightmove = static_cast<std::int8_t>((packed >> 8) & 0xFF);
854858
}
855859

860+
game::msg_t* pending_delta_msg = nullptr;
861+
int pending_delta_key = 0;
862+
game::usercmd_t* pending_delta_to = nullptr;
863+
856864
__declspec(naked) void MSG_ReadDeltaUsercmdKey_stub()
857865
{
858866
__asm
859867
{
860-
// Original QoS callsite passes:
861-
// eax = msg_t*
862-
// edi = to usercmd
863-
// [esp + 4] = from usercmd
864-
// [esp + 8] = key
865-
push ebx
866-
push esi
867-
868-
mov ebx, [esp + 0Ch]
869-
mov esi, [esp + 10h]
870-
871-
push edi
872-
push ebx
873-
push esi
874-
push eax
875-
call ApplyMovement
876-
add esp, 10h
868+
mov [pending_delta_msg], eax
869+
mov [pending_delta_key], ecx
870+
mov [pending_delta_to], edi
877871

878-
pop esi
879-
pop ebx
872+
mov edx, 0x103F0170
873+
call edx
880874

875+
push [pending_delta_to]
876+
push [pending_delta_key]
877+
push [pending_delta_msg]
878+
call CL_Gamepad_ReadHighPrecision
879+
add esp, 12
881880
ret
882881
}
883882
}
@@ -1406,4 +1405,4 @@ namespace gamepad
14061405
}
14071406
}
14081407

1409-
REGISTER_COMPONENT(xinput::component)
1408+
//REGISTER_COMPONENT(xinput::component)

0 commit comments

Comments
 (0)