Decompiled source of FixCollection v1.0.0

Sidious-FixCollection.dll

Decompiled 9 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dissonance;
using EnemyFix.Patches;
using FixRPCLag.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NutcrackerFixes.Patches;
using PathfindingLagFix.Patches;
using Sidious;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Sidious-FixCollection")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Sidious-FixCollection")]
[assembly: AssemblyTitle("Sidious-FixCollection")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[HarmonyPatch(typeof(MissFireFixPatch))]
internal class MissFireFixPatch
{
	[HarmonyPatch(typeof(ShotgunItem), "Update")]
	public class ShotgunItem_Update_Patch
	{
		public static void Postfix(ShotgunItem __instance)
		{
			__instance.misfireTimer = 9999f;
		}
	}
}
[HarmonyPatch(typeof(MaskedPlayerEnemy))]
internal class MaskedPlayerEnemyPatch
{
	[HarmonyPatch("CancelSpecialAnimationWithPlayer")]
	[HarmonyPrefix]
	private static bool CancelSpecialAnimationWithPlayerPatch(MaskedPlayerEnemy __instance)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		//IL_001f: Expected O, but got Unknown
		if ((Object)((EnemyAI)__instance).inSpecialAnimationWithPlayer == (Object)GameNetworkManager.Instance.localPlayerController)
		{
			SidiousFix_Collection.Instance.g_Log.LogInfo((object)"Removing biohazardDamage animation");
			HUDManager.Instance.HUDAnimator.SetBool("biohazardDamage", false);
			HUDManager.Instance.HideHUD(true);
			HUDManager.Instance.HideHUD(false);
		}
		__instance.FinishKillAnimation(false);
		((EnemyAI)__instance).inSpecialAnimationWithPlayer = null;
		return false;
	}
}
[HarmonyPatch(typeof(CentipedeAI))]
internal class FixCentipedeLag
{
	private static Dictionary<int, ulong> instanceMap = new Dictionary<int, ulong>();

	private static ulong deadtimer = 100uL;

	[HarmonyPatch("DoAIInterval")]
	[HarmonyPrefix]
	private static void DoAIInterval(CentipedeAI __instance)
	{
		if (((EnemyAI)__instance).TargetClosestPlayer(1.5f, false, 70f))
		{
			return;
		}
		int instanceID = ((Object)__instance).GetInstanceID();
		ulong num = (ulong)Time.frameCount;
		if (!instanceMap.ContainsKey(instanceID))
		{
			instanceMap.Add(instanceID, num);
			return;
		}
		ulong num2 = instanceMap[instanceID];
		if (num - num2 <= deadtimer)
		{
			((EnemyAI)__instance).KillEnemy(true);
			instanceMap.Remove(instanceID);
		}
		else
		{
			instanceMap[instanceID] = num;
		}
	}
}
namespace PathfindingLagFix.Patches
{
	public class SequenceMatch
	{
		public int Start;

		public int End;

		public SequenceMatch(int start, int end)
		{
			Start = start;
			End = end;
		}
	}
	public static class Common
	{
		public static SequenceMatch FindIndexOfSequence<T>(this List<T> list, int startIndex, int count, IEnumerable<Predicate<T>> predicates)
		{
			int num;
			for (num = startIndex; num < list.Count(); num++)
			{
				IEnumerator<Predicate<T>> enumerator = predicates.GetEnumerator();
				if (!enumerator.MoveNext())
				{
					return null;
				}
				num = list.FindIndex(num, enumerator.Current);
				if (num < 0)
				{
					break;
				}
				bool flag = true;
				int num2 = 1;
				while (enumerator.MoveNext())
				{
					if (num2 >= list.Count() - num || !enumerator.Current(list[num + num2]))
					{
						flag = false;
						break;
					}
					num2++;
				}
				if (flag)
				{
					return new SequenceMatch(num, num + predicates.Count());
				}
			}
			return null;
		}

		public static SequenceMatch FindIndexOfSequence<T>(this List<T> list, int startIndex, IEnumerable<Predicate<T>> predicates)
		{
			return list.FindIndexOfSequence(startIndex, -1, predicates);
		}

		public static SequenceMatch FindIndexOfSequence<T>(this List<T> list, IEnumerable<Predicate<T>> predicates)
		{
			return list.FindIndexOfSequence(0, -1, predicates);
		}

		public static IEnumerable<T> IndexRangeView<T>(this List<T> list, int start, int end)
		{
			for (int i = start; i < end; i++)
			{
				yield return list[i];
			}
		}

		public static IEnumerable<T> IndexRangeView<T>(this List<T> list, SequenceMatch range)
		{
			return list.IndexRangeView(range.Start, range.End);
		}

		public static void RemoveIndexRange<T>(this List<T> list, int start, int end)
		{
			list.RemoveRange(start, end - start);
		}

		public static void RemoveIndicesRange<T>(this List<T> list, SequenceMatch range)
		{
			list.RemoveIndexRange(range.Start, range.End);
		}

		public static void TransferLabelsAndVariables(this IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			Dictionary<LocalBuilder, LocalBuilder> localDict = new Dictionary<LocalBuilder, LocalBuilder>();
			Dictionary<Label, Label> labelDict = new Dictionary<Label, Label>();
			foreach (CodeInstruction instruction in instructions)
			{
				if (instruction.operand is LocalBuilder local2)
				{
					instruction.operand = GetLocal(local2);
				}
				for (int i = 0; i < instruction.labels.Count(); i++)
				{
					instruction.labels[i] = GetLabel(instruction.labels[i]);
				}
				if (instruction.operand is Label label2)
				{
					instruction.operand = GetLabel(label2);
				}
			}
			Label GetLabel(Label label)
			{
				if (!labelDict.ContainsKey(label))
				{
					labelDict[label] = generator.DefineLabel();
				}
				return labelDict[label];
			}
			LocalBuilder GetLocal(LocalBuilder local)
			{
				if (!localDict.ContainsKey(local))
				{
					localDict[local] = generator.DeclareLocal(local.LocalType);
				}
				return localDict[local];
			}
		}

		public static int GetLocalIndex(this CodeInstruction instruction)
		{
			if (instruction.opcode == OpCodes.Ldloc_0 || instruction.opcode == OpCodes.Stloc_0)
			{
				return 0;
			}
			if (instruction.opcode == OpCodes.Ldloc_1 || instruction.opcode == OpCodes.Stloc_1)
			{
				return 1;
			}
			if (instruction.opcode == OpCodes.Ldloc_2 || instruction.opcode == OpCodes.Stloc_2)
			{
				return 2;
			}
			if (instruction.opcode == OpCodes.Ldloc_3 || instruction.opcode == OpCodes.Stloc_3)
			{
				return 3;
			}
			if (instruction.opcode != OpCodes.Ldloc || instruction.opcode != OpCodes.Ldloc_S || instruction.opcode != OpCodes.Ldloca || instruction.opcode != OpCodes.Ldloca_S || instruction.opcode != OpCodes.Stloc || instruction.opcode != OpCodes.Stloc_S)
			{
				return -1;
			}
			return ((LocalBuilder)instruction.operand).LocalIndex;
		}

		public static int PopCount(this CodeInstruction instruction)
		{
			if (instruction.opcode == OpCodes.Call || instruction.opcode == OpCodes.Callvirt)
			{
				return ((MethodInfo)instruction.operand).GetParameters().Length;
			}
			return instruction.opcode.StackBehaviourPop switch
			{
				StackBehaviour.Pop0 => 0, 
				StackBehaviour.Pop1 => 1, 
				StackBehaviour.Pop1_pop1 => 2, 
				StackBehaviour.Popi => 1, 
				StackBehaviour.Popi_pop1 => 2, 
				StackBehaviour.Popi_popi => 2, 
				StackBehaviour.Popi_popi8 => 2, 
				StackBehaviour.Popi_popi_popi => 3, 
				StackBehaviour.Popi_popr4 => 2, 
				StackBehaviour.Popi_popr8 => 2, 
				StackBehaviour.Popref => 1, 
				StackBehaviour.Popref_pop1 => 2, 
				StackBehaviour.Popref_popi => 2, 
				StackBehaviour.Popref_popi_popi => 3, 
				StackBehaviour.Popref_popi_popi8 => 3, 
				StackBehaviour.Popref_popi_popr4 => 3, 
				StackBehaviour.Popref_popi_popr8 => 3, 
				StackBehaviour.Popref_popi_popref => 3, 
				StackBehaviour.Varpop => throw new NotImplementedException("Variable pop on non-call instruction"), 
				StackBehaviour.Popref_popi_pop1 => 3, 
				_ => throw new NotSupportedException($"StackBehaviourPop of {instruction.opcode.StackBehaviourPop} was not a pop for instruction '{instruction}'"), 
			};
		}

