Merge branch 'fix-respawn-cheat' into 'master'

Fix lap cheat prevention failing when player dies

Closes #1119

See merge request KartKrew/Kart!2079
This commit is contained in:
Oni 2024-03-11 05:25:40 +00:00
commit f932bccb6c

View file

@ -2138,6 +2138,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
boolean enteredGame;
UINT8 lastsafelap;
UINT8 lastsafecheatcheck;
UINT16 bigwaypointgap;
roundconditions_t roundconditions;
boolean saveroundconditions;
@ -2209,6 +2210,31 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
// SRB2kart
memcpy(&itemRoulette, &players[player].itemRoulette, sizeof (itemRoulette));
memcpy(&respawn, &players[player].respawn, sizeof (respawn));
// Here's the exact scenario:
// - Respawn with Ring Shooter (or lightsnake in general)
// - Spectate, re-enter the game
// - Now respawn.pointxyz is set to where the player
// spectated
// - K_DoIngameRespawn will be called after
// G_PlayerReborn (in P_MovePlayerToCheatcheck)
// - If the respawn state is not reset here, then the
// call to K_DoIngameRespawn will do nothing, and
// respawn.pointxyz will stay the same
// - This is bad, because when K_RespawnChecker runs, it
// clears the init state once the player reaches
// respawn.pointxyz
// - This is because it assumes respawn.pointxyz is where
// the respawn waypoint is located
// - In other words, the init state will reset before
// lightsnake reaches the respawn waypoint
// - This is bad because lap cheat prevention relies on
// the init state being cleared after reaching the
// respawn waypoint (because moving to the respawn
// waypoint could cross a finish line the wrong way and
// lose a lap)
respawn.state = RESPAWNST_NONE;
memcpy(&public_key, &players[player].public_key, sizeof(public_key));
if (betweenmaps || leveltime < introtime)
@ -2246,6 +2272,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
cheatchecknum = 0;
lastsafelap = 0;
lastsafecheatcheck = 0;
bigwaypointgap = 0;
saveroundconditions = false;
tallyactive = false;
@ -2293,6 +2320,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
lastsafelap = players[player].lastsafelap;
lastsafecheatcheck = players[player].lastsafecheatcheck;
bigwaypointgap = players[player].bigwaypointgap;
tallyactive = players[player].tally.active;
if (tallyactive)
@ -2366,6 +2394,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
p->angleturn = playerangleturn;
p->lastsafelap = lastsafelap;
p->lastsafecheatcheck = lastsafecheatcheck;
p->bigwaypointgap = bigwaypointgap;
// save player config truth reborn
p->skincolor = skincolor;