Decompiled source of EmeraudeConstruction v1.0.0

plugins/EmeraudeConstruction.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
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("EmeraudeConstruction")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EmeraudeConstruction")]
[assembly: AssemblyTitle("EmeraudeConstruction")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 EmeraudeConstruction
{
	[BepInPlugin("emeraude.construction", "Emeraude Construction", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "emeraude.construction";

		public const string Name = "Emeraude Construction";

		public const string Version = "1.0.0";

		internal static ConfigEntry<KeyboardShortcut> ResetKey;

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			ResetKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Placement", "ResetKey", new KeyboardShortcut((KeyCode)8, Array.Empty<KeyCode>()), "While placing a piece, puts it back in its default position: straight on every axis, automatic snapping.");
			new Harmony("emeraude.construction").PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} {1} loaded (default position key: {2})", "Emeraude Construction", "1.0.0", ResetKey.Value));
		}
	}
	[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
	internal static class ResetPlacementPatch
	{
		private const int AutomaticSnap = -1;

		private static void Prefix(Player __instance, bool flashGuardStone, GameObject ___m_placementGhost, ref int ___m_manualSnapPoint, ref int ___m_placeRotation)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (!flashGuardStone && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !((Object)(object)___m_placementGhost == (Object)null) && !KeysUsedElsewhere())
			{
				KeyboardShortcut value = Plugin.ResetKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					___m_manualSnapPoint = -1;
					___m_placeRotation = 0;
					PreciseRotationReset.Apply();
					((Character)__instance).Message((MessageType)2, DefaultPositionText(), 0, (Sprite)null, false);
				}
			}
		}

		private static bool KeysUsedElsewhere()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			if (!Hud.IsPieceSelectionVisible() && (int)Minimap.instance.m_mode != 2 && !Console.IsVisible() && !Chat.instance.HasFocus())
			{
				return TextInput.IsVisible();
			}
			return true;
		}

		private static string DefaultPositionText()
		{
			if (!(Localization.instance.GetSelectedLanguage() == "French"))
			{
				return "Default position";
			}
			return "Position par défaut";
		}
	}
	internal static class PreciseRotationReset
	{
		private const string PluginGuid = "com.github.johndowson.PreciseRotation";

		private static FieldInfo rotatorField;

		private static bool resolved;

		internal static void Apply()
		{
			if (Resolve())
			{
				object value = rotatorField.GetValue(null);
				Type type = value.GetType();
				string[] array = new string[3] { "x", "y", "z" };
				foreach (string name in array)
				{
					type.GetField(name).SetValue(value, 0f);
				}
				FieldInfo field = type.GetField("CurrentAxis");
				field.SetValue(value, Enum.Parse(field.FieldType, "Y"));
				rotatorField.SetValue(null, value);
			}
		}

		private static bool Resolve()
		{
			if (resolved)
			{
				return rotatorField != null;
			}
			resolved = true;
			if (!Chainloader.PluginInfos.TryGetValue("com.github.johndowson.PreciseRotation", out var value))
			{
				return false;
			}
			FieldInfo field = ((object)value.Instance).GetType().GetField("rotator", BindingFlags.Static | BindingFlags.NonPublic);
			Type type = field?.FieldType;
			int num;
			if (type != null && type.IsValueType)
			{
				FieldInfo? field2 = type.GetField("CurrentAxis");
				if ((object)field2 != null && field2.FieldType.IsEnum && type.GetField("x") != null && type.GetField("y") != null)
				{
					num = ((type.GetField("z") != null) ? 1 : 0);
					if (num != 0)
					{
						rotatorField = field;
						return (byte)num != 0;
					}
					goto IL_00c6;
				}
			}
			num = 0;
			goto IL_00c6;
			IL_00c6:
			Plugin.Log.LogWarning((object)"PreciseRotation found but its rotation could not be read: only vanilla rotation is reset.");
			return (byte)num != 0;
		}
	}
}