Decompiled source of SomeStuff v1.0.3

SomeStuff/SomeStuff.dll

Decompiled 6 months ago
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using System.Timers;
using BepInEx;
using HarmonyLib;
using NaNNaVH.slib;
using SomeStuff;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SomeStuff")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SomeStuff")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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 SomeStuff
{
	[BepInPlugin("nb.wackjob.NaNNaVH", "NaNNaVH", "0.11.0")]
	public class SomeStuff : BaseUnityPlugin
	{
		public static Timer mapSyncSaveTimer = new Timer(TimeSpan.FromMinutes(5.0).TotalMilliseconds);

		public static readonly string nVHDataDirectoryPath;

		public static Harmony harmony;

		private void Awake()
		{
			harmony.PatchAll();
			if (!Directory.Exists(nVHDataDirectoryPath))
			{
				Directory.CreateDirectory(nVHDataDirectoryPath);
			}
			if (ZNet.m_isServer)
			{
				mapSyncSaveTimer.AutoReset = true;
				mapSyncSaveTimer.Elapsed += delegate
				{
					MapSync.SaveMapDataToDisk();
				};
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}

		static SomeStuff()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			string bepInExRootPath = Paths.BepInExRootPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			nVHDataDirectoryPath = bepInExRootPath + directorySeparatorChar + "nvh-data";
			harmony = new Harmony("nb.wackjob.NaNNaVH");
		}
	}
}
namespace NaNNaVH.slib
{
	public class MapSync
	{
		public class MapRange
		{
			public int StartingX;

			public int EndingX;

			public int Y;
		}

		public static bool[] ServerMapData;

		public static bool ShouldSyncOnSpawn = true;

		public static void RPC_nVHMapSync(long sender, ZPackage mapPkg)
		{
			if (ZNet.m_isServer)
			{
				if (sender == ZRoutedRpc.instance.GetServerPeerID() || mapPkg == null)
				{
					return;
				}
				int num = mapPkg.ReadInt();
				if (num > 0)
				{
					for (int i = 0; i < num; i++)
					{
						MapRange mapRange = mapPkg.ReadnVHMapRange();
						for (int j = mapRange.StartingX; j < mapRange.EndingX; j++)
						{
							ServerMapData[mapRange.Y * Minimap.instance.m_textureSize + j] = true;
						}
					}
					ZLog.Log((object)$"Received {num} map ranges from peer #{sender}.");
					nVHAck.SendAck(sender);
				}
				if (!mapPkg.ReadBool())
				{
					return;
				}
				List<MapRange> list = ExplorationDataToMapRanges(ServerMapData);
				List<ZPackage> list2 = ChunkMapData(list);
				foreach (ZPackage item in list2)
				{
					RpcData rpcData = new RpcData();
					rpcData.Name = "nVHMapSync";
					rpcData.Payload = new object[1] { item };
					rpcData.Target = ZRoutedRpc.Everybody;
					RpcQueue.Enqueue(rpcData);
				}
				ZLog.Log((object)$"-------------------------- Packages: {list2.Count}");
				ZLog.Log((object)$"Sent map updates to all clients ({list.Count} map ranges, {list2.Count} chunks)");
			}
			else
			{
				if (sender != ZRoutedRpc.instance.GetServerPeerID())
				{
					return;
				}
				if (mapPkg == null)
				{
					ZLog.LogWarning((object)"Warning: Got empty map sync package from server.");
					return;
				}
				int num2 = mapPkg.ReadInt();
				if (num2 > 0)
				{
					for (int k = 0; k < num2; k++)
					{
						MapRange mapRange2 = mapPkg.ReadnVHMapRange();
						for (int l = mapRange2.StartingX; l < mapRange2.EndingX; l++)
						{
							Minimap.instance.Explore(l, mapRange2.Y);
						}
					}
					Minimap.instance.m_fogTexture.Apply();
					ZLog.Log((object)$"I got {num2} map ranges from the server!");
					nVHAck.SendAck(sender);
				}
				else
				{
					ZLog.Log((object)"Server has no explored areas to sync, continuing.");
				}
			}
		}

