From 60153e703511e49d4c2c56831954e498b5dac047 Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Wed, 5 Oct 2016 07:55:30 -0400 Subject: [PATCH] Ignore check_frames if CRCs are utterly inconsistent This effectively disables check_frames if frame 1's CRC differs between host and client. This is necessary because some important cores have nondeterminism in core_run, thus mandating check_frames, while some important cores have nondeterminism in core_serialize, thus mandating no check_frames. --- network/netplay/netplay_net.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/network/netplay/netplay_net.c b/network/netplay/netplay_net.c index 2562f48231..0b544f95b4 100644 --- a/network/netplay/netplay_net.c +++ b/network/netplay/netplay_net.c @@ -31,22 +31,33 @@ static void netplay_handle_frame_hash(netplay_t *netplay, struct delta_frame *delta) { + static bool crcs_valid = true; if (netplay_is_server(netplay)) { - if (netplay->check_frames && delta->frame % netplay->check_frames == 0) + if (netplay->check_frames && + (delta->frame % netplay->check_frames == 0 || delta->frame == 1)) { delta->crc = netplay_delta_frame_crc(netplay, delta); netplay_cmd_crc(netplay, delta); } } - else if (delta->crc) + else if (delta->crc && 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) { - /* Fix this! */ - netplay_cmd_request_savestate(netplay); + if (delta->frame == 1) + { + /* 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; + } + else if (crcs_valid) + { + /* Fix this! */ + netplay_cmd_request_savestate(netplay); + } } } }