Decompiled source of DistancedInteract v1.1.2

catrice.DistancedInteract.dll

Decompiled a month ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("catrice.DistancedInteract")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1")]
[assembly: AssemblyProduct("catrice.DistancedInteract")]
[assembly: AssemblyTitle("catrice.DistancedInteract")]
[assembly: AssemblyVersion("0.1.1.0")]
namespace catrice.DistancedInteract;

public static class InteractTimedPrefix
{
	public static bool SavedState;

	public static bool SavedLadderInteraction;

	public static bool SavedWantToEnterLadder;

	public static void AbortHandler()
	{
		Logger.Log("Aborted");
		Logger.Log(new StackTrace().ToString() ?? "");
	}

	public static void Prefix_Eval(Interact_Timed __instance)
	{
		__instance.AbortOnDotOrDistanceDiff = false;
	}

	public static void Prefix_SetTimerActive()
	{
		StackTrace stackTrace = new StackTrace();
		Logger.Log("Wht:" + stackTrace.ToString());
	}

	public static bool Prefix_UnSelectCurrentBsetInteraction(PlayerInteraction __instance)
	{
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Invalid comparison between Unknown and I4
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		if (__instance.m_bestSelectedInteract != null)
		{
			Logger.Log("Unselect WWW" + ((Object)__instance.m_bestSelectedInteract.Root).name);
		}
		IInteractable bestSelectedInteract = __instance.m_bestSelectedInteract;
		if ((Object)(object)((bestSelectedInteract != null) ? ((Il2CppObjectBase)bestSelectedInteract).TryCast<Interact_Timed>() : null) != (Object)null)
		{
			SavedState = true;
			SavedLadderInteraction = PlayerInteraction.LadderInteractionEnabled;
			SavedWantToEnterLadder = __instance.WantToEnterLadder;
			PlayerInteraction.LadderInteractionEnabled = false;
			__instance.WantToEnterLadder = true;
			return false;
		}
		if (!PlayerInteraction.InteractionEnabled)
		{
			return true;
		}
		if ((Object)(object)((PlayerAgent)__instance.m_owner).Inventory.WieldedItem != (Object)null && !((PlayerAgent)__instance.m_owner).Inventory.WieldedItem.AllowPlayerInteraction)
		{
			return true;
		}
		if (((PlayerAgent)__instance.m_owner).IsNSpace && (int)FocusStateManager.CurrentState != 9)
		{
			return true;
		}
		if (!((PlayerAgent)__instance.m_owner).IsNSpace)
		{
			_ = FocusStateManager.CurrentState;
			_ = 4;
			return true;
		}
		return true;
	}

	public static void Prefix_UpdateWorldInteractions(PlayerInteraction __instance)
	{
		if ((Object)(object)__instance == (Object)null)
		{
			return;
		}
		IInteractable bestSelectedInteract = __instance.m_bestSelectedInteract;
		Interact_Base val = ((bestSelectedInteract != null) ? ((Il2CppObjectBase)bestSelectedInteract).TryCast<Interact_Base>() : null);
		if ((Object)(object)val != (Object)null)
		{
			IInteractable bestSelectedInteract2 = __instance.m_bestSelectedInteract;
			Interact_Timed val2 = ((bestSelectedInteract2 != null) ? ((Il2CppObjectBase)bestSelectedInteract2).TryCast<Interact_Timed>() : null);
			if ((Object)(object)val2 != (Object)null && val2.TimerIsActive)
			{
				__instance.m_bestInteractInCurrentSearch = val;
			}
		}
	}

	public static void Postfix_UpdateWorldInteractions(PlayerInteraction __instance)
	{
		if (SavedState)
		{
			SavedState = false;
			PlayerInteraction.LadderInteractionEnabled = SavedLadderInteraction;
			__instance.WantToEnterLadder = SavedWantToEnterLadder;
		}
	}
}
public static class WatchStack
{
	[HarmonyPatch(typeof(Interact_Timed), "OnInteractorStateChanged")]
	[HarmonyPrefix]
	public static void OnChanged()
	{
		Logger.Log(new StackTrace().ToString() ?? "");
	}

	[HarmonyPatch(typeof(Interact_Timed), "SetActive")]
	[HarmonyPrefix]
	public static void SetActive()
	{
		Logger.Log(new StackTrace().ToString() ?? "");
	}

	[HarmonyPatch(typeof(Interact_Timed), "OnSelectedChange")]
	[HarmonyPrefix]
	public static void SetActive2()
	{
		Logger.Log(new StackTrace().ToString() ?? "");
	}

	[HarmonyPatch(typeof(Interact_Base), "PlayerSetSelected")]
	[HarmonyPrefix]
	public static void SetActive3()
	{
		Logger.Log(new StackTrace().ToString() ?? "");
	}

	[HarmonyPatch(typeof(Interact_Timed), "PlayerCheckInput")]
	[HarmonyPrefix]
	public static void SetActive4()
	{
		Logger.Log(new StackTrace().ToString() ?? "");
	}
}
[BepInPlugin("com.catrice.DistancedInteract", "DistancedInteract", "1.1.1")]
[BepInProcess("GTFO.exe")]
public class EntryPoint : BasePlugin
{
	public const string GUID = "com.catrice.DistancedInteract";

	private bool once;

	public override void Load()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Expected O, but got Unknown
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Expected O, but got Unknown
		//IL_00ad: Expected O, but got Unknown
		Logger.LogInstance = ((BasePlugin)this).Log;
		Harmony val = new Harmony("com.catrice.DistancedInteract");
		MethodInfo method = typeof(Interact_Timed).GetMethod("EvaluateTimedInteraction");
		MethodInfo method2 = typeof(InteractTimedPrefix).GetMethod("Prefix_Eval");
		val.Patch((MethodBase)method, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		MethodInfo method3 = typeof(PlayerInteraction).GetMethod("UpdateWorldInteractions");
		MethodInfo method4 = typeof(InteractTimedPrefix).GetMethod("Prefix_UpdateWorldInteractions");
		MethodInfo method5 = typeof(InteractTimedPrefix).GetMethod("Postfix_UpdateWorldInteractions");
		val.Patch((MethodBase)method3, new HarmonyMethod(method4), new HarmonyMethod(method5), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		val.PatchAll();
	}
}
public static class Logger
{
	public static ManualLogSource LogInstance;

	public static void Log(string format, params object[] args)
	{
		Log(string.Format(format, args));
	}

	public static void Log(string str)
	{
		ManualLogSource logInstance = LogInstance;
		if (logInstance != null)
		{
			logInstance.Log((LogLevel)8, (object)str);
		}
	}

	public static void Warning(string format, params object[] args)
	{
		Warning(string.Format(format, args));
	}

	public static void Warning(string str)
	{
		ManualLogSource logInstance = LogInstance;
		if (logInstance != null)
		{
			logInstance.Log((LogLevel)4, (object)str);
		}
	}

	public static void Error(string format, params object[] args)
	{
		Error(string.Format(format, args));
	}

	public static void Error(string str)
	{
		ManualLogSource logInstance = LogInstance;
		if (logInstance != null)
		{
			logInstance.Log((LogLevel)2, (object)str);
		}
	}
}