		public static void SendMapToServer()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			ZLog.Log((object)"-------------------- SENDING NVHMAPSYNC DATA");
			List<MapRange> list = ExplorationDataToMapRanges(Minimap.instance.m_explored);
			if (list.Count == 0)
			{
				ZPackage val = new ZPackage();
				val.Write(0);
				val.Write(true);
				ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "nVHMapSync", new object[1] { val });
				return;
			}
			List<ZPackage> list2 = ChunkMapData(list);
			foreach (ZPackage item in list2)
			{
				RpcData rpcData = new RpcData();
				rpcData.Name = "nVHMapSync";
				rpcData.Payload = new object[1] { item };
				rpcData.Target = ZRoutedRpc.instance.GetServerPeerID();
				RpcQueue.Enqueue(rpcData);
			}
			ZLog.Log((object)$"Sent my map data to the server ({list.Count} map ranges, {list2.Count} chunks)");
		}

		public static void LoadMapDataFromDisk()
		{
			if (ServerMapData == null)
			{
				return;
			}
			string nVHDataDirectoryPath = global::SomeStuff.SomeStuff.nVHDataDirectoryPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			if (!File.Exists(nVHDataDirectoryPath + directorySeparatorChar + ZNet.instance.GetWorldName() + "_mapSync.dat"))
			{
				return;
			}
			try
			{
				string nVHDataDirectoryPath2 = global::SomeStuff.SomeStuff.nVHDataDirectoryPath;
				directorySeparatorChar = Path.DirectorySeparatorChar;
				string text = File.ReadAllText(nVHDataDirectoryPath2 + directorySeparatorChar + ZNet.instance.GetWorldName() + "_mapSync.dat");
				string[] array = text.Split(new char[1] { ',' });
				string[] array2 = array;
				foreach (string s in array2)
				{
					if (int.TryParse(s, out var result))
					{
						ServerMapData[result] = true;
					}
				}
				ZLog.Log((object)$"Loaded {array.Length} map points from disk.");
			}
			catch (Exception ex)
			{
				ZLog.LogError((object)"Failed to load synchronized map data.");
				ZLog.LogError((object)ex);
			}
		}

		public static void SaveMapDataToDisk()
		{
			if (ServerMapData == null)
			{
				return;
			}
			List<int> list = new List<int>();
			for (int i = 0; i < Minimap.instance.m_textureSize; i++)
			{
				for (int j = 0; j < Minimap.instance.m_textureSize; j++)
				{
					if (ServerMapData[i * Minimap.instance.m_textureSize + j])
					{
						list.Add(i * Minimap.instance.m_textureSize + j);
					}
				}
			}
			if (list.Count > 0)
			{
				string nVHDataDirectoryPath = global::SomeStuff.SomeStuff.nVHDataDirectoryPath;
				char directorySeparatorChar = Path.DirectorySeparatorChar;
				File.Delete(nVHDataDirectoryPath + directorySeparatorChar + ZNet.instance.GetWorldName() + "_mapSync.dat");
				string nVHDataDirectoryPath2 = global::SomeStuff.SomeStuff.nVHDataDirectoryPath;
				directorySeparatorChar = Path.DirectorySeparatorChar;
				File.WriteAllText(nVHDataDirectoryPath2 + directorySeparatorChar + ZNet.instance.GetWorldName() + "_mapSync.dat", string.Join(",", list));
				ZLog.Log((object)$"Saved {list.Count} map points to disk.");
			}
		}

		private static List<MapRange> ExplorationDataToMapRanges(bool[] explorationData)
		{
			List<MapRange> list = new List<MapRange>();
			for (int i = 0; i < Minimap.instance.m_textureSize; i++)
			{
				int num = -1;
				int num2 = -1;
				for (int j = 0; j < Minimap.instance.m_textureSize; j++)
				{
					if (explorationData[i * Minimap.instance.m_textureSize + j] && num == -1 && num2 == -1)
					{
						num = j;
					}
					else if (!explorationData[i * Minimap.instance.m_textureSize + j] && num > -1 && num2 == -1)
					{
						num2 = j - 1;
					}
					else if (num > -1 && num2 > -1)
					{
						list.Add(new MapRange
						{
							StartingX = num,
							EndingX = num2,
							Y = i
						});
						num = -1;
						num2 = -1;
					}
				}
				if (num > -1 && num2 == -1)
				{
					list.Add(new MapRange
					{
						StartingX = num,
						EndingX = Minimap.instance.m_textureSize,
						Y = i
					});
				}
			}
			return list;
		}

		private static List<ZPackage> ChunkMapData(List<MapRange> mapData, int chunkSize = 10000)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			if (mapData == null || mapData.Count == 0)
			{
				return null;
			}
			List<List<MapRange>> list = mapData.ChunkBy(chunkSize);
			List<ZPackage> list2 = new List<ZPackage>();
			foreach (List<MapRange> item in list)
			{
				ZPackage val = new ZPackage();
				val.Write(item.Count);
				foreach (MapRange item2 in item)
				{
					val.WritenVHMapRange(item2);
				}
				if (item == list.Last())
				{
					val.Write(true);
				}
				else
				{
					val.Write(false);
				}
				list2.Add(val);
			}
			return list2;
		}
	}
	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 nVHAck
	{
		public static void RPC_nVHAck(long sender)
		{
			RpcQueue.GotAck();
		}

		public static void SendAck(long target)
		{
			ZRoutedRpc.instance.InvokeRoutedRPC(target, "nVHAck", Array.Empty<object>());
		}
	}
	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;
		}
	}
	internal static class sFunc
	{
		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 IEnumerable<CodeInstruction> StripForcedCase(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Callvirt)
				{
					MethodBase methodBase = list[i].operand as MethodBase;
					if (methodBase != null && (methodBase.Name == "ToLowerInvariant" || methodBase.Name == "ToUpper"))
					{
						list.RemoveRange(i - 1, 3);
						i -= 2;
					}
				}
			}
			return list;
		}

		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));
		}
	}
	internal static class versionCheck
	{
		[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
		private static class PatchZNetOnNewConnection
		{
			private static void Postfix(ZNet __instance, ZNetPeer peer)
			{
				if (__instance.IsServer())
				{
					ZLog.Log((object)("========== Server Client connected by the name of: " + peer.m_playerName));
				}
			}
		}

		public static void ReceiveClientVersion(long sender, string clientVersion)
		{
			string modVersion = GetModVersion();
			ZNetPeer val = FindPeerBySenderID(sender);
			if (val != null && clientVersion != modVersion)
			{
				ZLog.Log((object)("========== Version mismatch. Kicking peer: " + ((object)val).ToString()));
				ZNet.instance.InternalKick(val);
			}
		}

		public static ZNetPeer FindPeerBySenderID(long senderID)
		{
			foreach (ZNetPeer peer in ZNet.instance.m_peers)
			{
				if (peer.m_uid == senderID)
				{
					return peer;
				}
			}
			return null;
		}

		public static string GetModVersion()
		{
			BepInPlugin customAttribute = ((MemberInfo)typeof(global::SomeStuff.SomeStuff)).GetCustomAttribute<BepInPlugin>();
			return (customAttribute != null) ? customAttribute.Version.ToString() : "Unknown";
		}
	}
	public static class ZDODataBuffer
	{
		[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
		private class StartBufferingOnNewConnection
		{
			private static void Postfix(ZNet __instance, ZNetPeer peer)
			{
				if (!__instance.IsServer())
				{
					peer.m_rpc.Register<ZPackage>("ZDOData", (Action<ZRpc, ZPackage>)delegate(ZRpc _, ZPackage package)
					{
						packageBuffer.Add(package);
					});
				}
			}
		}

		[HarmonyPatch(typeof(ZNet), "Shutdown")]
		private class ClearPackageBufferOnShutdown
		{
			private static void Postfix()
			{
				packageBuffer.Clear();
			}
		}

		[HarmonyPatch(typeof(ZDOMan), "AddPeer")]
		private class EvaluateBufferedPackages
		{
			private static void Postfix(ZDOMan __instance, ZNetPeer netPeer)
			{
				foreach (ZPackage item in packageBuffer)
				{
					__instance.RPC_ZDOData(netPeer.m_rpc, item);
				}
				packageBuffer.Clear();
			}
		}

		private static readonly List<ZPackage> packageBuffer = new List<ZPackage>();
	}
	public static class ZPackageExtensions
	{
		public static MapSync.MapRange ReadnVHMapRange(this ZPackage pkg)
		{
			return new MapSync.MapRange
			{
				StartingX = pkg.m_reader.ReadInt32(),
				EndingX = pkg.m_reader.ReadInt32(),
				Y = pkg.m_reader.ReadInt32()
			};
		}

		public static void WritenVHMapRange(this ZPackage pkg, MapSync.MapRange mapRange)
		{
			pkg.m_writer.Write(mapRange.StartingX);
			pkg.m_writer.Write(mapRange.EndingX);
			pkg.m_writer.Write(mapRange.Y);
		}
	}
}
namespace NaNNaVH.mods
{
	[HarmonyPatch]
	internal static class AreaRepair
	{
		[HarmonyPatch(typeof(Player), "UpdatePlacement")]
		public static class Player_UpdatePlacement_Transpiler
		{
			private static MethodInfo method_Player_Repair = AccessTools.Method(typeof(Player), "Repair", (Type[])null, (Type[])null);

			private static FieldRef<Player, Piece> field_Player_m_hoveringPiece = AccessTools.FieldRefAccess<Player, Piece>("m_hoveringPiece");

			private static MethodInfo method_RepairNearby = AccessTools.Method(typeof(Player_UpdatePlacement_Transpiler), "RepairNearby", (Type[])null, (Type[])null);

			[HarmonyTranspiler]
			public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				List<CodeInstruction> list = instructions.ToList();
				for (int i = 0; i < list.Count; i++)
				{
					if (CodeInstructionExtensions.Calls(list[i], method_Player_Repair))
					{
						list[i].operand = method_RepairNearby;
					}
				}
				return list.AsEnumerable();
			}

			public static void RepairNearby(Player instance, ItemData toolItem, Piece _1)
			{
				//IL_0024: 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_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				Piece hoveringPiece = instance.GetHoveringPiece();
				Vector3 val = (((Object)(object)hoveringPiece != (Object)null) ? ((Component)hoveringPiece).transform.position : ((Component)instance).transform.position);
				List<Piece> list = new List<Piece>();
				Piece.GetAllPiecesInRadius(val, m_repair_radius, list);
				m_repair_count = 0;
				Traverse val2 = Traverse.Create((object)instance);
				Piece value = val2.Field("m_hoveringPiece").GetValue<Piece>();
				MethodInfo methodInfo = AccessTools.Method(typeof(Player), "Repair", (Type[])null, (Type[])null);
				foreach (Piece item in list)
				{
					bool flag = ((Character)instance).HaveStamina(toolItem.m_shared.m_attack.m_attackStamina);
					bool useDurability = toolItem.m_shared.m_useDurability;
					bool flag2 = toolItem.m_durability > 0f;
					if (!flag || (useDurability && !flag2))
					{
						break;
					}
					val2.Field("m_hoveringPiece").SetValue((object)item);
					methodInfo.Invoke(instance, new object[2] { toolItem, _1 });
					val2.Field("m_hoveringPiece").SetValue((object)value);
				}
				if (m_repair_count > 0)
				{
					((Character)instance).Message((MessageType)1, $"{m_repair_count} pieces repaired", 0, (Sprite)null);
				}
			}
		}

		[HarmonyPatch(typeof(Player), "Repair")]
		public static class Player_Repair_Transpiler
		{
			private static MethodInfo method_Character_Message = AccessTools.Method(typeof(Character), "Message", (Type[])null, (Type[])null);

			private static MethodInfo method_MessageNoop = AccessTools.Method(typeof(Player_Repair_Transpiler), "MessageNoop", (Type[])null, (Type[])null);

			[HarmonyTranspiler]
			public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Expected O, but got Unknown
				List<CodeInstruction> list = instructions.ToList();
				int num = 0;
				for (int i = 0; i < list.Count; i++)
				{
					if (CodeInstructionExtensions.Calls(list[i], method_Character_Message))
					{
						list[i].operand = method_MessageNoop;
						list.Insert(i++, new CodeInstruction((num++ == 0) ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0, (object)null));
					}
				}
				return list.AsEnumerable();
			}

			public static void MessageNoop(Character _0, MessageType _1, string _2, int _3, Sprite _4, int repaired)
			{
				m_repair_count += repaired;
			}
		}

		private static int m_repair_count;

		private static float m_repair_radius = 10f;
	}
	[HarmonyPatch(typeof(Minimap))]
	public static class Minimap_Patches
	{
		[HarmonyPatch("UpdateDynamicPins")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count - 1; i++)
			{
				if (list[i + 1].opcode == OpCodes.Call)
				{
					MethodBase methodBase = (MethodBase)list[i + 1].operand;
					if (methodBase.Name == "UpdateShoutPins")
					{
						list.RemoveRange(i, 2);
						break;
					}
				}
			}
			return list;
		}
	}
	[HarmonyPatch(typeof(Player), "Update")]
	public static class Player_Update_Patch
	{
		private static GameObject timeObj = null;

		private static double savedEnvMinutes = -1.0;

		private const float ColorRatio = 0.5882353f;

		private const float AlphaRatio = 44f / 51f;

		private const int FontSize = 24;

		private static void Postfix(ref Player __instance)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_00a1: 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_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Character)__instance).m_nview.IsValid() || !((Character)__instance).m_nview.IsOwner())
			{
				return;
			}
			Hud instance = Hud.instance;
			TMP_Text val;
			if ((Object)(object)timeObj == (Object)null)
			{
				MessageHud instance2 = MessageHud.instance;
				timeObj = new GameObject();
				timeObj.transform.SetParent(((Component)instance.m_statusEffectListRoot).transform.parent);
				timeObj.AddComponent<RectTransform>();
				val = (TMP_Text)(object)timeObj.AddComponent<TextMeshProUGUI>();
				((Graphic)val).color = new Color(0.5882353f, 0.5882353f, 0.5882353f, 44f / 51f);
				val.font = instance2.m_messageCenterText.font;
				val.fontSize = 24f;
				((Behaviour)val).enabled = true;
				val.alignment = (TextAlignmentOptions)514;
				val.overflowMode = (TextOverflowModes)0;
			}
			else
			{
				val = timeObj.GetComponent<TMP_Text>();
			}
			EnvMan instance3 = EnvMan.instance;
			if (savedEnvMinutes != instance3.m_totalSeconds / 60.0)
			{
				int currentDay = instance3.GetCurrentDay();
				float num = Mathf.Lerp(0f, 24f, instance3.GetDayFraction());
				float num2 = Mathf.Floor(num);
				num -= num2;
				float num3 = Mathf.Lerp(0f, 60f, num);
				int num4 = Mathf.FloorToInt(num2);
				int num5 = Mathf.FloorToInt(num3);
				string text = ((num4 < 12) ? " AM" : " PM");
				if (num4 > 12)
				{
					num4 -= 12;
				}
				val.text = $"Day {currentDay}, {num4:00}:{num5:00}{text}";
				Transform transform = ((Component)instance.m_staminaBar2Root).transform;
				RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				Transform transform2 = ((Component)instance.m_statusEffectListRoot).transform;
				RectTransform val3 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
				((Transform)timeObj.GetComponent<RectTransform>()).position = Vector2.op_Implicit(new Vector2(((Transform)val2).position.x, ((Transform)val3).position.y));
				timeObj.SetActive(true);
				savedEnvMinutes = instance3.m_totalSeconds / 60.0;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "GetFirstRequiredItem")]
	public static class Player_GetFirstRequiredItem_Transpiler
	{
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldarg_0)
				{
					list[i].opcode = OpCodes.Ldarg_1;
					list.RemoveAt(i + 1);
					return list.AsEnumerable();
				}
			}
			return instructions;
		}
	}
	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 class Crops
	{
		public static KeyCode MassActionHotkey;

		public static KeyCode ControllerPickupHotkey;

		public static float MassInteractRange;

		public static int PlantGridWidth;

		public static int PlantGridLength;

		public static bool IgnoreStamina;

		public static bool IgnoreDurability;

		public static bool GridAnchorWidth;

		public static bool GridAnchorLength;

		static Crops()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			MassActionHotkey = (KeyCode)304;
			ControllerPickupHotkey = (KeyCode)334;
			MassInteractRange = 5f;
			PlantGridWidth = 5;
			PlantGridLength = 5;
			IgnoreStamina = false;
			IgnoreDurability = false;
			GridAnchorWidth = true;
			GridAnchorLength = true;
		}
	}
	[HarmonyPatch]
	public static class MassPlant
	{
		private static readonly FieldInfo m_noPlacementCostField = AccessTools.Field(typeof(Player), "m_noPlacementCost");

		private static readonly FieldInfo m_placementGhostField = AccessTools.Field(typeof(Player), "m_placementGhost");

		private static readonly FieldInfo m_buildPiecesField = AccessTools.Field(typeof(Player), "m_buildPieces");

		private static readonly MethodInfo _GetRightItemMethod = AccessTools.Method(typeof(Humanoid), "GetRightItem", (Type[])null, (Type[])null);

		private static Vector3 placedPosition;

		private static Quaternion placedRotation;

		private static Piece placedPiece;

		private static bool placeSuccessful = false;

		private static int? massFarmingRotation = null;

		private static readonly int _plantSpaceMask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid" });

		private static GameObject[] _placementGhosts = (GameObject[])(object)new GameObject[1];

		private static readonly Piece _fakeResourcePiece;

		private static bool IsHotKeyPressed => Input.GetKey(Crops.ControllerPickupHotkey) || Input.GetKey(Crops.MassActionHotkey);

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "PlacePiece")]
		public static void PlacePiecePrefix(int ___m_placeRotation)
		{
			if (IsHotKeyPressed)
			{
				int? num = massFarmingRotation;
				if (!num.HasValue)
				{
					massFarmingRotation = ___m_placeRotation;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Player), "PlacePiece")]
		public static void PlacePiecePostfix(Player __instance, ref bool __result, Piece piece, ref int ___m_placeRotation)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			placeSuccessful = __result;
			if (__result)
			{
				GameObject val = (GameObject)m_placementGhostField.GetValue(__instance);
				placedPosition = val.transform.position;
				placedRotation = val.transform.rotation;
				placedPiece = piece;
			}
			if (IsHotKeyPressed)
			{
				___m_placeRotation = massFarmingRotation.Value;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "UpdatePlacement")]
		public static void UpdatePlacementPrefix(bool takeInput, float dt, ref int ___m_placeRotation)
		{
			placeSuccessful = false;
			if (IsHotKeyPressed && massFarmingRotation.HasValue)
			{
				___m_placeRotation = massFarmingRotation.Value;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Player), "UpdatePlacement")]
		public static void UpdatePlacementPostfix(Player __instance, bool takeInput, float dt, int ___m_placeRotation)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			if (IsHotKeyPressed)
			{
				massFarmingRotation = ___m_placeRotation;
			}
			if (!placeSuccessful)
			{
				return;
			}
			Plant component = ((Component)placedPiece).gameObject.GetComponent<Plant>();
			if (!Object.op_Implicit((Object)(object)component) || !IsHotKeyPressed)
			{
				return;
			}
			Heightmap val = Heightmap.FindHeightmap(placedPosition);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			foreach (Vector3 item in BuildPlantingGridPositions(placedPosition, component, placedRotation))
			{
				if ((placedPiece.m_cultivatedGroundOnly && !val.IsCultivated(item)) || placedPosition == item)
				{
					continue;
				}
				object? obj = _GetRightItemMethod.Invoke(__instance, Array.Empty<object>());
				ItemData val2 = (ItemData)((obj is ItemData) ? obj : null);
				if (val2 == null)
				{
					continue;
				}
				if (!Crops.IgnoreStamina && !((Character)__instance).HaveStamina(val2.m_shared.m_attack.m_attackStamina))
				{
					Hud.instance.StaminaBarUppgradeFlash();
					break;
				}
				if (!(bool)m_noPlacementCostField.GetValue(__instance) && !__instance.HaveRequirements(placedPiece, (RequirementMode)0))
				{
					break;
				}
				if (!HasGrowSpace(item, ((Component)placedPiece).gameObject))
				{
					continue;
				}
				GameObject val3 = Object.Instantiate<GameObject>(((Component)placedPiece).gameObject, item, placedRotation);
				Piece component2 = val3.GetComponent<Piece>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					component2.SetCreator(__instance.GetPlayerID());
				}
				placedPiece.m_placeEffect.Create(item, placedRotation, val3.transform, 1f, -1);
				Game.instance.IncrementPlayerStat((PlayerStatType)2, 1f);
				__instance.ConsumeResources(placedPiece.m_resources, 0, -1);
				if (!Crops.IgnoreStamina)
				{
					((Character)__instance).UseStamina(val2.m_shared.m_attack.m_attackStamina, false);
				}
				if (!Crops.IgnoreDurability && val2.m_shared.m_useDurability)
				{
					val2.m_durability -= val2.m_shared.m_useDurabilityDrain;
					if (val2.m_durability <= 0f)
					{
						break;
					}
				}
			}
		}

		private static List<Vector3> BuildPlantingGridPositions(Vector3 originPos, Plant placedPlant, Quaternion rotation)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_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)
			float num = placedPlant.m_growRadius * 2f;
			List<Vector3> list = new List<Vector3>(Crops.PlantGridWidth * Crops.PlantGridLength);
			Vector3 val = rotation * Vector3.left * num;
			Vector3 val2 = rotation * Vector3.forward * num;
			Vector3 val3 = originPos;
			if (Crops.GridAnchorLength)
			{
				val3 -= val2 * (float)(Crops.PlantGridLength / 2);
			}
			if (Crops.GridAnchorWidth)
			{
				val3 -= val * (float)(Crops.PlantGridWidth / 2);
			}
			for (int i = 0; i < Crops.PlantGridLength; i++)
			{
				Vector3 val4 = val3;
				for (int j = 0; j < Crops.PlantGridWidth; j++)
				{
					val4.y = ZoneSystem.instance.GetGroundHeight(val4);
					list.Add(val4);
					val4 += val;
				}
				val3 += val2;
			}
			return list;
		}

		private static bool HasGrowSpace(Vector3 newPos, GameObject go)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			Plant component = go.GetComponent<Plant>();
			if (component != null)
			{
				Collider[] array = Physics.OverlapSphere(newPos, component.m_growRadius, _plantSpaceMask);
				return array.Length == 0;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "SetupPlacementGhost")]
		public static void SetupPlacementGhostPrefix(Player __instance, int ___m_placeRotation)
		{
			if (IsHotKeyPressed)
			{
				int? num = massFarmingRotation;
				if (!num.HasValue)
				{
					massFarmingRotation = ___m_placeRotation;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Player), "SetupPlacementGhost")]
		public static void SetupPlacementGhostPostfix(Player __instance, ref int ___m_placeRotation)
		{
			if (IsHotKeyPressed && massFarmingRotation.HasValue)
			{
				___m_placeRotation = massFarmingRotation.Value;
			}
			DestroyGhosts();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
		public static void UpdatePlacementGhostPostfix(Player __instance, bool flashGuardStone)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: 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_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = (GameObject)m_placementGhostField.GetValue(__instance);
			if (!Object.op_Implicit((Object)(object)val) || !val.activeSelf)
			{
				SetGhostsActive(active: false);
				return;
			}
			if (!Input.GetKey(Crops.ControllerPickupHotkey) && !Input.GetKey(Crops.MassActionHotkey))
			{
				SetGhostsActive(active: false);
				return;
			}
			Plant component = val.GetComponent<Plant>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				SetGhostsActive(active: false);
				return;
			}
			if (!EnsureGhostsBuilt(__instance))
			{
				SetGhostsActive(active: false);
				return;
			}
			Requirement val2 = ((IEnumerable<Requirement>)val.GetComponent<Piece>().m_resources).FirstOrDefault((Func<Requirement, bool>)((Requirement r) => Object.op_Implicit((Object)(object)r.m_resItem) && r.m_amount > 0));
			_fakeResourcePiece.m_resources[0].m_resItem = val2.m_resItem;
			_fakeResourcePiece.m_resources[0].m_amount = val2.m_amount;
			float num = __instance.GetStamina();
			object? obj = _GetRightItemMethod.Invoke(__instance, Array.Empty<object>());
			ItemData val3 = (ItemData)((obj is ItemData) ? obj : null);
			if (val3 == null)
			{
				return;
			}
			Heightmap val4 = Heightmap.FindHeightmap(val.transform.position);
			List<Vector3> list = BuildPlantingGridPositions(val.transform.position, component, val.transform.rotation);
			for (int i = 0; i < _placementGhosts.Length; i++)
			{
				Vector3 val5 = list[i];
				if (val.transform.position == val5)
				{
					_placementGhosts[i].SetActive(false);
					continue;
				}
				Requirement obj2 = _fakeResourcePiece.m_resources[0];
				obj2.m_amount += val2.m_amount;
				_placementGhosts[i].transform.position = val5;
				_placementGhosts[i].transform.rotation = val.transform.rotation;
				_placementGhosts[i].SetActive(true);
				bool invalidPlacementHeightlight = false;
				if (val.GetComponent<Piece>().m_cultivatedGroundOnly && !val4.IsCultivated(val5))
				{
					invalidPlacementHeightlight = true;
				}
				else if (!HasGrowSpace(val5, val.gameObject))
				{
					invalidPlacementHeightlight = true;
				}
				else if (!Crops.IgnoreStamina && num < val3.m_shared.m_attack.m_attackStamina)
				{
					Hud.instance.StaminaBarUppgradeFlash();
					invalidPlacementHeightlight = true;
				}
				else if (!(bool)m_noPlacementCostField.GetValue(__instance) && !__instance.HaveRequirements(_fakeResourcePiece, (RequirementMode)0))
				{
					invalidPlacementHeightlight = true;
				}
				num -= val3.m_shared.m_attack.m_attackStamina;
				_placementGhosts[i].GetComponent<Piece>().SetInvalidPlacementHeightlight(invalidPlacementHeightlight);
			}
		}

		private static bool EnsureGhostsBuilt(Player player)
		{
			int num = Crops.PlantGridWidth * Crops.PlantGridLength;
			if (!Object.op_Implicit((Object)(object)_placementGhosts[0]) || _placementGhosts.Length != num)
			{
				DestroyGhosts();
				if (_placementGhosts.Length != num)
				{
					_placementGhosts = (GameObject[])(object)new GameObject[num];
				}
				object? value = m_buildPiecesField.GetValue(player);
				PieceTable val = (PieceTable)((value is PieceTable) ? value : null);
				if (val != null)
				{
					GameObject selectedPrefab = val.GetSelectedPrefab();
					if (selectedPrefab != null)
					{
						if (selectedPrefab.GetComponent<Piece>().m_repairPiece)
						{
							return false;
						}
						for (int i = 0; i < _placementGhosts.Length; i++)
						{
							_placementGhosts[i] = SetupMyGhost(player, selectedPrefab);
						}
						goto IL_00d6;
					}
				}
				return false;
			}
			goto IL_00d6;
			IL_00d6:
			return true;
		}

		private static void DestroyGhosts()
		{
			for (int i = 0; i < _placementGhosts.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)_placementGhosts[i]))
				{
					Object.Destroy((Object)(object)_placementGhosts[i]);
					_placementGhosts[i] = null;
				}
			}
		}

		private static void SetGhostsActive(bool active)
		{
			GameObject[] placementGhosts = _placementGhosts;
			foreach (GameObject val in placementGhosts)
			{
				if (val != null)
				{
					val.SetActive(active);
				}
			}
		}

		private static GameObject SetupMyGhost(Player player, GameObject prefab)
		{
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Expected O, but got Unknown
			ZNetView.m_forceDisableInit = true;
			GameObject val = Object.Instantiate<GameObject>(prefab);
			ZNetView.m_forceDisableInit = false;
			((Object)val).name = ((Object)prefab).name;
			Joint[] componentsInChildren = val.GetComponentsInChildren<Joint>();
			foreach (Joint val2 in componentsInChildren)
			{
				Object.Destroy((Object)(object)val2);
			}
			Rigidbody[] componentsInChildren2 = val.GetComponentsInChildren<Rigidbody>();
			foreach (Rigidbody val3 in componentsInChildren2)
			{
				Object.Destroy((Object)(object)val3);
			}
			int layer = LayerMask.NameToLayer("ghost");
			Transform[] componentsInChildren3 = val.GetComponentsInChildren<Transform>();
			foreach (Transform val4 in componentsInChildren3)
			{
				((Component)val4).gameObject.layer = layer;
			}
			TerrainModifier[] componentsInChildren4 = val.GetComponentsInChildren<TerrainModifier>();
			foreach (TerrainModifier val5 in componentsInChildren4)
			{
				Object.Destroy((Object)(object)val5);
			}
			GuidePoint[] componentsInChildren5 = val.GetComponentsInChildren<GuidePoint>();
			foreach (GuidePoint val6 in componentsInChildren5)
			{
				Object.Destroy((Object)(object)val6);
			}
			Light[] componentsInChildren6 = val.GetComponentsInChildren<Light>();
			foreach (Light val7 in componentsInChildren6)
			{
				Object.Destroy((Object)(object)val7);
			}
			Transform val8 = val.transform.Find("_GhostOnly");
			if (Object.op_Implicit((Object)(object)val8))
			{
				((Component)val8).gameObject.SetActive(true);
			}
			MeshRenderer[] componentsInChildren7 = val.GetComponentsInChildren<MeshRenderer>();
			foreach (MeshRenderer val9 in componentsInChildren7)
			{
				if (!((Object)(object)((Renderer)val9).sharedMaterial == (Object)null))
				{
					Material[] sharedMaterials = ((Renderer)val9).sharedMaterials;
					for (int num2 = 0; num2 < sharedMaterials.Length; num2++)
					{
						Material val10 = new Material(sharedMaterials[num2]);
						val10.SetFloat("_RippleDistance", 0f);
						val10.SetFloat("_ValueNoise", 0f);
						sharedMaterials[num2] = val10;
					}
					((Renderer)val9).sharedMaterials = sharedMaterials;
					((Renderer)val9).shadowCastingMode = (ShadowCastingMode)0;
				}
			}
			return val;
		}

		static MassPlant()
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			Piece val = new Piece();
			val.m_dlc = string.Empty;
			val.m_resources = (Requirement[])(object)new Requirement[1]
			{
				new Requirement()
			};
			_fakeResourcePiece = val;
		}
	}
	[HarmonyPatch(typeof(Player), "StartGuardianPower")]
	public static class Player_StartGuardianPower_Patch
	{
		private static bool Prefix(ref Player __instance, ref bool __result)
		{
			if ((Object)(object)__instance.m_guardianSE == (Object)null)
			{
				__result = false;
				return false;
			}
			if (__instance.m_guardianPowerCooldown > 0f)
			{
				((Character)__instance).Message((MessageType)2, "$hud_powernotready", 0, (Sprite)null);
				__result = false;
				return false;
			}
			__instance.ActivateGuardianPower();
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "RepairOneItem")]
	public static class InventoryGui_RepairOneItem_Transpiler
	{
		private static MethodInfo method_EffectList_Create = AccessTools.Method(typeof(EffectList), "Create", (Type[])null, (Type[])null);

		private static MethodInfo method_CreateNoop = AccessTools.Method(typeof(InventoryGui_RepairOneItem_Transpiler), "CreateNoop", (Type[])null, (Type[])null);

		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				if (CodeInstructionExtensions.Calls(list[i], method_EffectList_Create))
				{
					list[i].opcode = OpCodes.Call;
					list[i].operand = method_CreateNoop;
				}
			}
			return list;
		}

		private static GameObject[] CreateNoop(Vector3 _0, Quaternion _1, Transform _2, float _3, int _4)
		{
			return null;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateRepair")]
	public static class InventoryGui_UpdateRepair_Patch
	{
		[HarmonyPrefix]
		public static void Prefix(InventoryGui __instance)
		{
			//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)
			CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation();
			if (!((Object)(object)currentCraftingStation != (Object)null))
			{
				return;
			}
			int num = 0;
			foreach (ItemData allItem in ((Humanoid)Player.m_localPlayer).GetInventory().GetAllItems())
			{
				if (ItemRepair.CanRepair(allItem) && allItem.m_durability < allItem.GetMaxDurability())
				{
					allItem.m_durability = allItem.GetMaxDurability();
					num++;
				}
			}
			if (num > 0)
			{
				currentCraftingStation.m_repairItemDoneEffects.Create(((Component)currentCraftingStation).transform.position, Quaternion.identity, (Transform)null, 1f, -1);
			}
		}
	}
	public class ItemRepair
	{
		public static bool CanRepair(ItemData item)
		{
			Recipe recipe = ObjectDB.instance.GetRecipe(item);
			CraftingStation currentCraftingStation = Player.m_localPlayer.GetCurrentCraftingStation();
			if ((Object)(object)recipe == (Object)null || (Object)(object)currentCraftingStation == (Object)null || ((Object)(object)recipe.m_craftingStation == (Object)null && (Object)(object)recipe.m_repairStation == (Object)null))
			{
				return false;
			}
			return (((Object)(object)recipe.m_repairStation != (Object)null && recipe.m_repairStation.m_name == currentCraftingStation.m_name) || ((Object)(object)recipe.m_craftingStation != (Object)null && recipe.m_craftingStation.m_name == currentCraftingStation.m_name)) && currentCraftingStation.GetLevel(true) >= recipe.m_minStationLevel;
		}
	}
	[HarmonyPatch(typeof(Game), "Start")]
	public static class Game_Start_Patch
	{
		private static void Prefix()
		{
			ZRoutedRpc.instance.Register<ZPackage>("nVHMapSync", (Action<long, ZPackage>)MapSync.RPC_nVHMapSync);
			ZRoutedRpc.instance.Register("nVHAck", (Action<long>)nVHAck.RPC_nVHAck);
		}
	}
	[HarmonyPatch(typeof(Minimap))]
	public class HookExplore
	{
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(Minimap), "Explore", new Type[]
		{
			typeof(Vector3),
			typeof(float)
		})]
		public static void call_Explore(object instance, Vector3 p, float radius)
		{
			throw new NotImplementedException();
		}
	}
	[HarmonyPatch(typeof(Minimap), "UpdateExplore")]
	public static class ChangeMapBehavior
	{
		private static void Prefix(ref float dt, ref Player player, ref Minimap __instance, ref float ___m_exploreTimer, ref float ___m_exploreInterval)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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)
			float num = ___m_exploreTimer;
			num += Time.deltaTime;
			float radius = 200f;
			if (num > ___m_exploreInterval && ZNet.instance.m_players.Any())
			{
				foreach (PlayerInfo player2 in ZNet.instance.m_players)
				{
					HookExplore.call_Explore(__instance, player2.m_position, radius);
				}
			}
			HookExplore.call_Explore(__instance, ((Component)player).transform.position, radius);
		}
	}
	[HarmonyPatch(typeof(Minimap), "Awake")]
	public static class MinimapAwake
	{
		private static void Postfix()
		{
			if (ZNet.m_isServer)
			{
				MapSync.ServerMapData = new bool[Minimap.instance.m_textureSize * Minimap.instance.m_textureSize];
				MapSync.LoadMapDataFromDisk();
				global::SomeStuff.SomeStuff.mapSyncSaveTimer.Start();
			}
		}
	}
	[HarmonyPatch(typeof(ZNet))]
	public class HookZNet
	{
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPatch(typeof(ZNet), "GetOtherPublicPlayers", new Type[] { typeof(List<PlayerInfo>) })]
		public static void GetOtherPublicPlayers(object instance, List<PlayerInfo> playerList)
		{
			throw new NotImplementedException();
		}
	}
	[HarmonyPatch(typeof(ZNet), "SendPeriodicData")]
	public static class PeriodicDataHandler
	{
		private static void Postfix()
		{
			RpcQueue.SendNextRpc();
		}
	}
	[HarmonyPatch(typeof(ZNet), "Shutdown")]
	public static class OnErrorLoadOwnIni
	{
		private static void Prefix(ref ZNet __instance)
		{
			if (!__instance.IsServer())
			{
				global::SomeStuff.SomeStuff.harmony.UnpatchSelf();
				global::SomeStuff.SomeStuff.harmony.PatchAll();
				MapSync.ShouldSyncOnSpawn = true;
			}
			else
			{
				MapSync.SaveMapDataToDisk();
			}
		}
	}
	[HarmonyPatch(typeof(ZNet), "SetPublicReferencePosition")]
	public static class PreventPublicPositionToggle
	{
		private static void Postfix(ref bool pub, ref bool ___m_publicReferencePosition)
		{
			___m_publicReferencePosition = true;
		}
	}
	[HarmonyPatch(typeof(ZNet), "RPC_ServerSyncedPlayerData")]
	public static class PlayerPositionWatcher
	{
		private static void Postfix(ref ZNet __instance, ZRpc rpc)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.IsServer())
			{
				return;
			}
			ZNetPeer peer = __instance.GetPeer(rpc);
			if (peer == null)
			{
				return;
			}
			Vector3 refPos = peer.m_refPos;
			int num = default(int);
			int num2 = default(int);
			Minimap.instance.WorldToPixel(refPos, ref num, ref num2);
			int num3 = (int)Mathf.Ceil(200f / Minimap.instance.m_pixelSize);
			for (int i = num2 - num3; i <= num2 + num3; i++)
			{
				for (int j = num - num3; j <= num + num3; j++)
				{
					if (j >= 0 && i >= 0 && j < Minimap.instance.m_textureSize && i < Minimap.instance.m_textureSize)
					{
						Vector2 val = new Vector2((float)(j - num), (float)(i - num2));
						if ((double)((Vector2)(ref val)).magnitude <= (double)num3)
						{
							MapSync.ServerMapData[i * Minimap.instance.m_textureSize + j] = true;
						}
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player), "OnSpawned")]
	public static class Player_OnSpawned_Patch
	{
		private static void Prefix(ref Player __instance)
		{
			MapSync.SendMapToServer();
			MapSync.ShouldSyncOnSpawn = false;
		}
	}
	public class DisplayCartsAndBoatsOnMap
	{
		[HarmonyPatch(typeof(Minimap), "OnDestroy")]
		public static class Minimap_OnDestroy_Patch
		{
			private static void Postfix()
			{
				customPins.Clear();
				icons.Clear();
			}
		}

		[HarmonyPatch(typeof(Minimap), "UpdateMap")]
		public static class Minimap_UpdateMap_Patch
		{
			private static float timeCounter = updateInterval;

			private static void FindIcons()
			{
				GameObject val = ObjectDB.instance.m_itemByHash[hammerHashCode];
				if (!Object.op_Implicit((Object)(object)val))
				{
					return;
				}
				ItemDrop component = val.GetComponent<ItemDrop>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					return;
				}
				PieceTable buildPieces = component.m_itemData.m_shared.m_buildPieces;
				foreach (GameObject piece in buildPieces.m_pieces)
				{
					Piece component2 = piece.GetComponent<Piece>();
					icons.Add(StringExtensionMethods.GetStableHashCode(((Object)component2).name), component2.m_icon);
				}
			}

			private static bool CheckPin(Minimap __instance, Player player, ZDO zdo, int hashCode, string pinName)
			{
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: 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_008c: Unknown result type (might be due to invalid IL or missing references)
				if (zdo.m_prefab != hashCode)
				{
					return false;
				}
				PinData value;
				bool flag = customPins.TryGetValue(zdo, out value);
				Ship controlledShip = player.GetControlledShip();
				if (Object.op_Implicit((Object)(object)controlledShip) && Vector3.Distance(((Component)controlledShip).transform.position, zdo.m_position) < 0.01f)
				{
					if (flag)
					{
						__instance.RemovePin(value);
						customPins.Remove(zdo);
					}
					return true;
				}
				if (!flag)
				{
					value = __instance.AddPin(zdo.m_position, (PinType)4, pinName, false, false, 0L, "");
					if (icons.TryGetValue(hashCode, out var value2))
					{
						value.m_icon = value2;
					}
					value.m_doubleSize = true;
					customPins.Add(zdo, value);
				}
				else
				{
					value.m_pos = zdo.m_position;
				}
				return true;
			}

			public static void Postfix(ref Minimap __instance, Player player, float dt, bool takeInput)
			{
				timeCounter += dt;
				if (timeCounter < updateInterval)
				{
					return;
				}
				timeCounter -= updateInterval;
				if (icons.Count == 0)
				{
					FindIcons();
				}
				List<ZDO>[] objectsBySector = ZDOMan.instance.m_objectsBySector;
				foreach (List<ZDO> list in objectsBySector)
				{
					if (list == null)
					{
						continue;
					}
					foreach (ZDO item in list)
					{
						for (int j = 0; j < HashCodes.Length && !CheckPin(__instance, player, item, HashCodes[j], PinNames[j]); j++)
						{
						}
					}
				}
				List<ZDO> list2 = new List<ZDO>();
				foreach (KeyValuePair<ZDO, PinData> customPin in customPins)
				{
					if (!customPin.Key.IsValid())
					{
						__instance.RemovePin(customPin.Value);
						list2.Add(customPin.Key);
					}
				}
				foreach (ZDO item2 in list2)
				{
					customPins.Remove(item2);
				}
			}
		}

		private static Dictionary<ZDO, PinData> customPins = new Dictionary<ZDO, PinData>();

		private static Dictionary<int, Sprite> icons = new Dictionary<int, Sprite>();

		private static int[] HashCodes = new int[4]
		{
			StringExtensionMethods.GetStableHashCode("Cart"),
			StringExtensionMethods.GetStableHashCode("Raft"),
			StringExtensionMethods.GetStableHashCode("Karve"),
			StringExtensionMethods.GetStableHashCode("VikingShip")
		};

		private static string[] PinNames = new string[4] { "Cart", "Raft", "Karve", "Longship" };

		private static int hammerHashCode = StringExtensionMethods.GetStableHashCode("Hammer");

		private static float updateInterval = 5f;
	}
	[HarmonyPatch(typeof(Piece), "DropResources")]
	public static class PieceDropResourcesTranspiler
	{
		private static MethodInfo _methodPieceIsPlacedByPlayer = AccessTools.Method(typeof(Piece), "IsPlacedByPlayer", (Type[])null, (Type[])null);

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

		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				if (CodeInstructionExtensions.Calls(list[i], _methodPieceIsPlacedByPlayer))
				{
					list[i] = new CodeInstruction(OpCodes.Ldc_I4_1, (object)null);
					list.RemoveAt(i - 1);
				}
			}
			for (int j = 0; j < list.Count; j++)
			{
				if (CodeInstructionExtensions.LoadsField(list[j], _fieldRequirementMRecover, false))
				{
					list.RemoveRange(j - 1, 3);
				}
			}
			return list;
		}
	}
	[HarmonyPatch(typeof(ItemData), "GetMaxDurability", new Type[] { typeof(int) })]
	public static class ItemDrop_GetMaxDurability_Patch
	{
		private static HashSet<string> itemsToChangeDurability = new HashSet<string> { "hammer", "cultivator", "hoe", "torch" };

		private static bool Prefix(ref ItemData __instance, ref int quality, ref float __result)
		{
			string item = __instance.m_shared.m_name.Split('_', '$')[1];
			if (itemsToChangeDurability.Contains(item))
			{
				float targetValue = __instance.m_shared.m_maxDurability + (float)Mathf.Max(0, quality - 1) * __instance.m_shared.m_durabilityPerLevel;
				__result = sFunc.applyModifierValue(targetValue, 200f);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "EatFood")]
	public static class Player_EatFood_Transpiler
	{
		private static FieldInfo field_ItemDrop_ItemData_SharedData_m_foodBurnTime;

		private static MethodInfo method_ComputeModifiedFoodBurnTime;

		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				if (CodeInstructionExtensions.LoadsField(list[i], field_ItemDrop_ItemData_SharedData_m_foodBurnTime, false))
				{
					list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)method_ComputeModifiedFoodBurnTime));
					i++;
				}
			}
			return list.AsEnumerable();
		}

		private static float ComputeModifiedFoodBurnTime(float foodBurnTime)
		{
			return sFunc.applyModifierValue(foodBurnTime, 100f);
		}

		static Player_EatFood_Transpiler()
		{
			field_ItemDrop_ItemData_SharedData_m_foodBurnTime = AccessTools.Field(typeof(SharedData), "m_foodBurnTime");
			method_ComputeModifiedFoodBurnTime = AccessTools.Method(typeof(Player_EatFood_Transpiler), "ComputeModifiedFoodBurnTime", (Type[])null, (Type[])null);
		}
	}
	[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
	public static class Player_GetTotalFoodValue_Transpiler
	{
		private static FieldInfo field_Food_m_health = AccessTools.Field(typeof(Food), "m_health");

		private static FieldInfo field_Food_m_stamina = AccessTools.Field(typeof(Food), "m_stamina");

		private static FieldInfo field_Food_m_item = AccessTools.Field(typeof(Food), "m_item");

		private static FieldInfo field_ItemData_m_shared = AccessTools.Field(typeof(ItemData), "m_shared");

		private static FieldInfo field_SharedData_m_food = AccessTools.Field(typeof(SharedData), "m_food");

		private static FieldInfo field_SharedData_m_foodStamina = AccessTools.Field(typeof(SharedData), "m_foodStamina");

		[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
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			for (int i = 0; i < list.Count; i++)
			{
				bool flag = CodeInstructionExtensions.LoadsField(list[i], field_Food_m_health, false);
				bool flag2 = CodeInstructionExtensions.LoadsField(list[i], field_Food_m_stamina, false);
				if (flag || flag2)
				{
					list[i].operand = field_Food_m_item;
					list.Insert(++i, new CodeInstruction(OpCodes.Ldfld, (object)field_ItemData_m_shared));
					list.Insert(++i, new CodeInstruction(OpCodes.Ldfld, (object)(flag ? field_SharedData_m_food : field_SharedData_m_foodStamina)));
					i++;
				}
			}
			return list.AsEnumerable();
		}
	}
	public class Fuel
	{
		[HarmonyPatch(typeof(Fireplace), "UpdateFireplace")]
		private class Fireplace_UpdateFireplace_Patch
		{
			[HarmonyPrefix]
			private static void Fireplace_UpdateFireplace(Fireplace __instance, ref ZNetView ___m_nview)
			{
				___m_nview.GetZDO().Set("fuel", __instance.m_maxFuel);
			}
		}

		[HarmonyPatch(typeof(CookingStation), "SetFuel")]
		private class CookingStation_SetFuel_Patch
		{
			[HarmonyPrefix]
			private static void CookingStation_SetFuel(CookingStation __instance, ref float fuel)
			{
				fuel = __instance.m_maxFuel;
			}
		}

		[HarmonyPatch(typeof(CookingStation), "Awake")]
		private class CookingStation_Awake_Patch
		{
			[HarmonyPostfix]
			private static void CookingStation_Awake(CookingStation __instance, ref ZNetView ___m_nview)
			{
				if (!((Object)(object)Player.m_localPlayer == (Object)null) && !((Character)Player.m_localPlayer).IsTeleporting())
				{
					Refuel(___m_nview);
				}
			}
		}

		public static async void Refuel(ZNetView ___m_nview)
		{
			if (!((Object)(object)___m_nview == (Object)null) && ((Behaviour)___m_nview).isActiveAndEnabled)
			{
				await Task.Delay(33);
				___m_nview.InvokeRPC("AddFuel", Array.Empty<object>());
			}
		}
	}
	[HarmonyPatch(typeof(DropTable), "GetDropList", new Type[] { typeof(int) })]
	public static class DropTable_GetDropList_Patch
	{
		private static void Postfix(ref DropTable __instance, ref List<GameObject> __result, int amount)
		{
			__instance.m_dropChance = 1f;
			List<string> list = new List<string> { "Wood", "RoundLog", "Stone", "FineWood" };
			Dictionary<string, Tuple<int, GameObject>> dictionary = new Dictionary<string, Tuple<int, GameObject>>();
			List<GameObject> list2 = new List<GameObject>();
			foreach (GameObject item2 in __result)
			{
				if (list.Contains(((Object)item2).name))
				{
					if (!dictionary.ContainsKey(((Object)item2).name))
					{
						dictionary.Add(((Object)item2).name, new Tuple<int, GameObject>(1, item2));
						continue;
					}
					int item = dictionary[((Object)item2).name].Item1;
					dictionary[((Object)item2).name] = new Tuple<int, GameObject>(item + 1, item2);
				}
				else
				{
					list2.Add(item2);
				}
			}
			__result.Clear();
			__result.AddRange(list2);
			foreach (KeyValuePair<string, Tuple<int, GameObject>> item3 in dictionary)
			{
				int num = Mathf.RoundToInt(sFunc.applyModifierValue(item3.Value.Item1, 50f));
				for (int i = 0; i < num; i++)
				{
					__result.Add(item3.Value.Item2);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player), "UseStamina")]
	public static class Player_UseStamina_Patch
	{
		private static void Prefix(ref Player __instance, ref float v)
		{
			string name = new StackTrace().GetFrame(2).GetMethod().Name;
			if (name.Contains("UpdatePlacement") || name.Contains("Repair") || name.Contains("RemovePiece"))
			{
				switch (((Humanoid)__instance).GetRightItem()?.m_shared.m_name)
				{
				case "$item_hammer":
					v = sFunc.applyModifierValue(v, -100f);
					break;
				case "$item_hoe":
					v = sFunc.applyModifierValue(v, -100f);
					break;
				case "$item_cultivator":
					v = sFunc.applyModifierValue(v, -100f);
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(WearNTear), "HaveRoof")]
	public static class RemoveWearNTear
	{
		private static void Postfix(ref bool __result)
		{
			__result = true;
		}
	}
	[HarmonyPatch(typeof(WearNTear), "IsUnderWater")]
	public static class RemoveWearNTearFromUnderWater
	{
		private static void Postfix(ref bool __result)
		{
			__result = false;
		}
	}
	[HarmonyPatch(typeof(CraftingStation), "CheckUsable")]
	public static class WorkbenchRemoveRestrictions
	{
		private static bool Prefix(ref CraftingStation __instance, ref Player player, ref bool showMessage, ref bool __result)
		{
			__instance.m_craftRequireRoof = false;
			return true;
		}
	}
}