Skip to content

Commit

Permalink
fix(player): Buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
skuzzis committed Oct 16, 2024
1 parent a047834 commit e0d1c13
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/entrypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ void Swiftly::Hook_GameFrame(bool simulating, bool bFirstTick, bool bLastTick)
continue;

auto buttonStates = pawn->m_pMovementServices()->m_nButtons().m_pButtonStates();
player->SetButtons(buttonStates[0], buttonStates[1]);
player->SetButtons(buttonStates[0]);

if (player->HasMenuShown())
player->RenderMenu();
Expand Down
9 changes: 5 additions & 4 deletions src/player/player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,16 @@ const std::vector<std::string> key_buttons = {

void OnClientKeyStateChange(int playerid, std::string key, bool pressed);

void Player::SetButtons(uint64_t new_buttons, uint64_t changed_buttons)
void Player::SetButtons(uint64_t new_buttons)
{
if(changed_buttons > 0) {
if(buttons != new_buttons) {
for(uint16_t i = 0; i < 64; i++) {
if((new_buttons & (1ULL << i)) != 0 && (changed_buttons & (1ULL << i)) != 0)
if((buttons & (1ULL << i)) != 0 && (new_buttons & (1ULL << i)) == 0)
OnClientKeyStateChange(this->slot, key_buttons[i], true);
else if((new_buttons & (1ULL << i)) == 0 && (changed_buttons & (1ULL << i)) != 0)
else if((buttons & (1ULL << i)) == 0 && (new_buttons & (1ULL << i)) != 0)
OnClientKeyStateChange(this->slot, key_buttons[i], false);
}
buttons = new_buttons;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/player/player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Player
void SwitchTeam(int team);
void ChangeTeam(int team);

void SetButtons(uint64_t new_buttons, uint64_t changed_buttons);
void SetButtons(uint64_t new_buttons);

std::string tag = "";
std::string tagcolor = "{default}";
Expand Down Expand Up @@ -131,6 +131,7 @@ class Player
Menu* menu = nullptr;
int page = 0;
int selected = 0;
uint64_t buttons = 0;

std::map<std::string, std::any> internalVars;

Expand Down

0 comments on commit e0d1c13

Please sign in to comment.