Decompiled source of CoolerMultiplayer v1.2.0

plugins/CoolerMultiplayer.dll

Decompiled 7 hours ago
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using EntityStates;
using EntityStates.DroneTech.Weapon;
using EntityStates.MealPrep;
using EntityStates.Missions.BrotherEncounter;
using HUDdleUP;
using HUDdleUP.Patches;
using IL;
using IL.EntityStates.Enforcer;
using IL.EntityStates.MealPrep;
using IL.RoR2;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using On;
using On.EntityStates.DroneTech.Weapon;
using On.EntityStates.MealPrep;
using On.RoR2;
using On.RoR2.UI;
using R2API;
using R2API.Networking;
using R2API.Networking.Interfaces;
using R2API.Utils;
using RoR2;
using RoR2.ContentManagement;
using RoR2.Orbs;
using RoR2.Skills;
using RoR2.UI;
using RoR2BepInExPack.GameAssetPathsBetter;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace FluxSquido.CoolerMultiplayer;

internal static class BodyTeleport
{
	internal static void Teleport(CharacterBody body, CharacterBody target, bool groupTeleport)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: 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_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		Vector3 footPosition = target.footPosition;
		SpawnEffect(body, body.corePosition);
		TeleportBodyArgs val = new TeleportBodyArgs
		{
			targetPosition = footPosition,
			targetRotation = body.transform.rotation,
			teleportMinions = groupTeleport,
			resetStateMachines = groupTeleport
		};
		((TeleportBodyArgs)(ref val)).body = body;
		if (Util.HasEffectiveAuthority(((Component)body).gameObject))
		{
			val.forceOutOfVehicle = true;
			TeleportHelper.TeleportBody(val);
		}
		else
		{
			body.CallRpcTeleportWithLocalAuthority(val);
		}
		SpawnEffect(body, footPosition + (body.corePosition - body.footPosition));
	}

	internal static void SpawnEffect(CharacterBody body, Vector3 position)
	{
		//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_0020: 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_0027: 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)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		GameObject teleportEffectPrefab = Run.instance.GetTeleportEffectPrefab(((Component)body).gameObject);
		if (Object.op_Implicit((Object)(object)teleportEffectPrefab))
		{
			EffectManager.SpawnEffect(teleportEffectPrefab, new EffectData
			{
				origin = position,
				rotation = Quaternion.identity,
				scale = body.radius
			}, true);
		}
	}
}
internal sealed class ChefOrders : MonoBehaviour
{
	private struct Order
	{
		public CharacterMaster owner;

		public PickupIndex pickup;

		public int remaining;
	}

	private static bool directDelivery;

	private static readonly Action<ItemTransferOrb> onOrbArrival = OnOrbArrival;

	private readonly List<Order> orders = new List<Order>();

	private int pending;

	internal static void Init(bool deliverToInventory)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		directDelivery = deliverToInventory;
		MealPrepController.BeginCookingServer += new hook_BeginCookingServer(BeginCookingServer);
		MealPrepController.BeginCookingServer += new Manipulator(KeepCurrentCook);
		MealPrepBaseState.OnEnter += new hook_OnEnter(MealStateEnter);
		CookingToIdle.OnEnter += new hook_OnEnter(CookingToIdleEnter);
		CookingToIdle.DropItem += new Manipulator(ServeOrders);
	}

	private void Add(CharacterMaster owner, PickupIndex pickup, int count)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		count = Mathf.Max(1, count);
		orders.Add(new Order
		{
			owner = owner,
			pickup = pickup,
			remaining = count
		});
		pending += count;
	}

	private bool TryTake(out CharacterMaster owner, out PickupIndex pickup)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		if (orders.Count == 0)
		{
			owner = null;
			pickup = PickupIndex.none;
			return false;
		}
		Order value = orders[0];
		owner = value.owner;
		pickup = value.pickup;
		if (--value.remaining > 0)
		{
			orders[0] = value;
		}
		else
		{
			orders.RemoveAt(0);
		}
		pending--;
		return true;
	}

	private static void BeginCookingServer(orig_BeginCookingServer orig, MealPrepController self, Interactor activator, PickupIndex[] itemsToTake, PickupIndex reward, int count)
	{
		//IL_0067: 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)
		CharacterBody val = (Object.op_Implicit((Object)(object)activator) ? ((Component)activator).GetComponent<CharacterBody>() : null);
		if (NetworkServer.active && Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.inventory) && self.IsAffordable(itemsToTake, val))
		{
			ChefOrders chefOrders = ((Component)self).GetComponent<ChefOrders>();
			if (!Object.op_Implicit((Object)(object)chefOrders))
			{
				chefOrders = ((Component)self).gameObject.AddComponent<ChefOrders>();
			}
			chefOrders.Add(val.master, reward, count);
		}
		orig.Invoke(self, activator, itemsToTake, reward, count);
	}

	private static void KeepCurrentCook(ILContext il)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		ILCursor val = new ILCursor(il);
		if (!val.TryGotoNext(new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchCallvirt<EntityStateMachine>(x, "SetNextState")
		}))
		{
			CoolerMultiplayerPlugin.Log.LogError((object)(((MemberReference)il.Method).Name + " IL hook failed, new orders will restart the cook."));
			return;
		}
		val.NopNext();
		val.EmitDelegate<Action<EntityStateMachine, EntityState>>((Action<EntityStateMachine, EntityState>)delegate(EntityStateMachine esm, EntityState next)
		{
			EntityState state = esm.state;
			if (!(state is WaitToBeginCooking) && !(state is Cooking) && !(state is CookingToIdle))
			{
				esm.SetNextState(next);
			}
		});
	}

	private static void MealStateEnter(orig_OnEnter orig, MealPrepBaseState self)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: 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_006d: Expected O, but got Unknown
		orig.Invoke(self);
		if (NetworkServer.active && self is Idle)
		{
			ChefOrders component = ((EntityState)self).GetComponent<ChefOrders>();
			if (Object.op_Implicit((Object)(object)component) && component.pending != 0)
			{
				((EntityState)self).outer.SetNextState((EntityState)new WaitToBeginCooking
				{
					pickupsToTake = new List<PickupIndex>(),
					pickupToDrop = component.orders[0].pickup,
					amountToDrop = component.pending
				});
			}
		}
	}

	private static void CookingToIdleEnter(orig_OnEnter orig, CookingToIdle self)
	{
		ChefOrders component = ((EntityState)self).GetComponent<ChefOrders>();
		if (Object.op_Implicit((Object)(object)component) && component.pending > 0)
		{
			((MealPrepBaseState)self).amountToDrop = component.pending;
		}
		orig.Invoke(self);
	}

	private static void ServeOrders(ILContext il)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		if (!val.TryGotoNext(new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchCall(x, typeof(PickupDropletController), "CreatePickupDroplet")
		}))
		{
			CoolerMultiplayerPlugin.Log.LogError((object)(((MemberReference)il.Method).Name + " IL hook failed, meals will drop on the ground."));
			return;
		}
		val.NopNext();
		val.Emit(OpCodes.Ldarg_0);
		val.EmitDelegate<Action<PickupIndex, Vector3, Vector3, CookingToIdle>>((Action<PickupIndex, Vector3, Vector3, CookingToIdle>)Serve);
	}

	private static void Serve(PickupIndex pickup, Vector3 position, Vector3 velocity, CookingToIdle state)
	{
		//IL_0025: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		ChefOrders component = ((EntityState)state).GetComponent<ChefOrders>();
		if (Object.op_Implicit((Object)(object)component) && component.TryTake(out var owner, out var pickup2))
		{
			Deliver(owner, pickup2, position, velocity);
		}
		else
		{
			Drop(pickup, position, velocity);
		}
	}

	private static void Deliver(CharacterMaster owner, PickupIndex pickup, Vector3 position, Vector3 velocity)
	{
		//IL_0000: 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_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Invalid comparison between Unknown and I4
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0056: 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_0065: Unknown result type (might be due to invalid IL or missing references)
		PickupDef pickupDef = PickupCatalog.GetPickupDef(pickup);
		CharacterBody val = (Object.op_Implicit((Object)(object)owner) ? owner.GetBody() : null);
		if (!directDelivery || pickupDef == null || !Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)owner.inventory))
		{
			Drop(pickup, position, velocity);
			return;
		}
		if ((int)pickupDef.itemIndex == -1)
		{
			Drop(pickup, val.corePosition + Vector3.up, Vector3.up * 10f);
			return;
		}
		ItemTransferOrb.DispatchItemTransferOrb(new DispatchArgs
		{
			origin = position,
			inventoryToGrantTo = owner.inventory,
			itemIndex = pickupDef.itemIndex,
			permanentCount = 1,
			isPickup = true,
			travelDuration = 1f,
			onArrivalBehavior = onOrbArrival
		});
	}

	private static void OnOrbArrival(ItemTransferOrb orb)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)orb.inventoryToGrantTo))
		{
			ItemTransferOrb.DefaultOnArrivalBehavior(orb);
		}
		else
		{
			Drop(PickupCatalog.FindPickupIndex(orb.itemIndex), ((Orb)orb).origin, Vector3.up * 15f);
		}
	}

	private static void Drop(PickupIndex pickup, Vector3 position, Vector3 velocity)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: 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)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: 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)
		CreatePickupInfo val = default(CreatePickupInfo);
		((CreatePickupInfo)(ref val)).pickup = new UniquePickup(pickup);
		val.position = position;
		val.rotation = Quaternion.identity;
		PickupDropletController.CreatePickupDroplet(val, position, velocity);
	}
}
internal static class SharedChef
{
	private sealed class OpenMenu : INetMessage, ISerializableObject
	{
		private NetworkInstanceId chef;

