Decompiled source of RiskOfRoutes v1.0.1

RiskOfRoutes.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HG;
using HG.Reflection;
using IL.RoR2;
using LeTai.Asset.TranslucentImage;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using On.RoR2.Networking;
using On.RoR2.UI;
using R2API;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RiskOfRoutes;
using RiskOfRoutes.StageModifiers;
using RiskOfRoutes.StageModifiers.CombatModifiers;
using RiskOfRoutes.StageModifiers.OtherModifiers;
using RiskOfRoutes.StageModifiers.SceneModifiers;
using RoR2;
using RoR2.Artifacts;
using RoR2.CharacterAI;
using RoR2.ExpansionManagement;
using RoR2.Navigation;
using RoR2.Networking;
using RoR2.UI;
using SamplePlugin;
using SamplePlugin.StageModifiers;
using SamplePlugin.StageModifiers.BossRewardModifiers;
using SamplePlugin.StageModifiers.CombatModifiers;
using SamplePlugin.StageModifiers.OtherModifiers;
using SamplePlugin.StageModifiers.SceneModifiers;
using TMPro;
using Unity;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyInformationalVersion("1.0.0+99bd7d6f15004ac539300520f196f32964d4f8a1")]
[assembly: AssemblyProduct("RiskOfRoutes")]
[assembly: AssemblyTitle("RiskOfRoutes")]
[assembly: AssemblyCompany("RiskOfRoutes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public class RouteMap
{
	public class RouteNode
	{
		public RoutePortalType portalType;

		public int x;

		public int y;

		public bool visited;

		public RouteNode left;

		public RouteNode front;

		public RouteNode right;

		public RouteNode portalNode;

		public RouteNode(int x, int y)
		{
			portalType = RoutePortalType.None;
			this.x = x;
			this.y = y;
		}

		public List<RouteNode> GetPaths(bool usePortalNode = false)
		{
			List<RouteNode> list = new List<RouteNode>();
			if (left != null)
			{
				list.Add(left);
			}
			if (front != null)
			{
				list.Add(front);
			}
			if (right != null)
			{
				list.Add(right);
			}
			if (portalNode != null && usePortalNode)
			{
				list.Add(portalNode);
			}
			return list;
		}

		public override string ToString()
		{
			return $"Node:{x}.{y} with {GetPaths().Count} paths";
		}
	}

	public int width;

	public int height;

	public int startingRoutes = 3;

	public bool isMoonVisited = false;

	public RouteNode[,] mapGrid;

	public RouteNode root;

	public bool isDirty = false;

	public RouteMap(Xoroshiro128Plus rng)
	{
		width = global::RiskOfRoutes.RiskOfRoutes.routeMapWidth.Value;
		height = 5;
		mapGrid = new RouteNode[width + 1, height];
		mapGrid[0, 0] = new RouteNode(0, 0);
		root = mapGrid[0, 0];
		root.visited = true;
		root.portalType = RoutePortalType.Starting;
		for (int i = 0; i < width; i++)
		{
			for (int j = 1; j < height; j++)
			{
				mapGrid[i, j] = new RouteNode(i, j);
			}
		}
		List<RouteNode> list = SetupPaths(rng);
		list.Sort((RouteNode a, RouteNode b) => a.x.CompareTo(b.x));
		if (list.Count >= 1)
		{
			root.left = list[0];
		}
		if (list.Count >= 2)
		{
			root.front = list[1];
		}
		if (list.Count >= 3)
		{
			root.right = list[2];
		}
		SetupRewards(rng);
		isDirty = true;
	}

	public void SetupRewards(Xoroshiro128Plus rng)
	{
		WeightedSelection<RoutePortalType> val = new WeightedSelection<RoutePortalType>(8);
		val.AddChoice(RoutePortalType.Heal, 1f);
		val.AddChoice(RoutePortalType.Combat, 1f);
		val.AddChoice(RoutePortalType.Utility, 1f);
		val.AddChoice(RoutePortalType.DroneType, 1f);
		WeightedSelection<RoutePortalType> val2 = new WeightedSelection<RoutePortalType>(8);
		val2.AddChoice(RoutePortalType.Heal, 1f);
		val2.AddChoice(RoutePortalType.Combat, 1f);
		val2.AddChoice(RoutePortalType.Utility, 1f);
		val2.AddChoice(RoutePortalType.DroneType, 1f);
		val2.AddChoice(RoutePortalType.ChefType, 0.8f);
		val2.AddChoice(RoutePortalType.Rare, 0.8f);
		for (int i = 0; i < width; i++)
		{
			if (mapGrid[i, 1].portalType != 0)
			{
				mapGrid[i, 1].portalType = val.Evaluate(rng.nextNormalizedFloat);
			}
			if (mapGrid[i, 3].portalType != 0)
			{
				mapGrid[i, 3].portalType = val2.Evaluate(rng.nextNormalizedFloat);
			}
			if (mapGrid[i, 2].portalType != 0)
			{
				mapGrid[i, 2].portalType = val2.Evaluate(rng.nextNormalizedFloat);
			}
			if (mapGrid[i, 4].portalType != 0)
			{
				mapGrid[i, 4].portalType = RoutePortalType.ChefType;
			}
		}
		HashSet<Vector2> memory = new HashSet<Vector2>();
		List<RouteNode> paths = root.GetPaths();
		CheckNodeCorrect(root, rng, memory);
		foreach (RouteNode item in paths)
		{
			CheckNodeCorrect(item, rng, memory);
		}
	}

	private void CheckNodeCorrect(RouteNode node, Xoroshiro128Plus rng, HashSet<Vector2> memory)
	{
		//IL_0017: 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)
		Vector2 item = default(Vector2);
		((Vector2)(ref item))..ctor((float)node.x, (float)node.y);
		if (memory.Contains(item))
		{
			return;
		}
		memory.Add(item);
		RoutePortalType routePortalType = RoutePortalType.None;
		List<RouteNode> paths = node.GetPaths();
		if (paths.Count == 0)
		{
			return;
		}
		routePortalType = node.portalType;
		foreach (RouteNode item2 in paths)
		{
			if (item2.portalType == node.portalType)
			{
				item2.portalType = RollPortalType(rng, node.portalType);
			}
		}
		if (paths.Count > 1)
		{
			if (paths.Count == 2)
			{
				if (paths[0].portalType == paths[1].portalType)
				{
					paths[1].portalType = RollPortalType(rng, paths[0].portalType, routePortalType);
				}
			}
			else if (paths.Count == 3)
			{
				if (paths[0].portalType == paths[1].portalType)
				{
					paths[1].portalType = RollPortalType(rng, paths[0].portalType, routePortalType);
				}
				if (paths[2].portalType == paths[0].portalType || paths[2].portalType == paths[1].portalType)
				{
					paths[2].portalType = RollPortalType(rng, paths[0].portalType, paths[1].portalType, routePortalType);
				}
			}
		}
		foreach (RouteNode item3 in paths)
		{
			CheckNodeCorrect(item3, rng, memory);
		}
	}

	private RoutePortalType RollPortalType(Xoroshiro128Plus rng, params RoutePortalType[] skipTypes)
	{
		WeightedSelection<RoutePortalType> val = new WeightedSelection<RoutePortalType>(8);
		RoutePortalType[] array = new RoutePortalType[6]
		{
			RoutePortalType.Combat,
			RoutePortalType.Heal,
			RoutePortalType.Utility,
			RoutePortalType.DroneType,
			RoutePortalType.Rare,
			RoutePortalType.ChefType
		};
		RoutePortalType[] array2 = array;
		foreach (RoutePortalType routePortalType in array2)
		{
			if (!skipTypes.Contains(routePortalType))
			{
				if (routePortalType == RoutePortalType.Rare || routePortalType == RoutePortalType.ChefType)
				{
					val.AddChoice(routePortalType, 0.8f);
				}
				else
				{
					val.AddChoice(routePortalType, 1f);
				}
			}
		}
		return val.Evaluate(rng.nextNormalizedFloat);
	}

	public List<RouteNode> SetupPaths(Xoroshiro128Plus rng)
	{
		List<RouteNode> list = new List<RouteNode>();
		List<int> list2 = new List<int>();
		for (int i = 0; i < width; i++)
		{
			list2.Add(i);
		}
		for (int j = 0; j < startingRoutes; j++)
		{
			if (list2.Count == 0)
			{
				break;
			}
			int num = rng.NextElementUniform<int>(list2);
			list2.Remove(num);
			RouteNode routeNode = mapGrid[num, 1];
			if (routeNode != null)
			{
				routeNode.portalType = RoutePortalType.Rare;
				CreateRoute(routeNode, routeNode.x, routeNode.y, rng);
				list.Add(routeNode);
			}
		}
		return list;
	}

	public void CreateRoute(RouteNode curr, int x, int y, Xoroshiro128Plus rng)
	{
		if (y >= height - 1)
		{
			return;
		}
		List<RouteNode> list = new List<RouteNode>();
		for (int i = 0; i < 3; i++)
		{
			int num = x - 1 + i;
			int num2 = y + 1;
			if (num >= 0 && num <= width - 1 && (i != 0 || mapGrid[num, y].right == null) && (i != 2 || mapGrid[num, y].left == null))
			{
				list.Add(mapGrid[x - 1 + i, y + 1]);
			}
		}
		if (list.Count != 0)
		{
			RouteNode routeNode = rng.NextElementUniform<RouteNode>(list);
			if (list.Count > 1 && rng.nextNormalizedFloat < 0.2f)
			{
				list.Remove(routeNode);
				RouteNode routeNode2 = rng.NextElementUniform<RouteNode>(list);
				routeNode2.portalType = RoutePortalType.Rare;
				Connect(curr, routeNode2);
				CreateRoute(routeNode2, routeNode2.x, routeNode2.y, rng);
			}
			routeNode.portalType = RoutePortalType.Rare;
			Connect(curr, routeNode);
			CreateRoute(routeNode, routeNode.x, routeNode.y, rng);
		}
	}

	public RouteNode CreateColossusNode(RouteNode current, bool currentLayer = false)
	{
		if (current.y == height - 1 || current.y >= 3)
		{
			return null;
		}
		int num = (currentLayer ? current.y : (current.y + 1));
		Log.Info("Creating colossus node");
		isDirty = true;
		RouteNode routeNode = null;
		for (int i = 0; i < width + 1; i++)
		{
			if (mapGrid[i, num] != null && (mapGrid[i, num].portalType == RoutePortalType.Colossus || mapGrid[i, num].portalType == RoutePortalType.FalseSon))
			{
				routeNode = mapGrid[i, num];
				Log.Info("Floor already has colossus node");
				return routeNode;
			}
		}
		Log.Info("Has no colossus nodes");
		for (int j = 0; j < width; j++)
		{
			int[] array = new int[2]
			{
				current.x + j,
				current.x - j
			};
			int[] array2 = array;
			foreach (int num2 in array2)
			{
				if (num2 >= 0 && num2 < width && mapGrid[num2, num].portalType == RoutePortalType.None)
				{
					routeNode = mapGrid[num2, num];
					break;
				}
			}
			if (routeNode != null)
			{
				break;
			}
		}
		if (routeNode == null)
		{
			Log.Warning("No place for colossus node, placing on extra");
			mapGrid[width, num] = new RouteNode(width, num);
			routeNode = mapGrid[width, num];
		}
		if (routeNode != null)
		{
			routeNode.portalType = ((num != 3) ? RoutePortalType.Colossus : RoutePortalType.FalseSon);
			current.portalNode = routeNode;
			if (routeNode.portalType == RoutePortalType.FalseSon)
			{
				ConnectToRandomNode(routeNode, thisLayer: true);
			}
			else
			{
				ConnectToRandomNode(routeNode);
			}
			return routeNode;
		}
		Log.Error("Still null");
		return null;
	}

	public RouteNode CreateHardwareNode(RouteNode current)
	{
		int num = current.y + 1;
		Log.Info("Creating hardware node");
		isDirty = true;
		RouteNode routeNode = null;
		for (int i = 0; i < width + 1; i++)
		{
			if (mapGrid[i, num] != null && (mapGrid[i, num].portalType == RoutePortalType.Hardware || mapGrid[i, num].portalType == RoutePortalType.SolusWing))
			{
				routeNode = mapGrid[i, num];
				Log.Info("Floor already has hardware node");
				return routeNode;
			}
		}
		Log.Info("Has no hardware nodes");
		for (int j = 0; j < width; j++)
		{
			int[] array = new int[2]
			{
				current.x + j,
				current.x - j
			};
			int[] array2 = array;
			foreach (int num2 in array2)
			{
				if (num2 >= 0 && num2 < width && mapGrid[num2, num].portalType == RoutePortalType.None)
				{
					routeNode = mapGrid[num2, num];
					break;
				}
			}
			if (routeNode != null)
			{
				break;
			}
		}
		if (routeNode == null)
		{
			Log.Warning("No place for hardware node, placing on extra");
			mapGrid[width, num] = new RouteNode(width, num);
			routeNode = mapGrid[width, num];
		}
		if (routeNode != null)
		{
			routeNode.portalType = ((num != 4) ? RoutePortalType.Hardware : RoutePortalType.SolusWing);
			current.portalNode = routeNode;
			return routeNode;
		}
		Log.Error("Still null");
		return null;
	}

	private void ConnectToRandomNode(RouteNode node, bool thisLayer = false)
	{
		int y = node.y;
		int num = (thisLayer ? y : (y + 1));
		List<RouteNode> list = new List<RouteNode>();
		for (int i = 0; i < width; i++)
		{
			RouteNode routeNode = mapGrid[i, num];
			if (routeNode != null && routeNode.portalType != 0 && routeNode != node)
			{
				list.Add(routeNode);
			}
		}
		if (list.Count > 0)
		{
			node.front = Run.instance.stageRng.NextElementUniform<RouteNode>(list);
		}
		else
		{
			Log.Warning("ConnectToRandomNode: No valid target nodes to connect");
		}
	}

	private void Connect(RouteNode curr, RouteNode next)
	{
		if (curr.x - next.x == -1)
		{
			curr.right = next;
		}
		else if (curr.x - next.x == 0)
		{
			curr.front = next;
		}
		else
		{
			curr.left = next;
		}
	}

	public RouteNode GetStartingNode()
	{
		return mapGrid[0, 0];
	}
}
public enum RoutePortalType
{
	None,
	Rare,
	ItemType,
	DroneType,
	ChefType,
	Colossus,
	Hardware,
	SolusWing,
	Goldshores,
	Shop,
	FalseSon,
	Starting,
	Combat,
	Heal,
	Utility
}
public enum ModifierTier
{
	Tier1 = 1,
	Tier2,
	Tier3
}
public enum ModifierRarity
{
	Common,
	Rare
}
namespace SamplePlugin
{
	public class CommandHelper : MonoBehaviour
	{
		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void GetNextStagesScenesCommand(ConCommandArgs args)
		{
			Log.Info("Next stages available:");
			foreach (SceneDef nextStagesScenes in SceneHelper.GetNextStagesScenesList())
			{
				Log.Info(nextStagesScenes.cachedName);
			}
			Log.Info(Run.instance.nextStageScene.destinationsGroup);
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void GetNextGreenStage(ConCommandArgs args)
		{
			Log.Info($"Modul:{Stage.instance.sceneDef.stageOrder}");
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void GetDccs(ConCommandArgs args)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Log.Info("Available enemies");
			WeightedSelection<DirectorCard> monsterSelection = ClassicStageInfo.instance.monsterSelection;
			if (monsterSelection != null)
			{
				for (int i = 0; i < monsterSelection.Count; i++)
				{
					DirectorCard value = monsterSelection.GetChoice(i).value;
					Log.Info($"DirectorCard {((Object)value.spawnCard).name}, cost: {value.cost}, weight: {value.selectionWeight}");
				}
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void GetCurrentNode(ConCommandArgs args)
		{
			List<RouteNodeSync> routeNodesSynced = StageModifierDirector.instance.routeNodesSynced;
			if (routeNodesSynced.Count == 0)
			{
				Log.Error("none");
			}
			foreach (RouteNodeSync item in routeNodesSynced)
			{
				Log.Info($"{item.x}.{item.y}:{item.portalType}-{item.visited}");
			}
			RouteMap.RouteNode currentNode = StageModifierDirector.instance.currentNode;
			Log.Info($"Current node is {currentNode.x},{currentNode.y} with {currentNode.GetPaths().Count} children, visited {currentNode.visited}");
			Log.Info("\tNext scene:" + Run.instance.nextStageScene.cachedName);
			Log.Info("\tCurr scene:" + Stage.instance.sceneDef.cachedName);
			Log.Info($"\tLoop clear count:{Run.instance.loopClearCount}");
			Log.Info($"Child node: {currentNode.GetPaths()[0].x}.{currentNode.GetPaths()[0].y}: {currentNode.GetPaths()[0].portalType}");
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void GetElitesAvailable(ConCommandArgs args)
		{
			FieldInfo field = typeof(CombatDirector).GetField("eliteTiers", BindingFlags.Static | BindingFlags.NonPublic);
			if (!(field != null))
			{
				return;
			}
			EliteTierDef[] array = (EliteTierDef[])field.GetValue(null);
			Log.Info($"Tier count{array.Length}");
			for (int i = 0; i < array.Length; i++)
			{
				Log.Info($"Tier{i + 1}: {array[i].availableDefs.Count}");
				foreach (EliteDef availableDef in array[i].availableDefs)
				{
					if ((Object)(object)availableDef != (Object)null)
					{
						Log.Info("\t " + ((Object)availableDef).name);
					}
				}
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void GetItemDefs(ConCommandArgs args)
		{
			//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_000a: 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)
			Enumerator<ItemDef> enumerator = ItemCatalog.allItemDefs.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ItemDef current = enumerator.Current;
					Log.Info("\t" + ((Object)current).name);
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void SetMapDirty(ConCommandArgs args)
		{
			StageModifierDirector.instance.routeMap.isDirty = true;
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void ItemTags(ConCommandArgs args)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_001a: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Invalid comparison between Unknown and I4
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Invalid comparison between Unknown and I4
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Invalid comparison between Unknown and I4
			Log.Info("Items with damage tag");
			Enumerator<ItemDef> enumerator = ItemCatalog.allItemDefs.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ItemDef current = enumerator.Current;
					if (current.tags.Contains((ItemTag)1) && ((int)current.tier == 0 || (int)current.tier == 1))
					{
						Log.Info("\t" + ((Object)current).name + ":" + Language.GetString(current.nameToken));
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			Log.Info("Items with healing tag");
			Enumerator<ItemDef> enumerator2 = ItemCatalog.allItemDefs.GetEnumerator();
			try
			{
				while (enumerator2.MoveNext())
				{
					ItemDef current2 = enumerator2.Current;
					if (current2.tags.Contains((ItemTag)2) && ((int)current2.tier == 0 || (int)current2.tier == 1))
					{
						Log.Info("\t" + ((Object)current2).name + ":" + Language.GetString(current2.nameToken));
					}
				}
			}
			finally
			{
				((IDisposable)enumerator2).Dispose();
			}
			Log.Info("Items with utility tag");
			Enumerator<ItemDef> enumerator3 = ItemCatalog.allItemDefs.GetEnumerator();
			try
			{
				while (enumerator3.MoveNext())
				{
					ItemDef current3 = enumerator3.Current;
					if (current3.tags.Contains((ItemTag)3) && ((int)current3.tier == 0 || (int)current3.tier == 1))
					{
						Log.Info("\t" + ((Object)current3).name + ":" + Language.GetString(current3.nameToken));
					}
				}
			}
			finally
			{
				((IDisposable)enumerator3).Dispose();
			}
			Log.Info("Items with food-related tag");
			Enumerator<ItemDef> enumerator4 = ItemCatalog.allItemDefs.GetEnumerator();
			try
			{
				while (enumerator4.MoveNext())
				{
					ItemDef current4 = enumerator4.Current;
					if (current4.tags.Contains((ItemTag)28) && ((int)current4.tier == 0 || (int)current4.tier == 1))
					{
						Log.Info("\t" + ((Object)current4).name + ":" + Language.GetString(current4.nameToken));
					}
				}
			}
			finally
			{
				((IDisposable)enumerator4).Dispose();
			}
			Log.Info("Items with ai_blacklist tag");
			Enumerator<ItemDef> enumerator5 = ItemCatalog.allItemDefs.GetEnumerator();
			try
			{
				while (enumerator5.MoveNext())
				{
					ItemDef current5 = enumerator5.Current;
					if (current5.tags.Contains((ItemTag)4))
					{
						Log.Info("\t" + ((Object)current5).name + ":" + Language.GetString(current5.nameToken));
					}
				}
			}
			finally
			{
				((IDisposable)enumerator5).Dispose();
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void GetActiveModifiersCommand(ConCommandArgs args)
		{
			Log.Info("Getting synced modifiers");
			if (!((Object)(object)StageModifierDirector.instance != (Object)null))
			{
				return;
			}
			SyncListModifier modifiersSynced = StageModifierDirector.instance.modifiersSynced;
			if (modifiersSynced != null)
			{
				if (((SyncListStruct<ModifierSync>)modifiersSynced).Count > 0)
				{
					foreach (ModifierSync item in (SyncList<ModifierSync>)(object)modifiersSynced)
					{
						Log.Info($"{item.name}:{item.stack}");
					}
					return;
				}
				Log.Info("There are no modifiers");
			}
			else
			{
				Log.Error("Modifiers list is null");
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void GetSyncedData(ConCommandArgs args)
		{
			Log.Info("Getting synced modifiers");
			if ((Object)(object)StageModifierDirector.instance != (Object)null)
			{
				Log.Info("Modifiers synced");
				{
					foreach (ModifierSync item in (SyncList<ModifierSync>)(object)StageModifierDirector.instance.modifiersSynced)
					{
						Log.Info($"{item.name}:{item.stack}:{item.isArtifact}");
					}
					return;
				}
			}
			Log.Info("StageModifierDirector is null");
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void GetReservedModifiersCommand(ConCommandArgs args)
		{
			if ((Object)(object)StageModifierDirector.instance != (Object)null)
			{
				List<ModifierSync> reservedModifiers = StageModifierDirector.instance.reservedModifiers;
				if (reservedModifiers != null)
				{
					if (reservedModifiers.Count > 0)
					{
						foreach (ModifierSync item in reservedModifiers)
						{
							Log.Info(item);
						}
						return;
					}
					Log.Info("There are no modifiers");
				}
				else
				{
					Log.Error("Modifiers list is null");
				}
			}
			else
			{
				Log.Error("It is null");
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CheckOneShotProtection(ConCommandArgs args)
		{
			ReadOnlyCollection<PlayerCharacterMasterController> instances = PlayerCharacterMasterController.instances;
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				Log.Info($"{instance.body.hasOneShotProtection}:{((Object)instance).name}");
				instance.body.hasOneShotProtection = false;
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void FindShopPortal(ConCommandArgs args)
		{
			GameObject val = GameObject.Find("Node");
			if ((Object)(object)val == (Object)null)
			{
				Log.Error("Could not find it");
				return;
			}
			Log.Info("Found it");
			Component[] componentsInChildren = val.GetComponentsInChildren<Component>();
			foreach (Component val2 in componentsInChildren)
			{
				Log.Info(((object)val2).GetType());
			}
			SceneExitController component = val.GetComponent<SceneExitController>();
			Log.Info(component.destinationScene);
			Log.Info(component.useRunNextStageScene);
		}
	}
	[Serializable]
	public struct ModifierSync : IEquatable<ModifierSync>
	{
		public string name;

		public int stack;

		public bool isArtifact;

		public ModifierSync(ModifierDef mod)
		{
			name = mod.name;
			stack = 1;
			isArtifact = mod.isArtifact;
		}

		public ModifierSync(ModifierDef mod, int stack)
		{
			name = mod.name;
			this.stack = stack;
			isArtifact = mod.isArtifact;
		}

		public bool Equals(ModifierSync other)
		{
			return name == other.name;
		}
	}
	[Serializable]
	public struct RouteNodeSync : IEquatable<RouteNodeSync>
	{
		public RoutePortalType portalType;

		public int x;

		public int y;

		public int frontX;

		public int frontY;

		public int leftX;

		public int leftY;

		public int rightX;

		public int rightY;

		public int bonusX;

		public int bonusY;

		public bool visited;

		public RouteNodeSync(RouteMap.RouteNode node)
		{
			x = -1;
			y = -1;
			frontX = -1;
			frontY = -1;
			leftX = -1;
			leftY = -1;
			rightX = -1;
			rightY = -1;
			bonusX = -1;
			bonusY = -1;
			x = node.x;
			y = node.y;
			visited = node.visited;
			portalType = node.portalType;
			RouteMap.RouteNode front = node.front;
			if (front != null)
			{
				frontX = front.x;
				frontY = front.y;
			}
			RouteMap.RouteNode left = node.left;
			if (left != null)
			{
				leftX = left.x;
				leftY = left.y;
			}
			RouteMap.RouteNode right = node.right;
			if (node.right != null)
			{
				rightX = right.x;
				rightY = right.y;
			}
			if (node.portalNode != null)
			{
				bonusX = node.portalNode.x;
				bonusY = node.portalNode.y;
			}
		}

		public bool Equals(RouteNodeSync other)
		{
			return x == other.x && y == other.y && visited == other.visited && portalType == other.portalType && frontX == other.frontX && frontY == other.frontY && leftX == other.leftX && leftY == other.leftY && rightX == other.rightX && rightY == other.rightY && bonusX == other.bonusX && bonusY == other.bonusY;
		}
	}
	public class SyncListModifier : SyncListStruct<ModifierSync>
	{
		public override void SerializeItem(NetworkWriter writer, ModifierSync item)
		{
			writer.Write(item.name);
			writer.WritePackedUInt32((uint)item.stack);
			writer.Write(item.isArtifact);
		}

		public override ModifierSync DeserializeItem(NetworkReader reader)
		{
			ModifierSync result = default(ModifierSync);
			result.name = reader.ReadString();
			result.stack = (int)reader.ReadPackedUInt32();
			result.isArtifact = reader.ReadBoolean();
			return result;
		}
	}
	public class SyncListRouteNode : SyncListStruct<RouteNodeSync>
	{
		public override void SerializeItem(NetworkWriter writer, RouteNodeSync item)
		{
			writer.Write((int)item.portalType);
			writer.WritePackedUInt32((uint)item.x);
			writer.WritePackedUInt32((uint)item.y);
			writer.WritePackedUInt32((uint)item.frontX);
			writer.WritePackedUInt32((uint)item.frontY);
			writer.WritePackedUInt32((uint)item.leftX);
			writer.WritePackedUInt32((uint)item.leftY);
			writer.WritePackedUInt32((uint)item.rightX);
			writer.WritePackedUInt32((uint)item.rightY);
			writer.WritePackedUInt32((uint)item.bonusX);
			writer.WritePackedUInt32((uint)item.bonusY);
			writer.Write(item.visited);
		}

		public override RouteNodeSync DeserializeItem(NetworkReader reader)
		{
			RouteNodeSync result = default(RouteNodeSync);
			result.portalType = (RoutePortalType)reader.ReadInt32();
			result.x = (int)reader.ReadPackedUInt32();
			result.y = (int)reader.ReadPackedUInt32();
			result.frontX = (int)reader.ReadPackedUInt32();
			result.frontY = (int)reader.ReadPackedUInt32();
			result.leftX = (int)reader.ReadPackedUInt32();
			result.leftY = (int)reader.ReadPackedUInt32();
			result.rightX = (int)reader.ReadPackedUInt32();
			result.rightY = (int)reader.ReadPackedUInt32();
			result.bonusX = (int)reader.ReadPackedUInt32();
			result.bonusY = (int)reader.ReadPackedUInt32();
			result.visited = reader.ReadBoolean();
			return result;
		}
	}
	public class ModifierSlotConfiguration
	{
		public Dictionary<ModifierTier, int> positive = new Dictionary<ModifierTier, int>();

		public Dictionary<ModifierTier, int> negative = new Dictionary<ModifierTier, int>();
	}
	public class StageModifierDirector : NetworkBehaviour
	{
		public static StageModifierDirector instance;

		public static List<GameObject> activePortalInstances;

		public List<string> runArtifactsApplied;

		public SyncListModifier modifiersSynced = new SyncListModifier();

		public List<RouteNodeSync> routeNodesSynced = new List<RouteNodeSync>();

		public int mapState = 0;

		public float stageEnterTime = 0f;

		[SyncVar]
		public int mapWidth;

		[SyncVar]
		public int mapHeight;

		[SyncVar]
		public bool isMoonVisited;

		[SyncVar]
		public Vector2 currentNodeSync = new Vector2(-1f, -1f);

		public int uniqueModifierLimit = 5;

		public Inventory monsterTeamInventory;

		public RouteMap routeMap;

		public RouteMap.RouteNode currentNode;

		[SyncVar(hook = "OnBaseCurseSyncedUpdate")]
		public float syncedBaseCurse = 0f;

		[SyncVar]
		public int soulCostStack = 0;

		public int commandAddedStack = 0;

		public float punishmentTime = -1f;

		public bool purifyLunarItemModifier;

		public int doppelStackTime = 30;

		public bool modifiersCanBeBanned = true;

		public bool enemyItemsModifierCanStack = false;

		private List<string> syncNames = new List<string>();

		private List<int> syncTiers = new List<int>();

		private static int kListmodifiersSynced;

		private static int kRpcRpcReceiveFullMap;

		private static int kRpcRpcReceiveRunConfiguration;

		public List<StageModifier> activeModifiers { get; set; }

		public List<ModifierSync> reservedModifiers { get; set; }

		public HashSet<string> bannedModifiers { get; set; }

		public int NetworkmapWidth
		{
			get
			{
				return mapWidth;
			}
			[param: In]
			set
			{
				((NetworkBehaviour)this).SetSyncVar<int>(value, ref mapWidth, 2u);
			}
		}

		public int NetworkmapHeight
		{
			get
			{
				return mapHeight;
			}
			[param: In]
			set
			{
				((NetworkBehaviour)this).SetSyncVar<int>(value, ref mapHeight, 4u);
			}
		}

		public bool NetworkisMoonVisited
		{
			get
			{
				return isMoonVisited;
			}
			[param: In]
			set
			{
				((NetworkBehaviour)this).SetSyncVar<bool>(value, ref isMoonVisited, 8u);
			}
		}

		public Vector2 NetworkcurrentNodeSync
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return currentNodeSync;
			}
			[param: In]
			set
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				((NetworkBehaviour)this).SetSyncVar<Vector2>(value, ref currentNodeSync, 16u);
			}
		}

		public float NetworksyncedBaseCurse
		{
			get
			{
				return syncedBaseCurse;
			}
			[param: In]
			set
			{
				ref float reference = ref syncedBaseCurse;
				if (NetworkServer.localClientActive && !((NetworkBehaviour)this).syncVarHookGuard)
				{
					((NetworkBehaviour)this).syncVarHookGuard = true;
					OnBaseCurseSyncedUpdate(value);
					((NetworkBehaviour)this).syncVarHookGuard = false;
				}
				((NetworkBehaviour)this).SetSyncVar<float>(value, ref reference, 32u);
			}
		}

		public int NetworksoulCostStack
		{
			get
			{
				return soulCostStack;
			}
			[param: In]
			set
			{
				((NetworkBehaviour)this).SetSyncVar<int>(value, ref soulCostStack, 64u);
			}
		}

		public void Awake()
		{
			instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			activeModifiers = new List<StageModifier>();
			reservedModifiers = new List<ModifierSync>();
			bannedModifiers = new HashSet<string>();
			activePortalInstances = new List<GameObject>();
			Log.Info("Awake: StageModifierDirector created");
			if (NetworkServer.active)
			{
				Run.onRunStartGlobal += Run_onRunStartGlobal;
				Run.onRunDestroyGlobal += Run_onRunDestroyGlobal;
				SceneDirector.onPrePopulateSceneServer += SceneDirector_onPrePopulateSceneServer;
				Stage.onServerStageComplete += Stage_onServerStageComplete;
			}
			((SyncList<ModifierSync>)(object)modifiersSynced).InitializeBehaviour((NetworkBehaviour)(object)this, kListmodifiersSynced);
		}

		public void OnDestroy()
		{
			Run.onRunDestroyGlobal -= Run_onRunDestroyGlobal;
			Run.onRunStartGlobal -= Run_onRunStartGlobal;
			SceneDirector.onPrePopulateSceneServer -= SceneDirector_onPrePopulateSceneServer;
			Stage.onServerStageComplete -= Stage_onServerStageComplete;
		}

		private void Run_onRunStartGlobal(Run run)
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			Log.Info("Run_onRunStartGlobal: Run started");
			GameObject val = Object.Instantiate<GameObject>(global::RiskOfRoutes.RiskOfRoutes.networkedInventoryPrefab);
			Object.DontDestroyOnLoad((Object)(object)val);
			monsterTeamInventory = val.GetComponent<Inventory>();
			val.GetComponent<TeamFilter>().teamIndex = (TeamIndex)2;
			NetworkServer.Spawn(val);
			CreateRunConfiguration();
			Log.Info(string.Format("{0}: Got punishmentTimeMinutes value - {1}", "Run_onRunStartGlobal", punishmentTime));
			Log.Info("Creating route map");
			routeMap = new RouteMap(run.runRNG);
			currentNode = routeMap.GetStartingNode();
			currentNode.visited = true;
			NetworkcurrentNodeSync = new Vector2((float)currentNode.x, (float)currentNode.y);
			Log.Info($"Current:{currentNode.x},{currentNode.y} that has {currentNode.GetPaths().Count} paths");
			routeMap.isDirty = true;
			Log.Info("Run_onRunStartGlobal: Config banlist is:");
			foreach (string bannedModifier in bannedModifiers)
			{
				Log.Info("Banned: " + bannedModifier);
			}
		}

		private void CreateRunConfiguration()
		{
			enemyItemsModifierCanStack = global::RiskOfRoutes.RiskOfRoutes.enemyItemsModifierCanStack.Value;
			StageModifierCatalog.Init(AssetManager.bundle);
			runArtifactsApplied = GetArtifactsAppliedThisRun();
			if (global::RiskOfRoutes.RiskOfRoutes.negativeStackPunishment.Value)
			{
				punishmentTime = global::RiskOfRoutes.RiskOfRoutes.punishmentTimeMinutes.Value;
			}
			else
			{
				punishmentTime = -1f;
			}
			purifyLunarItemModifier = global::RiskOfRoutes.RiskOfRoutes.lunarTurnToPearl.Value;
			doppelStackTime = global::RiskOfRoutes.RiskOfRoutes.doppelStackTime.Value;
			modifiersCanBeBanned = global::RiskOfRoutes.RiskOfRoutes.modifiersCanBeBanned.Value;
			bannedModifiers.Clear();
			StageModifierCatalog.CleanAdditionalDefs();
			StageModifierCatalog.DisableDefaultPools(!global::RiskOfRoutes.RiskOfRoutes.useDefaultPrinterItems.Value, !global::RiskOfRoutes.RiskOfRoutes.useDefaultEnemyItems.Value, !global::RiskOfRoutes.RiskOfRoutes.useDefaultLunarItems.Value);
			List<string> list = (from s in global::RiskOfRoutes.RiskOfRoutes.tier1EnemyItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select s.Trim()).ToList();
			List<string> list2 = (from s in global::RiskOfRoutes.RiskOfRoutes.tier2EnemyItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select s.Trim()).ToList();
			List<string> list3 = (from s in global::RiskOfRoutes.RiskOfRoutes.tier3EnemyItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select s.Trim()).ToList();
			List<string> list4 = (from s in global::RiskOfRoutes.RiskOfRoutes.tier1PrinterItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select s.Trim()).ToList();
			List<string> list5 = (from s in global::RiskOfRoutes.RiskOfRoutes.tier2PrinterItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select s.Trim()).ToList();
			List<string> list6 = (from s in global::RiskOfRoutes.RiskOfRoutes.tier3PrinterItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select s.Trim()).ToList();
			List<string> list7 = (from s in global::RiskOfRoutes.RiskOfRoutes.tier1LunarItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select s.Trim()).ToList();
			List<string> list8 = (from s in global::RiskOfRoutes.RiskOfRoutes.tier2LunarItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select s.Trim()).ToList();
			List<string> list9 = (from s in global::RiskOfRoutes.RiskOfRoutes.tier3LunarItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select s.Trim()).ToList();
			foreach (string item in list)
			{
				StageModifierCatalog.RegEnemy(item, ModifierTier.Tier1, isAdditional: true);
				Log.Info(item + " registering as Tier1 enemy item");
			}
			foreach (string item2 in list2)
			{
				StageModifierCatalog.RegEnemy(item2, ModifierTier.Tier2, isAdditional: true);
				Log.Info(item2 + " registering as Tier2 enemy item");
			}
			foreach (string item3 in list3)
			{
				StageModifierCatalog.RegEnemy(item3, ModifierTier.Tier3, isAdditional: true);
				Log.Info(item3 + " registering as Tier3 enemy item");
			}
			foreach (string item4 in list4)
			{
				StageModifierCatalog.RegPrinter(item4, ModifierTier.Tier1, isAdditional: true);
				Log.Info(item4 + " registering as Tier1 printer item");
			}
			foreach (string item5 in list5)
			{
				StageModifierCatalog.RegPrinter(item5, ModifierTier.Tier2, isAdditional: true);
				Log.Info(item5 + " registering as Tier2 printer item");
			}
			foreach (string item6 in list6)
			{
				StageModifierCatalog.RegPrinter(item6, ModifierTier.Tier3, isAdditional: true);
				Log.Info(item6 + " registering as Tier3 printer item");
			}
			foreach (string item7 in list7)
			{
				StageModifierCatalog.RegLunar(item7, ModifierTier.Tier1, isAdditional: true);
				Log.Info(item7 + " registering as Tier1 lunar item");
			}
			foreach (string item8 in list8)
			{
				StageModifierCatalog.RegLunar(item8, ModifierTier.Tier2, isAdditional: true);
				Log.Info(item8 + " registering as Tier2 lunar item");
			}
			foreach (string item9 in list9)
			{
				StageModifierCatalog.RegLunar(item9, ModifierTier.Tier3, isAdditional: true);
				Log.Info(item9 + " registering as Tier3 lunar item");
			}
			AddToSync(list, ModifierTier.Tier1, "_EnemyItem");
			AddToSync(list2, ModifierTier.Tier2, "_EnemyItem");
			AddToSync(list3, ModifierTier.Tier3, "_EnemyItem");
			AddToSync(list4, ModifierTier.Tier1, "_Printer");
			AddToSync(list5, ModifierTier.Tier2, "_Printer");
			AddToSync(list6, ModifierTier.Tier3, "_Printer");
			AddToSync(list7, ModifierTier.Tier1, "_LunarItem");
			AddToSync(list8, ModifierTier.Tier2, "_LunarItem");
			AddToSync(list9, ModifierTier.Tier3, "_LunarItem");
			if (!global::RiskOfRoutes.RiskOfRoutes.allowAurelioniteModifier.Value)
			{
				bannedModifiers.Add("Aurelionite");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowBossRedItemModifier.Value)
			{
				bannedModifiers.Add("BossRedItem");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowBossYellowItemModifier.Value)
			{
				bannedModifiers.Add("BossYellowItem");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowDroneBossGreenModifier.Value)
			{
				bannedModifiers.Add("DroneBossGreen");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowDroneBossRedModifier.Value)
			{
				bannedModifiers.Add("DroneBossRed");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowMoreElitesModifier.Value)
			{
				bannedModifiers.Add("MoreElites");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowMoreDronesModifier.Value)
			{
				bannedModifiers.Add("MoreDrones");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowUpgradeDronesModifier.Value)
			{
				bannedModifiers.Add("UpgradeDrones");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowLunarEnemiesModifier.Value)
			{
				bannedModifiers.Add("LunarEnemies");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowVoidEnemiesModifier.Value)
			{
				bannedModifiers.Add("VoidEnemies");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowYellowPrinterModifier.Value)
			{
				bannedModifiers.Add("YellowPrinter");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowRedPrinterModifier.Value)
			{
				bannedModifiers.Add("RedPrinter");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowOnlyFlyingModifier.Value)
			{
				bannedModifiers.Add("OnlyFlying");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowPowerfulElitesModifier.Value)
			{
				bannedModifiers.Add("PowerfulElites");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowRepairModifier.Value)
			{
				bannedModifiers.Add("Repair");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowWanderingChefModifier.Value)
			{
				bannedModifiers.Add("WanderingChef");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowMountainModifier.Value)
			{
				bannedModifiers.Add("Mountain");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowSoulCostModifier.Value)
			{
				bannedModifiers.Add("SoulCost");
			}
			if (!global::RiskOfRoutes.RiskOfRoutes.allowDoppelgangerModifier.Value)
			{
				bannedModifiers.Add("Doppelganger");
			}
			void AddToSync(List<string> itemNames, ModifierTier tier, string modType)
			{
				foreach (string itemName in itemNames)
				{
					syncNames.Add(itemName + modType);
					syncTiers.Add((int)tier);
				}
			}
		}

		private void Run_onRunDestroyGlobal(Run obj)
		{
			Log.Info(string.Format("{0}: Run ended, clearing {1} modifiers", "Run_onRunDestroyGlobal", activeModifiers.Count));
			foreach (StageModifier activeModifier in activeModifiers)
			{
				if (activeModifier == null)
				{
					Log.Error("Run_onRunDestroyGlobal: Some active modifier is null");
				}
				else
				{
					activeModifier.OnEnd();
				}
			}
			reservedModifiers.Clear();
			runArtifactsApplied.Clear();
			((SyncList<ModifierSync>)(object)modifiersSynced).Clear();
			routeNodesSynced.Clear();
			if (Object.op_Implicit((Object)(object)((Component)this).gameObject))
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				Log.Info("Run_onRunDestroyGlobal: StageModifierDirector destroyed");
			}
			if (Object.op_Implicit((Object)(object)monsterTeamInventory))
			{
				NetworkServer.Destroy(((Component)monsterTeamInventory).gameObject);
			}
			monsterTeamInventory = null;
		}

		private void OnBaseCurseSyncedUpdate(float newValue)
		{
			NetworksyncedBaseCurse = newValue;
			foreach (CharacterMaster readOnlyInstances in CharacterMaster.readOnlyInstancesList)
			{
				if (!((Object)(object)readOnlyInstances.playerCharacterMasterController == (Object)null) && Object.op_Implicit((Object)(object)readOnlyInstances) && Object.op_Implicit((Object)(object)readOnlyInstances.GetBody()))
				{
					readOnlyInstances.GetBody().RecalculateStats();
				}
			}
		}

		public override void OnStartServer()
		{
			((NetworkBehaviour)this).OnStartServer();
		}

		private void CreateDirector(Run run)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			Log.Info("Run started");
			runArtifactsApplied = GetArtifactsAppliedThisRun();
			Log.Info("Creating route map");
			routeMap = new RouteMap(run.runRNG);
			currentNode = routeMap.GetStartingNode();
			currentNode.visited = true;
			NetworkcurrentNodeSync = new Vector2((float)currentNode.x, (float)currentNode.y);
			Log.Info($"Current:{currentNode.x},{currentNode.y} that has {currentNode.GetPaths().Count} paths");
			routeMap.isDirty = true;
		}

		private void OnEnable()
		{
			Stage.onStageStartGlobal += OnStageStartClient;
		}

		private void OnDisable()
		{
			Stage.onStageStartGlobal -= OnStageStartClient;
		}

		private void OnStageStartClient(Stage obj)
		{
			if (!NetworkServer.active)
			{
				Log.Info("OnStageStartClient: on client");
				LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
				NetworkUser val = ((firstLocalUser != null) ? firstLocalUser.currentNetworkUser : null);
				if (!((Object)(object)val == (Object)null))
				{
					Console.instance.SubmitCmd(val, "request_map", false);
				}
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCRequestMap(ConCommandArgs args)
		{
			if ((Object)(object)instance != (Object)null && instance.routeMap != null)
			{
				Log.Info("CCRequestMap: requested the map");
				instance.routeMap.isDirty = true;
			}
		}

		protected virtual void FixedUpdate()
		{
			if (NetworkServer.active && routeMap != null && routeMap.isDirty)
			{
				UpdateRouteMap();
				routeMap.isDirty = false;
			}
		}

		private void UpdateRouteMap()
		{
			Log.Info("UpdateRouteMap: Updating route map");
			int width = routeMap.width;
			int height = routeMap.height;
			RouteNodeSync[] array = new RouteNodeSync[(width + 1) * height];
			for (int i = 0; i < width + 1; i++)
			{
				for (int j = 0; j < height; j++)
				{
					int num = i * height + j;
					if (routeMap.mapGrid[i, j] != null)
					{
						array[num] = new RouteNodeSync(routeMap.mapGrid[i, j]);
					}
					else
					{
						array[num] = new RouteNodeSync(new RouteMap.RouteNode(-1, -1));
					}
				}
			}
			NetworkmapWidth = width;
			NetworkmapHeight = height;
			NetworkisMoonVisited = routeMap.isMoonVisited;
			routeNodesSynced = new List<RouteNodeSync>(array);
			CallRpcReceiveFullMap(array, width, height, routeMap.isMoonVisited, stageEnterTime);
			CallRpcReceiveRunConfiguration(syncNames.ToArray(), syncTiers.ToArray(), punishmentTime, purifyLunarItemModifier, doppelStackTime);
		}

		[ClientRpc]
		private void RpcReceiveFullMap(RouteNodeSync[] map, int width, int height, bool moon, float hostStageEnterTime)
		{
			NetworkmapWidth = width;
			NetworkmapHeight = height;
			NetworkisMoonVisited = moon;
			routeNodesSynced = new List<RouteNodeSync>(map);
			mapState++;
			stageEnterTime = hostStageEnterTime;
			Debug.Log((object)"RpcReceiveFullMap: Got map on client");
		}

		[ClientRpc]
		public void RpcReceiveRunConfiguration(string[] names, int[] tiers, float hostPunishmentTime, bool lunarConfig, int doppel)
		{
			if (NetworkServer.active)
			{
				return;
			}
			Debug.Log((object)"RpcReceiveRunConfiguration: Receiving run configuration.");
			if (hostPunishmentTime != -1f)
			{
				Debug.Log((object)string.Format("{0}: Host has punish time of {1}", "RpcReceiveFullMap", hostPunishmentTime));
			}
			else
			{
				Debug.Log((object)"RpcReceiveFullMap: Host has punish disabled");
			}
			punishmentTime = hostPunishmentTime;
			purifyLunarItemModifier = lunarConfig;
			doppelStackTime = doppel;
			for (int i = 0; i < names.Length; i++)
			{
				string text = names[i];
				int num = tiers[i];
				ModifierTier tier = (ModifierTier)num;
				string text2 = text.Split('_')[0];
				if (text.EndsWith("_EnemyItem"))
				{
					StageModifierCatalog.RegEnemy(text2, tier, isAdditional: true);
					Debug.Log((object)("RpcReceiveRunConfiguration: Registered enemy item " + text2 + " as additional."));
				}
				else if (text.EndsWith("_Printer"))
				{
					StageModifierCatalog.RegPrinter(text2, tier, isAdditional: true);
					Debug.Log((object)("RpcReceiveRunConfiguration: Registered enemy item " + text2 + " as additional."));
				}
				else if (text.EndsWith("_LunarItem"))
				{
					StageModifierCatalog.RegLunar(text2, tier, isAdditional: true);
					Debug.Log((object)("RpcReceiveRunConfiguration: Registered enemy item " + text2 + " as additional."));
				}
			}
		}

		public List<string> GetArtifactsAppliedThisRun()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			List<string> list = new List<string>();
			RunEnabledArtifacts enumerator = RunArtifactManager.enabledArtifactsEnumerable.GetEnumerator();
			try
			{
				while (((RunEnabledArtifacts)(ref enumerator)).MoveNext())
				{
					ArtifactDef current = ((RunEnabledArtifacts)(ref enumerator)).Current;
					list.Add(current.cachedName);
					Log.Info("Added " + current.cachedName);
				}
			}
			finally
			{
				((IDisposable)(RunEnabledArtifacts)(ref enumerator)).Dispose();
			}
			return list;
		}

		private void SceneDirector_onPrePopulateSceneServer(SceneDirector obj)
		{
			Log.Info($"Stage started, applying {reservedModifiers.Count} modifiers");
			if (reservedModifiers.Count == 0)
			{
				return;
			}
			Log.Info(reservedModifiers.Count);
			activeModifiers.Clear();
			foreach (ModifierSync reservedModifier in reservedModifiers)
			{
				StageModifier stageModifier = StageModifierCatalog.StageModifierFromDef(reservedModifier.name, reservedModifier.stack);
				if (stageModifier == null)
				{
					Log.Error("SceneDirector_onPrePopulateSceneServer: Modifier with def " + reservedModifier.name + " is null");
				}
				else
				{
					activeModifiers.Add(stageModifier);
				}
			}
			foreach (ModifierSync reservedModifier2 in reservedModifiers)
			{
				((SyncList<ModifierSync>)(object)modifiersSynced).Add(reservedModifier2);
				if (reservedModifier2.name == "SoulCost")
				{
					Log.Info("Found soulcost");
					NetworksoulCostStack = reservedModifier2.stack;
				}
			}
			foreach (StageModifier activeModifier in activeModifiers)
			{
				activeModifier.OnStart();
			}
			activePortalInstances.Clear();
			reservedModifiers.Clear();
			SceneDef sceneDefForCurrentScene = SceneCatalog.GetSceneDefForCurrentScene();
			stageEnterTime = Run.instance.GetRunStopwatch();
		}

		private void Stage_onServerStageComplete(Stage obj)
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Invalid comparison between Unknown and I4
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			Log.Info($"Stage completed, clearing {activeModifiers.Count} modifiers");
			foreach (StageModifier activeModifier in activeModifiers)
			{
				activeModifier.OnEnd();
			}
			activeModifiers.Clear();
			((SyncList<ModifierSync>)(object)modifiersSynced).Clear();
			Log.Info($"Modul:{Stage.instance.sceneDef.stageOrder}");
			if (Stage.instance.sceneDef.stageOrder == 5 || (currentNode.x == 0 && currentNode.y == 0 && Stage.instance.sceneDef.baseSceneName != "bazaar" && (int)Stage.instance.sceneDef.sceneType == 1))
			{
				Log.Info("Trying to create new map");
				if (Object.op_Implicit((Object)(object)TeleporterInteraction.instance) && TeleporterInteraction.instance.sceneExitController.destinationScene.baseSceneName == "moon2" && TeleporterInteraction.instance.isCharged)
				{
					routeMap.isMoonVisited = true;
				}
				else
				{
					routeMap = new RouteMap(Run.instance.runRNG);
					Log.Info("Created new map");
					currentNode = routeMap.GetStartingNode();
					NetworkcurrentNodeSync = new Vector2((float)currentNode.x, (float)currentNode.y);
					Log.Info($"Current:{currentNode.x},{currentNode.y} that has {currentNode.GetPaths().Count} paths");
					Log.Info($"Teleporter:{TeleporterInteraction.instance.sceneExitController.useRunNextStageScene}");
				}
			}
			else
			{
				Log.Info("Not creating new map yet");
				Log.Info($"\t{currentNode.x}:{currentNode.y}");
				Log.Info($"\t{Stage.instance.sceneDef.stageOrder}");
			}
			currentNode.visited = true;
			routeMap.isDirty = true;
		}

		public void GetNextStageModifiers(GameObject portal)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Invalid comparison between I4 and Unknown
			RoutePortalManager component = portal.GetComponent<RoutePortalManager>();
			if ((Object)(object)component == (Object)null || component.routeNode == null)
			{
				Log.Error("GetNextStageModifiers: Portal doesn't have routePortalManager or RouteNode, couldn't get modifiers.");
				return;
			}
			HashSet<string> hashSet = new HashSet<string>(bannedModifiers);
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			ModifierSlotConfiguration modifierSlots = GetModifierSlots(Run.instance.stageRng, component.routeNode.portalType, hashSet);
			if (SceneHelper.IsSceneColossus((SceneIndex)component.destinationSceneIndex, includeFalseSonScene: false))
			{
				if (!bannedModifiers.Contains("Aurelionite"))
				{
					dictionary.Add("Aurelionite", 1);
					Log.Info("GetNextStageModifiers: Added aurelionite modifier to colossus portal");
				}
				else
				{
					Log.Warning("Not adding aurelionite reward to collosus portal because modifier is banned");
				}
			}
			if (component.destinationSceneIndex == (int)SceneCatalog.FindSceneIndex("conduitcanyon"))
			{
				List<string> list = new List<string> { "UpgradeDrones", "DroneBossRed" };
				dictionary.Add(Run.instance.stageRng.NextElementUniform<string>(list), 1);
				Log.Info("GetNextStageModifiers: Added rare drone modifier to hardware portal");
			}
			if (component.routeNode.portalType == RoutePortalType.ChefType)
			{
				if (!bannedModifiers.Contains("WanderingChef"))
				{
					dictionary.Add("WanderingChef", 1);
					Log.Info("GetNextStageModifiers: Added chef modifier to route portal");
				}
				else
				{
					Log.Warning("Not adding wandering chef to chef portal because modifier is banned");
				}
			}
			if (CheckMountainShrine() && Run.instance.stageRng.nextNormalizedFloat > 0.5f && !bannedModifiers.Contains("Mountain"))
			{
				dictionary.Add("Mountain", TeleporterInteraction.instance.shrineBonusStacks);
			}
			if (CheckPlayersHaveConsumedItems() && Run.instance.stageRng.nextNormalizedFloat > 0.8f && !bannedModifiers.Contains("Repair"))
			{
				dictionary.Add("Repair", 1);
			}
			Dictionary<ModifierTier, int> positive = modifierSlots.positive;
			foreach (KeyValuePair<ModifierTier, int> item in positive)
			{
				for (int i = 0; i < item.Value; i++)
				{
					List<string> pool = StageModifierCatalog.GetPool(component.routeNode.portalType);
					ModifierDef modifierDef = StageModifierCatalog.SelectModifier(hashSet, component.routeNode.portalType, item.Key, pool);
					if (modifierDef == null)
					{
						continue;
					}
					hashSet.Add(modifierDef.name);
					if (modifierDef.conflictList != null)
					{
						foreach (string conflict in modifierDef.conflictList)
						{
							hashSet.Add(conflict);
						}
					}
					int num = CalculateStack(modifierDef, item.Key);
					if (dictionary.ContainsKey(modifierDef.name))
					{
						dictionary[modifierDef.name] += num;
					}
					else
					{
						dictionary.Add(modifierDef.name, num);
					}
				}
			}
			Dictionary<ModifierTier, int> negative = modifierSlots.negative;
			List<ModifierDef> list2 = new List<ModifierDef>();
			foreach (KeyValuePair<ModifierTier, int> item2 in negative)
			{
				for (int j = 0; j < item2.Value; j++)
				{
					List<string> pool2 = StageModifierCatalog.GetPool(component.routeNode.portalType, isNegative: true);
					ModifierDef modifierDef2 = StageModifierCatalog.SelectModifier(hashSet, component.routeNode.portalType, item2.Key, pool2);
					if (modifierDef2 == null)
					{
						continue;
					}
					hashSet.Add(modifierDef2.name);
					if (modifierDef2.conflictList != null)
					{
						foreach (string conflict2 in modifierDef2.conflictList)
						{
							hashSet.Add(conflict2);
						}
					}
					int num2 = CalculateStack(modifierDef2, item2.Key);
					if (dictionary.ContainsKey(modifierDef2.name))
					{
						dictionary[modifierDef2.name] += num2;
						continue;
					}
					dictionary.Add(modifierDef2.name, num2);
					list2.Add(modifierDef2);
				}
			}
			int num3 = (int)((Run.instance.GetRunStopwatch() - stageEnterTime) / (punishmentTime * 60f));
			num3 += commandAddedStack;
			if (num3 > 0)
			{
				Log.Info(string.Format("{0}: Adding {1} punishment stacks", "GetNextStageModifiers", num3));
			}
			IEnumerable<ModifierDef> source = list2.Where((ModifierDef s) => s.IsStackable());
			if (num3 > 0)
			{
				if (source.Count() == 0)
				{
					Log.Warning("GetNextStageModifiers: There are no stackable negative modifiers to apply punish, adding new");
					List<string> pool3 = StageModifierCatalog.GetPool(component.routeNode.portalType, isNegative: true);
					while (num3 > 0)
					{
						int num4 = Mathf.Min(num3, 3);
						int num5 = Run.instance.stageRng.RangeInt(1, num4 + 1);
						ModifierTier tier = (ModifierTier)num5;
						ModifierDef modifierDef3 = StageModifierCatalog.SelectModifier(hashSet, component.routeNode.portalType, tier, pool3);
						while (modifierDef3 == null && num5 > 1)
						{
							num5--;
							tier = (ModifierTier)num5;
							modifierDef3 = StageModifierCatalog.SelectModifier(hashSet, component.routeNode.portalType, tier, pool3);
						}
						if (modifierDef3 == null)
						{
							Log.Warning("GetNextStageModifiers: Couldnt add new negative modifiers");
							break;
						}
						hashSet.Add(modifierDef3.name);
						if (modifierDef3.conflictList != null)
						{
							foreach (string conflict3 in modifierDef3.conflictList)
							{
								hashSet.Add(conflict3);
							}
						}
						num3 -= num5;
						int num6 = 0;
						if (num3 > 0 && modifierDef3.IsStackable())
						{
							num6 = Run.instance.stageRng.RangeInt(0, num3 + 1);
							num3 -= num6;
						}
						dictionary.Add(modifierDef3.name, 1 + num6);
						Log.Info(string.Format("{0}: Punish added new modifier {1} with stack {2}", "GetNextStageModifiers", modifierDef3.name, 1 + num6));
					}
				}
				else
				{
					for (int k = 0; k < num3; k++)
					{
						ModifierDef modifierDef4 = Run.instance.stageRng.NextElementUniform<ModifierDef>(source.ToArray());
						if (dictionary.ContainsKey(modifierDef4.name))
						{
							dictionary[modifierDef4.name]++;
							Log.Info("GetNextStageModifiers: Added 1 additional stack to " + modifierDef4.name);
						}
					}
				}
			}
			List<ModifierSync> list3 = new List<ModifierSync>();
			foreach (KeyValuePair<string, int> item3 in dictionary)
			{
				ModifierDef modifierDef5 = StageModifierCatalog.FindModifier(item3.Key);
				if (modifierDef5 == null)
				{
					return;
				}
				list3.Add(new ModifierSync(modifierDef5, item3.Value));
			}
			((SyncList<string>)(object)component.stageModifiers).Clear();
			foreach (ModifierSync item4 in list3)
			{
				((SyncList<string>)(object)component.stageModifiers).Add($"{item4.name}={item4.stack}={item4.isArtifact}");
			}
		}

		private int CalculateStack(ModifierDef def, ModifierTier targetTier)
		{
			ModifierTier tier = def.tier;
			if (tier == targetTier)
			{
				return 1;
			}
			if ((tier == ModifierTier.Tier1 && targetTier == ModifierTier.Tier2) || (tier == ModifierTier.Tier2 && targetTier == ModifierTier.Tier3))
			{
				return 2;
			}
			if (tier == ModifierTier.Tier1 && targetTier == ModifierTier.Tier3)
			{
				return 3;
			}
			return 1;
		}

		public static ModifierSlotConfiguration GetModifierSlots(Xoroshiro128Plus rng, RoutePortalType type, HashSet<string> banned)
		{
			WeightedSelection<ModifierSlotConfiguration> val = new WeightedSelection<ModifierSlotConfiguration>(8);
			if (type != RoutePortalType.Rare)
			{
				val.AddChoice(new ModifierSlotConfiguration
				{
					positive = { 
					{
						ModifierTier.Tier1,
						1
					} },
					negative = { 
					{
						ModifierTier.Tier1,
						1
					} }
				}, 1f);
				val.AddChoice(new ModifierSlotConfiguration
				{
					positive = { 
					{
						ModifierTier.Tier1,
						2
					} },
					negative = { 
					{
						ModifierTier.Tier2,
						1
					} }
				}, 1f);
				val.AddChoice(new ModifierSlotConfiguration
				{
					positive = { 
					{
						ModifierTier.Tier2,
						1
					} },
					negative = { 
					{
						ModifierTier.Tier1,
						2
					} }
				}, 1f);
			}
			val.AddChoice(new ModifierSlotConfiguration
			{
				positive = { 
				{
					ModifierTier.Tier3,
					1
				} },
				negative = { 
				{
					ModifierTier.Tier3,
					1
				} }
			}, 0.3f);
			val.AddChoice(new ModifierSlotConfiguration
			{
				positive = { 
				{
					ModifierTier.Tier3,
					1
				} },
				negative = 
				{
					{
						ModifierTier.Tier2,
						1
					},
					{
						ModifierTier.Tier1,
						1
					}
				}
			}, 0.3f);
			ModifierSlotConfiguration modifierSlotConfiguration = val.Evaluate(rng.nextNormalizedFloat);
			if (modifierSlotConfiguration.positive.ContainsKey(ModifierTier.Tier3))
			{
				List<string> pool = StageModifierCatalog.GetPool(type);
				if (StageModifierCatalog.SelectModifier(banned, type, ModifierTier.Tier3, pool) == null)
				{
					Log.Warning(string.Format("{0}: Couldnt get Tier3 modifier for node type {1}, using Tier2", "GetModifierSlots", type));
					modifierSlotConfiguration.positive.Remove(ModifierTier.Tier2);
					if (modifierSlotConfiguration.positive.ContainsKey(ModifierTier.Tier2))
					{
						modifierSlotConfiguration.positive[ModifierTier.Tier2] = modifierSlotConfiguration.positive[ModifierTier.Tier2] + 1;
					}
					else
					{
						modifierSlotConfiguration.positive.Add(ModifierTier.Tier2, 2);
					}
				}
			}
			foreach (KeyValuePair<ModifierTier, int> item in modifierSlotConfiguration.positive)
			{
			}
			foreach (KeyValuePair<ModifierTier, int> item2 in modifierSlotConfiguration.negative)
			{
			}
			return modifierSlotConfiguration;
		}

		public bool IsModifierActive(string name)
		{
			foreach (ModifierSync item in (SyncList<ModifierSync>)(object)modifiersSynced)
			{
				if (item.name == name)
				{
					return true;
				}
			}
			return false;
		}

		public void AddRoutePortalInstance(GameObject portal)
		{
			if ((Object)(object)portal == (Object)null)
			{
				Log.Error("AddRoutePortalInstance: Route portal is null, cant add instance");
				return;
			}
			RoutePortalManager component = portal.GetComponent<RoutePortalManager>();
			if ((Object)(object)component == (Object)null)
			{
				Log.Error("AddRoutePortalInstance: Route portal manager is null, cant add instance");
			}
			activePortalInstances.Add(portal);
		}

		public void GetModifiersFromRandomPortal()
		{
			if (activePortalInstances == null || activePortalInstances.Count == 0)
			{
				Log.Warning("GetModifiersFromRandomPortal: There are no portal instances to get modifiers from");
				return;
			}
			GameObject val = Run.instance.stageRng.NextElementUniform<GameObject>(activePortalInstances);
			RoutePortalManager component = val.GetComponent<RoutePortalManager>();
			if ((Object)(object)component == (Object)null)
			{
				Log.Warning("GetModifiersFromRandomPortal: Route portal manager is null, cant get modifiers");
				return;
			}
			reservedModifiers.Clear();
			foreach (string item in (SyncList<string>)(object)component.stageModifiers)
			{
				string[] array = item.Split('=');
				instance.reservedModifiers.Add(new ModifierSync
				{
					name = array[0],
					stack = int.Parse(array[1])
				});
			}
			foreach (GameObject activePortalInstance in activePortalInstances)
			{
				GenericInteraction component2 = activePortalInstance.GetComponent<GenericInteraction>();
				if ((Object)(object)component2 != (Object)null)
				{
					((Behaviour)component2).enabled = false;
				}
			}
		}

		public void GetRouteNodeFromRandomPortal()
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			if (activePortalInstances == null || activePortalInstances.Count == 0)
			{
				Log.Warning("GetRouteNodeFromRandomPortal: There are no portal active instances to get routeNode from");
				return;
			}
			Log.Info(string.Format("{0}: Trying to get routeNode from {1} portal instances", "GetRouteNodeFromRandomPortal", activePortalInstances.Count));
			GameObject val = Run.instance.stageRng.NextElementUniform<GameObject>(activePortalInstances);
			RoutePortalManager component = val.GetComponent<RoutePortalManager>();
			if ((Object)(object)component == (Object)null)
			{
				Log.Warning("GetRouteNodeFromRandomPortal: Selected portal instance missing RoutePortalManager");
				return;
			}
			currentNode = component.routeNode;
			NetworkcurrentNodeSync = new Vector2((float)currentNode.x, (float)currentNode.y);
			foreach (GameObject activePortalInstance in activePortalInstances)
			{
				GenericInteraction component2 = activePortalInstance.GetComponent<GenericInteraction>();
				if ((Object)(object)component2 != (Object)null)
				{
					((Behaviour)component2).enabled = false;
				}
			}
		}

		[Server]
		public bool CheckPlayersRedItem()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0086: Invalid comparison between Unknown and I4
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Boolean SamplePlugin.StageModifierDirector::CheckPlayersRedItem()' called on client");
				return false;
			}
			int num = 0;
			foreach (CharacterMaster readOnlyInstances in CharacterMaster.readOnlyInstancesList)
			{
				if ((Object)(object)readOnlyInstances.playerCharacterMasterController == (Object)null)
				{
					continue;
				}
				foreach (ItemIndex item in readOnlyInstances.inventory.itemAcquisitionOrder)
				{
					ItemDef itemDef = ItemCatalog.GetItemDef(item);
					if ((Object)(object)itemDef != (Object)null && (int)itemDef.tier == 2)
					{
						num += readOnlyInstances.inventory.GetItemCount(item);
						Log.Info(string.Format("{0}: Found red item:{1}", "CheckPlayersRedItem", itemDef));
					}
				}
			}
			return num > 0;
		}

		[Server]
		public bool CheckPlayersYellowItem()
		{
			//IL_0077: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Invalid comparison between Unknown and I4
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Boolean SamplePlugin.StageModifierDirector::CheckPlayersYellowItem()' called on client");
				return false;
			}
			int num = 0;
			foreach (CharacterMaster readOnlyInstances in CharacterMaster.readOnlyInstancesList)
			{
				if ((Object)(object)readOnlyInstances.playerCharacterMasterController == (Object)null || !Object.op_Implicit((Object)(object)readOnlyInstances.inventory))
				{
					continue;
				}
				foreach (ItemIndex item in readOnlyInstances.inventory.itemAcquisitionOrder)
				{
					ItemDef itemDef = ItemCatalog.GetItemDef(item);
					if ((Object)(object)itemDef != (Object)null && (int)itemDef.tier == 4)
					{
						num += readOnlyInstances.inventory.GetItemCount(item);
						Log.Info(string.Format("{0}: Found yellow item:{1}", "CheckPlayersYellowItem", itemDef));
					}
				}
			}
			return num > 0;
		}

		[Server]
		public bool CheckPlayersHaveConsumedItems()
		{
			//IL_0077: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Boolean SamplePlugin.StageModifierDirector::CheckPlayersHaveConsumedItems()' called on client");
				return false;
			}
			int num = 0;
			foreach (CharacterMaster readOnlyInstances in CharacterMaster.readOnlyInstancesList)
			{
				if ((Object)(object)readOnlyInstances.playerCharacterMasterController == (Object)null || !Object.op_Implicit((Object)(object)readOnlyInstances.inventory))
				{
					continue;
				}
				foreach (ItemIndex item in readOnlyInstances.inventory.itemAcquisitionOrder)
				{
					ItemDef itemDef = ItemCatalog.GetItemDef(item);
					if ((Object)(object)itemDef != (Object)null && itemDef.isConsumed && (Object)(object)itemDef != (Object)(object)Items.RegeneratingScrapConsumed && (Object)(object)itemDef != (Object)(object)Items.LowerPricedChestsConsumed && (Object)(object)itemDef != (Object)(object)Items.TeleportOnLowHealthConsumed)
					{
						num++;
					}
				}
			}
			return num > 0;
		}

		[Server]
		public bool CheckMountainShrine()
		{
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Boolean SamplePlugin.StageModifierDirector::CheckMountainShrine()' called on client");
				return false;
			}
			if (Object.op_Implicit((Object)(object)TeleporterInteraction.instance))
			{
				return TeleporterInteraction.instance.shrineBonusStacks > 0;
			}
			return false;
		}

		[Server]
		public bool CheckArtifactOfDeathAvailable()
		{
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Boolean SamplePlugin.StageModifierDirector::CheckArtifactOfDeathAvailable()' called on client");
				return false;
			}
			return Run.instance.participatingPlayerCount > 1 && !runArtifactsApplied.Contains("TeamDeath");
		}

		[Server]
		public bool CheckArtifactAvailable(string name)
		{
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Boolean SamplePlugin.StageModifierDirector::CheckArtifactAvailable(System.String)' called on client");
				return false;
			}
			return !runArtifactsApplied.Contains(name);
		}

		[Server]
		public int CheckPlayersHaveFoodItems()
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Int32 SamplePlugin.StageModifierDirector::CheckPlayersHaveFoodItems()' called on client");
				return 0;
			}
			List<ItemDef> list = new List<ItemDef>
			{
				Items.FlatHealth,
				Items.Mushroom,
				Items.Infusion,
				Items.HealWhileSafe,
				Items.MushroomVoid
			};
			int num = 0;
			foreach (CharacterMaster readOnlyInstances in CharacterMaster.readOnlyInstancesList)
			{
				if ((Object)(object)readOnlyInstances.playerCharacterMasterController == (Object)null || !Object.op_Implicit((Object)(object)readOnlyInstances.inventory))
				{
					continue;
				}
				foreach (ItemIndex item in readOnlyInstances.inventory.itemAcquisitionOrder)
				{
					ItemDef itemDef = ItemCatalog.GetItemDef(item);
					if ((Object)(object)itemDef != (Object)null && list.Contains(itemDef))
					{
						num += readOnlyInstances.inventory.GetItemCount(itemDef);
					}
				}
			}
			Log.Info($"Players have {num} food related items right now");
			return num;
		}

		public List<RouteMap.RouteNode> GetAvailableNodes()
		{
			if (currentNode != null)
			{
				return currentNode.GetPaths();
			}
			Log.Error("GetAvailableNodes: Current node is null");
			return null;
		}

		private void UNetVersion()
		{
		}

		protected static void InvokeSyncListmodifiersSynced(NetworkBehaviour obj, NetworkReader reader)
		{
			if (!NetworkClient.active)
			{
				Debug.LogError((object)"SyncList modifiersSynced called on server.");
			}
			else
			{
				((SyncList<ModifierSync>)(object)((StageModifierDirector)(object)obj).modifiersSynced).HandleMsg(reader);
			}
		}

		protected static void InvokeRpcRpcReceiveFullMap(NetworkBehaviour obj, NetworkReader reader)
		{
			if (!NetworkClient.active)
			{
				Debug.LogError((object)"RPC RpcReceiveFullMap called on server.");
			}
			else
			{
				((StageModifierDirector)(object)obj).RpcReceiveFullMap(GeneratedNetworkCode._ReadArrayRouteNodeSync_None(reader), (int)reader.ReadPackedUInt32(), (int)reader.ReadPackedUInt32(), reader.ReadBoolean(), reader.ReadSingle());
			}
		}

		protected static void InvokeRpcRpcReceiveRunConfiguration(NetworkBehaviour obj, NetworkReader reader)
		{
			if (!NetworkClient.active)
			{
				Debug.LogError((object)"RPC RpcReceiveRunConfiguration called on server.");
			}
			else
			{
				((StageModifierDirector)(object)obj).RpcReceiveRunConfiguration(GeneratedNetworkCode._ReadArrayString_None(reader), GeneratedNetworkCode._ReadArrayInt32_None(reader), reader.ReadSingle(), reader.ReadBoolean(), (int)reader.ReadPackedUInt32());
			}
		}

		public void CallRpcReceiveFullMap(RouteNodeSync[] map, int width, int height, bool moon, float hostStageEnterTime)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogError((object)"RPC Function RpcReceiveFullMap called on client.");
				return;
			}
			NetworkWriter val = new NetworkWriter();
			val.Write((short)0);
			val.Write((short)2);
			val.WritePackedUInt32((uint)kRpcRpcReceiveFullMap);
			val.Write(((Component)this).GetComponent<NetworkIdentity>().netId);
			GeneratedNetworkCode._WriteArrayRouteNodeSync_None(val, map);
			val.WritePackedUInt32((uint)width);
			val.WritePackedUInt32((uint)height);
			val.Write(moon);
			val.Write(hostStageEnterTime);
			((NetworkBehaviour)this).SendRPCInternal(val, 0, "RpcReceiveFullMap");
		}

		public void CallRpcReceiveRunConfiguration(string[] names, int[] tiers, float hostPunishmentTime, bool lunarConfig, int doppel)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogError((object)"RPC Function RpcReceiveRunConfiguration called on client.");
				return;
			}
			NetworkWriter val = new NetworkWriter();
			val.Write((short)0);
			val.Write((short)2);
			val.WritePackedUInt32((uint)kRpcRpcReceiveRunConfiguration);
			val.Write(((Component)this).GetComponent<NetworkIdentity>().netId);
			GeneratedNetworkCode._WriteArrayString_None(val, names);
			GeneratedNetworkCode._WriteArrayInt32_None(val, tiers);
			val.Write(hostPunishmentTime);
			val.Write(lunarConfig);
			val.WritePackedUInt32((uint)doppel);
			((NetworkBehaviour)this).SendRPCInternal(val, 0, "RpcReceiveRunConfiguration");
		}

		static StageModifierDirector()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			kRpcRpcReceiveFullMap = -1012231583;
			NetworkBehaviour.RegisterRpcDelegate(typeof(StageModifierDirector), kRpcRpcReceiveFullMap, new CmdDelegate(InvokeRpcRpcReceiveFullMap));
			kRpcRpcReceiveRunConfiguration = -321686377;
			NetworkBehaviour.RegisterRpcDelegate(typeof(StageModifierDirector), kRpcRpcReceiveRunConfiguration, new CmdDelegate(InvokeRpcRpcReceiveRunConfiguration));
			kListmodifiersSynced = -163976013;
			NetworkBehaviour.RegisterSyncListDelegate(typeof(StageModifierDirector), kListmodifiersSynced, new CmdDelegate(InvokeSyncListmodifiersSynced));
			NetworkCRC.RegisterBehaviour("StageModifierDirector", 0);
		}

		public override bool OnSerialize(NetworkWriter writer, bool forceAll)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			if (forceAll)
			{
				GeneratedNetworkCode._WriteStructSyncListModifier_None(writer, modifiersSynced);
				writer.WritePackedUInt32((uint)mapWidth);
				writer.WritePackedUInt32((uint)mapHeight);
				writer.Write(isMoonVisited);
				writer.Write(currentNodeSync);
				writer.Write(syncedBaseCurse);
				writer.WritePackedUInt32((uint)soulCostStack);
				return true;
			}
			bool flag = false;
			if ((((NetworkBehaviour)this).syncVarDirtyBits & (true ? 1u : 0u)) != 0)
			{
				if (!flag)
				{
					writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
					flag = true;
				}
				GeneratedNetworkCode._WriteStructSyncListModifier_None(writer, modifiersSynced);
			}
			if ((((NetworkBehaviour)this).syncVarDirtyBits & 2u) != 0)
			{
				if (!flag)
				{
					writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
					flag = true;
				}
				writer.WritePackedUInt32((uint)mapWidth);
			}
			if ((((NetworkBehaviour)this).syncVarDirtyBits & 4u) != 0)
			{
				if (!flag)
				{
					writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
					flag = true;
				}
				writer.WritePackedUInt32((uint)mapHeight);
			}
			if ((((NetworkBehaviour)this).syncVarDirtyBits & 8u) != 0)
			{
				if (!flag)
				{
					writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
					flag = true;
				}
				writer.Write(isMoonVisited);
			}
			if ((((NetworkBehaviour)this).syncVarDirtyBits & 0x10u) != 0)
			{
				if (!flag)
				{
					writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
					flag = true;
				}
				writer.Write(currentNodeSync);
			}
			if ((((NetworkBehaviour)this).syncVarDirtyBits & 0x20u) != 0)
			{
				if (!flag)
				{
					writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
					flag = true;
				}
				writer.Write(syncedBaseCurse);
			}
			if ((((NetworkBehaviour)this).syncVarDirtyBits & 0x40u) != 0)
			{
				if (!flag)
				{
					writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
					flag = true;
				}
				writer.WritePackedUInt32((uint)soulCostStack);
			}
			if (!flag)
			{
				writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
			}
			return flag;
		}

		public override void OnDeserialize(NetworkReader reader, bool initialState)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			if (initialState)
			{
				GeneratedNetworkCode._ReadStructSyncListModifier_None(reader, modifiersSynced);
				mapWidth = (int)reader.ReadPackedUInt32();
				mapHeight = (int)reader.ReadPackedUInt32();
				isMoonVisited = reader.ReadBoolean();
				currentNodeSync = reader.ReadVector2();
				syncedBaseCurse = reader.ReadSingle();
				soulCostStack = (int)reader.ReadPackedUInt32();
				return;
			}
			int num = (int)reader.ReadPackedUInt32();
			if (((uint)num & (true ? 1u : 0u)) != 0)
			{
				GeneratedNetworkCode._ReadStructSyncListModifier_None(reader, modifiersSynced);
			}
			if (((uint)num & 2u) != 0)
			{
				mapWidth = (int)reader.ReadPackedUInt32();
			}
			if (((uint)num & 4u) != 0)
			{
				mapHeight = (int)reader.ReadPackedUInt32();
			}
			if (((uint)num & 8u) != 0)
			{
				isMoonVisited = reader.ReadBoolean();
			}
			if (((uint)num & 0x10u) != 0)
			{
				currentNodeSync = reader.ReadVector2();
			}
			if (((uint)num & 0x20u) != 0)
			{
				OnBaseCurseSyncedUpdate(reader.ReadSingle());
			}
			if (((uint)num & 0x40u) != 0)
			{
				soulCostStack = (int)reader.ReadPackedUInt32();
			}
		}
	}
}
namespace SamplePlugin.StageModifiers
{
	[Serializable]
	public abstract class StageModifier
	{
		public int stack = 1;

