Decompiled source of AutoHop v1.2.3

AutoHop.dll

Decompiled 4 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("AutoHop")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AutoHop")]
[assembly: AssemblyTitle("AutoHop")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace AutoHop
{
	internal static class ConfigMgr
	{
		private static ConfigFile _conf;

		private static ConfigEntry<bool> _enableInLevelCarryAssist;

		private static ConfigEntry<float> _dashTimeRel;

		private static ConfigEntry<float> _jumpTimeRel;

		public static bool EnableInLevelCarryAssist => _enableInLevelCarryAssist.Value;

		public static float DashTimeRel => _dashTimeRel.Value;

		public static float JumpTimeRel => _jumpTimeRel.Value;

		public static void Process()
		{
			Logger.Info($"assist={EnableInLevelCarryAssist}, dashRel={DashTimeRel}, jumpRel={JumpTimeRel}");
			CutePatch.CuteSpot = Mathf.Clamp01(DashTimeRel);
			CutePatch.CuterSpot = Mathf.Clamp01(JumpTimeRel);
		}

		static ConfigMgr()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			string text = Path.Combine(Paths.ConfigPath, "AutoHop.cfg");
			Logger.Debug("cfgPath = " + text);
			_conf = new ConfigFile(text, true);
			int num = 1;
			string text2 = $"({num++}) InLevelCarry Item Assist";
			_enableInLevelCarryAssist = _conf.Bind<bool>(text2, "Enable InLevelCarry Item Autohop Assist", true, "The assist works by blocking input to Sprint/Movement and Jump until specified progress for InLevelCarry interactions, this might not be desirable for you");
			_dashTimeRel = _conf.Bind<float>(text2, "Relative Dash Timing", 0.88f, "The minimum progress of the progress bar (0.0 - 1.0) at which a backward sprint/dash is allowed to be triggered");
			_jumpTimeRel = _conf.Bind<float>(text2, "Relative Jump Timing", 0.98f, "The minimum progress of the progress bar (0.0 - 1.0) at which a jump is allowed to be triggered, this should be after the dash timing");
		}
	}
	[HarmonyPatch]
	public class CutePatch
	{
		public static string CuteMsg = "Why are you looking at the source. It's literally too cute UwU";

		public static float CuteSpot = 0.88f;

		public static float CuterSpot = 0.98f;

		internal static Interact_Timed? CurrentInteraction = null;

		public static bool IsAttemptingInteractionBlocking = false;

		public static bool IsFinalJumpBlocking = false;

		[HarmonyPatch(typeof(InputMapper), "DoGetKeycodeButtonDown")]
		[HarmonyPostfix]
		public static void DoGetKeyDown(InputMapper __instance, InputMapData data)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
			if (!((Object)(object)localPlayerAgent == (Object)null) && (int)localPlayerAgent.Locomotion.m_currentStateEnum != 8 && (int)data.action == 5 && Input.GetKey(data.keycode))
			{
				InputMapData.s_tempBool = !IsFinalJumpBlocking;
			}
		}

		[HarmonyPatch(typeof(InputMapper), "DoGetAxis")]
		[HarmonyPostfix]
		public static void InputMapper_GetAxis(InputMapper __instance, InputAction action, InputMapData[] map, ref float __result)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			UpdateInvalidateInteraction();
			if (ConfigMgr.EnableInLevelCarryAssist && IsAttemptingInteractionBlocking && (int)action == 2)
			{
				__result = 0f;
			}
		}

		[HarmonyPatch(typeof(Interact_Timed), "Update")]
		[HarmonyPostfix]
		public static void Interact_Timed_Update(Interact_Timed __instance)
		{
			if (!ConfigMgr.EnableInLevelCarryAssist)
			{
				return;
			}
			UpdateInvalidateInteraction();
			if (!IsInLevelCarry(__instance))
			{
				return;
			}
			if (__instance.m_timerIsActive)
			{
				if ((Object)(object)CurrentInteraction == (Object)null)
				{
					CurrentInteraction = __instance;
				}
				else if ((Object)(object)CurrentInteraction != (Object)null && (Object)(object)CurrentInteraction != (Object)(object)__instance && __instance.m_timerProgressRel > CurrentInteraction.m_timerProgressRel)
				{
					CurrentInteraction = __instance;
				}
				IsAttemptingInteractionBlocking = __instance.m_timerProgressRel < CuteSpot;
				IsFinalJumpBlocking = __instance.m_timerProgressRel < CuterSpot;
			}
			else if (!((Object)(object)CurrentInteraction != (Object)null) || !((Object)(object)CurrentInteraction != (Object)(object)__instance))
			{
				IsAttemptingInteractionBlocking = false;
				IsFinalJumpBlocking = false;
			}
		}

		private static void UpdateInvalidateInteraction()
		{
			if ((Object)(object)CurrentInteraction != (Object)null && !CurrentInteraction.m_timerIsActive)
			{
				CurrentInteraction = null;
			}
		}

		private static bool IsInLevelCarry(Interact_Timed interact)
		{
			if ((Object)(object)CurrentInteraction != (Object)null)
			{
				return true;
			}
			return (Object)(object)((Component)interact).GetComponentInParent<CarryItemPickup_Core>() != (Object)null;
		}
	}
	internal static class Logger
	{
		private static ManualLogSource _mLogSource;

		public static bool Ready => _mLogSource != null;

		public static void Setup()
		{
			_mLogSource = Logger.CreateLogSource("io.takina.gtfo.AutoHop");
		}

		public static void SetupFromInit(ManualLogSource logSource)
		{
			_mLogSource = logSource;
		}

		private static string Format(object data)
		{
			return data.ToString();
		}

		public static void Debug(object msg)
		{
			_mLogSource.LogDebug((object)Format(msg));
		}

		public static void Info(object msg)
		{
			_mLogSource.LogInfo((object)Format(msg));
		}

		public static void Warn(object msg)
		{
			_mLogSource.LogWarning((object)Format(msg));
		}

		public static void Error(object msg)
		{
			_mLogSource.LogError((object)Format(msg));
		}

		public static void Fatal(object msg)
		{
			_mLogSource.LogFatal((object)Format(msg));
		}
	}
	[BepInPlugin("io.takina.gtfo.AutoHop", "AutoHop", "1.2.3")]
	public class Plugin : BasePlugin
	{
		public const string NAME = "AutoHop";

		public const string GUID = "io.takina.gtfo.AutoHop";

		public const string VERSION = "1.2.3";

		public override void Load()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Logger.Setup();
			Logger.Info("AutoHop [io.takina.gtfo.AutoHop @ 1.2.3]");
			Logger.Info("Patching...");
			Harmony val = new Harmony("io.takina.gtfo.AutoHop");
			ConfigMgr.Process();
			val.PatchAll(typeof(CutePatch));
			Logger.Info("Finished Patching");
		}
	}
}