Decompiled source of MoreDifficultyREPO v0.2.0

SK0R3N-DifficultyFeature/DifficultyFeature.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using DifficultyFeature;
using DifficultyFeature.DifficultyUpdate;
using ExitGames.Client.Photon;
using HarmonyLib;
using MenuLib;
using MenuLib.MonoBehaviors;
using MenuLib.Structs;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Autodesk.Fbx")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("FbxBuildTestAssets")]
[assembly: IgnoresAccessChecksTo("Klattersynth")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonChat")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.API")]
[assembly: IgnoresAccessChecksTo("PhotonVoice")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime.Public")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Formats.Fbx.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Postprocessing.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("websocket-sharp")]
[assembly: AssemblyCompany("SK0R3N")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+81925fcda83b57856b75b756758b5a59add693e1")]
[assembly: AssemblyProduct("DifficultyFeature")]
[assembly: AssemblyTitle("DifficultyFeature")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public static class DifficultySaveContext
{
	[HarmonyPatch(typeof(MenuPageSaves), "SaveFileSelected")]
	public class SaveFileSelectedPatch
	{
		private static void Postfix(MenuPageSaves __instance)
		{
			string value = Traverse.Create((object)__instance).Field<string>("currentSaveFileName").Value;
			Debug.Log((object)("[DifficultySaveContext] Selected save: " + value));
			SetCurrent(value);
			DifficultySaveManager.LoadDifficulty(value);
			DifficultyLabelUI.SetDifficulty(DifficultyManager.CurrentDifficulty.ToString());
		}
	}

	public static string CurrentSaveFileName { get; private set; } = "";


	public static void SetCurrent(string name)
	{
		CurrentSaveFileName = name;
	}
}
[HarmonyPatch(typeof(LevelGenerator), "Start")]
public static class Patch_LevelGeneratorStart
{
	private static readonly ManualLogSource Log = Logger.CreateLogSource("MyMOD.RunManagerPatch");

	[HarmonyPostfix]
	public static void Postfix(LevelGenerator __instance)
	{
		DifficultyManager.DifficultyLevel currentDifficulty = DifficultyManager.CurrentDifficulty;
		Level levelCurrent = RunManager.instance.levelCurrent;
		if (!((Object)(object)levelCurrent == (Object)null))
		{
			if (1 == 0)
			{
			}
			float num = currentDifficulty switch
			{
				DifficultyManager.DifficultyLevel.Normal => 1f, 
				DifficultyManager.DifficultyLevel.Hard => 1f, 
				DifficultyManager.DifficultyLevel.Hardcore => 2f, 
				DifficultyManager.DifficultyLevel.Nightmare => 2f, 
				DifficultyManager.DifficultyLevel.IsThatEvenPossible => 3f, 
				DifficultyManager.DifficultyLevel.CrazyMonster => 2f, 
				DifficultyManager.DifficultyLevel.Custom => 1f, 
				_ => 1f, 
			};
			if (1 == 0)
			{
			}
			float num2 = num;
			float num3 = num2;
			levelCurrent.PassageMaxAmount = Mathf.RoundToInt((float)currentDifficulty);
			((object)__instance).GetType().GetField("DeadEndAmount", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(__instance, Mathf.RoundToInt(1f));
			Log.LogInfo((object)$"[Difficulty] PassageMaxAmount x{num2} => {levelCurrent.PassageMaxAmount}");
			Log.LogInfo((object)$"[Difficulty] DeadEndAmount x{num3}");
		}
	}
}
namespace DifficultyFeature
{
	[BepInPlugin("SK0R3N.DifficultyFeature", "DifficultyFeature", "1.0")]
	public class DifficultyFeature : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(LevelGenerator))]
		internal static class PunManagerPatch
		{
			[HarmonyPostfix]
			[HarmonyPatch("GenerateDone")]
			private static void Start_Postfix(PunManager __instance)
			{
				if (!PhotonNetwork.IsMasterClient)
				{
					return;
				}
				foreach (EnemyParent item in EnemyDirector.instance.enemiesSpawned)
				{
					switch (DifficultyManager.CurrentDifficulty)
					{
					case DifficultyManager.DifficultyLevel.Custom:
						item.Enemy.Health.healthCurrent = item.Enemy.Health.healthCurrent * DifficultyManager.MultiplierEnemyLife;
						item.Enemy.Health.health = item.Enemy.Health.health * DifficultyManager.MultiplierEnemyLife;
						break;
					case DifficultyManager.DifficultyLevel.Easy:
						item.Enemy.Health.healthCurrent = item.Enemy.Health.healthCurrent / 2;
						item.Enemy.Health.health = item.Enemy.Health.healthCurrent / 2;
						break;
					case DifficultyManager.DifficultyLevel.Normal:
						item.Enemy.Health.healthCurrent = item.Enemy.Health.healthCurrent;
						item.Enemy.Health.health = item.Enemy.Health.health;
						break;
					case DifficultyManager.DifficultyLevel.Hard:
						item.Enemy.Health.healthCurrent = item.Enemy.Health.healthCurrent;
						item.Enemy.Health.health = item.Enemy.Health.health;
						break;
					case DifficultyManager.DifficultyLevel.Hardcore:
						item.Enemy.Health.healthCurrent = item.Enemy.Health.healthCurrent * 2;
						item.Enemy.Health.health = item.Enemy.Health.health * 2;
						break;
					case DifficultyManager.DifficultyLevel.Nightmare:
						item.Enemy.Health.healthCurrent = item.Enemy.Health.healthCurrent * 2;
						item.Enemy.Health.health = item.Enemy.Health.health * 2;
						break;
					case DifficultyManager.DifficultyLevel.IsThatEvenPossible:
						item.Enemy.Health.healthCurrent = item.Enemy.Health.healthCurrent * 3;
						item.Enemy.Health.health = item.Enemy.Health.health * 3;
						break;
					case DifficultyManager.DifficultyLevel.CrazyMonster:
						item.Enemy.Health.healthCurrent = item.Enemy.Health.healthCurrent;
						item.Enemy.Health.health = item.Enemy.Health.health;
						break;
					}
					if (DifficultyManager.ExplosionMob)
					{
						ExplosiveDeathEvent explosiveDeathEvent = new ExplosiveDeathEvent();
						explosiveDeathEvent.Execute();
					}
				}
			}
		}

		private bool subscribed = false;

		private static readonly ManualLogSource Log = Logger.CreateLogSource("DifficultyFeature.ViewIDLogger");

		private PhotonView[] lastPhotonViews = (PhotonView[])(object)new PhotonView[0];

		internal static DifficultyFeature Instance { get; private set; } = null;


		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		public static int DifficultyLevel { get; set; } = 1;


		private void Awake()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Harmony val = new Harmony("SK0R3N.DifficultyFeature");
			val.PatchAll();
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		private void Start()
		{
			Debug.Log((object)("[NetworkEventHandler] Start called. Instance is active: " + ((Component)this).gameObject.activeInHierarchy));
			if (!subscribed && PhotonNetwork.NetworkingClient != null)
			{
				PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
				subscribed = true;
				Debug.Log((object)"[NetworkEventHandler] Event listener registered from Start()");
			}
		}

		private void OnDestroy()
		{
			if (subscribed && PhotonNetwork.NetworkingClient != null)
			{
				PhotonNetwork.NetworkingClient.EventReceived -= OnEvent;
				Debug.Log((object)"[NetworkEventHandler] Event listener unregistered from OnDestroy()");
			}
		}

		public void OnEvent(EventData photonEvent)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)$"[NetworkEventHandler] OnEvent called with code: {photonEvent.Code}");
			switch (photonEvent.Code)
			{
			case 100:
			{
				object[] array = (object[])photonEvent.CustomData;
				Vector3 val = (Vector3)array[0];
				string text = (string)array[1];
				ExplosiveDeathEvent.CreateExplosion(val, text);
				Debug.Log((object)$"[NetworkEventHandler] Received ExplosiveDeathEvent at {val} for {text}");
				break;
			}
			case 101:
				if (photonEvent.Code == 101)
				{
					string label = (string)photonEvent.CustomData;
					DifficultyLabelUI.Instance.SetLabel(label);
				}
				break;
			}
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Expected O, but got Unknown
			if (((Object)RunManager.instance.levelCurrent).name.ToLower().Contains("vaultline"))
			{
				PhotonView[] photonViews = PhotonNetwork.PhotonViews;
				PhotonView[] array = photonViews;
				foreach (PhotonView val in array)
				{
					if (((Object)((Component)val).gameObject).name.ToLower().Contains("door") || ((Object)((Component)val).gameObject).name.ToLower().Contains("hinge"))
					{
						PhotonNetwork.Destroy(((Component)val).gameObject);
						Debug.Log((object)"PhotonDestroy");
					}
				}
			}
			GameObject val2 = GameObject.Find("Menu Page Lobby(Clone)");
			if ((Object)(object)val2 != (Object)null && PhotonNetwork.IsMasterClient)
			{
				Transform val3 = val2.transform.Find("DifficultyButton");
				if ((Object)(object)val3 == (Object)null)
				{
					DifficultyMenu.CreateDifficultyButton();
					Debug.Log((object)"[DifficultyUI] Difficulty button added to lobby.");
				}
			}
			if (!((Object)(object)val2 != (Object)null) || !PhotonNetwork.InRoom)
			{
				return;
			}
			DifficultyLabelUI difficultyLabelUI = Object.FindObjectOfType<DifficultyLabelUI>();
			if ((Object)(object)difficultyLabelUI == (Object)null || (Object)(object)difficultyLabelUI.label == (Object)null || (Object)(object)((Component)difficultyLabelUI.label).transform.parent == (Object)null)
			{
				if ((Object)(object)difficultyLabelUI != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)difficultyLabelUI).gameObject);
				}
				GameObject val4 = new GameObject("DifficultyLabelUI");
				PhotonView val5 = val4.AddComponent<PhotonView>();
				val4.AddComponent<DifficultyLabelUI>();
				Object.DontDestroyOnLoad((Object)(object)val4);
				Debug.Log((object)"[DifficultyLabelUI] Nouveau label instancié.");
			}
		}

		public string GetComponentInfo(GameObject go)
		{
			if ((Object)(object)go == (Object)null)
			{
				return "None";
			}
			MonoBehaviour[] components = go.GetComponents<MonoBehaviour>();
			if (components.Length == 0)
			{
				return "No MonoBehaviours";
			}
			StringBuilder stringBuilder = new StringBuilder();
			MonoBehaviour[] array = components;
			foreach (MonoBehaviour val in array)
			{
				if ((Object)(object)val != (Object)null && !(val is PhotonView))
				{
					stringBuilder.Append(((object)val).GetType().Name).Append(", ");
				}
			}
			return (stringBuilder.Length > 0) ? stringBuilder.ToString(0, stringBuilder.Length - 2) : "None";
		}

		public static void ListHUDObjects()
		{
			GameObject val = GameObject.Find("HUD Canvas");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"[HUD Explorer] HUD Canvas introuvable !");
				return;
			}
			Debug.Log((object)"[HUD Explorer] --- Objets enfants du HUD Canvas ---");
			ListChildrenRecursive(val.transform, 0);
		}

		private static void ListChildrenRecursive(Transform parent, int indent)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			string text = new string(' ', indent * 2);
			Debug.Log((object)(text + "- " + ((Object)parent).name));
			foreach (Transform item in parent)
			{
				Transform parent2 = item;
				ListChildrenRecursive(parent2, indent + 1);
			}
		}

		private void LogAllGameObjectsInScene()
		{
			GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
			GameObject[] array2 = array;
			foreach (GameObject val in array2)
			{
				if (((Object)val).name.ToLower().Contains("lobby"))
				{
					Debug.Log((object)$"[Debug Find] Found: {((Object)val).name} | ActiveInHierarchy: {val.activeInHierarchy} | Path: {GetGameObjectPath(val)}");
				}
			}
		}

		private string GetGameObjectPath(GameObject obj)
		{
			string text = "/" + ((Object)obj).name;
			Transform val = obj.transform;
			while ((Object)(object)val.parent != (Object)null)
			{
				val = val.parent;
				text = "/" + ((Object)val).name + text;
			}
			return text;
		}
	}
	[Serializable]
	public class CustomDifficultySettings
	{
		public int ExtractionMultiplier;

		public int ExtractionMaxMultiplier;

		public int PourcentageRoom1;

		public int PourcentageRoom2;

		public int PourcentageRoom3;

		public int EnemyMultiplier;

		public float ShopMultiplier;

		public int ValuableMultiplier;

		public int EnemyLifeMultiplier;

		public bool LevelScaler;

		public bool ExplosionMob;

		public CustomDifficultySettings()
		{
			ExtractionMultiplier = DifficultyManager.ExtractionMultiplier;
			ExtractionMaxMultiplier = DifficultyManager.ExtractionMaxMultiplier;
			PourcentageRoom1 = DifficultyManager.PourcentageRoom1;
			PourcentageRoom2 = DifficultyManager.PourcentageRoom2;
			PourcentageRoom3 = DifficultyManager.PourcentageRoom3;
			EnemyMultiplier = DifficultyManager.EnemyMultiplier;
			ShopMultiplier = DifficultyManager.ShopMultiplier;
			ValuableMultiplier = DifficultyManager.ValuableMultiplier;
			EnemyLifeMultiplier = DifficultyManager.MultiplierEnemyLife;
			LevelScaler = DifficultyManager.LevelScaler;
			ExplosionMob = DifficultyManager.ExplosionMob;
		}
	}
	[Serializable]
	public class DifficultyData
	{
		public string DifficultyName;

		public CustomDifficultySettings CustomSettings;
	}
	public static class DifficultySaveManager
	{
		private static string savePath;

		private static Dictionary<string, DifficultyData> difficultyData;

		static DifficultySaveManager()
		{
			savePath = Path.Combine(Paths.PluginPath, "SK0R3N-DifficultyFeature", "DifficultySaves.json");
			difficultyData = new Dictionary<string, DifficultyData>();
			Load();
		}

		public static void SaveDifficulty(string difficultyName)
		{
			string saveFileCurrent = StatsManager.instance.saveFileCurrent;
			string directoryName = Path.GetDirectoryName(savePath);
			if (!Directory.Exists(directoryName))
			{
				Directory.CreateDirectory(directoryName);
			}
			if (!difficultyData.ContainsKey(saveFileCurrent))
			{
				difficultyData[saveFileCurrent] = new DifficultyData();
			}
			difficultyData[saveFileCurrent] = new DifficultyData
			{
				DifficultyName = difficultyName,
				CustomSettings = new CustomDifficultySettings()
			};
			File.WriteAllText(savePath, JsonConvert.SerializeObject((object)difficultyData, (Formatting)1));
			Debug.Log((object)("[DifficultySaveManager] Difficulté sauvegardée pour " + saveFileCurrent + ": " + difficultyName));
		}

		public static string LoadDifficulty(string saveFileName)
		{
			Debug.Log((object)("[DifficultySaveManager] Chargement de la difficulté pour " + saveFileName));
			if (difficultyData.TryGetValue(saveFileName, out DifficultyData value) && value != null)
			{
				DifficultyManager.ExtractionMultiplier = value.CustomSettings.ExtractionMultiplier;
				DifficultyManager.ExtractionMaxMultiplier = value.CustomSettings.ExtractionMaxMultiplier;
				DifficultyManager.PourcentageRoom1 = value.CustomSettings.PourcentageRoom1;
				DifficultyManager.PourcentageRoom2 = value.CustomSettings.PourcentageRoom2;
				DifficultyManager.PourcentageRoom3 = value.CustomSettings.PourcentageRoom3;
				DifficultyManager.EnemyMultiplier = value.CustomSettings.EnemyMultiplier;
				DifficultyManager.ShopMultiplier = value.CustomSettings.ShopMultiplier;
				DifficultyManager.ValuableMultiplier = value.CustomSettings.ValuableMultiplier;
				DifficultyManager.MultiplierEnemyLife = value.CustomSettings.EnemyLifeMultiplier;
				DifficultyManager.CurrentDifficulty = Enum.Parse<DifficultyManager.DifficultyLevel>(value.DifficultyName);
				DifficultyManager.LevelScaler = value.CustomSettings.LevelScaler;
				DifficultyManager.ExplosionMob = value.CustomSettings.ExplosionMob;
				return value.DifficultyName;
			}
			Debug.Log((object)("[DifficultySaveManager] Aucune difficulté trouvée pour " + saveFileName + ", utilisation de Normal par défaut."));
			SaveDifficulty("Normal");
			return "Normal";
		}

		private static void SaveToFile()
		{
			File.WriteAllText(savePath, JsonConvert.SerializeObject((object)difficultyData, (Formatting)1));
		}

		private static void Load()
		{
			if (!File.Exists(savePath))
			{
				difficultyData = new Dictionary<string, DifficultyData>();
				return;
			}
			string text = File.ReadAllText(savePath);
			try
			{
				difficultyData = JsonConvert.DeserializeObject<Dictionary<string, DifficultyData>>(text) ?? new Dictionary<string, DifficultyData>();
				Debug.Log((object)"[DifficultySaveManager] Nouveau format chargé.");
			}
			catch
			{
				try
				{
					Dictionary<string, string> dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(text);
					if (dictionary != null)
					{
						Debug.Log((object)"[DifficultySaveManager] Ancien format détecté, conversion en cours...");
						difficultyData = new Dictionary<string, DifficultyData>();
						foreach (KeyValuePair<string, string> item in dictionary)
						{
							difficultyData[item.Key] = new DifficultyData
							{
								DifficultyName = item.Value,
								CustomSettings = new CustomDifficultySettings()
							};
						}
						File.WriteAllText(savePath, JsonConvert.SerializeObject((object)difficultyData, (Formatting)1));
						Debug.Log((object)"[DifficultySaveManager] Conversion de l'ancien format terminée et sauvegardée.");
					}
					else
					{
						difficultyData = new Dictionary<string, DifficultyData>();
					}
				}
				catch (Exception ex)
				{
					Debug.LogError((object)("[DifficultySaveManager] Échec de la lecture du fichier de sauvegarde : " + ex.Message));
					difficultyData = new Dictionary<string, DifficultyData>();
				}
			}
		}
	}
}
namespace DifficultyFeature.DifficultyUpdate
{
	public static class DifficultyManager
	{
		public enum DifficultyLevel
		{
			Custom,
			Easy,
			Normal,
			Hard,
			Hardcore,
			Nightmare,
			IsThatEvenPossible,
			CrazyMonster
		}

