Decompiled source of Gizmo v1.9.1

ComfyGizmo.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using ComfyGizmo.Core.Rotators;
using ComfyLib;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ComfyGizmo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ComfyGizmo")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("83d75858-7663-4c9b-abef-75ffd7e692e0")]
[assembly: AssemblyFileVersion("1.9.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.9.1.0")]
[module: UnverifiableCode]
namespace ComfyLib
{
	public static class ConfigFileExtensions
	{
		internal sealed class ConfigurationManagerAttributes
		{
			public Action<ConfigEntryBase> CustomDrawer;

			public bool? Browsable;

			public bool? HideDefaultButton;

			public bool? HideSettingName;

			public bool? IsAdvanced;

			public int? Order;

			public bool? ReadOnly;
		}

		private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>();

		private static int GetSettingOrder(string section)
		{
			if (!_sectionToSettingOrder.TryGetValue(section, out var value))
			{
				value = 0;
			}
			_sectionToSettingOrder[section] = value - 1;
			return value;
		}

		public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = GetSettingOrder(section)
				}
			}));
		}

		public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool readOnly = false, bool isAdvanced = false)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Browsable = browsable,
					IsAdvanced = isAdvanced,
					CustomDrawer = customDrawer,
					HideDefaultButton = hideDefaultButton,
					HideSettingName = hideSettingName,
					Order = GetSettingOrder(section),
					ReadOnly = readOnly
				}
			}));
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler)
		{
			configEntry.SettingChanged += delegate
			{
				settingChangedHandler();
			};
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler)
		{
			configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
			};
		}

		public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler)
		{
			configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				settingChangedHandler((ConfigEntry<T>)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
			};
		}
	}
}
namespace ComfyGizmo
{
	[BepInPlugin("bruce.valheim.comfymods.gizmo", "ComfyGizmo", "1.9.1")]
	public class ComfyGizmo : BaseUnityPlugin
	{
		public const string PluginGUID = "bruce.valheim.comfymods.gizmo";

		public const string PluginName = "ComfyGizmo";

		public const string PluginVersion = "1.9.1";

		private Harmony _harmony;

		private void Awake()
		{
			PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
			Gizmos.LoadGizmoPrefab();
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "bruce.valheim.comfymods.gizmo");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	public abstract class AbstractRotator
	{
		protected Gizmos _gizmos;

		protected GhostGizmo _ghostGizmo;

		protected string _name;

		protected Vector3 _eulerAngles = Vector3.zero;

		public abstract void Rotate(Vector3 rotationAxis);

		public abstract void ResetRotation();

		public abstract void ResetAxis(Vector3 axis);

		public abstract void MatchPieceRotation(Piece target);

		public abstract Quaternion GetRotation();

		public void DisplayModeChangeHudeMessage()
		{
			if (Object.op_Implicit((Object)(object)MessageHud.instance))
			{
				MessageHud.instance.ShowMessage((MessageType)1, "Switchted to " + GetModeName() + " mode.", 0, (Sprite)null);
			}
		}

		public void Destroy()
		{
			DestroyGizmos();
			DestroyGhostGizmo();
		}

		private void DestroyGizmos()
		{
			if (_gizmos != null)
			{
				_gizmos.Destroy();
			}
		}

		private void DestroyGhostGizmo()
		{
			if (_ghostGizmo != null)
			{
				_ghostGizmo.Destroy();
			}
		}

		protected abstract Gizmos GetGizmos();

		public void ShowGizmos(Player player)
		{
			GetGizmos().Show(player);
		}

		public void HideGizmos()
		{
			GetGizmos().Hide();
		}

		public void ResetScales()
		{
			GetGizmos().ResetScale();
		}

		public void SetXScale(float scale)
		{
			GetGizmos().SetXScale(scale);
		}

		public void SetYScale(float scale)
		{
			GetGizmos().SetYScale(scale);
		}

		public void SetZScale(float scale)
		{
			GetGizmos().SetZScale(scale);
		}

		protected abstract string GetModeName();

		protected float GetAngle()
		{
			return 180f / (float)PluginConfig.SnapDivisions.Value;
		}
	}
	public class DefaultRotator : AbstractRotator
	{
		public DefaultRotator()
		{
			_name = "Default Rotator";
			_gizmos = Gizmos.CreateGizmos();
			ResetRotation();
		}

		public override void Rotate(Vector3 rotationAxis)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			_eulerAngles += rotationAxis * GetAngle();
			_gizmos.SetLocalRotation(_eulerAngles);
		}

		public override void ResetRotation()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			_eulerAngles = Vector3.zero;
			_gizmos.SetLocalRotation(_eulerAngles);
		}

