Decompiled source of ValheimPlus Grantapher Temporary v9.12.0

BepInEx/plugins/ValheimPlus.dll

Decompiled 5 months ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
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.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Timers;
using BepInEx;
using BepInEx.Logging;
using Costura;
using Fishlabs.Valheim;
using HarmonyLib;
using IniParser;
using IniParser.Model;
using ServerSync;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using ValheimPlus.Configurations;
using ValheimPlus.Configurations.Sections;
using ValheimPlus.GameClasses;
using ValheimPlus.RPC;
using ValheimPlus.UI;
using ValheimPlus.Utility;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ValheimPlus")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ValheimPlus")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2a837100-a030-4d0c-bffb-b38356118d9a")]
[assembly: AssemblyFileVersion("0.9.12.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.9.12.0")]
[module: UnverifiableCode]
internal class <Module>
{
	static <Module>()
	{
		AssemblyLoader.Attach();
	}
}
public static class ZNetExtensions
{
	public enum ZNetInstanceType
	{
		Local,
		Client,
		Server
	}

	public static bool IsLocalInstance(this ZNet znet)
	{
		return znet.IsServer() && !znet.IsDedicated();
	}

	public static bool IsClientInstance(this ZNet znet)
	{
		return !znet.IsServer() && !znet.IsDedicated();
	}

	public static bool IsServerInstance(this ZNet znet)
	{
		return znet.IsServer() && znet.IsDedicated();
	}

	public static ZNetInstanceType GetInstanceType(this ZNet znet)
	{
		if (znet.IsLocalInstance())
		{
			return ZNetInstanceType.Local;
		}
		if (znet.IsClientInstance())
		{
			return ZNetInstanceType.Client;
		}
		return ZNetInstanceType.Server;
	}
}
namespace ValheimPlus
{
	internal class ABM
	{
		public static bool isActive;

		private static Player PlayerInstance;

		private static bool controlFlag;

		private static bool shiftFlag;

		private static bool altFlag;

		public static bool exitOnNextIteration;

		private static Piece component;

		private const float BASE_TRANSLATION_DISTANCE = 0.1f;

		private const float BASE_ROTATION_ANGLE_DEGREES = 3f;

		private static float currentModificationSpeed = 1f;

		private const float MIN_MODIFICATION_SPEED = 1f;

		private const float MAX_MODIFICATION_SPEED = 30f;

		private static Quaternion savedRotation;

		public static void Run(ref Player __instance)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			PlayerInstance = __instance;
			if (AEM.isActive)
			{
				if (isActive)
				{
					exitMode();
				}
				return;
			}
			if (Input.GetKeyDown(Configuration.Current.AdvancedBuildingMode.exitAdvancedBuildingMode))
			{
				if (isActive)
				{
					exitMode();
				}
				return;
			}
			if (exitOnNextIteration)
			{
				isActive = false;
				exitOnNextIteration = false;
				component = null;
			}
			if (isActive && (Object)(object)component == (Object)null)
			{
				exitMode();
			}
			else if ((Object)(object)selectedPrefab() == (Object)null || (Object)(object)PlayerInstance.m_placementGhost == (Object)null)
			{
				if (isActive)
				{
					exitMode();
				}
			}
			else if (isInBuildMode() && IsHoeOrTerrainTool(selectedPrefab()))
			{
				if (isActive)
				{
					exitMode();
				}
			}
			else if (isActive)
			{
				if (Vector3.Distance(((Component)PlayerInstance).transform.position, ((Component)component).transform.position) > PlayerInstance.m_maxPlaceDistance)
				{
					exitMode();
				}
				isRunning();
				listenToHotKeysAndDoWork();
			}
			else if (Input.GetKeyDown(Configuration.Current.AdvancedBuildingMode.enterAdvancedBuildingMode))
			{
				startMode();
			}
		}

