From 9b376b2975e200e27ffc70fcf42fef298eed9caf Mon Sep 17 00:00:00 2001 From: Jussi Tawaststjerna Date: Thu, 23 Nov 2023 11:10:28 +0200 Subject: [PATCH] AdvancedWardenObjective support --- MTFO.Ext.PartialData/Utils/InjectLibUtil.cs | 45 +++++++++++++++++++++ MTFO.Ext.PartialData/Utils/JSON.cs | 6 ++- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 MTFO.Ext.PartialData/Utils/InjectLibUtil.cs diff --git a/MTFO.Ext.PartialData/Utils/InjectLibUtil.cs b/MTFO.Ext.PartialData/Utils/InjectLibUtil.cs new file mode 100644 index 0000000..119ce6d --- /dev/null +++ b/MTFO.Ext.PartialData/Utils/InjectLibUtil.cs @@ -0,0 +1,45 @@ +using BepInEx.Unity.IL2CPP; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace MTFO.Ext.PartialData.Utils +{ + public static class InjectLibUtil + { + public const string PLUGIN_GUID = "GTFO.InjectLib"; + + public static JsonConverter InjectLibConnector { get; private set; } = null; + + public static bool IsLoaded { get; private set; } = false; + + static InjectLibUtil() + { + if (IL2CPPChainloader.Instance.Plugins.TryGetValue(PLUGIN_GUID, out var info)) + { + try + { + var ddAsm = info?.Instance?.GetType()?.Assembly ?? null; + + if (ddAsm is null) + throw new Exception("Assembly is Missing!"); + + var types = ddAsm.GetTypes(); + var converterType = types.First(t => t.Name == "InjectLibConnector"); + if (converterType is null) + throw new Exception("Unable to Find InjectLibConnector Class"); + + InjectLibConnector = (JsonConverter)Activator.CreateInstance(converterType); + IsLoaded = true; + } + catch (Exception e) + { + Logger.Error($"Exception thrown while reading data from GTFO.AWO: {e}"); + } + } + } + } +} diff --git a/MTFO.Ext.PartialData/Utils/JSON.cs b/MTFO.Ext.PartialData/Utils/JSON.cs index 69c3340..65e8c88 100644 --- a/MTFO.Ext.PartialData/Utils/JSON.cs +++ b/MTFO.Ext.PartialData/Utils/JSON.cs @@ -1,4 +1,5 @@ -using MTFO.Ext.PartialData.JsonConverters; +using InjectLib.JsonNETInjection.Supports; +using MTFO.Ext.PartialData.JsonConverters; using System; using System.Text.Json; using System.Text.Json.Serialization; @@ -28,10 +29,11 @@ private static JsonSerializerOptions CreateSetting() setting.Converters.Add(new ColorConverter()); setting.Converters.Add(new JsonStringEnumConverter()); setting.Converters.Add(new LocalizedTextConverter()); + setting.Converters.Add(new InjectLibConnector()); return setting; } - + public static T Deserialize(string json) { return JsonSerializer.Deserialize(json, _Setting);