		private NetworkInstanceId master;

		public OpenMenu()
		{
		}

		public OpenMenu(NetworkInstanceId chef, NetworkInstanceId master)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//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)
			this.chef = chef;
			this.master = master;
		}

		public void Serialize(NetworkWriter writer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(chef);
			writer.Write(master);
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			chef = reader.ReadNetworkId();
			master = reader.ReadNetworkId();
		}

		public void OnReceived()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			CraftingController val = NetworkLookup.Find<CraftingController>(chef);
			CharacterMaster val2 = NetworkLookup.Find<CharacterMaster>(master);
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val2) && !((PickupPickerController)val).networkUIPromptController.inUse)
			{
				CharacterBody body = val2.GetBody();
				if (Object.op_Implicit((Object)(object)body))
				{
					((PickupPickerController)val).SetOptionsInternal(((PickupPickerController)val).GetGeneratedOptionsFromInteractor(((Component)body).GetComponent<Interactor>()).ToArray());
					((PickupPickerController)val).networkUIPromptController.currentParticipantMaster = val2;
				}
			}
		}
	}

	private sealed class ConfirmRecipe : INetMessage, ISerializableObject
	{
		private const int MaxIngredients = 16;

		private NetworkInstanceId chef;

		private NetworkInstanceId cook;

		private PickupIndex[] ingredients;

		public ConfirmRecipe()
		{
		}

		public ConfirmRecipe(NetworkInstanceId chef, NetworkInstanceId cook, PickupIndex[] ingredients)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//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)
			this.chef = chef;
			this.cook = cook;
			this.ingredients = ingredients;
		}

		public void Serialize(NetworkWriter writer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(chef);
			writer.Write(cook);
			writer.WritePackedUInt32((uint)ingredients.Length);
			for (int i = 0; i < ingredients.Length; i++)
			{
				NetworkExtensions.Write(writer, ingredients[i]);
			}
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			chef = reader.ReadNetworkId();
			cook = reader.ReadNetworkId();
			ingredients = (PickupIndex[])(object)new PickupIndex[Math.Min(reader.ReadPackedUInt32(), 16u)];
			for (int i = 0; i < ingredients.Length; i++)
			{
				ingredients[i] = NetworkExtensions.ReadPickupIndex(reader);
			}
		}

		public void OnReceived()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			CraftingController val = NetworkLookup.Find<CraftingController>(chef);
			CharacterBody val2 = NetworkLookup.Find<CharacterBody>(cook);
			if (!Object.op_Implicit((Object)(object)val) || !((PickupPickerController)val).available || !Object.op_Implicit((Object)(object)val2) || !val2.isPlayerControlled || !val2.healthComponent.alive)
			{
				return;
			}
			Interactor component = ((Component)val2).GetComponent<Interactor>();
			float cutoffDistance = ((PickupPickerController)val).cutoffDistance;
			if (component.isRemoteOp && !((PickupPickerController)val).allowRemoteOpInteraction)
			{
				return;
			}
			Vector3 val3 = val2.inputBank.aimOrigin - ((Component)val).transform.position;
			if (!(((Vector3)(ref val3)).sqrMagnitude > cutoffDistance * cutoffDistance))
			{
				RecipeEntry val4 = FindRecipe(val);
				if (val4 != null)
				{
					val.OnResultConfirmed.Invoke(component, ingredients, val4.result, val4.amountToDrop);
				}
			}
		}

		private RecipeEntry FindRecipe(CraftingController crafting)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (ingredients.Length != crafting.ingredientCount || Array.IndexOf(ingredients, PickupIndex.none) >= 0)
			{
				return null;
			}
			RecipeEntry[] array = CraftableCatalog.FindRecipesThatCanAcceptIngredients(ingredients);
			CraftableCatalog.FilterByEntitlement(ref array);
			RecipeEntry result = null;
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i] != null && CraftableCatalog.ValidateRecipe(array[i], ingredients))
				{
					result = array[i];
				}
			}
			return result;
		}
	}

	internal static void Init()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected O, but got Unknown
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Expected O, but got Unknown
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Expected O, but got Unknown
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Expected O, but got Unknown
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Expected O, but got Unknown
		NetworkingAPI.RegisterMessageType<OpenMenu>();
		NetworkingAPI.RegisterMessageType<ConfirmRecipe>();
		PickupPickerController.OnInteractionBegin += new hook_OnInteractionBegin(OnInteractionBegin);
		PickupPickerController.GetInteractability += new hook_GetInteractability(GetInteractability);
		PickupPickerController.FixedUpdate += new hook_FixedUpdate(FixedUpdate);
		PickupPickerController.SubmitChoice += new hook_SubmitChoice(SubmitChoice);
		PickupPickerController.OnPanelDestroyed += new hook_OnPanelDestroyed(OnPanelDestroyed);
		PickupPickerController.SetAvailable += new hook_SetAvailable(SetAvailable);
		CraftingController.SetSlot += new Manipulator(SetSlotLocally);
		CraftingController.ClearSlot += new Manipulator(ClearSlotLocally);
		CraftingController.ConfirmSelection += new hook_ConfirmSelection(ConfirmSelection);
		CraftingController.OnSerialize += new hook_OnSerialize(OnSerialize);
	}

	private static void OnInteractionBegin(orig_OnInteractionBegin orig, PickupPickerController self, Interactor activator)
	{
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		if (!(self is CraftingController) || !((Behaviour)self).enabled)
		{
			orig.Invoke(self, activator);
			return;
		}
		CharacterMaster val = NetworkLookup.MasterOf(activator);
		NetworkUser val2 = ((Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.playerCharacterMasterController)) ? val.playerCharacterMasterController.networkUser : null);
		if (Object.op_Implicit((Object)(object)val2))
		{
			Option[] array = (self.networkUIPromptController.inUse ? ((Option[])self.options.Clone()) : null);
			((UnityEvent<Interactor>)(object)self.onServerInteractionBegin).Invoke(activator);
			if (array != null)
			{
				self.SetOptionsInternal(array);
			}
			NetMessageExtensions.Send((INetMessage)(object)new OpenMenu(((NetworkBehaviour)self).netId, ((NetworkBehaviour)val).netId), ((NetworkBehaviour)val2).connectionToClient);
		}
	}

	private static Interactability GetInteractability(orig_GetInteractability orig, PickupPickerController self, Interactor activator)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		if (!(self is CraftingController))
		{
			return orig.Invoke(self, activator);
		}
		if (activator.isRemoteOp && !self.allowRemoteOpInteraction)
		{
			return (Interactability)0;
		}
		CharacterMaster currentParticipantMaster = self.networkUIPromptController.currentParticipantMaster;
		if (Object.op_Implicit((Object)(object)currentParticipantMaster) && (Object)(object)currentParticipantMaster == (Object)(object)NetworkLookup.MasterOf(activator))
		{
			return (Interactability)1;
		}
		if (self.available)
		{
			return (Interactability)2;
		}
		return (Interactability)0;
	}

	private static void FixedUpdate(orig_FixedUpdate orig, PickupPickerController self)
	{
		//IL_0043: 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_0053: 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)
		if (!(self is CraftingController))
		{
			orig.Invoke(self);
			return;
		}
		NetworkUIPromptController networkUIPromptController = self.networkUIPromptController;
		CharacterMaster currentParticipantMaster = networkUIPromptController.currentParticipantMaster;
		if (!Object.op_Implicit((Object)(object)currentParticipantMaster))
		{
			return;
		}
		CharacterBody body = currentParticipantMaster.GetBody();
		float cutoffDistance = self.cutoffDistance;
		if (Object.op_Implicit((Object)(object)body))
		{
			Vector3 val = body.inputBank.aimOrigin - ((Component)self).transform.position;
			if (!(((Vector3)(ref val)).sqrMagnitude > cutoffDistance * cutoffDistance))
			{
				return;
			}
		}
		networkUIPromptController.currentParticipantMaster = null;
	}

	private static void SubmitChoice(orig_SubmitChoice orig, PickupPickerController self, int choiceIndex)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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_0055: Unknown result type (might be due to invalid IL or missing references)
		if (!(self is CraftingController))
		{
			orig.Invoke(self, choiceIndex);
		}
		else if ((uint)choiceIndex < (uint)self.options.Length)
		{
			Option val = self.options[choiceIndex];
			if (val.available)
			{
				((UnityEvent<int>)(object)self.onPickupSelected).Invoke(val.pickup.pickupIndex.value);
				((UnityEvent<UniquePickup>)(object)self.onUniquePickupSelected).Invoke(val.pickup);
			}
		}
	}

	private static void OnPanelDestroyed(orig_OnPanelDestroyed orig, PickupPickerController self, OnDestroyCallback callback)
	{
		if (self is CraftingController)
		{
			self.networkUIPromptController.currentParticipantMaster = null;
		}
		else
		{
			orig.Invoke(self, callback);
		}
	}

	private static void SetAvailable(orig_SetAvailable orig, PickupPickerController self, bool newAvailable)
	{
		if (!(self is CraftingController))
		{
			orig.Invoke(self, newAvailable);
		}
		else if (NetworkServer.active)
		{
			orig.Invoke(self, true);
		}
	}

	private static void SetSlotLocally(ILContext il)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		ILCursor val = new ILCursor(il);
		if (val.TryGotoNext(new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchCall<CraftingController>(x, "UpdateSlotAndDirty")
		}))
		{
			val.Next.Operand = il.Import((MethodBase)typeof(CraftingController).GetMethod("UpdateSlot", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic));
		}
		else
		{
			CoolerMultiplayerPlugin.Log.LogError((object)(((MemberReference)il.Method).Name + " IL hook failed, chef slots won't fill for clients."));
		}
	}

	private static void ClearSlotLocally(ILContext il)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchCall<NetworkServer>(x, "get_active")
		}))
		{
			val.Emit(OpCodes.Pop);
			val.Emit(OpCodes.Ldc_I4_1);
		}
		else
		{
			CoolerMultiplayerPlugin.Log.LogError((object)(((MemberReference)il.Method).Name + " IL hook failed, chef slots won't clear for clients."));
		}
	}

	private static void ConfirmSelection(orig_ConfirmSelection orig, CraftingController self)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		CharacterMaster currentParticipantMaster = ((PickupPickerController)self).networkUIPromptController.currentParticipantMaster;
		CharacterBody val = (Object.op_Implicit((Object)(object)currentParticipantMaster) ? currentParticipantMaster.GetBody() : null);
		if (Object.op_Implicit((Object)(object)val))
		{
			NetMessageExtensions.Send((INetMessage)(object)new ConfirmRecipe(((NetworkBehaviour)self).netId, ((NetworkBehaviour)val).netId, (PickupIndex[])self.ingredients.Clone()), (NetworkDestination)2);
		}
	}

	private static bool OnSerialize(orig_OnSerialize orig, CraftingController self, NetworkWriter writer, bool initialState)
	{
		if (!initialState)
		{
			uint num = ((NetworkBehaviour)self).syncVarDirtyBits & CraftingController.availableDirtyBit;
			if (num != ((NetworkBehaviour)self).syncVarDirtyBits)
			{
				((NetworkBehaviour)self).ClearAllDirtyBits();
				((NetworkBehaviour)self).SetDirtyBit(num);
			}
		}
		return orig.Invoke(self, writer, initialState);
	}
}
[BepInPlugin("FluxSquido.CoolerMultiplayer", "CoolerMultiplayer", "1.2.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public sealed class CoolerMultiplayerPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "FluxSquido.CoolerMultiplayer";

	public const string PluginName = "CoolerMultiplayer";

	public const string PluginVersion = "1.2.0";

	internal static ManualLogSource Log;

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		BindChef();
		BindRemoteOpDrones();
		BindDroneGiving();
		BindSharedDrones();
		BindMithrix();
		if (HUDdleUPCompat.Loaded)
		{
			HUDdleUPCompat.Init();
		}
	}

	private void BindChef()
	{
		bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("Wandering Chef", "Multiple Players At Once", true, "Several players can use the chef at the same time.").Value;
		bool value2 = ((BaseUnityPlugin)this).Config.Bind<bool>("Wandering Chef", "Deliver Meals To Inventory", true, "Cooked items go straight into the inventory of the player who ordered them instead of dropping on the ground. Equipments will land at that player's feet so your current equipment isn't swapped out.").Value;
		if (value)
		{
			SharedChef.Init();
		}
		if (value || value2)
		{
			ChefOrders.Init(value2);
		}
	}

	private void BindRemoteOpDrones()
	{
		bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("Remote Op Drones", "Drone Abilities", true, "Remote Op drone abilities: gives drones a Disconnect (Utility) and a Teleport to Player (Special) skill. Needs a restart.").Value;
		bool value2 = ((BaseUnityPlugin)this).Config.Bind<bool>("Remote Op Drones", "Disconnect", true, "Disconnect (Utility): hold to leave the drone and go back to spectating.").Value;
		float value3 = ((BaseUnityPlugin)this).Config.Bind<float>("Remote Op Drones", "Disconnect Hold Seconds", 1f, "How long you hold Disconnect before leaving the drone, 0 to 5 seconds.").Value;
		bool value4 = ((BaseUnityPlugin)this).Config.Bind<bool>("Remote Op Drones", "Teleport To Player", true, "Teleport to Player (Special): Teleport to the nearest living player.").Value;
		float value5 = ((BaseUnityPlugin)this).Config.Bind<float>("Remote Op Drones", "Teleport Cooldown", 15f, "Teleport to Player's base cooldown in seconds, 1 to 600.").Value;
		if (value)
		{
			DroneAbilities.Init(value2, value3, value4, value5);
		}
	}

	private void BindDroneGiving()
	{
		if (((BaseUnityPlugin)this).Config.Bind<bool>("Drones", "Give Drones", true, "Drag one of your drones from the ally list onto another player's bar on the scoreboard, or their icon in the ally list, to give it to them. Works on any drone you can buy, except gunner turrets.").Value)
		{
			DroneGiving.Init();
		}
	}

	private void BindSharedDrones()
	{
		bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("Survivors", "Operator Drone Override", true, "Lets Operator use every player's drones, instead of just his own. Become the ultimate drone hoarder!!! His secondary skill stocks count as well. Turns itself off when there's more than one Operator in the lobby to prevent immense jank, might revisit to see if I can get a clean implementation for more than one.").Value;
		bool value2 = ((BaseUnityPlugin)this).Config.Bind<bool>("Survivors", "Enforcer Shared Turrets", true, "Enforcer's special teleports every player's gunner turrets to him, not just his own.").Value;
		if (value)
		{
			SharedDrones.InitOperator();
		}
		if (value2)
		{
			SharedDrones.InitEnforcer();
		}
	}

	private void BindMithrix()
	{
		if (((BaseUnityPlugin)this).Config.Bind<bool>("Mithrix", "One Player Starts The Fight", true, "Gearbox made it so that their final bosses tp everyone to the arena the moment someone steps inside, like False Son or Solus Heart/Wing for example. I wanted Mithrix to use this same system too so if one person has a pillar-skip, everyone has a pillar-skip. :)").Value)
		{
			MithrixArena.Init();
		}
	}
}
internal static class DroneAbilities
{
	private sealed class DisconnectRequest : INetMessage, ISerializableObject
	{
		private NetworkInstanceId drone;