		private static void listenToHotKeysAndDoWork()
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: 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_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			float num2 = 0f;
			float num3 = 0f;
			if (Input.GetKeyDown((KeyCode)306))
			{
				controlFlag = true;
			}
			if (Input.GetKeyUp((KeyCode)306))
			{
				controlFlag = false;
			}
			if (Input.GetKeyDown((KeyCode)304))
			{
				shiftFlag = true;
			}
			if (Input.GetKeyUp((KeyCode)304))
			{
				shiftFlag = false;
			}
			if (Input.GetKeyDown((KeyCode)308))
			{
				altFlag = true;
			}
			if (Input.GetKeyUp((KeyCode)308))
			{
				altFlag = false;
			}
			changeModificationSpeed();
			if (Input.GetKeyUp(Configuration.Current.AdvancedBuildingMode.copyObjectRotation))
			{
				savedRotation = ((Component)component).transform.rotation;
			}
			if (Input.GetKeyUp(Configuration.Current.AdvancedBuildingMode.pasteObjectRotation))
			{
				((Component)component).transform.rotation = savedRotation;
			}
			float num4 = 3f * currentModificationSpeed;
			if (Input.GetAxis("Mouse ScrollWheel") > 0f)
			{
				Quaternion rotation;
				if (controlFlag)
				{
					num += 1f;
					rotation = Quaternion.Euler(((Component)component).transform.eulerAngles.x + num4 * num, ((Component)component).transform.eulerAngles.y, ((Component)component).transform.eulerAngles.z);
				}
				else if (altFlag)
				{
					num2 += 1f;
					rotation = Quaternion.Euler(((Component)component).transform.eulerAngles.x, ((Component)component).transform.eulerAngles.y, ((Component)component).transform.eulerAngles.z + num4 * num2);
				}
				else
				{
					num3 += 1f;
					rotation = Quaternion.Euler(((Component)component).transform.eulerAngles.x, ((Component)component).transform.eulerAngles.y + num4 * num3, ((Component)component).transform.eulerAngles.z);
				}
				((Component)component).transform.rotation = rotation;
			}
			if (Input.GetAxis("Mouse ScrollWheel") < 0f)
			{
				Quaternion rotation2;
				if (controlFlag)
				{
					num -= 1f;
					rotation2 = Quaternion.Euler(((Component)component).transform.eulerAngles.x + num4 * num, ((Component)component).transform.eulerAngles.y, ((Component)component).transform.eulerAngles.z);
				}
				else if (altFlag)
				{
					num2 -= 1f;
					rotation2 = Quaternion.Euler(((Component)component).transform.eulerAngles.x, ((Component)component).transform.eulerAngles.y, ((Component)component).transform.eulerAngles.z + num4 * num2);
				}
				else
				{
					num3 -= 1f;
					rotation2 = Quaternion.Euler(((Component)component).transform.eulerAngles.x, ((Component)component).transform.eulerAngles.y + num4 * num3, ((Component)component).transform.eulerAngles.z);
				}
				((Component)component).transform.rotation = rotation2;
			}
			float num5 = 0.1f * currentModificationSpeed;
			if (Input.GetKeyDown((KeyCode)273))
			{
				if (controlFlag)
				{
					((Component)component).transform.Translate(Vector3.up * num5);
				}
				else
				{
					((Component)component).transform.Translate(Vector3.forward * num5);
				}
			}
			if (Input.GetKeyDown((KeyCode)274))
			{
				if (controlFlag)
				{
					((Component)component).transform.Translate(Vector3.down * num5);
				}
				else
				{
					((Component)component).transform.Translate(Vector3.back * num5);
				}
			}
			if (Input.GetKeyDown((KeyCode)276))
			{
				((Component)component).transform.Translate(Vector3.left * num5);
			}
			if (Input.GetKeyDown((KeyCode)275))
			{
				((Component)component).transform.Translate(Vector3.right * num5);
			}
			try
			{
				isValidPlacement();
			}
			catch
			{
			}
		}

		private static void isValidPlacement()
		{
			//IL_0007: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Invalid comparison between Unknown and I4
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			PlayerInstance.m_placementStatus = (PlacementStatus)0;
			if (component.m_groundOnly || component.m_groundPiece || component.m_cultivatedGroundOnly)
			{
				PlayerInstance.m_placementMarkerInstance.SetActive(false);
			}
			StationExtension val = ((Component)component).GetComponent<StationExtension>();
			if ((Object)(object)val != (Object)null)
			{
				CraftingStation val2 = val.FindClosestStationInRange(((Component)component).transform.position);
				if (Object.op_Implicit((Object)(object)val2))
				{
					val.StartConnectionEffect(val2, 1f);
				}
				else
				{
					val.StopConnectionEffect();
					PlayerInstance.m_placementStatus = (PlacementStatus)7;
				}
				if (val.OtherExtensionInRange(component.m_spaceRequirement))
				{
					PlayerInstance.m_placementStatus = (PlacementStatus)5;
				}
			}
			if (component.m_onlyInTeleportArea && !Object.op_Implicit((Object)(object)EffectArea.IsPointInsideArea(((Component)component).transform.position, (Type)16, 0f)))
			{
				PlayerInstance.m_placementStatus = (PlacementStatus)6;
			}
			if (!component.m_allowedInDungeons && ((Component)component).transform.position.y > 3000f)
			{
				PlayerInstance.m_placementStatus = (PlacementStatus)11;
			}
			if (Location.IsInsideNoBuildLocation(PlayerInstance.m_placementGhost.transform.position))
			{
				PlayerInstance.m_placementStatus = (PlacementStatus)3;
			}
			float num = (Object.op_Implicit((Object)(object)((Component)component).GetComponent<PrivateArea>()) ? ((Component)component).GetComponent<PrivateArea>().m_radius : 0f);
			if (!PrivateArea.CheckAccess(PlayerInstance.m_placementGhost.transform.position, num, true, false))
			{
				PlayerInstance.m_placementStatus = (PlacementStatus)4;
			}
			if ((int)PlayerInstance.m_placementStatus > 0)
			{
				component.SetInvalidPlacementHeightlight(true);
			}
			else
			{
				component.SetInvalidPlacementHeightlight(false);
			}
		}

		private static void startMode()
		{
			notifyUser("Starting ABM", (MessageType)1);
			isActive = true;
			component = PlayerInstance.m_placementGhost.GetComponent<Piece>();
		}

		private static void exitMode()
		{
			notifyUser("Exiting ABM", (MessageType)1);
			exitOnNextIteration = true;
			isActive = false;
			component = null;
		}

		private static bool isInBuildMode()
		{
			return ((Character)PlayerInstance).InPlaceMode();
		}

		private static GameObject selectedPrefab()
		{
			if ((Object)(object)PlayerInstance.m_buildPieces != (Object)null)
			{
				try
				{
					return PlayerInstance.m_buildPieces.GetSelectedPrefab();
				}
				catch
				{
					return null;
				}
			}
			return null;
		}

		private static bool IsHoeOrTerrainTool(GameObject selectedPrefab)
		{
			string[] source = new string[4] { "paved_road", "mud_road", "raise", "path" };
			string[] source2 = new string[2] { "cultivate", "replant" };
			if (((Object)selectedPrefab).name.ToLower().Contains("sapling"))
			{
				return true;
			}
			if (source.Contains(((Object)selectedPrefab).name) || source2.Contains(((Object)selectedPrefab).name))
			{
				return true;
			}
			return false;
		}

		private static void notifyUser(string Message, MessageType position = 1)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			MessageHud.instance.ShowMessage(position, "ABM: " + Message, 0, (Sprite)null);
		}

		private static void isRunning()
		{
			if (isActive)
			{
				MessageHud.instance.ShowMessage((MessageType)2, "ABM is active", 0, (Sprite)null);
			}
		}

		private static void changeModificationSpeed()
		{
			//IL_0022: 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)
			float num = 1f;
			if (shiftFlag)
			{
				num = 10f;
			}
			if (Input.GetKeyDown(Configuration.Current.AdvancedBuildingMode.increaseScrollSpeed))
			{
				currentModificationSpeed = Mathf.Clamp(currentModificationSpeed + num, 1f, 30f);
				notifyUser("Modification Speed: " + currentModificationSpeed, (MessageType)1);
			}
			if (Input.GetKeyDown(Configuration.Current.AdvancedBuildingMode.decreaseScrollSpeed))
			{
				currentModificationSpeed = Mathf.Clamp(currentModificationSpeed - num, 1f, 30f);
				notifyUser("Modification Speed: " + currentModificationSpeed, (MessageType)1);
			}
		}
	}
	internal class AEM
	{
		public static bool isActive;

		public static Player PlayerInstance;

		private static bool controlFlag;

		private static bool shiftFlag;

		private static bool altFlag;

		public static Vector3 HitPoint;

		public static Vector3 HitNormal;

		public static Piece HitPiece;

		public static GameObject HitObject;

		public static Heightmap HitHeightmap;

		private static Quaternion InitialRotation;

		private static Vector3 InitialPosition;

		private static bool isInExistence;

		private const float BASE_TRANSLATION_DISTANCE = 0.1f;

		private const float BASE_ROTATION_ANGLE_DEGREES = 3f;

		private static float currentModificationSpeed = 1f;

		private const float MIN_MODIFICATION_SPEED = 1f;

		private const float MAX_MODIFICATION_SPEED = 30f;

		private static Quaternion savedRotation;

		public static bool forceExitNextIteration;

		public static bool ExecuteRayCast(Player playerInstance)
		{
			//IL_0012: 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)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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)
			int placeRayMask = playerInstance.m_placeRayMask;
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val, 50f, placeRayMask) && Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).collider) && !Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).collider.attachedRigidbody) && Vector3.Distance(Helper.getPlayerCharacter(playerInstance).m_eye.position, ((RaycastHit)(ref val)).point) < playerInstance.m_maxPlaceDistance)
			{
				HitPoint = ((RaycastHit)(ref val)).point;
				HitNormal = ((RaycastHit)(ref val)).normal;
				HitPiece = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Piece>();
				HitObject = ((Component)((RaycastHit)(ref val)).collider).gameObject;
				HitHeightmap = ((Component)((RaycastHit)(ref val)).collider).GetComponent<Heightmap>();
				InitialRotation = ((Component)HitPiece).transform.rotation;
				InitialPosition = ((Component)HitPiece).transform.position;
				return isValidRayCastTarget();
			}
			resetObjectInfo();
			return false;
		}

		public static bool checkForObject()
		{
			if ((Object)(object)PlayerInstance == (Object)null)
			{
				return false;
			}
			if (!ExecuteRayCast(PlayerInstance))
			{
				return false;
			}
			return true;
		}

		public static void run()
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if (forceExitNextIteration)
			{
				forceExitNextIteration = false;
				resetObjectInfo();
				isActive = false;
				return;
			}
			if (isInBuildMode())
			{
				if (isActive)
				{
					exitMode();
					resetObjectTransform();
				}
				return;
			}
			if (ABM.isActive)
			{
				if (isActive)
				{
					exitMode();
					resetObjectTransform();
				}
				return;
			}
			if (!isActive && Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.enterAdvancedEditingMode))
			{
				if (checkForObject())
				{
					startMode();
				}
				return;
			}
			if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.abortAndExitAdvancedEditingMode))
			{
				exitMode();
				resetObjectTransform();
			}
			if (!isActive)
			{
				return;
			}
			if (hitPieceStillExists())
			{
				try
				{
					ZNetView component = ((Component)HitPiece).GetComponent<ZNetView>();
					if ((Object)(object)component == (Object)null)
					{
						ValheimPlusPlugin.Logger.LogWarning((object)"AEM: Error, network object empty. Code: 2.");
						exitMode();
						return;
					}
				}
				catch
				{
					ValheimPlusPlugin.Logger.LogWarning((object)"AEM: Error, network object empty. Code: 3.");
					exitMode();
				}
				isRunning();
				listenToHotKeysAndDoWork();
			}
			else
			{
				exitMode();
			}
		}

		private static void listenToHotKeysAndDoWork()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_055a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_053a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0541: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0498: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_059c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0612: Unknown result type (might be due to invalid IL or missing references)
			//IL_0619: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			float num2 = 0f;
			float num3 = 0f;
			if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.resetAdvancedEditingMode))
			{
				resetObjectTransform();
			}
			if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.confirmPlacementOfAdvancedEditingMode))
			{
				if (isContainer())
				{
					dropContainerContents();
				}
				GameObject val = Object.Instantiate<GameObject>(((Component)HitPiece).gameObject, ((Component)HitPiece).transform.position, ((Component)HitPiece).transform.rotation);
				HitPiece.m_placeEffect.Create(((Component)HitPiece).transform.position, ((Component)HitPiece).transform.rotation, val.transform, 1f, -1);
				ZNetView component = ((Component)HitPiece).GetComponent<ZNetView>();
				if ((Object)(object)component == (Object)null)
				{
					ValheimPlusPlugin.Logger.LogWarning((object)"AEM: Error, network object empty.");
					resetObjectTransform();
					exitMode();
				}
				else
				{
					component.ClaimOwnership();
					ZNetScene.instance.Destroy(((Component)HitPiece).gameObject);
					ValheimPlusPlugin.Logger.LogInfo((object)"AEM: Executed.");
					exitMode();
				}
				return;
			}
			if (Input.GetKeyDown((KeyCode)306))
			{
				controlFlag = true;
			}
			if (Input.GetKeyUp((KeyCode)306))
			{
				controlFlag = false;
			}
			if (Input.GetKeyDown((KeyCode)304))
			{
				shiftFlag = true;
			}
			if (Input.GetKeyUp((KeyCode)304))
			{
				shiftFlag = false;
			}
			if (Input.GetKeyDown((KeyCode)308))
			{
				altFlag = true;
			}
			if (Input.GetKeyUp((KeyCode)308))
			{
				altFlag = false;
			}
			changeModificationSpeed();
			if (Input.GetKeyUp(Configuration.Current.AdvancedEditingMode.copyObjectRotation))
			{
				savedRotation = ((Component)HitPiece).transform.rotation;
			}
			if (Input.GetKeyUp(Configuration.Current.AdvancedEditingMode.pasteObjectRotation))
			{
				((Component)HitPiece).transform.rotation = savedRotation;
			}
			if (Vector3.Distance(((Component)PlayerInstance).transform.position, ((Component)HitPiece).transform.position) > PlayerInstance.m_maxPlaceDistance)
			{
				resetObjectTransform();
				exitMode();
			}
			float num4 = 3f * currentModificationSpeed;
			if (Input.GetAxis("Mouse ScrollWheel") > 0f)
			{
				Quaternion rotation;
				if (controlFlag)
				{
					num += 1f;
					rotation = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x + num4 * num, ((Component)HitPiece).transform.eulerAngles.y, ((Component)HitPiece).transform.eulerAngles.z);
				}
				else if (altFlag)
				{
					num2 += 1f;
					rotation = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x, ((Component)HitPiece).transform.eulerAngles.y, ((Component)HitPiece).transform.eulerAngles.z + num4 * num2);
				}
				else
				{
					num3 += 1f;
					rotation = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x, ((Component)HitPiece).transform.eulerAngles.y + num4 * num3, ((Component)HitPiece).transform.eulerAngles.z);
				}
				((Component)HitPiece).transform.rotation = rotation;
			}
			if (Input.GetAxis("Mouse ScrollWheel") < 0f)
			{
				Quaternion rotation2;
				if (controlFlag)
				{
					num -= 1f;
					rotation2 = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x + num4 * num, ((Component)HitPiece).transform.eulerAngles.y, ((Component)HitPiece).transform.eulerAngles.z);
				}
				else if (altFlag)
				{
					num2 -= 1f;
					rotation2 = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x, ((Component)HitPiece).transform.eulerAngles.y, ((Component)HitPiece).transform.eulerAngles.z + num4 * num2);
				}
				else
				{
					num3 -= 1f;
					rotation2 = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x, ((Component)HitPiece).transform.eulerAngles.y + num4 * num3, ((Component)HitPiece).transform.eulerAngles.z);
				}
				((Component)HitPiece).transform.rotation = rotation2;
			}
			float num5 = 0.1f * currentModificationSpeed;
			if (Input.GetKeyDown((KeyCode)273))
			{
				if (controlFlag)
				{
					((Component)HitPiece).transform.Translate(Vector3.up * num5);
				}
				else
				{
					((Component)HitPiece).transform.Translate(Vector3.forward * num5);
				}
			}
			if (Input.GetKeyDown((KeyCode)274))
			{
				if (controlFlag)
				{
					((Component)HitPiece).transform.Translate(Vector3.down * num5);
				}
				else
				{
					((Component)HitPiece).transform.Translate(Vector3.back * num5);
				}
			}
			if (Input.GetKeyDown((KeyCode)276))
			{
				((Component)HitPiece).transform.Translate(Vector3.left * num5);
			}
			if (Input.GetKeyDown((KeyCode)275))
			{
				((Component)HitPiece).transform.Translate(Vector3.right * num5);
			}
		}

		private static bool hitPieceStillExists()
		{
			try
			{
				if (isActive)
				{
					isInExistence = true;
				}
			}
			catch
			{
				isInExistence = false;
			}
			return isInExistence;
		}

		private static bool isValidRayCastTarget()
		{
			//IL_0019: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			bool result = true;
			if (HitPiece.m_onlyInTeleportArea && !Object.op_Implicit((Object)(object)EffectArea.IsPointInsideArea(((Component)HitPiece).transform.position, (Type)16, 0f)))
			{
				result = false;
			}
			if (!HitPiece.m_allowedInDungeons && ((Component)HitPiece).transform.position.y > 3000f)
			{
				result = false;
			}
			if (Location.IsInsideNoBuildLocation(((Component)HitPiece).transform.position))
			{
				result = false;
			}
			float num = (Object.op_Implicit((Object)(object)((Component)HitPiece).GetComponent<PrivateArea>()) ? ((Component)HitPiece).GetComponent<PrivateArea>().m_radius : 0f);
			if (!PrivateArea.CheckAccess(((Component)HitPiece).transform.position, num, true, false))
			{
				result = false;
			}
			return result;
		}

		private static bool isInBuildMode()
		{
			return ((Character)PlayerInstance).InPlaceMode();
		}

		private static void resetObjectTransform()
		{
			//IL_0017: 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)
			notifyUser("Object has been reset to initial position & rotation.", (MessageType)1);
			((Component)HitPiece).transform.position = InitialPosition;
			((Component)HitPiece).transform.rotation = InitialRotation;
		}

		private static void resetObjectInfo()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			HitPoint = Vector3.zero;
			HitNormal = Vector3.zero;
			HitObject = null;
			HitPiece = null;
			HitHeightmap = null;
			InitialRotation = default(Quaternion);
			InitialPosition = default(Vector3);
		}

		private static void startMode()
		{
			notifyUser("Entering AEM", (MessageType)1);
			isActive = true;
		}

		private static void exitMode()
		{
			notifyUser("Exiting AEM", (MessageType)1);
			forceExitNextIteration = true;
		}

		private static void notifyUser(string Message, MessageType position = 1)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			MessageHud.instance.ShowMessage(position, "AEM: " + Message, 0, (Sprite)null);
		}

		private static void isRunning()
		{
			if (isActive)
			{
				MessageHud.instance.ShowMessage((MessageType)2, "AEM is active", 0, (Sprite)null);
			}
		}

		private static bool isContainer()
		{
			Container component = ((Component)HitPiece).GetComponent<Container>();
			return (Object)(object)component != (Object)null;
		}

		private static void dropContainerContents()
		{
			Container component = ((Component)HitPiece).GetComponent<Container>();
			component.DropAllItems();
		}

		private static void changeModificationSpeed()
		{
			//IL_0022: 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)
			float num = 1f;
			if (shiftFlag)
			{
				num = 10f;
			}
			if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.increaseScrollSpeed))
			{
				currentModificationSpeed = Mathf.Clamp(currentModificationSpeed + num, 1f, 30f);
				notifyUser("Modification Speed: " + currentModificationSpeed, (MessageType)1);
			}
			if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.decreaseScrollSpeed))
			{
				currentModificationSpeed = Mathf.Clamp(currentModificationSpeed - num, 1f, 30f);
				notifyUser("Modification Speed: " + currentModificationSpeed, (MessageType)1);
			}
		}
	}
	public class FreePlacementRotation
	{
		private class PlayerData
		{
			public Vector3 PlaceRotation = Vector3.zero;

			public bool Opposite;

			public Piece LastPiece;

			public KeyCode LastKeyCode;
		}

		[HarmonyPatch(typeof(Player), "UpdatePlacement")]
		public static class ModifyPUpdatePlacement
		{
			private static void Postfix(Player __instance, bool takeInput, float dt)
			{
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				if (Configuration.Current.FreePlacementRotation.IsEnabled && !ABM.isActive && ((Character)__instance).InPlaceMode() && takeInput && !Hud.IsPieceSelectionVisible())
				{
					if (!PlayersData.ContainsKey(__instance))
					{
						PlayersData[__instance] = new PlayerData();
					}
					RotateWithWheel(__instance);
					SyncRotationWithTargetInFront(__instance, Configuration.Current.FreePlacementRotation.copyRotationParallel, perpendicular: false);
					SyncRotationWithTargetInFront(__instance, Configuration.Current.FreePlacementRotation.copyRotationPerpendicular, perpendicular: true);
				}
			}

			private static void RotateWithWheel(Player __instance)
			{
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: 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_0066: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ca: 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_014d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0152: Unknown result type (might be due to invalid IL or missing references)
				//IL_0162: Unknown result type (might be due to invalid IL or missing references)
				//IL_0167: Unknown result type (might be due to invalid IL or missing references)
				//IL_013b: 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)
				//IL_00ef: 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)
				//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_0109: Unknown result type (might be due to invalid IL or missing references)
				float axis = Input.GetAxis("Mouse ScrollWheel");
				PlayerData playerData = PlayersData[__instance];
				if (!axis.Equals(0f) || ZInput.GetButton("JoyRotate"))
				{
					if (Input.GetKey(Configuration.Current.FreePlacementRotation.rotateY))
					{
						playerData.PlaceRotation += Vector3.up * Mathf.Sign(axis);
						__instance.m_placeRotation = (int)(playerData.PlaceRotation.y / 22.5f);
					}
					else if (Input.GetKey(Configuration.Current.FreePlacementRotation.rotateX))
					{
						playerData.PlaceRotation += Vector3.right * Mathf.Sign(axis);
					}
					else if (Input.GetKey(Configuration.Current.FreePlacementRotation.rotateZ))
					{
						playerData.PlaceRotation += Vector3.forward * Mathf.Sign(axis);
					}
					else
					{
						__instance.m_placeRotation = ClampPlaceRotation(__instance.m_placeRotation);
						playerData.PlaceRotation = new Vector3(0f, (float)__instance.m_placeRotation * 22.5f, 0f);
					}
					playerData.PlaceRotation = ClampAngles(playerData.PlaceRotation);
					ManualLogSource logger = ValheimPlusPlugin.Logger;
					Vector3 placeRotation = playerData.PlaceRotation;
					logger.LogInfo((object)("Angle " + ((object)(Vector3)(ref placeRotation)).ToString()));
				}
			}

			private static void SyncRotationWithTargetInFront(Player __instance, KeyCode keyCode, bool perpendicular)
			{
				//IL_0016: 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_0065: 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)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_0109: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = default(Vector3);
				Vector3 val2 = default(Vector3);
				Piece val3 = default(Piece);
				Heightmap val4 = default(Heightmap);
				Collider val5 = default(Collider);
				if (!((Object)(object)__instance.m_placementGhost == (Object)null) && Input.GetKeyUp(keyCode) && __instance.PieceRayTest(ref val, ref val2, ref val3, ref val4, ref val5, false) && (Object)(object)val3 != (Object)null)
				{
					PlayerData playerData = PlayersData[__instance];
					Quaternion val6 = ((Component)val3).transform.rotation;
					if (perpendicular)
					{
						val6 *= Quaternion.Euler(0f, 90f, 0f);
					}
					if (playerData.LastKeyCode != keyCode || (Object)(object)playerData.LastPiece != (Object)(object)val3)
					{
						playerData.Opposite = false;
					}
					playerData.LastKeyCode = keyCode;
					playerData.LastPiece = val3;
					if (playerData.Opposite)
					{
						val6 *= Quaternion.Euler(0f, 180f, 0f);
					}
					playerData.Opposite = !playerData.Opposite;
					playerData.PlaceRotation = ((Quaternion)(ref val6)).eulerAngles;
					ManualLogSource logger = ValheimPlusPlugin.Logger;
					Vector3 placeRotation = playerData.PlaceRotation;
					logger.LogInfo((object)("Sync Angle " + ((object)(Vector3)(ref placeRotation)).ToString()));
				}
			}
		}

		[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
		public static class ModifyPlacingRestrictionOfGhost
		{
			private static void Postfix(Player __instance, bool flashGuardStone)
			{
				if (Configuration.Current.FreePlacementRotation.IsEnabled && !ABM.isActive)
				{
					UpdatePlacementGhost(__instance, flashGuardStone);
				}
			}

			private static void UpdatePlacementGhost(Player __instance, bool flashGuardStone)
			{
				//IL_0094: Unknown result type (might be due to invalid IL or missing references)
				//IL_07f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_07fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0804: Invalid comparison between Unknown and I4
				//IL_0156: Unknown result type (might be due to invalid IL or missing references)
				//IL_018a: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_020f: Unknown result type (might be due to invalid IL or missing references)
				//IL_023d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0262: Unknown result type (might be due to invalid IL or missing references)
				//IL_027b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0294: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_02be: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c4: Invalid comparison between Unknown and I4
				//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_030c: Unknown result type (might be due to invalid IL or missing references)
				//IL_032a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0337: Unknown result type (might be due to invalid IL or missing references)
				//IL_0355: Unknown result type (might be due to invalid IL or missing references)
				//IL_0362: Unknown result type (might be due to invalid IL or missing references)
				//IL_0383: Unknown result type (might be due to invalid IL or missing references)
				//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0400: Unknown result type (might be due to invalid IL or missing references)
				//IL_0402: Unknown result type (might be due to invalid IL or missing references)
				//IL_0407: Unknown result type (might be due to invalid IL or missing references)
				//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0503: Unknown result type (might be due to invalid IL or missing references)
				//IL_0519: Unknown result type (might be due to invalid IL or missing references)
				//IL_0521: Unknown result type (might be due to invalid IL or missing references)
				//IL_0526: Unknown result type (might be due to invalid IL or missing references)
				//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_05cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_04be: Unknown result type (might be due to invalid IL or missing references)
				//IL_048a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0717: Unknown result type (might be due to invalid IL or missing references)
				//IL_0707: Unknown result type (might be due to invalid IL or missing references)
				//IL_066c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0671: Unknown result type (might be due to invalid IL or missing references)
				//IL_0675: Unknown result type (might be due to invalid IL or missing references)
				//IL_067c: Unknown result type (might be due to invalid IL or missing references)
				//IL_068c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0691: Unknown result type (might be due to invalid IL or missing references)
				//IL_0696: Unknown result type (might be due to invalid IL or missing references)
				//IL_069b: Unknown result type (might be due to invalid IL or missing references)
				//IL_069e: Unknown result type (might be due to invalid IL or missing references)
				//IL_06ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_05ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_0601: Unknown result type (might be due to invalid IL or missing references)
				//IL_0617: Unknown result type (might be due to invalid IL or missing references)
				//IL_06e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_074d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0766: Unknown result type (might be due to invalid IL or missing references)
				//IL_0760: Unknown result type (might be due to invalid IL or missing references)
				//IL_0778: Unknown result type (might be due to invalid IL or missing references)
				//IL_077d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0783: Unknown result type (might be due to invalid IL or missing references)
				//IL_0788: Unknown result type (might be due to invalid IL or missing references)
				//IL_078a: Invalid comparison between Unknown and I4
				//IL_0581: Unknown result type (might be due to invalid IL or missing references)
				//IL_0583: Unknown result type (might be due to invalid IL or missing references)
				//IL_0588: Unknown result type (might be due to invalid IL or missing references)
				//IL_058a: Unknown result type (might be due to invalid IL or missing references)
				//IL_058c: Unknown result type (might be due to invalid IL or missing references)
				//IL_05a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0797: Unknown result type (might be due to invalid IL or missing references)
				//IL_07c0: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__instance.m_placementGhost == (Object)null)
				{
					if (Object.op_Implicit((Object)(object)__instance.m_placementMarkerInstance))
					{
						__instance.m_placementMarkerInstance.SetActive(false);
					}
					return;
				}
				bool flag = ZInput.GetButton("AltPlace") || ZInput.GetButton("JoyAltPlace");
				Piece component = __instance.m_placementGhost.GetComponent<Piece>();
				bool flag2 = component.m_waterPiece || component.m_noInWater;
				Vector3 val = default(Vector3);
				Vector3 up = default(Vector3);
				Piece val2 = default(Piece);
				Heightmap val3 = default(Heightmap);
				Collider val4 = default(Collider);
				if (__instance.PieceRayTest(ref val, ref up, ref val2, ref val3, ref val4, flag2))
				{
					__instance.m_placementStatus = (PlacementStatus)0;
					if ((Object)(object)__instance.m_placementMarkerInstance == (Object)null)
					{
						__instance.m_placementMarkerInstance = Object.Instantiate<GameObject>(__instance.m_placeMarker, val, Quaternion.identity);
					}
					__instance.m_placementMarkerInstance.SetActive(true);
					__instance.m_placementMarkerInstance.transform.position = val;
					__instance.m_placementMarkerInstance.transform.rotation = Quaternion.LookRotation(up);
					if (component.m_groundOnly || component.m_groundPiece || component.m_cultivatedGroundOnly)
					{
						__instance.m_placementMarkerInstance.SetActive(false);
					}
					WearNTear val5 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<WearNTear>() : null);
					StationExtension component2 = ((Component)component).GetComponent<StationExtension>();
					if ((Object)(object)component2 != (Object)null)
					{
						CraftingStation val6 = component2.FindClosestStationInRange(val);
						if (Object.op_Implicit((Object)(object)val6))
						{
							component2.StartConnectionEffect(val6, 1f);
						}
						else
						{
							component2.StopConnectionEffect();
							__instance.m_placementStatus = (PlacementStatus)7;
						}
						if (component2.OtherExtensionInRange(component.m_spaceRequirement))
						{
							__instance.m_placementStatus = (PlacementStatus)5;
						}
					}
					if (Object.op_Implicit((Object)(object)val5) && !val5.m_supports)
					{
						__instance.m_placementStatus = (PlacementStatus)1;
					}
					if (component.m_waterPiece && (Object)(object)val4 == (Object)null && !flag)
					{
						__instance.m_placementStatus = (PlacementStatus)1;
					}
					if (component.m_noInWater && (Object)(object)val4 != (Object)null)
					{
						__instance.m_placementStatus = (PlacementStatus)1;
					}
					if (component.m_groundPiece && (Object)(object)val3 == (Object)null)
					{
						__instance.m_placementGhost.SetActive(false);
						__instance.m_placementStatus = (PlacementStatus)1;
						return;
					}
					if (component.m_groundOnly && (Object)(object)val3 == (Object)null)
					{
						__instance.m_placementStatus = (PlacementStatus)1;
					}
					if (component.m_cultivatedGroundOnly && ((Object)(object)val3 == (Object)null || !val3.IsCultivated(val)))
					{
						__instance.m_placementStatus = (PlacementStatus)9;
					}
					if (component.m_notOnWood && Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val5) && ((int)val5.m_materialType == 0 || (int)val5.m_materialType == 3))
					{
						__instance.m_placementStatus = (PlacementStatus)1;
					}
					if (component.m_notOnTiltingSurface && (double)up.y < 0.800000011920929)
					{
						__instance.m_placementStatus = (PlacementStatus)1;
					}
					if (component.m_inCeilingOnly && (double)up.y > -0.5)
					{
						__instance.m_placementStatus = (PlacementStatus)1;
					}
					if (component.m_notOnFloor && (double)up.y > 0.100000001490116)
					{
						__instance.m_placementStatus = (PlacementStatus)1;
					}
					if (component.m_onlyInTeleportArea && !Object.op_Implicit((Object)(object)EffectArea.IsPointInsideArea(val, (Type)16, 0f)))
					{
						__instance.m_placementStatus = (PlacementStatus)6;
					}
					if (!component.m_allowedInDungeons && ((Character)__instance).InInterior())
					{
						__instance.m_placementStatus = (PlacementStatus)11;
					}
					if (Object.op_Implicit((Object)(object)val3))
					{
						up = Vector3.up;
					}
					__instance.m_placementGhost.SetActive(true);
					Vector3 val7 = (PlayersData.ContainsKey(__instance) ? PlayersData[__instance].PlaceRotation : ((float)__instance.m_placeRotation * 22.5f * Vector3.up));
					Quaternion rotation = Quaternion.Euler(val7);
					if (((component.m_groundPiece || component.m_clipGround) && Object.op_Implicit((Object)(object)val3)) || component.m_clipEverything)
					{
						if (Object.op_Implicit((Object)(object)__instance.m_buildPieces.GetSelectedPrefab().GetComponent<TerrainModifier>()) && component.m_allowAltGroundPlacement && component.m_groundPiece && !ZInput.GetButton("AltPlace") && !ZInput.GetButton("JoyAltPlace"))
						{
							float groundHeight = ZoneSystem.instance.GetGroundHeight(((Component)__instance).transform.position);
							val.y = groundHeight;
						}
						__instance.m_placementGhost.transform.position = val;
						__instance.m_placementGhost.transform.rotation = rotation;
					}
					else
					{
						Collider[] componentsInChildren = __instance.m_placementGhost.GetComponentsInChildren<Collider>();
						if (componentsInChildren.Length != 0)
						{
							__instance.m_placementGhost.transform.position = val + up * 50f;
							__instance.m_placementGhost.transform.rotation = rotation;
							Vector3 val8 = Vector3.zero;
							float num = 999999f;
							Collider[] array = componentsInChildren;
							foreach (Collider val9 in array)
							{
								if (val9.isTrigger || !val9.enabled)
								{
									continue;
								}
								MeshCollider val10 = (MeshCollider)(object)((val9 is MeshCollider) ? val9 : null);
								if (!((Object)(object)val10 != (Object)null) || val10.convex)
								{
									Vector3 val11 = val9.ClosestPoint(val);
									float num2 = Vector3.Distance(val11, val);
									if ((double)num2 < (double)num)
									{
										val8 = val11;
										num = num2;
									}
								}
							}
							Vector3 val12 = __instance.m_placementGhost.transform.position - val8;
							if (component.m_waterPiece)
							{
								val12.y = 3f;
							}
							__instance.m_placementGhost.transform.position = val + val12;
							__instance.m_placementGhost.transform.rotation = rotation;
						}
					}
					if (!flag)
					{
						__instance.m_tempPieces.Clear();
						Transform val13 = default(Transform);
						Transform val14 = default(Transform);
						if (__instance.FindClosestSnapPoints(__instance.m_placementGhost.transform, 0.5f, ref val13, ref val14, __instance.m_tempPieces))
						{
							Vector3 position = val14.parent.position;
							Vector3 val15 = val14.position - (val13.position - __instance.m_placementGhost.transform.position);
							if (!__instance.IsOverlappingOtherPiece(val15, __instance.m_placementGhost.transform.rotation, ((Object)__instance.m_placementGhost).name, __instance.m_tempPieces, component.m_allowRotatedOverlap))
							{
								__instance.m_placementGhost.transform.position = val15;
							}
						}
					}
					if (Location.IsInsideNoBuildLocation(__instance.m_placementGhost.transform.position))
					{
						__instance.m_placementStatus = (PlacementStatus)3;
					}
					if (!PrivateArea.CheckAccess(__instance.m_placementGhost.transform.position, Object.op_Implicit((Object)(object)((Component)component).GetComponent<PrivateArea>()) ? ((Component)component).GetComponent<PrivateArea>().m_radius : 0f, flashGuardStone, false))
					{
						__instance.m_placementStatus = (PlacementStatus)4;
					}
					if (__instance.CheckPlacementGhostVSPlayers())
					{
						__instance.m_placementStatus = (PlacementStatus)2;
					}
					if ((int)component.m_onlyInBiome != 0 && (Heightmap.FindBiome(__instance.m_placementGhost.transform.position) & component.m_onlyInBiome) == 0)
					{
						__instance.m_placementStatus = (PlacementStatus)8;
					}
					if (component.m_noClipping && __instance.TestGhostClipping(__instance.m_placementGhost, 0.2f))
					{
						__instance.m_placementStatus = (PlacementStatus)1;
					}
				}
				else
				{
					if (Object.op_Implicit((Object)(object)__instance.m_placementMarkerInstance))
					{
						__instance.m_placementMarkerInstance.SetActive(false);
					}
					__instance.m_placementGhost.SetActive(false);
					__instance.m_placementStatus = (PlacementStatus)1;
				}
				__instance.SetPlacementGhostValid((int)__instance.m_placementStatus == 0);
			}
		}

		private static readonly Dictionary<Player, PlayerData> PlayersData = new Dictionary<Player, PlayerData>();

		private static Vector3 ClampAngles(Vector3 angles)
		{
			//IL_0001: 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_0017: 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_0027: 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)
			return new Vector3(ClampAngle(angles.x), ClampAngle(angles.y), ClampAngle(angles.z));
		}

		private static int ClampPlaceRotation(int index)
		{
			if (index < 0)
			{
				index = 16 + index;
			}
			else if (index >= 16)
			{
				index -= 16;
			}
			return index;
		}

		private static float ClampAngle(float angle)
		{
			if (angle < 0f)
			{
				angle = 360f + angle;
			}
			else if (angle >= 360f)
			{
				angle -= 360f;
			}
			return angle;
		}
	}
	[HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")]
	public static class CharacterDrop_GenerateDropList_Patch
	{
		private static void Prefix(ref List<Drop> ___m_drops, ref List<Drop> __state)
		{
			if (Configuration.Current.LootDrop.IsEnabled)
			{
				__state = ___m_drops;
				ItemDrop val = default(ItemDrop);
				___m_drops = ___m_drops.ConvertAll((Drop originalDrop) => (Drop)((!originalDrop.m_prefab.TryGetComponent<ItemDrop>(ref val)) ? ((object)originalDrop) : ((object)new Drop
				{
					m_prefab = originalDrop.m_prefab,
					m_amountMin = (int)Helper.applyModifierValue(originalDrop.m_amountMin, Configuration.Current.LootDrop.lootDropAmountMultiplier),
					m_amountMax = (int)Helper.applyModifierValue(originalDrop.m_amountMax, Configuration.Current.LootDrop.lootDropAmountMultiplier),
					m_chance = Helper.applyModifierValue(originalDrop.m_chance, Configuration.Current.LootDrop.lootDropChanceMultiplier),
					m_onePerPlayer = originalDrop.m_onePerPlayer,
					m_levelMultiplier = originalDrop.m_levelMultiplier
				})));
			}
		}

		private static void Postfix(ref List<Drop> ___m_drops, List<Drop> __state)
		{
			if (Configuration.Current.LootDrop.IsEnabled)
			{
				___m_drops = __state;
			}
		}
	}
	[HarmonyPatch(typeof(Hud), "DamageFlash")]
	public static class Hud_DamageFlash_Patch
	{
		private static void Postfix(Hud __instance)
		{
			if (Configuration.Current.Hud.IsEnabled && Configuration.Current.Hud.removeDamageFlash)
			{
				((Component)__instance.m_damageScreen).gameObject.SetActive(false);
			}
		}
	}
	[HarmonyPatch(typeof(SE_Rested), "UpdateTTL")]
	public static class SE_Rested_UpdateTTL_Patch
	{
		[HarmonyPrefix]
		public static void Prefix(ref float ___m_TTLPerComfortLevel)
		{
			if (Configuration.Current.Player.IsEnabled)
			{
				___m_TTLPerComfortLevel = Configuration.Current.Player.restSecondsPerComfortLevel;
			}
		}
	}
	[HarmonyPatch(typeof(SE_Rested), "GetNearbyComfortPieces")]
	public static class SE_Rested_GetNearbyPieces_Transpiler
	{
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			if (!Configuration.Current.Building.IsEnabled || Configuration.Current.Building.pieceComfortRadius == 10f)
			{
				return instructions;
			}
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_R4)
				{
					list[i].operand = Mathf.Clamp(Configuration.Current.Building.pieceComfortRadius, 1f, 300f);
				}
			}
			return list.AsEnumerable();
		}
	}
	[HarmonyPatch(typeof(SE_Rested), "GetNearbyComfortPieces")]
	public static class SE_Rested_GetNearbyComfortPieces_Transpiler
	{
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			if (!Configuration.Current.Building.IsEnabled || Configuration.Current.Building.pieceComfortRadius == 10f)
			{
				return instructions;
			}
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_R4)
				{
					list[i].operand = Mathf.Clamp(Configuration.Current.Building.pieceComfortRadius, 1f, 300f);
				}
			}
			return list.AsEnumerable();
		}
	}
	[HarmonyPatch(typeof(Piece), "DropResources")]
	public static class Piece_DropResources_Transpiler
	{
		private static MethodInfo method_Piece_IsPlacedByPlayer = AccessTools.Method(typeof(Piece), "IsPlacedByPlayer", (Type[])null, (Type[])null);

		private static FieldInfo field_Requirement_m_recover = AccessTools.Field(typeof(Requirement), "m_recover");

		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			if (!Configuration.Current.Building.IsEnabled)
			{
				return instructions;
			}
			List<CodeInstruction> list = instructions.ToList();
			if (Configuration.Current.Building.alwaysDropResources)
			{
				for (int i = 0; i < list.Count; i++)
				{
					if (CodeInstructionExtensions.Calls(list[i], method_Piece_IsPlacedByPlayer))
					{
						list[i] = new CodeInstruction(OpCodes.Ldc_I4_1, (object)null);
						list.RemoveAt(i - 1);
					}
				}
			}
			if (Configuration.Current.Building.alwaysDropExcludedResources)
			{
				for (int j = 0; j < list.Count; j++)
				{
					if (CodeInstructionExtensions.LoadsField(list[j], field_Requirement_m_recover, false))
					{
						list.RemoveRange(j - 1, 3);
					}
				}
			}
			return list.AsEnumerable();
		}
	}
	[HarmonyPatch(typeof(StationExtension), "Awake")]
	public static class StationExtension_Awake_Patch
	{
		[HarmonyPrefix]
		public static void Prefix(ref float ___m_maxStationDistance)
		{
			if (Configuration.Current.Workbench.IsEnabled)
			{
				___m_maxStationDistance = Configuration.Current.Workbench.workbenchAttachmentRange;
			}
		}
	}
	internal static class GameObjectAssistant
	{
		private static ConcurrentDictionary<float, Stopwatch> stopwatches = new ConcurrentDictionary<float, Stopwatch>();

		public static Stopwatch GetStopwatch(GameObject o)
		{
			float gameObjectPosHash = GetGameObjectPosHash(o);
			Stopwatch value = null;
			if (!stopwatches.TryGetValue(gameObjectPosHash, out value))
			{
				value = new Stopwatch();
				stopwatches.TryAdd(gameObjectPosHash, value);
			}
			return value;
		}

		private static float GetGameObjectPosHash(GameObject o)
		{
			//IL_000c: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			return 1000f * o.transform.position.x + o.transform.position.y + 0.001f * o.transform.position.z;
		}

		public static T GetChildComponentByName<T>(string name, GameObject objected) where T : Component
		{
			T[] componentsInChildren = objected.GetComponentsInChildren<T>(true);
			foreach (T val in componentsInChildren)
			{
				if (((Object)((Component)val).gameObject).name == name)
				{
					return val;
				}
			}
			return default(T);
		}
	}
	internal static class InventoryAssistant
	{
		public static List<Container> GetNearbyChests(GameObject target, float range, bool checkWard = true)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			string[] array = new string[1] { "piece" };
			if (Configuration.Current.CraftFromChest.allowCraftingFromCarts || Configuration.Current.CraftFromChest.allowCraftingFromShips)
			{
				array = new string[3] { "piece", "item", "vehicle" };
			}
			Collider[] source = Physics.OverlapSphere(target.transform.position, range, LayerMask.GetMask(array));
			IOrderedEnumerable<Collider> orderedEnumerable = source.OrderBy((Collider x) => Vector3.Distance(((Component)x).gameObject.transform.position, target.transform.position));
			List<Container> list = new List<Container>();
			foreach (Collider item in orderedEnumerable)
			{
				try
				{
					Container componentInParent = ((Component)item).GetComponentInParent<Container>();
					if (Object.op_Implicit((Object)(object)componentInParent) && !list.Contains(componentInParent))
					{
						bool flag = componentInParent.CheckAccess(Player.m_localPlayer.GetPlayerID());
						if (checkWard)
						{
							flag = flag && PrivateArea.CheckAccess(((Component)item).gameObject.transform.position, 0f, false, true);
						}
						Piece componentInParent2 = ((Component)componentInParent).GetComponentInParent<Piece>();
						bool flag2 = (Object)(object)((Component)componentInParent).GetComponentInParent<Vagon>() != (Object)null;
						bool flag3 = (Object)(object)((Component)componentInParent).GetComponentInParent<Ship>() != (Object)null;
						if ((Object)(object)componentInParent2 != (Object)null && flag && componentInParent.GetInventory() != null && (!flag2 || Configuration.Current.CraftFromChest.allowCraftingFromCarts) && (!flag3 || Configuration.Current.CraftFromChest.allowCraftingFromShips) && (componentInParent2.IsPlacedByPlayer() || (flag3 && Configuration.Current.CraftFromChest.allowCraftingFromShips)))
						{
							list.Add(componentInParent);
						}
					}
				}
				catch
				{
				}
			}
			return list;
		}

		public static List<Container> GetNearbyChestsWithItem(GameObject target, float range, ItemData itemInfo, bool checkWard = true)
		{
			List<Container> nearbyChests = GetNearbyChests(target, range, checkWard);
			List<Container> list = new List<Container>();
			foreach (Container item in nearbyChests)
			{
				if (ChestContainsItem(item, itemInfo))
				{
					list.Add(item);
				}
			}
			return list;
		}

		public static bool ChestContainsItem(Container chest, ItemData needle)
		{
			List<ItemData> allItems = chest.GetInventory().GetAllItems();
			foreach (ItemData item in allItems)
			{
				if (item.m_shared.m_name == needle.m_shared.m_name)
				{
					return true;
				}
			}
			return false;
		}

		public static bool ChestContainsItem(Container chest, string needle)
		{
			List<ItemData> allItems = chest.GetInventory().GetAllItems();
			foreach (ItemData item in allItems)
			{
				if (item.m_shared.m_name == needle)
				{
					return true;
				}
			}
			return false;
		}

		public static List<ItemData> GetNearbyChestItems(GameObject target, float range = 10f, bool checkWard = true)
		{
			List<ItemData> list = new List<ItemData>();
			List<Container> nearbyChests = GetNearbyChests(target, range, checkWard);
			foreach (Container item in nearbyChests)
			{
				List<ItemData> allItems = item.GetInventory().GetAllItems();
				foreach (ItemData item2 in allItems)
				{
					list.Add(item2);
				}
			}
			return list;
		}

		public static List<ItemData> GetNearbyChestItemsByContainerList(List<Container> nearbyChests)
		{
			List<ItemData> list = new List<ItemData>();
			foreach (Container nearbyChest in nearbyChests)
			{
				List<ItemData> allItems = nearbyChest.GetInventory().GetAllItems();
				foreach (ItemData item in allItems)
				{
					list.Add(item);
				}
			}
			return list;
		}

		public static int GetItemAmountInItemList(List<ItemData> itemList, ItemData needle)
		{
			int num = 0;
			foreach (ItemData item in itemList)
			{
				if (item.m_shared.m_name == needle.m_shared.m_name)
				{
					num += item.m_stack;
				}
			}
			return num;
		}

		public static int GetItemAmountInItemList(List<ItemData> itemList, string needle)
		{
			int num = 0;
			foreach (ItemData item in itemList)
			{
				if (item.m_shared.m_name == needle)
				{
					num += item.m_stack;
				}
			}
			return num;
		}

		public static int RemoveItemInAmountFromAllNearbyChests(GameObject target, float range, ItemData needle, int amount, bool checkWard = true)
		{
			List<Container> nearbyChests = GetNearbyChests(target, range, checkWard);
			List<ItemData> nearbyChestItemsByContainerList = GetNearbyChestItemsByContainerList(nearbyChests);
			int itemAmountInItemList = GetItemAmountInItemList(nearbyChestItemsByContainerList, needle);
			if (amount == 0)
			{
				return 0;
			}
			int num = 0;
			foreach (Container item in nearbyChests)
			{
				if (num != amount)
				{
					int num2 = RemoveItemFromChest(item, needle, amount);
					num += num2;
					amount -= num2;
				}
			}
			return num;
		}

		public static int RemoveItemInAmountFromAllNearbyChests(GameObject target, float range, string needle, int amount, bool checkWard = true)
		{
			List<Container> nearbyChests = GetNearbyChests(target, range, checkWard);
			List<ItemData> nearbyChestItemsByContainerList = GetNearbyChestItemsByContainerList(nearbyChests);
			int itemAmountInItemList = GetItemAmountInItemList(nearbyChestItemsByContainerList, needle);
			if (amount == 0)
			{
				return 0;
			}
			int num = 0;
			foreach (Container item in nearbyChests)
			{
				if (num != amount)
				{
					int num2 = RemoveItemFromChest(item, needle, amount);
					num += num2;
					amount -= num2;
				}
			}
			return num;
		}

		public static int RemoveItemFromChest(Container chest, ItemData needle, int amount = 1)
		{
			if (!ChestContainsItem(chest, needle))
			{
				return 0;
			}
			int num = 0;
			List<ItemData> allItems = chest.GetInventory().GetAllItems();
			foreach (ItemData item in allItems)
			{
				if (item.m_shared.m_name == needle.m_shared.m_name)
				{
					int num2 = Mathf.Min(item.m_stack, amount);
					item.m_stack -= num2;
					amount -= num2;
					num += num2;
					if (amount <= 0)
					{
						break;
					}
				}
			}
			if (num == 0)
			{
				return 0;
			}
			allItems.RemoveAll((ItemData x) => x.m_stack <= 0);
			chest.m_inventory.m_inventory = allItems;
			ConveyContainerToNetwork(chest);
			return num;
		}

		public static int RemoveItemFromChest(Container chest, string needle, int amount = 1)
		{
			if (!ChestContainsItem(chest, needle))
			{
				return 0;
			}
			int num = 0;
			List<ItemData> allItems = chest.GetInventory().GetAllItems();
			foreach (ItemData item in allItems)
			{
				if (item.m_shared.m_name == needle)
				{
					int num2 = Mathf.Min(item.m_stack, amount);
					item.m_stack -= num2;
					amount -= num2;
					num += num2;
					if (amount <= 0)
					{
						break;
					}
				}
			}
			if (num == 0)
			{
				return 0;
			}
			allItems.RemoveAll((ItemData x) => x.m_stack <= 0);
			chest.m_inventory.m_inventory = allItems;
			ConveyContainerToNetwork(chest);
			return num;
		}

		public static void ConveyContainerToNetwork(Container c)
		{
			c.Save();
			c.GetInventory().Changed();
		}
	}
	[BepInPlugin("org.bepinex.plugins.valheim_plus", "Valheim Plus", "0.9.12.0")]
	public class ValheimPlusPlugin : BaseUnityPlugin
	{
		public const string numericVersion = "0.9.12.0";

		public const string versionExtra = "";

		public const string fullVersion = "0.9.12.0";

		public const string minRequiredNumericVersion = "0.9.12.0";

		public static readonly GameVersion minSupportedGameVersion = new GameVersion(0, 217, 36);

		public static readonly GameVersion targetGameVersion = new GameVersion(0, 217, 38);

		public static string newestVersion = "";

		public static bool isUpToDate = false;

		public static System.Timers.Timer mapSyncSaveTimer = new System.Timers.Timer(TimeSpan.FromMinutes(5.0).TotalMilliseconds);

		public static readonly string VPlusDataDirectoryPath;

		private static Harmony harmony;

		public static string Repository;

		public static string ApiRepository;

		public static string iniFile;

		private static object versionCheck;

		public static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Valheim Plus full version: 0.9.12.0");
			Logger.LogInfo((object)"Trying to load the configuration file");
			if (!ConfigurationExtra.LoadSettings())
			{
				Logger.LogError((object)"Error while loading configuration file.");
				return;
			}
			Logger.LogInfo((object)"Configuration file loaded succesfully.");
			PatchAll();
			isUpToDate = !IsNewVersionAvailable();
			if (!isUpToDate)
			{
				Logger.LogWarning((object)("There is a newer version available of ValheimPlus. Please visit " + Repository + "."));
			}
			else
			{
				Logger.LogInfo((object)"ValheimPlus [0.9.12.0] is up to date.");
			}
			if (!Directory.Exists(VPlusDataDirectoryPath))
			{
				Directory.CreateDirectory(VPlusDataDirectoryPath);
			}
			VPlusMainMenu.Load();
			VPlusSettings.Load();
			if (ZNet.m_isServer && Configuration.Current.Map.IsEnabled && Configuration.Current.Map.shareMapProgression)
			{
				mapSyncSaveTimer.AutoReset = true;
				mapSyncSaveTimer.Elapsed += delegate
				{
					VPlusMapSync.SaveMapDataToDisk();
				};
			}
			Logger.LogInfo((object)"ValheimPlus done loading.");
		}

		public static string getCurrentWebIniFile()
		{
			WebClient webClient = new WebClient();
			webClient.Headers.Add("User-Agent: V+ Server");
			try
			{
				Logger.LogInfo((object)("Downloading config from: '" + iniFile + "'"));
				return webClient.DownloadString(iniFile);
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Error downloading config from '{iniFile}': {arg}");
				return null;
			}
		}

		public static bool isGameVersionTooOld()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return Version.CurrentVersion < minSupportedGameVersion;
		}

		public static bool isGameVersionNewerThanTarget()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return Version.CurrentVersion > targetGameVersion;
		}

		public static bool IsNewVersionAvailable()
		{
			WebClient webClient = new WebClient();
			webClient.Headers.Add("User-Agent: V+ Server");
			try
			{
				string input = webClient.DownloadString(ApiRepository);
				newestVersion = new Regex("\"tag_name\":\"([^\"]*)?\"").Match(input).Groups[1].Value;
			}
			catch
			{
				Logger.LogWarning((object)"The newest version could not be determined.");
				newestVersion = "Unknown";
			}
			if (Version.TryParse(newestVersion, out Version result))
			{
				if (Version.TryParse("0.9.12.0", out Version result2))
				{
					if (result2 < result)
					{
						return true;
					}
				}
				else
				{
					Logger.LogWarning((object)"Couldn't parse current version");
				}
			}
			else
			{
				Logger.LogWarning((object)"Couldn't parse newest version, comparing version strings with equality.");
				if (newestVersion != "0.9.12.0")
				{
					return true;
				}
			}
			return false;
		}

		public static void PatchAll()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: 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)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Expected O, but got Unknown
			Logger.LogInfo((object)"Applying patches.");
			try
			{
				harmony.PatchAll();
				harmony.Patch((MethodBase)typeof(ZPlayFabMatchmaking).GetMethod("CreateLobby", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ZPlayFabMatchmaking_CreateLobby_Transpiler).GetMethod("Transpiler")), (HarmonyMethod)null, (HarmonyMethod)null);
				if (AppDomain.CurrentDomain.GetAssemblies().Any((Assembly assembly) => assembly.FullName.Contains("assembly_steamworks")))
				{
					harmony.Patch((MethodBase)AccessTools.TypeByName("SteamGameServer").GetMethod("SetMaxPlayerCount"), new HarmonyMethod(typeof(ChangeSteamServerVariables).GetMethod("Prefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				((VersionCheck)versionCheck).ModRequired = Configuration.Current.Server.enforceMod;
				Logger.LogInfo((object)"Patches successfully applied.");
			}
			catch (Exception ex)
			{
				Logger.LogError((object)"Failed to apply patches.");
				if (isGameVersionTooOld())
				{
					Logger.LogWarning((object)(string.Format("This version of Valheim Plus ({0}) expects a minimum game version of \"{1}\", but this game version is older at \"{2}\". ", "0.9.12.0", minSupportedGameVersion, Version.CurrentVersion) + "Please either update the Valheim game, or use an older version of Valheim Plus as per https://github.com/Grantapher/ValheimPlus/blob/grantapher-development/COMPATIBILITY.md."));
				}
				else if (isGameVersionNewerThanTarget())
				{
					Logger.LogWarning((object)(string.Format("This version of Valheim Plus ({0}) was compiled with a game version of \"{1}\", but this game version is newer at \"{2}\". ", "0.9.12.0", targetGameVersion, Version.CurrentVersion) + "If you are using the PTB, you likely need to use the non-beta version of the game. Otherwise, the errors seen above likely will require the Valheim Plus mod to be updated. If a game update just came out for Valheim, this may take some time for the mod to be updated. See https://github.com/Grantapher/ValheimPlus/blob/grantapher-development/COMPATIBILITY.md for what game versions are compatible with what mod versions."));
				}
				else
				{
					Logger.LogWarning((object)("Valheim Plus failed to apply patches. Please ensure the game version (" + Version.GetVersionString(false) + ") is compatible with the Valheim Plus version (0.9.12.0) at https://github.com/Grantapher/ValheimPlus/blob/grantapher-development/COMPATIBILITY.md. If it already is, please report a bug at https://github.com/Grantapher/ValheimPlus/issues."));
				}
				throw ex;
			}
		}

		public static void UnpatchSelf()
		{
			Logger.LogInfo((object)"Unpatching.");
			try
			{
				harmony.UnpatchSelf();
				Logger.LogInfo((object)"Successfully unpatched.");
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Failed to unpatch. Exception: {arg}");
			}
		}

		static ValheimPlusPlugin()
		{
			//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_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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			string bepInExRootPath = Paths.BepInExRootPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			VPlusDataDirectoryPath = bepInExRootPath + directorySeparatorChar + "vplus-data";
			harmony = new Harmony("mod.valheim_plus");
			Repository = "https://github.com/Grantapher/ValheimPlus/releases/latest";
			ApiRepository = "https://api.github.com/repos/grantapher/valheimPlus/releases/latest";
			iniFile = "https://github.com/Grantapher/ValheimPlus/releases/download/0.9.12.0/valheim_plus.cfg";
			versionCheck = (object)new VersionCheck("org.bepinex.plugins.valheim_plus")
			{
				DisplayName = "Valheim Plus",
				CurrentVersion = "0.9.12.0",
				MinimumRequiredVersion = "0.9.12.0"
			};
		}
	}
	internal static class Helper
	{
		public static Character getPlayerCharacter(Player __instance)
		{
			return (Character)(object)__instance;
		}

		public static Player getPlayerBySenderId(long id)
		{
			//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_0026: 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)
			List<Player> allPlayers = Player.GetAllPlayers();
			foreach (Player item in allPlayers)
			{
				ZDOID zDOID = getPlayerCharacter(item).GetZDOID();
				if (zDOID != new ZDOID(0L, 0u) && ((ZDOID)(ref zDOID)).UserID == id)
				{
					return item;
				}
			}
			return null;
		}

		public static List<CodeInstruction> removeForcedCaseFunctionCalls(List<CodeInstruction> il)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			for (int i = 0; i < il.Count; i++)
			{
				if (il[i].operand != null)
				{
					string text = il[i].operand.ToString();
					if (text.Contains("ToUpper") || text.Contains("ToLower") || text.Contains("ToLowerInvariant"))
					{
						il[i] = new CodeInstruction(OpCodes.Nop, (object)null);
						il[i - 1] = new CodeInstruction(OpCodes.Nop, (object)null);
						il[i + 1] = new CodeInstruction(OpCodes.Nop, (object)null);
					}
				}
			}
			return il;
		}

		public static float tFloat(this float value, int digits)
		{
			double num = Math.Pow(10.0, digits);
			double num2 = Math.Truncate(num * (double)value) / num;
			return (float)num2;
		}

		public static float applyModifierValue(float targetValue, float value)
		{
			if (value <= -100f)
			{
				value = -100f;
			}
			float num = targetValue;
			if (value >= 0f)
			{
				return targetValue + targetValue / 100f * value;
			}
			return targetValue - targetValue / 100f * (value * -1f);
		}

		public static Texture2D LoadPng(Stream fileStream)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			Texture2D val = null;
			if (fileStream != null)
			{
				using MemoryStream memoryStream = new MemoryStream();
				fileStream.CopyTo(memoryStream);
				val = new Texture2D(2, 2);
				ImageConversion.LoadImage(val, memoryStream.ToArray());
			}
			return val;
		}

		public static string CreateMD5(string input)
		{
			using MD5 mD = MD5.Create();
			byte[] bytes = Encoding.ASCII.GetBytes(input);
			byte[] array = mD.ComputeHash(bytes);
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < array.Length; i++)
			{
				stringBuilder.Append(array[i].ToString("X2"));
			}
			return stringBuilder.ToString();
		}

		public static void ResizeChildEffectArea(MonoBehaviour parent, Type includedTypes, float newRadius)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0029: Invalid comparison between Unknown and I4
			if (!((Object)(object)parent != (Object)null))
			{
				return;
			}
			EffectArea componentInChildren = ((Component)parent).GetComponentInChildren<EffectArea>();
			if ((Object)(object)componentInChildren != (Object)null && (componentInChildren.m_type & includedTypes) > 0)
			{
				SphereCollider component = ((Component)componentInChildren).GetComponent<SphereCollider>();
				if ((Object)(object)component != (Object)null)
				{
					component.radius = newRadius;
				}
			}
		}

		public static int Clamp(int value, int min, int max)
		{
			return Math.Min(max, Math.Max(min, value));
		}

		public static float Clamp(float value, float min, float max)
		{
			return Math.Min(max, Math.Max(min, value));
		}
	}
	public static class VPlusDataObjects
	{
		public class MapRange
		{
			public int StartingX;

			public int EndingX;

			public int Y;
		}
	}
}
namespace ValheimPlus.Utility
{
	public static class ListExtensions
	{
		public static List<List<T>> ChunkBy<T>(this List<T> source, int chunkSize)
		{
			return (from x in source.Select((T x, int i) => new
				{
					Index = i,
					Value = x
				})
				group x by x.Index / chunkSize into x
				select x.Select(v => v.Value).ToList()).ToList();
		}
	}
	public class RpcData
	{
		public string Name;

