Decompiled source of HalfGridSnap v1.1.0

HalfGridSnap.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using CommonAPI;
using CommonAPI.Systems;
using CommonAPI.Systems.ModLocalization;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HalfGridSnap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+bfe28c32812bd8bd9b729b31bf75db2e9d49fc9b")]
[assembly: AssemblyProduct("HalfGridSnap")]
[assembly: AssemblyTitle("HalfGridSnap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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 HalfGridSnap
{
	[BepInPlugin("HalfGridSnap", "HalfGridSnap", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[CommonAPISubmoduleDependency(new string[] { "CustomKeyBindSystem" })]
	[CommonAPISubmoduleDependency(new string[] { "LocalizationModule" })]
	public class HalfGridSnap : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private readonly Harmony harmony = new Harmony("HalfGridSnap");

		private const string keyName = "切换是否半格点吸附";

		[CompilerGenerated]
		private bool <IsEnable>k__BackingField;

		public bool IsEnable
		{
			get
			{
				return <IsEnable>k__BackingField;
			}
			set
			{
				if (<IsEnable>k__BackingField != value)
				{
					<IsEnable>k__BackingField = value;
					if (IsEnable)
					{
						harmony.PatchAll(typeof(PlanetGridPatch));
					}
					else
					{
						harmony.UnpatchSelf();
					}
				}
			}
		}

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			RegisterKeyBinds();
			IsEnable = true;
			Logger.LogInfo((object)"Plugin HalfGridSnap is loaded!");
		}

		private void RegisterKeyBinds()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			CombineKey val = default(CombineKey);
			val.keyCode = 96;
			val.action = (ECombineKeyAction)0;
			CombineKey key = val;
			BuiltinKey val2 = default(BuiltinKey);
			val2.name = "切换是否半格点吸附";
			val2.key = key;
			val2.canOverride = true;
			val2.conflictGroup = 2052;
			CustomKeyBindSystem.RegisterKeyBind<ReleaseKeyBind>(val2);
			LocalizationModule.RegisterTranslation("切换是否半格点吸附", "Toggle Half Grid Snap Function");
		}

		private void Update()
		{
			if (CustomKeyBindSystem.GetKeyBind("切换是否半格点吸附").keyValue)
			{
				IsEnable = !IsEnable;
			}
		}
	}
	public static class PlanetGridPatch
	{
		[CompilerGenerated]
		private sealed class <SnapTo_Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private IEnumerator<CodeInstruction> <>7__wrap1;

			CodeInstruction IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SnapTo_Transpiler>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 1u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>7__wrap1 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<>7__wrap1 = instructions.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						break;
					case 2:
						<>1__state = -3;
						break;
					}
					if (<>7__wrap1.MoveNext())
					{
						CodeInstruction current = <>7__wrap1.Current;
						if (current.opcode == OpCodes.Ldc_R4 && (float)current.operand == 5f)
						{
							<>2__current = new CodeInstruction(OpCodes.Ldc_R4, (object)10f);
							<>1__state = 1;
							return true;
						}
						<>2__current = current;
						<>1__state = 2;
						return true;
					}
					<>m__Finally1();
					<>7__wrap1 = null;
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>7__wrap1 != null)
				{
					<>7__wrap1.Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<SnapTo_Transpiler>d__0 <SnapTo_Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<SnapTo_Transpiler>d__ = this;
				}
				else
				{
					<SnapTo_Transpiler>d__ = new <SnapTo_Transpiler>d__0(0);
				}
				<SnapTo_Transpiler>d__.instructions = <>3__instructions;
				return <SnapTo_Transpiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		[IteratorStateMachine(typeof(<SnapTo_Transpiler>d__0))]
		[HarmonyTranspiler]
		[HarmonyPatch(typeof(PlanetGrid), "SnapTo", new Type[] { typeof(Vector3) })]
		[HarmonyPatch(typeof(PlanetGrid), "SnapInCurrentSeg", new Type[] { typeof(Vector3) })]
		[HarmonyPatch(typeof(PlanetGrid), "SnapTo", new Type[]
		{
			typeof(Vector3),
			typeof(int)
		})]
		[HarmonyPatch(typeof(PlanetGrid), "SnapTo", new Type[]
		{
			typeof(float),
			typeof(float)
		})]
		public static IEnumerable<CodeInstruction> SnapTo_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SnapTo_Transpiler>d__0(-2)
			{
				<>3__instructions = instructions
			};
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "HalfGridSnap";

		public const string PLUGIN_NAME = "HalfGridSnap";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}