Decompiled source of Locater Fix v1.0.1

plugins/LocaterFix.dll

Decompiled 17 hours ago
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
using RoR2;
using RoR2.UI;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ForNull.LocaterFix;

[BepInPlugin("for_null.locaterfix", "Locater Fix", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInProcess("Risk of Rain 2.exe")]
public sealed class LocaterFixPlugin : BaseUnityPlugin
{
	private const string OriginalSha256 = "795383F173ADC9B9AC50ACE3B426993105EF362FD3578E9A0A2BEF3896D24599";

	private Harmony harmony;

	private void Awake()
	{
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Expected O, but got Unknown
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Expected O, but got Unknown
		try
		{
			if (!Chainloader.PluginInfos.TryGetValue("com.Hyru.Locater", out var value) || (Object)(object)value.Instance == (Object)null)
			{
				throw new InvalidOperationException("Original Locater must be installed and enabled.");
			}
			Type type = ((object)value.Instance).GetType();
			if (AccessTools.DeclaredMethod(type, "PrepareStaticMarkerLocalFix", (Type[])null, (Type[])null) != null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Locater already contains the private local-fix1 binary repair. No runtime patch applied. Restore official Locater 1.3.5 when using this public plugin.");
				return;
			}
			string text;
			using (SHA256 sHA = SHA256.Create())
			{
				text = BitConverter.ToString(sHA.ComputeHash(File.ReadAllBytes(type.Assembly.Location))).Replace("-", "");
			}
			if (value.Metadata.Version != new Version(1, 3, 5) || text != "795383F173ADC9B9AC50ACE3B426993105EF362FD3578E9A0A2BEF3896D24599")
			{
				((BaseUnityPlugin)this).Logger.LogError((object)string.Concat("Unsupported Locater binary (", value.Metadata.Version, ", SHA256 ", text, "). This release only supports the official Hyru-Locater-1.3.5 package. Nothing was patched."));
				return;
			}
			MethodInfo methodInfo = AccessTools.DeclaredMethod(type, "RemoveEdgeComponents", new Type[1] { typeof(GameObject) }, (Type[])null);
			MethodInfo testSpawn = AccessTools.DeclaredMethod(type, "OnPopulateScenePostfix", new Type[1] { typeof(SceneDirector) }, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.DeclaredMethod(typeof(SceneDirector), "PopulateScene", (Type[])null, (Type[])null);
			MethodInfo methodInfo3 = AccessTools.DeclaredMethod(typeof(LocaterFixPlugin), "PrepareStaticMarker", (Type[])null, (Type[])null);
			if (methodInfo == null || testSpawn == null || methodInfo2 == null || methodInfo3 == null)
			{
				throw new MissingMethodException("Locater marker or scene methods could not be located.");
			}
			Patches patchInfo = Harmony.GetPatchInfo((MethodBase)methodInfo2);
			if (patchInfo == null || !patchInfo.Postfixes.Any((Patch p) => p.PatchMethod == testSpawn))
			{
				throw new InvalidOperationException("Locater's expected test-spawn postfix was not registered. Refusing an unexpected setup.");
			}
			harmony = new Harmony("for_null.locaterfix");
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo3), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Unpatch((MethodBase)methodInfo2, testSpawn);
			patchInfo = Harmony.GetPatchInfo((MethodBase)methodInfo2);
			if (patchInfo != null && patchInfo.Postfixes.Any((Patch p) => p.PatchMethod == testSpawn))
			{
				throw new InvalidOperationException("Locater's test-spawn postfix could not be removed.");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Locater Fix 1.0.0 enabled for official Locater 1.3.5: static marker cleanup prefix installed; leftover test chest spawns removed.");
		}
		catch (Exception ex)
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			((BaseUnityPlugin)this).Logger.LogError((object)("Locater Fix did not initialize: " + ex));
		}
	}

	private static void PrepareStaticMarker(GameObject indicator)
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)indicator))
		{
			return;
		}
		ChargeIndicatorController component = indicator.GetComponent<ChargeIndicatorController>();
		if (!Object.op_Implicit((Object)(object)component))
		{
			return;
		}
		((Behaviour)component).enabled = false;
		SpriteRenderer[] iconSprites = component.iconSprites;
		if (iconSprites != null)
		{
			SpriteRenderer[] array = iconSprites;
			foreach (SpriteRenderer val in array)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					val.color = component.spriteBaseColor;
				}
			}
		}
		if (Object.op_Implicit((Object)(object)component.chargingText))
		{
			((Component)component.chargingText).gameObject.SetActive(false);
		}
		if (Object.op_Implicit((Object)(object)component.pingText))
		{
			((Component)component.pingText).gameObject.SetActive(false);
		}
	}
}