		public static int PushCount(this CodeInstruction instruction)
		{
			if (instruction.opcode == OpCodes.Call || instruction.opcode == OpCodes.Callvirt)
			{
				return 1;
			}
			return instruction.opcode.StackBehaviourPush switch
			{
				StackBehaviour.Push0 => 1, 
				StackBehaviour.Push1 => 1, 
				StackBehaviour.Push1_push1 => 2, 
				StackBehaviour.Pushi => 1, 
				StackBehaviour.Pushi8 => 1, 
				StackBehaviour.Pushr4 => 1, 
				StackBehaviour.Pushr8 => 1, 
				StackBehaviour.Pushref => 1, 
				StackBehaviour.Varpush => throw new NotImplementedException("Variable push on non-call instruction"), 
				_ => throw new NotSupportedException($"StackBehaviourPush of {instruction.opcode.StackBehaviourPush} was not a push for instruction '{instruction}'"), 
			};
		}

		public static SequenceMatch InstructionRangeForStackItems(this List<CodeInstruction> instructions, int instructionIndex, int startIndex, int endIndex)
		{
			int num = -1;
			int num2 = -1;
			instructionIndex--;
			int num3 = 0;
			while (instructionIndex >= 0)
			{
				CodeInstruction instruction = instructions[instructionIndex];
				int num4 = instruction.PushCount();
				if (num2 == -1 && num3 == startIndex && num4 > 0)
				{
					num2 = instructionIndex + 1;
				}
				num3 += instruction.PushCount();
				num3 -= instruction.PopCount();
				if (num3 > endIndex)
				{
					num = instructionIndex;
					break;
				}
				instructionIndex--;
			}
			if (num == -1 || num2 == -1)
			{
				return null;
			}
			return new SequenceMatch(num, num2);
		}

		public static Exception PatchError(string message, string patchName)
		{
			return new Exception(message + ", " + patchName + " may not be supported on this game version");
		}

		public static Exception StubError(string name, string patchName)
		{
			return new NotSupportedException(name + " stub was called, " + patchName + " may not be supported on this game version");
		}
	}
	public static class Coroutines
	{
		public static IEnumerator<Transform> ChooseFarthestNodeFromPosition(EnemyAI enemy, Vector3 pos, bool avoidLineOfSight = false, int offset = 0)
		{
			//IL_000e: 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)
			GameObject[] candidateNodes = enemy.allAINodes.OrderByDescending((GameObject node) => Vector3.Distance(pos, node.transform.position)).ToArray();
			yield return null;
			Transform firstAccessibleNode = null;
			int pathsRemaining = offset;
			for (int i = 0; i < candidateNodes.Length; i++)
			{
				Transform transform = candidateNodes[i].transform;
				Vector3 position = transform.position;
				if (!enemy.agent.CalculatePath(position, enemy.path1))
				{
					yield return null;
					continue;
				}
				if ((Object)(object)firstAccessibleNode == (Object)null)
				{
					firstAccessibleNode = transform;
				}
				if (Vector3.Distance(enemy.path1.corners[enemy.path1.corners.Length - 1], RoundManager.Instance.GetNavMeshPosition(position, RoundManager.Instance.navHit, 2.7f, -1)) > 1.5f)
				{
					yield return null;
					continue;
				}
				if (avoidLineOfSight)
				{
					bool flag = false;
					for (int j = 1; j < enemy.path1.corners.Length; j++)
					{
						if (flag)
						{
							break;
						}
						flag = Physics.Linecast(enemy.path1.corners[j - 1], enemy.path1.corners[j], 262144);
					}
					if (flag)
					{
						yield return null;
						continue;
					}
				}
				enemy.mostOptimalDistance = Vector3.Distance(pos, transform.position);
				yield return transform;
				if (pathsRemaining == 0)
				{
					yield break;
				}
				pathsRemaining--;
			}
			if (avoidLineOfSight)
			{
				yield return firstAccessibleNode;
			}
		}
	}
	[HarmonyPatch(typeof(CentipedeAI))]
	public class PatchCentipedeAI
	{
		private static readonly FieldInfo f_CentipedeAI_mainEntrancePosition = AccessTools.Field(typeof(CentipedeAI), "mainEntrancePosition");

		private static readonly FieldInfo f_CentipedeAI_choseHidingSpotNoPlayersNearby = AccessTools.Field(typeof(CentipedeAI), "choseHidingSpotNoPlayersNearby");

		public const string PATCH_NAME = "Snare Flea lag patch";

		public static int NoPlayerToTargetNodeVar = -1;

		public static List<CodeInstruction> NoPlayerToTargetInstructions = null;

		public static void FinishChoosingFarthestNodeFromEntrance(CentipedeAI centipede, Transform node)
		{
			throw Common.StubError("FinishChoosingFarthestNodeFromEntrance", "Snare Flea lag patch");
		}

		private static IEnumerator ChooseFarthestNodeFromEntrance(CentipedeAI centipede, Vector3 position, bool avoidLineOfSight, int offset)
		{
			//IL_000e: 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)
			IEnumerator<Transform> farthestNodeCoroutine = Coroutines.ChooseFarthestNodeFromPosition((EnemyAI)(object)centipede, position, avoidLineOfSight, offset);
			Transform lastTransform = null;
			while (farthestNodeCoroutine.MoveNext())
			{
				if ((Object)(object)farthestNodeCoroutine.Current != (Object)null)
				{
					lastTransform = farthestNodeCoroutine.Current;
				}
				yield return null;
			}
			((EnemyAI)centipede).searchCoroutine = null;
			if (!((Object)(object)farthestNodeCoroutine.Current == (Object)null))
			{
				FinishChoosingFarthestNodeFromEntrance(centipede, lastTransform);
			}
		}