		public static float DifficultyMultiplier = 1f;

		public static DifficultyLevel CurrentDifficulty = DifficultyLevel.Normal;

		public static int EnemyMultiplier = 1;

		public static float ShopMultiplier = 1f;

		public static int ExtractionMultiplier = 1;

		public static int ExtractionMaxMultiplier = 1;

		public static int ValuableMultiplier = 1;

		public static int RoomNumber = 30;

		public static int PourcentageRoom1 = 100;

		public static int PourcentageRoom2 = 0;

		public static int PourcentageRoom3 = 0;

		public static string DifficultyPreset = "None";

		public static int MultiplierEnemyLife = 1;

		public static bool LevelScaler = true;

		public static bool ExplosionMob = false;
	}
	public class DifficultyLabelUI : MonoBehaviour, IInRoomCallbacks
	{
		public static DifficultyLabelUI Instance;

		internal REPOLabel label;

		public const byte DifficultyEventCode = 101;

		private void Awake()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			GameObject val = GameObject.Find("HUD Canvas");
			if (!Object.op_Implicit((Object)(object)val))
			{
				Debug.LogError((object)"[DifficultyLabelUI] HUD Canvas introuvable.");
				return;
			}
			label = MenuAPI.CreateREPOLabel($"Difficulty: {DifficultyManager.CurrentDifficulty}", val.transform, Vector2.zero);
			((REPOElement)label).rectTransform.anchorMin = new Vector2(1f, 1f);
			((REPOElement)label).rectTransform.anchorMax = new Vector2(1f, 1f);
			((REPOElement)label).rectTransform.pivot = new Vector2(1f, 1f);
			((MonoBehaviour)this).StartCoroutine(AdjustDifficultyLabelPosition());
			PhotonNetwork.AddCallbackTarget((object)this);
		}