		public long Target = ZRoutedRpc.Everybody;

		public object[] Payload;
	}
	public static class RpcQueue
	{
		private static Queue<RpcData> _rpcQueue = new Queue<RpcData>();

		private static bool _ack = true;

		public static void Enqueue(RpcData rpc)
		{
			_rpcQueue.Enqueue(rpc);
		}

		public static bool SendNextRpc()
		{
			if (_rpcQueue.Count == 0 || !_ack)
			{
				return false;
			}
			RpcData rpcData = _rpcQueue.Dequeue();
			if (Utility.IsNullOrWhiteSpace(rpcData.Name) || rpcData.Payload == null)
			{
				return false;
			}
			ZRoutedRpc.instance.InvokeRoutedRPC(rpcData.Target, rpcData.Name, rpcData.Payload);
			_ack = false;
			return true;
		}

		public static void GotAck()
		{
			_ack = true;
		}
	}
	public static class ZPackageExtensions
	{
		public static VPlusDataObjects.MapRange ReadVPlusMapRange(this ZPackage pkg)
		{
			return new VPlusDataObjects.MapRange
			{
				StartingX = pkg.m_reader.ReadInt32(),
				EndingX = pkg.m_reader.ReadInt32(),
				Y = pkg.m_reader.ReadInt32()
			};
		}