		[HarmonyPatch("DoAIInterval")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> DoAIIntervalTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Expected O, but got Unknown
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Expected O, but got Unknown
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Expected O, but got Unknown
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Expected O, but got Unknown
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Expected O, but got Unknown
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Expected O, but got Unknown
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Expected O, but got Unknown
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			list.FindIndexOfSequence(new Predicate<CodeInstruction>[2]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Reflection.m_EnemyAI_TargetClosestPlayer),
				(CodeInstruction insn) => insn.opcode == OpCodes.Brtrue || insn.opcode == OpCodes.Brtrue_S
			});
			SequenceMatch sequenceMatch = list.FindIndexOfSequence(new Predicate<CodeInstruction>[3]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, f_CentipedeAI_choseHidingSpotNoPlayersNearby, false),
				(CodeInstruction insn) => insn.opcode == OpCodes.Brtrue || insn.opcode == OpCodes.Brtrue_S
			});
			Label hasChosenHidingSpotLabel = (Label)list[sequenceMatch.End - 1].operand;
			int num = list.FindIndex(sequenceMatch.End, (CodeInstruction insn) => insn.labels.Contains(hasChosenHidingSpotLabel)) - 1;
			int num2 = list.FindIndex(sequenceMatch.End, (CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Reflection.m_EnemyAI_ChooseFarthestNodeFromPosition));
			if (num2 >= num)
			{
				throw new Exception("Unexpected ordering of instructions in CentipedeAI.DoAIInterval().");
			}
			SequenceMatch sequenceMatch2 = list.InstructionRangeForStackItems(num2, 1, 4);
			NoPlayerToTargetInstructions = list.IndexRangeView(sequenceMatch.End, sequenceMatch2.Start).Append(new CodeInstruction(OpCodes.Ldarg_1, (object)null)).Concat(list.IndexRangeView(num2 + 1, num))
				.ToList();
			List<CodeInstruction> second = list.IndexRangeView(sequenceMatch2.Start, sequenceMatch2.End).ToList();
			list.RemoveIndexRange(sequenceMatch.End, num);
			IEnumerable<CodeInstruction> collection = ((IEnumerable<CodeInstruction>)(object)new CodeInstruction[5]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)Reflection.f_EnemyAI_searchCoroutine),
				new CodeInstruction(OpCodes.Brtrue_S, (object)hasChosenHidingSpotLabel),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null)
			}).Concat(second).Concat((IEnumerable<CodeInstruction>)(object)new CodeInstruction[3]
			{
				CodeInstruction.Call(typeof(PatchCentipedeAI), "ChooseFarthestNodeFromEntrance", new Type[4]
				{
					typeof(CentipedeAI),
					typeof(Vector3),
					typeof(bool),
					typeof(int)
				}, (Type[])null),
				new CodeInstruction(OpCodes.Call, (object)Reflection.m_MonoBehaviour_StartCoroutine),
				new CodeInstruction(OpCodes.Stfld, (object)Reflection.f_EnemyAI_searchCoroutine)
			});
			list.InsertRange(sequenceMatch.End, collection);
			return list;
		}
	}
	[HarmonyPatch(typeof(PatchCentipedeAI))]
	internal class PatchCopyVanillaCentipedeCode
	{
		[HarmonyPatch("FinishChoosingFarthestNodeFromEntrance")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> PatchCentipedeAI_FinishChoosingFarthestNodeFromEntranceTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			List<CodeInstruction> noPlayerToTargetInstructions = PatchCentipedeAI.NoPlayerToTargetInstructions;
			noPlayerToTargetInstructions.TransferLabelsAndVariables(generator);
			return noPlayerToTargetInstructions.Append(new CodeInstruction(OpCodes.Ret, (object)null));
		}
	}
	[HarmonyPatch(typeof(FlowermanAI))]
	public class PatchFlowermanAI
	{
		private static readonly FieldInfo f_FlowermanAI_mainEntrancePosition = AccessTools.Field(typeof(FlowermanAI), "mainEntrancePosition");

		public const string PATCH_NAME = "Bracken lag patch";

		public static int NoPlayerToTargetNodeVar = -1;

		public static List<CodeInstruction> NoPlayerToTargetInstructions = null;

		public static List<CodeInstruction> AvoidClosestPlayerInstructions = null;

		public static void FinishChoosingFarthestNodeFromEntrance(FlowermanAI flowerman, Transform node)
		{
			throw Common.StubError("FinishChoosingFarthestNodeFromEntrance", "Bracken lag patch");
		}

		private static IEnumerator ChooseFarthestNodeFromEntrance(FlowermanAI flowerman, Vector3 mainEntrancePosition)
		{
			//IL_000e: 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)
			IEnumerator<Transform> farthestNodeCoroutine = Coroutines.ChooseFarthestNodeFromPosition((EnemyAI)(object)flowerman, mainEntrancePosition);
			Transform lastTransform = null;
			while (farthestNodeCoroutine.MoveNext())
			{
				if ((Object)(object)farthestNodeCoroutine.Current != (Object)null)
				{
					lastTransform = farthestNodeCoroutine.Current;
				}
				yield return null;
			}
			((EnemyAI)flowerman).searchCoroutine = null;
			if (!((Object)(object)farthestNodeCoroutine.Current == (Object)null))
			{
				FinishChoosingFarthestNodeFromEntrance(flowerman, lastTransform);
			}
		}

		[HarmonyPatch("DoAIInterval")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> DoAIIntervalTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Expected O, but got Unknown
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Expected O, but got Unknown
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Expected O, but got Unknown
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Expected O, but got Unknown
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Expected O, but got Unknown
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Expected O, but got Unknown
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Expected O, but got Unknown
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Expected O, but got Unknown
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Expected O, but got Unknown
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			Label? noPlayerTargetLabel = null;
			list.FindIndexOfSequence(new Predicate<CodeInstruction>[2]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Reflection.m_EnemyAI_TargetClosestPlayer),
				(CodeInstruction insn) => CodeInstructionExtensions.Branches(insn, ref noPlayerTargetLabel)
			});
			int num = list.FindIndex((CodeInstruction insn) => insn.labels.Contains(noPlayerTargetLabel.Value));
			Label afterNoPlayerTargetLabel = (Label)list[num - 1].operand;
			int end = list.FindIndex(num, (CodeInstruction insn) => insn.labels.Contains(afterNoPlayerTargetLabel));
			SequenceMatch sequenceMatch = list.FindIndexOfSequence(num, new Predicate<CodeInstruction>[8]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, f_FlowermanAI_mainEntrancePosition, false),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsConstant(insn, 0L),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsConstant(insn, 0L),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsConstant(insn, 0L),
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Reflection.m_EnemyAI_ChooseFarthestNodeFromPosition),
				(CodeInstruction insn) => CodeInstructionExtensions.IsStloc(insn, (LocalBuilder)null)
			});
			NoPlayerToTargetNodeVar = list[sequenceMatch.End - 1].GetLocalIndex();
			NoPlayerToTargetInstructions = list.IndexRangeView(sequenceMatch.End, end).ToList();
			Label[] array = list[sequenceMatch.Start].labels.ToArray();
			list.RemoveIndexRange(sequenceMatch.Start, end);
			Label label = generator.DefineLabel();
			list[sequenceMatch.Start].labels.Add(label);
			list.InsertRange(sequenceMatch.Start, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[11]
			{
				CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_0, (object)null), array),
				new CodeInstruction(OpCodes.Ldfld, (object)Reflection.f_EnemyAI_searchCoroutine),
				new CodeInstruction(OpCodes.Brtrue_S, (object)label),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)f_FlowermanAI_mainEntrancePosition),
				CodeInstruction.Call(typeof(PatchFlowermanAI), "ChooseFarthestNodeFromEntrance", new Type[2]
				{
					typeof(FlowermanAI),
					typeof(Vector3)
				}, (Type[])null),
				new CodeInstruction(OpCodes.Callvirt, (object)Reflection.m_MonoBehaviour_StartCoroutine),
				new CodeInstruction(OpCodes.Stfld, (object)Reflection.f_EnemyAI_searchCoroutine)
			});
			return list;
		}

		public static void FinishChoosingPlayerEvasionLocation(FlowermanAI flowerman, Transform node)
		{
			throw Common.StubError("FinishChoosingPlayerEvasionLocation", "Bracken lag patch");
		}

		public static IEnumerator ChoosePlayerEvasionLocation(FlowermanAI flowerman)
		{
			IEnumerator<Transform> farthestNodeCoroutine = Coroutines.ChooseFarthestNodeFromPosition((EnemyAI)(object)flowerman, ((Component)((EnemyAI)flowerman).targetPlayer).transform.position, avoidLineOfSight: true);
			Transform lastTransform = null;
			while (farthestNodeCoroutine.MoveNext())
			{
				if ((Object)(object)farthestNodeCoroutine.Current != (Object)null)
				{
					lastTransform = farthestNodeCoroutine.Current;
				}
				yield return null;
			}
			((EnemyAI)flowerman).searchCoroutine = null;
			if ((Object)(object)farthestNodeCoroutine.Current == (Object)null)
			{
				SidiousFix_Collection.Instance.g_Log.LogWarning((object)"Failed to find avoid player target.");
			}
			else
			{
				FinishChoosingPlayerEvasionLocation(flowerman, lastTransform);
			}
		}

		[HarmonyPatch("AvoidClosestPlayer")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> DoAvoidClosestPlayerTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Expected O, but got Unknown
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Expected O, but got Unknown
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Expected O, but got Unknown
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Expected O, but got Unknown
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Expected O, but got Unknown
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Expected O, but got Unknown
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Expected O, but got Unknown
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Expected O, but got Unknown
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			SequenceMatch sequenceMatch = list.FindIndexOfSequence(new Predicate<CodeInstruction>[10]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, Reflection.f_EnemyAI_targetPlayer, false),
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Reflection.m_Component_get_transform),
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Reflection.m_Transform_get_position),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsConstant(insn, 1L),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsConstant(insn, 0L),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsConstant(insn, 1L),
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Reflection.m_EnemyAI_ChooseFarthestNodeFromPosition),
				(CodeInstruction insn) => CodeInstructionExtensions.IsStloc(insn, (LocalBuilder)null)
			});
			int end = list.FindLastIndex((CodeInstruction insn) => insn.opcode == OpCodes.Ret);
			AvoidClosestPlayerInstructions = list.IndexRangeView(sequenceMatch.End, end).ToList();
			Label label = generator.DefineLabel();
			return (IEnumerable<CodeInstruction>)(object)new CodeInstruction[10]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)Reflection.f_EnemyAI_searchCoroutine),
				new CodeInstruction(OpCodes.Brtrue_S, (object)label),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				CodeInstruction.Call(typeof(PatchFlowermanAI), "ChoosePlayerEvasionLocation", new Type[1] { typeof(FlowermanAI) }, (Type[])null),
				new CodeInstruction(OpCodes.Callvirt, (object)Reflection.m_MonoBehaviour_StartCoroutine),
				new CodeInstruction(OpCodes.Stfld, (object)Reflection.f_EnemyAI_searchCoroutine),
				CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ret, (object)null), new Label[1] { label })
			};
		}
	}
	[HarmonyPatch(typeof(PatchFlowermanAI))]
	internal class PatchCopyVanillaFlowermanCode
	{
		[HarmonyPatch("FinishChoosingPlayerEvasionLocation")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> PatchFlowermanAI_FinishChoosingPlayerEvasionLocationTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			if (PatchFlowermanAI.AvoidClosestPlayerInstructions == null)
			{
				throw Common.PatchError("Code was not copied from FlowermanAI.AvoidPlayerTarget()", "Bracken lag patch");
			}
			CodeInstruction[] array = PatchFlowermanAI.AvoidClosestPlayerInstructions.ToArray();
			if (!CodeInstructionExtensions.IsLdloc(array[0], (LocalBuilder)null))
			{
				throw Common.PatchError("Copied code from FlowermanAI.AvoidPlayerTarget() does not begin with an ldloc", "Bracken lag patch");
			}
			LocalBuilder localBuilder = (LocalBuilder)array[0].operand;
			for (int i = 0; i < array.Length; i++)
			{
				CodeInstruction val = array[i];
				if (CodeInstructionExtensions.IsLdloc(val, localBuilder))
				{
					array[i] = CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_1, (object)null), (IEnumerable<Label>)val.labels);
				}
			}
			array.TransferLabelsAndVariables(generator);
			return array.Append(new CodeInstruction(OpCodes.Ret, (object)null));
		}

		[HarmonyPatch("FinishChoosingFarthestNodeFromEntrance")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> PatchFlowermanAI_FinishChoosingFarthestNodeFromEntranceTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			if (PatchFlowermanAI.NoPlayerToTargetNodeVar == -1)
			{
				throw Common.PatchError("Target node variable was not found in DoAIInterval()", "Bracken lag patch");
			}
			if (PatchFlowermanAI.NoPlayerToTargetInstructions == null)
			{
				throw Common.PatchError("Code was not copied from DoAIInterval()", "Bracken lag patch");
			}
			List<CodeInstruction> noPlayerToTargetInstructions = PatchFlowermanAI.NoPlayerToTargetInstructions;
			int noPlayerToTargetNodeVar = PatchFlowermanAI.NoPlayerToTargetNodeVar;
			PatchFlowermanAI.NoPlayerToTargetInstructions = null;
			PatchFlowermanAI.NoPlayerToTargetNodeVar = -1;
			for (int i = 0; i < noPlayerToTargetInstructions.Count(); i++)
			{
				CodeInstruction val = noPlayerToTargetInstructions[i];
				if (CodeInstructionExtensions.IsLdloc(val, (LocalBuilder)null) && val.GetLocalIndex() == noPlayerToTargetNodeVar)
				{
					noPlayerToTargetInstructions[i] = CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_1, (object)null), (IEnumerable<Label>)val.labels);
				}
			}
			noPlayerToTargetInstructions.TransferLabelsAndVariables(generator);
			return noPlayerToTargetInstructions.Append(new CodeInstruction(OpCodes.Ret, (object)null));
		}
	}
	[HarmonyPatch(typeof(PufferAI))]
	public class PatchPufferAI
	{
		private static readonly FieldInfo f_PufferAI_closestSeenPlayer = AccessTools.Field(typeof(PufferAI), "closestSeenPlayer");

		public const string PATCH_NAME = "Spore Lizard lag patch";

		public static List<CodeInstruction> AvoidClosestPlayerInstructions = null;

		public static void FinishChoosingPlayerEvasionLocation(PufferAI puffer, Transform node)
		{
			throw Common.StubError("FinishChoosingPlayerEvasionLocation stub was called", "Spore Lizard lag patch");
		}

		public static IEnumerator ChoosePlayerEvasionLocation(PufferAI puffer, Vector3 origin)
		{
			//IL_000e: 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)
			IEnumerator<Transform> farthestNodeCoroutine = Coroutines.ChooseFarthestNodeFromPosition((EnemyAI)(object)puffer, origin, avoidLineOfSight: true);
			Transform lastTransform = null;
			while (farthestNodeCoroutine.MoveNext())
			{
				if ((Object)(object)farthestNodeCoroutine.Current != (Object)null)
				{
					lastTransform = farthestNodeCoroutine.Current;
				}
				yield return null;
			}
			((EnemyAI)puffer).currentSearch = puffer.roamMap;
			if ((Object)(object)farthestNodeCoroutine.Current == (Object)null)
			{
				SidiousFix_Collection.Instance.g_Log.LogWarning((object)"Failed to find avoid player target.");
			}
			else
			{
				FinishChoosingPlayerEvasionLocation(puffer, lastTransform);
			}
		}

		[HarmonyPatch("AvoidClosestPlayer")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> DoAvoidClosestPlayerTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Expected O, but got Unknown
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Expected O, but got Unknown
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Expected O, but got Unknown
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Expected O, but got Unknown
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Expected O, but got Unknown
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Expected O, but got Unknown
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Expected O, but got Unknown
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Expected O, but got Unknown
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Expected O, but got Unknown
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Expected O, but got Unknown
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Expected O, but got Unknown
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Expected O, but got Unknown
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Expected O, but got Unknown
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			SequenceMatch sequenceMatch = list.FindIndexOfSequence(new Predicate<CodeInstruction>[10]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, f_PufferAI_closestSeenPlayer, false),
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Reflection.m_Component_get_transform),
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Reflection.m_Transform_get_position),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsConstant(insn, 1L),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsConstant(insn, 0L),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsConstant(insn, 0L),
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Reflection.m_EnemyAI_ChooseFarthestNodeFromPosition),
				(CodeInstruction insn) => CodeInstructionExtensions.IsStloc(insn, (LocalBuilder)null)
			});
			AvoidClosestPlayerInstructions = list.IndexRangeView(sequenceMatch.End, list.Count()).ToList();
			Label label = generator.DefineLabel();
			Label label2 = generator.DefineLabel();
			return (IEnumerable<CodeInstruction>)(object)new CodeInstruction[17]
			{
				CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_0, (object)null), new Label[1] { label }),
				new CodeInstruction(OpCodes.Ldfld, (object)Reflection.f_EnemyAI_currentSearch),
				new CodeInstruction(OpCodes.Brfalse_S, (object)label2),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)f_PufferAI_closestSeenPlayer),
				new CodeInstruction(OpCodes.Call, (object)Reflection.m_Component_get_transform),
				new CodeInstruction(OpCodes.Call, (object)Reflection.m_Transform_get_position),
				CodeInstruction.Call(typeof(PatchPufferAI), "ChoosePlayerEvasionLocation", new Type[2]
				{
					typeof(PufferAI),
					typeof(Vector3)
				}, (Type[])null),
				new CodeInstruction(OpCodes.Callvirt, (object)Reflection.m_MonoBehaviour_StartCoroutine),
				new CodeInstruction(OpCodes.Stfld, (object)Reflection.f_EnemyAI_searchCoroutine),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldnull, (object)null),
				new CodeInstruction(OpCodes.Stfld, (object)Reflection.f_EnemyAI_currentSearch),
				CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ret, (object)null), new Label[1] { label2 })
			};
		}
	}
	[HarmonyPatch(typeof(PatchPufferAI))]
	internal class PatchCopyVanillaPufferCode
	{
		[HarmonyPatch("FinishChoosingPlayerEvasionLocation")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> PatchPufferAI_FinishChoosingPlayerEvasionLocationTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			if (PatchPufferAI.AvoidClosestPlayerInstructions == null)
			{
				throw Common.PatchError("Code was not copied from PufferAI.AvoidPlayerTarget()", "Spore Lizard lag patch");
			}
			List<CodeInstruction> list = instructions.ToList();
			CodeInstruction[] array = PatchPufferAI.AvoidClosestPlayerInstructions.ToArray();
			if (!CodeInstructionExtensions.IsLdloc(array[0], (LocalBuilder)null))
			{
				throw Common.PatchError("Copied code from PufferAI.AvoidPlayerTarget() does not begin with an ldloc", "Spore Lizard lag patch");
			}
			LocalBuilder localBuilder = (LocalBuilder)array[0].operand;
			for (int i = 0; i < array.Length; i++)
			{
				CodeInstruction val = array[i];
				if (CodeInstructionExtensions.IsLdloc(val, localBuilder))
				{
					array[i] = CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_1, (object)null), (IEnumerable<Label>)val.labels);
				}
			}
			array.TransferLabelsAndVariables(generator);
			list.FindIndex((CodeInstruction insn) => insn.opcode == OpCodes.Ret);
			return array.Append(new CodeInstruction(OpCodes.Ret, (object)null));
		}
	}
	public static class Reflection
	{
		public static readonly MethodInfo m_Debug_Log = typeof(Debug).GetMethod("Log", new Type[1] { typeof(object) });

		public static readonly MethodInfo m_EnemyAI_DoAIInterval = typeof(EnemyAI).GetMethod("DoAIInterval", new Type[0]);

		public static readonly MethodInfo m_EnemyAI_TargetClosestPlayer = typeof(EnemyAI).GetMethod("TargetClosestPlayer", new Type[3]
		{
			typeof(float),
			typeof(bool),
			typeof(float)
		});

		public static readonly MethodInfo m_EnemyAI_ChooseFarthestNodeFromPosition = typeof(EnemyAI).GetMethod("ChooseFarthestNodeFromPosition", new Type[4]
		{
			typeof(Vector3),
			typeof(bool),
			typeof(int),
			typeof(bool)
		});

		public static readonly MethodInfo m_EnemyAI_SetDestinationToPosition = typeof(EnemyAI).GetMethod("SetDestinationToPosition", new Type[2]
		{
			typeof(Vector3),
			typeof(bool)
		});

		public static readonly FieldInfo f_EnemyAI_targetNode = typeof(EnemyAI).GetField("targetNode");

		public static readonly FieldInfo f_EnemyAI_targetPlayer = typeof(EnemyAI).GetField("targetPlayer");

		public static readonly FieldInfo f_EnemyAI_favoriteSpot = typeof(EnemyAI).GetField("favoriteSpot");

		public static readonly FieldInfo f_EnemyAI_searchCoroutine = typeof(EnemyAI).GetField("searchCoroutine");

		public static readonly FieldInfo f_EnemyAI_currentSearch = typeof(EnemyAI).GetField("currentSearch");

		public static readonly MethodInfo m_MonoBehaviour_StartCoroutine = typeof(MonoBehaviour).GetMethod("StartCoroutine", new Type[1] { typeof(IEnumerator) });

		public static readonly MethodInfo m_MonoBehaviour_StopCoroutine = typeof(MonoBehaviour).GetMethod("StopCoroutine", new Type[1] { typeof(Coroutine) });

		public static readonly MethodInfo m_Component_get_transform = typeof(Component).GetMethod("get_transform", new Type[0]);

		public static readonly MethodInfo m_Transform_get_position = typeof(Transform).GetMethod("get_position", new Type[0]);

		public static readonly MethodInfo m_Object_op_Equality = typeof(Object).GetMethod("op_Equality", new Type[2]
		{
			typeof(Object),
			typeof(Object)
		});
	}
}
namespace NutcrackerFixes.Patches
{
	public class SequenceMatch
	{
		public int Start;