		public DisconnectRequest()
		{
		}

		public DisconnectRequest(NetworkInstanceId drone)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			this.drone = drone;
		}

		public void Serialize(NetworkWriter writer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(drone);
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			drone = reader.ReadNetworkId();
		}

		public void OnReceived()
		{
			//IL_0001: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody val = NetworkLookup.Find<CharacterBody>(drone);
			CharacterMaster val2 = (Object.op_Implicit((Object)(object)val) ? val.master : null);
			if (IsPlayerDrone(val) && Object.op_Implicit((Object)(object)val2) && !((Object)(object)val2.GetBodyObject() != (Object)(object)((Component)val).gameObject) && val.healthComponent.alive)
			{
				BodyTeleport.SpawnEffect(val, val.corePosition);
				val2.deathFootPosition = val.footPosition;
				val2.lostBodyToDeath = true;
				val2.preventGameOver = false;
				val2.preventRespawnUntilNextStageServer = true;
				val2.inventory.SetEquipmentDisabled(false);
				if (Object.op_Implicit((Object)(object)((Component)val).GetComponent<Inventory>()))
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
				else
				{
					val2.DestroyBody();
				}
				val2.RestoreOriginalBodyPrefab();
			}
		}
	}

	private sealed class TeleportRequest : INetMessage, ISerializableObject
	{
		private NetworkInstanceId drone;

		public TeleportRequest()
		{
		}

		public TeleportRequest(NetworkInstanceId drone)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			this.drone = drone;
		}

		public void Serialize(NetworkWriter writer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(drone);
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			drone = reader.ReadNetworkId();
		}

		public void OnReceived()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody body = NetworkLookup.Find<CharacterBody>(drone);
			CharacterBody val = (IsPlayerDrone(body) ? NearestPlayer(body) : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				BodyTeleport.Teleport(body, val, groupTeleport: false);
			}
		}
	}

	private const string StateMachineName = "CoolerMultiplayerDroneAbility";

	private static SkillFamily disconnectFamily;

	private static SkillFamily teleportFamily;

	internal static float HoldSeconds { get; private set; }

	internal static void Init(bool disconnect, float holdSeconds, bool teleport, float cooldown)
	{
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Expected O, but got Unknown
		NetworkingAPI.RegisterMessageType<DisconnectRequest>();
		NetworkingAPI.RegisterMessageType<TeleportRequest>();
		if (disconnect)
		{
			HoldSeconds = Mathf.Clamp(holdSeconds, 0f, 5f);
			OnePressSkillDef onePressSkillDef = CreateSkill<OnePressSkillDef>("Disconnect", typeof(DisconnectState), (InterruptPriority)0, RoR2_DLC3_Drone_Tech.DroneBall_asset);
			((SkillDef)onePressSkillDef).baseRechargeInterval = Mathf.Max(0.1f, HoldSeconds);
			((SkillDef)onePressSkillDef).beginSkillCooldownOnSkillEnd = true;
			disconnectFamily = CreateFamily((SkillDef)(object)onePressSkillDef);
		}
		if (teleport)
		{
			TeleportSkillDef teleportSkillDef = CreateSkill<TeleportSkillDef>("Teleport", typeof(TeleportState), (InterruptPriority)1, RoR2_DLC3_Drone_Tech.Command_asset);
			((SkillDef)teleportSkillDef).baseRechargeInterval = Mathf.Clamp(cooldown, 1f, 600f);
			teleportFamily = CreateFamily((SkillDef)(object)teleportSkillDef);
		}
		if (Object.op_Implicit((Object)(object)disconnectFamily) || Object.op_Implicit((Object)(object)teleportFamily))
		{
			BodyCatalog.SetBodyPrefabs += new hook_SetBodyPrefabs(SetBodyPrefabs);
		}
	}

	private static T CreateSkill<T>(string name, Type state, InterruptPriority priority, string iconSkillGuid) where T : SkillDef
	{
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: 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_0192: Unknown result type (might be due to invalid IL or missing references)
		string text = "FLUXSQUIDO_COOLERMULTIPLAYER_DRONE_" + name.ToUpperInvariant();
		T skill = ScriptableObject.CreateInstance<T>();
		((SkillDef)skill).skillName = "CoolerMultiplayerDrone" + name;
		((Object)(object)skill).name = ((SkillDef)skill).skillName;
		((SkillDef)skill).skillNameToken = text + "_NAME";
		((SkillDef)skill).skillDescriptionToken = text + "_DESCRIPTION";
		((SkillDef)skill).activationStateMachineName = "CoolerMultiplayerDroneAbility";
		bool flag = default(bool);
		((SkillDef)skill).activationState = ContentAddition.AddEntityState(state, ref flag);
		((SkillDef)skill).interruptPriority = priority;
		((SkillDef)skill).baseMaxStock = 1;
		((SkillDef)skill).rechargeStock = 1;
		((SkillDef)skill).requiredStock = 1;
		((SkillDef)skill).stockToConsume = 1;
		((SkillDef)skill).fullRestockOnAssign = true;
		((SkillDef)skill).hideStockCount = true;
		((SkillDef)skill).isCombatSkill = false;
		((SkillDef)skill).canceledFromSprinting = false;
		((SkillDef)skill).cancelSprintingOnActivation = false;
		((SkillDef)skill).mustKeyPress = true;
		ContentAddition.AddSkillDef((SkillDef)(object)skill);
		AsyncOperationHandle<SkillDef> val = Addressables.LoadAssetAsync<SkillDef>((object)iconSkillGuid);
		val.Completed += delegate(AsyncOperationHandle<SkillDef> handle)
		{
			((SkillDef)skill).icon = handle.Result.icon;
		};
		return skill;
	}

	private static SkillFamily CreateFamily(SkillDef skill)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Expected O, but got Unknown
		//IL_0049: 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)
		SkillFamily val = ScriptableObject.CreateInstance<SkillFamily>();
		((Object)val).name = skill.skillName + "Family";
		Variant[] array = new Variant[1];
		Variant val2 = new Variant
		{
			skillDef = skill
		};
		((Variant)(ref val2)).viewableNode = new Node(skill.skillName, false, (Node)null);
		array[0] = val2;
		val.variants = (Variant[])(object)array;
		ContentAddition.AddSkillFamily(val);
		return val;
	}

	private static void SetBodyPrefabs(orig_SetBodyPrefabs orig, GameObject[] newBodyPrefabs)
	{
		HashSet<GameObject> hashSet = new HashSet<GameObject>();
		DroneDef[] droneDefs = ContentManager.droneDefs;
		foreach (DroneDef val in droneDefs)
		{
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.remoteOpBody))
			{
				hashSet.Add(val.remoteOpBody);
			}
		}
		foreach (GameObject val2 in newBodyPrefabs)
		{
			if (hashSet.Contains(val2))
			{
				AddSkills(val2);
			}
		}
		orig.Invoke(newBodyPrefabs);
	}

	private static void AddSkills(GameObject body)
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		SkillLocator component = body.GetComponent<SkillLocator>();
		if (!Object.op_Implicit((Object)(object)component) || Object.op_Implicit((Object)(object)EntityStateMachine.FindByCustomName(body, "CoolerMultiplayerDroneAbility")))
		{
			return;
		}
		bool flag = Object.op_Implicit((Object)(object)disconnectFamily) && !Object.op_Implicit((Object)(object)component.utility);
		bool flag2 = Object.op_Implicit((Object)(object)teleportFamily) && !Object.op_Implicit((Object)(object)component.special);
		if (flag || flag2)
		{
			EntityStateMachine obj = body.AddComponent<EntityStateMachine>();
			obj.customName = "CoolerMultiplayerDroneAbility";
			obj.initialStateType = new SerializableEntityStateType(typeof(Idle));
			obj.mainStateType = new SerializableEntityStateType(typeof(Idle));
			if (flag)
			{
				component.utility = AddSlot(body, disconnectFamily);
			}
			if (flag2)
			{
				component.special = AddSlot(body, teleportFamily);
			}
		}
	}

	private static GenericSkill AddSlot(GameObject body, SkillFamily family)
	{
		GenericSkill obj = body.AddComponent<GenericSkill>();
		obj.skillName = family.variants[0].skillDef.skillName;
		obj.hideInCharacterSelect = true;
		obj._skillFamily = family;
		return obj;
	}

	internal static bool IsPlayerDrone(CharacterBody body)
	{
		if (Object.op_Implicit((Object)(object)body) && body.isRemoteOp)
		{
			return body.isPlayerControlled;
		}
		return false;
	}

	internal static CharacterBody NearestPlayer(CharacterBody drone)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		CharacterBody result = null;
		float num = float.PositiveInfinity;
		ReadOnlyCollection<PlayerCharacterMasterController> instances = PlayerCharacterMasterController.instances;
		for (int i = 0; i < instances.Count; i++)
		{
			CharacterMaster master = instances[i].master;
			CharacterBody val = (Object.op_Implicit((Object)(object)master) ? master.GetBody() : null);
			if (instances[i].isConnected && Object.op_Implicit((Object)(object)val) && !((Object)(object)val == (Object)(object)drone) && !val.isRemoteOp && val.healthComponent.alive)
			{
				Vector3 val2 = val.corePosition - drone.corePosition;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude < num)
				{
					num = sqrMagnitude;
					result = val;
				}
			}
		}
		return result;
	}

	internal static void RequestDisconnect(CharacterBody body)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		NetMessageExtensions.Send((INetMessage)(object)new DisconnectRequest(((NetworkBehaviour)body).netId), (NetworkDestination)2);
	}

	internal static void RequestTeleport(CharacterBody body)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		NetMessageExtensions.Send((INetMessage)(object)new TeleportRequest(((NetworkBehaviour)body).netId), (NetworkDestination)2);
	}
}
internal static class DroneGiving
{
	private sealed class GiveRequest : INetMessage, ISerializableObject
	{
		private NetworkInstanceId drone;