		public abstract void OnStart();

		public abstract void OnEnd();

		protected GameObject TryPlaceObjectOnScene(SpawnCard spawnCard, string name = "object")
		{
			//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)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Log.Error("SERVER IS NOT ACTIVE");
				return null;
			}
			if ((Object)(object)spawnCard == (Object)null)
			{
				Log.Error("Something went wrong with " + name + " spawncard");
				return null;
			}
			if (!Object.op_Implicit((Object)(object)Run.instance))
			{
				return null;
			}
			Log.Info("Trying to place " + name);
			GameObject val = null;
			for (int i = 0; i < 15; i++)
			{
				DirectorPlacementRule val2 = new DirectorPlacementRule
				{
					placementMode = (PlacementMode)4
				};
				val = DirectorCore.instance.TrySpawnObject(new DirectorSpawnRequest(spawnCard, val2, Run.instance.stageRng));
				if (Object.op_Implicit((Object)(object)val))
				{
					Log.Info($"Succesfully placed {name} on {val.transform.position}");
					break;
				}
				Log.Error("Failed to place " + name + ", retrying");
			}
			if ((Object)(object)val == (Object)null)
			{
				Log.Error("It was impossible to place " + name);
			}
			return val;
		}
	}
}
namespace SamplePlugin.StageModifiers.SceneModifiers
{
	public class MoreDronesModifier : StageModifier
	{
		public MoreDronesModifier(int stack)
		{
			base.stack = stack;
		}

