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

Resolve an issue where Release builds of the server caused exceptions in the client (!94)

Some code cleanup and refactoring

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: SPT-AKI/Modules#94
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-03-11 08:44:50 +00:00 committed by chomp
parent 059334d0cd
commit 6a77131249
7 changed files with 143 additions and 121 deletions

View File

@ -17,6 +17,7 @@
<Reference Include="Comfort" HintPath="..\Shared\Managed\Comfort.dll" Private="False" />
<Reference Include="DissonanceVoip" HintPath="..\Shared\Managed\DissonanceVoip.dll" Private="False" />
<Reference Include="Sirenix.Serialization" HintPath="..\Shared\Managed\Sirenix.Serialization.dll" Private="False" />
<Reference Include="Unity.TextMeshPro" HintPath="..\Shared\Managed\Unity.TextMeshPro.dll" Private="False" />
<Reference Include="UnityEngine" HintPath="..\Shared\Managed\UnityEngine.dll" Private="False" />
<Reference Include="UnityEngine.AIModule" HintPath="..\Shared\Managed\UnityEngine.AIModule.dll" Private="False" />
<Reference Include="UnityEngine.AnimationModule" HintPath="..\Shared\Managed\UnityEngine.AnimationModule.dll" Private="False" />

View File

@ -4,6 +4,8 @@ using Aki.Custom.Airdrops.Patches;
using Aki.Custom.BTR.Patches;
using Aki.Custom.Patches;
using Aki.Custom.Utils;
using Aki.Reflection.Utils;
using Aki.SinglePlayer.Utils.MainMenu;
using BepInEx;
namespace Aki.Custom
@ -72,7 +74,7 @@ namespace Aki.Custom
new ResetTraderServicesPatch().Enable();
new CultistAmuletRemovalPatch().Enable();
HookObject.AddOrGetComponent<MenuNotificationManager>();
}
catch (Exception ex)
{

View File

@ -3,6 +3,7 @@ namespace Aki.Custom.Models
public struct ReleaseResponse
{
public bool isBeta { get; set; }
public bool isModdable { get; set; }
public string betaDisclaimer { get; set; }
public float betaDisclaimerTimeoutDelay { get; set; }
public string releaseSummary { get; set; }

View File

@ -1,14 +1,15 @@
using Aki.Reflection.Patching;
using EFT;
using EFT.UI;
using EFT;
using HarmonyLib;
using System.Reflection;
using Aki.SinglePlayer.Utils.MainMenu;
using TMPro;
using UnityEngine;
namespace Aki.Debugging.Patches
namespace Aki.SinglePlayer.Patches.MainMenu
{
public class DebugLogoPatch : ModulePatch
public class BetaLogoPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
@ -22,10 +23,8 @@ namespace Aki.Debugging.Patches
}
}
public class DebugLogoPatch2 : ModulePatch
public class BetaLogoPatch2 : ModulePatch
{
private static string sptVersion;
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ClientWatermark), nameof(ClientWatermark.method_0));
@ -34,18 +33,18 @@ namespace Aki.Debugging.Patches
[PatchPostfix]
private static void PatchPostfix(ref TextMeshProUGUI ____label, Profile ___profile_0)
{
____label.text = $"{AkiDebuggingPlugin.commitHash}";
____label.text = $"{MenuNotificationManager.commitHash}";
}
}
public class DebugLogoPatch3 : ModulePatch
public class BetaLogoPatch3 : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ClientWatermark), nameof(ClientWatermark.smethod_0));
}
// Prefix so the logic isnt being duplicated.
// Prefix so the logic isn't being duplicated.
[PatchPrefix]
private static bool PatchPrefix(int screenHeight, int screenWidth, int rectHeight, int rectWidth, ref Vector2 __result)
{
@ -57,6 +56,8 @@ namespace Aki.Debugging.Patches
int newY = random.Next(-maxY, maxY);
__result = new Vector2(newX, newY);
// Skip original
return false;
}
}

View File

