0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00

Implement getting data from server, and showing release notes (!90)

Needs merged with: SPT-AKI/Server#249

Added
- Moved beta disclaimer text to the server
- Moved `PreventClientModsPatch` to AKI.Debugging as it makes more sense here after this PR. People who need to know, know why.
- Ability to show a release note summary to users in-game
- Cool debug message only shows build hash.

Instructions for testing
- Since I opted to store properties in the registry, its not as straight forward as deleting a file. (Thanks Drakia for the suggestion). So in order to test you need to open up regedit and navigate to `Computer\HKEY_CURRENT_USER\Software\Battlestate Games\EscapeFromTarkov` inside of that directory are 3 values stored in relation to this PR.

`SPT_AcceptedBETerms` - `REG_DWORD` that stores a value of 0 or 1
`SPT_ShownReleaseNotes` - `REG_DWORD` that stores a value of 0 or 1
`SPT_Version` - `REG_BINARY` that stores a binary converted string.

In order to reset after first run for a second test, you just delete all 3 entries.

Co-authored-by: Cj <161484149+CJ-SPT@users.noreply.github.com>
Reviewed-on: SPT-AKI/Modules#90
Co-authored-by: Cj <cj@noreply.dev.sp-tarkov.com>
Co-committed-by: Cj <cj@noreply.dev.sp-tarkov.com>
This commit is contained in:
Cj 2024-03-07 22:10:07 +00:00 committed by chomp
parent 454cea79f8
commit b87b569ece
4 changed files with 69 additions and 42 deletions

View File

@ -27,7 +27,6 @@ namespace Aki.Core
new UnityWebRequestPatch().Enable(); new UnityWebRequestPatch().Enable();
new WebSocketPatch().Enable(); new WebSocketPatch().Enable();
new TransportPrefixPatch().Enable(); new TransportPrefixPatch().Enable();
new PreventClientModsPatch().Enable();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -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; }
}
}

View File