		public static void WriteVPlusMapRange(this ZPackage pkg, VPlusDataObjects.MapRange mapRange)
		{
			pkg.m_writer.Write(mapRange.StartingX);
			pkg.m_writer.Write(mapRange.EndingX);
			pkg.m_writer.Write(mapRange.Y);
		}
	}
	public static class EmbeddedAsset
	{
		public static Stream LoadEmbeddedAsset(string assetPath)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			if (executingAssembly.GetManifestResourceInfo(executingAssembly.GetName().Name + "." + assetPath) != null)
			{
				return executingAssembly.GetManifestResourceStream(executingAssembly.GetName().Name + "." + assetPath);
			}
			return null;
		}
	}
}
namespace ValheimPlus.UI
{
	[HarmonyPatch(typeof(HotkeyBar), "UpdateIcons")]
	public static class HotkeyBar_UpdateIcons_Patch
	{
		private const string hudObjectNamePrefix = "BowAmmoCounts";

		private const string noAmmoDisplay = "No Ammo";

		private static readonly GameObject[] ammoCounters = (GameObject[])(object)new GameObject[8];

		private static int elementCount = -1;

		private static bool IsEnabled()
		{
			return Configuration.Current.Hud.IsEnabled && Configuration.Current.Hud.displayBowAmmoCounts > 0;
		}

