Skip to content

Commit

Permalink
Fix hideweapon crashing with switchhands #281
Browse files Browse the repository at this point in the history
  • Loading branch information
zer0k-z committed Jan 5, 2025
1 parent 826717d commit 128c42f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/kz/misc/kz_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ static_function SCMD_CALLBACK(Command_KzRestart)
player->noclipService->HandleNoclip();
}
player->GetPlayerPawn()->Respawn();
player->quietService->ResetHideWeapon();
}
else
{
Expand Down Expand Up @@ -332,6 +333,13 @@ void KZ::misc::OnServerActivate()
interfaces::pEngine->ServerCommand("mp_restartgame 1");
}

SCMD_CALLBACK(Command_KzSwitchHands)
{
KZPlayer *player = g_pKZPlayerManager->ToPlayer(controller);
player->quietService->ResetHideWeapon();
return MRES_IGNORED;
}

// TODO: move command registration to the service class?
void KZ::misc::RegisterCommands()
{
Expand All @@ -347,6 +355,9 @@ void KZ::misc::RegisterCommands()
scmd::RegisterCmd("kz_pc", Command_KzPlayerCheck);
scmd::RegisterCmd("kz_playercheck", Command_KzPlayerCheck);
scmd::RegisterCmd("jointeam", Command_JoinTeam, true);
scmd::RegisterCmd("switchhands", Command_KzSwitchHands, true);
scmd::RegisterCmd("switchhandsleft", Command_KzSwitchHands, true);
scmd::RegisterCmd("switchhandsright", Command_KzSwitchHands, true);
// TODO: Fullupdate spectators on spec_mode/spec_next/spec_player/spec_prev
KZGotoService::RegisterCommands();
KZCheckpointService::RegisterCommands();
Expand Down Expand Up @@ -391,6 +402,7 @@ void KZ::misc::JoinTeam(KZPlayer *player, int newTeam, bool restorePos)
player->GetPlayerPawn()->CommitSuicide(false, true);
player->GetController()->SwitchTeam(newTeam);
player->GetController()->Respawn();
player->quietService->ResetHideWeapon();
if (restorePos && player->specService->HasSavedPosition())
{
player->specService->LoadPosition();
Expand Down
5 changes: 1 addition & 4 deletions src/kz/quiet/kz_quiet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ void KZQuietService::Reset()
{
this->hideOtherPlayers = this->player->optionService->GetPreferenceBool("hideOtherPlayers", false);
this->hideWeapon = this->player->optionService->GetPreferenceBool("hideWeapon", false);
for (u32 i = 0; i < sizeof(this->weaponShownCount) / sizeof(this->weaponShownCount[0]); i++)
{
this->weaponShownCount[i] = 0;
}
this->ResetHideWeapon();
}

void KZQuietService::SendFullUpdate()
Expand Down
8 changes: 8 additions & 0 deletions src/kz/quiet/kz_quiet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ class KZQuietService : public KZBaseService
bool ShouldHide();
bool ShouldHideIndex(u32 targetIndex);

void ResetHideWeapon()
{
for (u32 i = 0; i < sizeof(this->weaponShownCount) / sizeof(this->weaponShownCount[0]); i++)
{
this->weaponShownCount[i] = 0;
}
}

bool ShouldHideWeapon()
{
if (!this->player->IsAlive())
Expand Down
18 changes: 12 additions & 6 deletions src/utils/simplecmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ META_RES scmd::OnClientCommand(CPlayerSlot &slot, const CCommand &args)

if (!V_stricmp(g_cmdManager.cmds[i].name, args[0]))
{
g_cmdManager.cmds[i].callback(controller, &args);
return MRES_SUPERCEDE;
result = g_cmdManager.cmds[i].callback(controller, &args);
if (result == MRES_SUPERCEDE)
{
return result;
}
}
}
return result;
Expand Down Expand Up @@ -234,8 +237,8 @@ META_RES scmd::OnDispatchConCommand(ConCommandHandle cmd, const CCommandContext
const char *cmdName = cmds[i].hasConsolePrefix ? cmds[i].name + strlen(SCMD_CONSOLE_PREFIX) : cmds[i].name;
if (!V_stricmp(arg, cmdName))
{
cmds[i].callback(controller, &cmdArgs);
if (args[1][0] == SCMD_CHAT_SILENT_TRIGGER)
META_RES result = cmds[i].callback(controller, &cmdArgs);
if (args[1][0] == SCMD_CHAT_SILENT_TRIGGER || result == MRES_SUPERCEDE)
{
// don't send chat message
return MRES_SUPERCEDE;
Expand All @@ -258,8 +261,11 @@ META_RES scmd::OnDispatchConCommand(ConCommandHandle cmd, const CCommandContext
const char *cmdName = cmds[i].hasConsolePrefix ? cmds[i].name + strlen(SCMD_CONSOLE_PREFIX) : cmds[i].name;
if (!V_stricmp(commandName, cmdName))
{
cmds[i].callback(controller, &args);
return MRES_SUPERCEDE;
META_RES result = g_cmdManager.cmds[i].callback(controller, &args);
if (result == MRES_SUPERCEDE)
{
return result;
}
}
}
}
Expand Down

0 comments on commit 128c42f

Please sign in to comment.