		private void OnDestroy()
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
		}

		public static void SendDifficultyToEveryone(string difficulty)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			Debug.Log((object)"[DifficultyLabelUI] Send Photon");
			PhotonNetwork.RaiseEvent((byte)101, (object)difficulty, new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)1
			}, SendOptions.SendReliable);
		}

		public void SetLabel(string difficulty)
		{
			Debug.Log((object)"[DifficultyLabelUI] J'ai recu mon rpc");
			if (!((Object)(object)label == (Object)null))
			{
				((TMP_Text)label.labelTMP).text = "Difficulty: " + difficulty;
				((MonoBehaviour)this).StartCoroutine(AdjustDifficultyLabelPosition());
			}
		}

		public static IEnumerator AdjustDifficultyLabelPosition()
		{
			yield return null;
			float width = ((TMP_Text)Instance.label.labelTMP).preferredWidth;
			float padding = 20f;
			((REPOElement)Instance.label).rectTransform.anchoredPosition = new Vector2(0f - width - padding, -40f);
		}

		public static void SetDifficulty(string difficulty)
		{
			if (!((Object)(object)Instance?.label == (Object)null))
			{
				Debug.Log((object)("[DifficultyLabelUI] Updating label: " + difficulty));
				Instance.SetLabel(difficulty);
				SendDifficultyToEveryone(difficulty);
			}
		}

		public void OnPlayerEnteredRoom(Player newPlayer)
		{
			Debug.Log((object)"[DifficultyLabelUI] J'envoieMonRPC");
			if (PhotonNetwork.IsMasterClient)
			{
				Debug.Log((object)"[DifficultyLabelUI] Un joueur a rejoint, envoi de la difficulté dans 1 seconde.");
				((MonoBehaviour)this).StartCoroutine(SendDifficultyDelayed());
			}
		}

		private IEnumerator SendDifficultyDelayed()
		{
			Debug.Log((object)"[DifficultyLabelUI] Début seconde");
			yield return (object)new WaitForSeconds(5f);
			Debug.Log((object)"[DifficultyLabelUI] Fin seconde");
			SendDifficultyToEveryone(DifficultyManager.CurrentDifficulty.ToString());
		}

		public void OnPlayerLeftRoom(Player otherPlayer)
		{
		}

		public void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
		{
		}

		public void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
		{
		}

		public void OnMasterClientSwitched(Player newMasterClient)
		{
		}
	}
	public class DifficultyMenu
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Action<string> <>9__4_1;

			public static Action<string> <>9__4_2;

			public static Action<string> <>9__4_3;

			public static Action<string> <>9__7_1;

			public static Action<float> <>9__7_2;

			public static Action<float> <>9__7_3;

			public static Action<float> <>9__7_4;

			public static Action<float> <>9__7_5;

			public static Action<float> <>9__7_6;

			public static Action<float> <>9__7_7;

			public static Action<float> <>9__7_8;

			public static Action<float> <>9__7_9;

			public static Action<float> <>9__7_10;

			public static ScrollViewBuilderDelegate <>9__7_0;

			internal void <OpenDifficultyPopup>b__4_1(string difficulty)
			{
				SelectedDifficulty = difficulty;
				DifficultyManager.CurrentDifficulty = (DifficultyManager.DifficultyLevel)Enum.Parse(typeof(DifficultyManager.DifficultyLevel), SelectedDifficulty);
				DifficultySaveManager.SaveDifficulty(SelectedDifficulty);
				DifficultyLabelUI.SetDifficulty(SelectedDifficulty);
				Debug.Log((object)("[MyMod] Difficulty selected: " + SelectedDifficulty));
				UpdateDifficultyRightPopup(difficulty);
			}

			internal void <OpenDifficultyPopup>b__4_2(string difficulty)
			{
				DifficultyManager.ExplosionMob = bool.Parse(difficulty);
				DifficultySaveManager.SaveDifficulty(SelectedDifficulty);
			}

			internal void <OpenDifficultyPopup>b__4_3(string difficulty)
			{
				DifficultyManager.LevelScaler = bool.Parse(difficulty);
				DifficultySaveManager.SaveDifficulty(SelectedDifficulty);
			}

			internal RectTransform <UpdateDifficultyRightPopup>b__7_0(Transform scroll)
			{
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0154: Unknown result type (might be due to invalid IL or missing references)
				//IL_01af: Unknown result type (might be due to invalid IL or missing references)
				//IL_020a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0265: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_031b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0375: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
				string[] array = new string[13]
				{
					"None", "Easy", "Normal", "Normal+", "Normal++", "Hard", "Hard+", "Hard++", "Hardcore", "Hardcore+",
					"Nightmare", "IsThatEvenPossible", "CrazyMonster"
				};
				REPOSlider val2 = MenuAPI.CreateREPOSlider("Difficulty Preset", "", (Action<string>)delegate(string difficulty)
				{
					ApplyPreset(difficulty);
					UpdateSliders();
					DifficultyManager.DifficultyPreset = difficulty;
					DifficultySaveManager.SaveDifficulty("Custom");
				}, scroll, array, DifficultyManager.DifficultyPreset, new Vector2(0f, 210f), "", "", (BarBehavior)0);
				MenuAPI.CreateREPOSlider("Extraction Amount", "", (Action<float>)delegate(float val)
				{
					DifficultyManager.ExtractionMultiplier = (int)val;
					DifficultySaveManager.SaveDifficulty("Custom");
				}, scroll, new Vector2(0f, 190f), 0f, 12f, 0, (float)DifficultyManager.ExtractionMultiplier, "", "", (BarBehavior)0);
				MenuAPI.CreateREPOSlider("MaxExtraction Amount", "", (Action<float>)delegate(float val)
				{
					DifficultyManager.ExtractionMaxMultiplier = (int)val;
					DifficultySaveManager.SaveDifficulty("Custom");
				}, scroll, new Vector2(0f, 170f), 0f, 12f, 0, (float)DifficultyManager.ExtractionMaxMultiplier, "", "", (BarBehavior)0);
				MenuAPI.CreateREPOSlider("Room Difficulty 1 (%)", "", (Action<float>)delegate(float val)
				{
					DifficultyManager.PourcentageRoom1 = (int)val;
					DifficultySaveManager.SaveDifficulty("Custom");
				}, scroll, new Vector2(0f, 150f), 0f, 100f, 0, (float)DifficultyManager.PourcentageRoom1, "", "", (BarBehavior)0);
				MenuAPI.CreateREPOSlider("Room Difficulty 2 (%)", "", (Action<float>)delegate(float val)
				{
					DifficultyManager.PourcentageRoom2 = (int)val;
					DifficultySaveManager.SaveDifficulty("Custom");
				}, scroll, new Vector2(0f, 130f), 0f, 100f, 0, (float)DifficultyManager.PourcentageRoom2, "", "", (BarBehavior)0);
				MenuAPI.CreateREPOSlider("Room Difficulty 3 (%)", "", (Action<float>)delegate(float val)
				{
					DifficultyManager.PourcentageRoom3 = (int)val;
					DifficultySaveManager.SaveDifficulty("Custom");
				}, scroll, new Vector2(0f, 110f), 0f, 100f, 0, (float)DifficultyManager.PourcentageRoom3, "", "", (BarBehavior)0);
				MenuAPI.CreateREPOSlider("Number of Enemy", "", (Action<float>)delegate(float val)
				{
					DifficultyManager.EnemyMultiplier = (int)val;
					DifficultySaveManager.SaveDifficulty("Custom");
				}, scroll, new Vector2(0f, 90f), 0f, 20f, 0, (float)DifficultyManager.EnemyMultiplier, "", "", (BarBehavior)0);
				MenuAPI.CreateREPOSlider("Shop Price Multiplier", "", (Action<float>)delegate(float val)
				{
					DifficultyManager.ShopMultiplier = val;
					DifficultySaveManager.SaveDifficulty("Custom");
				}, scroll, new Vector2(0f, 70f), 0f, 10f, 1, DifficultyManager.ShopMultiplier, "", "", (BarBehavior)0);
				MenuAPI.CreateREPOSlider("Valuable Multiplier", "", (Action<float>)delegate(float val)
				{
					DifficultyManager.ValuableMultiplier = (int)val;
					DifficultySaveManager.SaveDifficulty("Custom");
				}, scroll, new Vector2(0f, 50f), 1f, 10f, 0, (float)DifficultyManager.ValuableMultiplier, "", "", (BarBehavior)0);
				MenuAPI.CreateREPOSlider("Multiplier Enemy Life", "", (Action<float>)delegate(float val)
				{
					DifficultyManager.MultiplierEnemyLife = (int)val;
					DifficultySaveManager.SaveDifficulty("Custom");
				}, scroll, new Vector2(0f, 30f), 1f, 10f, 0, (float)DifficultyManager.MultiplierEnemyLife, "", "", (BarBehavior)0);
				return (RectTransform)(object)((scroll is RectTransform) ? scroll : null);
			}

			internal void <UpdateDifficultyRightPopup>b__7_1(string difficulty)
			{
				ApplyPreset(difficulty);
				UpdateSliders();
				DifficultyManager.DifficultyPreset = difficulty;
				DifficultySaveManager.SaveDifficulty("Custom");
			}

			internal void <UpdateDifficultyRightPopup>b__7_2(float val)
			{
				DifficultyManager.ExtractionMultiplier = (int)val;
				DifficultySaveManager.SaveDifficulty("Custom");
			}

			internal void <UpdateDifficultyRightPopup>b__7_3(float val)
			{
				DifficultyManager.ExtractionMaxMultiplier = (int)val;
				DifficultySaveManager.SaveDifficulty("Custom");
			}

			internal void <UpdateDifficultyRightPopup>b__7_4(float val)
			{
				DifficultyManager.PourcentageRoom1 = (int)val;
				DifficultySaveManager.SaveDifficulty("Custom");
			}

			internal void <UpdateDifficultyRightPopup>b__7_5(float val)
			{
				DifficultyManager.PourcentageRoom2 = (int)val;
				DifficultySaveManager.SaveDifficulty("Custom");
			}

			internal void <UpdateDifficultyRightPopup>b__7_6(float val)
			{
				DifficultyManager.PourcentageRoom3 = (int)val;
				DifficultySaveManager.SaveDifficulty("Custom");
			}

			internal void <UpdateDifficultyRightPopup>b__7_7(float val)
			{
				DifficultyManager.EnemyMultiplier = (int)val;
				DifficultySaveManager.SaveDifficulty("Custom");
			}

			internal void <UpdateDifficultyRightPopup>b__7_8(float val)
			{
				DifficultyManager.ShopMultiplier = val;
				DifficultySaveManager.SaveDifficulty("Custom");
			}

			internal void <UpdateDifficultyRightPopup>b__7_9(float val)
			{
				DifficultyManager.ValuableMultiplier = (int)val;
				DifficultySaveManager.SaveDifficulty("Custom");
			}

			internal void <UpdateDifficultyRightPopup>b__7_10(float val)
			{
				DifficultyManager.MultiplierEnemyLife = (int)val;
				DifficultySaveManager.SaveDifficulty("Custom");
			}
		}

		public static string SelectedDifficulty = "Normal";

		private static REPOPopupPage popupRight = null;

		private static REPOPopupPage popupPageDifficulty = null;

		public static void CreateDifficultyButton()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Menu Page Lobby(Clone)");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"[MyMod] Menu Page Lobby not found!");
				return;
			}
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(540f, 320f);
			REPOButton val3 = MenuAPI.CreateREPOButton("Choose Difficulty", (Action)OpenDifficultyPopup, val.transform, val2);
			((Object)val3).name = "DifficultyButton";
			Debug.Log((object)"[MyMod] Difficulty button added to Lobby!");
		}

		private static void OpenDifficultyPopup()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			REPOPopupPage popupPage = MenuAPI.CreateREPOPopupPage("Select Difficulty", (PresetSide)0, false, true, 0f);
			popupPage.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform scroll)
			{
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0102: Unknown result type (might be due to invalid IL or missing references)
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_017d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0182: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
				string[] array = new string[8] { "Custom", "Easy", "Normal", "Hard", "Hardcore", "Nightmare", "IsThatEvenPossible", "CrazyMonster" };
				REPOSlider val = MenuAPI.CreateREPOSlider("Difficulty", "Select the game difficulty.", (Action<string>)delegate(string difficulty)
				{
					SelectedDifficulty = difficulty;
					DifficultyManager.CurrentDifficulty = (DifficultyManager.DifficultyLevel)Enum.Parse(typeof(DifficultyManager.DifficultyLevel), SelectedDifficulty);
					DifficultySaveManager.SaveDifficulty(SelectedDifficulty);
					DifficultyLabelUI.SetDifficulty(SelectedDifficulty);
					Debug.Log((object)("[MyMod] Difficulty selected: " + SelectedDifficulty));
					UpdateDifficultyRightPopup(difficulty);
				}, scroll, array, DifficultyManager.CurrentDifficulty.ToString(), new Vector2(0f, 210f), "", "", (BarBehavior)0);
				string[] array2 = new string[2] { "false", "true" };
				REPOSlider val2 = MenuAPI.CreateREPOSlider("Explosion Ennemy", "All Ennemy are exploding when their die", (Action<string>)delegate(string difficulty)
				{
					DifficultyManager.ExplosionMob = bool.Parse(difficulty);
					DifficultySaveManager.SaveDifficulty(SelectedDifficulty);
				}, scroll, array2, DifficultyManager.ExplosionMob ? "true" : "false", new Vector2(0f, 160f), "", "", (BarBehavior)0);
				REPOSlider val3 = MenuAPI.CreateREPOSlider("Difficulty Scaler", "Difficulty increases every 6 levels", (Action<string>)delegate(string difficulty)
				{
					DifficultyManager.LevelScaler = bool.Parse(difficulty);
					DifficultySaveManager.SaveDifficulty(SelectedDifficulty);
				}, scroll, array2, DifficultyManager.LevelScaler ? "true" : "false", new Vector2(0f, 100f), "", "", (BarBehavior)0);
				Vector2 anchoredPosition = ((REPOElement)val).rectTransform.anchoredPosition;
				Vector2 val4 = default(Vector2);
				((Vector2)(ref val4))..ctor(0f, 120f);
				MenuAPI.CreateREPOButton("Apply", (Action)delegate
				{
					popupPage.ClosePage(true);
				}, ((Component)popupPage).transform, anchoredPosition + val4);
				return ((REPOElement)val).rectTransform;
			}, 0f, 0f);
			UpdateDifficultyRightPopup(SelectedDifficulty);
			popupPage.OpenPage(true);
		}

		private static void ApplyPreset(string Difficulty)
		{
			switch (Difficulty)
			{
			case "Easy":
				DifficultyManager.ExtractionMultiplier = 0;
				DifficultyManager.ExtractionMaxMultiplier = 2;
				DifficultyManager.PourcentageRoom1 = 100;
				DifficultyManager.PourcentageRoom2 = 0;
				DifficultyManager.PourcentageRoom3 = 0;
				DifficultyManager.EnemyMultiplier = 2;
				DifficultyManager.ShopMultiplier = 0.75f;
				DifficultyManager.ValuableMultiplier = 2;
				DifficultyManager.MultiplierEnemyLife = 1;
				break;
			case "Normal":
				DifficultyManager.ExtractionMultiplier = 0;
				DifficultyManager.ExtractionMaxMultiplier = 3;
				DifficultyManager.PourcentageRoom1 = 100;
				DifficultyManager.PourcentageRoom2 = 0;
				DifficultyManager.PourcentageRoom3 = 0;
				DifficultyManager.EnemyMultiplier = 2;
				DifficultyManager.ShopMultiplier = 1f;
				DifficultyManager.ValuableMultiplier = 1;
				DifficultyManager.MultiplierEnemyLife = 1;
				break;
			case "Normal+":
				DifficultyManager.ExtractionMultiplier = 0;
				DifficultyManager.ExtractionMaxMultiplier = 3;
				DifficultyManager.PourcentageRoom1 = 70;
				DifficultyManager.PourcentageRoom2 = 30;
				DifficultyManager.PourcentageRoom3 = 0;
				DifficultyManager.EnemyMultiplier = 2;
				DifficultyManager.ShopMultiplier = 1f;
				DifficultyManager.ValuableMultiplier = 1;
				DifficultyManager.MultiplierEnemyLife = 1;
				break;
			case "Normal++":
				DifficultyManager.ExtractionMultiplier = 0;
				DifficultyManager.ExtractionMaxMultiplier = 3;
				DifficultyManager.PourcentageRoom1 = 40;
				DifficultyManager.PourcentageRoom2 = 40;
				DifficultyManager.PourcentageRoom3 = 20;
				DifficultyManager.EnemyMultiplier = 2;
				DifficultyManager.ShopMultiplier = 1f;
				DifficultyManager.ValuableMultiplier = 1;
				DifficultyManager.MultiplierEnemyLife = 1;
				break;
			case "Hard":
				DifficultyManager.ExtractionMultiplier = 1;
				DifficultyManager.ExtractionMaxMultiplier = 5;
				DifficultyManager.PourcentageRoom1 = 100;
				DifficultyManager.PourcentageRoom2 = 0;
				DifficultyManager.PourcentageRoom3 = 0;
				DifficultyManager.EnemyMultiplier = 3;
				DifficultyManager.ShopMultiplier = 1.5f;
				DifficultyManager.ValuableMultiplier = 2;
				DifficultyManager.MultiplierEnemyLife = 1;
				break;
			case "Hard+":
				DifficultyManager.ExtractionMultiplier = 1;
				DifficultyManager.ExtractionMaxMultiplier = 5;
				DifficultyManager.PourcentageRoom1 = 70;
				DifficultyManager.PourcentageRoom2 = 30;
				DifficultyManager.PourcentageRoom3 = 0;
				DifficultyManager.EnemyMultiplier = 3;
				DifficultyManager.ShopMultiplier = 1.5f;
				DifficultyManager.ValuableMultiplier = 2;
				DifficultyManager.MultiplierEnemyLife = 1;
				break;
			case "Hard++":
				DifficultyManager.ExtractionMultiplier = 1;
				DifficultyManager.ExtractionMaxMultiplier = 5;
				DifficultyManager.PourcentageRoom1 = 40;
				DifficultyManager.PourcentageRoom2 = 40;
				DifficultyManager.PourcentageRoom3 = 20;
				DifficultyManager.EnemyMultiplier = 3;
				DifficultyManager.ShopMultiplier = 1.5f;
				DifficultyManager.ValuableMultiplier = 2;
				DifficultyManager.MultiplierEnemyLife = 1;
				break;
			case "Hardcore":
				DifficultyManager.ExtractionMultiplier = 2;
				DifficultyManager.ExtractionMaxMultiplier = 7;
				DifficultyManager.PourcentageRoom1 = 40;
				DifficultyManager.PourcentageRoom2 = 60;
				DifficultyManager.PourcentageRoom3 = 0;
				DifficultyManager.EnemyMultiplier = 5;
				DifficultyManager.ShopMultiplier = 2f;
				DifficultyManager.ValuableMultiplier = 3;
				DifficultyManager.MultiplierEnemyLife = 2;
				break;
			case "Hardcore+":
				DifficultyManager.ExtractionMultiplier = 2;
				DifficultyManager.ExtractionMaxMultiplier = 7;
				DifficultyManager.PourcentageRoom1 = 20;
				DifficultyManager.PourcentageRoom2 = 50;
				DifficultyManager.PourcentageRoom3 = 30;
				DifficultyManager.EnemyMultiplier = 5;
				DifficultyManager.ShopMultiplier = 2f;
				DifficultyManager.ValuableMultiplier = 3;
				DifficultyManager.MultiplierEnemyLife = 2;
				break;
			case "Nightmare":
				DifficultyManager.ExtractionMultiplier = 3;
				DifficultyManager.ExtractionMaxMultiplier = 9;
				DifficultyManager.PourcentageRoom1 = 30;
				DifficultyManager.PourcentageRoom2 = 40;
				DifficultyManager.PourcentageRoom3 = 30;
				DifficultyManager.EnemyMultiplier = 7;
				DifficultyManager.ShopMultiplier = 2.5f;
				DifficultyManager.ValuableMultiplier = 4;
				DifficultyManager.MultiplierEnemyLife = 2;
				break;
			case "IsThatEvenPossible":
				DifficultyManager.ExtractionMultiplier = 4;
				DifficultyManager.ExtractionMaxMultiplier = 11;
				DifficultyManager.PourcentageRoom1 = 10;
				DifficultyManager.PourcentageRoom2 = 30;
				DifficultyManager.PourcentageRoom3 = 60;
				DifficultyManager.EnemyMultiplier = 10;
				DifficultyManager.ShopMultiplier = 3f;
				DifficultyManager.ValuableMultiplier = 5;
				DifficultyManager.MultiplierEnemyLife = 3;
				break;
			case "CrazyMonster":
				DifficultyManager.ExtractionMultiplier = 1;
				DifficultyManager.ExtractionMaxMultiplier = 3;
				DifficultyManager.PourcentageRoom1 = 0;
				DifficultyManager.PourcentageRoom2 = 20;
				DifficultyManager.PourcentageRoom3 = 80;
				DifficultyManager.EnemyMultiplier = 10;
				DifficultyManager.ShopMultiplier = 0.5f;
				DifficultyManager.ValuableMultiplier = 2;
				DifficultyManager.MultiplierEnemyLife = 1;
				break;
			}
		}

		private static void UpdateSliders()
		{
			REPOSlider[] componentsInChildren = ((Component)popupRight).GetComponentsInChildren<REPOSlider>();
			REPOSlider[] array = componentsInChildren;
			foreach (REPOSlider val in array)
			{
				Debug.Log((object)((Object)val).name);
				switch (((Object)val).name)
				{
				case "Float Slider - Extraction Amount":
					val.SetValue((float)DifficultyManager.ExtractionMultiplier, true);
					break;
				case "Float Slider - MaxExtraction Amount":
					val.SetValue((float)DifficultyManager.ExtractionMaxMultiplier, true);
					break;
				case "Float Slider - Room Difficulty 1 (%)":
					val.SetValue((float)DifficultyManager.PourcentageRoom1, true);
					break;
				case "Float Slider - Room Difficulty 2 (%)":
					val.SetValue((float)DifficultyManager.PourcentageRoom2, true);
					break;
				case "Float Slider - Room Difficulty 3 (%)":
					val.SetValue((float)DifficultyManager.PourcentageRoom3, true);
					break;
				case "Float Slider - Number of Enemy":
					val.SetValue((float)DifficultyManager.EnemyMultiplier, true);
					break;
				case "Float Slider - Shop Price Multiplier":
					val.SetValue(DifficultyManager.ShopMultiplier, true);
					break;
				case "Float Slider - Valuable Multiplier":
					val.SetValue((float)DifficultyManager.ValuableMultiplier, true);
					break;
				}
			}
		}

		private static void UpdateDifficultyRightPopup(string difficulty)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_051d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0541: Unknown result type (might be due to invalid IL or missing references)
			//IL_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_0589: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0619: Unknown result type (might be due to invalid IL or missing references)
			//IL_0658: Unknown result type (might be due to invalid IL or missing references)
			//IL_067c: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_070c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0730: Unknown result type (might be due to invalid IL or missing references)
			//IL_0754: Unknown result type (might be due to invalid IL or missing references)
			//IL_0793: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07db: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0823: Unknown result type (might be due to invalid IL or missing references)
			//IL_0847: Unknown result type (might be due to invalid IL or missing references)
			//IL_086b: Unknown result type (might be due to invalid IL or missing references)
			//IL_088f: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0916: Unknown result type (might be due to invalid IL or missing references)
			//IL_093a: Unknown result type (might be due to invalid IL or missing references)
			//IL_095e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0982: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ca: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)popupRight != (Object)null || (Object)(object)popupPageDifficulty != (Object)null)
			{
				REPOPopupPage obj = popupRight;
				if (obj != null)
				{
					obj.ClosePage(false);
				}
				REPOPopupPage obj2 = popupPageDifficulty;
				if (obj2 != null)
				{
					obj2.ClosePage(false);
				}
			}
			popupRight = MenuAPI.CreateREPOPopupPage("Difficulty Details", (PresetSide)1, true, true, 2.5f);
			popupPageDifficulty = MenuAPI.CreateREPOPopupPage("Difficulty Details", (PresetSide)1, true, true, 0f);
			popupRight.maskPadding = new Padding(10f, 10f, 10f, 0f);
			if ((Object)(object)popupRight == (Object)null || (Object)(object)popupPageDifficulty == (Object)null)
			{
				Debug.LogWarning((object)"[MyMod] Right popup not initialized yet.");
				return;
			}
			Debug.Log((object)("[MyMod] Opening: " + SelectedDifficulty));
			if (difficulty == "Custom")
			{
				popupRight.OpenPage(true);
				REPOPopupPage obj3 = popupRight;
				object obj4 = <>c.<>9__7_0;
				if (obj4 == null)
				{
					ScrollViewBuilderDelegate val2 = delegate(Transform scroll)
					{
						//IL_00af: Unknown result type (might be due to invalid IL or missing references)
						//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
						//IL_0154: Unknown result type (might be due to invalid IL or missing references)
						//IL_01af: Unknown result type (might be due to invalid IL or missing references)
						//IL_020a: Unknown result type (might be due to invalid IL or missing references)
						//IL_0265: Unknown result type (might be due to invalid IL or missing references)
						//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
						//IL_031b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0375: Unknown result type (might be due to invalid IL or missing references)
						//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
						string[] array = new string[13]
						{
							"None", "Easy", "Normal", "Normal+", "Normal++", "Hard", "Hard+", "Hard++", "Hardcore", "Hardcore+",
							"Nightmare", "IsThatEvenPossible", "CrazyMonster"
						};
						REPOSlider val3 = MenuAPI.CreateREPOSlider("Difficulty Preset", "", (Action<string>)delegate(string difficulty)
						{
							ApplyPreset(difficulty);
							UpdateSliders();
							DifficultyManager.DifficultyPreset = difficulty;
							DifficultySaveManager.SaveDifficulty("Custom");
						}, scroll, array, DifficultyManager.DifficultyPreset, new Vector2(0f, 210f), "", "", (BarBehavior)0);
						MenuAPI.CreateREPOSlider("Extraction Amount", "", (Action<float>)delegate(float val)
						{
							DifficultyManager.ExtractionMultiplier = (int)val;
							DifficultySaveManager.SaveDifficulty("Custom");
						}, scroll, new Vector2(0f, 190f), 0f, 12f, 0, (float)DifficultyManager.ExtractionMultiplier, "", "", (BarBehavior)0);
						MenuAPI.CreateREPOSlider("MaxExtraction Amount", "", (Action<float>)delegate(float val)
						{
							DifficultyManager.ExtractionMaxMultiplier = (int)val;
							DifficultySaveManager.SaveDifficulty("Custom");
						}, scroll, new Vector2(0f, 170f), 0f, 12f, 0, (float)DifficultyManager.ExtractionMaxMultiplier, "", "", (BarBehavior)0);
						MenuAPI.CreateREPOSlider("Room Difficulty 1 (%)", "", (Action<float>)delegate(float val)
						{
							DifficultyManager.PourcentageRoom1 = (int)val;
							DifficultySaveManager.SaveDifficulty("Custom");
						}, scroll, new Vector2(0f, 150f), 0f, 100f, 0, (float)DifficultyManager.PourcentageRoom1, "", "", (BarBehavior)0);
						MenuAPI.CreateREPOSlider("Room Difficulty 2 (%)", "", (Action<float>)delegate(float val)
						{
							DifficultyManager.PourcentageRoom2 = (int)val;
							DifficultySaveManager.SaveDifficulty("Custom");
						}, scroll, new Vector2(0f, 130f), 0f, 100f, 0, (float)DifficultyManager.PourcentageRoom2, "", "", (BarBehavior)0);
						MenuAPI.CreateREPOSlider("Room Difficulty 3 (%)", "", (Action<float>)delegate(float val)
						{
							DifficultyManager.PourcentageRoom3 = (int)val;
							DifficultySaveManager.SaveDifficulty("Custom");
						}, scroll, new Vector2(0f, 110f), 0f, 100f, 0, (float)DifficultyManager.PourcentageRoom3, "", "", (BarBehavior)0);
						MenuAPI.CreateREPOSlider("Number of Enemy", "", (Action<float>)delegate(float val)
						{
							DifficultyManager.EnemyMultiplier = (int)val;
							DifficultySaveManager.SaveDifficulty("Custom");
						}, scroll, new Vector2(0f, 90f), 0f, 20f, 0, (float)DifficultyManager.EnemyMultiplier, "", "", (BarBehavior)0);
						MenuAPI.CreateREPOSlider("Shop Price Multiplier", "", (Action<float>)delegate(float val)
						{
							DifficultyManager.ShopMultiplier = val;
							DifficultySaveManager.SaveDifficulty("Custom");
						}, scroll, new Vector2(0f, 70f), 0f, 10f, 1, DifficultyManager.ShopMultiplier, "", "", (BarBehavior)0);
						MenuAPI.CreateREPOSlider("Valuable Multiplier", "", (Action<float>)delegate(float val)
						{
							DifficultyManager.ValuableMultiplier = (int)val;
							DifficultySaveManager.SaveDifficulty("Custom");
						}, scroll, new Vector2(0f, 50f), 1f, 10f, 0, (float)DifficultyManager.ValuableMultiplier, "", "", (BarBehavior)0);
						MenuAPI.CreateREPOSlider("Multiplier Enemy Life", "", (Action<float>)delegate(float val)
						{
							DifficultyManager.MultiplierEnemyLife = (int)val;
							DifficultySaveManager.SaveDifficulty("Custom");
						}, scroll, new Vector2(0f, 30f), 1f, 10f, 0, (float)DifficultyManager.MultiplierEnemyLife, "", "", (BarBehavior)0);
						return (RectTransform)(object)((scroll is RectTransform) ? scroll : null);
					};
					<>c.<>9__7_0 = val2;
					obj4 = (object)val2;
				}
				obj3.AddElementToScrollView((ScrollViewBuilderDelegate)obj4, 0f, 0f);
				return;
			}
			popupPageDifficulty.OpenPage(true);
			switch (difficulty)
			{
			case "Easy":
				MenuAPI.CreateREPOLabel("Enemy Number (2)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 220f));
				MenuAPI.CreateREPOLabel("Start Number Room (6)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 190f));
				MenuAPI.CreateREPOLabel("Start Extraction (1)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 160f));
				MenuAPI.CreateREPOLabel("Max Extraction (3)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 130f));
				MenuAPI.CreateREPOLabel("Valuable boost (x2)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 100f));
				MenuAPI.CreateREPOLabel("Shop price (x0.75)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 70f));
				MenuAPI.CreateREPOLabel("Average Difficulty room (1)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 40f));
				MenuAPI.CreateREPOLabel("Enemy Multiplier Life (x0.5)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 10f));
				break;
			case "Normal":
				MenuAPI.CreateREPOLabel("Enemy Number (2)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 220f));
				MenuAPI.CreateREPOLabel("Start Number Room (8)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 190f));
				MenuAPI.CreateREPOLabel("Start Extraction (1)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 160f));
				MenuAPI.CreateREPOLabel("Max Extraction (4)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 130f));
				MenuAPI.CreateREPOLabel("Valuable boost (x1)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 100f));
				MenuAPI.CreateREPOLabel("Shop price (x1)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 70f));
				MenuAPI.CreateREPOLabel("Average Difficulty room (1)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 40f));
				MenuAPI.CreateREPOLabel("Enemy Multiplier Life (x1)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 10f));
				break;
			case "Hard":
				MenuAPI.CreateREPOLabel("Enemy Number (3)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 220f));
				MenuAPI.CreateREPOLabel("Start Number Room (8)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 190f));
				MenuAPI.CreateREPOLabel("Start Extraction (2)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 160f));
				MenuAPI.CreateREPOLabel("Max Extraction (6)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 130f));
				MenuAPI.CreateREPOLabel("Valuable boost (x2)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 100f));
				MenuAPI.CreateREPOLabel("Shop price (x1.5)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 70f));
				MenuAPI.CreateREPOLabel("Average Difficulty room (1)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 40f));
				MenuAPI.CreateREPOLabel("Enemy Multiplier Life (x1)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 10f));
				break;
			case "Hardcore":
				MenuAPI.CreateREPOLabel("Enemy Number (5)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 220f));
				MenuAPI.CreateREPOLabel("Start Number Room (10)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 190f));
				MenuAPI.CreateREPOLabel("Start Extraction (3)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 160f));
				MenuAPI.CreateREPOLabel("Max Extraction (8)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 130f));
				MenuAPI.CreateREPOLabel("Valuable boost (x3)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 100f));
				MenuAPI.CreateREPOLabel("Shop price (x2)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 70f));
				MenuAPI.CreateREPOLabel("Average Difficulty room (1 & 2)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 40f));
				MenuAPI.CreateREPOLabel("Enemy Multiplier Life (x2)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 10f));
				break;
			case "Nightmare":
				MenuAPI.CreateREPOLabel("Enemy Number (7)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 220f));
				MenuAPI.CreateREPOLabel("Start Number Room (12)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 190f));
				MenuAPI.CreateREPOLabel("Start Extraction (4)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 160f));
				MenuAPI.CreateREPOLabel("Max Extraction (10)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 130f));
				MenuAPI.CreateREPOLabel("Valuable boost (x4)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 100f));
				MenuAPI.CreateREPOLabel("Shop price (x2.5)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 70f));
				MenuAPI.CreateREPOLabel("Average Difficulty room (1 & 2 & 3)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 40f));
				MenuAPI.CreateREPOLabel("Enemy Multiplier Life (x2)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 10f));
				break;
			case "IsThatEvenPossible":
				MenuAPI.CreateREPOLabel("Enemy Number (10)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 220f));
				MenuAPI.CreateREPOLabel("Start Number Room (15)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 190f));
				MenuAPI.CreateREPOLabel("Start Extraction (5)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 160f));
				MenuAPI.CreateREPOLabel("Max Extraction (12)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 130f));
				MenuAPI.CreateREPOLabel("Valuable boost (x5)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 100f));
				MenuAPI.CreateREPOLabel("Shop price (x3)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 70f));
				MenuAPI.CreateREPOLabel("Average Difficulty room (2 & 3)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 40f));
				MenuAPI.CreateREPOLabel("Enemy Multiplier Life (x3)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 10f));
				break;
			case "CrazyMonster":
				MenuAPI.CreateREPOLabel("Enemy Number (12)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 220f));
				MenuAPI.CreateREPOLabel("Start Number Room (8)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 190f));
				MenuAPI.CreateREPOLabel("Start Extraction (1)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 160f));
				MenuAPI.CreateREPOLabel("Max Extraction (4)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 130f));
				MenuAPI.CreateREPOLabel("Valuable boost (x2)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 100f));
				MenuAPI.CreateREPOLabel("Shop price (x0.5)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 70f));
				MenuAPI.CreateREPOLabel("Average Difficulty room (3)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 40f));
				MenuAPI.CreateREPOLabel("Enemy Multiplier Life (x1)", ((Component)popupPageDifficulty).transform, new Vector2(350f, 10f));
				break;
			}
		}
	}
	public class ExplosiveDeathEvent : MonoBehaviour
	{
		private class ExplosiveDeathManager : MonoBehaviour
		{
			private ExplosiveDeathEvent parentEvent;

			private HashSet<EnemyParent> deadEnemies = new HashSet<EnemyParent>();

			private HashSet<Vector3> explosionPositions = new HashSet<Vector3>();

			public void Initialize(ExplosiveDeathEvent parent, float duration)
			{
				parentEvent = parent;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
				Debug.Log((object)"[ExplosiveDeathEvent] Manager initialized.");
				((MonoBehaviour)this).StartCoroutine(MonitorEnemies(duration));
			}

			private IEnumerator MonitorEnemies(float duration)
			{
				Debug.Log((object)"[ExplosiveDeathEvent] Monitoring enemies started.");
				float elapsed = 0f;
				while (elapsed < duration && isExplosiveDeathActive)
				{
					if ((Object)(object)EnemyDirector.instance == (Object)null || EnemyDirector.instance.enemiesSpawned == null)
					{
						Debug.LogWarning((object)"[ExplosiveDeathEvent] EnemyDirector or enemiesSpawned is null. Waiting...");
						yield return (object)new WaitForSeconds(checkInterval);
						elapsed += checkInterval;
						continue;
					}
					foreach (EnemyParent enemyParent in EnemyDirector.instance.enemiesSpawned)
					{
						if (!((Object)(object)enemyParent == (Object)null) && !((Object)(object)enemyParent.Enemy == (Object)null) && !((Object)(object)((Component)enemyParent.Enemy).gameObject == (Object)null) && !deadEnemies.Contains(enemyParent) && enemyParent.Enemy.HasHealth && (Object)(object)enemyParent.Enemy.Health != (Object)null && enemyParent.Enemy.Health.healthCurrent <= 0)
						{
							deadEnemies.Add(enemyParent);
							TriggerExplosion(enemyParent);
						}
					}
					yield return (object)new WaitForSeconds(checkInterval);
					elapsed += checkInterval;
				}
				isExplosiveDeathActive = false;
				deadEnemies.Clear();
				explosionPositions.Clear();
				Debug.Log((object)"[ExplosiveDeathEvent] Monitoring ended. Cleaning up.");
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}

			private void TriggerExplosion(EnemyParent enemyParent)
			{
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: 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_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_019a: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_013f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				//IL_0146: Unknown result type (might be due to invalid IL or missing references)
				//IL_014d: Expected O, but got Unknown
				//IL_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_017a: Unknown result type (might be due to invalid IL or missing references)
				string name = ((Object)((Component)enemyParent.Enemy).gameObject).name;
				Vector3 val = (((Object)(object)enemyParent.Enemy.CenterTransform != (Object)null) ? enemyParent.Enemy.CenterTransform.position : ((Component)enemyParent.Enemy).transform.position);
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(Mathf.Round(val.x * 1000f) / 1000f, Mathf.Round(val.y * 1000f) / 1000f, Mathf.Round(val.z * 1000f) / 1000f);
				if (explosionPositions.Contains(val2))
				{
					Debug.Log((object)$"[ExplosiveDeathEvent] Explosion already triggered at {val2} for {name}. Skipping.");
					return;
				}
				explosionPositions.Add(val2);
				Debug.Log((object)$"[ExplosiveDeathEvent] Triggering explosion for {name} at {val}");
				if (SemiFunc.IsMultiplayer())
				{
					if (!PhotonNetwork.IsConnectedAndReady)
					{
						Debug.LogWarning((object)"[ExplosiveDeathEvent] Photon is not connected. Cannot raise event.");
						return;
					}
					object[] array = new object[2] { val, name };
					Debug.Log((object)$"[ExplosiveDeathEvent] Preparing to raise event. Position: {val}, EnemyName: {name}");
					RaiseEventOptions val3 = new RaiseEventOptions
					{
						Receivers = (ReceiverGroup)1
					};
					bool flag = PhotonNetwork.RaiseEvent((byte)100, (object)array, val3, SendOptions.SendReliable);
					Debug.Log((object)$"[ExplosiveDeathEvent] Raised event {(byte)100} for {name} at {val}. Success: {flag}");
				}
				else
				{
					CreateExplosion(val, name);
				}
			}
		}

		public const byte ExplosiveDeathEventCode = 100;

		[SerializeField]
		private GameObject explosionPrefab;

		private static bool isExplosiveDeathActive = false;

		private static float effectDuration = 180f;

		private static float checkInterval = 0.1f;

		private void Awake()
		{
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			Debug.Log((object)"[ExplosiveDeathEvent] Awake called. Initializing NetworkEventHandler.");
		}

		public void Execute()
		{
			((MonoBehaviour)CoroutineRunner.instance).StartCoroutine(ExecuteCoroutine());
		}

		private IEnumerator ExecuteCoroutine()
		{
			if (isExplosiveDeathActive)
			{
				Debug.LogWarning((object)"[ExplosiveDeathEvent] Explosive death event is already active. Ignoring.");
				yield break;
			}
			if ((Object)(object)EnemyDirector.instance == (Object)null)
			{
				Debug.LogWarning((object)"[ExplosiveDeathEvent] EnemyDirector.instance is null. Cannot execute.");
				yield break;
			}
			Debug.Log((object)$"[ExplosiveDeathEvent] Starting explosive death event for {effectDuration} seconds.");
			isExplosiveDeathActive = true;
			GameObject managerObj = new GameObject("ExplosiveDeathManager");
			ExplosiveDeathManager manager = managerObj.AddComponent<ExplosiveDeathManager>();
			manager.Initialize(this, effectDuration);
		}

		public static void CreateExplosion(Vector3 position, string sourceName)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			try
			{
				GameObject val = Resources.Load<GameObject>("Effects/Part Prefab Explosion");
				if ((Object)(object)val == (Object)null)
				{
					Debug.LogError((object)("[ExplosiveDeathEvent] Failed to load explosion prefab for " + sourceName + ". Skipping explosion."));
					return;
				}
				GameObject val2 = Object.Instantiate<GameObject>(val, position, Quaternion.identity);
				Debug.Log((object)$"[ExplosiveDeathEvent] Instantiated explosion for {sourceName} at {position}: {((Object)val2).name}");
				ParticleScriptExplosion component = val2.GetComponent<ParticleScriptExplosion>();
				if ((Object)(object)component != (Object)null)
				{
					if ((Object)(object)component.explosionPreset == (Object)null)
					{
						ExplosionPreset val3 = Resources.Load<ExplosionPreset>("Explosions/ExplosionPreset");
						if ((Object)(object)val3 == (Object)null)
						{
							val3 = ScriptableObject.CreateInstance<ExplosionPreset>();
							val3.explosionForceMultiplier = 1f;
							val3.explosionColors = new Gradient();
							val3.smokeColors = new Gradient();
							val3.lightColor = new Gradient();
							Debug.Log((object)("[ExplosiveDeathEvent] Created temporary ExplosionPreset for " + sourceName));
						}
						component.explosionPreset = val3;
					}
					ParticlePrefabExplosion val4 = component.Spawn(position, 1f, 25, 25, 2f, false, false, 1f);
					if ((Object)(object)val4 != (Object)null)
					{
						Debug.Log((object)("[ExplosiveDeathEvent] Spawned particle effect for " + sourceName + ": " + ((Object)((Component)val4).gameObject).name));
						Object.Destroy((Object)(object)((Component)val4).gameObject, 2f);
					}
					else
					{
						Debug.LogWarning((object)("[ExplosiveDeathEvent] Failed to spawn particle effect for " + sourceName + "."));
					}
				}
				else
				{
					Debug.LogWarning((object)("[ExplosiveDeathEvent] No ParticleScriptExplosion on prefab for " + sourceName + "."));
				}
				Object.Destroy((Object)(object)val2, 2f);
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[ExplosiveDeathEvent] Error creating explosion for " + sourceName + ": " + ex.Message));
			}
		}
	}
}
namespace DifficultyFeature.DifficultyUpdate.GenerationRework
{
	[HarmonyPatch(typeof(ValuableDirector), "SetupHost")]
	public static class Patch_ValuableDirector_SetupHost
	{
		private static readonly ManualLogSource Log = Logger.CreateLogSource("MyMOD.RunManagerPatch");

		public static void Prefix(ValuableDirector __instance)
		{
			DifficultyManager.DifficultyLevel currentDifficulty = DifficultyManager.CurrentDifficulty;
			float valuableMultiplier = DifficultyManager3.GetValuableMultiplier(currentDifficulty);
			Log.LogInfo((object)$"[Valuables] Applying valuable multiplier x{valuableMultiplier} for difficulty {currentDifficulty}");
			__instance.totalMaxAmountCurve = ScaleCurve(__instance.totalMaxAmountCurve, valuableMultiplier);
			__instance.tinyMaxAmountCurve = ScaleCurve(__instance.tinyMaxAmountCurve, valuableMultiplier);
			__instance.smallMaxAmountCurve = ScaleCurve(__instance.smallMaxAmountCurve, valuableMultiplier);
			__instance.mediumMaxAmountCurve = ScaleCurve(__instance.mediumMaxAmountCurve, valuableMultiplier);
			__instance.bigMaxAmountCurve = ScaleCurve(__instance.bigMaxAmountCurve, valuableMultiplier);
			__instance.wideMaxAmountCurve = ScaleCurve(__instance.wideMaxAmountCurve, valuableMultiplier);
			__instance.tallMaxAmountCurve = ScaleCurve(__instance.tallMaxAmountCurve, valuableMultiplier);
			__instance.veryTallMaxAmountCurve = ScaleCurve(__instance.veryTallMaxAmountCurve, valuableMultiplier);
		}

		private static AnimationCurve ScaleCurve(AnimationCurve original, float multiplier)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			Keyframe[] keys = original.keys;
			for (int i = 0; i < keys.Length; i++)
			{
				ref Keyframe reference = ref keys[i];
				((Keyframe)(ref reference)).value = ((Keyframe)(ref reference)).value * multiplier;
			}
			return new AnimationCurve(keys);
		}
	}
	[HarmonyPatch(typeof(EnemyDirector), "AmountSetup")]
	public static class Patch_EnemyDirector_AmountSetup
	{
		private static readonly ManualLogSource Log = Logger.CreateLogSource("MyMOD.RunManagerPatch");

		public static bool Prefix(EnemyDirector __instance)
		{
			Log.LogInfo((object)"[Difficulty] Custom Enemy Setup Launched");
			List<EnemySetup> list = new List<EnemySetup>();
			int levelsCompleted = RunManager.instance.levelsCompleted;
			DifficultyManager.DifficultyLevel currentDifficulty = DifficultyManager.CurrentDifficulty;
			int targetEnemyCount = GetTargetEnemyCount(levelsCompleted, currentDifficulty);
			Log.LogInfo((object)$"[Difficulty] Level Completed: {levelsCompleted}, Target Enemy Count: {targetEnemyCount}");
			AddEnemies(__instance.enemiesDifficulty1, list, levelsCompleted, 1);
			AddEnemies(__instance.enemiesDifficulty2, list, levelsCompleted, 3);
			AddEnemies(__instance.enemiesDifficulty3, list, levelsCompleted, 5);
			ListExtension.Shuffle<EnemySetup>((IList<EnemySetup>)list);
			if (list.Count > targetEnemyCount)
			{
				list = list.GetRange(0, targetEnemyCount);
			}
			FieldInfo fieldInfo = AccessTools.Field(typeof(EnemyDirector), "enemyList");
			fieldInfo.SetValue(__instance, list);
			__instance.totalAmount = list.Count;
			foreach (EnemySetup item in list)
			{
				try
				{
					Log.LogInfo((object)$"[Difficulty]  enemy list: {((Object)item).name} && {((Object)item.rarityPreset).name}&& {item.levelsCompletedMin}");
				}
				catch (Exception)
				{
					Log.LogError((object)("[Difficulty]  enemy list: " + ((Object)item).name));
				}
			}
			Log.LogInfo((object)$"[Difficulty] Final enemy list count: {list.Count}");
			return false;
		}

		private static int GetTargetEnemyCount(int completed, DifficultyManager.DifficultyLevel difficulty)
		{
			int num = 2 + completed;
			return difficulty switch
			{
				DifficultyManager.DifficultyLevel.Hard => num + 1, 
				DifficultyManager.DifficultyLevel.Hardcore => num + 3, 
				DifficultyManager.DifficultyLevel.Nightmare => num + 5, 
				DifficultyManager.DifficultyLevel.IsThatEvenPossible => num + 8, 
				DifficultyManager.DifficultyLevel.CrazyMonster => num + 10, 
				DifficultyManager.DifficultyLevel.Custom => DifficultyManager.EnemyMultiplier, 
				_ => num, 
			};
		}

		private static void AddEnemies(List<EnemySetup> sourceList, List<EnemySetup> target, int completed, int tier)
		{
			foreach (EnemySetup source in sourceList)
			{
				if ((Object)(object)source == (Object)null)
				{
					continue;
				}
				int num = Random.Range(0, 100);
				Log.LogInfo((object)$"[DifficultyAddEnemies]  Random: {num}");
				try
				{
					Log.LogInfo((object)$"[DifficultyAddEnemies]  enemy list: {((Object)source).name} && {((Object)source.rarityPreset).name}&& {source.levelsCompletedMin}");
				}
				catch (Exception)
				{
					Log.LogError((object)("[DifficultyAddEnemies]  enemy list: " + ((Object)source).name));
				}
				try
				{
					if (((Object)source.rarityPreset).name.ToLower().Contains("rare") && num >= 20)
					{
						continue;
					}
				}
				catch (Exception)
				{
				}
				if (!source.levelsCompletedCondition || (completed >= source.levelsCompletedMin && completed <= source.levelsCompletedMax))
				{
					target.Add(source);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ShopManager), "ShopInitialize")]
	public static class Patch_ShopManager_ShopInitialize
	{
		private static readonly ManualLogSource Log = Logger.CreateLogSource("MyMOD.ShopPatch");

		public static void Prefix(ShopManager __instance)
		{
			float shopPriceMultiplier = DifficultyManager3.GetShopPriceMultiplier(DifficultyManager.CurrentDifficulty);
			__instance.itemValueMultiplier = shopPriceMultiplier * 4f;
			Log.LogError((object)$"{__instance.itemValueMultiplier}");
			Log.LogInfo((object)$"[Difficulty] Shop price multiplier applied: x{shopPriceMultiplier}");
		}
	}
	public static class DifficultyScaler
	{
		private static readonly ManualLogSource Log = Logger.CreateLogSource("MyMOD.RunManagerPatch");

		public static void ApplyDifficultyScaling()
		{
			DifficultyManager.DifficultyLevel currentDifficulty = DifficultyManager.CurrentDifficulty;
			float valuableMultiplier = DifficultyManager3.GetValuableMultiplier(currentDifficulty);
			Log.LogInfo((object)$"[Valuables] Applying valuable multiplier x{valuableMultiplier} for difficulty {currentDifficulty}");
		}
	}
	public static class DifficultyManager3
	{
		public static DifficultyManager.DifficultyLevel CurrentDifficulty = DifficultyManager.CurrentDifficulty;

		public static float GetValuableMultiplier(DifficultyManager.DifficultyLevel difficulty)
		{
			if (1 == 0)
			{
			}
			float result = difficulty switch
			{
				DifficultyManager.DifficultyLevel.Easy => 2f, 
				DifficultyManager.DifficultyLevel.Hard => 1.5f, 
				DifficultyManager.DifficultyLevel.Hardcore => 1.5f, 
				DifficultyManager.DifficultyLevel.Nightmare => 2f, 
				DifficultyManager.DifficultyLevel.IsThatEvenPossible => 3f, 
				DifficultyManager.DifficultyLevel.CrazyMonster => 2f, 
				DifficultyManager.DifficultyLevel.Custom => DifficultyManager.ValuableMultiplier, 
				_ => 1f, 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		public static float GetShopPriceMultiplier(DifficultyManager.DifficultyLevel difficulty)
		{
			if (1 == 0)
			{
			}
			float result = difficulty switch
			{
				DifficultyManager.DifficultyLevel.Easy => 0.75f, 
				DifficultyManager.DifficultyLevel.Hard => 1.5f, 
				DifficultyManager.DifficultyLevel.Hardcore => 2f, 
				DifficultyManager.DifficultyLevel.Nightmare => 2.5f, 
				DifficultyManager.DifficultyLevel.IsThatEvenPossible => 3f, 
				DifficultyManager.DifficultyLevel.CrazyMonster => 0.5f, 
				DifficultyManager.DifficultyLevel.Custom => DifficultyManager.ShopMultiplier, 
				_ => 1f, 
			};
			if (1 == 0)
			{
			}
			return result;
		}
	}
	[HarmonyPatch(typeof(LevelGenerator), "TileGeneration")]
	public static class Patch_TileGeneration
	{
		private static readonly ManualLogSource Log = Logger.CreateLogSource("MyMOD.RunManagerPatch");

		public static bool Prefix(LevelGenerator __instance, ref IEnumerator __result)
		{
			__result = CustomTileGen(__instance);
			return false;
		}

		private static IEnumerator CustomTileGen(LevelGenerator gen)
		{
			bool success = false;
			while (!success)
			{
				Log.LogInfo((object)"[CustomTileGen] Override launched!");
				FieldInfo waitingField = AccessTools.Field(typeof(LevelGenerator), "waitingForSubCoroutine");
				waitingField.SetValue(gen, true);
				int width = gen.LevelWidth;
				int height = gen.LevelHeight;
				Log.LogInfo((object)("[CustomTileGen]" + gen.LevelWidth));
				Log.LogInfo((object)("[CustomTileGen]" + gen.LevelHeight));
				FieldInfo gridField = AccessTools.Field(typeof(LevelGenerator), "LevelGrid");
				Tile[,] grid = new Tile[width, height];
				if (RunManager.instance.levelsCompleted % 6 + 1 == 6 && DifficultyManager.LevelScaler)
				{
					switch (DifficultyManager.CurrentDifficulty)
					{
					case DifficultyManager.DifficultyLevel.Easy:
						switch (RunManager.instance.levelsCompleted)
						{
						case 5:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.Normal;
							break;
						case 11:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.Hard;
							break;
						case 17:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.Hardcore;
							break;
						case 23:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.Nightmare;
							break;
						case 29:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.IsThatEvenPossible;
							break;
						}
						break;
					case DifficultyManager.DifficultyLevel.Normal:
						switch (RunManager.instance.levelsCompleted)
						{
						case 5:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.Hard;
							break;
						case 11:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.Hardcore;
							break;
						case 17:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.Nightmare;
							break;
						case 23:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.IsThatEvenPossible;
							break;
						}
						break;
					case DifficultyManager.DifficultyLevel.Hard:
						switch (RunManager.instance.levelsCompleted)
						{
						case 5:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.Hardcore;
							break;
						case 11:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.Nightmare;
							break;
						case 17:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.IsThatEvenPossible;
							break;
						}
						break;
					case DifficultyManager.DifficultyLevel.Hardcore:
						switch (RunManager.instance.levelsCompleted)
						{
						case 5:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.Nightmare;
							break;
						case 11:
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.IsThatEvenPossible;
							break;
						}
						break;
					case DifficultyManager.DifficultyLevel.Nightmare:
					{
						int levelsCompleted = RunManager.instance.levelsCompleted;
						int num = levelsCompleted;
						if (num == 5)
						{
							DifficultyManager.CurrentDifficulty = DifficultyManager.DifficultyLevel.IsThatEvenPossible;
						}
						break;
					}
					}
					DifficultySaveManager.SaveDifficulty(DifficultyManager.CurrentDifficulty.ToString());
				}
				for (int x = 0; x < width; x++)
				{
					for (int y = 0; y < height; y++)
					{
						grid[x, y] = new Tile
						{
							x = x,
							y = y,
							active = false,
							type = (Type)(-1)
						};
					}
				}
				if ((Object)(object)gen.Level == (Object)(object)RunManager.instance.levelShop || (Object)(object)gen.Level == (Object)(object)RunManager.instance.levelArena || (Object)(object)gen.Level == (Object)(object)RunManager.instance.levelMainMenu || (Object)(object)gen.Level == (Object)(object)RunManager.instance.levelLobby || (Object)(object)gen.Level == (Object)(object)RunManager.instance.levelLobbyMenu)
				{
					grid[width / 2, 0].active = true;
					grid[width / 2, 0].first = true;
					gen.Level.PassageMaxAmount = 0;
					gen.DeadEndAmount = 1;
					gen.ExtractionAmount = 0;
					gridField.SetValue(gen, grid);
					waitingField.SetValue(gen, false);
					break;
				}
				int moduleCount = DifficultyManager2.GetModifiedModuleAmount() + RunManager.instance.levelsCompleted / 2;
				if (moduleCount > DifficultyManager2.GetMaxModuleAmount())
				{
					moduleCount = DifficultyManager2.GetMaxModuleAmount();
				}
				DifficultyManager.DifficultyLevel difficulty = DifficultyManager.CurrentDifficulty;
				gen.Level.PassageMaxAmount = Mathf.RoundToInt((float)gen.Level.PassageMaxAmount);
				Log.LogInfo((object)$"[Difficulty] PassageAmount → {gen.Level.PassageMaxAmount}");
				gen.DeadEndAmount = Mathf.RoundToInt((float)gen.DeadEndAmount);
				Log.LogInfo((object)$"[Difficulty] DeadEndAmount → {gen.DeadEndAmount}");
				int baseExtraction = DifficultyManager2.GetFixedExtractionAmount(difficulty);
				int extraFromProgress = (RunManager.instance.levelsCompleted + 1) / 2;
				int maxExtraction = DifficultyManager2.GetExtractionCap(difficulty);
				gen.ExtractionAmount = Mathf.Min(baseExtraction + extraFromProgress, maxExtraction);
				Log.LogInfo((object)$"[Difficulty] ExtractionAmount → {gen.ExtractionAmount} (Base {baseExtraction} + Progress)");
				int completed = RunManager.instance.levelsCompleted;
				switch (difficulty)
				{
				case DifficultyManager.DifficultyLevel.Easy:
					if (completed < 3)
					{
						RarityOverrideManager.Set(1f, 0f, 0f);
					}
					else if (completed < 6)
					{
						RarityOverrideManager.Set(0.7f, 0.3f, 0f);
					}
					else
					{
						RarityOverrideManager.Set(0.6f, 0.4f, 0f);
					}
					break;
				case DifficultyManager.DifficultyLevel.Normal:
				case DifficultyManager.DifficultyLevel.Hard:
					if (completed < 3)
					{
						RarityOverrideManager.Set(1f, 0f, 0f);
					}
					else if (completed < 6)
					{
						RarityOverrideManager.Set(0.7f, 0.3f, 0f);
					}
					else
					{
						RarityOverrideManager.Set(0.4f, 0.4f, 0.2f);
					}
					break;
				case DifficultyManager.DifficultyLevel.Hardcore:
					if (completed < 4)
					{
						RarityOverrideManager.Set(0.4f, 0.6f, 0f);
					}
					else
					{
						RarityOverrideManager.Set(0.2f, 0.5f, 0.3f);
					}
					break;
				case DifficultyManager.DifficultyLevel.Nightmare:
					RarityOverrideManager.Set(0.3f, 0.4f, 0.3f);
					break;
				case DifficultyManager.DifficultyLevel.IsThatEvenPossible:
					RarityOverrideManager.Set(0.1f, 0.3f, 0.6f);
					break;
				case DifficultyManager.DifficultyLevel.CrazyMonster:
					RarityOverrideManager.Set(0f, 0.2f, 0.8f);
					break;
				case DifficultyManager.DifficultyLevel.Custom:
					RarityOverrideManager.Set((float)DifficultyManager.PourcentageRoom1 / 100f, (float)DifficultyManager.PourcentageRoom2 / 100f, (float)DifficultyManager.PourcentageRoom3 / 100f);
					break;
				}
				int centerX = width / 2;
				int centerY = 0;
				grid[centerX, centerY].active = true;
				grid[centerX, centerY].first = true;
				moduleCount--;
				int currentX = centerX;
				int currentY = centerY;
				Random rand = new Random();
				int tentative = 0;
				int tentativeMax = 10;
				bool notworking = true;
				while (moduleCount > 0)
				{
					int dx = 0;
					int dy = 0;
					switch (rand.Next(4))
					{
					case 0:
						dx = 1;
						break;
					case 1:
						dx = -1;
						break;
					case 2:
						dy = 1;
						break;
					case 3:
						dy = -1;
						break;
					}
					int newX = currentX + dx;
					int newY = currentY + dy;
					Log.LogInfo((object)$"[Difficulty] ModuleAmount → {moduleCount} Progress)");
					if (newX >= 0 && newX < width && newY >= 0 && newY < height && !grid[newX, newY].active)
					{
						grid[newX, newY].active = true;
						currentX = newX;
						currentY = newY;
						moduleCount--;
						tentative = 0;
					}
					else
					{
						if (tentative >= tentativeMax)
						{
							Log.LogError((object)$"[Difficulty] ModuleAmount → {moduleCount} Failed)");
							moduleCount = 0;
							success = false;
							notworking = false;
						}
						tentative++;
					}
					yield return null;
				}
				if (notworking)
				{
					success = true;
				}
				List<Tile> possibleExtractionTiles = new List<Tile>();
				for (int x2 = 0; x2 < width; x2++)
				{
					for (int y2 = 0; y2 < height; y2++)
					{
						if (!grid[x2, y2].active)
						{
							int adjacent = 0;
							if (x2 > 0 && grid[x2 - 1, y2].active)
							{
								adjacent++;
							}
							if (x2 < width - 1 && grid[x2 + 1, y2].active)
							{
								adjacent++;
							}
							if (y2 > 0 && grid[x2, y2 - 1].active)
							{
								adjacent++;
							}
							if (y2 < height - 1 && grid[x2, y2 + 1].active)
							{
								adjacent++;
							}
							if (adjacent == 1)
							{
								possibleExtractionTiles.Add(grid[x2, y2]);
							}
						}
					}
				}
				List<Tile> extractionTiles = new List<Tile>
				{
					new Tile
					{
						x = width / 2,
						y = -1
					}
				};
				while (gen.ExtractionAmount > 0 && possibleExtractionTiles.Count > 0)
				{
					Tile best = null;
					float bestDist = -1f;
					foreach (Tile tile in possibleExtractionTiles)
					{
						float minDist = float.MaxValue;
						foreach (Tile used in extractionTiles)
						{
							float dist = Vector2.Distance(new Vector2((float)tile.x, (float)tile.y), new Vector2((float)used.x, (float)used.y));
							if (dist < minDist)
							{
								minDist = dist;
							}
						}
						if (minDist > bestDist)
						{
							bestDist = minDist;
							best = tile;
						}
					}
					if (best != null)
					{
						SetSpecialTile(grid, best, (Type)3);
						extractionTiles.Add(best);
						possibleExtractionTiles.Remove(best);
						gen.ExtractionAmount--;
					}
					yield return null;
				}
				possibleExtractionTiles.RemoveAll((Tile t) => (int)t.type == -1);
				while (gen.DeadEndAmount > 0 && possibleExtractionTiles.Count > 0)
				{
					int index = rand.Next(possibleExtractionTiles.Count);
					Tile tile2 = possibleExtractionTiles[index];
					SetSpecialTile(grid, tile2, (Type)2);
					possibleExtractionTiles.RemoveAt(index);
					gen.DeadEndAmount--;
					yield return null;
				}
				if (success)
				{
					PrintMiniMap(grid);
					gridField.SetValue(gen, grid);
					waitingField.SetValue(gen, false);
					Log.LogInfo((object)"[CustomTileGen] Tile generation completed.");
				}
			}
		}

		private static void SetSpecialTile(Tile[,] grid, Tile target, Type type)
		{
			//IL_0011: 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)
			Tile[,] grid2 = grid;
			target.active = true;
			target.type = type;
			int x = target.x;
			int y = target.y;
			RemoveNeighbor(x - 1, y);
			RemoveNeighbor(x + 1, y);
			RemoveNeighbor(x, y - 1);
			RemoveNeighbor(x, y + 1);
			void RemoveNeighbor(int nx, int ny)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				if (nx >= 0 && nx < grid2.GetLength(0) && ny >= 0 && ny < grid2.GetLength(1))
				{
					grid2[nx, ny].type = (Type)(-1);
				}
			}
		}

		private static void PrintMiniMap(Tile[,] grid)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected I4, but got Unknown
			int length = grid.GetLength(0);
			int length2 = grid.GetLength(1);
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("[TileGen] --- MINI MAP ---");
			for (int num = length2 - 1; num >= 0; num--)
			{
				for (int i = 0; i < length; i++)
				{
					Tile val = grid[i, num];
					if (!val.active)
					{
						stringBuilder.Append(" . ");
						continue;
					}
					Type type = val.type;
					Type val2 = type;
					switch ((int)val2)
					{
					case 3:
						stringBuilder.Append(" E ");
						continue;
					case 2:
						stringBuilder.Append(" D ");
						continue;
					case 1:
						stringBuilder.Append(" P ");
						continue;
					case 0:
						stringBuilder.Append(" N ");
						continue;
					}
					if (val.first)
					{
						stringBuilder.Append(" S ");
					}
					else
					{
						stringBuilder.Append(" # ");
					}
				}
				stringBuilder.AppendLine();
			}
			stringBuilder.AppendLine("[TileGen] ----------------");
			Log.LogInfo((object)stringBuilder.ToString());
		}
	}
	[HarmonyPatch]
	public static class Patch_ModuleGeneration_MoveNext
	{
		private static readonly ManualLogSource Log = Logger.CreateLogSource("MyMOD.ModuleGenerationPatch");

		[HarmonyTargetMethod]
		public static MethodBase TargetMethod()
		{
			Type[] nestedTypes = typeof(LevelGenerator).GetNestedTypes(BindingFlags.Instance | BindingFlags.NonPublic);
			Type[] array = nestedTypes;
			foreach (Type type in array)
			{
				if (type.Name.Contains("ModuleGeneration") && typeof(IEnumerator).IsAssignableFrom(type))
				{
					MethodInfo methodInfo = AccessTools.Method(type, "MoveNext", (Type[])null, (Type[])null);
					if (methodInfo != null)
					{
						return methodInfo;
					}
				}
			}
			Log.LogError((object)"Could not find MoveNext for ModuleGeneration coroutine.");
			return null;
		}

		public static void Postfix(object __instance)
		{
			FieldInfo fieldInfo = AccessTools.Field(__instance.GetType(), "<>4__this");
			if (fieldInfo == null)
			{
				Log.LogError((object)"Could not find '<>4__this' field.");
				return;
			}
			object? value = fieldInfo.GetValue(__instance);
			LevelGenerator val = (LevelGenerator)((value is LevelGenerator) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				Log.LogError((object)"LevelGenerator instance not found.");
			}
			else if (RarityOverrideManager.Rarity1.HasValue)
			{
				val.ModuleRarity1 = RarityOverrideManager.Rarity1.Value;
				val.ModuleRarity2 = RarityOverrideManager.Rarity2.Value;
				val.ModuleRarity3 = RarityOverrideManager.Rarity3.Value;
				Log.LogInfo((object)$"[Patch_ModuleGeneration_MoveNext] Overridden rarities → {val.ModuleRarity1}, {val.ModuleRarity2}, {val.ModuleRarity3}");
			}
			else
			{
				Log.LogInfo((object)"[Patch_ModuleGeneration_MoveNext] No override set, using default values.");
			}
		}
	}
	[HarmonyPatch(typeof(LevelGenerator), "SpawnModule")]
	public static class Patch_SpawnModule_Log
	{
		private static readonly ManualLogSource Log = Logger.CreateLogSource("MyMOD.SpawnModuleLogger");

		public static void Postfix(int x, int y, Vector3 position, Vector3 rotation, Type type)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Log.LogInfo((object)$"[SpawnModule] Spawned module at ({x},{y}) | Type: {type}");
		}
	}
	public static class RarityOverrideManager
	{
		public static float? Rarity1;

		public static float? Rarity2;

		public static float? Rarity3;

		public static void Set(float r1, float r2, float r3)
		{
			Rarity1 = r1;
			Rarity2 = r2;
			Rarity3 = r3;
		}

		public static void Clear()
		{
			Rarity1 = (Rarity2 = (Rarity3 = null));
		}
	}
	public static class DifficultyManager2
	{
		private static readonly ManualLogSource Log = Logger.CreateLogSource("MyMOD.RunManagerPatch");

		public static int GetModifiedModuleAmount()
		{
			Log.LogInfo((object)$"[CustomTileGen] Difficulty: {DifficultyManager.CurrentDifficulty}");
			return DifficultyManager.CurrentDifficulty switch
			{
				DifficultyManager.DifficultyLevel.Easy => 6, 
				DifficultyManager.DifficultyLevel.Hard => 8, 
				DifficultyManager.DifficultyLevel.Hardcore => 10, 
				DifficultyManager.DifficultyLevel.Nightmare => 12, 
				DifficultyManager.DifficultyLevel.IsThatEvenPossible => 14, 
				DifficultyManager.DifficultyLevel.CrazyMonster => 10, 
				DifficultyManager.DifficultyLevel.Custom => CustomRoom(), 
				_ => 8, 
			};
		}

		public static int GetMaxModuleAmount()
		{
			Log.LogInfo((object)$"[CustomTileGen] Difficulty: {DifficultyManager.CurrentDifficulty}");
			return DifficultyManager.CurrentDifficulty switch
			{
				DifficultyManager.DifficultyLevel.Easy => 11, 
				DifficultyManager.DifficultyLevel.Normal => 12, 
				DifficultyManager.DifficultyLevel.Hard => 14, 
				DifficultyManager.DifficultyLevel.Hardcore => 16, 
				DifficultyManager.DifficultyLevel.Nightmare => 18, 
				DifficultyManager.DifficultyLevel.IsThatEvenPossible => 20, 
				DifficultyManager.DifficultyLevel.CrazyMonster => 16, 
				DifficultyManager.DifficultyLevel.Custom => CustomRoom(), 
				_ => 12, 
			};
		}

		public static int CustomRoom()
		{
			if (DifficultyManager.ExtractionMultiplier <= 12 && DifficultyManager.ExtractionMultiplier >= 7)
			{
				return DifficultyManager.RoomNumber;
			}
			if (DifficultyManager.ExtractionMultiplier < 7 && DifficultyManager.ExtractionMultiplier >= 4)
			{
				return 20;
			}
			if (DifficultyManager.ExtractionMultiplier < 4 && DifficultyManager.ExtractionMultiplier >= 2)
			{
				return 15;
			}
			return 10;
		}

		public static float GetPassageMultiplier(DifficultyManager.DifficultyLevel difficulty)
		{
			return 1f + (float)difficulty * 2f;
		}

		public static float GetDeadEndMultiplier(DifficultyManager.DifficultyLevel difficulty)
		{
			return 1f + (float)difficulty * 2f;
		}

		public static int GetFixedExtractionAmount(DifficultyManager.DifficultyLevel difficulty)
		{
			if (1 == 0)
			{
			}
			int result = difficulty switch
			{
				DifficultyManager.DifficultyLevel.Easy => 0, 
				DifficultyManager.DifficultyLevel.Normal => 0, 
				DifficultyManager.DifficultyLevel.Hard => 1, 
				DifficultyManager.DifficultyLevel.Hardcore => 2, 
				DifficultyManager.DifficultyLevel.Nightmare => 3, 
				DifficultyManager.DifficultyLevel.IsThatEvenPossible => 4, 
				DifficultyManager.DifficultyLevel.CrazyMonster => 0, 
				DifficultyManager.DifficultyLevel.Custom => DifficultyManager.ExtractionMultiplier, 
				_ => 1, 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		public static int GetExtractionCap(DifficultyManager.DifficultyLevel difficulty)
		{
			if (1 == 0)
			{
			}
			int result = difficulty switch
			{
				DifficultyManager.DifficultyLevel.Easy => 2, 
				DifficultyManager.DifficultyLevel.Normal => 3, 
				DifficultyManager.DifficultyLevel.Hard => 4, 
				DifficultyManager.DifficultyLevel.Hardcore => 5, 
				DifficultyManager.DifficultyLevel.Nightmare => 6, 
				DifficultyManager.DifficultyLevel.IsThatEvenPossible => 8, 
				DifficultyManager.DifficultyLevel.CrazyMonster => 3, 
				DifficultyManager.DifficultyLevel.Custom => DifficultyManager.ExtractionMaxMultiplier, 
				_ => 4, 
			};
			if (1 == 0)
			{
			}
			return result;
		}
	}
}