Decompiled source of XenologistUIFix v1.0.0

plugins/XenologistUIFix.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("XenologistUIFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("XenologistUIFix")]
[assembly: AssemblyTitle("XenologistUIFix")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace XenologistUIFix
{
	[HarmonyPatch]
	internal static class HUDTrackerPatch
	{
		private static FieldInfo hudField;

		private static FieldInfo behaviourField;

		private static FieldInfo panelField;

		private static FieldInfo targetBodyField;

		private static PropertyInfo targetBodyProperty;

		private static Type xenoBehaviourType;

		private static bool warned;

		private static MethodBase TargetMethod()
		{
			Type type = AccessTools.TypeByName("Xenologist.HUDTracker");
			if (type == null)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)"Could not find Xenologist.HUDTracker.");
				}
				return null;
			}
			hudField = AccessTools.Field(type, "hud");
			behaviourField = AccessTools.Field(type, "behaviour");
			panelField = AccessTools.Field(type, "samplePanel");
			xenoBehaviourType = AccessTools.TypeByName("Xenologist.XenoSampleBehaviour");
			return AccessTools.Method(type, "FixedUpdate", (Type[])null, (Type[])null);
		}

		private static object ReadTargetBody(object hud)
		{
			if (hud == null)
			{
				return null;
			}
			Type type = hud.GetType();
			if (targetBodyField == null && targetBodyProperty == null)
			{
				targetBodyField = AccessTools.Field(type, "targetBodyObject");
				if (targetBodyField == null)
				{
					targetBodyProperty = AccessTools.Property(type, "targetBodyObject");
				}
			}
			if (targetBodyField != null)
			{
				return targetBodyField.GetValue(hud);
			}
			if (targetBodyProperty != null)
			{
				return targetBodyProperty.GetValue(hud, null);
			}
			return null;
		}

		[HarmonyPostfix]
		private static void Postfix(object __instance)
		{
			try
			{
				if (__instance == null || hudField == null || behaviourField == null || panelField == null || xenoBehaviourType == null)
				{
					return;
				}
				object value = hudField.GetValue(__instance);
				object? value2 = panelField.GetValue(__instance);
				GameObject val = (GameObject)((value2 is GameObject) ? value2 : null);
				if (value == null || (Object)(object)val == (Object)null)
				{
					return;
				}
				object obj = ReadTargetBody(value);
				GameObject val2 = (GameObject)((obj is GameObject) ? obj : null);
				Component val3 = null;
				if ((Object)(object)val2 != (Object)null)
				{
					val3 = val2.GetComponent(xenoBehaviourType);
				}
				if (behaviourField.GetValue(__instance) != val3)
				{
					behaviourField.SetValue(__instance, val3);
					if ((Object)(object)val3 != (Object)null)
					{
						MethodInfo method = xenoBehaviourType.GetMethod("SetPanel", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						if (method != null)
						{
							method.Invoke(val3, new object[1] { val });
						}
					}
				}
				val.SetActive((Object)(object)val3 != (Object)null);
			}
			catch (Exception ex)
			{
				if (!warned)
				{
					warned = true;
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogError((object)("HUDTracker Postfix error: " + ex));
					}
				}
			}
		}
	}
	[BepInPlugin("com.chatgpt.xenologistuifix", "Xenologist UI Fix", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.chatgpt.xenologistuifix";

		public const string PluginName = "Xenologist UI Fix";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("com.chatgpt.xenologistuifix");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Xenologist UI Fix loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}