		private NetworkInstanceId giver;

		private NetworkInstanceId target;

		public GiveRequest()
		{
		}

		public GiveRequest(NetworkInstanceId drone, NetworkInstanceId giver, NetworkInstanceId target)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			this.drone = drone;
			this.giver = giver;
			this.target = target;
		}

		public void Serialize(NetworkWriter writer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(drone);
			writer.Write(giver);
			writer.Write(target);
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//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)
			drone = reader.ReadNetworkId();
			giver = reader.ReadNetworkId();
			target = reader.ReadNetworkId();
		}

		public void OnReceived()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			CharacterMaster val = NetworkLookup.Find<CharacterMaster>(drone);
			CharacterMaster val2 = NetworkLookup.Find<CharacterMaster>(giver);
			CharacterMaster val3 = NetworkLookup.Find<CharacterMaster>(target);
			if (CanGive(val, val2) && CanReceive(val3, val2))
			{
				Give(val, val2, val3);
			}
		}
	}

	private const string MessageColor = "<color=#96EBAA>";

	private const string NameColor = "<color=#AAE6F0>";

	private static DroneDef gunnerTurret;

	internal static void Init()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		NetworkingAPI.RegisterMessageType<GiveRequest>();
		AllyCardManager.BuildFromCharacterData += new hook_BuildFromCharacterData(RelayoutAllyCards);
		AsyncOperationHandle<DroneDef> val = Addressables.LoadAssetAsync<DroneDef>((object)RoR2_Base_Drones.Turret1_asset);
		val.Completed += delegate(AsyncOperationHandle<DroneDef> handle)
		{
			gunnerTurret = handle.Result;
		};
		AsyncOperationHandle<GameObject> val2 = Addressables.LoadAssetAsync<GameObject>((object)RoR2_Base_UI.AllyCard_prefab);
		val2.Completed += delegate(AsyncOperationHandle<GameObject> handle)
		{
			AddDragSource(handle.Result);
		};
		val2 = Addressables.LoadAssetAsync<GameObject>((object)RoR2_Base_UI.ScoreboardStrip_prefab);
		val2.Completed += delegate(AsyncOperationHandle<GameObject> handle)
		{
			AddDropTarget(handle.Result);
		};
	}

	private static void RelayoutAllyCards(orig_BuildFromCharacterData orig, AllyCardManager self, object characterDataSet)
	{
		orig.Invoke(self, characterDataSet);
		LayoutRebuilder.MarkLayoutForRebuild(self.rectTransform);
	}

	private static void AddDragSource(GameObject card)
	{
		((Graphic)card.GetComponent<AllyCardController>().portraitIconImage).raycastTarget = true;
		card.AddComponent<DroneDragSource>();
		card.AddComponent<DroneDropTarget>();
	}

	private static void AddDropTarget(GameObject strip)
	{
		strip.AddComponent<DroneDropTarget>();
	}

	internal static bool CanGive(CharacterMaster drone, CharacterMaster giver)
	{
		CharacterBody val = (Object.op_Implicit((Object)(object)drone) ? drone.GetBody() : null);
		if (!Object.op_Implicit((Object)(object)val) || !val.healthComponent.alive || !Object.op_Implicit((Object)(object)giver) || !Object.op_Implicit((Object)(object)giver.playerCharacterMasterController) || (Object)(object)drone.minionOwnership.ownerMaster != (Object)(object)giver)
		{
			return false;
		}
		DroneDef val2 = DroneDefOf(val);
		if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.droneBrokenSpawnCard))
		{
			return (Object)(object)val2 != (Object)(object)gunnerTurret;
		}
		return false;
	}

	private static DroneDef DroneDefOf(CharacterBody body)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		return DroneCatalog.GetDroneDef(DroneCatalog.GetDroneIndexFromBodyIndex(body.bodyIndex));
	}

	private static bool CanReceive(CharacterMaster target, CharacterMaster giver)
	{
		CharacterBody val = (Object.op_Implicit((Object)(object)target) ? target.GetBody() : null);
		if (Object.op_Implicit((Object)(object)val) && val.healthComponent.alive && (Object)(object)target != (Object)(object)giver)
		{
			return Object.op_Implicit((Object)(object)target.playerCharacterMasterController);
		}
		return false;
	}

	internal static void RequestGive(CharacterMaster drone, CharacterMaster giver, CharacterMaster target)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//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)
		if (CanGive(drone, giver) && CanReceive(target, giver))
		{
			NetMessageExtensions.Send((INetMessage)(object)new GiveRequest(((NetworkBehaviour)drone).netId, ((NetworkBehaviour)giver).netId, ((NetworkBehaviour)target).netId), (NetworkDestination)2);
		}
	}

	private static void Give(CharacterMaster drone, CharacterMaster giver, CharacterMaster target)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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_0079: 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)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: 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_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Expected O, but got Unknown
		CharacterBody body = drone.GetBody();
		CharacterBody body2 = target.GetBody();
		DroneDef val = DroneDefOf(body);
		ItemDef droneUpgradeHidden = Items.DroneUpgradeHidden;
		int num = drone.inventory.GetItemCountEffective(droneUpgradeHidden) + 1;
		CharacterMaster val2 = new MasterSummon
		{
			masterPrefab = MasterCatalog.GetMasterPrefab(drone.masterIndex),
			position = (Vector3)(((??)TeleportHelper.FindSafeTeleportDestination(body2.footPosition, body, RoR2Application.rng)) ?? body2.footPosition),
			rotation = body2.transform.rotation,
			summonerBodyObject = ((Component)body2).gameObject,
			ignoreTeamMemberLimit = true,
			useAmbientLevel = true,
			inventoryToCopy = drone.inventory
		}.Perform();
		if (Object.op_Implicit((Object)(object)val2))
		{
			int num2 = drone.inventory.GetItemCountPermanent(droneUpgradeHidden) - val2.inventory.GetItemCountPermanent(droneUpgradeHidden);
			if (num2 > 0)
			{
				val2.inventory.GiveItemPermanent(droneUpgradeHidden, num2);
			}
			BodyTeleport.SpawnEffect(body, body.corePosition);
			drone.DestroyBody();
			NetworkServer.Destroy(((Component)drone).gameObject);
			CharacterBody body3 = val2.GetBody();
			if (Object.op_Implicit((Object)(object)body3))
			{
				BodyTeleport.SpawnEffect(body3, body3.corePosition);
			}
			string text = Util.GenerateColoredString(Language.GetString(val.nameToken) + ((num > 1) ? (" (T" + num + ")") : ""), ColorCatalog.GetColor(val.color));
			SimpleChatMessage val3 = new SimpleChatMessage();
			val3.baseToken = "<color=#96EBAA>" + PlayerName(giver) + " gave " + text + " to </color>" + PlayerName(target);
			Chat.SendBroadcastChat((ChatMessageBase)(object)val3);
		}
	}

	private static string PlayerName(CharacterMaster master)
	{
		return "<color=#AAE6F0>" + master.playerCharacterMasterController.GetDisplayName() + "</color>";
	}
}
internal sealed class DroneDragSource : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler
{
	private AllyCardController card;

