diff --git a/src/data/context/GameContext.cpp b/src/data/context/GameContext.cpp index b53bd4f6..68f422bf 100644 --- a/src/data/context/GameContext.cpp +++ b/src/data/context/GameContext.cpp @@ -18,6 +18,7 @@ #include "data\models\RichPresenceModel.hh" #include "services\AchievementRuntime.hh" +#include "services\FrameEventQueue.hh" #include "services\IAudioSystem.hh" #include "services\IConfiguration.hh" #include "services\ILocalStorage.hh" @@ -290,6 +291,39 @@ void GameContext::FinishLoadGame(int nResult, const char* sErrorMessage, bool bW pRuntime.SyncAssets(); EndLoad(); + + // non-hardcore warning + auto& pConfiguration = ra::services::ServiceLocator::Get(); + if (!pConfiguration.IsFeatureEnabled(ra::services::Feature::Hardcore)) + { + bool bShowHardcorePrompt = false; + if (pConfiguration.IsFeatureEnabled(ra::services::Feature::NonHardcoreWarning)) + bShowHardcorePrompt = Assets().HasCoreAssets(); + + if (bShowHardcorePrompt) + { + ra::services::ServiceLocator::GetMutable().QueueFunction([]() { + ra::ui::viewmodels::MessageBoxViewModel vmWarning; + vmWarning.SetHeader(L"Enable Hardcore mode?"); + vmWarning.SetMessage(L"You are loading a game with achievements and do not currently have hardcore mode enabled."); + vmWarning.SetIcon(ra::ui::viewmodels::MessageBoxViewModel::Icon::Warning); + vmWarning.SetButtons(ra::ui::viewmodels::MessageBoxViewModel::Buttons::YesNo); + + if (vmWarning.ShowModal() == ra::ui::DialogResult::Yes) + ra::services::ServiceLocator::GetMutable().EnableHardcoreMode(false); + }); + } + else + { + const bool bLeaderboardsEnabled = pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards); + + ra::services::ServiceLocator::Get().PlayAudioFile(L"Overlay\\info.wav"); + ra::services::ServiceLocator::GetMutable().QueueMessage( + L"Playing in Softcore Mode", + bLeaderboardsEnabled ? L"Leaderboard entries will not be submitted." : L""); + } + } + OnActiveGameChanged(); } diff --git a/src/services/FrameEventQueue.cpp b/src/services/FrameEventQueue.cpp index e3f391e2..d7e9ee4e 100644 --- a/src/services/FrameEventQueue.cpp +++ b/src/services/FrameEventQueue.cpp @@ -13,6 +13,14 @@ void FrameEventQueue::DoFrame() { std::wstring sPauseMessage; + if (!m_vFunctions.empty()) + { + for (auto& fFunction : m_vFunctions) + fFunction(); + + m_vFunctions.clear(); + } + if (!m_vTriggeredTriggers.empty()) { sPauseMessage.append(L"The following triggers have triggered:"); diff --git a/src/services/FrameEventQueue.hh b/src/services/FrameEventQueue.hh index 3aefb09f..5539bb2f 100644 --- a/src/services/FrameEventQueue.hh +++ b/src/services/FrameEventQueue.hh @@ -35,12 +35,18 @@ public: m_vTriggeredTriggers.push_back(sTriggerName); } + void QueueFunction(std::function fAction) + { + m_vFunctions.push_back(fAction); + } + void DoFrame(); protected: std::set m_vMemChanges; std::vector m_vResetTriggers; std::vector m_vTriggeredTriggers; + std::vector> m_vFunctions; }; } // namespace services diff --git a/src/services/GameIdentifier.cpp b/src/services/GameIdentifier.cpp index 3f70b48b..f9935ba9 100644 --- a/src/services/GameIdentifier.cpp +++ b/src/services/GameIdentifier.cpp @@ -184,35 +184,6 @@ void GameIdentifier::ActivateGame(unsigned int nGameId) pGameContext.SetGameHash((nGameId == m_nPendingGameId) ? m_sPendingHash : ""); ra::services::ServiceLocator::GetMutable().BeginSession(nGameId); - - auto& pConfiguration = ra::services::ServiceLocator::Get(); - if (!pConfiguration.IsFeatureEnabled(ra::services::Feature::Hardcore)) - { - bool bShowHardcorePrompt = false; - if (pConfiguration.IsFeatureEnabled(ra::services::Feature::NonHardcoreWarning)) - bShowHardcorePrompt = pGameContext.Assets().HasCoreAssets(); - - if (bShowHardcorePrompt) - { - ra::ui::viewmodels::MessageBoxViewModel vmWarning; - vmWarning.SetHeader(L"Enable Hardcore mode?"); - vmWarning.SetMessage(L"You are loading a game with achievements and do not currently have hardcore mode enabled."); - vmWarning.SetIcon(ra::ui::viewmodels::MessageBoxViewModel::Icon::Warning); - vmWarning.SetButtons(ra::ui::viewmodels::MessageBoxViewModel::Buttons::YesNo); - - if (vmWarning.ShowModal() == ra::ui::DialogResult::Yes) - ra::services::ServiceLocator::GetMutable().EnableHardcoreMode(false); - } - else - { - const bool bLeaderboardsEnabled = pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards); - - ra::services::ServiceLocator::Get().PlayAudioFile(L"Overlay\\info.wav"); - ra::services::ServiceLocator::GetMutable().QueueMessage( - L"Playing in Softcore Mode", - bLeaderboardsEnabled ? L"Leaderboard entries will not be submitted." : L""); - } - } } else { diff --git a/tests/data/context/GameContext_Tests.cpp b/tests/data/context/GameContext_Tests.cpp index 6aab2225..c5230976 100644 --- a/tests/data/context/GameContext_Tests.cpp +++ b/tests/data/context/GameContext_Tests.cpp @@ -12,6 +12,7 @@ #include "tests\RA_UnitTestHelpers.h" #include "tests\data\DataAsserts.hh" +#include "tests\ui\UIAsserts.hh" #include "tests\mocks\MockAchievementRuntime.hh" #include "tests\mocks\MockAudioSystem.hh" @@ -20,6 +21,7 @@ #include "tests\mocks\MockClock.hh" #include "tests\mocks\MockConfiguration.hh" #include "tests\mocks\MockDesktop.hh" +#include "tests\mocks\MockFrameEventQueue.hh" #include "tests\mocks\MockLocalStorage.hh" #include "tests\mocks\MockOverlayManager.hh" #include "tests\mocks\MockServer.hh" @@ -65,6 +67,7 @@ TEST_CLASS(GameContext_Tests) ra::services::mocks::MockThreadPool mockThreadPool; ra::services::mocks::MockAudioSystem mockAudioSystem; ra::services::mocks::MockAchievementRuntime mockAchievementRuntime; + ra::services::mocks::MockFrameEventQueue mockFrameEventQueue; ra::ui::viewmodels::mocks::MockOverlayManager mockOverlayManager; ra::data::context::mocks::MockConsoleContext mockConsoleContext; ra::data::context::mocks::MockEmulatorContext mockEmulator; @@ -1235,6 +1238,180 @@ TEST_CLASS(GameContext_Tests) Assert::AreEqual(GameContext::Mode::Normal, game.GetMode()); Assert::IsFalse(notifyHarness.m_bNotified); } + + + TEST_METHOD(TestLoadGameNonHardcoreWarningHardcore) + { + GameContextHarness game; + game.MockLoadGameAPIs(1U, "0123456789abcdeffedcba987654321", "", + "{\"ID\":5,\"Title\":\"Ach1\",\"Description\":\"Desc1\",\"Flags\":3," + "\"Points\":5,\"MemAddr\":\"1=1\",\"Author\":\"Auth1\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}," + "{\"ID\":7,\"Title\":\"Ach2\",\"Description\":\"Desc2\",\"Flags\":3," + "\"Points\":10,\"MemAddr\":\"1=1\",\"Author\":\"Auth2\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}" + ); + + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::NonHardcoreWarning, true); + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, true); + game.LoadGame(1U, "0123456789abcdeffedcba987654321"); + + // no dialogs when game with achievements loaded in hardcore mode + game.mockFrameEventQueue.DoFrame(); // hardcore warning gets queued for the UI thread + Assert::IsFalse(game.mockDesktop.WasDialogShown()); + Assert::IsNull(game.mockOverlayManager.GetMessage(2U)); // message 1 will be game placard + } + + TEST_METHOD(TestLoadGameNonHardcoreWarningLeaderboards) + { + GameContextHarness game; + game.MockLoadGameAPIs(1U, "0123456789abcdeffedcba987654321", "", + "{\"ID\":5,\"Title\":\"Ach1\",\"Description\":\"Desc1\",\"Flags\":3," + "\"Points\":5,\"MemAddr\":\"1=1\",\"Author\":\"Auth1\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}," + "{\"ID\":7,\"Title\":\"Ach2\",\"Description\":\"Desc2\",\"Flags\":3," + "\"Points\":10,\"MemAddr\":\"1=1\",\"Author\":\"Auth2\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}" + ); + + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::NonHardcoreWarning, false); + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, false); + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Leaderboards, true); + game.LoadGame(1U, "0123456789abcdeffedcba987654321"); + + // should get popup message indicating leaderboards not supported in softcore + game.mockFrameEventQueue.DoFrame(); // hardcore warning gets queued for the UI thread + Assert::IsFalse(game.mockDesktop.WasDialogShown()); + + const auto* pPopup = game.mockOverlayManager.GetMessage(2U); + Expects(pPopup != nullptr); + Assert::AreEqual(std::wstring(L"Playing in Softcore Mode"), pPopup->GetTitle()); + Assert::AreEqual(std::wstring(L"Leaderboard entries will not be submitted."), pPopup->GetDescription()); + } + + TEST_METHOD(TestLoadGameNonHardcoreWarningLeaderboardsOff) + { + GameContextHarness game; + game.MockLoadGameAPIs(1U, "0123456789abcdeffedcba987654321", "", + "{\"ID\":5,\"Title\":\"Ach1\",\"Description\":\"Desc1\",\"Flags\":3," + "\"Points\":5,\"MemAddr\":\"1=1\",\"Author\":\"Auth1\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}," + "{\"ID\":7,\"Title\":\"Ach2\",\"Description\":\"Desc2\",\"Flags\":3," + "\"Points\":10,\"MemAddr\":\"1=1\",\"Author\":\"Auth2\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}" + ); + + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::NonHardcoreWarning, false); + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, false); + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Leaderboards, false); + game.LoadGame(1U, "0123456789abcdeffedcba987654321"); + + // should get popup message indicating playing in softcore + game.mockFrameEventQueue.DoFrame(); // hardcore warning gets queued for the UI thread + Assert::IsFalse(game.mockDesktop.WasDialogShown()); + + const auto* pPopup = game.mockOverlayManager.GetMessage(2U); + Expects(pPopup != nullptr); + Assert::AreEqual(std::wstring(L"Playing in Softcore Mode"), pPopup->GetTitle()); + Assert::AreEqual(std::wstring(L""), pPopup->GetDescription()); + } + + TEST_METHOD(TestLoadGameNonHardcoreWarningCancel) + { + GameContextHarness game; + game.MockLoadGameAPIs(1U, "0123456789abcdeffedcba987654321", "", + "{\"ID\":5,\"Title\":\"Ach1\",\"Description\":\"Desc1\",\"Flags\":3," + "\"Points\":5,\"MemAddr\":\"1=1\",\"Author\":\"Auth1\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}," + "{\"ID\":7,\"Title\":\"Ach2\",\"Description\":\"Desc2\",\"Flags\":3," + "\"Points\":10,\"MemAddr\":\"1=1\",\"Author\":\"Auth2\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}" + ); + + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::NonHardcoreWarning, true); + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, false); + game.mockDesktop.ExpectWindow( + [](ra::ui::viewmodels::MessageBoxViewModel& vmMessageBox) { + Assert::AreEqual(std::wstring(L"Enable Hardcore mode?"), vmMessageBox.GetHeader()); + Assert::AreEqual(std::wstring(L"You are loading a game with achievements and do not currently have hardcore mode enabled."), vmMessageBox.GetMessage()); + Assert::AreEqual(ra::ui::viewmodels::MessageBoxViewModel::Icon::Warning, vmMessageBox.GetIcon()); + Assert::AreEqual(ra::ui::viewmodels::MessageBoxViewModel::Buttons::YesNo, vmMessageBox.GetButtons()); + return ra::ui::DialogResult::No; + }); + + game.LoadGame(1U, "0123456789abcdeffedcba987654321"); + + // should get confirmation dialog about hardcore and no popups + game.mockFrameEventQueue.DoFrame(); // hardcore warning gets queued for the UI thread + Assert::IsTrue(game.mockDesktop.WasDialogShown()); + Assert::IsNull(game.mockOverlayManager.GetMessage(2U)); + + // hardcore should remain disabled + Assert::IsFalse(game.mockConfiguration.IsFeatureEnabled(ra::services::Feature::Hardcore)); + } + + TEST_METHOD(TestLoadGameNonHardcoreWarningAccept) + { + GameContextHarness game; + game.MockLoadGameAPIs(1U, "0123456789abcdeffedcba987654321", "", + "{\"ID\":5,\"Title\":\"Ach1\",\"Description\":\"Desc1\",\"Flags\":3," + "\"Points\":5,\"MemAddr\":\"1=1\",\"Author\":\"Auth1\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}," + "{\"ID\":7,\"Title\":\"Ach2\",\"Description\":\"Desc2\",\"Flags\":3," + "\"Points\":10,\"MemAddr\":\"1=1\",\"Author\":\"Auth2\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}" + ); + + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::NonHardcoreWarning, true); + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, false); + game.mockDesktop.ExpectWindow( + [](ra::ui::viewmodels::MessageBoxViewModel& vmMessageBox) { + Assert::AreEqual(std::wstring(L"Enable Hardcore mode?"), vmMessageBox.GetHeader()); + Assert::AreEqual(std::wstring(L"You are loading a game with achievements and do not currently have hardcore mode enabled."), vmMessageBox.GetMessage()); + Assert::AreEqual(ra::ui::viewmodels::MessageBoxViewModel::Icon::Warning, vmMessageBox.GetIcon()); + Assert::AreEqual(ra::ui::viewmodels::MessageBoxViewModel::Buttons::YesNo, vmMessageBox.GetButtons()); + return ra::ui::DialogResult::Yes; + }); + + game.LoadGame(1U, "0123456789abcdeffedcba987654321"); + + // should get confirmation dialog about hardcore and no popups + game.mockFrameEventQueue.DoFrame(); // hardcore warning gets queued for the UI thread + Assert::IsTrue(game.mockDesktop.WasDialogShown()); + Assert::IsNull(game.mockOverlayManager.GetMessage(2U)); + + // hardcore should remain disabled + Assert::IsTrue(game.mockConfiguration.IsFeatureEnabled(ra::services::Feature::Hardcore)); + } + + TEST_METHOD(TestLoadGameNonHardcoreWarningNoCoreAchievements) + { + GameContextHarness game; + game.MockLoadGameAPIs(1U, "0123456789abcdeffedcba987654321", "", + "{\"ID\":5,\"Title\":\"Ach1\",\"Description\":\"Desc1\",\"Flags\":5," + "\"Points\":5,\"MemAddr\":\"1=1\",\"Author\":\"Auth1\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}," + "{\"ID\":7,\"Title\":\"Ach2\",\"Description\":\"Desc2\",\"Flags\":5," + "\"Points\":10,\"MemAddr\":\"1=1\",\"Author\":\"Auth2\",\"BadgeName\":\"12345\"," + "\"Created\":1234567890,\"Modified\":123459999}"); + + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::NonHardcoreWarning, true); + game.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, false); + + game.LoadGame(1U, "0123456789abcdeffedcba987654321"); + + // should only get softcore popup + game.mockFrameEventQueue.DoFrame(); // hardcore warning gets queued for the UI thread + Assert::IsFalse(game.mockDesktop.WasDialogShown()); + + const auto* pPopup = game.mockOverlayManager.GetMessage(2U); + Expects(pPopup != nullptr); + Assert::AreEqual(std::wstring(L"Playing in Softcore Mode"), pPopup->GetTitle()); + Assert::AreEqual(std::wstring(L""), pPopup->GetDescription()); + + // hardcore should remain disabled + Assert::IsFalse(game.mockConfiguration.IsFeatureEnabled(ra::services::Feature::Hardcore)); + } }; } // namespace tests diff --git a/tests/services/GameIdentifier_Tests.cpp b/tests/services/GameIdentifier_Tests.cpp index cf2d4b85..7641c262 100644 --- a/tests/services/GameIdentifier_Tests.cpp +++ b/tests/services/GameIdentifier_Tests.cpp @@ -369,165 +369,6 @@ TEST_CLASS(GameIdentifier_Tests) Assert::IsFalse(identifier.mockGameContext.WasLoaded()); } - TEST_METHOD(TestActivateGamePendingHardcore) - { - GameIdentifierHarness identifier; - identifier.MockResolveHashResponse(23U); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, true); - identifier.mockUserContext.Initialize("User", "ApiToken"); - - Assert::AreEqual(23U, identifier.IdentifyGame(&ROM.at(0), ROM.size())); - identifier.ActivateGame(23U); - - Assert::AreEqual(23U, identifier.mockGameContext.GameId()); - Assert::AreEqual(ROM_HASH, identifier.mockGameContext.GameHash()); - Assert::AreEqual(ra::data::context::GameContext::Mode::Normal, identifier.mockGameContext.GetMode()); - Assert::AreEqual(23U, identifier.mockSessionTracker.CurrentSessionGameId()); - Assert::IsNull(identifier.mockOverlayManager.GetMessage(1U)); - Assert::IsTrue(identifier.mockGameContext.WasLoaded()); - } - - TEST_METHOD(TestActivateGamePendingCompatibilityTest) - { - GameIdentifierHarness identifier; - identifier.MockCompatibilityTest(23U); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, true); - identifier.mockUserContext.Initialize("User", "ApiToken"); - - Assert::AreEqual(23U, identifier.IdentifyGame(&ROM.at(0), ROM.size())); - identifier.ActivateGame(23U); - - Assert::AreEqual(23U, identifier.mockGameContext.GameId()); - Assert::AreEqual(ROM_HASH, identifier.mockGameContext.GameHash()); - Assert::AreEqual(ra::data::context::GameContext::Mode::CompatibilityTest, identifier.mockGameContext.GetMode()); - Assert::AreEqual(23U, identifier.mockSessionTracker.CurrentSessionGameId()); - Assert::IsNull(identifier.mockOverlayManager.GetMessage(1U)); - Assert::IsTrue(identifier.mockGameContext.WasLoaded()); - } - - TEST_METHOD(TestActivateGamePendingNonHardcoreLeaderboards) - { - GameIdentifierHarness identifier; - identifier.MockResolveHashResponse(23U); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, false); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Leaderboards, true); - identifier.mockUserContext.Initialize("User", "ApiToken"); - - Assert::AreEqual(23U, identifier.IdentifyGame(&ROM.at(0), ROM.size())); - identifier.ActivateGame(23U); - - Assert::AreEqual(23U, identifier.mockGameContext.GameId()); - Assert::AreEqual(ROM_HASH, identifier.mockGameContext.GameHash()); - Assert::AreEqual(23U, identifier.mockSessionTracker.CurrentSessionGameId()); - const auto* pPopup = identifier.mockOverlayManager.GetMessage(1U); - Expects(pPopup != nullptr); - Assert::AreEqual(std::wstring(L"Playing in Softcore Mode"), pPopup->GetTitle()); - Assert::AreEqual(std::wstring(L"Leaderboard entries will not be submitted."), pPopup->GetDescription()); - } - - TEST_METHOD(TestActivateGamePendingNonHardcoreNoLeaderboards) - { - GameIdentifierHarness identifier; - identifier.MockResolveHashResponse(23U); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, false); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Leaderboards, false); - identifier.mockUserContext.Initialize("User", "ApiToken"); - - Assert::AreEqual(23U, identifier.IdentifyGame(&ROM.at(0), ROM.size())); - identifier.ActivateGame(23U); - - Assert::AreEqual(23U, identifier.mockGameContext.GameId()); - Assert::AreEqual(ROM_HASH, identifier.mockGameContext.GameHash()); - Assert::AreEqual(23U, identifier.mockSessionTracker.CurrentSessionGameId()); - const auto* pPopup = identifier.mockOverlayManager.GetMessage(1U); - Expects(pPopup != nullptr); - Assert::AreEqual(std::wstring(L"Playing in Softcore Mode"), pPopup->GetTitle()); - Assert::AreEqual(std::wstring(L""), pPopup->GetDescription()); - } - - TEST_METHOD(TestActivateGamePendingNonHardcoreWarningNoCoreAchievements) - { - GameIdentifierHarness identifier; - identifier.MockResolveHashResponse(23U); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, false); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::NonHardcoreWarning, true); - identifier.mockUserContext.Initialize("User", "ApiToken"); - - Assert::AreEqual(23U, identifier.IdentifyGame(&ROM.at(0), ROM.size())); - identifier.ActivateGame(23U); - - Assert::AreEqual(23U, identifier.mockGameContext.GameId()); - Assert::AreEqual(ROM_HASH, identifier.mockGameContext.GameHash()); - Assert::AreEqual(23U, identifier.mockSessionTracker.CurrentSessionGameId()); - const auto* pPopup = identifier.mockOverlayManager.GetMessage(1U); - Expects(pPopup != nullptr); - Assert::AreEqual(std::wstring(L"Playing in Softcore Mode"), pPopup->GetTitle()); - Assert::AreEqual(std::wstring(L""), pPopup->GetDescription()); - - Assert::IsFalse(identifier.mockDesktop.WasDialogShown()); - Assert::IsFalse(identifier.mockConfiguration.IsFeatureEnabled(ra::services::Feature::Hardcore)); - } - - TEST_METHOD(TestActivateGamePendingNonHardcoreWarningDecline) - { - GameIdentifierHarness identifier; - identifier.MockResolveHashResponse(23U); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, false); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::NonHardcoreWarning, true); - identifier.mockUserContext.Initialize("User", "ApiToken"); - identifier.mockGameContext.Assets().NewAchievement().SetCategory(ra::data::models::AssetCategory::Core); - identifier.mockDesktop.ExpectWindow([](ra::ui::viewmodels::MessageBoxViewModel & vmMessageBox) - { - Assert::AreEqual(std::wstring(L"Enable Hardcore mode?"), vmMessageBox.GetHeader()); - Assert::AreEqual(std::wstring(L"You are loading a game with achievements and do not currently have hardcore mode enabled."), vmMessageBox.GetMessage()); - Assert::AreEqual(ra::ui::viewmodels::MessageBoxViewModel::Icon::Warning, vmMessageBox.GetIcon()); - Assert::AreEqual(ra::ui::viewmodels::MessageBoxViewModel::Buttons::YesNo, vmMessageBox.GetButtons()); - return ra::ui::DialogResult::No; - }); - - Assert::AreEqual(23U, identifier.IdentifyGame(&ROM.at(0), ROM.size())); - identifier.ActivateGame(23U); - - Assert::AreEqual(23U, identifier.mockGameContext.GameId()); - Assert::AreEqual(ROM_HASH, identifier.mockGameContext.GameHash()); - Assert::AreEqual(23U, identifier.mockSessionTracker.CurrentSessionGameId()); - const auto* pPopup = identifier.mockOverlayManager.GetMessage(1U); - Assert::IsNull(pPopup); - - Assert::IsTrue(identifier.mockDesktop.WasDialogShown()); - Assert::IsFalse(identifier.mockConfiguration.IsFeatureEnabled(ra::services::Feature::Hardcore)); - } - - TEST_METHOD(TestActivateGamePendingNonHardcoreWarningAccept) - { - GameIdentifierHarness identifier; - identifier.MockResolveHashResponse(23U); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, false); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::NonHardcoreWarning, true); - identifier.mockUserContext.Initialize("User", "ApiToken"); - identifier.mockGameContext.Assets().NewAchievement().SetCategory(ra::data::models::AssetCategory::Core); - identifier.mockDesktop.ExpectWindow([](ra::ui::viewmodels::MessageBoxViewModel & vmMessageBox) - { - Assert::AreEqual(std::wstring(L"Enable Hardcore mode?"), vmMessageBox.GetHeader()); - Assert::AreEqual(std::wstring(L"You are loading a game with achievements and do not currently have hardcore mode enabled."), vmMessageBox.GetMessage()); - Assert::AreEqual(ra::ui::viewmodels::MessageBoxViewModel::Icon::Warning, vmMessageBox.GetIcon()); - Assert::AreEqual(ra::ui::viewmodels::MessageBoxViewModel::Buttons::YesNo, vmMessageBox.GetButtons()); - return ra::ui::DialogResult::Yes; - }); - - Assert::AreEqual(23U, identifier.IdentifyGame(&ROM.at(0), ROM.size())); - identifier.ActivateGame(23U); - - Assert::AreEqual(23U, identifier.mockGameContext.GameId()); - Assert::AreEqual(ROM_HASH, identifier.mockGameContext.GameHash()); - Assert::AreEqual(23U, identifier.mockSessionTracker.CurrentSessionGameId()); - const auto* pPopup = identifier.mockOverlayManager.GetMessage(1U); - Assert::IsNull(pPopup); - - Assert::IsTrue(identifier.mockDesktop.WasDialogShown()); - Assert::IsTrue(identifier.mockConfiguration.IsFeatureEnabled(ra::services::Feature::Hardcore)); - } - TEST_METHOD(TestActivateGameResetCompatibility) { GameIdentifierHarness identifier; @@ -800,28 +641,6 @@ TEST_CLASS(GameIdentifier_Tests) Assert::AreEqual(32U, identifier.IdentifyGame(&ROM.at(0), ROM.size())); Assert::IsFalse(identifier.mockDesktop.WasDialogShown()); } - - TEST_METHOD(TestActivateGamePendingOffline) - { - GameIdentifierHarness identifier; - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Hardcore, true); - identifier.mockConfiguration.SetFeatureEnabled(ra::services::Feature::Offline, true); - - const auto sFileContents = ra::StringPrintf("%s=%u\n", ROM_HASH, 32U); - identifier.mockLocalStorage.MockStoredData( - ra::services::StorageItemType::HashMapping, KNOWN_HASHES_KEY, sFileContents); - - Assert::AreEqual(32U, identifier.IdentifyGame(&ROM.at(0), ROM.size())); - identifier.ActivateGame(32U); - - Assert::AreEqual(32U, identifier.mockGameContext.GameId()); - Assert::AreEqual(ROM_HASH, identifier.mockGameContext.GameHash()); - Assert::AreEqual(ra::data::context::GameContext::Mode::Normal, identifier.mockGameContext.GetMode()); - Assert::AreEqual(32U, identifier.mockSessionTracker.CurrentSessionGameId()); - Assert::IsNull(identifier.mockOverlayManager.GetMessage(1U)); - Assert::IsTrue(identifier.mockGameContext.WasLoaded()); - } - }; } // namespace tests