0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/SPT.Custom/Patches/VersionLabelPatch.cs
2024-05-21 19:10:17 +01:00

41 lines
1.5 KiB
C#

using SPT.Common.Http;
using SPT.Common.Utils;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using SPT.Custom.Models;
using EFT.UI;
using HarmonyLib;
using System.Reflection;
using Comfort.Common;
namespace SPT.Custom.Patches
{
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)
.GetMethod("Create", BindingFlags.Public | BindingFlags.Static);
}
[PatchPostfix]
internal static void PatchPostfix(object __result)
{
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}");
}
}
}