		public override void OnEnd()
		{
			Log.Info("MoreDronesModifier end");
		}

		public override void OnStart()
		{
			Log.Info("MoreDronesModifier start");
			PopulateDrones();
		}

		public void PopulateDrones()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Invalid comparison between Unknown and I4
			int num = 0;
			int sceneDirectorInteractibleCredits = ClassicStageInfo.instance.sceneDirectorInteractibleCredits;
			float num2 = (float)global::RiskOfRoutes.RiskOfRoutes.droneStackPercent.Value / 100f;
			Log.Info($"Drone stack percent is {num2}");
			int num3 = (int)((float)(sceneDirectorInteractibleCredits * stack) * num2);
			Log.Info("Spawning more drones");
			ClassicStageInfo instance = ClassicStageInfo.instance;
			WeightedSelection<DirectorCard> val = new WeightedSelection<DirectorCard>(8);
			Category val2 = ((IEnumerable<Category>)instance.interactableCategories.categories).FirstOrDefault((Func<Category, bool>)((Category c) => c.name == "Drones"));
			if (val2.cards.Length == 0)
			{
				Log.Error("No drones available on stage");
			}
			DirectorCard[] cards = val2.cards;
			foreach (DirectorCard val3 in cards)
			{
				if (val3.IsAvailable())
				{
					val.AddChoice(val3, (float)val3.selectionWeight);
				}
			}
			int num4 = 100;
			while (num3 > 0 && num4 > 0)
			{
				DirectorCard val4 = SelectCard(val, num3);
				if (val4 == null)
				{
					break;
				}
				if (!val4.IsAvailable())
				{
					continue;
				}
				GameObject val5 = TryPlaceObjectOnScene(val4.spawnCard, ((Object)val4.spawnCard).name);
				if ((Object)(object)val5 != (Object)null)
				{
					PurchaseInteraction component = val5.GetComponent<PurchaseInteraction>();
					if (Object.op_Implicit((Object)(object)component) && (int)component.costType == 1)
					{
						component.Networkcost = Run.instance.GetDifficultyScaledCost(component.cost);
					}
					num3 -= val4.cost;
					num++;
				}
				num4--;
			}
			Log.Info($"Spawned {num} more drones");
		}

