diff --git a/project/Aki.Core/AkiCorePlugin.cs b/project/Aki.Core/AkiCorePlugin.cs index 4d91738..5c020f3 100644 --- a/project/Aki.Core/AkiCorePlugin.cs +++ b/project/Aki.Core/AkiCorePlugin.cs @@ -27,7 +27,6 @@ namespace Aki.Core new UnityWebRequestPatch().Enable(); new WebSocketPatch().Enable(); new TransportPrefixPatch().Enable(); - new PreventClientModsPatch().Enable(); } catch (Exception ex) { diff --git a/project/Aki.Custom/Models/ReleaseResponse.cs b/project/Aki.Custom/Models/ReleaseResponse.cs new file mode 100644 index 0000000..17fe164 --- /dev/null +++ b/project/Aki.Custom/Models/ReleaseResponse.cs @@ -0,0 +1,11 @@ +namespace Aki.Custom.Models +{ + public struct ReleaseResponse + { + public bool isBeta { get; set; } + public string betaDisclaimer { get; set; } + public float betaDisclaimerTimeoutDelay { get; set; } + public string releaseSummary { get; set; } + + } +} \ No newline at end of file diff --git a/project/Aki.Debugging/AkiDebuggingPlugin.cs b/project/Aki.Debugging/AkiDebuggingPlugin.cs index 619b815..9a5bc8f 100644 --- a/project/Aki.Debugging/AkiDebuggingPlugin.cs +++ b/project/Aki.Debugging/AkiDebuggingPlugin.cs @@ -1,11 +1,14 @@ using System; +using System.Runtime.CompilerServices; using Aki.Common; using Aki.Common.Http; using Aki.Common.Utils; +using Aki.Core.Patches; using Aki.Custom.Models; using Aki.Debugging.Patches; using BepInEx; using Comfort.Common; +using EFT; using EFT.UI; using UnityEngine; @@ -14,24 +17,12 @@ namespace Aki.Debugging [BepInPlugin("com.spt-aki.debugging", "AKI.Debugging", AkiPluginInfo.PLUGIN_VERSION)] public class AkiDebuggingPlugin : BaseUnityPlugin { - public static string sptVersion; public static string commitHash; - // 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."; + private ReleaseResponse release; - // 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; + private bool _isBetaDisclaimerOpen = false; public void Awake() { @@ -42,15 +33,7 @@ namespace Aki.Debugging new EndRaidDebug().Enable(); // new CoordinatesPatch().Enable(); // new StaticLootDumper().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(); @@ -68,20 +51,45 @@ namespace Aki.Debugging public void Start() { - var json = RequestHandler.GetJson("/singleplayer/settings/version"); - sptVersion = Json.Deserialize(json).Version; + var versionJson = RequestHandler.GetJson("/singleplayer/settings/version"); + sptVersion = Json.Deserialize(versionJson).Version; + var splitVersion = sptVersion.Split(' '); commitHash = splitVersion[4] ?? ""; + + var releaseJson = RequestHandler.GetJson("/singleplayer/release"); + release = Json.Deserialize(releaseJson); - _hasVersionChangedSinceLastRun = SetVersionPref(); + SetVersionPref(); + + // Enable the watermark if this is a bleeding edge build. + // Enabled in start to allow time for the request containing the bool to process. + if (release.isBeta) + { + new DebugLogoPatch().Enable(); + new DebugLogoPatch2().Enable(); + new DebugLogoPatch3().Enable(); + new PreventClientModsPatch().Enable(); + } + + if (release.isBeta && PlayerPrefs.GetInt("SPT_AcceptedBETerms") == 1) + { + Logger.LogInfo("User accepted the beta disclaimer"); + } } public void Update() { - if (Singleton.Instantiated && ShouldShowMessage() && !_IsMessageOpen && _isBleeding) + if (Singleton.Instantiated && ShouldShowBetaMessage()) { - Singleton.Instance.ShowCriticalErrorScreen(sptVersion, _message, ErrorScreen.EButtonType.OkButton, _timeOutDelay, new Action(OnMessageAccepted), new Action(OnTimeOut)); - _IsMessageOpen = true; + Singleton.Instance.ShowCriticalErrorScreen(sptVersion, release.betaDisclaimer, ErrorScreen.EButtonType.OkButton, release.betaDisclaimerTimeoutDelay, new Action(OnMessageAccepted), new Action(OnTimeOut)); + _isBetaDisclaimerOpen = true; + } + + if (Singleton.Instantiated && ShouldShowReleaseNotes()) + { + Singleton.Instance.ShowCriticalErrorScreen(sptVersion, release.releaseSummary, ErrorScreen.EButtonType.OkButton, 36000, null, null); + PlayerPrefs.SetInt("SPT_ShownReleaseNotes", 1); } } @@ -89,6 +97,8 @@ namespace Aki.Debugging private void OnMessageAccepted() { Logger.LogInfo("User accepted the terms"); + PlayerPrefs.SetInt("SPT_AcceptedBETerms", 1); + _isBetaDisclaimerOpen = false; } // If the user doesnt accept the message "Ok" then the game will close. @@ -99,29 +109,35 @@ namespace Aki.Debugging // Stores the current build in the registry to check later // Return true if changed, false if not - private bool SetVersionPref() + private void SetVersionPref() { if (GetVersionPref() == string.Empty || GetVersionPref() != sptVersion) { PlayerPrefs.SetString("SPT_Version", sptVersion); - return true; - } - return false; + // 0 val used to indicate false, 1 val used to indicate true + PlayerPrefs.SetInt("SPT_AcceptedBETerms", 0); + PlayerPrefs.SetInt("SPT_ShownReleaseNotes", 0); + } } // 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 + // 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() + // Should we show the message, only show if first run or if build has changed + private bool ShouldShowBetaMessage() { - return GetVersionPref() != sptVersion || _hasVersionChangedSinceLastRun ? true : false; + return PlayerPrefs.GetInt("SPT_AcceptedBETerms") == 0 && release.isBeta && !_isBetaDisclaimerOpen ? true : false; + } + + // Should we show the release notes, only show on first run or if build has changed + private bool ShouldShowReleaseNotes() + { + return PlayerPrefs.GetInt("SPT_ShownReleaseNotes") == 0 && !_isBetaDisclaimerOpen && release.releaseSummary != string.Empty ? true : false; } } } diff --git a/project/Aki.Core/Patches/PreventClientModsPatch.cs b/project/Aki.Debugging/Patches/PreventClientModsPatch.cs similarity index 82% rename from project/Aki.Core/Patches/PreventClientModsPatch.cs rename to project/Aki.Debugging/Patches/PreventClientModsPatch.cs index ad71dd5..8f5cb1f 100644 --- a/project/Aki.Core/Patches/PreventClientModsPatch.cs +++ b/project/Aki.Debugging/Patches/PreventClientModsPatch.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using Aki.Reflection.Patching; using BepInEx.Bootstrap; +using BepInEx.Logging; using EFT; using HarmonyLib; @@ -22,10 +23,10 @@ namespace Aki.Core.Patches [PatchPrefix] private static void Prefix() { - CheckForNonWhitelistedPlugins(); + CheckForNonWhitelistedPlugins(Logger); } - private static void CheckForNonWhitelistedPlugins() + private static void CheckForNonWhitelistedPlugins(ManualLogSource logger) { var whitelistedPlugins = new HashSet { @@ -46,7 +47,7 @@ namespace Aki.Core.Patches var disallowedPlugins = Chainloader.PluginInfos.Values.Select(pi => pi.Metadata.GUID).Except(whitelistedPlugins).ToArray(); if (disallowedPlugins.Any()) { - AkiCorePlugin._logger.LogError($"One or more non-whitelisted plugins were detected. Mods are not allowed in BleedingEdge builds of SPT. Illegal plugins:\n{string.Join("\n", disallowedPlugins)}"); + logger.LogError($"One or more non-whitelisted plugins were detected. Mods are not allowed in BleedingEdge builds of SPT. Illegal plugins:\n{string.Join("\n", disallowedPlugins)}"); throw new Exception("Non-debug client mods have been detected. Mods are not allowed in BleedingEdge builds of SPT - please remove them before playing!"); } }