Decompiled source of GOI Perfected Joystick v1.0.0

PerfectedJoystick/goi.barackobusiness.perfectedjoystick.dll

Decompiled 7 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using Rewired;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("goi.barackobusiness.perfectedjoystick")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A Getting Over It mod that rewrites the relationship between joystick input and the cursor")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1fd852b242419ab862ff44dc8113655de844dd70")]
[assembly: AssemblyProduct("Perfected Joystick")]
[assembly: AssemblyTitle("goi.barackobusiness.perfectedjoystick")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 PerfectedJoystick
{
	[BepInPlugin("goi.barackobusiness.perfectedjoystick", "Perfected Joystick", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Manipulator <0>__PlayerControl_FixedUpdate;
		}

		private ILHook _hook;

		public static Plugin Instance { get; private set; }

		public ConfigEntry<string> Stick { get; private set; }

		private void Awake()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			Instance = this;
			Stick = ((BaseUnityPlugin)this).Config.Bind<string>("", "Stick Selection", "Left", new ConfigDescription("Which joystick on the controller to read input from.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Left", "Right" }), Array.Empty<object>()));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Your joystick has been perfected.");
		}

		private void OnEnable()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Hooking `PlayerControl::FixedUpdate`");
			MethodInfo? method = typeof(PlayerControl).GetMethod("FixedUpdate", BindingFlags.Instance | BindingFlags.NonPublic);
			object obj = <>O.<0>__PlayerControl_FixedUpdate;
			if (obj == null)
			{
				Manipulator val = PlayerControl_FixedUpdate;
				<>O.<0>__PlayerControl_FixedUpdate = val;
				obj = (object)val;
			}
			_hook = new ILHook((MethodBase)method, (Manipulator)obj);
		}

		private void OnDisable()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Releasing `PlayerControl::FixedUpdate`");
			ILHook hook = _hook;
			if (hook != null)
			{
				hook.Dispose();
			}
		}

		private static void PlayerControl_FixedUpdate(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<PlayerControl>(x, "fakeCursorRB"),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 9),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<Rigidbody2D>(x, "MovePosition")
			}))
			{
				((BaseUnityPlugin)Instance).Logger.LogDebug((object)"Hooked successfully");
				try
				{
					val.RemoveRange(12);
					val.Emit(OpCodes.Ldarg_0);
					val.Emit(OpCodes.Ldarg_0);
					val.Emit<PlayerControl>(OpCodes.Ldfld, "fakeCursorRB");
					val.Emit(OpCodes.Ldarg_0);
					val.Emit<PlayerControl>(OpCodes.Ldfld, "player");
					val.EmitDelegate<Action<PlayerControl, Rigidbody2D, Player>>((Action<PlayerControl, Rigidbody2D, Player>)delegate(PlayerControl self, Rigidbody2D rb, Player player)
					{
						//IL_005d: Unknown result type (might be due to invalid IL or missing references)
						//IL_0063: Unknown result type (might be due to invalid IL or missing references)
						//IL_0068: Unknown result type (might be due to invalid IL or missing references)
						//IL_0077: Unknown result type (might be due to invalid IL or missing references)
						//IL_007d: Unknown result type (might be due to invalid IL or missing references)
						//IL_0082: Unknown result type (might be due to invalid IL or missing references)
						//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
						//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
						//IL_00be: Unknown result type (might be due to invalid IL or missing references)
						//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
						//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
						//IL_0086: Unknown result type (might be due to invalid IL or missing references)
						//IL_0091: Unknown result type (might be due to invalid IL or missing references)
						//IL_0096: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
						//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
						Vector2 val2 = default(Vector2);
						((Vector2)(ref val2))..ctor(player.GetAxis("Stick" + Instance.Stick.Value.Substring(0, 1) + "X"), player.GetAxis("Stick" + Instance.Stick.Value.Substring(0, 1) + "Y"));
						val2 = Vector2.ClampMagnitude(val2, 1f);
						bool num = ((Vector2)(ref val2)).sqrMagnitude > 0.01f;
						val2 *= 3.5f;
						Vector2 val3 = (num ? Vector2.op_Implicit(((Component)self).transform.TransformPoint(new Vector3(val2.x, val2.y, 0f))) : Vector2.Lerp(rb.position, Vector2.op_Implicit(self.tip.position), 0.5f));
						rb.MovePosition(val3);
					});
					return;
				}
				catch (Exception arg)
				{
					((BaseUnityPlugin)Instance).Logger.LogError((object)$"Error occurred in IL injection: {arg}");
					return;
				}
				finally
				{
					((BaseUnityPlugin)Instance).Logger.LogDebug((object)"Injected IL without error");
				}
			}
			((BaseUnityPlugin)Instance).Logger.LogError((object)"Failed to hook");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "goi.barackobusiness.perfectedjoystick";

		public const string PLUGIN_NAME = "Perfected Joystick";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}