@ -1,11 +1,14 @@
using System; using System;
using System.Runtime.CompilerServices;
using Aki.Common; using Aki.Common;
using Aki.Common.Http; using Aki.Common.Http;
using Aki.Common.Utils; using Aki.Common.Utils;
using Aki.Core.Patches;
using Aki.Custom.Models; using Aki.Custom.Models;
using Aki.Debugging.Patches; using Aki.Debugging.Patches;
using BepInEx; using BepInEx;
using Comfort.Common; using Comfort.Common;
using EFT;
using EFT.UI; using EFT.UI;
using UnityEngine; using UnityEngine;
@ -14,24 +17,12 @@ namespace Aki.Debugging
[BepInPlugin("com.spt-aki.debugging", "AKI.Debugging", AkiPluginInfo.PLUGIN_VERSION)] [BepInPlugin("com.spt-aki.debugging", "AKI.Debugging", AkiPluginInfo.PLUGIN_VERSION)]
public class AkiDebuggingPlugin : BaseUnityPlugin public class AkiDebuggingPlugin : BaseUnityPlugin
{ {
public static string sptVersion; public static string sptVersion;
public static string commitHash; public static string commitHash;
// Disable this in release builds. private ReleaseResponse release;
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 bool _isBetaDisclaimerOpen = false;
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() public void Awake()
{ {
@ -42,15 +33,7 @@ namespace Aki.Debugging
new EndRaidDebug().Enable(); new EndRaidDebug().Enable();
// new CoordinatesPatch().Enable(); // new CoordinatesPatch().Enable();
// new StaticLootDumper().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 // BTR debug command patches, can be disabled later
//new BTRDebugCommandPatch().Enable(); //new BTRDebugCommandPatch().Enable();
//new BTRDebugDataPatch().Enable(); //new BTRDebugDataPatch().Enable();
@ -68,20 +51,45 @@ namespace Aki.Debugging
public void Start() public void Start()
{ {
var json = RequestHandler.GetJson("/singleplayer/settings/version"); var versionJson = RequestHandler.GetJson("/singleplayer/settings/version");
sptVersion = Json.Deserialize<VersionResponse>(json).Version; sptVersion = Json.Deserialize<VersionResponse>(versionJson).Version;
var splitVersion = sptVersion.Split(' '); var splitVersion = sptVersion.Split(' ');
commitHash = splitVersion[4] ?? ""; commitHash = splitVersion[4] ?? "";
var releaseJson = RequestHandler.GetJson("/singleplayer/release");
release = Json.Deserialize<ReleaseResponse>(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() public void Update()
{ {
if (Singleton<PreloaderUI>.Instantiated && ShouldShowMessage() && !_IsMessageOpen && _isBleeding) if (Singleton<PreloaderUI>.Instantiated && ShouldShowBetaMessage())
{ {
Singleton<PreloaderUI>.Instance.ShowCriticalErrorScreen(sptVersion, _message, ErrorScreen.EButtonType.OkButton, _timeOutDelay, new Action(OnMessageAccepted), new Action(OnTimeOut)); Singleton<PreloaderUI>.Instance.ShowCriticalErrorScreen(sptVersion, release.betaDisclaimer, ErrorScreen.EButtonType.OkButton, release.betaDisclaimerTimeoutDelay, new Action(OnMessageAccepted), new Action(OnTimeOut));
_IsMessageOpen = true; _isBetaDisclaimerOpen = true;
}
if (Singleton<PreloaderUI>.Instantiated && ShouldShowReleaseNotes())
{
Singleton<PreloaderUI>.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() private void OnMessageAccepted()
{ {
Logger.LogInfo("User accepted the terms"); 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. // 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 // Stores the current build in the registry to check later
// Return true if changed, false if not // Return true if changed, false if not
private bool SetVersionPref() private void SetVersionPref()
{ {
if (GetVersionPref() == string.Empty || GetVersionPref() != sptVersion) if (GetVersionPref() == string.Empty || GetVersionPref() != sptVersion)
{ {
PlayerPrefs.SetString("SPT_Version", 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 // 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() private string GetVersionPref()
{ {
return PlayerPrefs.GetString("SPT_Version", string.Empty); return PlayerPrefs.GetString("SPT_Version", string.Empty);
} }
// Should we show the message, only show if first run // Should we show the message, only show if first run or if build has changed
// or if build has changed. private bool ShouldShowBetaMessage()
private bool ShouldShowMessage()
{ {
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;
} }
} }
} }

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using Aki.Reflection.Patching; using Aki.Reflection.Patching;
using BepInEx.Bootstrap; using BepInEx.Bootstrap;
using BepInEx.Logging;
using EFT; using EFT;
using HarmonyLib; using HarmonyLib;
@ -22,10 +23,10 @@ namespace Aki.Core.Patches
[PatchPrefix] [PatchPrefix]
private static void Prefix() private static void Prefix()
{ {
CheckForNonWhitelistedPlugins(); CheckForNonWhitelistedPlugins(Logger);
} }
private static void CheckForNonWhitelistedPlugins() private static void CheckForNonWhitelistedPlugins(ManualLogSource logger)
{ {
var whitelistedPlugins = new HashSet<string> var whitelistedPlugins = new HashSet<string>
{ {
@ -46,7 +47,7 @@ namespace Aki.Core.Patches
var disallowedPlugins = Chainloader.PluginInfos.Values.Select(pi => pi.Metadata.GUID).Except(whitelistedPlugins).ToArray(); var disallowedPlugins = Chainloader.PluginInfos.Values.Select(pi => pi.Metadata.GUID).Except(whitelistedPlugins).ToArray();
if (disallowedPlugins.Any()) 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!"); throw new Exception("Non-debug client mods have been detected. Mods are not allowed in BleedingEdge builds of SPT - please remove them before playing!");
} }
} }