		private static void Prefix(HotkeyBar __instance, Player player)
		{
			if (IsEnabled())
			{
				elementCount = __instance.m_elements.Count;
				if ((Object)(object)player == (Object)null || ((Character)player).IsDead())
				{
					DestroyAllAmmoCounters();
				}
			}
		}

		private static void Postfix(HotkeyBar __instance, Player player)
		{
			if (IsEnabled())
			{
				if (elementCount != __instance.m_elements.Count)
				{
					DestroyAllAmmoCounters();
				}
				if (!((Object)(object)player == (Object)null) && !((Character)player).IsDead())
				{
					DisplayAmmoCountsUnderBowHotbarIcons(__instance, player);
				}
			}
		}

		private static void DisplayAmmoCountsUnderBowHotbarIcons(HotkeyBar __instance, Player player)
		{
			HashSet<int> hashSet = new HashSet<int> { 0, 1, 2, 3, 4, 5, 6, 7 };
			foreach (ItemData item in __instance.m_items)
			{
				if (item != null)
				{
					hashSet.Remove(item.m_gridPos.x);
					DisplayAmmoCountsUnderBowHotbarIcon(__instance, player, item);
				}
			}
			foreach (int item2 in hashSet)
			{
				DestroyAmmoCounter(item2);
			}
		}