	private HUD hud;

	private RectTransform ghost;

	internal CharacterMaster Drone { get; private set; }

	internal CharacterMaster Giver { get; private set; }

	private void Awake()
	{
		card = ((Component)this).GetComponent<AllyCardController>();
	}

	private void Start()
	{
		Canvas obj = ((Component)this).gameObject.AddComponent<Canvas>();
		obj.overrideSorting = true;
		obj.sortingOrder = obj.rootCanvas.sortingOrder + 1;
		((Component)this).gameObject.AddComponent<GraphicRaycaster>();
	}

	public void OnBeginDrag(PointerEventData eventData)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		hud = ((Component)this).GetComponentInParent<HUD>();
		Drone = card.sourceMaster;
		Giver = (Object.op_Implicit((Object)(object)hud) ? hud.localUserViewer.cachedMaster : null);
		if ((int)eventData.button != 0 || !DroneGiving.CanGive(Drone, Giver))
		{
			eventData.pointerDrag = null;
			return;
		}
		RawImage val = new GameObject("DroneDragGhost").AddComponent<RawImage>();
		val.texture = card.portraitIconImage.texture;
		((Graphic)val).color = new Color(1f, 1f, 1f, 0.6f);
		((Graphic)val).raycastTarget = false;
		ghost = ((Graphic)val).rectTransform;
		((Transform)ghost).SetParent(hud.mainContainer.transform, false);
		((Transform)ghost).SetAsLastSibling();
		RectTransform obj = ghost;
		Rect rect = ((Graphic)card.portraitIconImage).rectTransform.rect;
		obj.sizeDelta = ((Rect)(ref rect)).size;
		OnDrag(eventData);
	}

	public void OnDrag(PointerEventData eventData)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = default(Vector3);
		if (Object.op_Implicit((Object)(object)ghost) && RectTransformUtility.ScreenPointToWorldPointInRectangle((RectTransform)((Transform)ghost).parent, eventData.position, eventData.pressEventCamera, ref position))
		{
			((Transform)ghost).position = position;
		}
	}

	public void OnEndDrag(PointerEventData eventData)
	{
		DestroyGhost();
	}

	private void OnDisable()
	{
		DestroyGhost();
	}

	private void DestroyGhost()
	{
		if (Object.op_Implicit((Object)(object)ghost))
		{
			Object.Destroy((Object)(object)((Component)ghost).gameObject);
		}
	}
}
internal sealed class DroneDropTarget : MonoBehaviour, IDropHandler, IEventSystemHandler
{
	private ScoreboardStrip strip;

