using System;
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 HarmonyLib;
using HarmonyLib.Tools;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ATTMorePlayers")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+744fea5d945f02a5947279a3fcd843fd7aa213d8")]
[assembly: AssemblyProduct("Ale and Tavern Tale - 8 Players Mod")]
[assembly: AssemblyTitle("ATTMorePlayers")]
[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;
}
}
}
namespace ATTMorePlayers
{
[BepInPlugin("com.michaelrooplall.mods.attmoreplayers", "More Players", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(SteamManager), "Awake")]
public static class SteamManagerTranspilerPatch
{
private static int maxPlayers = 8;
[HarmonyPrefix]
public static void Prefix(SteamManager __instance)
{
Debug.Log((object)"[MOREPLAYERS] Patching maxMembers on SteamManager");
__instance.maxMembers = maxPlayers;
if (Object.op_Implicit((Object)(object)SteamManager.Instance))
{
SteamManager.Instance.maxMembers = maxPlayers;
}
}
}
public static class GenNewGameName_Patch
{
[HarmonyDebug]
[HarmonyPatch(typeof(MainMenu), "GenNewGameName")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
bool found = false;
Debug.Log((object)"\n\nPatching MainMenu GenNewGameName method");
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode.Equals(OpCodes.Ldstr))
{
Debug.Log((object)("Found OpCode String variable with value \"" + instruction.operand.ToString() + "\""));
}
if (instruction.opcode.Equals(OpCodes.Ldstr) && instruction.operand.ToString() == "Tavern")
{
found = true;
yield return new CodeInstruction(OpCodes.Ldstr, (object)"BiggerTavern");
Debug.Log((object)("Changed OpCode String variable with value \"" + instruction.operand.ToString() + "\""));
}
else
{
yield return instruction;
}
}
if (!found)
{
Debug.Log((object)"Failed to set OpCode String to BiggerTavern");
}
}
}
public class PatchPlayerManager_Awake
{
[HarmonyDebug]
[HarmonyPatch(typeof(PlayerManager), "Awake")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
int maxPlayers = 8;
bool changed = false;
Debug.Log((object)"\n\nPatching PlayerManager Awake method to edit lastPlayerPlatformIdByPlayerIndex");
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode.Equals(OpCodes.Ldc_I4_4))
{
if (maxPlayers >= 0 && maxPlayers <= 8)
{
yield return new CodeInstruction(OpCodes.Ldc_I4, (object)maxPlayers);
}
else if (maxPlayers >= -128 && maxPlayers <= 127)
{
yield return new CodeInstruction(OpCodes.Ldc_I4_S, (object)(sbyte)maxPlayers);
}
else
{
yield return new CodeInstruction(OpCodes.Ldc_I4, (object)maxPlayers);
}
changed = true;
}
else
{
yield return instruction;
}
}
if (changed)
{
Debug.Log((object)"Patched lastPlayerPlatformIdByPlayerIndex");
}
else
{
Debug.Log((object)"Failed to patch lastPlayerPlatformIdByPlayerIndex");
}
}
}
[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");
List<byte> list = new List<byte> { 0, 1, 2, 3, 4, 5, 6, 7 };
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;
}
}
}
__result = list[0];
return false;
}
}
public class PatchContainerManager_Awake
{
[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);
}
}
[HarmonyDebug]
[HarmonyPatch(typeof(ContainerManager), "Awake")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
int maxPlayers = 8;
bool changed = false;
Debug.Log((object)"\n\n[MORE PLAYERS] Patching ContainerManager Awake method");
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode.Equals(OpCodes.Ldc_I4_5))
{
yield return new CodeInstruction(OpCodes.Ldc_I4_S, (object)(sbyte)(1 + maxPlayers));
changed = true;
}
else
{
yield return instruction;
}
}
if (changed)
{
Debug.Log((object)"[MORE PLAYERS] Patched ContainerManager");
}
else
{
Debug.Log((object)"[MORE PLAYERS] Failed to patch ContainerManager");
}
}
private static void expandPlayerContainers(ContainerManager __instance)
{
int num = 8;
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");
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>();
if ((Object)(object)val4 == (Object)null)
{
val4 = val3.AddComponent<ContainerNet>();
}
val4.id.Value = (ushort)i;
val3.transform.SetParent(((Component)val.transform.parent).transform);
Array.Resize(ref __instance.playerContainers, __instance.playerContainers.Length + 1);
__instance.playerContainers[i] = val4;
Debug.Log((object)("[MORE PLAYERS] Pushed Networked ContainerP" + i + " to ContainerManager and playerContainers"));
}
buildBackpacks();
}
private static void buildBackpacks()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: 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 = 8;
GameObject val = GameObject.Find("Tavern/Interactive/Backpacks/3");
GameObject val2 = GameObject.Find("Tavern/Interactive/Backpacks/2");
float num2 = val.transform.position.z - val2.transform.position.z;
if ((Object)(object)val != (Object)null)
{
for (int i = 4; i < num; i++)
{
GameObject val3 = Object.Instantiate<GameObject>(val);
((Object)val3).name = i.ToString();
val3.transform.SetParent(((Component)val.transform.parent).transform, false);
val3.transform.position = new Vector3(val.transform.position.x, val.transform.position.y, val.transform.position.z + (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}.");
}
}
else
{
Logger.LogWarning((object)"[MORE PLAYERS] Original object originalBackpack3 not found at Tavern/Interactive/Backpacks/3.");
}
}
private static void modifyBackpackBaseboard()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
int num = 8;
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");
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 PatchSpawnManager_Awake
{
[HarmonyDebug]
[HarmonyPatch(typeof(SpawnManager), "Awake")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
int maxPlayers = 8;
bool changed = false;
Debug.Log((object)"\n\n[MORE PLAYERS] Patching SpawnManager Awake method to edit _playerCheckPoint");
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode.Equals(OpCodes.Ldc_I4_4))
{
if (maxPlayers >= 0 && maxPlayers <= 8)
{
yield return new CodeInstruction(OpCodes.Ldc_I4, (object)maxPlayers);
}
else if (maxPlayers >= -128 && maxPlayers <= 127)
{
yield return new CodeInstruction(OpCodes.Ldc_I4_S, (object)(sbyte)maxPlayers);
}
else
{
yield return new CodeInstruction(OpCodes.Ldc_I4, (object)maxPlayers);
}
changed = true;
}
else
{
yield return instruction;
}
}
if (changed)
{
Debug.Log((object)"[MORE PLAYERS] Patched SpawnManager _playerCheckPoint");
}
else
{
Debug.Log((object)"[MORE PLAYERS] Failed to patch SpawnManager _playerCheckPoint");
}
}
}
public class PatchPlayerList_Refresh
{
[HarmonyDebug]
[HarmonyPatch(typeof(PlayerList), "Refresh")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
int maxPlayers = 8;
bool changed = false;
Debug.Log((object)"\n\n[MORE PLAYERS] Patching PlayerList Refresh method");
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode.Equals(OpCodes.Ldc_I4_4))
{
if (maxPlayers >= 0 && maxPlayers <= 8)
{
yield return new CodeInstruction(OpCodes.Ldc_I4, (object)maxPlayers);
}
else if (maxPlayers >= -128 && maxPlayers <= 127)
{
yield return new CodeInstruction(OpCodes.Ldc_I4_S, (object)(sbyte)maxPlayers);
}
else
{
yield return new CodeInstruction(OpCodes.Ldc_I4, (object)maxPlayers);
}
changed = true;
}
else
{
yield return instruction;
}
}
if (changed)
{
Debug.Log((object)"[MORE PLAYERS] Patched PlayerList[Refresh]");
}
else
{
Debug.Log((object)"[MORE PLAYERS] Failed to patch PlayerList[Refresh]");
}
}
}
[HarmonyPatch(typeof(RecipeManager), "Awake")]
public static class RecipeManagerTranspilerPatch
{
private static int maxPlayers = 8;
[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)
{
float[] value = new float[8] { 2f, 1.5f, 1.25f, 1f, 1f, 1f, 1f, 1f };
field.SetValue(__instance, value);
}
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_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: 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)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"\n\n[MORE PLAYERS] Patching (Overwriting) CaveSpawnManager SpawnCreatures method");
Debug.Log((object)"CaveSpawnManager.SpawnCreatures");
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_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"\n\n[MORE PLAYERS] Patching (Overwriting) CaveSpawnManager SpawnLoot method");
Debug.Log((object)"CaveSpawnManager.SpawnLoot");
int count = PlayerManager.Instance.players.Count;
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);
lootItemsCount = ((lootItemsCount == -1) ? num3 : lootItemsCount);
List<Transform> list2 = source.OrderBy((Transform n) => Guid.NewGuid()).ToList();
lootItemsCount = Math.Min(lootItemsCount, 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_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
//IL_0178: 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_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"\n\n[MORE PLAYERS] Patching (Overwriting) CaveSpawnManager SpawnChests method");
Debug.Log((object)"CaveSpawnManager.SpawnChests");
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, 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)
{
List<int> value = new List<int> { 7, 5, 4, 3, 3, 3, 3, 3 };
field.SetValue(__instance, value);
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)
{
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);
Transform[] value = (Transform[])(object)new Transform[6]
{
array[0],
array[1],
array[0],
array[1],
array[0],
array[1]
};
field.SetValue(__instance, value);
Debug.Log((object)"[MORE PLAYERS] Re-using bearSpawnPoints for more players");
}
else
{
Debug.LogError((object)"[MORE PLAYERS] _bearSpawnPoint field not found!");
}
}
}
private ConfigEntry<int> maxPlayers;
internal static ManualLogSource Logger;
private void Awake()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
maxPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "MaxPlayers", 8, "<int> Max Players (maximum : 8)");
Logger = ((BaseUnityPlugin)this).Logger;
HarmonyFileLog.Enabled = true;
Logger.LogInfo((object)"[MORE PLAYERS] Plugin ATTMorePlayers is loaded!");
Harmony val = new Harmony("com.michaelrooplall.mods.attmoreplayers.patch");
Debug.Log((object)"\n\n==========================\n[MORE PLAYERS][PATCHES][HARMONY]\n==========================\n");
val.PatchAll(typeof(MainMenu));
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);
}
try
{
expandPlayerListMenu();
}
catch (Exception ex2)
{
Logger.LogError((object)ex2);
}
Debug.Log((object)"\n==========================\n\n");
}
private void createMorePlayerSpawns()
{
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>();
Transform[] array = (Transform[])(object)new Transform[maxPlayers.Value];
for (int i = 0; i < component.playerSpawnPos.Length; i++)
{
array[i] = component.playerSpawnPos[i];
}
for (int j = 4; j < maxPlayers.Value; j++)
{
array[j] = component.playerSpawnPos[j % 4];
}
component.playerSpawnPos = array;
Debug.Log((object)"[MORE PLAYERS] Added more spawnpoints");
}
private void expandPlayerListMenu()
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"\n\n[MORE PLAYERS] [Expanding Player List Menu]");
GameObject val = GameObject.Find("Common/GameCanvas/Menu Players Screen");
GameObject val2 = GameObject.Find("Common/GameCanvas/Menu Players Screen/Panel/Panel/");
GameObject val3 = GameObject.Find("Common/GameCanvas/Menu Players Screen/Panel/Panel/PlayerListElement_2");
GameObject val4 = GameObject.Find("Common/GameCanvas/Menu Players Screen/Panel/Panel/PlayerListElement_3");
float num = val4.transform.position.y - val3.transform.position.y;
if ((Object)(object)val != (Object)null && (Object)(object)val3 != (Object)null && (Object)(object)val4 != (Object)null)
{
PlayerList component = val.GetComponent<PlayerList>();
if ((Object)(object)component == (Object)null)
{
Debug.Log((object)"[MORE PLAYERS] Failed to find PlayerList Component on MenuPlayerScreen");
return;
}
PlayerListElement[] array = (PlayerListElement[])(object)new PlayerListElement[maxPlayers.Value];
FieldInfo field = ((object)component).GetType().GetField("_ples", BindingFlags.Instance | BindingFlags.NonPublic);
if (field == null)
{
Debug.Log((object)"[MORE PLAYERS] Failed to extract _ples from PlayerList");
return;
}
PlayerListElement[] array2 = (PlayerListElement[])field.GetValue(component);
for (int i = 0; i < array2.Length; i++)
{
array[i] = array2[i];
}
for (int j = 4; j < maxPlayers.Value; j++)
{
GameObject val5 = Object.Instantiate<GameObject>(val4);
val5.transform.SetParent(val4.transform.parent);
((Object)val5).name = $"PlayerListElement_{j}";
val5.transform.position = new Vector3(val4.transform.position.x, val4.transform.position.y + (float)(j - 3) * num * 0.7f, val4.transform.position.z);
val5.transform.localScale = val4.transform.localScale;
val5.SetActive(false);
PlayerListElement component2 = val5.GetComponent<PlayerListElement>();
((Object)component2).name = $"PlayerListElement_{j}";
array[j] = component2;
Debug.Log((object)$"[MORE PLAYERS] Created new PlayerListElement for Player {j + 1}");
}
field.SetValue(component, array);
int childCount = val2.transform.childCount;
for (int num2 = childCount - 1; num2 >= 0; num2--)
{
Transform child = val2.transform.GetChild(num2);
((Component)child).transform.localScale = new Vector3(0.62f, 0.62f, 0.62f);
}
VerticalLayoutGroup component3 = val2.GetComponent<VerticalLayoutGroup>();
((HorizontalOrVerticalLayoutGroup)component3).childControlHeight = true;
((HorizontalOrVerticalLayoutGroup)component3).childScaleHeight = true;
Debug.Log((object)"[MORE PLAYERS] Finished adding PlayerListElement items to Player List");
}
else
{
Debug.Log((object)"[MORE PLAYERS] MenuPlayerScreen or PlayerListElement_2 or PlayerListElement_3 not found.");
}
}
private void insertScrollViewOnPlayerList()
{
Debug.Log((object)"[MORE PLAYERS] Inserting ScrollView to PlayerList");
GameObject val = GameObject.Find("Common/GameCanvas/Menu Players Screen/Panel/Panel");
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)"[MORE PLAYERS] Base Canvas Element not found.");
return;
}
GameObject val2 = Object.Instantiate<GameObject>(GameObject.Find("Common/GameCanvas/Shop Screen/BG/Consumables/QuestListPanel/Scroll View"));
Transform parent = val2.transform.Find("Viewport/Content");
val2.transform.SetParent(val.transform, false);
int childCount = val.transform.childCount;
for (int num = childCount - 1; num >= 0; num--)
{
Transform child = val.transform.GetChild(num);
if ((Object)(object)((Component)child).transform != (Object)(object)val2.transform)
{
child.SetParent(parent);
}
}
}
}
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 = "1.0.0";
}
}