0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:10:44 -05:00
modules/project/SPT.Custom/Patches/VersionLabelPatch.cs

41 lines
1.5 KiB
C#
Raw Normal View History

2024-05-21 19:10:17 +01:00
using SPT.Common.Http;
using SPT.Common.Utils;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using SPT.Custom.Models;
2023-03-03 18:52:31 +00:00
using EFT.UI;
using HarmonyLib;
using System.Reflection;
using Comfort.Common;
2023-03-03 18:52:31 +00:00
2024-05-21 19:10:17 +01:00
namespace SPT.Custom.Patches
2023-03-03 18:52:31 +00:00
{
public class VersionLabelPatch : ModulePatch
{
private static string _versionLabel;
protected override MethodBase GetTargetMethod()
{
return PatchConstants.EftTypes
.SingleCustom(x => x.GetField("Taxonomy", BindingFlags.Public | BindingFlags.Instance) != null)
2023-03-03 18:52:31 +00:00
.GetMethod("Create", BindingFlags.Public | BindingFlags.Static);
}
[PatchPostfix]
public static void PatchPostfix(object __result)
2023-03-03 18:52:31 +00:00
{
if (string.IsNullOrEmpty(_versionLabel))
{
var json = RequestHandler.GetJson("/singleplayer/settings/version");
_versionLabel = Json.Deserialize<VersionResponse>(json).Version;
Logger.LogInfo($"Server version: {_versionLabel}");
}
Traverse.Create(Singleton<PreloaderUI>.Instance).Field("_alphaVersionLabel").Property("LocalizationKey").SetValue("{0}");
Traverse.Create(Singleton<PreloaderUI>.Instance).Field("string_2").SetValue(_versionLabel);
var major = Traverse.Create(__result).Field("Major");
var existingValue = major.GetValue();
major.SetValue($"{existingValue} {_versionLabel}");
2023-03-03 18:52:31 +00:00
}
}
}