Decompiled source of ServerSideTweaks v2.2.2

ServerSideTweaks.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.InfiniteTowerSafeWard;
using HG.Reflection;
using IL.EntityStates.ChildMonster;
using IL.RoR2;
using InLobbyConfig;
using InLobbyConfig.Fields;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using On.EntityStates.InfiniteTowerSafeWard;
using On.RoR2;
using On.RoR2.Artifacts;
using On.RoR2.Items;
using ProperSave;
using RoR2;
using RoR2.Navigation;
using ShareSuite;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ServerSideTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9ddc3c571d238e773a452ea9236a778ffc02579a")]
[assembly: AssemblyProduct("ServerSideTweaks")]
[assembly: AssemblyTitle("ServerSideTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ServerSideTweaks
{
	public class BepConfig
	{
		public static ConfigEntry<float> PearlReplacesLunarItemChance;

		public static ConfigEntry<float> IrradiantPearlReplacesLunarItemChance;

		public static ConfigEntry<bool> NoPearlsInBazaar;

		public static ConfigEntry<bool> ChildReducedTeleportRange;

		public static ConfigEntry<bool> ChildRemoveInvincibility;

		public static ConfigEntry<bool> VoidJailerNoCooldownReductions;

		public static ConfigEntry<bool> SolusInvalidatorNoCooldownReductions;

		public static ConfigEntry<bool> VoidlingNoCooldownReductions;

		public static ConfigEntry<float> MonsterGoldMultiplier;

		public static ConfigEntry<bool> SimulacrumNonSharedLoot;

		public static ConfigEntry<int> SimulacrumLootMaxItemDebt;

		public static ConfigEntry<bool> SimulacrumLootSkullTokens;

		public static ConfigEntry<float> SimulacrumCommencementArtifactDissonanceChance;

		public static ConfigEntry<float> SimulacrumDirectorEnemyPowerBias;

		public static ConfigEntry<int> SimulacrumMaxSquadSize;

		public static ConfigEntry<float> SimulacrumWavePeriodSecondsFactor;

		public static ConfigEntry<bool> SimulacrumFastVoidCrab;

		public static ConfigEntry<float> SimulacrumEmptyWaveDirectorSpeedup;

		public static ConfigEntry<bool> SimulacrumCaptainBeaconsAfterBossWave;

		public static ConfigEntry<bool> SimulacrumAllowDrones;

		public static ConfigEntry<float> ClassicDirectorEnemyPowerBias;

		public static ConfigEntry<bool> Enabled { get; set; }

		public static void Init()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Expected O, but got Unknown
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Expected O, but got Unknown
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Expected O, but got Unknown
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Expected O, but got Unknown
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Expected O, but got Unknown
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Expected O, but got Unknown
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Expected O, but got Unknown
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Expected O, but got Unknown
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Expected O, but got Unknown
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Expected O, but got Unknown
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Expected O, but got Unknown
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Expected O, but got Unknown
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Expected O, but got Unknown
			ConfigFile config = ((BaseUnityPlugin)ServerSideTweaks.instance).Config;
			Enabled = config.Bind<bool>("Main", "Enabled", true, "Enable Mod");
			PearlReplacesLunarItemChance = config.Bind<float>("Main", "Pearl replaces Lunar Item chance", 0.1f, new ConfigDescription("Adds a chance for lunar items to be replaced by a pearl.", (AcceptableValueBase)null, Array.Empty<object>()));
			IrradiantPearlReplacesLunarItemChance = config.Bind<float>("Main", "Irradiant Pearl replaces Lunar Item chance", 0.02f, new ConfigDescription("Adds a chance for lunar items to be replaced by an irradiant pearl.", (AcceptableValueBase)null, Array.Empty<object>()));
			NoPearlsInBazaar = config.Bind<bool>("Main", "No Pearl replacements in the Bazaar between Times", true, new ConfigDescription("Prevents pearls from appearing in the Bazaar to prevent hoarding.", (AcceptableValueBase)null, Array.Empty<object>()));
			ChildReducedTeleportRange = config.Bind<bool>("Main", "Child: Reduced teleport range", true, new ConfigDescription("Reduces the range children can teleport away.", (AcceptableValueBase)null, Array.Empty<object>()));
			ChildRemoveInvincibility = config.Bind<bool>("Main", "Child: Remove invincibility", true, new ConfigDescription("Removes the invincibility buff that children get before teleporting.", (AcceptableValueBase)null, Array.Empty<object>()));
			VoidJailerNoCooldownReductions = config.Bind<bool>("Main", "Void Jailer: No cooldown reductions", true, new ConfigDescription("Prevents Void Jailer from getting its cooldown reduced by items like Alien Head for balancing purposes.", (AcceptableValueBase)null, Array.Empty<object>()));
			SolusInvalidatorNoCooldownReductions = config.Bind<bool>("Main", "Solus Invalidator: No cooldown reductions", true, new ConfigDescription("Prevents Solus Invalidator from getting its cooldown reduced by items like Alien Head for balancing purposes.", (AcceptableValueBase)null, Array.Empty<object>()));
			VoidlingNoCooldownReductions = config.Bind<bool>("Main", "Voidling: No cooldown reductions", true, new ConfigDescription("Prevents Voidling from getting its cooldown reduced by items like Alien Head for balancing purposes.", (AcceptableValueBase)null, Array.Empty<object>()));
			MonsterGoldMultiplier = config.Bind<float>("Main", "Monster gold multiplier", 1f, new ConfigDescription("Multiplies the gold monsters give when killed. A value smaller than 1.0 gives less gold. (1.0 = vanilla).", (AcceptableValueBase)null, Array.Empty<object>()));
			SimulacrumNonSharedLoot = config.Bind<bool>("Simulacrum", "Non-shared loot", false, new ConfigDescription("(ShareSuite only) Forces the loot dropped at the end of each wave to be non-shared.", (AcceptableValueBase)null, Array.Empty<object>()));
			SimulacrumLootMaxItemDebt = config.Bind<int>("Simulacrum", "Max loot debt", 2, new ConfigDescription("Prevents greedy players from taking too much of the loot dropped at the end of each wave.", (AcceptableValueBase)null, Array.Empty<object>()));
			SimulacrumLootSkullTokens = config.Bind<bool>("Simulacrum", "Max loot debt - Skull Tokens", true, new ConfigDescription("Indicate to players how many void potentials they can take by assigning Skull Tokens.", (AcceptableValueBase)null, Array.Empty<object>()));
			SimulacrumCommencementArtifactDissonanceChance = config.Bind<float>("Simulacrum", "Commencement Artifact of Dissonance Chance", 0.5f, new ConfigDescription("The chance for Artifact of Dissonance to be activated each wave when in the commencement stage to increase enemy variety.", (AcceptableValueBase)null, Array.Empty<object>()));
			SimulacrumDirectorEnemyPowerBias = config.Bind<float>("Simulacrum", "Director: Enemy Power Bias", 0.5f, new ConfigDescription("Bias towards many,weak enemies (=0) or few,strong enemies (=1). Value between 0 and 1, 0.5 = vanilla.", (AcceptableValueBase)null, Array.Empty<object>()));
			SimulacrumMaxSquadSize = config.Bind<int>("Simulacrum", "Max squad size", 30, new ConfigDescription("No more than this many enemies shall be spawned at the same time (30 = vanilla).", (AcceptableValueBase)null, Array.Empty<object>()));
			SimulacrumWavePeriodSecondsFactor = config.Bind<float>("Simulacrum", "Wave Period Seconds Factor", 1f, new ConfigDescription("A factor on how long each wave takes. A value smaller than 1.0 makes the wave go faster, but also with stronger enemies. A value higher than 1.0 makes the wave take longer but the enemies are weaker. (1.0 = vanilla).", (AcceptableValueBase)null, Array.Empty<object>()));
			SimulacrumFastVoidCrab = config.Bind<bool>("Simulacrum", "Void Crab picks up speed", false, new ConfigDescription("Makes the Void Crab faster the more waves you complete.", (AcceptableValueBase)null, Array.Empty<object>()));
			SimulacrumEmptyWaveDirectorSpeedup = config.Bind<float>("Simulacrum", "Director: Speed-up without enemies", 3f, new ConfigDescription("While no enemy of the wave is alive, the director earns its credits this many times faster, so the next enemies come sooner. (1.0 = vanilla).", (AcceptableValueBase)null, Array.Empty<object>()));
			SimulacrumCaptainBeaconsAfterBossWave = config.Bind<bool>("Simulacrum", "Captain: Beacons after boss waves", true, new ConfigDescription("Gives Captains their beacons back after each boss wave. A Captain who used a beacon is respawned in place, since only a new body gets them back, which also restores their health.", (AcceptableValueBase)null, Array.Empty<object>()));
			SimulacrumAllowDrones = config.Bind<bool>("Simulacrum", "Allow drones", false, new ConfigDescription("Lets broken drones appear on Simulacrum's stages, as on normal stages, to repair with gold.", (AcceptableValueBase)null, Array.Empty<object>()));
			ClassicDirectorEnemyPowerBias = config.Bind<float>("Classic", "Director: Enemy Power Bias", 0.5f, new ConfigDescription("Bias towards many,weak enemies (=0) or few,strong enemies (=1). Value between 0 and 1, 0.5 = vanilla.", (AcceptableValueBase)null, Array.Empty<object>()));
			if (ModCompatibilityInLobbyConfig.enabled)
			{
				ModCompatibilityInLobbyConfig.CreateFromBepInExConfigFile(config, "Server-Side Tweaks");
			}
		}
	}
	public static class ChatHelper
	{
		private const string RedColor = "ff0000";

		private const string GreenColor = "32cd32";

		private const string SilverColor = "c0c0c0";

		public static void PlayerHasTooManyItems(string userName)
		{
			//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)
			//IL_0022: Expected O, but got Unknown
			string baseToken = "<color=#ff0000>" + userName + " is being greedy!</color>";
			Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
			{
				baseToken = baseToken
			});
		}
	}
	public class FastSimulacrumVrab
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_OnEnter <0>__Travelling_OnEnter;
		}

		public static void Setup()
		{
		}

		public static void Enable()
		{
			//IL_0010: 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_001b: Expected O, but got Unknown
			object obj = <>O.<0>__Travelling_OnEnter;
			if (obj == null)
			{
				hook_OnEnter val = Travelling_OnEnter;
				<>O.<0>__Travelling_OnEnter = val;
				obj = (object)val;
			}
			Travelling.OnEnter += (hook_OnEnter)obj;
		}

		public static void Disable()
		{
			//IL_0010: 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_001b: Expected O, but got Unknown
			object obj = <>O.<0>__Travelling_OnEnter;
			if (obj == null)
			{
				hook_OnEnter val = Travelling_OnEnter;
				<>O.<0>__Travelling_OnEnter = val;
				obj = (object)val;
			}
			Travelling.OnEnter -= (hook_OnEnter)obj;
		}

		private static void Travelling_OnEnter(orig_OnEnter orig, Travelling self)
		{
			//IL_007f: 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_0053: Expected O, but got Unknown
			orig.Invoke(self);
			if (BepConfig.Enabled.Value && BepConfig.SimulacrumFastVoidCrab.Value)
			{
				if ((Object)(object)Run.instance != (Object)null && ((object)Run.instance).GetType() == typeof(InfiniteTowerRun))
				{
					InfiniteTowerRun val = (InfiniteTowerRun)Run.instance;
					self.travelSpeed = 5f + (float)val.waveIndex * 0.1f;
				}
				if (NetworkServer.active)
				{
					List<NodeIndex> list = self.groundNodeGraph.FindNodesInRangeWithFlagConditions(((EntityState)self).transform.position, self.minDistanceToNewLocation, 500f, (HullMask)1, (NodeFlags)2, (NodeFlags)0, false);
					Util.ShuffleList<NodeIndex>(list, self.rng);
					self.potentialEndNodes.AddRange(list);
				}
			}
		}
	}
	internal static class Log
	{
		internal static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void LogDebug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void LogError(object data)
		{
			_logSource.LogError(data);
		}

		internal static void LogFatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void LogInfo(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void LogMessage(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void LogWarning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	public static class ModCompatibilityInLobbyConfig
	{
		private static bool? _enabled;

		public static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("com.KingEnderBrine.InLobbyConfig");
				}
				return _enabled.Value;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void CreateFromBepInExConfigFile(ConfigFile config, string displayName)
		{
			ModConfigCatalog.Add(ConfigFieldUtilities.CreateFromBepInExConfigFile(config, displayName));
		}
	}
	public static class ModCompatibilityProperSave
	{
		private class SaveDataHandler
		{
			public string key;

			public Func<object> save;

			public Action<object> load;

			public void GatherSaveData(Dictionary<string, object> data)
			{
				data[key] = save();
			}

			public void OnLoadingEnded(object saveFile)
			{
				if (saveFile != null)
				{
					object moddedData;
					try
					{
						moddedData = GetModdedData(saveFile);
					}
					catch (KeyNotFoundException)
					{
						return;
					}
					load(moddedData);
				}
			}

			[MethodImpl(MethodImplOptions.NoInlining)]
			private object GetModdedData(object saveFile)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return ((SaveFile)saveFile).GetModdedData<object>(key);
			}
		}

		private static bool? _enabled;

		public static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("com.KingEnderBrine.ProperSave");
				}
				return _enabled.Value;
			}
		}

		public static void Register(string key, Func<object> save, Action<object> load)
		{
			if (!enabled)
			{
				return;
			}
			try
			{
				RegisterWithProperSave(key, save, load);
			}
			catch (Exception ex)
			{
				Log.LogWarning("Could not register " + key + " with ProperSave - " + ex.Message);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		private static void RegisterWithProperSave(string key, Func<object> save, Action<object> load)
		{
			SaveDataHandler saveDataHandler = new SaveDataHandler
			{
				key = key,
				save = save,
				load = load
			};
			SaveFile.OnGatherSaveData += saveDataHandler.GatherSaveData;
			Loading.OnLoadingEnded += (Action<SaveFile>)Delegate.CreateDelegate(typeof(Action<SaveFile>), saveDataHandler, typeof(SaveDataHandler).GetMethod("OnLoadingEnded"));
		}
	}
	public static class ModCompatibilityShareSuite
	{
		private static bool? _enabled;

		public static bool enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("com.funkfrog_sipondo.sharesuite");
				}
				return _enabled.Value;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddPickupEventHandler(Func<GenericPickupController, CharacterBody, bool> f)
		{
			ItemSharingHooks.AdditionalPickupValidityChecks += f;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void RemovePickupEventHandler(Func<GenericPickupController, CharacterBody, bool> f)
		{
			ItemSharingHooks.AdditionalPickupValidityChecks -= f;
		}
	}
	public class NonShareableItem : MonoBehaviour
	{
	}
	[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.*/)]
	[BepInPlugin("Def.ServerSideTweaks", "ServerSideTweaks", "2.2.2")]
	public class ServerSideTweaks : BaseUnityPlugin
	{
		private class BiasedSelection
		{
			public float powerBias;

			public float signature;

			public WeightedSelection<DirectorCard> selection;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static hook_Awake <0>__CombatDirector_Awake;
		}

		public static ServerSideTweaks instance;

		public static float directorEnemyPowerBiasOverride = -1f;

		public static List<EquipmentIndex> disableEquipments = new List<EquipmentIndex>();

		public static List<PickupIndex> availableEquipmentDropList_Saved = new List<PickupIndex>();

		public static List<PickupIndex> availableLunarItemDropList_Saved = new List<PickupIndex>();

		public static List<PickupIndex> availableLunarEquipmentDropList_Saved = new List<PickupIndex>();

		public static SimulacrumLootTweaks simulacrumLootTweaks = new SimulacrumLootTweaks();

		private static bool dissonanceEnabledForWave = false;

		public const string PluginGUID = "Def.ServerSideTweaks";

		public const string PluginAuthor = "Def";

		public const string PluginName = "ServerSideTweaks";

		public const string PluginVersion = "2.2.2";

		private const float SimulacrumDronesWeight = 14f;

		private const float PowerBiasExponent = 4f;

		private static readonly ConditionalWeakTable<WeightedSelection<DirectorCard>, BiasedSelection> biasedSelections = new ConditionalWeakTable<WeightedSelection<DirectorCard>, BiasedSelection>();

		private static Hook finalMonsterCardsSelectionHook;

		private const int MaxConsecutiveCheapSkips = 4;

		public static PluginInfo PInfo { get; private set; }

		public void Awake()
		{
			PInfo = ((BaseUnityPlugin)this).Info;
			instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			BepConfig.Init();
			BepConfig.ChildReducedTeleportRange.SettingChanged += ChildReducedTeleportRange_SettingChanged;
			ChildReducedTeleportRange_SettingChanged(null, null);
			FastSimulacrumVrab.Setup();
			simulacrumLootTweaks.RegisterSaveData();
		}

		private void ChildReducedTeleportRange_SettingChanged(object sender, EventArgs e)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (BepConfig.ChildReducedTeleportRange.Value)
			{
				FrolicAway.TeleportAway += new Manipulator(FrolicAway_TeleportAway);
			}
			else
			{
				FrolicAway.TeleportAway -= new Manipulator(FrolicAway_TeleportAway);
			}
		}

		private void OnEnable()
		{
			//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
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			Run.Start += new hook_Start(Run_Start);
			InfiniteTowerRun.OnWaveAllEnemiesDefeatedServer += new hook_OnWaveAllEnemiesDefeatedServer(InfiniteTowerRun_OnWaveAllEnemiesDefeatedServer);
			InfiniteTowerRun.AdvanceWave += new hook_AdvanceWave(InfiniteTowerRun_AdvanceWave);
			finalMonsterCardsSelectionHook = new Hook((MethodBase)typeof(CombatDirector).GetProperty("finalMonsterCardsSelection", BindingFlags.Instance | BindingFlags.NonPublic).GetGetMethod(nonPublic: true), typeof(ServerSideTweaks).GetMethod("CombatDirector_get_finalMonsterCardsSelection", BindingFlags.Static | BindingFlags.NonPublic));
			object obj = <>O.<0>__CombatDirector_Awake;
			if (obj == null)
			{
				hook_Awake val = CombatDirector_Awake;
				<>O.<0>__CombatDirector_Awake = val;
				obj = (object)val;
			}
			CombatDirector.Awake += (hook_Awake)obj;
			RandomlyLunarUtils.CheckForLunarReplacementUniqueArray += new hook_CheckForLunarReplacementUniqueArray(RandomlyLunarUtils_CheckForLunarReplacementUniqueArray);
			RandomlyLunarUtils.CheckForLunarReplacement_UniquePickup_Xoroshiro128Plus += new hook_CheckForLunarReplacement_UniquePickup_Xoroshiro128Plus(RandomlyLunarUtils_CheckForLunarReplacement_UniquePickup_Xoroshiro128Plus);
			InfiniteTowerWaveController.Initialize += new hook_Initialize(InfiniteTowerWaveController_Initialize);
			InfiniteTowerWaveController.FixedUpdate += new hook_FixedUpdate(InfiniteTowerWaveController_FixedUpdate);
			InfiniteTowerWaveController.OnAllEnemiesDefeatedServer += new hook_OnAllEnemiesDefeatedServer(InfiniteTowerWaveController_OnAllEnemiesDefeatedServer);
			SceneDirector.GenerateInteractableCardSelection += new hook_GenerateInteractableCardSelection(SceneDirector_GenerateInteractableCardSelection);
			ChildMonsterController.RegisterTeleport += new hook_RegisterTeleport(ChildMonsterController_RegisterTeleport);
			MonsterTeamGainsItemsArtifactManager.OnServerCardSpawnedGlobal += new hook_OnServerCardSpawnedGlobal(MonsterTeamGainsItemsArtifactManager_OnServerCardSpawnedGlobal);
			InfiniteTowerWaveController.OnCombatSquadMemberDiscovered += new hook_OnCombatSquadMemberDiscovered(InfiniteTowerWaveController_OnCombatSquadMemberDiscovered);
			DeathRewards.OnKilledServer += new hook_OnKilledServer(DeathRewards_OnKilledServer);
			simulacrumLootTweaks.Hook();
			FastSimulacrumVrab.Enable();
		}

		private void MonsterTeamGainsItemsArtifactManager_OnServerCardSpawnedGlobal(orig_OnServerCardSpawnedGlobal orig, SpawnResult spawnResult)
		{
			//IL_0001: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(spawnResult);
			RemoveAlienHeads(Object.op_Implicit((Object)(object)spawnResult.spawnedInstance) ? spawnResult.spawnedInstance.GetComponent<CharacterMaster>() : null);
		}

		private void InfiniteTowerWaveController_OnCombatSquadMemberDiscovered(orig_OnCombatSquadMemberDiscovered orig, InfiniteTowerWaveController self, CharacterMaster master)
		{
			orig.Invoke(self, master);
			if (NetworkServer.active)
			{
				RemoveAlienHeads(master);
			}
		}

		private static void RemoveAlienHeads(CharacterMaster characterMaster)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Invalid comparison between Unknown and I4
			if (BepConfig.Enabled.Value && (BepConfig.VoidJailerNoCooldownReductions.Value || BepConfig.SolusInvalidatorNoCooldownReductions.Value || BepConfig.VoidlingNoCooldownReductions.Value) && Object.op_Implicit((Object)(object)characterMaster) && (int)characterMaster.teamIndex == 2 && (Object)(object)characterMaster.bodyPrefab != (Object)null)
			{
				string name = ((Object)characterMaster.bodyPrefab).name;
				if (name == "VoidJailerBody" && BepConfig.VoidJailerNoCooldownReductions.Value)
				{
					characterMaster.inventory.RemoveItemPermanent(Items.AlienHead, 10000);
				}
				if (name == "DefectiveUnitBody" && BepConfig.SolusInvalidatorNoCooldownReductions.Value)
				{
					characterMaster.inventory.RemoveItemPermanent(Items.AlienHead, 10000);
				}
				if ((name == "VoidRaidCrabBody" || name.StartsWith("MiniVoidRaidCrabBodyPhase")) && BepConfig.VoidlingNoCooldownReductions.Value)
				{
					characterMaster.inventory.RemoveItemPermanent(Items.AlienHead, 10000);
				}
			}
		}

		private void OnDisable()
		{
			//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
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			Run.Start -= new hook_Start(Run_Start);
			InfiniteTowerRun.OnWaveAllEnemiesDefeatedServer -= new hook_OnWaveAllEnemiesDefeatedServer(InfiniteTowerRun_OnWaveAllEnemiesDefeatedServer);
			InfiniteTowerRun.AdvanceWave -= new hook_AdvanceWave(InfiniteTowerRun_AdvanceWave);
			Hook obj = finalMonsterCardsSelectionHook;
			if (obj != null)
			{
				obj.Dispose();
			}
			finalMonsterCardsSelectionHook = null;
			object obj2 = <>O.<0>__CombatDirector_Awake;
			if (obj2 == null)
			{
				hook_Awake val = CombatDirector_Awake;
				<>O.<0>__CombatDirector_Awake = val;
				obj2 = (object)val;
			}
			CombatDirector.Awake -= (hook_Awake)obj2;
			RandomlyLunarUtils.CheckForLunarReplacement_UniquePickup_Xoroshiro128Plus -= new hook_CheckForLunarReplacement_UniquePickup_Xoroshiro128Plus(RandomlyLunarUtils_CheckForLunarReplacement_UniquePickup_Xoroshiro128Plus);
			RandomlyLunarUtils.CheckForLunarReplacementUniqueArray -= new hook_CheckForLunarReplacementUniqueArray(RandomlyLunarUtils_CheckForLunarReplacementUniqueArray);
			InfiniteTowerWaveController.Initialize -= new hook_Initialize(InfiniteTowerWaveController_Initialize);
			InfiniteTowerWaveController.FixedUpdate -= new hook_FixedUpdate(InfiniteTowerWaveController_FixedUpdate);
			InfiniteTowerWaveController.OnAllEnemiesDefeatedServer -= new hook_OnAllEnemiesDefeatedServer(InfiniteTowerWaveController_OnAllEnemiesDefeatedServer);
			SceneDirector.GenerateInteractableCardSelection -= new hook_GenerateInteractableCardSelection(SceneDirector_GenerateInteractableCardSelection);
			ChildMonsterController.RegisterTeleport -= new hook_RegisterTeleport(ChildMonsterController_RegisterTeleport);
			MonsterTeamGainsItemsArtifactManager.OnServerCardSpawnedGlobal -= new hook_OnServerCardSpawnedGlobal(MonsterTeamGainsItemsArtifactManager_OnServerCardSpawnedGlobal);
			InfiniteTowerWaveController.OnCombatSquadMemberDiscovered -= new hook_OnCombatSquadMemberDiscovered(InfiniteTowerWaveController_OnCombatSquadMemberDiscovered);
			DeathRewards.OnKilledServer -= new hook_OnKilledServer(DeathRewards_OnKilledServer);
			simulacrumLootTweaks.Unhook();
			FastSimulacrumVrab.Disable();
		}

		private void DeathRewards_OnKilledServer(orig_OnKilledServer orig, DeathRewards self, DamageReport damageReport)
		{
			float value = BepConfig.MonsterGoldMultiplier.Value;
			if (NetworkServer.active && BepConfig.Enabled.Value && value != 1f)
			{
				self.goldReward = (uint)Mathf.Max(0, Mathf.RoundToInt((float)self.goldReward * value));
			}
			orig.Invoke(self, damageReport);
		}

		private void ChildMonsterController_RegisterTeleport(orig_RegisterTeleport orig, ChildMonsterController self, bool addInvincibility)
		{
			if (BepConfig.Enabled.Value && BepConfig.ChildRemoveInvincibility.Value)
			{
				orig.Invoke(self, false);
			}
			else
			{
				orig.Invoke(self, addInvincibility);
			}
		}

		private void FrolicAway_TeleportAway(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0067: 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)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 100f),
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 200f)
			});
			val.Remove();
			val.Remove();
			val.Emit(OpCodes.Ldc_R4, 50f);
			val.Emit(OpCodes.Ldc_R4, 100f);
		}

		private void InfiniteTowerWaveController_Initialize(orig_Initialize orig, InfiniteTowerWaveController self, int waveIndex, Inventory enemyInventory, GameObject spawnTarget)
		{
			if (BepConfig.Enabled.Value)
			{
				self.maxSquadSize = BepConfig.SimulacrumMaxSquadSize.Value;
			}
			if (NetworkServer.active && BepConfig.Enabled.Value)
			{
				self.wavePeriodSeconds *= BepConfig.SimulacrumWavePeriodSecondsFactor.Value;
			}
			orig.Invoke(self, waveIndex, enemyInventory, spawnTarget);
		}

		private void InfiniteTowerWaveController_FixedUpdate(orig_FixedUpdate orig, InfiniteTowerWaveController self)
		{
			float value = BepConfig.SimulacrumEmptyWaveDirectorSpeedup.Value;
			if (!NetworkServer.active || !BepConfig.Enabled.Value || value == 1f || (Object)(object)self.combatSquad == (Object)null || self.combatSquad.memberCount > 0)
			{
				orig.Invoke(self);
				return;
			}
			float creditsPerSecond = self.creditsPerSecond;
			self.creditsPerSecond = creditsPerSecond * Math.Max(0f, value);
			try
			{
				orig.Invoke(self);
			}
			finally
			{
				self.creditsPerSecond = creditsPerSecond;
			}
		}

		private void InfiniteTowerWaveController_OnAllEnemiesDefeatedServer(orig_OnAllEnemiesDefeatedServer orig, InfiniteTowerWaveController self)
		{
			//IL_008b: 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)
			orig.Invoke(self);
			if (!NetworkServer.active || !BepConfig.Enabled.Value || !BepConfig.SimulacrumCaptainBeaconsAfterBossWave.Value || !self.isBossWave)
			{
				return;
			}
			CaptainSupplyDropController val2 = default(CaptainSupplyDropController);
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				CharacterMaster master = instance.master;
				CharacterBody val = (((Object)(object)master != (Object)null) ? master.GetBody() : null);
				if ((Object)(object)val != (Object)null && val.healthComponent.alive && ((Component)val).TryGetComponent<CaptainSupplyDropController>(ref val2) && val2.netEnabledSkillsMask != 3)
				{
					master.Respawn(val.transform.position, val.transform.rotation, false);
				}
			}
		}

		private WeightedSelection<DirectorCard> SceneDirector_GenerateInteractableCardSelection(orig_GenerateInteractableCardSelection orig, SceneDirector self)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			WeightedSelection<DirectorCard> val = orig.Invoke(self);
			if (!NetworkServer.active || !BepConfig.Enabled.Value || !BepConfig.SimulacrumAllowDrones.Value || !(Run.instance is InfiniteTowerRun) || val == null)
			{
				return val;
			}
			for (int i = 0; i < val.Count; i++)
			{
				DirectorCard value = val.GetChoice(i).value;
				SpawnCard obj = ((value != null) ? value.GetSpawnCard() : null);
				InteractableSpawnCard val2 = (InteractableSpawnCard)(object)((obj is InteractableSpawnCard) ? obj : null);
				if (val2 != null && val2.skipSpawnWhenDevotionArtifactEnabled)
				{
					return val;
				}
			}
			List<(SpawnCard droneBrokenSpawnCard, float weight)> list = (from droneDef in DroneCatalog.allDroneDefs
				where (Object)(object)droneDef != (Object)null && (Object)(object)droneDef.droneBrokenSpawnCard != (Object)null && droneDef.CheckRequiredExpansionEnabled((NetworkUser)null)
				select (droneBrokenSpawnCard: droneDef.droneBrokenSpawnCard, weight: ((int)droneDef.tier == 0) ? 4f : (((int)droneDef.tier == 1) ? 2f : 1f))).ToList();
			float num = list.Sum(((SpawnCard droneBrokenSpawnCard, float weight) drone) => drone.weight);
			foreach (var (spawnCard, num2) in list)
			{
				val.AddChoice(new DirectorCard
				{
					spawnCard = spawnCard,
					selectionWeight = 1
				}, 14f * num2 / num);
			}
			return val;
		}

		private void Run_Start(orig_Start orig, Run self)
		{
			simulacrumLootTweaks.RunStart();
			ResetOverridePowerBias();
			dissonanceEnabledForWave = false;
			orig.Invoke(self);
		}

		public static void SetOverridePowerBias(float powerBias)
		{
			directorEnemyPowerBiasOverride = powerBias;
		}

		public static float GetCurrentPowerBias()
		{
			if (((object)Run.instance).GetType() == typeof(InfiniteTowerRun) && BepConfig.Enabled.Value)
			{
				return BepConfig.SimulacrumDirectorEnemyPowerBias.Value;
			}
			if (BepConfig.Enabled.Value)
			{
				return BepConfig.ClassicDirectorEnemyPowerBias.Value;
			}
			return 0.5f;
		}

		public static void ResetOverridePowerBias()
		{
			directorEnemyPowerBiasOverride = -1f;
		}

		private static float GetPowerBias()
		{
			if (directorEnemyPowerBiasOverride >= 0f)
			{
				return directorEnemyPowerBiasOverride;
			}
			if (!((Object)(object)Run.instance != (Object)null))
			{
				return 0.5f;
			}
			return GetCurrentPowerBias();
		}

		private static WeightedSelection<DirectorCard> CombatDirector_get_finalMonsterCardsSelection(Func<CombatDirector, WeightedSelection<DirectorCard>> orig, CombatDirector self)
		{
			//IL_0037: 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_0045: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			WeightedSelection<DirectorCard> val = orig(self);
			float powerBias = GetPowerBias();
			if (val == null || !NetworkServer.active || Mathf.Approximately(powerBias, 0.5f))
			{
				return val;
			}
			float num = val.Count;
			for (int i = 0; i < val.Count; i++)
			{
				ChoiceInfo<DirectorCard> choice = val.GetChoice(i);
				num = num * 31f + choice.weight * 7f + (float)((choice.value != null) ? choice.value.cost : 0);
			}
			if (biasedSelections.TryGetValue(val, out var value) && value.powerBias == powerBias && value.signature == num)
			{
				return value.selection;
			}
			float num2 = 4f * (powerBias - 0.5f);
			WeightedSelection<DirectorCard> val2 = new WeightedSelection<DirectorCard>(val.Count);
			for (int j = 0; j < val.Count; j++)
			{
				ChoiceInfo<DirectorCard> choice2 = val.GetChoice(j);
				int num3 = ((choice2.value == null) ? 1 : Mathf.Max(1, choice2.value.cost));
				val2.AddChoice(choice2.value, choice2.weight * Mathf.Pow((float)num3, num2));
			}
			biasedSelections.Remove(val);
			biasedSelections.Add(val, new BiasedSelection
			{
				powerBias = powerBias,
				signature = num,
				selection = val2
			});
			return val2;
		}

		private static void CombatDirector_Awake(orig_Awake orig, CombatDirector self)
		{
			orig.Invoke(self);
			if (BepConfig.Enabled.Value)
			{
				self.maxConsecutiveCheapSkips = Math.Min(self.maxConsecutiveCheapSkips, 4);
			}
		}

		private void InfiniteTowerRun_OnWaveAllEnemiesDefeatedServer(orig_OnWaveAllEnemiesDefeatedServer orig, InfiniteTowerRun self, InfiniteTowerWaveController wc)
		{
			orig.Invoke(self, wc);
			if (dissonanceEnabledForWave && NetworkServer.active)
			{
				dissonanceEnabledForWave = false;
				RunArtifactManager.instance.SetArtifactEnabledServer(Artifacts.MixEnemy, false);
			}
		}

		private void InfiniteTowerRun_AdvanceWave(orig_AdvanceWave orig, InfiniteTowerRun self)
		{
			orig.Invoke(self);
			if (BepConfig.Enabled.Value && NetworkServer.active && !(BepConfig.SimulacrumCommencementArtifactDissonanceChance.Value <= 0f) && IsCurrentMapCommencment() && !RunArtifactManager.instance.IsArtifactEnabled(Artifacts.MixEnemy) && BepConfig.SimulacrumCommencementArtifactDissonanceChance.Value > RoR2Application.rng.nextNormalizedFloat)
			{
				dissonanceEnabledForWave = true;
				RunArtifactManager.instance.SetArtifactEnabledServer(Artifacts.MixEnemy, true);
			}
		}

		private bool IsCurrentMapInBazaar()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			return ((Scene)(ref activeScene)).name == "bazaar";
		}

		private bool IsCurrentMapCommencment()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_001e: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (!(((Scene)(ref activeScene)).name == "moon"))
			{
				activeScene = SceneManager.GetActiveScene();
				if (!(((Scene)(ref activeScene)).name == "moon2"))
				{
					activeScene = SceneManager.GetActiveScene();
					return ((Scene)(ref activeScene)).name == "itmoon";
				}
			}
			return true;
		}

		private UniquePickup RandomlyLunarUtils_CheckForLunarReplacement_UniquePickup_Xoroshiro128Plus(orig_CheckForLunarReplacement_UniquePickup_Xoroshiro128Plus orig, UniquePickup uniquePickup, Xoroshiro128Plus rng)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: 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_0024: 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_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_00b9: 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_0047: Invalid comparison between Unknown and I4
			//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_00b7: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			uniquePickup = orig.Invoke(uniquePickup, rng);
			if (!BepConfig.Enabled.Value || ((UniquePickup)(ref uniquePickup)).Equals(UniquePickup.none))
			{
				return uniquePickup;
			}
			PickupDef pickupDef = PickupCatalog.GetPickupDef(uniquePickup.pickupIndex);
			if (pickupDef != null && pickupDef.isLunar && (int)pickupDef.itemIndex != -1 && (!BepConfig.NoPearlsInBazaar.Value || !IsCurrentMapInBazaar()))
			{
				float nextNormalizedFloat = rng.nextNormalizedFloat;
				if (nextNormalizedFloat < BepConfig.IrradiantPearlReplacesLunarItemChance.Value)
				{
					((UniquePickup)(ref uniquePickup))..ctor(PickupCatalog.FindPickupIndex(ItemCatalog.FindItemIndex("ShinyPearl")));
				}
				else if (nextNormalizedFloat < BepConfig.IrradiantPearlReplacesLunarItemChance.Value + BepConfig.PearlReplacesLunarItemChance.Value)
				{
					((UniquePickup)(ref uniquePickup))..ctor(PickupCatalog.FindPickupIndex(ItemCatalog.FindItemIndex("Pearl")));
				}
				return uniquePickup;
			}
			return uniquePickup;
		}

		private void RandomlyLunarUtils_CheckForLunarReplacementUniqueArray(orig_CheckForLunarReplacementUniqueArray orig, PickupIndex[] pickupIndices, Xoroshiro128Plus rng)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_009c: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(pickupIndices, rng);
			if (!BepConfig.Enabled.Value)
			{
				return;
			}
			for (int i = 0; i < pickupIndices.Length; i++)
			{
				PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndices[i]);
				if (pickupDef != null && pickupDef.isLunar && (int)pickupDef.itemIndex != -1 && (!BepConfig.NoPearlsInBazaar.Value || !IsCurrentMapInBazaar()))
				{
					float nextNormalizedFloat = rng.nextNormalizedFloat;
					if (nextNormalizedFloat < BepConfig.IrradiantPearlReplacesLunarItemChance.Value)
					{
						pickupIndices[i] = PickupCatalog.FindPickupIndex(ItemCatalog.FindItemIndex("ShinyPearl"));
					}
					else if (nextNormalizedFloat < BepConfig.IrradiantPearlReplacesLunarItemChance.Value + BepConfig.PearlReplacesLunarItemChance.Value)
					{
						pickupIndices[i] = PickupCatalog.FindPickupIndex(ItemCatalog.FindItemIndex("Pearl"));
					}
				}
			}
		}
	}
	public class SimulacrumLootTweaks
	{
		public GameObject mostRecentlyCreatedPickup;

		public float totalItemRewardCount;

		private bool comingFromInfiniteTowerWaveController_DropRewards;

		public Dictionary<PlayerCharacterMasterController, float> usersItemCredit = new Dictionary<PlayerCharacterMasterController, float>();

		private readonly Dictionary<PlayerCharacterMasterController, float> lastGreedyWarningTime = new Dictionary<PlayerCharacterMasterController, float>();

		private const float GreedyWarningInterval = 5f;

		public void RegisterSaveData()
		{
			ModCompatibilityProperSave.Register("ServerSideTweaks.SimulacrumLootCredits", SaveItemCredits, LoadItemCredits);
		}

		private object SaveItemCredits()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, float> dictionary = new Dictionary<string, float>();
			foreach (KeyValuePair<PlayerCharacterMasterController, float> item in usersItemCredit)
			{
				if (Object.op_Implicit((Object)(object)item.Key) && Object.op_Implicit((Object)(object)item.Key.networkUser))
				{
					dictionary[GetUserKey(item.Key.networkUser.id)] = item.Value;
				}
			}
			return dictionary;
		}

		private void LoadItemCredits(object saved)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (!(saved is Dictionary<string, float> dictionary))
			{
				return;
			}
			usersItemCredit.Clear();
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				if (Object.op_Implicit((Object)(object)instance.networkUser) && dictionary.TryGetValue(GetUserKey(instance.networkUser.id), out var value))
				{
					usersItemCredit[instance] = value;
				}
			}
		}

		private static string GetUserKey(NetworkUserId id)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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)
			return $"{id.value}/{id.strValue}/{id.subId}";
		}

		public void RunStart()
		{
			mostRecentlyCreatedPickup = null;
			totalItemRewardCount = 0f;
			usersItemCredit.Clear();
			lastGreedyWarningTime.Clear();
		}

		public void Hook()
		{
			//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
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			InfiniteTowerWaveController.DropRewards += new hook_DropRewards(InfiniteTowerWaveController_DropRewards);
			PickupDropletController.CreatePickupDroplet_CreatePickupInfo_Vector3_Vector3 += new Manipulator(PickupDropletController_CreatePickupDroplet_CreatePickupInfo_Vector3_Vector3);
			PickupDropletController.CreatePickup += new hook_CreatePickup(PickupDropletController_CreatePickup);
			PickupDropletController.CreateCommandCube += new Manipulator(PickupDropletController_CreateCommandCube);
			GenericPickupController.CreatePickup += new Manipulator(GenericPickupController_CreatePickup);
			PickupPickerController.CreatePickup_UniquePickup += new hook_CreatePickup_UniquePickup(PickupPickerController_CreatePickup_UniquePickup);
			GenericPickupController.OnInteractionBegin += new hook_OnInteractionBegin(GenericPickupController_OnInteractionBegin);
			PickupPickerController.OnInteractionBegin += new hook_OnInteractionBegin(PickupPickerController_OnInteractionBegin);
			GenericPickupController.AttemptGrant += new hook_AttemptGrant(GenericPickupController_AttemptGrant);
			if (ModCompatibilityShareSuite.enabled)
			{
				ModCompatibilityShareSuite.AddPickupEventHandler(NonShareableItemCheck);
			}
		}

		public void Unhook()
		{
			//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
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			InfiniteTowerWaveController.DropRewards -= new hook_DropRewards(InfiniteTowerWaveController_DropRewards);
			PickupDropletController.CreatePickupDroplet_CreatePickupInfo_Vector3_Vector3 -= new Manipulator(PickupDropletController_CreatePickupDroplet_CreatePickupInfo_Vector3_Vector3);
			PickupDropletController.CreatePickup -= new hook_CreatePickup(PickupDropletController_CreatePickup);
			PickupDropletController.CreateCommandCube -= new Manipulator(PickupDropletController_CreateCommandCube);
			GenericPickupController.CreatePickup -= new Manipulator(GenericPickupController_CreatePickup);
			PickupPickerController.CreatePickup_UniquePickup -= new hook_CreatePickup_UniquePickup(PickupPickerController_CreatePickup_UniquePickup);
			GenericPickupController.OnInteractionBegin -= new hook_OnInteractionBegin(GenericPickupController_OnInteractionBegin);
			PickupPickerController.OnInteractionBegin -= new hook_OnInteractionBegin(PickupPickerController_OnInteractionBegin);
			GenericPickupController.AttemptGrant -= new hook_AttemptGrant(GenericPickupController_AttemptGrant);
			if (ModCompatibilityShareSuite.enabled)
			{
				ModCompatibilityShareSuite.RemovePickupEventHandler(NonShareableItemCheck);
			}
		}

		private void InfiniteTowerWaveController_DropRewards(orig_DropRewards orig, InfiniteTowerWaveController self)
		{
			try
			{
				comingFromInfiniteTowerWaveController_DropRewards = true;
				orig.Invoke(self);
			}
			finally
			{
				comingFromInfiniteTowerWaveController_DropRewards = false;
			}
			if (!BepConfig.Enabled.Value || !NetworkServer.active)
			{
				return;
			}
			float num = 0f;
			int num2 = 0;
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				if (instance.isConnected)
				{
					num2++;
				}
				else if (usersItemCredit.ContainsKey(instance))
				{
					num += Math.Max(0f, usersItemCredit[instance]);
					usersItemCredit[instance] = 0f;
					Inventory inventory = instance.master.inventory;
					int value = BepConfig.SimulacrumLootMaxItemDebt.Value;
					CharacterBody body = instance.body;
					SetSkullCounterCount(inventory, value, (body != null) ? ((Component)body).gameObject : null);
				}
			}
			foreach (PlayerCharacterMasterController instance2 in PlayerCharacterMasterController.instances)
			{
				if (instance2.isConnected)
				{
					if (usersItemCredit.ContainsKey(instance2))
					{
						usersItemCredit[instance2] += totalItemRewardCount / (float)num2;
					}
					else
					{
						usersItemCredit.Add(instance2, totalItemRewardCount / (float)num2);
					}
					usersItemCredit[instance2] += num / Math.Max(1f, num2);
					if (num2 == 1)
					{
						SetSkullCounterCount(instance2.master.inventory, 0, null);
					}
					else
					{
						Inventory inventory2 = instance2.master.inventory;
						int count = (int)Math.Floor(usersItemCredit[instance2] + (float)BepConfig.SimulacrumLootMaxItemDebt.Value);
						CharacterBody body2 = instance2.body;
						SetSkullCounterCount(inventory2, count, (body2 != null) ? ((Component)body2).gameObject : null);
					}
					Log.LogDebug(instance2.networkUser.userName + " itemCredit: " + usersItemCredit[instance2]);
				}
			}
			totalItemRewardCount = 0f;
		}

		private void PickupDropletController_CreatePickupDroplet_CreatePickupInfo_Vector3_Vector3(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);
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCall<Object>(x, "Instantiate")
			});
			val.Index += 1;
			val.EmitDelegate<Func<GameObject, GameObject>>((Func<GameObject, GameObject>)delegate(GameObject obj)
			{
				if (comingFromInfiniteTowerWaveController_DropRewards && BepConfig.Enabled.Value && NetworkServer.active)
				{
					obj.AddComponent<NonShareableItem>();
					totalItemRewardCount += 1f;
				}
				return obj;
			});
		}

		private void PickupDropletController_CreatePickup(orig_CreatePickup orig, PickupDropletController self)
		{
			mostRecentlyCreatedPickup = null;
			orig.Invoke(self);
			if (BepConfig.Enabled.Value && (Object)(object)mostRecentlyCreatedPickup != (Object)null && (Object)(object)((Component)self).GetComponent<NonShareableItem>() != (Object)null)
			{
				mostRecentlyCreatedPickup.AddComponent<NonShareableItem>();
			}
		}

		private void PickupDropletController_CreateCommandCube(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);
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCall<Object>(x, "Instantiate")
			});
			val.Index += 1;
			val.EmitDelegate<Func<GameObject, GameObject>>((Func<GameObject, GameObject>)delegate(GameObject obj)
			{
				mostRecentlyCreatedPickup = obj;
				return obj;
			});
		}

		private void GenericPickupController_CreatePickup(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);
			val.GotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCall<Object>(x, "Instantiate")
			});
			val.Index += 1;
			val.EmitDelegate<Func<GameObject, GameObject>>((Func<GameObject, GameObject>)delegate(GameObject obj)
			{
				mostRecentlyCreatedPickup = obj;
				return obj;
			});
		}

		private void PickupPickerController_CreatePickup_UniquePickup(orig_CreatePickup_UniquePickup orig, PickupPickerController self, UniquePickup pickupState)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			mostRecentlyCreatedPickup = null;
			orig.Invoke(self, pickupState);
			if (BepConfig.Enabled.Value && (Object)(object)mostRecentlyCreatedPickup != (Object)null && Object.op_Implicit((Object)(object)((Component)self).GetComponent<NonShareableItem>()))
			{
				mostRecentlyCreatedPickup.AddComponent<NonShareableItem>();
			}
		}

		private void PickupPickerController_OnInteractionBegin(orig_OnInteractionBegin orig, PickupPickerController self, Interactor activator)
		{
			if (CanInteract(((Component)self).gameObject, activator))
			{
				orig.Invoke(self, activator);
			}
		}

		private void GenericPickupController_OnInteractionBegin(orig_OnInteractionBegin orig, GenericPickupController self, Interactor activator)
		{
			if (CanInteract(((Component)self).gameObject, activator))
			{
				orig.Invoke(self, activator);
			}
		}

		private void GenericPickupController_AttemptGrant(orig_AttemptGrant orig, GenericPickupController self, CharacterBody body)
		{
			bool consumed = self.consumed;
			if ((BepConfig.Enabled.Value && CanInteract(((Component)self).gameObject, body)) || !BepConfig.Enabled.Value)
			{
				orig.Invoke(self, body);
			}
			NonShareableItem nonShareableItem = default(NonShareableItem);
			if (!NetworkServer.active || !BepConfig.Enabled.Value || !((Component)self).TryGetComponent<NonShareableItem>(ref nonShareableItem) || consumed || !self.consumed)
			{
				return;
			}
			CharacterMaster master = body.master;
			if ((Object)(object)master != (Object)null && (Object)(object)master.playerCharacterMasterController != (Object)null)
			{
				PlayerCharacterMasterController playerCharacterMasterController = master.playerCharacterMasterController;
				if (usersItemCredit.ContainsKey(playerCharacterMasterController))
				{
					usersItemCredit[playerCharacterMasterController] -= 1f;
				}
				else
				{
					usersItemCredit.Add(playerCharacterMasterController, -1f);
				}
				if (PlayerCharacterMasterController.instances.Where((PlayerCharacterMasterController pc) => pc.isConnected).Count() == 1)
				{
					SetSkullCounterCount(body.inventory, 0, null);
				}
				else
				{
					SetSkullCounterCount(body.inventory, (int)Math.Floor(usersItemCredit[playerCharacterMasterController] + (float)BepConfig.SimulacrumLootMaxItemDebt.Value), ((Component)body).gameObject);
				}
			}
		}

		private bool NonShareableItemCheck(GenericPickupController pickup, CharacterBody picker)
		{
			NonShareableItem nonShareableItem = default(NonShareableItem);
			if (BepConfig.SimulacrumNonSharedLoot.Value)
			{
				return !((Component)pickup).TryGetComponent<NonShareableItem>(ref nonShareableItem);
			}
			return true;
		}

		private bool CanInteract(GameObject self, CharacterBody body)
		{
			if (!BepConfig.Enabled.Value)
			{
				return true;
			}
			NonShareableItem nonShareableItem = default(NonShareableItem);
			if (self.TryGetComponent<NonShareableItem>(ref nonShareableItem))
			{
				CharacterMaster master = body.master;
				if ((Object)(object)master != (Object)null && (Object)(object)master.playerCharacterMasterController != (Object)null)
				{
					PlayerCharacterMasterController playerCharacterMasterController = master.playerCharacterMasterController;
					if (usersItemCredit.TryGetValue(playerCharacterMasterController, out var value))
					{
						if (value + (float)BepConfig.SimulacrumLootMaxItemDebt.Value >= 1f)
						{
							return true;
						}
						if (!lastGreedyWarningTime.TryGetValue(playerCharacterMasterController, out var value2) || Time.time - value2 >= 5f)
						{
							lastGreedyWarningTime[playerCharacterMasterController] = Time.time;
							ChatHelper.PlayerHasTooManyItems(playerCharacterMasterController.GetDisplayName());
						}
						return false;
					}
				}
			}
			return true;
		}

		private bool CanInteract(GameObject self, Interactor activator)
		{
			return CanInteract(self, (activator != null) ? ((Component)activator).GetComponent<CharacterBody>() : null);
		}

		private void SetSkullCounterCount(Inventory inventory, int count, GameObject playerObject)
		{
			//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)
			//IL_0018: 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_0033: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			if (!BepConfig.SimulacrumLootSkullTokens.Value)
			{
				return;
			}
			ItemIndex val = ItemCatalog.FindItemIndex("SkullCounter");
			int itemCountPermanent = inventory.GetItemCountPermanent(val);
			int num = count - itemCountPermanent;
			if (num == 0)
			{
				return;
			}
			inventory.GiveItemPermanent(val, num);
			InfiniteTowerSafeWardController safeWardController = ((InfiniteTowerRun)Run.instance).safeWardController;
			if ((Object)(object)playerObject != (Object)null && (Object)(object)safeWardController != (Object)null)
			{
				if (num > 0)
				{
					PurchaseInteraction.CreateItemTakenOrb(((Component)safeWardController).transform.position, playerObject, val);
				}
				else
				{
					PurchaseInteraction.CreateItemTakenOrb(playerObject.transform.position, ((Component)safeWardController).gameObject, val);
				}
			}
		}

		public void GiveAllPlayersItemCredit(float credit)
		{
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				if (usersItemCredit.ContainsKey(instance))
				{
					usersItemCredit[instance] += credit;
				}
				else
				{
					usersItemCredit.Add(instance, credit);
				}
				Log.LogDebug($"{instance.networkIdentity}.ItemCredit: {usersItemCredit[instance]}");
			}
		}
	}
}