Fix OOB accesses rendering ghosts, fix ghost hook collision line

Fix out-of-bounds accesses when rendering ghost players, which use the client ID `-2`. This was causing the hook collision line of ghost players to be affected by real players, which is not correct, as ghosts do not interact with other characters.

Closes #8239.
This commit is contained in:
Robert Müller 2024-04-20 23:11:19 +02:00
parent a00d6a3119
commit 9be40e1782

View file

@ -214,7 +214,7 @@ void CPlayers::RenderHookCollLine(
}
}
if(m_pClient->IntersectCharacter(OldPos, FinishPos, FinishPos, ClientId) != -1)
if(ClientId >= 0 && m_pClient->IntersectCharacter(OldPos, FinishPos, FinishPos, ClientId) != -1)
{
HookCollColor = color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClHookCollColorTeeColl));
break;
@ -417,7 +417,7 @@ void CPlayers::RenderPlayer(
bool InAir = !Collision()->CheckPoint(Player.m_X, Player.m_Y + 16);
bool Running = Player.m_VelX >= 5000 || Player.m_VelX <= -5000;
bool WantOtherDir = (Player.m_Direction == -1 && Vel.x > 0) || (Player.m_Direction == 1 && Vel.x < 0);
bool Inactive = m_pClient->m_aClients[ClientId].m_Afk || m_pClient->m_aClients[ClientId].m_Paused;
bool Inactive = ClientId >= 0 && (m_pClient->m_aClients[ClientId].m_Afk || m_pClient->m_aClients[ClientId].m_Paused);
// evaluate animation
float WalkTime = std::fmod(Position.x, 100.0f) / 100.0f;
@ -561,7 +561,7 @@ void CPlayers::RenderPlayer(
}
if(g_pData->m_Weapons.m_aId[CurrentWeapon].m_aSpriteMuzzles[IteX])
{
if(PredictLocalWeapons)
if(PredictLocalWeapons || ClientId < 0)
Dir = vec2(pPlayerChar->m_X, pPlayerChar->m_Y) - vec2(pPrevChar->m_X, pPrevChar->m_Y);
else
Dir = vec2(m_pClient->m_Snap.m_aCharacters[ClientId].m_Cur.m_X, m_pClient->m_Snap.m_aCharacters[ClientId].m_Cur.m_Y) - vec2(m_pClient->m_Snap.m_aCharacters[ClientId].m_Prev.m_X, m_pClient->m_Snap.m_aCharacters[ClientId].m_Prev.m_Y);
@ -681,6 +681,9 @@ void CPlayers::RenderPlayer(
GameClient()->m_Effects.FreezingFlakes(BodyPos, vec2(32, 32), Alpha);
}
if(ClientId < 0)
return;
int QuadOffsetToEmoticon = NUM_WEAPONS * 2 + 2 + 2;
if((Player.m_PlayerFlags & PLAYERFLAG_CHATTING) && !m_pClient->m_aClients[ClientId].m_Afk)
{
@ -694,9 +697,6 @@ void CPlayers::RenderPlayer(
Graphics()->QuadsSetRotation(0);
}
if(ClientId < 0)
return;
if(g_Config.m_ClAfkEmote && m_pClient->m_aClients[ClientId].m_Afk && !(Client()->DummyConnected() && ClientId == m_pClient->m_aLocalIds[!g_Config.m_ClDummy]))
{
int CurEmoticon = (SPRITE_ZZZ - SPRITE_OOP);