	private AllyCardController card;

	private void Awake()
	{
		strip = ((Component)this).GetComponent<ScoreboardStrip>();
		card = ((Component)this).GetComponent<AllyCardController>();
	}

	public void OnDrop(PointerEventData eventData)
	{
		DroneDragSource droneDragSource = (Object.op_Implicit((Object)(object)eventData.pointerDrag) ? eventData.pointerDrag.GetComponent<DroneDragSource>() : null);
		if (Object.op_Implicit((Object)(object)droneDragSource))
		{
			DroneGiving.RequestGive(droneDragSource.Drone, droneDragSource.Giver, Object.op_Implicit((Object)(object)strip) ? strip.master : card.sourceMaster);
		}
	}
}
internal class OnePressSkillDef : SkillDef
{
	public override bool CanExecute(GenericSkill skillSlot)
	{
		if (((SkillDef)this).CanExecute(skillSlot))
		{
			return !PressClaimed(skillSlot);
		}
		return false;
	}

	public override void OnExecute(GenericSkill skillSlot)
	{
		((SkillDef)this).OnExecute(skillSlot);
		InputBankTest inputBank = skillSlot.characterBody.inputBank;
		if (IsUtility(skillSlot))
		{
			inputBank.skill3.hasPressBeenClaimed = true;
		}
		else
		{
			inputBank.skill4.hasPressBeenClaimed = true;
		}
	}

	private static bool PressClaimed(GenericSkill skillSlot)
	{
		//IL_001d: 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)
		InputBankTest inputBank = skillSlot.characterBody.inputBank;
		return (IsUtility(skillSlot) ? inputBank.skill3 : inputBank.skill4).hasPressBeenClaimed;
	}

	private static bool IsUtility(GenericSkill skillSlot)
	{
		return (Object)(object)skillSlot.characterBody.skillLocator.utility == (Object)(object)skillSlot;
	}
}
internal sealed class TeleportSkillDef : OnePressSkillDef
{
	public override bool IsReady(GenericSkill skillSlot)
	{
		if (((SkillDef)this).IsReady(skillSlot))
		{
			return Object.op_Implicit((Object)(object)DroneAbilities.NearestPlayer(skillSlot.characterBody));
		}
		return false;
	}
}
public sealed class DisconnectState : BaseSkillState
{
	private const float ResponseTimeout = 3f;

	private bool requested;

	public override void FixedUpdate()
	{
		((EntityState)this).FixedUpdate();
		if (!((EntityState)this).isAuthority)
		{
			return;
		}
		float holdSeconds = DroneAbilities.HoldSeconds;
		if (requested)
		{
			if (((EntityState)this).fixedAge >= holdSeconds + 3f)
			{
				((EntityState)this).outer.SetNextStateToMain();
			}
			return;
		}
		if (!((BaseSkillState)this).IsKeyDownAuthority())
		{
			((EntityState)this).outer.SetNextStateToMain();
			return;
		}
		float num = ((holdSeconds > 0f) ? Mathf.Clamp01(((EntityState)this).fixedAge / holdSeconds) : 1f);
		((BaseSkillState)this).activatorSkillSlot.rechargeStopwatch = num * (((BaseSkillState)this).activatorSkillSlot.CalculateFinalRechargeInterval() - 0.01f);
		if (((EntityState)this).fixedAge >= holdSeconds)
		{
			requested = true;
			DroneAbilities.RequestDisconnect(((EntityState)this).characterBody);
		}
	}

	public override void OnExit()
	{
		((BaseSkillState)this).activatorSkillSlot.stock = ((BaseSkillState)this).activatorSkillSlot.maxStock;
		((BaseSkillState)this).activatorSkillSlot.rechargeStopwatch = 0f;
		((EntityState)this).OnExit();
	}

	public override InterruptPriority GetMinimumInterruptPriority()
	{
		return (InterruptPriority)0;
	}
}
public sealed class TeleportState : BaseSkillState
{
	public override void OnEnter()
	{
		((BaseState)this).OnEnter();
		if (((EntityState)this).isAuthority)
		{
			DroneAbilities.RequestTeleport(((EntityState)this).characterBody);
		}
	}

	public override void FixedUpdate()
	{
		((EntityState)this).FixedUpdate();
		if (((EntityState)this).isAuthority)
		{
			((EntityState)this).outer.SetNextStateToMain();
		}
	}

	public override InterruptPriority GetMinimumInterruptPriority()
	{
		return (InterruptPriority)0;
	}
}
internal static class SharedDrones
{
	private sealed class LeadMessage : INetMessage, ISerializableObject
	{
		private NetworkInstanceId drone;