		public override void ResetAxis(Vector3 axis)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			if (axis == Vector3.up)
			{
				_eulerAngles.y = 0f;
			}
			if (axis == Vector3.right)
			{
				_eulerAngles.x = 0f;
			}
			if (axis == Vector3.forward)
			{
				_eulerAngles.z = 0f;
			}
			_gizmos.SetLocalRotation(_eulerAngles);
		}

		public override void MatchPieceRotation(Piece target)
		{
			//IL_000f: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			ResetRotation();
			_eulerAngles = ((Component)target).GetComponent<Transform>().eulerAngles;
			Rotate(Vector3.zero);
		}

		protected override string GetModeName()
		{
			return "default rotation";
		}

		protected override Gizmos GetGizmos()
		{
			return _gizmos;
		}

		public override Quaternion GetRotation()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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)
			return _gizmos.GetXGizmoRoot().rotation;
		}
	}
	public class Gizmos
	{
		private static GameObject _prefab;

		private static readonly List<Gizmos> _gizmoInstances = new List<Gizmos>();

		private readonly GameObject _gizmo;

		private Transform _gizmoRoot;

		private Transform _xGizmo;

		private Transform _yGizmo;

		private Transform _zGizmo;

		private Transform _xGizmoRoot;

		private Transform _yGizmoRoot;

		private Transform _zGizmoRoot;

		private Material _xMaterial;

		private Material _yMaterial;

		private Material _zMaterial;

		public static Gizmos CreateGizmos()
		{
			Gizmos gizmos = new Gizmos();
			_gizmoInstances.Add(gizmos);
			return gizmos;
		}

		public static void ResetAllScales()
		{
			foreach (Gizmos gizmoInstance in _gizmoInstances)
			{
				gizmoInstance.ResetScale();
			}
		}

		public static void SetAllXColors()
		{
			foreach (Gizmos gizmoInstance in _gizmoInstances)
			{
				gizmoInstance.SetXGizmoColor();
			}
		}

		public static void SetAllYColors()
		{
			foreach (Gizmos gizmoInstance in _gizmoInstances)
			{
				gizmoInstance.SetYGizmoColor();
			}
		}

		public static void SetAllZColors()
		{
			foreach (Gizmos gizmoInstance in _gizmoInstances)
			{
				gizmoInstance.SetZGizmoColor();
			}
		}

		public Gizmos()
		{
			_gizmo = Object.Instantiate<GameObject>(_prefab);
			SetupComponentsAndRoots();
		}

		public void Show(Player player)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)player.m_placementMarkerInstance))
			{
				SetActive(player);
				SetPosition(player.m_placementMarkerInstance.transform.position + Vector3.up * 0.5f);
			}
		}

		public void Hide()
		{
			((Component)_gizmoRoot).gameObject.SetActive(false);
		}

		public Transform GetXGizmoRoot()
		{
			return _xGizmoRoot;
		}

		public void ApplyRotation(Quaternion rotation)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			Transform gizmoRoot = _gizmoRoot;
			gizmoRoot.rotation *= rotation;
		}

		public void SetLocalRotation(Vector3 eulerAngles)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			_xGizmoRoot.localRotation = Quaternion.Euler(eulerAngles.x, 0f, 0f);
			_yGizmoRoot.localRotation = Quaternion.Euler(0f, eulerAngles.y, 0f);
			_zGizmoRoot.localRotation = Quaternion.Euler(0f, 0f, eulerAngles.z);
		}

		public void SetAxisRotation(float angle, Vector3 axis)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			_gizmoRoot.rotation = Quaternion.AngleAxis(angle, axis);
		}

		public void SetLocalAxisRotation(float angle, Vector3 axis)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			_gizmoRoot.localRotation = Quaternion.AngleAxis(angle, axis);
		}

		public void ResetScale()
		{
			SetLocalScale(1f);
		}

		public void SetLocalScale(float scale)
		{
			SetXScale(scale);
			SetYScale(scale);
			SetZScale(scale);
		}

		public void SetXScale(float scale)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			_xGizmo.localScale = Vector3.one * scale;
		}

		public void SetYScale(float scale)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			_yGizmo.localScale = Vector3.one * scale;
		}

		public void SetZScale(float scale)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			_zGizmo.localScale = Vector3.one * scale;
		}

		public void SetXColor()
		{
			SetXGizmoColor();
		}

		public void SetYColor()
		{
			SetYGizmoColor();
		}

		public void SetZColor()
		{
			SetZGizmoColor();
		}

		public void SetRotation(Quaternion rotation)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			_gizmoRoot.rotation = rotation;
		}

		public void SetPosition(Vector3 position)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			_gizmoRoot.position = position;
		}

		public void SetActive(Player player)
		{
			((Component)_gizmoRoot).gameObject.SetActive(PluginConfig.ShowGizmoPrefab.Value && player.m_placementMarkerInstance.activeSelf);
		}

		public void SetXGizmoColor()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			_xMaterial.SetColor("_Color", PluginConfig.XGizmoColor.Value * PluginConfig.XEmissionColorFactor.Value);
		}

		public void SetYGizmoColor()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			_yMaterial.SetColor("_Color", PluginConfig.YGizmoColor.Value * PluginConfig.YEmissionColorFactor.Value);
		}

		public void SetZGizmoColor()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			_zMaterial.SetColor("_Color", PluginConfig.ZGizmoColor.Value * PluginConfig.ZEmissionColorFactor.Value);
		}

		public void Destroy()
		{
			Object.Destroy((Object)(object)_gizmo);
		}

		private void SetupComponentsAndRoots()
		{
			_gizmoRoot = _gizmo.transform;
			_xGizmo = _gizmoRoot.Find("YRoot/ZRoot/XRoot/X");
			_yGizmo = _gizmoRoot.Find("YRoot/Y");
			_zGizmo = _gizmoRoot.Find("YRoot/ZRoot/Z");
			_xMaterial = ((Component)_xGizmo).gameObject.GetComponent<Renderer>().material;
			_yMaterial = ((Component)_yGizmo).gameObject.GetComponent<Renderer>().material;
			_zMaterial = ((Component)_zGizmo).gameObject.GetComponent<Renderer>().material;
			SetXGizmoColor();
			SetYGizmoColor();
			SetZGizmoColor();
			_xGizmoRoot = _gizmoRoot.Find("YRoot/ZRoot/XRoot");
			_yGizmoRoot = _gizmoRoot.Find("YRoot");
			_zGizmoRoot = _gizmoRoot.Find("YRoot/ZRoot");
		}

		public static GameObject LoadGizmoPrefab()
		{
			AssetBundle val = AssetBundle.LoadFromMemory(GetResource(Assembly.GetExecutingAssembly(), "ComfyGizmo.Resources.gizmos"));
			_prefab = val.LoadAsset<GameObject>("GizmoRoot");
			val.Unload(false);
			return _prefab;
		}

		private static byte[] GetResource(Assembly assembly, string resourceName)
		{
			Stream manifestResourceStream = assembly.GetManifestResourceStream(resourceName);
			byte[] array = new byte[manifestResourceStream.Length];
			manifestResourceStream.Read(array, 0, (int)manifestResourceStream.Length);
			return array;
		}
	}
	public class HammerTableManager
	{
		private static readonly string _searsCatalogGUID = "redseiko.valheim.searscatalog";

		private static readonly string _columnConfigSection = "BuildHud.Panel";

		private static readonly string _columnConfigKey = "buildHudPanelColumns";

		private static readonly int _defaultColumnCount = 15;

		private static BaseUnityPlugin _searsCatalog = null;

		private static ConfigEntry<int> _searsCatalogColumnsConfigEntry;

		private static Dictionary<string, Vector2Int> _pieceLocations = new Dictionary<string, Vector2Int>();

		private static int _cachedAvailablePieceCount = -1;

		private static bool _targetSelection = false;

		public static void Initialize()
		{
			if (IsSearsCatalogEnabled())
			{
				FindSearsCatalogPlugin();
			}
		}

		public static void SelectTargetPiece(Player player)
		{
			if (IsHammerTableChanged(player) || !IsHammerTableCached())
			{
				CacheHammerTable(player);
			}
			if (HasCachedPiece(player.GetHoveringPiece()))
			{
				_targetSelection = true;
				SetSelectedPiece(player, player.GetHoveringPiece());
			}
		}

		public static bool IsTargetSelected()
		{
			return _targetSelection;
		}

		public static int GetColumnCount()
		{
			if (!IsSearsCatalogEnabled())
			{
				return _defaultColumnCount;
			}
			return GetSearsCatalogColumnCount();
		}

		public static bool HasCachedPiece(Piece piece)
		{
			return _pieceLocations.ContainsKey(GetPieceIdentifier(piece));
		}

		public static void SetSelectedPiece(Player player, Piece piece)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_002b: 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)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			Vector2Int val = _pieceLocations[GetPieceIdentifier(piece)];
			PieceCategory selectedCategory = player.m_buildPieces.m_selectedCategory;
			player.m_buildPieces.m_selectedCategory = (PieceCategory)((Vector2Int)(ref val)).x;
			player.SetSelectedPiece(new Vector2Int(((Vector2Int)(ref val)).y % GetColumnCount(), ((Vector2Int)(ref val)).y / GetColumnCount()));
			player.SetupPlacementGhost();
			if (selectedCategory != player.m_buildPieces.m_selectedCategory)
			{
				Hud.instance.UpdatePieceList(player, new Vector2Int(((Vector2Int)(ref val)).y % 15, ((Vector2Int)(ref val)).y / 15), (PieceCategory)((Vector2Int)(ref val)).x, true);
			}
		}

		public static bool IsHammerTableCached()
		{
			return _cachedAvailablePieceCount != -1;
		}

		public static void CacheHammerTable(Player player)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			PieceTable buildPieces = player.m_buildPieces;
			_cachedAvailablePieceCount = 0;
			_pieceLocations = new Dictionary<string, Vector2Int>();
			for (int i = 0; i < buildPieces.m_availablePieces.Count; i++)
			{
				List<Piece> list = buildPieces.m_availablePieces[i];
				for (int j = 0; j < list.Count; j++)
				{
					if (!_pieceLocations.ContainsKey(GetPieceIdentifier(list[j])))
					{
						_pieceLocations.Add(GetPieceIdentifier(list[j]), new Vector2Int(i, j));
						_cachedAvailablePieceCount++;
					}
				}
			}
		}

		public static bool IsHammerTableChanged(Player player)
		{
			if (!Object.op_Implicit((Object)(object)player) || !Object.op_Implicit((Object)(object)player.m_buildPieces) || player.m_buildPieces.m_availablePieces == null)
			{
				return false;
			}
			int num = 0;
			for (int i = 0; i < player.m_buildPieces.m_availablePieces.Count; i++)
			{
				num += player.m_buildPieces.m_availablePieces[i].Count;
			}
			if (num == _cachedAvailablePieceCount)
			{
				return false;
			}
			return true;
		}

		private static string GetPieceIdentifier(Piece piece)
		{
			return piece.m_name + piece.m_description;
		}

		public static bool IsSearsCatalogEnabled()
		{
			FindSearsCatalogPlugin();
			if (!Object.op_Implicit((Object)(object)_searsCatalog))
			{
				return false;
			}
			return true;
		}

		public static int GetSearsCatalogColumnCount()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			if (_searsCatalogColumnsConfigEntry != null)
			{
				return _searsCatalogColumnsConfigEntry.Value;
			}
			ConfigEntry<int> val = default(ConfigEntry<int>);
			if (_searsCatalog.Config.TryGetEntry<int>(new ConfigDefinition(_columnConfigSection, _columnConfigKey), ref val))
			{
				_searsCatalogColumnsConfigEntry = val;
				return val.Value;
			}
			return _defaultColumnCount;
		}

		private static void FindSearsCatalogPlugin()
		{
			IEnumerable<BaseUnityPlugin> loadedPlugins = GetLoadedPlugins();
			if (loadedPlugins != null)
			{
				Dictionary<string, BaseUnityPlugin> dictionary = loadedPlugins.Where((BaseUnityPlugin plugin) => plugin.Info.Metadata.GUID == _searsCatalogGUID).ToDictionary((BaseUnityPlugin plugin) => plugin.Info.Metadata.GUID);
				if (dictionary.TryGetValue(_searsCatalogGUID, out var value))
				{
					_searsCatalog = value;
				}
			}
		}

		private static IEnumerable<BaseUnityPlugin> GetLoadedPlugins()
		{
			return from x in Chainloader.PluginInfos
				where x.Value != null && (Object)(object)x.Value.Instance != (Object)null
				select x.Value.Instance;
		}
	}
	public class GhostGizmo
	{
		private readonly GameObject _prefab;

		private readonly Transform _root;

		public static GhostGizmo CreateGhostGizmo()
		{
			return new GhostGizmo();
		}

		public GhostGizmo()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			_prefab = new GameObject("ComfyGizmo");
			_root = _prefab.transform;
		}

		public void Destroy()
		{
			Object.Destroy((Object)(object)_prefab);
		}

		public void ApplyRotation(Quaternion rotation)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			Transform root = _root;
			root.rotation *= rotation;
		}

		public void ApplyLocalRotation(Quaternion rotation)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			Transform root = _root;
			root.localRotation *= rotation;
		}

		public void SetRotation(Quaternion rotation)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			_root.rotation = rotation;
		}

		public Quaternion GetRotation()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			return _root.rotation;
		}

		public void SetLocalRotation(Quaternion rotation)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			_root.localRotation = rotation;
		}

		public void SetAxisRotation(float angle, Vector3 axis)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			_root.rotation = Quaternion.AngleAxis(angle, axis);
		}

		public void SetLocalAxisRotation(float angle, Vector3 axis)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			_root.localRotation = Quaternion.AngleAxis(angle, axis);
		}
	}
	public class RotationManager
	{
		private static DefaultRotator _defaultRotator;

		private static InternalRotator _internalRotator;

		private static LocalFrameRotator _localFrameRotator;

		private static RoofRotator _roofRotator;

		public static void Initialize()
		{
			_defaultRotator = new DefaultRotator();
			_internalRotator = new InternalRotator();
			_localFrameRotator = new LocalFrameRotator();
			_roofRotator = new RoofRotator();
		}

		public static void Rotate(Vector3 rotationAxis)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			_defaultRotator.Rotate(rotationAxis);
			_internalRotator.Rotate(rotationAxis);
			_localFrameRotator.Rotate(rotationAxis);
			_roofRotator.Rotate(rotationAxis);
		}

		public static void ResetRotation()
		{
			_defaultRotator.ResetRotation();
			_internalRotator.ResetRotation();
			_localFrameRotator.ResetRotation();
			_roofRotator.ResetRotation();
		}

		public static void ResetAxis(Vector3 axis)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			_defaultRotator.ResetAxis(axis);
			_internalRotator.ResetAxis(axis);
			_localFrameRotator.ResetAxis(axis);
			_roofRotator.ResetAxis(axis);
		}

		public static void MatchPieceRotation(Piece target)
		{
			_defaultRotator.MatchPieceRotation(target);
			_internalRotator.MatchPieceRotation(target);
			_localFrameRotator.MatchPieceRotation(target);
			_roofRotator.MatchPieceRotation(target);
		}

		public static Quaternion GetRotation()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return GetActiveRotator().GetRotation();
		}

		public static void ShowGizmos(Player player)
		{
			GetActiveRotator().ShowGizmos(player);
		}

		public static void HideGizmos()
		{
			_defaultRotator.HideGizmos();
			_internalRotator.HideGizmos();
			_localFrameRotator.HideGizmos();
			_roofRotator.HideGizmos();
		}

		public static void ResetScales()
		{
			_defaultRotator.ResetScales();
			_internalRotator.ResetScales();
			_localFrameRotator.ResetScales();
			_roofRotator.ResetScales();
		}

		public static void SetActiveXScale(float scale)
		{
			GetActiveRotator().SetXScale(scale);
		}

		public static void SetActiveYScale(float scale)
		{
			GetActiveRotator().SetYScale(scale);
		}

		public static void SetActiveZScale(float scale)
		{
			GetActiveRotator().SetZScale(scale);
		}

		public static void OnModeChange(Player player)
		{
			if (PluginConfig.ResetRotationOnModeChange.Value)
			{
				ResetRotation();
			}
			HideGizmos();
			GetActiveRotator().DisplayModeChangeHudeMessage();
			GetActiveRotator().ShowGizmos(player);
		}

		private static AbstractRotator GetActiveRotator()
		{
			if (PluginConfig.IsRoofModeEnabled.Value && RoofRotator.IsCornerRoofPieceSelected())
			{
				return _roofRotator;
			}
			if (PluginConfig.IsLocalFrameEnabled.Value)
			{
				return _localFrameRotator;
			}
			if (PluginConfig.IsOldRotationEnabled.Value)
			{
				return _internalRotator;
			}
			return _defaultRotator;
		}

		public static void DestroyRotators()
		{
			if (_defaultRotator != null)
			{
				_defaultRotator.Destroy();
				_defaultRotator = null;
			}
			if (_internalRotator != null)
			{
				_internalRotator.Destroy();
				_internalRotator = null;
			}
			if (_localFrameRotator != null)
			{
				_localFrameRotator.Destroy();
				_localFrameRotator = null;
			}
			if (_roofRotator != null)
			{
				_roofRotator.Destroy();
				_roofRotator = null;
			}
		}

		public static void DisableLocalFrameMode()
		{
			if (PluginConfig.IsLocalFrameEnabled.Value)
			{
				PluginConfig.IsRoofModeEnabled.Value = false;
				if (Object.op_Implicit((Object)(object)MessageHud.instance))
				{
					MessageHud.instance.ShowMessage((MessageType)1, "Disabled roof mode.", 0, (Sprite)null);
				}
			}
		}

		public static void IncreaseSnapDivisions()
		{
			if (PluginConfig.SnapDivisions.Value * 2 <= PluginConfig.MaxSnapDivisions)
			{
				MessageHud.instance.ShowMessage((MessageType)1, $"Snap divisions increased to {PluginConfig.SnapDivisions.Value * 2}", 0, (Sprite)null);
				PluginConfig.SnapDivisions.Value = PluginConfig.SnapDivisions.Value * 2;
				if (PluginConfig.ResetRotationOnSnapDivisionChange.Value)
				{
					ResetRotation();
				}
			}
		}

		public static void DecreaseSnapDivisions()
		{
			if (Math.Floor((float)PluginConfig.SnapDivisions.Value / 2f) == (double)((float)PluginConfig.SnapDivisions.Value / 2f) && PluginConfig.SnapDivisions.Value / 2 >= PluginConfig.MinSnapDivisions)
			{
				MessageHud.instance.ShowMessage((MessageType)1, $"Snap divisions decreased to {PluginConfig.SnapDivisions.Value / 2}", 0, (Sprite)null);
				PluginConfig.SnapDivisions.Value = PluginConfig.SnapDivisions.Value / 2;
				if (PluginConfig.ResetRotationOnSnapDivisionChange.Value)
				{
					ResetRotation();
				}
			}
		}
	}
	public class LocalFrameRotator : AbstractRotator
	{
		public LocalFrameRotator()
		{
			_name = "Local Frame Rotator";
			_ghostGizmo = GhostGizmo.CreateGhostGizmo();
			_gizmos = Gizmos.CreateGizmos();
			ResetRotation();
		}

		public override void Rotate(Vector3 rotationAxis)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			Quaternion rotation = Quaternion.AngleAxis(GetAngle(), rotationAxis);
			_ghostGizmo.ApplyRotation(rotation);
			_gizmos.ApplyRotation(rotation);
		}

		public override void ResetRotation()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			_ghostGizmo.SetRotation(Quaternion.identity);
			_gizmos.SetRotation(Quaternion.identity);
		}

		public override void ResetAxis(Vector3 axis)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			_ghostGizmo.SetAxisRotation(0f, axis);
			_gizmos.SetAxisRotation(0f, axis);
		}

		public override void MatchPieceRotation(Piece target)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			_ghostGizmo.SetRotation(((Component)target).GetComponent<Transform>().localRotation);
			_gizmos.SetRotation(((Component)target).GetComponent<Transform>().localRotation);
		}

		protected override string GetModeName()
		{
			return "local frame rotation";
		}

		protected override Gizmos GetGizmos()
		{
			return _gizmos;
		}

		public override Quaternion GetRotation()
		{
			//IL_002c: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (!PluginConfig.IsOldRotationEnabled.Value)
			{
				return _gizmos.GetXGizmoRoot().rotation;
			}
			return _ghostGizmo.GetRotation();
		}
	}
	public static class PluginConfig
	{
		public static readonly int MinSnapDivisions = 2;

		public static readonly int MaxSnapDivisions = 256;

		public static ConfigEntry<int> SnapDivisions { get; private set; }

		public static ConfigEntry<bool> ShowGizmoPrefab { get; private set; }

		public static ConfigEntry<bool> ResetRotationOnModeChange { get; private set; }

		public static ConfigEntry<bool> ResetRotationOnSnapDivisionChange { get; private set; }

		public static ConfigEntry<bool> IsLocalFrameEnabled { get; private set; }

		public static ConfigEntry<bool> IsOldRotationEnabled { get; private set; }

		public static ConfigEntry<bool> IsRoofModeEnabled { get; private set; }

		public static ConfigEntry<KeyboardShortcut> XRotationKey { get; private set; }

		public static ConfigEntry<KeyboardShortcut> ZRotationKey { get; private set; }

		public static ConfigEntry<KeyboardShortcut> ResetRotationKey { get; private set; }

		public static ConfigEntry<KeyboardShortcut> ResetAllRotationKey { get; private set; }

		public static ConfigEntry<KeyboardShortcut> ChangeRotationModeKey { get; private set; }

		public static ConfigEntry<KeyboardShortcut> CopyPieceRotationKey { get; private set; }

		public static ConfigEntry<KeyboardShortcut> SelectTargetPieceKey { get; private set; }

		public static ConfigEntry<KeyboardShortcut> SnapDivisionIncrementKey { get; private set; }

		public static ConfigEntry<KeyboardShortcut> SnapDivisionDecrementKey { get; private set; }

		public static ConfigEntry<Color> XGizmoColor { get; private set; }

		public static ConfigEntry<Color> YGizmoColor { get; private set; }

		public static ConfigEntry<Color> ZGizmoColor { get; private set; }

		public static ConfigEntry<float> XEmissionColorFactor { get; private set; }

		public static ConfigEntry<float> YEmissionColorFactor { get; private set; }

		public static ConfigEntry<float> ZEmissionColorFactor { get; private set; }

		public static void BindConfig(ConfigFile config)
		{
			SnapDivisions = config.BindInOrder("Gizmo", "snapDivisions", 16, "Number of snap angles per 180 degrees. Vanilla uses 8.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(MinSnapDivisions, MaxSnapDivisions));
			BindKeysConfig(config);
			BindGizmoColorsConfig(config);
			ShowGizmoPrefab = config.BindInOrder("UI", "showGizmoPrefab", defaultValue: true, "Show the Gizmo prefab in placement mode.");
			ResetRotationOnSnapDivisionChange = config.BindInOrder("Reset", "resetOnSnapDivisionChange", defaultValue: true, "Resets the piece's rotation on snap division change.");
			ResetRotationOnModeChange = config.BindInOrder("Reset", "resetOnModeChange", defaultValue: true, "Resets the piece's rotation on mode switch.");
			IsRoofModeEnabled = config.BindInOrder("Modes", "isRoofModeEnabled", defaultValue: false, "Enables roof mode which allows corner roof piece rotation 45 deg compared to normal rotation.");
			IsRoofModeEnabled.OnSettingChanged<bool>((Action)delegate
			{
				RotationManager.ResetRotation();
				RotationManager.OnModeChange(Player.m_localPlayer);
			});
			IsOldRotationEnabled = config.BindInOrder("Modes", "isOldRotationModeEnabled", defaultValue: false, "Enables pre Gizmo-v1.4.0 rotation scheme.");
			IsOldRotationEnabled.OnSettingChanged<bool>((Action)delegate
			{
				RotationManager.OnModeChange(Player.m_localPlayer);
			});
			IsLocalFrameEnabled = config.BindInOrder("Modes", "isLocalFrameModeEnabled", defaultValue: false, "Enables localFrame rotation mode. Allows rotation around the piece's Y-axis rather than world-Y.");
			IsLocalFrameEnabled.OnSettingChanged<bool>((Action)delegate
			{
				RotationManager.OnModeChange(Player.m_localPlayer);
				RotationManager.DisableLocalFrameMode();
			});
		}

		public static void BindKeysConfig(ConfigFile config)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			XRotationKey = config.BindInOrder<KeyboardShortcut>("Keys", "xRotationKey", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), "Hold this key to rotate on the x-axis/plane (red circle).");
			ZRotationKey = config.BindInOrder<KeyboardShortcut>("Keys", "zRotationKey", new KeyboardShortcut((KeyCode)308, Array.Empty<KeyCode>()), "Hold this key to rotate on the z-axis/plane (blue circle).");
			ResetRotationKey = config.BindInOrder<KeyboardShortcut>("Keys", "resetRotationKey", new KeyboardShortcut((KeyCode)118, Array.Empty<KeyCode>()), "Press this key to reset the selected axis to zero rotation.");
			ResetAllRotationKey = config.BindInOrder<KeyboardShortcut>("Keys", "resetAllRotationKey", KeyboardShortcut.Empty, "Press this key to reset _all axis_ rotations to zero rotation.");
			ChangeRotationModeKey = config.BindInOrder<KeyboardShortcut>("Keys", "changeRotationMode", new KeyboardShortcut((KeyCode)96, Array.Empty<KeyCode>()), "Press this key to toggle rotation modes.");
			CopyPieceRotationKey = config.BindInOrder<KeyboardShortcut>("Keys", "copyPieceRotation", KeyboardShortcut.Empty, "Press this key to copy targeted piece's rotation.");
			SelectTargetPieceKey = config.BindInOrder<KeyboardShortcut>("Keys", "selectTargetPieceKey", new KeyboardShortcut((KeyCode)112, Array.Empty<KeyCode>()), "Selects target piece to be used.");
			SnapDivisionIncrementKey = config.BindInOrder<KeyboardShortcut>("Keys", "snapDivisionIncrement", new KeyboardShortcut((KeyCode)280, Array.Empty<KeyCode>()), "Doubles snap divisions from current.");
			SnapDivisionDecrementKey = config.BindInOrder<KeyboardShortcut>("Keys", "snapDivisionDecrement", new KeyboardShortcut((KeyCode)281, Array.Empty<KeyCode>()), "Doubles snap divisions from current.");
		}

		public static void BindGizmoColorsConfig(ConfigFile config)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			XGizmoColor = config.BindInOrder<Color>("GizmoColors - X", "xGizmoColor", new Color(1f, 0f, 0f, 0.502f), "Sets the color of x gizmo (rotations about x axis).");
			XGizmoColor.OnSettingChanged<Color>(Gizmos.SetAllXColors);
			YGizmoColor = config.BindInOrder<Color>("GizmoColors - Y", "yGizmoColor", new Color(0f, 1f, 0f, 0.502f), "Sets the color of y gizmo (rotations about y axis).");
			YGizmoColor.OnSettingChanged<Color>(Gizmos.SetAllYColors);
			ZGizmoColor = config.BindInOrder<Color>("GizmoColors - Z", "zGizmoColor", new Color(0f, 0f, 1f, 0.502f), "Sets the color of z gizmo (rotations about z axis).");
			ZGizmoColor.OnSettingChanged<Color>(Gizmos.SetAllZColors);
			XEmissionColorFactor = config.BindInOrder("GizmoColors - X", "emissionColorFactorX", 0.4f, "Factor to multiply the target color by and set as emission color.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f));
			XEmissionColorFactor.OnSettingChanged<float>(Gizmos.SetAllXColors);
			YEmissionColorFactor = config.BindInOrder("GizmoColors - Y", "emissionColorFactorY", 0.4f, "Factor to multiply the target color by and set as emission color.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f));
			YEmissionColorFactor.OnSettingChanged<float>(Gizmos.SetAllYColors);
			ZEmissionColorFactor = config.BindInOrder("GizmoColors - Z", "emissionColorFactorZ", 0.4f, "Factor to multiply the target color by and set as emission color.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f));
			ZEmissionColorFactor.OnSettingChanged<float>(Gizmos.SetAllZColors);
		}
	}
}
namespace ComfyGizmo.Patches
{
	[HarmonyPatch(typeof(FejdStartup))]
	internal static class FejdStartupPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePostfix()
		{
			HammerTableManager.Initialize();
		}
	}
	[HarmonyPatch(typeof(Game))]
	internal static class GamePatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void StartPostfix()
		{
			RotationManager.Initialize();
		}
	}
	[HarmonyPatch(typeof(Player))]
	internal static class PlayerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("UpdatePlacementGhost")]
		private static void UpdatePlacementGhostPrefix(ref Player __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = PluginConfig.SelectTargetPieceKey.Value;
			if (Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey) && Object.op_Implicit((Object)(object)__instance) && Object.op_Implicit((Object)(object)__instance.m_buildPieces) && __instance.m_buildPieces.m_availablePieces != null && Object.op_Implicit((Object)(object)__instance.GetHoveringPiece()))
			{
				HammerTableManager.SelectTargetPiece(__instance);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("UpdatePlacement")]
		private static void UpdatePlacementPostfix(ref Player __instance, ref bool takeInput)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			RotationManager.HideGizmos();
			RotationManager.ShowGizmos(__instance);
			if (!Object.op_Implicit((Object)(object)__instance.m_buildPieces) || !takeInput || Hud.IsPieceSelectionVisible())
			{
				return;
			}
			KeyboardShortcut value = PluginConfig.SnapDivisionIncrementKey.Value;
			if (Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
			{
				RotationManager.IncreaseSnapDivisions();
			}
			value = PluginConfig.SnapDivisionDecrementKey.Value;
			if (Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
			{
				RotationManager.DecreaseSnapDivisions();
			}
			value = PluginConfig.CopyPieceRotationKey.Value;
			if (Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey) && (Object)(object)__instance.m_hoveringPiece != (Object)null)
			{
				RotationManager.MatchPieceRotation(__instance.m_hoveringPiece);
			}
			value = PluginConfig.ChangeRotationModeKey.Value;
			if (Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
			{
				PluginConfig.IsLocalFrameEnabled.Value = !PluginConfig.IsLocalFrameEnabled.Value;
			}
			RotationManager.ResetScales();
			value = PluginConfig.ResetAllRotationKey.Value;
			if (Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
			{
				RotationManager.ResetRotation();
				return;
			}
			Vector3 rotationAxis = GetRotationAxis();
			value = PluginConfig.ResetRotationKey.Value;
			if (Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
			{
				RotationManager.ResetAxis(rotationAxis);
			}
			rotationAxis *= (float)GetSign();
			RotationManager.Rotate(rotationAxis);
		}

		private static int GetSign()
		{
			return Math.Sign(Input.GetAxis("Mouse ScrollWheel"));
		}

		private static Vector3 GetRotationAxis()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = PluginConfig.XRotationKey.Value;
			if (Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
			{
				RotationManager.SetActiveXScale(1.5f);
				return Vector3.right;
			}
			value = PluginConfig.ZRotationKey.Value;
			if (Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
			{
				RotationManager.SetActiveZScale(1.5f);
				return Vector3.forward;
			}
			RotationManager.SetActiveYScale(1.5f);
			return Vector3.up;
		}

		[HarmonyTranspiler]
		[HarmonyPatch("UpdatePlacementGhost")]
		private static IEnumerable<CodeInstruction> UpdatePlacementGhostTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[6]
			{
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Player), "m_placeRotation"), (string)null),
				new CodeMatch((OpCode?)OpCodes.Conv_R4, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Mul, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null)
			}).Advance(5).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { Transpilers.EmitDelegate<Func<Quaternion, Quaternion>>((Func<Quaternion, Quaternion>)((Quaternion _) => RotationManager.GetRotation())) })
				.InstructionEnumeration();
		}
	}
}
namespace ComfyGizmo.Core.Rotators
{
	public class InternalRotator : AbstractRotator
	{
		public InternalRotator()
		{
			_name = "Internal Rotator";
			_ghostGizmo = GhostGizmo.CreateGhostGizmo();
			_gizmos = Gizmos.CreateGizmos();
			ResetRotation();
		}

