diff --git a/network/netplay/netplay_init.c b/network/netplay/netplay_init.c index 579f1cb09d..5494e532a1 100644 --- a/network/netplay/netplay_init.c +++ b/network/netplay/netplay_init.c @@ -429,6 +429,8 @@ netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port, netplay->nat_traversal = netplay->is_server ? nat_traversal : false; netplay->delay_frames = delay_frames; netplay->check_frames = check_frames; + netplay->crc_validity_checked = false; + netplay->crcs_valid = true; netplay->quirks = quirks; netplay->self_mode = netplay->is_server ? NETPLAY_CONNECTION_PLAYING : diff --git a/network/netplay/netplay_private.h b/network/netplay/netplay_private.h index 25f16ab8cc..f404c3b480 100644 --- a/network/netplay/netplay_private.h +++ b/network/netplay/netplay_private.h @@ -430,6 +430,12 @@ struct netplay /* Frequency with which to check CRCs */ uint32_t check_frames; + + /* Have we checked whether CRCs are valid at all? */ + bool crc_validity_checked; + + /* Are they valid? */ + bool crcs_valid; }; diff --git a/network/netplay/netplay_sync.c b/network/netplay/netplay_sync.c index 551b61afd7..5307651528 100644 --- a/network/netplay/netplay_sync.c +++ b/network/netplay/netplay_sync.c @@ -131,34 +131,37 @@ void netplay_simulate_input(netplay_t *netplay, size_t sim_ptr, bool resim) static void netplay_handle_frame_hash(netplay_t *netplay, struct delta_frame *delta) { - static bool crcs_valid = true; if (netplay->is_server) { if (netplay->check_frames && - (delta->frame % netplay->check_frames == 0 || delta->frame == 1)) + delta->frame % netplay->check_frames == 0) { delta->crc = netplay_delta_frame_crc(netplay, delta); netplay_cmd_crc(netplay, delta); } } - else if (delta->crc && crcs_valid) + else if (delta->crc && netplay->crcs_valid) { /* We have a remote CRC, so check it */ uint32_t local_crc = netplay_delta_frame_crc(netplay, delta); if (local_crc != delta->crc) { - if (delta->frame == 1) + if (!netplay->crc_validity_checked) { - /* We check frame 1 just to make sure the CRCs make sense at all. - * If we've diverged at frame 1, we assume CRCs are not useful. */ - crcs_valid = false; + /* If the very first check frame is wrong, they probably just don't + * work */ + netplay->crcs_valid = false; } - else if (crcs_valid) + else if (netplay->crcs_valid) { /* Fix this! */ netplay_cmd_request_savestate(netplay); } } + else if (!netplay->crc_validity_checked) + { + netplay->crc_validity_checked = true; + } } }