From 546aace3dd120b17b0bbc7f6534a16fa2b3e86d4 Mon Sep 17 00:00:00 2001 From: Yaroslav Tretyakov Date: Tue, 7 Feb 2017 05:04:41 -0700 Subject: [PATCH] Fix invalid desync checks #5185 --- src/openrct2/network/network.cpp | 10 +++++++++- src/openrct2/network/network.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/openrct2/network/network.cpp b/src/openrct2/network/network.cpp index ba227e0f7b..0f7cdd44ae 100644 --- a/src/openrct2/network/network.cpp +++ b/src/openrct2/network/network.cpp @@ -472,7 +472,6 @@ void Network::UpdateClient() } Close(); } - ProcessGameCommandQueue(); // Check synchronisation if (!_desynchronised && !CheckSRAND(gCurrentTicks, gScenarioSrand0)) { @@ -484,6 +483,8 @@ void Network::UpdateClient() Close(); } } + + ProcessGameCommandQueue(); break; } } @@ -562,6 +563,11 @@ bool Network::CheckSRAND(uint32 tick, uint32 srand0) return true; } + if (game_commands_processed_this_tick != 0) { + // SRAND/sprite hash is only updated once at beginning of tick so it is invalid otherwise + return true; + } + if (tick == server_srand0_tick) { server_srand0_tick = 0; // Check that the server and client sprite hashes match @@ -1231,6 +1237,7 @@ void Network::ProcessGameCommandQueue() sint32 command = gc.esi; money32 cost = game_do_command_p(command, (sint32*)&gc.eax, (sint32*)&gc.ebx, (sint32*)&gc.ecx, (sint32*)&gc.edx, (sint32*)&gc.esi, (sint32*)&gc.edi, (sint32*)&gc.ebp); if (cost != MONEY32_UNDEFINED) { + game_commands_processed_this_tick++; NetworkPlayer* player = GetPlayerByID(gc.playerid); if (player) { player->LastAction = NetworkActions::FindCommand(command); @@ -1778,6 +1785,7 @@ void Network::Client_Handle_TICK(NetworkConnection& connection, NetworkPacket& p } } } + game_commands_processed_this_tick = 0; } void Network::Client_Handle_PLAYERLIST(NetworkConnection& connection, NetworkPacket& packet) diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index 8d7ded8bf1..2af7c1eca7 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -213,6 +213,7 @@ private: uint8 default_group = 0; SDL_RWops *_chatLogStream = nullptr; std::string _chatLogPath; + uint32 game_commands_processed_this_tick = 0; void UpdateServer(); void UpdateClient();