From bf8108c2d6f117523fe6629adffddf1409470d24 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 6 Dec 2018 08:48:00 +0100 Subject: [PATCH] Lock game actions and commands to replay commands if replay is active. --- src/openrct2/Game.cpp | 15 ++++++++++++++- src/openrct2/actions/GameAction.cpp | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 4c9b94614e..e9a65a6ab8 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -388,6 +388,18 @@ int32_t game_do_command_p( flags = *ebx; + auto* replayManager = GetContext()->GetReplayManager(); + if (replayManager != nullptr && replayManager->IsReplaying()) + { + // We only accept replay commands as long the replay is active. + if ((flags & GAME_COMMAND_FLAG_REPLAY) == 0) + { + // TODO: Introduce proper error. + gGameCommandErrorText = STR_CHEAT_BUILD_IN_PAUSE_MODE; + return MONEY32_UNDEFINED; + } + } + if (gGameCommandNestLevel == 0) { gGameCommandErrorText = STR_NONE; @@ -473,7 +485,6 @@ int32_t game_do_command_p( // Second call to actually perform the operation new_game_command_table[command](eax, ebx, ecx, edx, esi, edi, ebp); - auto* replayManager = GetContext()->GetReplayManager(); if (replayManager != nullptr && replayManager->IsRecording() && (flags & GAME_COMMAND_FLAG_APPLY) && (flags & GAME_COMMAND_FLAG_GHOST) == 0 && (flags & GAME_COMMAND_FLAG_5) == 0) { @@ -544,7 +555,9 @@ int32_t game_do_command_p( // Show error window if (gGameCommandNestLevel == 0 && (flags & GAME_COMMAND_FLAG_APPLY) && gUnk141F568 == gUnk13CA740 && !(flags & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED) && !(flags & GAME_COMMAND_FLAG_NETWORKED)) + { context_show_error(gGameCommandErrorTitle, gGameCommandErrorText); + } return MONEY32_UNDEFINED; } diff --git a/src/openrct2/actions/GameAction.cpp b/src/openrct2/actions/GameAction.cpp index b6ed69acc1..12efb3e80c 100644 --- a/src/openrct2/actions/GameAction.cpp +++ b/src/openrct2/actions/GameAction.cpp @@ -200,6 +200,23 @@ namespace GameActions uint16_t actionFlags = action->GetActionFlags(); uint32_t flags = action->GetFlags(); + auto* replayManager = OpenRCT2::GetContext()->GetReplayManager(); + if (replayManager != nullptr && replayManager->IsReplaying()) + { + // We only accept replay commands as long the replay is active. + if ((flags & GAME_COMMAND_FLAG_REPLAY) == 0) + { + // TODO: Introduce proper error. + GameActionResult::Ptr result = std::make_unique(); + + result->Error = GA_ERROR::GAME_PAUSED; + result->ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE; + result->ErrorMessage = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED; + + return result; + } + } + GameActionResult::Ptr result = Query(action); if (result->Error == GA_ERROR::OK) { @@ -265,7 +282,6 @@ namespace GameActions } else if (network_get_mode() == NETWORK_MODE_NONE) { - auto* replayManager = OpenRCT2::GetContext()->GetReplayManager(); if (replayManager != nullptr && replayManager->IsRecording()) { replayManager->AddGameAction(gCurrentTicks, action);