From 73db17ea78c084bff94745036d40fd35dd0cc4ba Mon Sep 17 00:00:00 2001 From: Cj Date: Mon, 11 Mar 2024 22:02:45 +0000 Subject: [PATCH] Show mods loaded in cool debug message (!95) needs merged with: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/258 Shows if mods are loaded in the cool debug message, will show if either server mods or client mods are present. Co-authored-by: Cj <161484149+CJ-SPT@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/95 Co-authored-by: Cj Co-committed-by: Cj --- project/Aki.Custom/Models/ReleaseResponse.cs | 13 +++- .../Patches/PreventClientModsPatch.cs | 24 ++----- .../Utils/MenuNotificationManager.cs | 63 ++++++++++++++++--- 3 files changed, 68 insertions(+), 32 deletions(-) diff --git a/project/Aki.Custom/Models/ReleaseResponse.cs b/project/Aki.Custom/Models/ReleaseResponse.cs index b60274d..9eb319c 100644 --- a/project/Aki.Custom/Models/ReleaseResponse.cs +++ b/project/Aki.Custom/Models/ReleaseResponse.cs @@ -4,9 +4,16 @@ namespace Aki.Custom.Models { public bool isBeta { get; set; } public bool isModdable { get; set; } - public string betaDisclaimer { get; set; } + public bool isModded { get; set; } public float betaDisclaimerTimeoutDelay { get; set; } - public string releaseSummary { get; set; } - + public string betaDisclaimerText { get; set; } + public string betaDisclaimerAcceptText { get; set; } + public string serverModsLoadedText { get; set; } + public string serverModsLoadedDebugText { get; set; } + public string clientModsLoadedText { get; set; } + public string clientModsLoadedDebugText { get; set; } + public string illegalPluginsLoadedText { get; set; } + public string illegalPluginsExceptionText { get; set; } + public string releaseSummaryText { get; set; } } } \ No newline at end of file diff --git a/project/Aki.Custom/Patches/PreventClientModsPatch.cs b/project/Aki.Custom/Patches/PreventClientModsPatch.cs index 983e941..8a3d04e 100644 --- a/project/Aki.Custom/Patches/PreventClientModsPatch.cs +++ b/project/Aki.Custom/Patches/PreventClientModsPatch.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; using Aki.Reflection.Patching; +using Aki.SinglePlayer.Utils.MainMenu; using BepInEx.Bootstrap; using BepInEx.Logging; using EFT; @@ -28,27 +29,10 @@ namespace Aki.SinglePlayer.Patches.MainMenu private static void CheckForNonWhitelistedPlugins(ManualLogSource logger) { - var whitelistedPlugins = new HashSet + if (MenuNotificationManager.disallowedPlugins.Any()) { - "com.spt-aki.core", - "com.spt-aki.custom", - "com.spt-aki.debugging", - "com.spt-aki.singleplayer", - "com.bepis.bepinex.configurationmanager", - "com.terkoiz.freecam", - "com.sinai.unityexplorer", - "com.cwx.debuggingtool-dxyz", - "com.cwx.debuggingtool", - "xyz.drakia.botdebug", - "com.kobrakon.camunsnap", - "RuntimeUnityEditor" - }; - - var disallowedPlugins = Chainloader.PluginInfos.Values.Select(pi => pi.Metadata.GUID).Except(whitelistedPlugins).ToArray(); - if (disallowedPlugins.Any()) - { - 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!"); + logger.LogError($"{MenuNotificationManager.release.illegalPluginsLoadedText}\n{string.Join("\n", MenuNotificationManager.disallowedPlugins)}"); + throw new Exception(MenuNotificationManager.release.illegalPluginsExceptionText); } } } diff --git a/project/Aki.Custom/Utils/MenuNotificationManager.cs b/project/Aki.Custom/Utils/MenuNotificationManager.cs index 9912490..573738b 100644 --- a/project/Aki.Custom/Utils/MenuNotificationManager.cs +++ b/project/Aki.Custom/Utils/MenuNotificationManager.cs @@ -2,10 +2,12 @@ using Aki.Common.Utils; using Aki.Custom.Models; using Aki.SinglePlayer.Patches.MainMenu; +using BepInEx.Bootstrap; using BepInEx.Logging; using Comfort.Common; using EFT.UI; using System; +using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -15,10 +17,25 @@ namespace Aki.SinglePlayer.Utils.MainMenu { public static string sptVersion; public static string commitHash; - private ReleaseResponse release; - + internal static HashSet whitelistedPlugins = new HashSet + { + "com.spt-aki.core", + "com.spt-aki.custom", + "com.spt-aki.debugging", + "com.spt-aki.singleplayer", + "com.bepis.bepinex.configurationmanager", + "com.terkoiz.freecam", + "com.sinai.unityexplorer", + "com.cwx.debuggingtool-dxyz", + "com.cwx.debuggingtool", + "xyz.drakia.botdebug", + "com.kobrakon.camunsnap", + "RuntimeUnityEditor" + }; + + public static string[] disallowedPlugins; + internal static ReleaseResponse release; private bool _isBetaDisclaimerOpen = false; - private ManualLogSource Logger; public void Start() @@ -43,15 +60,31 @@ namespace Aki.SinglePlayer.Utils.MainMenu new BetaLogoPatch3().Enable(); } + disallowedPlugins = Chainloader.PluginInfos.Values + .Select(pi => pi.Metadata.GUID).Except(whitelistedPlugins).ToArray(); + // Prevent client mods if the server is built with mods disabled if (!release.isModdable) { new PreventClientModsPatch().Enable(); } - + if (release.isBeta && PlayerPrefs.GetInt("SPT_AcceptedBETerms") == 1) { - Logger.LogInfo("User accepted the beta disclaimer"); + Logger.LogInfo(release.betaDisclaimerAcceptText); + ServerLog.Info("Aki.Custom", release.betaDisclaimerAcceptText); + } + + if (release.isModded && release.isBeta && release.isModdable) + { + commitHash += $"\n {release.serverModsLoadedDebugText}"; + ServerLog.Warn("Aki.Custom", release.serverModsLoadedText); + } + + if (disallowedPlugins.Any() && release.isBeta && release.isModdable) + { + commitHash += $"\n {release.clientModsLoadedDebugText}"; + ServerLog.Warn("Aki.Custom", $"{release.clientModsLoadedText}\n{string.Join("\n", disallowedPlugins)}"); } } public void Update() @@ -61,15 +94,27 @@ namespace Aki.SinglePlayer.Utils.MainMenu return; } + ShowBetaMessage(); + ShowReleaseNotes(); + } + + // Show the beta message + // if mods are enabled show that mods are loaded in the message. + private void ShowBetaMessage() + { if (Singleton.Instantiated && ShouldShowBetaMessage()) { - Singleton.Instance.ShowCriticalErrorScreen(sptVersion, release.betaDisclaimer, ErrorScreen.EButtonType.OkButton, release.betaDisclaimerTimeoutDelay, new Action(OnMessageAccepted), new Action(OnTimeOut)); + Singleton.Instance.ShowCriticalErrorScreen(sptVersion, release.betaDisclaimerText, ErrorScreen.EButtonType.OkButton, release.betaDisclaimerTimeoutDelay, new Action(OnMessageAccepted), new Action(OnTimeOut)); _isBetaDisclaimerOpen = true; } + } + // Show the release notes. + private void ShowReleaseNotes() + { if (Singleton.Instantiated && ShouldShowReleaseNotes()) { - Singleton.Instance.ShowCriticalErrorScreen(sptVersion, release.releaseSummary, ErrorScreen.EButtonType.OkButton, 36000, null, null); + Singleton.Instance.ShowCriticalErrorScreen(sptVersion, release.releaseSummaryText, ErrorScreen.EButtonType.OkButton, 36000, null, null); PlayerPrefs.SetInt("SPT_ShownReleaseNotes", 1); } } @@ -77,7 +122,7 @@ namespace Aki.SinglePlayer.Utils.MainMenu // User accepted the terms, allow to continue. private void OnMessageAccepted() { - Logger.LogInfo("User accepted the terms"); + Logger.LogInfo(release.betaDisclaimerAcceptText); PlayerPrefs.SetInt("SPT_AcceptedBETerms", 1); _isBetaDisclaimerOpen = false; } @@ -118,7 +163,7 @@ namespace Aki.SinglePlayer.Utils.MainMenu // 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; + return PlayerPrefs.GetInt("SPT_ShownReleaseNotes") == 0 && !_isBetaDisclaimerOpen && release.releaseSummaryText != string.Empty ? true : false; } } }