6470: Fix ninja not getting predicted r=heinrich5991 a=Zwelf

Fixes #6464

This was regressed by #6246 by the wrong transformation of `if(!m_FreezeTime)` to `if(m_FreezeTime != 0)` instead of the correct `if(m_FreezeTime == 0)`.

And take additional measure to never set m_FreezeTime to a negative number in client prediction code.

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Zwelf <zwelf@strct.cc>
This commit is contained in:
bors[bot] 2023-03-26 14:50:25 +00:00 committed by GitHub
commit b207826df1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View file

@ -489,7 +489,7 @@ void CCharacter::GiveNinja()
{
m_Core.m_Ninja.m_ActivationTick = GameWorld()->GameTick();
m_Core.m_aWeapons[WEAPON_NINJA].m_Got = true;
if(m_FreezeTime > 0)
if(m_FreezeTime == 0)
m_Core.m_aWeapons[WEAPON_NINJA].m_Ammo = -1;
if(m_Core.m_ActiveWeapon != WEAPON_NINJA)
m_LastWeapon = m_Core.m_ActiveWeapon;
@ -1205,7 +1205,7 @@ void CCharacter::Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtende
{
if(m_FreezeTime == 0)
Freeze();
m_FreezeTime = pExtended->m_FreezeEnd - GameWorld()->GameTick();
m_FreezeTime = maximum(1, pExtended->m_FreezeEnd - GameWorld()->GameTick());
}
else if(pExtended->m_FreezeEnd == -1)
m_Core.m_DeepFrozen = true;

View file

@ -1022,7 +1022,7 @@ void CCharacter::SnapCharacter(int SnappingClient, int ID)
Health = m_Health;
Armor = m_Armor;
if(m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo > 0)
AmmoCount = (m_FreezeTime > 0) ? m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo : 0;
AmmoCount = (m_FreezeTime == 0) ? m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo : 0;
}
if(GetPlayer()->IsAfk() || GetPlayer()->IsPaused())