		public int End;

		public int Size => End - Start;

		public SequenceMatch(int start, int end)
		{
			Start = start;
			End = end;
		}
	}
	public static class Common
	{
		public static readonly MethodInfo m_Debug_Log = typeof(Debug).GetMethod("Log", new Type[1] { typeof(object) });

		public static MethodInfo GetGenericMethod(Type type, string name, Type[] parameters, Type[] genericArguments)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			MethodInfo[] methods = type.GetMethods();
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name != name)
				{
					continue;
				}
				MethodInfo methodInfo2 = methodInfo;
				if (genericArguments.Length != 0)
				{
					try
					{
						methodInfo2 = methodInfo2.MakeGenericMethod(genericArguments);
					}
					catch
					{
					}
				}
				ParameterInfo[] parameters2 = methodInfo2.GetParameters();
				if (parameters2.Length != parameters.Length)
				{
					continue;
				}
				for (int j = 0; j < parameters.Length; j++)
				{
					if (parameters2[j].ParameterType != parameters[j])
					{
						methodInfo2 = null;
						break;
					}
				}
				if (methodInfo2 != null)
				{
					return methodInfo2;
				}
			}
			throw new MemberNotFoundException("Could not find method " + type.Name + "::" + name);
		}

		public static SequenceMatch FindIndexOfSequence<T>(this List<T> list, int startIndex, int count, IEnumerable<Predicate<T>> predicates)
		{
			int num;
			for (num = startIndex; num < list.Count(); num++)
			{
				IEnumerator<Predicate<T>> enumerator = predicates.GetEnumerator();
				if (!enumerator.MoveNext())
				{
					return null;
				}
				num = list.FindIndex(num, enumerator.Current);
				if (num < 0)
				{
					break;
				}
				bool flag = true;
				int num2 = 1;
				while (enumerator.MoveNext())
				{
					if (num2 >= list.Count() - num || !enumerator.Current(list[num + num2]))
					{
						flag = false;
						break;
					}
					num2++;
				}
				if (flag)
				{
					return new SequenceMatch(num, num + predicates.Count());
				}
			}
			return null;
		}

		public static SequenceMatch FindIndexOfSequence<T>(this List<T> list, int startIndex, IEnumerable<Predicate<T>> predicates)
		{
			return list.FindIndexOfSequence(startIndex, -1, predicates);
		}

		public static SequenceMatch FindIndexOfSequence<T>(this List<T> list, IEnumerable<Predicate<T>> predicates)
		{
			return list.FindIndexOfSequence(0, -1, predicates);
		}
	}
	[HarmonyPatch(typeof(BlobAI))]
	internal class PatchBlobAI
	{
		private static readonly MethodInfo m_Component_get_transform = AccessTools.Method(typeof(Component), "get_transform", new Type[0], (Type[])null);

		private static readonly MethodInfo m_Transform_get_position = AccessTools.Method(typeof(Transform), "get_position", new Type[0], (Type[])null);

		private static readonly MethodInfo m_Transform_set_position = AccessTools.Method(typeof(Transform), "set_position", new Type[1] { typeof(Vector3) }, (Type[])null);

		private static readonly FieldInfo f_PlayerControllerB_gameplayCamera = typeof(PlayerControllerB).GetField("gameplayCamera");

		[HarmonyTranspiler]
		[HarmonyPatch("HitEnemy")]
		private static IEnumerable<CodeInstruction> DoHitEnemyTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			SequenceMatch sequenceMatch = list.FindIndexOfSequence(new Predicate<CodeInstruction>[2]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)2),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, f_PlayerControllerB_gameplayCamera, false)
			});
			CodeInstruction val = list[sequenceMatch.Start];
			Label label = generator.DefineLabel();
			list[sequenceMatch.Start].labels.Add(label);
			Label label2 = generator.DefineLabel();
			int index = list.FindIndex(sequenceMatch.End, (CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_Transform_set_position));
			list[index].labels.Add(label2);
			list.InsertRange(sequenceMatch.Start, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[6]
			{
				new CodeInstruction(val.opcode, val.operand),
				new CodeInstruction(OpCodes.Brtrue_S, (object)label),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Call, (object)m_Component_get_transform),
				new CodeInstruction(OpCodes.Call, (object)m_Transform_get_position),
				new CodeInstruction(OpCodes.Br, (object)label2)
			});
			return list;
		}
	}
	[HarmonyPatch(typeof(NutcrackerEnemyAI))]
	internal class PatchNutcrackerEnemyAI
	{
		[HarmonyTranspiler]
		[HarmonyPatch("TurnTorsoToTargetDegrees")]
		private static IEnumerable<CodeInstruction> TurnTorsoToTargetDegreesTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Calls(instruction, Common.m_Debug_Log))
				{
					yield return new CodeInstruction(OpCodes.Pop, (object)null);
				}
				else
				{
					yield return instruction;
				}
			}
		}
	}
	[HarmonyPatch(typeof(SandSpiderAI))]
	internal class PatchSandSpiderAI
	{
		private static readonly MethodInfo m_NetworkBehavior_get_IsOwner = typeof(NetworkBehaviour).GetMethod("get_IsOwner");

		private static readonly MethodInfo m_SandSpiderAI_TriggerChaseWithPlayer = typeof(SandSpiderAI).GetMethod("TriggerChaseWithPlayer");

		[HarmonyTranspiler]
		[HarmonyPatch("HitEnemy")]
		private static IEnumerable<CodeInstruction> DoHitEnemyTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			Label? label2 = default(Label?);
			SequenceMatch sequenceMatch = list.FindIndexOfSequence(new Predicate<CodeInstruction>[6]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_NetworkBehavior_get_IsOwner),
				(CodeInstruction insn) => CodeInstructionExtensions.Branches(insn, ref label2),
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)null),
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_SandSpiderAI_TriggerChaseWithPlayer)
			});
			Label label = (Label)list[sequenceMatch.Start + 2].operand;
			list.InsertRange(sequenceMatch.Start + 3, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[2]
			{
				new CodeInstruction(list[sequenceMatch.End - 2]),
				new CodeInstruction(OpCodes.Brfalse_S, (object)label)
			});
			return list;
		}
	}
	[HarmonyPatch(typeof(ShotgunItem))]
	internal class PatchShotgunItem
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static RpcReceiveHandler <0>__RPCHandlerSetSafetyServer;

			public static RpcReceiveHandler <1>__RPCHandlerSetSafetyClient;

			public static RpcReceiveHandler <2>__RPCHandlerSynchronizeServer;

			public static RpcReceiveHandler <3>__RPCHandlerSynchronizeClient;
		}

		private static readonly MethodInfo m_PatchShotgunItem_SetSafetyServerRpc = typeof(PatchShotgunItem).GetMethod("SetSafetyServerRpc", new Type[2]
		{
			typeof(ShotgunItem),
			typeof(bool)
		});

		private static readonly FieldInfo f_ShotgunItem_enemyColliders = AccessTools.Field(typeof(ShotgunItem), "enemyColliders");

		private static readonly FieldInfo f_ShotgunItem_safetyOn = typeof(ShotgunItem).GetField("safetyOn");

		private static readonly MethodInfo m_ShotgunItem_SetSafetyControlTip = AccessTools.Method(typeof(ShotgunItem), "SetSafetyControlTip", new Type[0], (Type[])null);

		private static readonly MethodInfo m_Physics_SphereCastNonAlloc = AccessTools.Method(typeof(Physics), "SphereCastNonAlloc", new Type[6]
		{
			typeof(Ray),
			typeof(float),
			typeof(RaycastHit[]),
			typeof(float),
			typeof(int),
			typeof(QueryTriggerInteraction)
		}, (Type[])null);

		private static readonly ConstructorInfo m_HashSet_EnemyAI_Constructor = typeof(HashSet<EnemyAI>).GetConstructor(new Type[0]);

		private static readonly MethodInfo m_HashSet_EnemyAI_Contains = typeof(HashSet<EnemyAI>).GetMethod("Contains", new Type[1] { typeof(EnemyAI) });

		private static readonly MethodInfo m_HashSet_EnemyAI_Add = typeof(HashSet<EnemyAI>).GetMethod("Add", new Type[1] { typeof(EnemyAI) });

		private static readonly MethodInfo m_Component_GetComponent_EnemyAICollisionDetect = Common.GetGenericMethod(typeof(Component), "GetComponent", new Type[0], new Type[1] { typeof(EnemyAICollisionDetect) });

		private static readonly MethodInfo m_Component_TryGetComponent_IHittable = Common.GetGenericMethod(typeof(Component), "TryGetComponent", new Type[1] { typeof(IHittable).MakeByRefType() }, new Type[1] { typeof(IHittable) });

		private static readonly MethodInfo m_UnityEngine_Object_op_Implicit = typeof(Object).GetMethod("op_Implicit", new Type[1] { typeof(Object) });

		private static readonly FieldInfo f_EnemyAICollisionDetect_onlyCollideWhenGrounded = typeof(EnemyAICollisionDetect).GetField("onlyCollideWhenGrounded");

		private static readonly FieldInfo f_EnemyAICollisionDetect_mainScript = typeof(EnemyAICollisionDetect).GetField("mainScript");

		private static readonly MethodInfo m_RaycastHit_get_transform = AccessTools.Method(typeof(RaycastHit), "get_transform", new Type[0], (Type[])null);

		private const uint SET_SAFETY_SERVER_RPC = 391u;

		private const uint SET_SAFETY_CLIENT_RPC = 392u;

		private const uint SYNCHRONIZE_CLIENT_RPC = 393u;

		private const uint SYNCHRONIZE_SERVER_RPC = 394u;

		[HarmonyTranspiler]
		[HarmonyPatch("ShootGun")]
		private static IEnumerable<CodeInstruction> ShootGunTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Expected O, but got Unknown
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Expected O, but got Unknown
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Expected O, but got Unknown
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Expected O, but got Unknown
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Expected O, but got Unknown
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Expected O, but got Unknown
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Expected O, but got Unknown
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Expected O, but got Unknown
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Expected O, but got Unknown
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Expected O, but got Unknown
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Expected O, but got Unknown
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Expected O, but got Unknown
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Expected O, but got Unknown
			//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c6: Expected O, but got Unknown
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Expected O, but got Unknown
			//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Expected O, but got Unknown
			//IL_0615: Unknown result type (might be due to invalid IL or missing references)
			//IL_061b: Expected O, but got Unknown
			//IL_0624: Unknown result type (might be due to invalid IL or missing references)
			//IL_062a: Expected O, but got Unknown
			//IL_0636: Unknown result type (might be due to invalid IL or missing references)
			//IL_063c: Expected O, but got Unknown
			//IL_064a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0650: Expected O, but got Unknown
			//IL_0659: Unknown result type (might be due to invalid IL or missing references)
			//IL_065f: Expected O, but got Unknown
			//IL_0668: Unknown result type (might be due to invalid IL or missing references)
			//IL_066e: Expected O, but got Unknown
			//IL_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0680: Expected O, but got Unknown
			//IL_0688: Unknown result type (might be due to invalid IL or missing references)
			//IL_068e: Expected O, but got Unknown
			//IL_0777: Unknown result type (might be due to invalid IL or missing references)
			//IL_0781: Expected O, but got Unknown
			//IL_07cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d7: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			int num = list.FindIndex((CodeInstruction insn) => insn.opcode == OpCodes.Newarr && insn.operand as Type == typeof(RaycastHit));
			list[num - 1].operand = 50;
			SequenceMatch sequenceMatch = list.FindIndexOfSequence(new Predicate<CodeInstruction>[2]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_Physics_SphereCastNonAlloc),
				(CodeInstruction insn) => CodeInstructionExtensions.IsStloc(insn, (LocalBuilder)null)
			});
			LocalBuilder localBuilder = generator.DeclareLocal(typeof(HashSet<EnemyAI>));
			CodeInstruction[] array = (CodeInstruction[])(object)new CodeInstruction[2]
			{
				new CodeInstruction(OpCodes.Newobj, (object)m_HashSet_EnemyAI_Constructor),
				new CodeInstruction(OpCodes.Stloc, (object)localBuilder)
			};
			list.InsertRange(sequenceMatch.End, array);
			sequenceMatch.End += array.Length;
			Label? label4 = default(Label?);
			SequenceMatch sequenceMatch2 = list.FindIndexOfSequence(sequenceMatch.End, new Predicate<CodeInstruction>[3]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsConstant(insn, 0L),
				(CodeInstruction insn) => CodeInstructionExtensions.IsStloc(insn, (LocalBuilder)null),
				(CodeInstruction insn) => CodeInstructionExtensions.Branches(insn, ref label4)
			});
			LocalBuilder hitEnemyIndexVar = (LocalBuilder)list[sequenceMatch2.Start + 1].operand;
			Label label = generator.DefineLabel();
			Predicate<CodeInstruction>[] first = new Predicate<CodeInstruction>[6]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, f_ShotgunItem_enemyColliders, false),
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdloc(insn, hitEnemyIndexVar),
				(CodeInstruction insn) => insn.opcode == OpCodes.Ldelema,
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_RaycastHit_get_transform),
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_Component_GetComponent_EnemyAICollisionDetect)
			};
			Label? label3 = default(Label?);
			SequenceMatch sequenceMatch3 = list.FindIndexOfSequence(sequenceMatch2.End, first.Concat(new Predicate<CodeInstruction>[3]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_UnityEngine_Object_op_Implicit),
				(CodeInstruction insn) => CodeInstructionExtensions.Branches(insn, ref label3),
				(CodeInstruction insn) => insn.opcode == OpCodes.Ret
			}));
			list.RemoveRange(sequenceMatch3.Start, sequenceMatch3.Size);
			sequenceMatch3.End -= sequenceMatch3.Size;
			LocalBuilder localBuilder2 = generator.DeclareLocal(typeof(EnemyAICollisionDetect));
			CodeInstruction[] array2 = (CodeInstruction[])(object)new CodeInstruction[13]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)f_ShotgunItem_enemyColliders),
				new CodeInstruction(OpCodes.Ldloc, (object)hitEnemyIndexVar),
				new CodeInstruction(OpCodes.Ldelema, (object)typeof(RaycastHit)),
				new CodeInstruction(OpCodes.Call, (object)m_RaycastHit_get_transform),
				new CodeInstruction(OpCodes.Call, (object)m_Component_GetComponent_EnemyAICollisionDetect),
				new CodeInstruction(OpCodes.Stloc, (object)localBuilder2),
				new CodeInstruction(OpCodes.Ldloc, (object)localBuilder2),
				new CodeInstruction(OpCodes.Call, (object)m_UnityEngine_Object_op_Implicit),
				new CodeInstruction(OpCodes.Brfalse_S, (object)label),
				new CodeInstruction(OpCodes.Ldloc, (object)localBuilder2),
				new CodeInstruction(OpCodes.Ldfld, (object)f_EnemyAICollisionDetect_onlyCollideWhenGrounded),
				new CodeInstruction(OpCodes.Brtrue_S, (object)label)
			};
			list.InsertRange(sequenceMatch3.Start, array2);
			SequenceMatch sequenceMatch4 = list.FindIndexOfSequence(sequenceMatch3.Start + array2.Length, first.Concat(new Predicate<CodeInstruction>[2]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, f_EnemyAICollisionDetect_mainScript, false),
				(CodeInstruction insn) => CodeInstructionExtensions.IsStloc(insn, (LocalBuilder)null)
			}));
			LocalBuilder localBuilder3 = (LocalBuilder)list[sequenceMatch4.End - 1].operand;
			list.RemoveRange(sequenceMatch4.Start, sequenceMatch4.Size);
			list.InsertRange(sequenceMatch4.Start, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3]
			{
				new CodeInstruction(OpCodes.Ldloc, (object)localBuilder2),
				new CodeInstruction(OpCodes.Ldfld, (object)f_EnemyAICollisionDetect_mainScript),
				new CodeInstruction(OpCodes.Stloc, (object)localBuilder3)
			});
			Label? label2 = default(Label?);
			SequenceMatch sequenceMatch5 = list.FindIndexOfSequence(sequenceMatch2.End, new Predicate<CodeInstruction>[8]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)0),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsField(insn, f_ShotgunItem_enemyColliders, false),
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdloc(insn, hitEnemyIndexVar),
				(CodeInstruction insn) => insn.opcode == OpCodes.Ldelema,
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_RaycastHit_get_transform),
				(CodeInstruction insn) => insn.opcode == OpCodes.Ldloca_S,
				(CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, m_Component_TryGetComponent_IHittable),
				(CodeInstruction insn) => CodeInstructionExtensions.Branches(insn, ref label2)
			});
			list.InsertRange(sequenceMatch5.End, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[8]
			{
				new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder),
				new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder3),
				new CodeInstruction(OpCodes.Call, (object)m_HashSet_EnemyAI_Contains),
				new CodeInstruction(OpCodes.Brtrue_S, (object)label),
				new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder),
				new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder3),
				new CodeInstruction(OpCodes.Call, (object)m_HashSet_EnemyAI_Add),
				new CodeInstruction(OpCodes.Pop, (object)null)
			});
			SequenceMatch sequenceMatch6 = list.FindIndexOfSequence(sequenceMatch2.End, new Predicate<CodeInstruction>[3]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdloc(insn, (LocalBuilder)null),
				(CodeInstruction insn) => CodeInstructionExtensions.LoadsConstant(insn, 1L),
				(CodeInstruction insn) => insn.opcode == OpCodes.Add
			});
			list[sequenceMatch6.Start].labels.Add(label);
			int num2 = sequenceMatch2.End;
			while (true)
			{
				num2 = list.FindIndex(num2, sequenceMatch6.Start - num2, (CodeInstruction insn) => insn.opcode == OpCodes.Ret);
				if (num2 < 0)
				{
					break;
				}
				list[num2] = new CodeInstruction(OpCodes.Br_S, (object)label);
			}
			num2 = sequenceMatch2.End;
			while (true)
			{
				num2 = list.FindIndex(num2, sequenceMatch6.Start - num2, (CodeInstruction insn) => CodeInstructionExtensions.Calls(insn, Common.m_Debug_Log));
				if (num2 < 0)
				{
					break;
				}
				list[num2] = new CodeInstruction(OpCodes.Pop, (object)null);
			}
			return list;
		}

		[HarmonyPostfix]
		[HarmonyPatch("EquipItem")]
		private static void EquipItemPostfix(ShotgunItem __instance)
		{
			SynchronizeServerRpc(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch("LoadItemSaveData")]
		private static void LoadItemSaveDataPostfix(ShotgunItem __instance)
		{
			SetSafetyServerRpc(__instance, __instance.safetyOn);
		}

		[HarmonyTranspiler]
		[HarmonyPatch("ItemInteractLeftRight")]
		private static IEnumerable<CodeInstruction> ItemInteractLeftRightTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			SequenceMatch sequenceMatch = list.FindIndexOfSequence(new Predicate<CodeInstruction>[2]
			{
				(CodeInstruction insn) => CodeInstructionExtensions.IsLdarg(insn, (int?)1),
				(CodeInstruction insn) => insn.opcode == OpCodes.Brtrue || insn.opcode == OpCodes.Brtrue_S
			});
			Label isLeftInteractEndLabel = (Label)list[sequenceMatch.End - 1].operand;
			int num = list.FindIndex((CodeInstruction insn) => insn.labels.Contains(isLeftInteractEndLabel));
			Label label = generator.DefineLabel();
			list[sequenceMatch.End].labels.Add(label);
			CodeInstruction[] array = (CodeInstruction[])(object)new CodeInstruction[4]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Call, (object)Reflection.m_NetworkBehaviour_get_IsOwner),
				new CodeInstruction(OpCodes.Brtrue_S, (object)label),
				new CodeInstruction(OpCodes.Ret, (object)null)
			};
			list.InsertRange(sequenceMatch.End, array);
			CodeInstruction[] collection = (CodeInstruction[])(object)new CodeInstruction[4]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)f_ShotgunItem_safetyOn),
				new CodeInstruction(OpCodes.Call, (object)m_PatchShotgunItem_SetSafetyServerRpc)
			};
			list.InsertRange(num - 1 + array.Length, collection);
			return list;
		}

		public static void SetSafetyServerRpc(ShotgunItem shotgun, bool safetyOn)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)shotgun).IsOwner && !((NetworkBehaviour)shotgun).IsHost && !((NetworkBehaviour)shotgun).IsServer)
			{
				return;
			}
			NetworkManager networkManager = ((NetworkBehaviour)shotgun).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if (((NetworkBehaviour)shotgun).IsHost || ((NetworkBehaviour)shotgun).IsServer)
				{
					SetSafetyClientRpc(shotgun, safetyOn);
				}
				else if (((NetworkBehaviour)shotgun).IsClient)
				{
					ServerRpcParams rpcParams = default(ServerRpcParams);
					FastBufferWriter buffer = Reflection.BeginSendServerRPC((NetworkBehaviour)(object)shotgun, 391u, rpcParams, (RpcDelivery)0);
					((FastBufferWriter)(ref buffer)).WriteValueSafe<bool>(ref safetyOn, default(ForPrimitives));
					Reflection.EndSendServerRPC((NetworkBehaviour)(object)shotgun, ref buffer, 391u, rpcParams, (RpcDelivery)0);
				}
			}
		}

		public static void SetSafetyClientRpc(ShotgunItem shotgun, bool safetyOn)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (((NetworkBehaviour)shotgun).IsOwner || ((NetworkBehaviour)shotgun).IsHost || ((NetworkBehaviour)shotgun).IsServer)
			{
				NetworkManager networkManager = ((NetworkBehaviour)shotgun).NetworkManager;
				if (networkManager != null && networkManager.IsListening && (((NetworkBehaviour)shotgun).IsHost || ((NetworkBehaviour)shotgun).IsServer))
				{
					ClientRpcParams rpcParams = default(ClientRpcParams);
					FastBufferWriter buffer = Reflection.BeginSendClientRPC((NetworkBehaviour)(object)shotgun, 392u, rpcParams, (RpcDelivery)0);
					((FastBufferWriter)(ref buffer)).WriteValueSafe<bool>(ref safetyOn, default(ForPrimitives));
					Reflection.EndSendClientRPC((NetworkBehaviour)(object)shotgun, ref buffer, 392u, rpcParams, (RpcDelivery)0);
				}
			}
		}

		private static void RPCHandlerSetSafetyServer(NetworkBehaviour target, FastBufferReader reader, __RpcParams parameters)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool safetyOn = default(bool);
				((FastBufferReader)(ref reader)).ReadValue<bool>(ref safetyOn, default(ForPrimitives));
				SetSafetyClientRpc((ShotgunItem)target, safetyOn);
			}
		}

		private static void RPCHandlerSetSafetyClient(NetworkBehaviour target, FastBufferReader reader, __RpcParams parameters)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool safetyOn = default(bool);
				((FastBufferReader)(ref reader)).ReadValue<bool>(ref safetyOn, default(ForPrimitives));
				SetSafety((ShotgunItem)target, safetyOn);
			}
		}

		private static void SetSafety(ShotgunItem shotgun, bool safetyOn)
		{
			shotgun.safetyOn = safetyOn;
			m_ShotgunItem_SetSafetyControlTip.Invoke(shotgun, new object[0]);
		}

		public static void SynchronizeServerRpc(ShotgunItem shotgun)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)shotgun).IsOwner || ((NetworkBehaviour)shotgun).IsHost || ((NetworkBehaviour)shotgun).IsServer)
			{
				return;
			}
			NetworkManager networkManager = ((NetworkBehaviour)shotgun).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if (((NetworkBehaviour)shotgun).IsHost || ((NetworkBehaviour)shotgun).IsServer)
				{
					SynchronizeClientRpc(shotgun);
				}
				else if (((NetworkBehaviour)shotgun).IsClient)
				{
					ServerRpcParams rpcParams = default(ServerRpcParams);
					FastBufferWriter buffer = Reflection.BeginSendServerRPC((NetworkBehaviour)(object)shotgun, 394u, rpcParams, (RpcDelivery)0);
					Reflection.EndSendServerRPC((NetworkBehaviour)(object)shotgun, ref buffer, 394u, rpcParams, (RpcDelivery)0);
				}
			}
		}

		public static void SynchronizeClientRpc(ShotgunItem shotgun)
		{
			//IL_0036: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_005a: 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_0070: 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)
			if (((NetworkBehaviour)shotgun).IsHost || ((NetworkBehaviour)shotgun).IsServer)
			{
				NetworkManager networkManager = ((NetworkBehaviour)shotgun).NetworkManager;
				if (networkManager != null && networkManager.IsListening && (((NetworkBehaviour)shotgun).IsHost || ((NetworkBehaviour)shotgun).IsServer))
				{
					ClientRpcParams rpcParams = default(ClientRpcParams);
					FastBufferWriter buffer = Reflection.BeginSendClientRPC((NetworkBehaviour)(object)shotgun, 393u, rpcParams, (RpcDelivery)0);
					((FastBufferWriter)(ref buffer)).WriteValueSafe<int>(ref shotgun.shellsLoaded, default(ForPrimitives));
					((FastBufferWriter)(ref buffer)).WriteValueSafe<bool>(ref shotgun.safetyOn, default(ForPrimitives));
					Reflection.EndSendClientRPC((NetworkBehaviour)(object)shotgun, ref buffer, 393u, rpcParams, (RpcDelivery)0);
				}
			}
		}

		private static void RPCHandlerSynchronizeServer(NetworkBehaviour target, FastBufferReader reader, __RpcParams parameters)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				SynchronizeClientRpc((ShotgunItem)target);
			}
		}

		private static void RPCHandlerSynchronizeClient(NetworkBehaviour target, FastBufferReader reader, __RpcParams parameters)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int shellsLoaded = default(int);
				((FastBufferReader)(ref reader)).ReadValue<int>(ref shellsLoaded, default(ForPrimitives));
				bool safetyOn = default(bool);
				((FastBufferReader)(ref reader)).ReadValue<bool>(ref safetyOn, default(ForPrimitives));
				Synchronize((ShotgunItem)target, shellsLoaded, safetyOn);
			}
		}

		private static void Synchronize(ShotgunItem shotgun, int shellsLoaded, bool safetyOn)
		{
			shotgun.shellsLoaded = shellsLoaded;
			((Renderer)shotgun.shotgunShellLeft).enabled = shellsLoaded >= 1;
			((Renderer)shotgun.shotgunShellRight).enabled = shellsLoaded >= 2;
			shotgun.safetyOn = safetyOn;
			m_ShotgunItem_SetSafetyControlTip.Invoke(shotgun, new object[0]);
		}

		[HarmonyPostfix]
		[HarmonyPatch("InitializeRPCS_ShotgunItem")]
		private static void InitializeRPCS_ShotgunItemPostfix()
		{
			//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_0025: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0098: 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_00a3: Expected O, but got Unknown
			Dictionary<uint, RpcReceiveHandler> _rpc_func_table = NetworkManager.__rpc_func_table;
			object obj = <>O.<0>__RPCHandlerSetSafetyServer;
			if (obj == null)
			{
				RpcReceiveHandler val = RPCHandlerSetSafetyServer;
				<>O.<0>__RPCHandlerSetSafetyServer = val;
				obj = (object)val;
			}
			_rpc_func_table.Add(391u, (RpcReceiveHandler)obj);
			Dictionary<uint, RpcReceiveHandler> _rpc_func_table2 = NetworkManager.__rpc_func_table;
			object obj2 = <>O.<1>__RPCHandlerSetSafetyClient;
			if (obj2 == null)
			{
				RpcReceiveHandler val2 = RPCHandlerSetSafetyClient;
				<>O.<1>__RPCHandlerSetSafetyClient = val2;
				obj2 = (object)val2;
			}
			_rpc_func_table2.Add(392u, (RpcReceiveHandler)obj2);
			Dictionary<uint, RpcReceiveHandler> _rpc_func_table3 = NetworkManager.__rpc_func_table;
			object obj3 = <>O.<2>__RPCHandlerSynchronizeServer;
			if (obj3 == null)
			{
				RpcReceiveHandler val3 = RPCHandlerSynchronizeServer;
				<>O.<2>__RPCHandlerSynchronizeServer = val3;
				obj3 = (object)val3;
			}
			_rpc_func_table3.Add(394u, (RpcReceiveHandler)obj3);
			Dictionary<uint, RpcReceiveHandler> _rpc_func_table4 = NetworkManager.__rpc_func_table;
			object obj4 = <>O.<3>__RPCHandlerSynchronizeClient;
			if (obj4 == null)
			{
				RpcReceiveHandler val4 = RPCHandlerSynchronizeClient;
				<>O.<3>__RPCHandlerSynchronizeClient = val4;
				obj4 = (object)val4;
			}
			_rpc_func_table4.Add(393u, (RpcReceiveHandler)obj4);
		}
	}
	public static class Reflection
	{
		public static readonly MethodInfo m_Debug_Log = typeof(Debug).GetMethod("Log", new Type[1] { typeof(object) });

		public static readonly MethodInfo m_NetworkBehaviour_get_IsOwner = typeof(NetworkBehaviour).GetMethod("get_IsOwner", new Type[0]);

		public static readonly MethodInfo m_NetworkBehaviour_beginSendServerRpc = AccessTools.Method(typeof(NetworkBehaviour), "__beginSendServerRpc", new Type[3]
		{
			typeof(uint),
			typeof(ServerRpcParams),
			typeof(RpcDelivery)
		}, (Type[])null);

		public static readonly MethodInfo m_NetworkBehaviour_endSendServerRpc = AccessTools.Method(typeof(NetworkBehaviour), "__endSendServerRpc", new Type[4]
		{
			typeof(FastBufferWriter).MakeByRefType(),
			typeof(uint),
			typeof(ServerRpcParams),
			typeof(RpcDelivery)
		}, (Type[])null);

		public static readonly MethodInfo m_NetworkBehaviour_beginSendClientRpc = AccessTools.Method(typeof(NetworkBehaviour), "__beginSendClientRpc", new Type[3]
		{
			typeof(uint),
			typeof(ClientRpcParams),
			typeof(RpcDelivery)
		}, (Type[])null);

		public static readonly MethodInfo m_NetworkBehaviour_endSendClientRpc = AccessTools.Method(typeof(NetworkBehaviour), "__endSendClientRpc", new Type[4]
		{
			typeof(FastBufferWriter).MakeByRefType(),
			typeof(uint),
			typeof(ClientRpcParams),
			typeof(RpcDelivery)
		}, (Type[])null);

		public static FastBufferWriter BeginSendServerRPC(NetworkBehaviour behaviour, uint rpcID, ServerRpcParams rpcParams, RpcDelivery delivery)
		{
			//IL_0017: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			return (FastBufferWriter)m_NetworkBehaviour_beginSendServerRpc.Invoke(behaviour, new object[3] { rpcID, rpcParams, delivery });
		}

		public static void EndSendServerRPC(NetworkBehaviour behaviour, ref FastBufferWriter buffer, uint rpcID, ServerRpcParams rpcParams, RpcDelivery delivery)
		{
			//IL_0009: 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_0028: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[4] { buffer, rpcID, rpcParams, delivery };
			m_NetworkBehaviour_endSendServerRpc.Invoke(behaviour, array);
			buffer = (FastBufferWriter)array[0];
		}

		public static FastBufferWriter BeginSendClientRPC(NetworkBehaviour behaviour, uint rpcID, ClientRpcParams rpcParams, RpcDelivery delivery)
		{
			//IL_0017: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			return (FastBufferWriter)m_NetworkBehaviour_beginSendClientRpc.Invoke(behaviour, new object[3] { rpcID, rpcParams, delivery });
		}

		public static void EndSendClientRPC(NetworkBehaviour behaviour, ref FastBufferWriter buffer, uint rpcID, ClientRpcParams rpcParams, RpcDelivery delivery)
		{
			//IL_0009: 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_0028: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[4] { buffer, rpcID, rpcParams, delivery };
			m_NetworkBehaviour_endSendClientRpc.Invoke(behaviour, array);
			buffer = (FastBufferWriter)array[0];
		}
	}
}
namespace EnemyFix.Patches
{
	[HarmonyPatch(typeof(StartOfRound), "EndOfGame")]
	public class RemoveEnemiesPatch
	{
		[HarmonyPrefix]
		public static void Prefix()
		{
			SidiousFix_Collection.Instance.g_Log.LogWarning((object)">>>> Despawning enemies early to fix the unspawned enemies on the map!");
			RoundManager.Instance.UnloadSceneObjectsEarly();
		}
	}
}
namespace FixRPCLag.Patches
{
	[HarmonyPatch(typeof(NetworkManager))]
	internal class NetworkManagerPatches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void Patch(NetworkManager __instance)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			__instance.LogLevel = SidiousFix_Collection.g_LogLevel.Value;
		}
	}
	[HarmonyPatch(typeof(Logs))]
	internal class DissonanceLagFixPatch
	{
		[HarmonyPatch("Awake")]
		private void Awake()
		{
			Logs.SetLogLevel((LogCategory)1, (LogLevel)4);
		}
	}
}
namespace Sidious
{
	[BepInPlugin("Sidious.Fix_Collection", "Fix_Collection", "1.0.0")]
	public class SidiousFix_Collection : BaseUnityPlugin
	{
		private const string Name = "Fix-Collection";