		private NetworkInstanceId leader;

		public LeadMessage()
		{
		}

		public LeadMessage(NetworkInstanceId drone, NetworkInstanceId leader)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//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)
			this.drone = drone;
			this.leader = leader;
		}

		public void Serialize(NetworkWriter writer)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			writer.Write(drone);
			writer.Write(leader);
		}

		public void Deserialize(NetworkReader reader)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			drone = reader.ReadNetworkId();
			leader = reader.ReadNetworkId();
		}

		public void OnReceived()
		{
			//IL_0009: 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)
			if (!NetworkServer.active)
			{
				DroneCommandReceiver val = NetworkLookup.Find<DroneCommandReceiver>(drone);
				DroneTechController val2 = NetworkLookup.Find<DroneTechController>(leader);
				if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val2))
				{
					SetLeader(val, val2);
				}
			}
		}
	}

	internal static void InitOperator()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		NetworkingAPI.RegisterMessageType<LeadMessage>();
		DroneTechController.GetAllDrones += new Manipulator(AddPlayerDronesForOperator);
		DroneTechController.OnBodyStartGlobal += new Manipulator(AcceptPlayerDrones);
		DroneTechController.CommandHeadbuttInternal += new hook_CommandHeadbuttInternal(CommandHeadbutt);
		DroneTechController.CommandHeadbuttFollowInternal += new hook_CommandHeadbuttFollowInternal(CommandHeadbuttFollow);
		DroneTechController.CommandFollowInternal += new hook_CommandFollowInternal(CommandFollow);
		Activate.OnEnter += new hook_OnEnter(ActivateEnter);
	}

	internal static void InitEnforcer()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		CrowdControlSlamGround.SummonAlliesServer += new Manipulator(AddPlayerDrones);
	}

	private static void AddPlayerDrones(ILContext il)
	{
		ReplaceMinionBodies(il, WithPlayerDrones);
	}

	private static void AddPlayerDronesForOperator(ILContext il)
	{
		ReplaceMinionBodies(il, (CharacterBody body) => (!SoleOperator(body)) ? body.GetMinionBodies() : WithPlayerDrones(body));
	}

	private static void ReplaceMinionBodies(ILContext il, Func<CharacterBody, CharacterBody[]> minionBodies)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		ILCursor val = new ILCursor(il);
		if (!val.TryGotoNext(new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchCallvirt<CharacterBody>(x, "GetMinionBodies")
		}))
		{
			CoolerMultiplayerPlugin.Log.LogError((object)(((MemberReference)il.Method).Name + " IL hook failed, other players' drones won't be shared."));
			return;
		}
		val.NopNext();
		val.EmitDelegate<Func<CharacterBody, CharacterBody[]>>(minionBodies);
	}

	private static CharacterBody[] WithPlayerDrones(CharacterBody body)
	{
		return body.GetMinionBodies().Union(PlayerDrones()).ToArray();
	}

	private static bool SoleOperator(CharacterBody body)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		foreach (NetworkUser readOnlyInstances in NetworkUser.readOnlyInstancesList)
		{
			if (readOnlyInstances.bodyIndexPreference == body.bodyIndex)
			{
				num++;
			}
		}
		return num == 1;
	}

	private static void AcceptPlayerDrones(ILContext il)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchCallvirt<CharacterBody>(x, "GetOwnerBody")
		}))
		{
			CoolerMultiplayerPlugin.Log.LogError((object)(((MemberReference)il.Method).Name + " IL hook failed, new drones from other players won't be shared."));
			return;
		}
		val.Emit(OpCodes.Ldarg_1);
		val.Emit(OpCodes.Ldarg_0);
		val.EmitDelegate<Func<CharacterBody, CharacterBody, DroneTechController, CharacterBody>>((Func<CharacterBody, CharacterBody, DroneTechController, CharacterBody>)((CharacterBody owner, CharacterBody drone, DroneTechController controller) => (!SoleOperator(controller.characterBody) || !OwnedByPlayer(drone)) ? owner : controller.characterBody));
	}

	private static IEnumerable<CharacterBody> PlayerDrones()
	{
		return CharacterBody.readOnlyInstancesList.Where((CharacterBody body) => (int)DroneCatalog.GetDroneIndexFromBodyIndex(body.bodyIndex) != -1 && OwnedByPlayer(body));
	}

	private static bool OwnedByPlayer(CharacterBody body)
	{
		CharacterMaster val = (Object.op_Implicit((Object)(object)body.master) ? body.master.minionOwnership.ownerMaster : null);
		if (Object.op_Implicit((Object)(object)val))
		{
			return Object.op_Implicit((Object)(object)val.playerCharacterMasterController);
		}
		return false;
	}

	private static void Lead(DroneTechController controller, GameObject drone)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		DroneCommandReceiver val = default(DroneCommandReceiver);
		if (Object.op_Implicit((Object)(object)drone) && drone.TryGetComponent<DroneCommandReceiver>(ref val) && !((Object)(object)val.leaderBody == (Object)(object)controller.characterBody))
		{
			SetLeader(val, controller);
			NetMessageExtensions.Send((INetMessage)(object)new LeadMessage(((NetworkBehaviour)val).netId, ((NetworkBehaviour)controller).netId), (NetworkDestination)1);
		}
	}

	private static void SetLeader(DroneCommandReceiver receiver, DroneTechController controller)
	{
		receiver.leaderBody = controller.characterBody;
		receiver.leaderController = controller;
	}

	private static void CommandHeadbutt(orig_CommandHeadbuttInternal orig, DroneTechController self, GameObject droneBody, HurtBoxReference hurtBox, Vector3 position)
	{
		//IL_000a: 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)
		Lead(self, droneBody);
		orig.Invoke(self, droneBody, hurtBox, position);
	}

	private static void CommandHeadbuttFollow(orig_CommandHeadbuttFollowInternal orig, DroneTechController self, GameObject droneBody)
	{
		Lead(self, droneBody);
		orig.Invoke(self, droneBody);
	}

	private static void CommandFollow(orig_CommandFollowInternal orig, DroneTechController self, bool shouldFollow, GameObject droneBody)
	{
		Lead(self, droneBody);
		orig.Invoke(self, shouldFollow, droneBody);
	}

	private static void ActivateEnter(orig_OnEnter orig, Activate self)
	{
		orig.Invoke(self);
		if (self.drone.hasAuthority)
		{
			Lead(self.droneController, ((Component)self.drone.characterBody).gameObject);
		}
	}
}
internal static class HUDdleUPCompat
{
	internal const string PluginGuid = "itsschwer.HUDdleUP";

	internal static bool Loaded => Chainloader.PluginInfos.ContainsKey("itsschwer.HUDdleUP");

	internal static void Init()
	{
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		//IL_007c: 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_0056: Expected O, but got Unknown
		if (Find("HUDdleUP.Plugin", "get_Config") != null && Find("HUDdleUP.Config", "get_FullerItemDescriptions") != null && Find("HUDdleUP.Patches.FullerDescriptions", "GetCombinedDescription") != null)
		{
			ItemIcon.SetItemIndex_SetItemIndexArgs += new hook_SetItemIndex_SetItemIndexArgs(SetItemIndex);
		}
		MethodInfo methodInfo = Find("HUDdleUP.Behaviours.EquipmentCooldownPanel", "Update");
		if (methodInfo != null)
		{
			new ILHook((MethodBase)methodInfo, new Manipulator(CooldownTracksShownEquipment));
		}
	}

