0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/Aki.Custom/Patches/VersionLabelPatch.cs
chomp 1e238c426e 0.13.5.0 (!33)
Co-authored-by: Dev <dev@dev.sp-tarkov.com>
Co-authored-by: CWX <CWX@noreply.dev.sp-tarkov.com>
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-authored-by: RaiRaiTheRaichu <rairaitheraichu@noreply.dev.sp-tarkov.com>
Co-authored-by: CWX <cwx@noreply.dev.sp-tarkov.com>
Co-authored-by: Kaeno <e>
Reviewed-on: SPT-AKI/Modules#33
2023-10-10 10:58:33 +00:00

49 lines
1.6 KiB
C#

using Aki.Common.Http;
using Aki.Common.Utils;
using Aki.Reflection.Patching;
using Aki.Reflection.Utils;
using Aki.Custom.Models;
using EFT.UI;
using HarmonyLib;
using System.Linq;
using System.Reflection;
using Comfort.Common;
namespace Aki.Custom.Patches
{
public class VersionLabelPatch : ModulePatch
{
private static string _versionLabel;
protected override MethodBase GetTargetMethod()
{
try
{
return PatchConstants.EftTypes
.Single(x => x.GetField("Taxonomy", BindingFlags.Public | BindingFlags.Instance) != null)
.GetMethod("Create", BindingFlags.Public | BindingFlags.Static);
}
catch (System.Exception e)
{
Logger.LogInfo($"VersionLabelPatch failed {e.Message} {e.StackTrace} {e.InnerException.StackTrace}");
throw;
}
}
[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);
Traverse.Create(__result).Field("Major").SetValue(_versionLabel);
}
}
}