Decompiled source of AwwyeahEvenMorePlayers v1.0.0

AwwyeahEvenMorePlayers-v1.0.0.dll

Decompiled 3 weeks 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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HarmonyLib.Tools;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TestATT16")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestATT16")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3a98c9dd-4813-4dbb-b6db-5990abac5d6e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TestATT16;

[BepInPlugin("com.michaelrooplall.mods.attmoreplayers", "More Players", "0.9.2")]
public class Class1 : BaseUnityPlugin
{
	[HarmonyPatch(typeof(SteamManager), "Awake")]
	public static class SteamManagerTranspilerPatch
	{
		[HarmonyPrefix]
		public static void Prefix(SteamManager __instance)
		{
			int maxMembers = Instance?.MaxPlayers ?? 16;
			Debug.Log((object)"[MOREPLAYERS] Patching maxMembers on SteamManager");
			__instance.maxMembers = maxMembers;
			if (Object.op_Implicit((Object)(object)SteamManager.Instance))
			{
				SteamManager.Instance.maxMembers = maxMembers;
			}
		}
	}

	public static class GenNewGameName_Patch
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private bool <found>5__1;

			private IEnumerator<CodeInstruction> <>s__2;

			private CodeInstruction <instruction>5__3;

			private string <s>5__4;

			CodeInstruction IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 1u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>s__2 = null;
				<instruction>5__3 = null;
				<s>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0100: Unknown result type (might be due to invalid IL or missing references)
				//IL_010a: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<found>5__1 = false;
						Debug.Log((object)"\n\nPatching MainMenu GenNewGameName method");
						<>s__2 = instructions.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						Debug.Log((object)("Changed OpCode String variable with value \"" + <s>5__4 + "\""));
						break;
					case 2:
						<>1__state = -3;
						<s>5__4 = null;
						<instruction>5__3 = null;
						break;
					}
					if (<>s__2.MoveNext())
					{
						<instruction>5__3 = <>s__2.Current;
						if (<instruction>5__3.opcode == OpCodes.Ldstr)
						{
							object operand = <instruction>5__3.operand;
							<s>5__4 = operand as string;
							if (<s>5__4 != null)
							{
								Debug.Log((object)("Found OpCode String variable with value \"" + <s>5__4 + "\""));
								if (<s>5__4 == "Tavern")
								{
									<found>5__1 = true;
									<>2__current = new CodeInstruction(OpCodes.Ldstr, (object)"BiggerTavern");
									<>1__state = 1;
									return true;
								}
							}
						}
						<>2__current = <instruction>5__3;
						<>1__state = 2;
						return true;
					}
					<>m__Finally1();
					<>s__2 = null;
					if (!<found>5__1)
					{
						Debug.Log((object)"Failed to set OpCode String to BiggerTavern");
					}
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>s__2 != null)
				{
					<>s__2.Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__0 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__0(0);
				}
				<Transpiler>d__.instructions = <>3__instructions;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		[IteratorStateMachine(typeof(<Transpiler>d__0))]
		[HarmonyDebug]
		[HarmonyPatch(typeof(MainMenu), "GenNewGameName")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Transpiler>d__0(-2)
			{
				<>3__instructions = instructions
			};
		}
	}

	public class PatchContainerManager_Awake
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__1 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private int <maxPlayers>5__1;

			private bool <changed>5__2;

			private IEnumerator<CodeInstruction> <>s__3;

			private CodeInstruction <instruction>5__4;

			CodeInstruction IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 2u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>s__3 = null;
				<instruction>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0137: Unknown result type (might be due to invalid IL or missing references)
				//IL_0141: Expected O, but got Unknown
				//IL_0102: Unknown result type (might be due to invalid IL or missing references)
				//IL_010c: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<maxPlayers>5__1 = Instance?.MaxPlayers ?? 16;
						<changed>5__2 = false;
						Debug.Log((object)"\n\n[MORE PLAYERS] Patching ContainerManager Awake method");
						<>s__3 = instructions.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						goto IL_0158;
					case 2:
						<>1__state = -3;
						goto IL_0158;
					case 3:
						{
							<>1__state = -3;
							goto IL_0183;
						}
						IL_0158:
						<changed>5__2 = true;
						goto IL_0183;
						IL_0183:
						<instruction>5__4 = null;
						break;
					}
					if (<>s__3.MoveNext())
					{
						<instruction>5__4 = <>s__3.Current;
						if (<instruction>5__4.opcode == OpCodes.Ldc_I4_4 || <instruction>5__4.opcode == OpCodes.Ldc_I4_5)
						{
							if (<maxPlayers>5__1 >= -128 && <maxPlayers>5__1 <= 127)
							{
								<>2__current = new CodeInstruction(OpCodes.Ldc_I4_S, (object)(sbyte)<maxPlayers>5__1);
								<>1__state = 1;
								return true;
							}
							<>2__current = new CodeInstruction(OpCodes.Ldc_I4, (object)<maxPlayers>5__1);
							<>1__state = 2;
							return true;
						}
						<>2__current = <instruction>5__4;
						<>1__state = 3;
						return true;
					}
					<>m__Finally1();
					<>s__3 = null;
					if (<changed>5__2)
					{
						Debug.Log((object)"[MORE PLAYERS] Patched ContainerManager");
					}
					else
					{
						Debug.Log((object)"[MORE PLAYERS] Failed to patch ContainerManager");
					}
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>s__3 != null)
				{
					<>s__3.Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__1 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__1(0);
				}
				<Transpiler>d__.instructions = <>3__instructions;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		[HarmonyDebug]
		[HarmonyPatch(typeof(ContainerManager), "Awake")]
		[HarmonyPrefix]
		private static void Prefix(ContainerManager __instance)
		{
			Debug.Log((object)("[MORE PLAYERS] ContainerManager Instance " + ((Object)(object)ContainerManager.Instance != (Object)null)));
			if (!((Object)(object)ContainerManager.Instance != (Object)null))
			{
				expandPlayerContainers(__instance);
			}
		}

		[IteratorStateMachine(typeof(<Transpiler>d__1))]
		[HarmonyDebug]
		[HarmonyPatch(typeof(ContainerManager), "Awake")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Transpiler>d__1(-2)
			{
				<>3__instructions = instructions
			};
		}

		private static void expandPlayerContainers(ContainerManager __instance)
		{
			int num = Instance?.MaxPlayers ?? 16;
			Debug.Log((object)"\n\n[MORE PLAYERS] [Adding More Player Containers]");
			GameObject val = GameObject.Find("Common/Game/PlayerContainers/ContainerP0");
			GameObject val2 = GameObject.Find("Common/Game/PlayerContainers");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Debug.LogError((object)"[MORE PLAYERS] Could not find player container prefab or parent");
				return;
			}
			ContainerNet[] playerContainers = __instance.playerContainers;
			Debug.Log((object)$"[MORE PLAYERS] (Before adding more player containers) Found number of slots: {((playerContainers != null) ? playerContainers.Length : 0)} in playerContainers");
			Array.Resize(ref __instance.playerContainers, num);
			for (int i = 4; i < num; i++)
			{
				Debug.Log((object)$"[MORE PLAYERS] Creating Networked Container ContainerP{i}");
				GameObject val3 = Object.Instantiate<GameObject>(val);
				((Object)val3).name = $"ContainerP{i}";
				ContainerNet val4 = val3.GetComponent<ContainerNet>() ?? val3.AddComponent<ContainerNet>();
				val4.id.Value = (ushort)(i + 1);
				val3.transform.SetParent(val.transform.parent, false);
				__instance.playerContainers[i] = val4;
				Debug.Log((object)$"[MORE PLAYERS] Pushed Networked ContainerP{i} to ContainerManager and playerContainers");
			}
			Debug.Log((object)$"[MORE PLAYERS] Found number of slots: {__instance.playerContainers.Length} in playerContainers");
			buildBackpacks();
		}

		private static void buildBackpacks()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)"\n\n[MORE PLAYERS] [Adding More Backpacks]");
			modifyBackpackBaseboard();
			int num = Instance?.MaxPlayers ?? 16;
			GameObject val = GameObject.Find("Tavern/Interactive/Backpacks/3");
			GameObject val2 = GameObject.Find("Tavern/Interactive/Backpacks/2");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Logger.LogWarning((object)"[MORE PLAYERS] original backpack references missing");
				return;
			}
			float num2 = val.transform.position.z - val2.transform.position.z;
			for (int i = 4; i < num; i++)
			{
				GameObject val3 = Object.Instantiate<GameObject>(val);
				((Object)val3).name = i.ToString();
				val3.transform.SetParent(val.transform.parent, false);
				val3.transform.position = val.transform.position + new Vector3(0f, 0f, (float)(i - 3) * num2);
				val3.transform.rotation = val.transform.rotation;
				PlayerContainerRef component = val3.GetComponent<PlayerContainerRef>();
				if ((Object)(object)component != (Object)null)
				{
					FieldInfo field = typeof(PlayerContainerRef).GetField("playerIndex", BindingFlags.Instance | BindingFlags.NonPublic);
					if (field != null)
					{
						field.SetValue(component, (byte)i);
					}
					else
					{
						Logger.LogWarning((object)"[MORE PLAYERS] Unable to find playerIndex field via reflection.");
					}
					Interactive component2 = val3.GetComponent<Interactive>();
					if ((Object)(object)component2 != (Object)null)
					{
						component2.ObjectTitle = $"Player {i + 1} Inventory";
						((Object)component2).name = i.ToString();
					}
					else
					{
						Logger.LogWarning((object)"[MORE PLAYERS] Unable to find Interactive Component.");
					}
				}
				else
				{
					Logger.LogWarning((object)"[MORE PLAYERS] Unable to find PlayerContainerRef Component.");
				}
				Logger.LogInfo((object)$"[MORE PLAYERS] Created wall backpack for {i + 1}.");
			}
		}

		private static void modifyBackpackBaseboard()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			int num = Instance?.MaxPlayers ?? 16;
			Debug.Log((object)"\n\n[MORE PLAYERS] [Modifying Backpack Baseboard]");
			GameObject val = GameObject.Find("Tavern/Interactive/Backpacks");
			GameObject val2 = GameObject.Find("Tavern/Interactive/Backpacks/Modular_Door_A");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogWarning((object)"[MORE PLAYERS] Backpacks parent not found");
				return;
			}
			val.transform.position = new Vector3(val.transform.position.x, val.transform.position.y, 46.6f);
			if ((Object)(object)val2 != (Object)null)
			{
				val2.transform.position = new Vector3(-22.05f, 4.65f, 46.9f + 0.38f * (float)(num - 4));
				val2.transform.localScale = new Vector3(1f, 1f + 0.3f * (float)(num - 4), 1f);
				Logger.LogInfo((object)"[MORE PLAYERS] Backpack backboard position and scale modified!");
			}
			else
			{
				Logger.LogWarning((object)"[MORE PLAYERS] Backpack backboard not found!");
			}
		}
	}

	public class PatchPlayerManager_Awake
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private int <maxPlayers>5__1;

			private bool <changed>5__2;

			private IEnumerator<CodeInstruction> <>s__3;

			private CodeInstruction <instruction>5__4;

			CodeInstruction IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 2u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>s__3 = null;
				<instruction>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Expected O, but got Unknown
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<maxPlayers>5__1 = Instance?.MaxPlayers ?? 16;
						<changed>5__2 = false;
						Debug.Log((object)"\n\nPatching PlayerManager Awake method to edit lastPlayerPlatformIdByPlayerIndex");
						<>s__3 = instructions.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						goto IL_013a;
					case 2:
						<>1__state = -3;
						goto IL_013a;
					case 3:
						{
							<>1__state = -3;
							goto IL_0165;
						}
						IL_013a:
						<changed>5__2 = true;
						goto IL_0165;
						IL_0165:
						<instruction>5__4 = null;
						break;
					}
					if (<>s__3.MoveNext())
					{
						<instruction>5__4 = <>s__3.Current;
						if (<instruction>5__4.opcode == OpCodes.Ldc_I4_4)
						{
							if (<maxPlayers>5__1 >= -128 && <maxPlayers>5__1 <= 127)
							{
								<>2__current = new CodeInstruction(OpCodes.Ldc_I4_S, (object)(sbyte)<maxPlayers>5__1);
								<>1__state = 1;
								return true;
							}
							<>2__current = new CodeInstruction(OpCodes.Ldc_I4, (object)<maxPlayers>5__1);
							<>1__state = 2;
							return true;
						}
						<>2__current = <instruction>5__4;
						<>1__state = 3;
						return true;
					}
					<>m__Finally1();
					<>s__3 = null;
					if (<changed>5__2)
					{
						Debug.Log((object)"Patched lastPlayerPlatformIdByPlayerIndex");
					}
					else
					{
						Debug.Log((object)"Failed to patch lastPlayerPlatformIdByPlayerIndex");
					}
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>s__3 != null)
				{
					<>s__3.Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__0 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__0(0);
				}
				<Transpiler>d__.instructions = <>3__instructions;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		[IteratorStateMachine(typeof(<Transpiler>d__0))]
		[HarmonyDebug]
		[HarmonyPatch(typeof(PlayerManager), "Awake")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Transpiler>d__0(-2)
			{
				<>3__instructions = instructions
			};
		}
	}

	[HarmonyPatch(typeof(PlayerManager), "GetFreePlayerIndex")]
	public static class PatchPlayerManager_GetFreePlayerIndex
	{
		[HarmonyPrefix]
		private static bool Prefix(PlayerManager __instance, ref byte __result, ulong playerId = 0uL)
		{
			Debug.Log((object)"\n\n[MORE PLAYERS] Patching PlayerManager GetFreePlayerIndex method");
			int count = Instance?.MaxPlayers ?? 16;
			List<byte> list = (from i in Enumerable.Range(0, count)
				select (byte)i).ToList();
			foreach (KeyValuePair<ulong, byte> item in PlayerManager.Instance.playerIndex)
			{
				list.Remove(item.Value);
			}
			if (playerId != 0)
			{
				for (byte b = 0; b < PlayerManager.Instance.lastPlayerPlatformIdByPlayerIndex.Length; b++)
				{
					if (PlayerManager.Instance.lastPlayerPlatformIdByPlayerIndex[b] == playerId && list.Contains(b))
					{
						__result = b;
						return false;
					}
				}
			}
			if (list.Count == 0)
			{
				__result = byte.MaxValue;
				return false;
			}
			__result = list[0];
			return false;
		}
	}

	public class PatchSpawnManager_Awake
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private int <maxPlayers>5__1;

			private bool <changed>5__2;

			private IEnumerator<CodeInstruction> <>s__3;

			private CodeInstruction <instruction>5__4;

			CodeInstruction IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 2u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>s__3 = null;
				<instruction>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Expected O, but got Unknown
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<maxPlayers>5__1 = Instance?.MaxPlayers ?? 16;
						<changed>5__2 = false;
						Debug.Log((object)"\n\n[MORE PLAYERS] Patching SpawnManager Awake method to edit _playerCheckPoint");
						<>s__3 = instructions.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						goto IL_013a;
					case 2:
						<>1__state = -3;
						goto IL_013a;
					case 3:
						{
							<>1__state = -3;
							goto IL_0165;
						}
						IL_013a:
						<changed>5__2 = true;
						goto IL_0165;
						IL_0165:
						<instruction>5__4 = null;
						break;
					}
					if (<>s__3.MoveNext())
					{
						<instruction>5__4 = <>s__3.Current;
						if (<instruction>5__4.opcode == OpCodes.Ldc_I4_4)
						{
							if (<maxPlayers>5__1 >= -128 && <maxPlayers>5__1 <= 127)
							{
								<>2__current = new CodeInstruction(OpCodes.Ldc_I4_S, (object)(sbyte)<maxPlayers>5__1);
								<>1__state = 1;
								return true;
							}
							<>2__current = new CodeInstruction(OpCodes.Ldc_I4, (object)<maxPlayers>5__1);
							<>1__state = 2;
							return true;
						}
						<>2__current = <instruction>5__4;
						<>1__state = 3;
						return true;
					}
					<>m__Finally1();
					<>s__3 = null;
					if (<changed>5__2)
					{
						Debug.Log((object)"[MORE PLAYERS] Patched SpawnManager _playerCheckPoint");
					}
					else
					{
						Debug.Log((object)"[MORE PLAYERS] Failed to patch SpawnManager _playerCheckPoint");
					}
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>s__3 != null)
				{
					<>s__3.Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__0 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__0(0);
				}
				<Transpiler>d__.instructions = <>3__instructions;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		[IteratorStateMachine(typeof(<Transpiler>d__0))]
		[HarmonyDebug]
		[HarmonyPatch(typeof(SpawnManager), "Awake")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Transpiler>d__0(-2)
			{
				<>3__instructions = instructions
			};
		}
	}

	public class PatchPlayerList_Refresh
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private int <maxPlayers>5__1;

			private bool <changed>5__2;

			private IEnumerator<CodeInstruction> <>s__3;

			private CodeInstruction <instruction>5__4;

			CodeInstruction IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 2u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>s__3 = null;
				<instruction>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0124: Expected O, but got Unknown
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<maxPlayers>5__1 = Instance?.MaxPlayers ?? 16;
						<changed>5__2 = false;
						Debug.Log((object)"\n\n[MORE PLAYERS] Patching PlayerList Refresh method");
						<>s__3 = instructions.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						goto IL_013a;
					case 2:
						<>1__state = -3;
						goto IL_013a;
					case 3:
						{
							<>1__state = -3;
							goto IL_0165;
						}
						IL_013a:
						<changed>5__2 = true;
						goto IL_0165;
						IL_0165:
						<instruction>5__4 = null;
						break;
					}
					if (<>s__3.MoveNext())
					{
						<instruction>5__4 = <>s__3.Current;
						if (<instruction>5__4.opcode == OpCodes.Ldc_I4_4)
						{
							if (<maxPlayers>5__1 >= -128 && <maxPlayers>5__1 <= 127)
							{
								<>2__current = new CodeInstruction(OpCodes.Ldc_I4_S, (object)(sbyte)<maxPlayers>5__1);
								<>1__state = 1;
								return true;
							}
							<>2__current = new CodeInstruction(OpCodes.Ldc_I4, (object)<maxPlayers>5__1);
							<>1__state = 2;
							return true;
						}
						<>2__current = <instruction>5__4;
						<>1__state = 3;
						return true;
					}
					<>m__Finally1();
					<>s__3 = null;
					if (<changed>5__2)
					{
						Debug.Log((object)"[MORE PLAYERS] Patched PlayerList[Refresh]");
					}
					else
					{
						Debug.Log((object)"[MORE PLAYERS] Failed to patch PlayerList[Refresh]");
					}
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>s__3 != null)
				{
					<>s__3.Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__0 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__0(0);
				}
				<Transpiler>d__.instructions = <>3__instructions;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		[IteratorStateMachine(typeof(<Transpiler>d__0))]
		[HarmonyDebug]
		[HarmonyPatch(typeof(PlayerList), "Refresh")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Transpiler>d__0(-2)
			{
				<>3__instructions = instructions
			};
		}
	}

	[HarmonyPatch(typeof(RecipeManager), "Awake")]
	public static class RecipeManagerTranspilerPatch
	{
		[HarmonyPrefix]
		public static void Prefix(RecipeManager __instance)
		{
			Debug.Log((object)"[MORE PLAYERS] Patching RecipeManager playerCountK EXP Multiplier");
			FieldInfo field = ((object)__instance).GetType().GetField("playerCountK", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				int num = Instance?.MaxPlayers ?? 16;
				float[] array = Enumerable.Repeat(1f, num).ToArray();
				if (num >= 1)
				{
					array[0] = 2f;
				}
				if (num >= 2)
				{
					array[1] = 1.5f;
				}
				if (num >= 3)
				{
					array[2] = 1.25f;
				}
				if (num >= 4)
				{
					array[3] = 1f;
				}
				field.SetValue(__instance, array);
			}
			else
			{
				Debug.LogError((object)"[MORE PLAYERS] playerCountK field not found!");
			}
		}
	}

	[HarmonyPatch(typeof(CaveSpawnManager), "SpawnCreatures")]
	public static class CaveSpawnManager_SpawnCreatures_Patch
	{
		[HarmonyPrefix]
		private static bool Prefix(CaveSpawnManager __instance, ref int creaturesCount)
		{
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)"\n\n[MORE PLAYERS] Patching (Overwriting) CaveSpawnManager SpawnCreatures method");
			int num = 2 * Random.Range(PlayerManager.Instance.players.Count, PlayerManager.Instance.players.Count * 3 + 1);
			creaturesCount = ((creaturesCount == -1) ? num : creaturesCount);
			FieldInfo field = ((object)CaveSpawnManager.Instance).GetType().GetField("creaturesSpawnPoints", BindingFlags.Instance | BindingFlags.NonPublic);
			List<Transform> source = (List<Transform>)field.GetValue(__instance);
			FieldInfo field2 = ((object)CaveSpawnManager.Instance).GetType().GetField("creatureTypes", BindingFlags.Instance | BindingFlags.NonPublic);
			List<Type> list = (List<Type>)field2.GetValue(__instance);
			FieldInfo field3 = ((object)CaveSpawnManager.Instance).GetType().GetField("spawnedCreatures", BindingFlags.Instance | BindingFlags.NonPublic);
			List<Vulnerable> list2 = (List<Vulnerable>)field3.GetValue(__instance);
			MethodInfo method = ((object)__instance).GetType().GetMethod("OnCreatureDeath", BindingFlags.Instance | BindingFlags.NonPublic);
			List<Transform> list3 = source.OrderBy((Transform n) => Guid.NewGuid()).ToList();
			creaturesCount = Math.Min(creaturesCount, list3.Count - 1);
			Spawnable val2 = default(Spawnable);
			Vulnerable val3 = default(Vulnerable);
			for (int i = 0; i < creaturesCount; i++)
			{
				Type val = list[Random.Range(0, list.Count)];
				SpawnManager.Instance.ManualSpawn(val, list3[i].position, Quaternion.identity, ref val2, true);
				if (((Component)val2).TryGetComponent<Vulnerable>(ref val3))
				{
					list2.Add(val3);
					Vulnerable val4 = val3;
					Action<Vulnerable> b = (Action<Vulnerable>)Delegate.CreateDelegate(typeof(Action<Vulnerable>), __instance, method);
					val4.onDeath = (Action<Vulnerable>)Delegate.Combine(val4.onDeath, b);
				}
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(CaveSpawnManager), "SpawnLoot")]
	public static class CaveSpawnManager_SpawnLoot_Patch
	{
		[HarmonyPrefix]
		private static bool Prefix(CaveSpawnManager __instance, ref int lootItemsCount)
		{
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)"\n\n[MORE PLAYERS] Patching (Overwriting) CaveSpawnManager SpawnLoot method");
			FieldInfo field = ((object)CaveSpawnManager.Instance).GetType().GetField("minLootObjectsPerPlayer", BindingFlags.Instance | BindingFlags.NonPublic);
			int num = (int)field.GetValue(CaveSpawnManager.Instance);
			FieldInfo field2 = ((object)CaveSpawnManager.Instance).GetType().GetField("maxLootObjectsPerPlayer", BindingFlags.Instance | BindingFlags.NonPublic);
			int num2 = (int)field2.GetValue(CaveSpawnManager.Instance);
			FieldInfo field3 = ((object)CaveSpawnManager.Instance).GetType().GetField("lootSpawnPositions", BindingFlags.Instance | BindingFlags.NonPublic);
			List<Transform> source = (List<Transform>)field3.GetValue(CaveSpawnManager.Instance);
			FieldInfo field4 = ((object)CaveSpawnManager.Instance).GetType().GetField("spawnedLoot", BindingFlags.Instance | BindingFlags.NonPublic);
			List<Vulnerable> list = (List<Vulnerable>)field4.GetValue(__instance);
			MethodInfo method = ((object)__instance).GetType().GetMethod("OnLootDestroy", BindingFlags.Instance | BindingFlags.NonPublic);
			int num3 = 2 * Random.Range(PlayerManager.Instance.players.Count * num, PlayerManager.Instance.players.Count * num2 + 1);
			List<Transform> list2 = source.OrderBy((Transform n) => Guid.NewGuid()).ToList();
			lootItemsCount = Math.Min((lootItemsCount == -1) ? num3 : lootItemsCount, Math.Max(0, list2.Count - 1));
			Spawnable val2 = default(Spawnable);
			Vulnerable val3 = default(Vulnerable);
			for (int i = 0; i < lootItemsCount; i++)
			{
				Vector3 position = list2[i].position;
				Quaternion rotation = list2[i].rotation;
				Type val = (Type)(((double)Random.value > 0.5) ? 51 : 50);
				if (SpawnManager.Instance.ManualSpawn(val, position, rotation, ref val2, true) && ((Component)val2).TryGetComponent<Vulnerable>(ref val3))
				{
					list.Add(val3);
					Vulnerable val4 = val3;
					Action<Vulnerable> b = (Action<Vulnerable>)Delegate.CreateDelegate(typeof(Action<Vulnerable>), __instance, method);
					val4.onDeath = (Action<Vulnerable>)Delegate.Combine(val4.onDeath, b);
				}
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(CaveSpawnManager), "SpawnChests")]
	public static class CaveSpawnManager_SpawnChests_Patch
	{
		[HarmonyPrefix]
		private static bool Prefix(CaveSpawnManager __instance)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)"\n\n[MORE PLAYERS] Patching (Overwriting) CaveSpawnManager SpawnChests method");
			FieldInfo field = ((object)CaveSpawnManager.Instance).GetType().GetField("minChestsPerPlayer", BindingFlags.Instance | BindingFlags.NonPublic);
			int num = (int)field.GetValue(CaveSpawnManager.Instance);
			FieldInfo field2 = ((object)CaveSpawnManager.Instance).GetType().GetField("maxChestsPerPlayer", BindingFlags.Instance | BindingFlags.NonPublic);
			int num2 = (int)field2.GetValue(CaveSpawnManager.Instance);
			FieldInfo field3 = ((object)CaveSpawnManager.Instance).GetType().GetField("chestSpawnPositions", BindingFlags.Instance | BindingFlags.NonPublic);
			List<Transform> source = (List<Transform>)field3.GetValue(CaveSpawnManager.Instance);
			FieldInfo field4 = ((object)CaveSpawnManager.Instance).GetType().GetField("chestPrefab", BindingFlags.Instance | BindingFlags.NonPublic);
			NetworkObject val = (NetworkObject)field4.GetValue(CaveSpawnManager.Instance);
			FieldInfo field5 = ((object)CaveSpawnManager.Instance).GetType().GetField("spawnedChests", BindingFlags.Instance | BindingFlags.NonPublic);
			List<NetworkObject> list = (List<NetworkObject>)field5.GetValue(CaveSpawnManager.Instance);
			MethodInfo method = ((object)__instance).GetType().GetMethod("FillChestWithLoot", BindingFlags.Instance | BindingFlags.NonPublic);
			int val2 = Random.Range(PlayerManager.Instance.players.Count * num, PlayerManager.Instance.players.Count * num2 + 1);
			List<Transform> list2 = source.OrderBy((Transform n) => Guid.NewGuid()).ToList();
			val2 = Math.Min(val2, Math.Max(0, list2.Count - 1));
			ContainerNet val5 = default(ContainerNet);
			for (int i = 0; i < val2; i++)
			{
				Vector3 position = list2[i].position;
				Quaternion rotation = list2[i].rotation;
				NetworkObject val3 = Object.Instantiate<NetworkObject>(val, position, rotation);
				list.Add(val3);
				NetworkObject val4 = val3;
				if (Master.Instance.HasConnectingClients() && AppSettingsManager.Instance.appSettings.system.useSpawnQueue)
				{
					Game.Instance.SpawnEnqueue(val4);
				}
				else
				{
					val4.Spawn(false);
				}
				if (((Component)val3).TryGetComponent<ContainerNet>(ref val5))
				{
					method.Invoke(__instance, new object[1] { val5 });
				}
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(DefenceQuestController), "Awake")]
	public static class DefenceQuestControllerTranspilerPatch
	{
		[HarmonyPrefix]
		public static void Prefix(DefenceQuestController __instance)
		{
			Debug.Log((object)"[MORE PLAYERS] Patching DefenceQuestController delayPerEnemyByPlayers List");
			FieldInfo field = ((object)__instance).GetType().GetField("delayPerEnemyByPlayers", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				int num = Instance?.MaxPlayers ?? 16;
				List<int> list = Enumerable.Repeat(3, num).ToList();
				if (num > 0)
				{
					list[0] = 7;
				}
				if (num > 1)
				{
					list[1] = 5;
				}
				if (num > 2)
				{
					list[2] = 4;
				}
				field.SetValue(__instance, list);
				Debug.Log((object)"[MORE PLAYERS] Successfully added values to delayField for more players");
			}
			else
			{
				Debug.LogWarning((object)"[MORE PLAYERS] delayPerEnemyByPlayers field not found");
			}
		}
	}

	[HarmonyPatch(typeof(HerbalistQuestController), "Awake")]
	public static class HerbalistQuestControllerPatch
	{
		[HarmonyPrefix]
		public static void Prefix(HerbalistQuestController __instance)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00b8: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)"[MORE PLAYERS] Adding more HerbalistQuestController Bear Spawns");
			FieldInfo field = ((object)__instance).GetType().GetField("_bearSpawnPoint", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field != null)
			{
				Transform[] array = (Transform[])field.GetValue(__instance);
				if (array != null && array.Length >= 2)
				{
					int num = Instance?.MaxPlayers ?? 16;
					Transform[] array2 = (Transform[])(object)new Transform[num];
					for (int i = 0; i < num; i++)
					{
						Transform val = array[i % array.Length];
						GameObject val2 = new GameObject($"BearSpawn_{i}");
						val2.transform.SetParent(val.parent, false);
						val2.transform.position = val.position + new Vector3(0f, 0f, (float)(i / array.Length) * 1.2f);
						val2.transform.rotation = val.rotation;
						array2[i] = val2.transform;
					}
					field.SetValue(__instance, array2);
					Debug.Log((object)"[MORE PLAYERS] Re-using bearSpawnPoints for more players");
				}
				else
				{
					Debug.LogWarning((object)"[MORE PLAYERS] Not enough original bear spawn points to expand from");
				}
			}
			else
			{
				Debug.LogError((object)"[MORE PLAYERS] _bearSpawnPoint field not found!");
			}
		}
	}

	private ConfigEntry<int> cfgMaxPlayers;

	internal static ManualLogSource Logger;

	public static Class1 Instance { get; private set; }

	public int MaxPlayers => Utils.Clamp(cfgMaxPlayers.Value, 4, 64);

	private void Awake()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		Instance = this;
		cfgMaxPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "MaxPlayers", 16, new ConfigDescription("<int> Max Players (minimum: 4)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(4, 64), Array.Empty<object>()));
		Logger = ((BaseUnityPlugin)this).Logger;
		HarmonyFileLog.Enabled = true;
		Logger.LogInfo((object)"[MORE PLAYERS] Plugin loaded - v0.9.2-alpha");
		Harmony val = new Harmony("com.michaelrooplall.mods.attmoreplayers.patch");
		Debug.Log((object)"\n\n==========================\n[MORE PLAYERS][PATCHES][HARMONY]\n==========================\n");
		val.PatchAll(typeof(SteamManagerTranspilerPatch));
		val.PatchAll(typeof(GenNewGameName_Patch));
		val.PatchAll(typeof(PatchContainerManager_Awake));
		val.PatchAll(typeof(PatchPlayerManager_Awake));
		val.PatchAll(typeof(PatchPlayerManager_GetFreePlayerIndex));
		val.PatchAll(typeof(PatchSpawnManager_Awake));
		val.PatchAll(typeof(PatchPlayerList_Refresh));
		val.PatchAll(typeof(RecipeManagerTranspilerPatch));
		val.PatchAll(typeof(CaveSpawnManager_SpawnCreatures_Patch));
		val.PatchAll(typeof(CaveSpawnManager_SpawnLoot_Patch));
		val.PatchAll(typeof(CaveSpawnManager_SpawnChests_Patch));
		val.PatchAll(typeof(DefenceQuestControllerTranspilerPatch));
		val.PatchAll(typeof(HerbalistQuestControllerPatch));
		Debug.Log((object)"\n==========================\n\n");
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnDestroy()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		if (((Scene)(ref scene)).name == "Playtest")
		{
			Debug.Log((object)"\n\n[MORE PLAYERS] SCENE CHANGE DETECTED");
			((MonoBehaviour)this).Invoke("build", 2f);
		}
	}

	private void build()
	{
		Debug.Log((object)"\n\n==========================\n[MORE PLAYERS][PATCHES][UNITY]\n==========================\n");
		DebugLog.Instance.logAll = true;
		try
		{
			createMorePlayerSpawns();
		}
		catch (Exception ex)
		{
			Logger.LogError((object)ex);
		}
		Debug.Log((object)"\n==========================\n\n");
	}

	private void createMorePlayerSpawns()
	{
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Expected O, but got Unknown
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)"\n\n[MORE PLAYERS] [Adding Spawn Points for Extra Players]");
		GameObject val = GameObject.Find("Common/Game");
		if ((Object)(object)val == (Object)null)
		{
			Debug.Log((object)"[MORE PLAYERS] Failed to find Common/Game GameObject");
			return;
		}
		PlayerManager component = val.GetComponent<PlayerManager>();
		if ((Object)(object)component == (Object)null)
		{
			Debug.LogError((object)"[MORE PLAYERS] PlayerManager component not found on Common/Game");
			return;
		}
		int maxPlayers = MaxPlayers;
		Transform[] playerSpawnPos = component.playerSpawnPos;
		if (playerSpawnPos == null || playerSpawnPos.Length == 0)
		{
			Debug.LogError((object)"[MORE PLAYERS] playerSpawnPos is empty");
			return;
		}
		Transform[] array = (Transform[])(object)new Transform[maxPlayers];
		for (int i = 0; i < Math.Min(playerSpawnPos.Length, array.Length); i++)
		{
			array[i] = playerSpawnPos[i];
		}
		for (int j = playerSpawnPos.Length; j < maxPlayers; j++)
		{
			Transform val2 = playerSpawnPos[j % playerSpawnPos.Length];
			GameObject val3 = new GameObject($"Spawn_{j}");
			val3.transform.SetParent(val2.parent, false);
			val3.transform.position = val2.position + new Vector3(0f, 0f, (float)(j / playerSpawnPos.Length) * 1.5f);
			val3.transform.rotation = val2.rotation;
			array[j] = val3.transform;
		}
		component.playerSpawnPos = array;
		Debug.Log((object)"[MORE PLAYERS] Added more spawnpoints");
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "ATTMorePlayers";

	public const string PLUGIN_NAME = "Ale and Tavern Tale - 8 Players Mod";

	public const string PLUGIN_VERSION = "0.9.2-alpha";
}
public static class Utils
{
	public static int Clamp(int value, int min, int max)
	{
		if (value < min)
		{
			return min;
		}
		if (value > max)
		{
			return max;
		}
		return value;
	}
}