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;
|
2023-10-10 10:58:33 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2024-01-13 22:08:29 +00:00
|
|
|
|
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]
|
|
|
|
|
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}");
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-10 10:58:33 +00:00
|
|
|
|
Traverse.Create(Singleton<PreloaderUI>.Instance).Field("_alphaVersionLabel").Property("LocalizationKey").SetValue("{0}");
|
|
|
|
|
Traverse.Create(Singleton<PreloaderUI>.Instance).Field("string_2").SetValue(_versionLabel);
|
2024-01-04 10:11:47 +00:00
|
|
|
|
var major = Traverse.Create(__result).Field("Major");
|
|
|
|
|
var existingValue = major.GetValue();
|
2024-01-13 22:08:29 +00:00
|
|
|
|
major.SetValue($"{existingValue} {_versionLabel}");
|
2023-03-03 18:52:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|