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

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: SPT-AKI/Modules#89
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-06 22:58:57 +00:00 committed by chomp
parent 1e68f3cd6f
commit 9f8767bd0d
2 changed files with 91 additions and 15 deletions

View File

@ -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<VersionResponse>(json).Version;
_hasVersionChangedSinceLastRun = SetVersionPref();
}
public void Update()
{
if (Singleton<PreloaderUI>.Instantiated && ShouldShowMessage() && !_IsMessageOpen && _isBleeding)
{
Singleton<PreloaderUI>.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;
}
}
}

View File

@ -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<VersionResponse>(json).Version;
}
____label.text = $"{sptVersion}";
____label.text = $"{AkiDebuggingPlugin.sptVersion}";
}
}