		public override void Rotate(Vector3 rotationAxis)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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)
			_eulerAngles += rotationAxis * GetAngle();
			_ghostGizmo.SetLocalRotation(Quaternion.Euler(_eulerAngles));
			_gizmos.SetLocalRotation(_eulerAngles);
		}

		public override void ResetRotation()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			_eulerAngles = Vector3.zero;
			_ghostGizmo.SetLocalRotation(Quaternion.Euler(_eulerAngles));
			_gizmos.SetLocalRotation(_eulerAngles);
		}

		public override void ResetAxis(Vector3 axis)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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)
			if (axis == Vector3.up)
			{
				_eulerAngles.y = 0f;
			}
			if (axis == Vector3.right)
			{
				_eulerAngles.x = 0f;
			}
			if (axis == Vector3.forward)
			{
				_eulerAngles.z = 0f;
			}
			_ghostGizmo.SetLocalRotation(Quaternion.Euler(_eulerAngles));
			_gizmos.SetLocalRotation(_eulerAngles);
		}

		public override void MatchPieceRotation(Piece target)
		{
			//IL_000f: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			ResetRotation();
			_eulerAngles = ((Component)target).GetComponent<Transform>().eulerAngles;
			Rotate(Vector3.zero);
		}

		protected override string GetModeName()
		{
			return "old rotation";
		}

		protected override Gizmos GetGizmos()
		{
			return _gizmos;
		}

		public override Quaternion GetRotation()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			return _ghostGizmo.GetRotation();
		}
	}
	public class RoofRotator : AbstractRotator
	{
		private Quaternion _roofRotation;

		private static readonly List<int> _roofCornerPieceHashCodes = new List<int>
		{
			StringExtensionMethods.GetStableHashCode("wood_roof_ocorner"),
			StringExtensionMethods.GetStableHashCode("wood_roof_ocorner_45"),
			StringExtensionMethods.GetStableHashCode("wood_roof_icorner"),
			StringExtensionMethods.GetStableHashCode("wood_roof_icorner_45"),
			StringExtensionMethods.GetStableHashCode("darkwood_roof_ocorner"),
			StringExtensionMethods.GetStableHashCode("darkwood_roof_ocorner_45"),
			StringExtensionMethods.GetStableHashCode("darkwood_roof_icorner"),
			StringExtensionMethods.GetStableHashCode("darkwood_roof_icorner_45")
		};

		public RoofRotator()
		{
			_name = "Roof Rotator";
			_ghostGizmo = GhostGizmo.CreateGhostGizmo();
			_gizmos = Gizmos.CreateGizmos();
			ResetRotation();
		}

		public override void Rotate(Vector3 rotationAxis)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			_eulerAngles += rotationAxis * GetAngle();
			Vector3 val = ConvertAxisRoofMode(rotationAxis);
			_gizmos.SetLocalRotation(_eulerAngles);
			_roofRotation *= Quaternion.AngleAxis(GetAngle(), val);
		}

		public override void ResetRotation()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			_eulerAngles = Vector3.zero;
			_gizmos.SetLocalRotation(_eulerAngles);
			_roofRotation = GetBaseRotation();
		}

		public override void ResetAxis(Vector3 axis)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			if (axis == Vector3.up)
			{
				_eulerAngles.y = 0f;
			}
			if (axis == Vector3.right)
			{
				_eulerAngles.x = 0f;
			}
			if (axis == Vector3.forward)
			{
				_eulerAngles.z = 0f;
			}
			_gizmos.SetLocalRotation(_eulerAngles);
			_roofRotation = GetBaseRotation() * Quaternion.Euler(_eulerAngles);
		}

		public override void MatchPieceRotation(Piece target)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			ResetRotation();
			Quaternion val = GetInverseBaseRotation() * Quaternion.Euler(((Component)target).GetComponent<Transform>().eulerAngles);
			_eulerAngles = ((Quaternion)(ref val)).eulerAngles;
			_gizmos.SetLocalRotation(_eulerAngles);
			_roofRotation = Quaternion.Euler(((Component)target).GetComponent<Transform>().eulerAngles);
		}

		protected override string GetModeName()
		{
			return "roof rotation";
		}

		protected override Gizmos GetGizmos()
		{
			return _gizmos;
		}

		public override Quaternion GetRotation()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			return _roofRotation;
		}

		private Vector3 ConvertAxisRoofMode(Vector3 rotationAxis)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			return Quaternion.Euler(0f, -45f, 0f) * rotationAxis;
		}

		private Quaternion GetBaseRotation()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return Quaternion.AngleAxis(45f, Vector3.up);
		}

		private Quaternion GetInverseBaseRotation()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return Quaternion.AngleAxis(-45f, Vector3.up);
		}

		public static bool IsCornerRoofPieceSelected()
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)Player.m_localPlayer.m_placementGhost == (Object)null)
			{
				return false;
			}
			if (!_roofCornerPieceHashCodes.Contains(StringExtensionMethods.GetStableHashCode(((Object)Player.m_localPlayer.m_placementGhost).name.Replace("(Clone)", ""))))
			{
				return false;
			}
			return true;
		}
	}
}