Decompiled source of Unconstrained Placement v1.2.0

BepInEx/plugins/UCHUnconstrainedPlacement.dll

Decompiled 4 days 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("UCHUnconstrainedPlacement")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+09c2dc19d70bc4634e82b0f244d421768bb4ed32")]
[assembly: AssemblyProduct("UCHUnconstrainedPlacement")]
[assembly: AssemblyTitle("UCHUnconstrainedPlacement")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 UncontrainedPlacement
{
	[Serializable]
	[BepInPlugin("com.brynzananas.uncontrainedplacement", "Uncontrained Placement", "1.2.0")]
	public class Main : BaseUnityPlugin
	{
		public const string ModGuid = "com.brynzananas.uncontrainedplacement";

		public const string ModName = "Uncontrained Placement";

		public const string ModVer = "1.2.0";

		private Harmony harmonyPatcher;

		public void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			harmonyPatcher = new Harmony("com.brynzananas.uncontrainedplacement");
			harmonyPatcher.CreateClassProcessor(typeof(Patches)).Patch();
		}

		public static void RemovePlacementRounding(ILCursor iLCursor)
		{
			while (iLCursor.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCall<Mathf>(x, "Round")
			}))
			{
				iLCursor.Remove();
			}
		}

		public static void RemoveRotationRounding(ILCursor iLCursor)
		{
			if (iLCursor.TryGotoNext((MoveType)0, new Func<Instruction, bool>[7]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 90f),
				(Instruction x) => ILPatternMatchingExt.MatchDiv(x),
				(Instruction x) => ILPatternMatchingExt.MatchCall<Mathf>(x, "Round"),
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 90f),
				(Instruction x) => ILPatternMatchingExt.MatchMul(x),
				(Instruction x) => ILPatternMatchingExt.MatchStloc(x, 0)
			}))
			{
				iLCursor.RemoveRange(7);
			}
			else
			{
				Debug.LogError((object)(((MemberReference)iLCursor.Context.Method).Name + " IL hook failed"));
			}
		}

		public static void SetRotationOverride(ILCursor iLCursor)
		{
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			ILLabel iLLabel = null;
			ILLabel val2 = default(ILLabel);
			int num = default(int);
			ILLabel val = default(ILLabel);
			ILLabel[] array = default(ILLabel[]);
			if (iLCursor.TryGotoNext((MoveType)0, new Func<Instruction, bool>[17]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1),
				(Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref val2),
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchCall<PiecePlacementCursor>(x, "get_Piece"),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<Placeable>(x, "OrientationAlt"),
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, ref num),
				(Instruction x) => ILPatternMatchingExt.MatchBneUn(x, ref iLLabel),
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchCall<PiecePlacementCursor>(x, "get_Piece"),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<Placeable>(x, "Orientation"),
				(Instruction x) => ILPatternMatchingExt.MatchBr(x, ref val),
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchCall<PiecePlacementCursor>(x, "get_Piece"),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<Placeable>(x, "OrientationAlt"),
				(Instruction x) => ILPatternMatchingExt.MatchStloc(x, 1),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 1),
				(Instruction x) => ILPatternMatchingExt.MatchSwitch(x, ref array)
			}))
			{
				iLCursor.Index += 1;
				iLCursor.RemoveRange(6);
				iLCursor.Emit(OpCodes.Brtrue_S, (object)iLLabel);
				iLCursor.Index += 3;
				iLCursor.Emit(OpCodes.Pop);
				iLCursor.Emit(OpCodes.Ldc_I4, 0);
				iLCursor.Index += 4;
				iLCursor.Emit(OpCodes.Pop);
				iLCursor.Emit(OpCodes.Ldc_I4, 1);
			}
			else
			{
				Debug.LogError((object)(((MemberReference)iLCursor.Context.Method).Name + " IL hook failed"));
			}
		}
	}
	[HarmonyPatch]
	internal class Patches
	{
		[HarmonyPatch(typeof(QuickSaver), "RestoreSaveables")]
		[HarmonyILManipulator]
		private static void QuickSaver_RestoreSaveables(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			int num2 = default(int);
			int num = default(int);
			while (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[9]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloca(x, ref num2),
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<Vector3>(x, "z"),
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 90f),
				(Instruction x) => ILPatternMatchingExt.MatchDiv(x),
				(Instruction x) => ILPatternMatchingExt.MatchCall<Mathf>(x, "Round"),
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 90f),
				(Instruction x) => ILPatternMatchingExt.MatchMul(x),
				(Instruction x) => ILPatternMatchingExt.MatchStfld<Vector3>(x, "z")
			}))
			{
				val.RemoveRange(9);
			}
		}

		[HarmonyPatch(typeof(PiecePlacementCursor), "FixedUpdate")]
		[HarmonyILManipulator]
		private static void PiecePlacementCursor_FixedUpdate(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor iLCursor = new ILCursor(il);
			Main.RemovePlacementRounding(iLCursor);
		}

		[HarmonyPatch(typeof(Placeable), "Place", new Type[]
		{
			typeof(int),
			typeof(bool),
			typeof(bool)
		})]
		[HarmonyILManipulator]
		private static void Placeable_Place_int_bool_bool(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor iLCursor = new ILCursor(il);
			Main.RemoveRotationRounding(iLCursor);
		}

		[HarmonyPatch(typeof(PiecePlacementCursor), "SetPiece")]
		[HarmonyILManipulator]
		private static void PiecePlacementCursor_SetPiece(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			ILCursor iLCursor = new ILCursor(il);
			Main.RemoveRotationRounding(iLCursor);
			iLCursor = new ILCursor(il);
			Main.RemovePlacementRounding(iLCursor);
		}

		[HarmonyPatch(typeof(PiecePlacementCursor), "PerformRightRotation")]
		[HarmonyILManipulator]
		private static void PiecePlacementCursor_PerformRightRotation(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			ILCursor rotationOverride = new ILCursor(il);
			Main.SetRotationOverride(rotationOverride);
			rotationOverride = new ILCursor(il);
			if (rotationOverride.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, -90f)
			}))
			{
				rotationOverride.Remove();
				rotationOverride.Emit(OpCodes.Ldc_R4, -15f);
			}
			else
			{
				Debug.LogError((object)(((MemberReference)il.Method).Name + " IL hook failed"));
			}
		}

		[HarmonyPatch(typeof(PiecePlacementCursor), "PerformLeftRotation")]
		[HarmonyILManipulator]
		private static void PiecePlacementCursor_PerformLeftRotation(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			ILCursor rotationOverride = new ILCursor(il);
			Main.SetRotationOverride(rotationOverride);
			rotationOverride = new ILCursor(il);
			if (rotationOverride.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 90f)
			}))
			{
				rotationOverride.Remove();
				rotationOverride.Emit(OpCodes.Ldc_R4, 15f);
			}
			else
			{
				Debug.LogError((object)(((MemberReference)il.Method).Name + " IL hook failed"));
			}
		}

		[HarmonyPatch(typeof(SwingingAxe), "Update")]
		[HarmonyILManipulator]
		private static void SwingingAxe_Update(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[5]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<SwingingAxe>(x, "RotateLocked"),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<Component>(x, "get_transform"),
				(Instruction x) => ILPatternMatchingExt.MatchCall<Quaternion>(x, "get_identity"),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<Transform>(x, "set_rotation")
			}))
			{
				val.RemoveRange(5);
			}
			else
			{
				Debug.LogError((object)(((MemberReference)val.Context.Method).Name + " IL hook failed"));
			}
		}
	}
}