		private static DirectorCard SelectCard(WeightedSelection<DirectorCard> deck, int maxCost)
		{
			//IL_0016: 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)
			//IL_001c: 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)
			WeightedSelection<DirectorCard> val = new WeightedSelection<DirectorCard>(maxCost);
			int i = 0;
			for (int count = deck.Count; i < count; i++)
			{
				ChoiceInfo<DirectorCard> choice = deck.GetChoice(i);
				if (choice.value.cost <= maxCost)
				{
					val.AddChoice(choice);
				}
			}
			if (val.Count == 0)
			{
				return null;
			}
			return val.Evaluate(Run.instance.stageRng.nextNormalizedFloat);
		}
	}
	public class PrinterItemModifier : StageModifier
	{
		public ItemDef selectedItem;

		public static InteractableSpawnCard printerSpawnCard;

		public PrinterItemModifier(string internalName)
		{
			selectedItem = stringToItemDef(internalName);
			if (!((Object)(object)selectedItem == (Object)null))
			{
				CreatePrinterSpawnCard();
			}
		}

		public static ItemDef stringToItemDef(string selectedItemName)
		{
			//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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			ItemIndex val = ItemCatalog.FindItemIndex(selectedItemName);
			if ((int)val != -1)
			{
				return ItemCatalog.GetItemDef(val);
			}
			Log.Error("Error finding item");
			return null;
		}

		public override void OnEnd()
		{
			Log.Info("PrinterItemModifier end");
		}

		public override void OnStart()
		{
			Log.Info("PrinterItemModifier start");
			SpawnPrinter();
		}

		private void SpawnPrinter()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_0094: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = TryPlaceObjectOnScene((SpawnCard)(object)printerSpawnCard, "Printer with " + ((Object)selectedItem).name);
			if (Object.op_Implicit((Object)(object)val))
			{
				Log.Info($"printer appeared at {val.transform.position} on stage");
				ShopTerminalBehavior component = val.GetComponent<ShopTerminalBehavior>();
				component.dropTable = null;
				component.selfGeneratePickup = false;
				component.itemTier = selectedItem.tier;
				PickupIndex pickupIndex = PickupCatalog.FindPickupIndex(selectedItem.itemIndex);
				UniquePickup val2 = default(UniquePickup);
				val2.pickupIndex = pickupIndex;
				UniquePickup val3 = val2;
				component.SetPickup(val3, false);
			}
		}

		private void CreatePrinterSpawnCard()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_002b: Expected I4, but got Unknown
			ItemTier tier = selectedItem.tier;
			if (1 == 0)
			{
			}
			InteractableSpawnCard val = (InteractableSpawnCard)((int)tier switch
			{
				0 => AssetManager.tier1Printer, 
				1 => AssetManager.tier2Printer, 
				2 => AssetManager.tier3Printer, 
				4 => AssetManager.bossPrinter, 
				_ => AssetManager.tier1Printer, 
			});
			if (1 == 0)
			{
			}
			InteractableSpawnCard val2 = val;
			if ((Object)(object)val2 != (Object)null)
			{
				printerSpawnCard = val2;
			}
			else
			{
				Log.Info("Asset path is invalid");
			}
		}
	}
	public class RedPrinterModifier : StageModifier
	{
		public static InteractableSpawnCard redPrinterSpawnCard;

		public ItemTag tag;

		public RedPrinterModifier(int stack, ItemTag tag = 0)
		{
			//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)
			CreateRedPrinterSpawnCard();
			base.stack = stack;
			this.tag = tag;
		}

		public override void OnEnd()
		{
			Log.Info("RedPrinterModifier end");
		}

		public override void OnStart()
		{
			Log.Info("RedPrinterModifier start");
			SpawnRedPrinter();
		}

		private void SpawnRedPrinter()
		{
			//IL_001e: 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)
			//IL_0025: 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_0039: Invalid comparison between Unknown and I4
			//IL_00b7: 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_0068: 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_011e: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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)
			List<PickupIndex> availableTier3DropList = Run.instance.availableTier3DropList;
			List<PickupIndex> list = new List<PickupIndex>();
			foreach (PickupIndex item in availableTier3DropList)
			{
				PickupDef pickupDef = PickupCatalog.GetPickupDef(item);
				if (pickupDef != null && (int)pickupDef.itemIndex != -1)
				{
					ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex);
					if ((Object)(object)itemDef != (Object)null && itemDef.tags.Contains(tag))
					{
						list.Add(item);
					}
				}
			}
			if (list.Count == 0)
			{
				Log.Error($"No red items available for tag {tag}");
				list = availableTier3DropList;
			}
			for (int i = 0; i < stack; i++)
			{
				GameObject val = TryPlaceObjectOnScene((SpawnCard)(object)redPrinterSpawnCard, "Red item printer");
				if (Object.op_Implicit((Object)(object)val))
				{
					ShopTerminalBehavior component = val.GetComponent<ShopTerminalBehavior>();
					component.dropTable = null;
					component.selfGeneratePickup = false;
					PickupIndex pickupIndex = Run.instance.stageRng.NextElementUniform<PickupIndex>(list);
					UniquePickup val2 = default(UniquePickup);
					val2.pickupIndex = pickupIndex;
					UniquePickup val3 = val2;
					component.SetPickup(val3, false);
				}
			}
		}

		private void CreateRedPrinterSpawnCard()
		{
			InteractableSpawnCard tier3Printer = AssetManager.tier3Printer;
			if ((Object)(object)tier3Printer != (Object)null)
			{
				redPrinterSpawnCard = tier3Printer;
			}
		}
	}
	public class WanderingChefModifier : StageModifier
	{
		public static bool spawnCardCreated;

		public static InteractableSpawnCard chefSpawnCard;

		public override void OnEnd()
		{
		}

		public override void OnStart()
		{
			SpawnWanderingChef();
		}

		private void SpawnWanderingChef()
		{
			//IL_0026: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			InteractableSpawnCard wanderingChefSpawnCard = AssetManager.wanderingChefSpawnCard;
			GameObject val = TryPlaceObjectOnScene((SpawnCard)(object)wanderingChefSpawnCard, "Wandering Chef");
			if (Object.op_Implicit((Object)(object)val))
			{
				Transform transform = val.transform;
				transform.position += val.transform.up * 1f;
			}
		}
	}
	public class YellowPrinterModifier : StageModifier
	{
		public static InteractableSpawnCard yellowPrinterSpawnCard;

		public ItemTag tag;

		public YellowPrinterModifier(int stack, ItemTag tag = 0)
		{
			//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)
			CreateYellowPrinterSpawnCard();
			base.stack = stack;
			this.tag = tag;
		}

		public override void OnEnd()
		{
			Log.Info("YellowPrinterModifier end");
		}

		public override void OnStart()
		{
			Log.Info("YellowPrinterModifier start");
			SpawnYellowPrinter();
		}

		private void SpawnYellowPrinter()
		{
			//IL_001e: 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)
			//IL_0025: 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_0039: Invalid comparison between Unknown and I4
			//IL_00b7: 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_0068: 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_011e: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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)
			List<PickupIndex> availableBossDropList = Run.instance.availableBossDropList;
			List<PickupIndex> list = new List<PickupIndex>();
			foreach (PickupIndex item in availableBossDropList)
			{
				PickupDef pickupDef = PickupCatalog.GetPickupDef(item);
				if (pickupDef != null && (int)pickupDef.itemIndex != -1)
				{
					ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex);
					if ((Object)(object)itemDef != (Object)null && itemDef.tags.Contains(tag))
					{
						list.Add(item);
					}
				}
			}
			if (list.Count == 0)
			{
				Log.Error($"No yellow items available for tag {tag}");
				list = availableBossDropList;
			}
			for (int i = 0; i < stack; i++)
			{
				GameObject val = TryPlaceObjectOnScene((SpawnCard)(object)yellowPrinterSpawnCard, "Yellow item printer");
				if (Object.op_Implicit((Object)(object)val))
				{
					ShopTerminalBehavior component = val.GetComponent<ShopTerminalBehavior>();
					component.dropTable = null;
					component.selfGeneratePickup = false;
					PickupIndex pickupIndex = Run.instance.stageRng.NextElementUniform<PickupIndex>(list);
					UniquePickup val2 = default(UniquePickup);
					val2.pickupIndex = pickupIndex;
					UniquePickup val3 = val2;
					component.SetPickup(val3, false);
				}
			}
		}

		private void CreateYellowPrinterSpawnCard()
		{
			//IL_0006: 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)
			InteractableSpawnCard val = Addressables.LoadAssetAsync<InteractableSpawnCard>((object)"RoR2/Base/DuplicatorWild/iscDuplicatorWild.asset").WaitForCompletion();
			if ((Object)(object)val != (Object)null)
			{
				yellowPrinterSpawnCard = val;
			}
			else
			{
				Log.Info("Asset path is invalid");
			}
		}
	}
}
namespace SamplePlugin.StageModifiers.OtherModifiers
{
	public class ArtifactModifier : StageModifier
	{
		private ArtifactDef currentArtifact;

