From 9f8767bd0d9002347c1000af33932c42b93482f6 Mon Sep 17 00:00:00 2001 From: Cj Date: Wed, 6 Mar 2024 22:58:57 +0000 Subject: [PATCH] Bleeding edge message window (!89) This PR introduces a message to be shown to users when first running bleeding edge, or if the version has changed since last run. the SPT version string is stored in the registry and checked against on each subsequent run. In the future this can be expanded to displaying the patch notes if we wish, but for now its just a generic message. For questions, ping me on discord. Co-authored-by: Cj <161484149+CJ-SPT@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/89 Co-authored-by: Cj Co-committed-by: Cj --- project/Aki.Debugging/AkiDebuggingPlugin.cs | 93 ++++++++++++++++++- .../Aki.Debugging/Patches/DebugLogoPatch.cs | 13 +-- 2 files changed, 91 insertions(+), 15 deletions(-) diff --git a/project/Aki.Debugging/AkiDebuggingPlugin.cs b/project/Aki.Debugging/AkiDebuggingPlugin.cs index 2e98638..0834233 100644 --- a/project/Aki.Debugging/AkiDebuggingPlugin.cs +++ b/project/Aki.Debugging/AkiDebuggingPlugin.cs @@ -1,13 +1,37 @@ using System; using Aki.Common; +using Aki.Common.Http; +using Aki.Common.Utils; +using Aki.Custom.Models; using Aki.Debugging.Patches; using BepInEx; +using Comfort.Common; +using EFT.UI; +using UnityEngine; namespace Aki.Debugging { [BepInPlugin("com.spt-aki.debugging", "AKI.Debugging", AkiPluginInfo.PLUGIN_VERSION)] public class AkiDebuggingPlugin : BaseUnityPlugin { + + public static string sptVersion; + + // Disable this in release builds. + private bool _isBleeding = true; + private readonly string _message = "By pressing OK you agree that no support is offered and that this is for bug testing only. NOT actual gameplay." + + " Mods are disabled. New profiles may be required frequently. Report all bugs in the reports channel in discord, or on the issues page on the website." + + " If you don't press OK by the time specified, the game will close."; + + // How long before the message times out and closes the game. + private const float _timeOutDelay = 30f; + + // Is this a new build? + private bool _hasVersionChangedSinceLastRun = false; + + // Is the message open, avoids reinstantiating the error screen over and over again. + private bool _IsMessageOpen = false; + public void Awake() { Logger.LogInfo("Loading: Aki.Debugging"); @@ -17,10 +41,15 @@ namespace Aki.Debugging new EndRaidDebug().Enable(); // new CoordinatesPatch().Enable(); // new StaticLootDumper().Enable(); - new DebugLogoPatch().Enable(); - new DebugLogoPatch2().Enable(); - new DebugLogoPatch3().Enable(); - + + // Enable the watermark if this is a bleeding edge build. + if (_isBleeding) + { + new DebugLogoPatch().Enable(); + new DebugLogoPatch2().Enable(); + new DebugLogoPatch3().Enable(); + } + // BTR debug command patches, can be disabled later //new BTRDebugCommandPatch().Enable(); //new BTRDebugDataPatch().Enable(); @@ -35,5 +64,61 @@ namespace Aki.Debugging Logger.LogInfo("Completed: Aki.Debugging"); } + + public void Start() + { + var json = RequestHandler.GetJson("/singleplayer/settings/version"); + sptVersion = Json.Deserialize(json).Version; + + _hasVersionChangedSinceLastRun = SetVersionPref(); + } + + public void Update() + { + if (Singleton.Instantiated && ShouldShowMessage() && !_IsMessageOpen && _isBleeding) + { + Singleton.Instance.ShowCriticalErrorScreen(sptVersion, _message, ErrorScreen.EButtonType.OkButton, _timeOutDelay, new Action(OnMessageAccepted), new Action(OnTimeOut)); + _IsMessageOpen = true; + } + } + + // User accepted the terms, allow to continue. + private void OnMessageAccepted() + { + Logger.LogInfo("User accepted the terms"); + } + + // If the user doesnt accept the message "Ok" then the game will close. + private void OnTimeOut() + { + Application.Quit(); + } + + // Stores the current build in the registry to check later + // Return true if changed, false if not + private bool SetVersionPref() + { + if (GetVersionPref() == string.Empty || GetVersionPref() != sptVersion) + { + PlayerPrefs.SetString("SPT_Version", sptVersion); + return true; + } + + return false; + } + + // Retrieves the current build from the registry to check against the current build + // If this is the first run and no entry exists, returns an empty string + private string GetVersionPref() + { + return PlayerPrefs.GetString("SPT_Version", string.Empty); + } + + // Should we show the message, only show if first run + // or if build has changed. + private bool ShouldShowMessage() + { + return GetVersionPref() != sptVersion || _hasVersionChangedSinceLastRun ? true : false; + } } } diff --git a/project/Aki.Debugging/Patches/DebugLogoPatch.cs b/project/Aki.Debugging/Patches/DebugLogoPatch.cs index c7c522b..621feb0 100644 --- a/project/Aki.Debugging/Patches/DebugLogoPatch.cs +++ b/project/Aki.Debugging/Patches/DebugLogoPatch.cs @@ -1,7 +1,4 @@ -using Aki.Common.Http; -using Aki.Common.Utils; -using Aki.Custom.Models; -using Aki.Reflection.Patching; +using Aki.Reflection.Patching; using EFT; using EFT.UI; using HarmonyLib; @@ -37,13 +34,7 @@ namespace Aki.Debugging.Patches [PatchPostfix] private static void PatchPostfix(ref TextMeshProUGUI ____label, Profile ___profile_0) { - if (sptVersion is null) - { - var json = RequestHandler.GetJson("/singleplayer/settings/version"); - sptVersion = Json.Deserialize(json).Version; - } - - ____label.text = $"{sptVersion}"; + ____label.text = $"{AkiDebuggingPlugin.sptVersion}"; } }