	private static MethodInfo Find(string type, string method)
	{
		return Type.GetType(type + ", HUDdleUP")?.GetMethod(method, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	private static void SetItemIndex(orig_SetItemIndex_SetItemIndexArgs orig, ItemIcon self, SetItemIndexArgs args)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		orig.Invoke(self, args);
		if (Plugin.Config.FullerItemDescriptions && Object.op_Implicit((Object)(object)self.tooltipProvider))
		{
			ItemDef itemDef = ItemCatalog.GetItemDef(self.itemIndex);
			if (Object.op_Implicit((Object)(object)itemDef))
			{
				self.tooltipProvider.overrideBodyText = FullerDescriptions.GetCombinedDescription(itemDef.descriptionToken, itemDef.pickupToken);
			}
		}
	}

	private static void CooldownTracksShownEquipment(ILContext il)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		ILCursor val = new ILCursor(il);
		if (val.TryGotoNext(new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Inventory>(x, "get_alternateEquipmentState")
		}))
		{
			val.NopNext();
			val.EmitDelegate<Func<Inventory, EquipmentState>>((Func<Inventory, EquipmentState>)AlternateEquipmentState);
		}
	}

	private static EquipmentState AlternateEquipmentState(Inventory inventory)
	{
		//IL_000a: 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_001a: Unknown result type (might be due to invalid IL or missing references)
		if (inventory.accessibleEquipmentSetCount > 1)
		{
			return inventory.nextSetEquipmentState;
		}
		if (inventory.equipmentSlotCount > 1)
		{
			return inventory.nextSlotEquipmentState;
		}
		return EquipmentState.empty;
	}
}
internal static class ILCursorExtensions
{
	internal static void NopNext(this ILCursor c)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		c.Next.OpCode = OpCodes.Nop;
		c.Next.Operand = null;
		int index = c.Index;
		c.Index = index + 1;
	}
}
internal static class MithrixArena
{
	private const float AlreadyThereSqr = 400f;

	private static MultiBodyTrigger firedTrigger;

	private static readonly HashSet<Object> logged = new HashSet<Object>();

	private static bool OnCommencement
	{
		get
		{
			if (Object.op_Implicit((Object)(object)SceneCatalog.mostRecentSceneDef))
			{
				return SceneCatalog.mostRecentSceneDef.cachedName == "moon2";
			}
			return false;
		}
	}

	internal static void Init()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		MultiBodyTrigger.SetEncounteredBodies += new hook_SetEncounteredBodies(SetEncounteredBodies);
		MultiBodyTrigger.KillAllOutsideWithVoidDeath += new hook_KillAllOutsideWithVoidDeath(KillAllOutsideWithVoidDeath);
		AllPlayersTrigger.FixedUpdate += new Manipulator(AllPlayersTriggerNeedsOne);
		PreEncounter.onEnter += OnPreEncounter;
	}

	private static bool IsArenaTrigger(MultiBodyTrigger trigger)
	{
		if (trigger.playerControlledOnly && ((UnityEventBase)trigger.onAllQualifyingBodiesEnter).GetPersistentEventCount() > 0)
		{
			return OnCommencement;
		}
		return false;
	}

	private static void SetEncounteredBodies(orig_SetEncounteredBodies orig, MultiBodyTrigger self, List<CharacterBody> newEncounteredBodies, int candidateCount)
	{
		bool flag = NetworkServer.active && IsArenaTrigger(self);
		orig.Invoke(self, newEncounteredBodies, flag ? Math.Min(candidateCount, 1) : candidateCount);
		if (flag && self.allCandidatesPreviouslyTriggering)
		{
			firedTrigger = self;
			LogStart((Object)(object)self);
		}
	}

	private static void AllPlayersTriggerNeedsOne(ILContext il)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		int countLocal = -1;
		if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref countLocal),
			(Instruction x) => ILPatternMatchingExt.MatchCall<Run>(x, "get_instance"),
			(Instruction x) => ILPatternMatchingExt.MatchCallvirt<Run>(x, "get_livingPlayerCount")
		}))
		{
			CoolerMultiplayerPlugin.Log.LogError((object)(((MemberReference)il.Method).Name + " IL hook failed, AllPlayersTrigger arenas still need every player."));
			return;
		}
		val.Emit(OpCodes.Ldloc, il.Body.Variables[countLocal]);
		val.Emit(OpCodes.Ldarg_0);
		val.EmitDelegate<Func<int, int, AllPlayersTrigger, int>>((Func<int, int, AllPlayersTrigger, int>)delegate(int livingPlayers, int playersInside, AllPlayersTrigger trigger)
		{
			if (playersInside == 0 || !NetworkServer.active || !OnCommencement || ((UnityEventBase)trigger.onTriggerStart).GetPersistentEventCount() == 0)
			{
				return livingPlayers;
			}
			if (!trigger.triggerActiveServer)
			{
				LogStart((Object)(object)trigger);
			}
			return playersInside;
		});
	}

	private static void OnPreEncounter()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: 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)
		if (!NetworkServer.active || !OnCommencement)
		{
			return;
		}
		List<CharacterBody> list = (Object.op_Implicit((Object)(object)firedTrigger) ? firedTrigger.encounteredBodies : null);
		CharacterBody val = PickAnchor(list);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		foreach (CharacterBody item in LivingPlayers())
		{
			bool num;
			if (list == null)
			{
				Vector3 val2 = item.corePosition - val.corePosition;
				num = ((Vector3)(ref val2)).sqrMagnitude < 400f;
			}
			else
			{
				num = list.Contains(item);
			}
			bool flag = num;
			if ((Object)(object)item != (Object)(object)val && !flag)
			{
				BodyTeleport.Teleport(item, val, groupTeleport: true);
			}
		}
	}

	private static void KillAllOutsideWithVoidDeath(orig_KillAllOutsideWithVoidDeath orig, MultiBodyTrigger self)
	{
		if (NetworkServer.active && OnCommencement)
		{
			List<CharacterBody> encounteredBodies = self.encounteredBodies;
			CharacterBody val = PickAnchor(encounteredBodies);
			foreach (CharacterBody item in LivingPlayers())
			{
				if (!encounteredBodies.Contains(item))
				{
					encounteredBodies.Add(item);
					if (Object.op_Implicit((Object)(object)val) && (Object)(object)val != (Object)(object)item)
					{
						BodyTeleport.Teleport(item, val, groupTeleport: true);
					}
				}
			}
		}
		orig.Invoke(self);
	}

	private static CharacterBody PickAnchor(List<CharacterBody> inside)
	{
		ChildLocator val = (Object.op_Implicit((Object)(object)SceneInfo.instance) ? ((Component)SceneInfo.instance).GetComponent<ChildLocator>() : null);
		Transform val2 = (Object.op_Implicit((Object)(object)val) ? val.FindChild("CenterOfArena") : null);
		CharacterBody val3 = Closest(inside, val2);
		if (!Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val2))
		{
			return Closest(LivingPlayers(), val2);
		}
		return val3;
	}

	private static CharacterBody Closest(IEnumerable<CharacterBody> bodies, Transform center)
	{
		//IL_0048: 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_0053: 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)
		if (bodies == null)
		{
			return null;
		}
		CharacterBody result = null;
		float num = float.PositiveInfinity;
		foreach (CharacterBody body in bodies)
		{
			if (Object.op_Implicit((Object)(object)body) && body.isPlayerControlled && body.healthComponent.alive)
			{
				if (!Object.op_Implicit((Object)(object)center))
				{
					return body;
				}
				Vector3 val = body.corePosition - center.position;
				float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
				if (sqrMagnitude < num)
				{
					num = sqrMagnitude;
					result = body;
				}
			}
		}
		return result;
	}

	private static IEnumerable<CharacterBody> LivingPlayers()
	{
		ReadOnlyCollection<PlayerCharacterMasterController> players = PlayerCharacterMasterController.instances;
		for (int i = 0; i < players.Count; i++)
		{
			CharacterBody val = (Object.op_Implicit((Object)(object)players[i].master) ? players[i].master.GetBody() : null);
			if (Object.op_Implicit((Object)(object)val) && val.healthComponent.alive)
			{
				yield return val;
			}
		}
	}

	private static void LogStart(Object trigger)
	{
		if (logged.Add(trigger))
		{
			CoolerMultiplayerPlugin.Log.LogInfo((object)("Mithrix arena: fight started by one player via '" + trigger.name + "'."));
		}
	}
}
internal static class NetworkLookup
{
	internal static T Find<T>(NetworkInstanceId id) where T : Component
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Util.FindNetworkObject(id);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return default(T);
		}
		return val.GetComponent<T>();
	}

	internal static CharacterMaster MasterOf(Interactor activator)
	{
		CharacterBody val = (Object.op_Implicit((Object)(object)activator) ? ((Component)activator).GetComponent<CharacterBody>() : null);
		if (!Object.op_Implicit((Object)(object)val))
		{
			return null;
		}
		return val.master;
	}
}