@ -8,7 +8,7 @@ using BepInEx.Logging;
using EFT;
using HarmonyLib;
namespace Aki.Core.Patches
namespace Aki.SinglePlayer.Patches.MainMenu
{
/// <summary>
/// Prevents loading of non-whitelisted client mods to minimize the amount of false issue reports being made during the public BE phase

View File

@ -0,0 +1,124 @@
using Aki.Common.Http;
using Aki.Common.Utils;
using Aki.Custom.Models;
using Aki.SinglePlayer.Patches.MainMenu;
using BepInEx.Logging;
using Comfort.Common;
using EFT.UI;
using System;
using System.Linq;
using UnityEngine;
namespace Aki.SinglePlayer.Utils.MainMenu
{
public class MenuNotificationManager : MonoBehaviour
{
public static string sptVersion;
public static string commitHash;
private ReleaseResponse release;
private bool _isBetaDisclaimerOpen = false;
private ManualLogSource Logger;
public void Start()
{
Logger = BepInEx.Logging.Logger.CreateLogSource(nameof(MenuNotificationManager));
var versionJson = RequestHandler.GetJson("/singleplayer/settings/version");
sptVersion = Json.Deserialize<VersionResponse>(versionJson).Version;
commitHash = sptVersion?.Trim()?.Split(' ')?.Last() ?? "";
var releaseJson = RequestHandler.GetJson("/singleplayer/release");
release = Json.Deserialize<ReleaseResponse>(releaseJson);
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 BetaLogoPatch().Enable();
new BetaLogoPatch2().Enable();
new BetaLogoPatch3().Enable();
}
// 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");
}
}
public void Update()
{
if (sptVersion == null)
{
return;
}
if (Singleton<PreloaderUI>.Instantiated && ShouldShowBetaMessage())
{
Singleton<PreloaderUI>.Instance.ShowCriticalErrorScreen(sptVersion, release.betaDisclaimer, ErrorScreen.EButtonType.OkButton, release.betaDisclaimerTimeoutDelay, new Action(OnMessageAccepted), new Action(OnTimeOut));
_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);
}
}
// User accepted the terms, allow to continue.
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.
private void OnTimeOut()
{
Application.Quit();
}
// Stores the current build in the registry to check later
// Return true if changed, false if not
private void SetVersionPref()
{
if (GetVersionPref() == string.Empty || GetVersionPref() != sptVersion)
{
PlayerPrefs.SetString("SPT_Version", sptVersion);
// 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
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 ShouldShowBetaMessage()
{
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

@ -1,29 +1,13 @@
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;
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;
private ReleaseResponse release;
private bool _isBetaDisclaimerOpen = false;
public void Awake()
{
Logger.LogInfo("Loading: Aki.Debugging");
@ -48,96 +32,5 @@ namespace Aki.Debugging
Logger.LogInfo("Completed: Aki.Debugging");
}
public void Start()
{
var versionJson = RequestHandler.GetJson("/singleplayer/settings/version");
sptVersion = Json.Deserialize<VersionResponse>(versionJson).Version;
var splitVersion = sptVersion.Split(' ');
commitHash = splitVersion[4] ?? "";
var releaseJson = RequestHandler.GetJson("/singleplayer/release");
release = Json.Deserialize<ReleaseResponse>(releaseJson);
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<PreloaderUI>.Instantiated && ShouldShowBetaMessage())
{
Singleton<PreloaderUI>.Instance.ShowCriticalErrorScreen(sptVersion, release.betaDisclaimer, ErrorScreen.EButtonType.OkButton, release.betaDisclaimerTimeoutDelay, new Action(OnMessageAccepted), new Action(OnTimeOut));
_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);
}
}
// User accepted the terms, allow to continue.
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.
private void OnTimeOut()
{
Application.Quit();
}
// Stores the current build in the registry to check later
// Return true if changed, false if not
private void SetVersionPref()
{
if (GetVersionPref() == string.Empty || GetVersionPref() != sptVersion)
{
PlayerPrefs.SetString("SPT_Version", sptVersion);
// 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
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 ShouldShowBetaMessage()
{
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;
}
}
}