		public ArtifactModifier(ArtifactDef artifact, bool isPositive)
		{
			currentArtifact = artifact;
		}

		public ArtifactModifier(string name, bool isPositive)
		{
			currentArtifact = ArtifactCatalog.FindArtifactDef(name);
			if ((Object)(object)currentArtifact == (Object)null)
			{
				Log.Error("Could not find artifact by the name " + name);
			}
			else
			{
				name = currentArtifact.cachedName;
			}
		}

		public ArtifactModifier()
		{
			currentArtifact = Artifacts.MixEnemy;
			if ((Object)(object)currentArtifact == (Object)null)
			{
				Log.Error("CurrentArtifact is null");
			}
		}

		public override void OnEnd()
		{
			Log.Info("On artifactModifier end");
			if (Object.op_Implicit((Object)(object)currentArtifact))
			{
				if (Object.op_Implicit((Object)(object)Run.instance))
				{
					RunArtifactManager.instance.SetArtifactEnabled(currentArtifact, false);
					Log.Info("Succesfully disabled artifact: " + currentArtifact.cachedName);
				}
				else
				{
					Log.Info("Run already ended");
				}
			}
			else
			{
				Log.Info("No current artifact for some reason");
			}
		}

		public override void OnStart()
		{
			Log.Info("ArtifactModifier start");
			if (Object.op_Implicit((Object)(object)currentArtifact))
			{
				RunArtifactManager.instance.SetArtifactEnabled(currentArtifact, true);
				Chat.AddMessage("Artifact " + currentArtifact.cachedName + " enabled");
			}
			else
			{
				Log.Info("No such artifact");
			}
		}
	}
	public class MysteryModifier : StageModifier
	{
		public override void OnEnd()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			Log.Info("On mystery modifier end");
			PickupDisplay.RebuildModel -= new hook_RebuildModel(PickupDisplay_RebuildModel);
			GenericPickupController.GetDisplayName -= new hook_GetDisplayName(GenericPickupController_GetDisplayName);
			GenericPickupController.GetInspectInfoProvider -= new hook_GetInspectInfoProvider(GenericPickupController_GetInspectInfoProvider);
			ShopTerminalBehavior.Start -= new hook_Start(ShopTerminalBehavior_Start);
			PickupDisplay.Update -= new hook_Update(PickupDisplay_Update);
		}

		private void PickupDisplay_Update(orig_Update orig, PickupDisplay self)
		{
			//IL_008a: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_0060: Unknown