		private static void DisplayAmmoCountsUnderBowHotbarIcon(HotkeyBar __instance, Player player, ItemData item)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Invalid comparison between Unknown and I4
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Invalid comparison between Unknown and I4
			int x = item.m_gridPos.x;
			GameObject val = ammoCounters[x];
			if ((int)item.m_shared.m_itemType != 4 || (Configuration.Current.Hud.displayBowAmmoCounts == 1 && !((Humanoid)player).IsItemEquiped(item)) || x >= __instance.m_elements.Count || x < 0)
			{
				DestroyAmmoCounter(x);
				return;
			}
			ElementData val2 = __instance.m_elements[x];
			TMP_Text componentInChildren;
			if ((Object)(object)val == (Object)null)
			{
				GameObject gameObject = ((Component)val2.m_amount).gameObject;
				val = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent, false);
				((Object)val).name = "BowAmmoCounts" + x;
				val.SetActive(true);
				Vector3 val3 = gameObject.transform.position - ((Component)val2.m_icon).transform.position - new Vector3(0f, 15f);
				val.transform.Translate(val3);
				componentInChildren = val.GetComponentInChildren<TMP_Text>();
				TMP_Text obj = componentInChildren;
				obj.fontSize -= 2f;
				ammoCounters[x] = val;
			}
			else
			{
				componentInChildren = val.GetComponentInChildren<TMP_Text>();
			}
			val.gameObject.transform.SetParent(((Component)val2.m_amount).gameObject.transform.parent, false);
			ItemData ammoItem = ((Humanoid)player).m_ammoItem;
			if (ammoItem == null || ammoItem.m_shared.m_ammoType != item.m_shared.m_ammoType)
			{
				ammoItem = ((Humanoid)player).GetInventory().GetAmmoItem(item.m_shared.m_ammoType, (string)null);
			}
			int num = 0;
			int num2 = 0;
			List<ItemData> allItems = ((Humanoid)player).GetInventory().GetAllItems();
			foreach (ItemData item2 in allItems)
			{
				if (item2.m_shared.m_ammoType == item.m_shared.m_ammoType && ((int)item2.m_shared.m_itemType == 9 || (int)item2.m_shared.m_itemType == 2))
				{
					num2 += item2.m_stack;
					if (item2.m_shared.m_name == ammoItem.m_shared.m_name)
					{
						num += item2.m_stack;
					}
				}
			}
			if (num2 == 0)
			{
				componentInChildren.text = "No Ammo";
				return;
			}
			componentInChildren.text = ammoItem.m_shared.m_name.Split(new char[1] { '_' }).Last() + "\n" + num + "/" + num2;
		}

		private static void DestroyAllAmmoCounters()
		{
			for (int i = 0; i < 8; i++)
			{
				DestroyAmmoCounter(i);
			}
		}

		private static void DestroyAmmoCounter(int index)
		{
			GameObject val = ammoCounters[index];
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
				ammoCounters[index] = null;
			}
		}
	}
	public static class VPlusSettings
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Font, bool> <>9__23_0;

			public static Func<Font, bool> <>9__25_0;

			public static UnityAction <>9__25_1;

			public static UnityAction <>9__25_2;

			public static Func<PropertyInfo, string> <>9__25_5;

			public static Func<OptionData, string> <>9__25_3;

			public static UnityAction<int> <>9__25_4;

			internal bool <Load>b__23_0(Font fnt)
			{
				return ((Object)fnt).name == "Norse";
			}

			internal bool <Show>b__25_0(Font fnt)
			{
				return ((Object)fnt).name == "Norse";
			}

			internal void <Show>b__25_1()
			{
				int value = dropper.value;
				dropper.value = 0;
				Apply();
				Show();
				dropper.value = value;
			}

			internal void <Show>b__25_2()
			{
				//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)
				Apply();
				modSettingsPanel.SetActive(false);
				Scene activeScene = SceneManager.GetActiveScene();
				SceneManager.LoadScene(((Scene)(ref activeScene)).buildIndex);
			}

			internal string <Show>b__25_5(PropertyInfo prop)
			{
				return prop.Name;
			}

			internal string <Show>b__25_3(OptionData option)
			{
				return option.text;
			}

			internal void <Show>b__25_4(int <p0>)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Expected O, but got Unknown
				foreach (Transform item in settingsContentPanel.transform)
				{
					Transform val = item;
					((Component)val).gameObject.SetActive(false);
				}
				foreach (GameObject item2 in settingFamillySettings[availableSettings[dropper.value]])
				{
					item2.SetActive(true);
				}
			}
		}

		public static bool haveAddedModMenu = false;

		public static GameObject modSettingsPanel = null;

		public static GameObject modSettingsPanelCloner = null;

		public static AssetBundle modSettingsBundle = null;

		public static GameObject enableToggle = null;

		public static Font norseFont;

		public static Color32 vplusYellow = new Color32(byte.MaxValue, (byte)164, (byte)0, byte.MaxValue);

		public static GameObject settingsContentPanel;

		public static Dictionary<string, List<GameObject>> settingFamillySettings;

		public static Button applyButton;

		public static Button okButton;

		public static Dropdown dropper;

		public static GameObject uiTooltipPrefab = null;

		public static string[] keycodeNames;

		public static List<string> availableSettings { get; private set; }

		public static object GetPropValue(object src, string propName)
		{
			return src.GetType().GetProperty(propName).GetValue(src, null);
		}

		public static GameObject CreateEnableToggle(string settingName, string value, Transform parent, string comments)
		{
			//IL_0037: 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)
			bool isOn = bool.Parse(value);
			GameObject val = Object.Instantiate<GameObject>(enableToggle);
			val.AddComponent<UITooltip>().m_tooltipPrefab = uiTooltipPrefab;
			val.GetComponent<UITooltip>().Set(settingName ?? "", comments, (RectTransform)null, default(Vector2));
			val.GetComponentInChildren<Toggle>().isOn = isOn;
			val.transform.SetParent(parent, false);
			val.SetActive(false);
			return val;
		}

		public static GameObject CreateTextSettingEntry(string name, string value, Transform parent, string comments)
		{
			//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)
			GameObject val = Object.Instantiate<GameObject>(modSettingsBundle.LoadAsset<GameObject>("SettingEntry_Text"));
			((Object)val).name = name;
			((Component)val.transform.GetChild(0)).GetComponent<Text>().text = "Setting: " + name + "\nCurrent value: " + value;
			val.transform.SetParent(parent, false);
			val.AddComponent<UITooltip>().m_tooltipPrefab = uiTooltipPrefab;
			val.GetComponent<UITooltip>().Set(name ?? "", comments, (RectTransform)null, default(Vector2));
			val.SetActive(false);
			return val;
		}

		public static GameObject CreateKeyCodeSettingEntry(string name, string value, Transform parent, string comments)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(modSettingsBundle.LoadAsset<GameObject>("SettingEntry_KeyCode"));
			((Object)val).name = name;
			((Component)val.transform.GetChild(0)).GetComponent<Text>().text = "Setting: " + name;
			val.transform.SetParent(parent, false);
			Dropdown componentInChildren = val.GetComponentInChildren<Dropdown>();
			componentInChildren.options.Clear();
			string[] array = keycodeNames;
			foreach (st