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.Logging;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ButlerAdditionalPlayerFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ButlerAdditionalPlayerFix")]
[assembly: AssemblyTitle("ButlerAdditionalPlayerFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ButlerAdditionalPlayerFix;
[BepInPlugin("Dev1A3.ButlerAdditionalPlayerFix", "ButlerAdditionalPlayerFix", "1.0.0")]
internal class Plugin : BaseUnityPlugin
{
internal const string modGUID = "Dev1A3.ButlerAdditionalPlayerFix";
internal const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("Dev1A3.ButlerAdditionalPlayerFix");
internal static ManualLogSource logSource;
private void Awake()
{
logSource = ((BaseUnityPlugin)this).Logger;
Assembly executingAssembly = Assembly.GetExecutingAssembly();
harmony.PatchAll(executingAssembly);
logSource.LogInfo((object)"Patched ButlerEnemyAI");
}
}
[HarmonyPatch(typeof(ButlerEnemyAI), "Start")]
internal static class HarmonyPatches
{
public static int maxPlayers = 4;
[HarmonyPrefix]
public static void ButlerStart()
{
maxPlayers = StartOfRound.Instance.allPlayerScripts.Length;
}
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>();
int num = 0;
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode == OpCodes.Ldc_I4_4)
{
num++;
CodeInstruction item = new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.Field(typeof(HarmonyPatches), "maxPlayers"));
list.Add(item);
}
else
{
list.Add(instruction);
}
}
if (num != 3)
{
Plugin.logSource.LogWarning((object)$"Failed to replace butler array lengths: {num}/3");
}
return list.AsEnumerable();
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "ButlerAdditionalPlayerFix";
public const string PLUGIN_NAME = "ButlerAdditionalPlayerFix";
public const string PLUGIN_VERSION = "1.0.0";
}