		private const string Version = "1.0.0";

		private readonly Harmony Harmony = new Harmony("Sidious.Fix-Collection");

		public ManualLogSource g_Log = new ManualLogSource("Fix-Collection");

		public static ConfigEntry<LogLevel> g_LogLevel;

		public static SidiousFix_Collection Instance { get; private set; }

		private void Configs()
		{
			g_LogLevel = ((BaseUnityPlugin)this).Config.Bind<LogLevel>("General", "LogLevel", (LogLevel)1, "The network manager's LogLevel. If you want absolutely no debug messages related to networking, set it to \"Nothing\". If you want all debug messages related to networking (not recommended), set it to \"Developer\"");
		}

		private void Awake()
		{
			Instance = this;
			Configs();
			Harmony.PatchAll(typeof(SidiousFix_Collection));
			Harmony.PatchAll(typeof(PatchFlowermanAI));
			Harmony.PatchAll(typeof(PatchCopyVanillaFlowermanCode));
			Harmony.PatchAll(typeof(PatchPufferAI));
			Harmony.PatchAll(typeof(PatchCopyVanillaPufferCode));
			Harmony.PatchAll(typeof(PatchCentipedeAI));
			Harmony.PatchAll(typeof(PatchCopyVanillaCentipedeCode));
			Harmony.PatchAll(typeof(PatchNutcrackerEnemyAI));
			Harmony.PatchAll(typeof(PatchShotgunItem));
			Harmony.PatchAll(typeof(PatchBlobAI));
			Harmony.PatchAll(typeof(PatchSandSpiderAI));
			Harmony.PatchAll(typeof(MaskedPlayerEnemyPatch));
			Harmony.PatchAll(typeof(RemoveEnemiesPatch));
			Harmony.PatchAll(typeof(DissonanceLagFixPatch));
			Harmony.PatchAll(typeof(FixCentipedeLag));
			Harmony.PatchAll(typeof(MissFireFixPatch));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Fix-Collection" + "1.0.0 Successfully Loaded."));
			g_Log = ((BaseUnityPlugin)this).Logger;
		}
	}
}