Decompiled source of cybergrindbosswaves v1.0.0

CyberGrindBossWaves.dll

Decompiled 2 hours ago
using System;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CyberGrindBossWaves
{
	internal static class BossArenaLoader
	{
		private const string EmbeddedResourceName = "CyberGrindBossWaves.BossArena.cgp";

		private static string _rawContent;

		private static ArenaPattern _cachedPattern;

		public static string CustomArenaFilePath => Path.Combine(Paths.ConfigPath, "CyberGrindBossWaves", "BossArena.cgp");

		public static void Initialize()
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("CyberGrindBossWaves.BossArena.cgp");
			if (stream == null)
			{
				Plugin.Log.LogError((object)"Failed to locate embedded resource 'CyberGrindBossWaves.BossArena.cgp'.");
				return;
			}
			using StreamReader streamReader = new StreamReader(stream, Encoding.UTF8);
			_rawContent = streamReader.ReadToEnd();
		}

		public static ArenaPattern GetBossArenaPattern()
		{
			if ((Object)(object)_cachedPattern != (Object)null)
			{
				return _cachedPattern;
			}
			string rawText = _rawContent;
			if (File.Exists(CustomArenaFilePath))
			{
				try
				{
					string text = File.ReadAllText(CustomArenaFilePath, Encoding.UTF8);
					if (!string.IsNullOrWhiteSpace(text))
					{
						rawText = text;
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Failed reading custom BossArena.cgp override, falling back to embedded layout: " + ex.Message));
				}
			}
			_cachedPattern = ParsePattern(rawText, "BOSS_ARENA.cgp");
			if ((Object)(object)_cachedPattern != (Object)null)
			{
				((Object)_cachedPattern).hideFlags = (HideFlags)32;
			}
			return _cachedPattern;
		}

		private static ArenaPattern ParsePattern(string rawText, string patternName)
		{
			if (string.IsNullOrEmpty(rawText))
			{
				return null;
			}
			string[] array = rawText.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
			if (array.Length < 33)
			{
				Plugin.Log.LogError((object)$"BossArena.cgp has {array.Length} lines instead of 33.");
				return null;
			}
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < 16; i++)
			{
				stringBuilder.Append(array[i].Trim());
				if (i != 15)
				{
					stringBuilder.Append('\n');
				}
			}
			StringBuilder stringBuilder2 = new StringBuilder();
			for (int j = 17; j < 33; j++)
			{
				stringBuilder2.Append(array[j].Trim());
				if (j != 32)
				{
					stringBuilder2.Append('\n');
				}
			}
			ArenaPattern obj = ScriptableObject.CreateInstance<ArenaPattern>();
			((Object)obj).name = patternName;
			obj.heights = stringBuilder.ToString();
			obj.prefabs = stringBuilder2.ToString();
			return obj;
		}
	}
	internal sealed class BossDefinition
	{
		public string Id { get; }

		public string LevelTag { get; }

		public string DisplayName { get; }

		public EnemyType EnemyType { get; }

		public float SpawnHeightOffset { get; }

		public bool DefaultEnabled { get; }

		public bool IsFloating { get; }

		public string ConfigLabel => "[" + LevelTag + "] " + DisplayName;

		public BossDefinition(string id, string levelTag, string displayName, EnemyType enemyType, float spawnHeightOffset = 0f, bool defaultEnabled = true, bool isFloating = false)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Id = id;
			LevelTag = levelTag;
			DisplayName = displayName;
			EnemyType = enemyType;
			SpawnHeightOffset = spawnHeightOffset;
			DefaultEnabled = defaultEnabled;
			IsFloating = isFloating;
		}
	}
	internal static class BossRoster
	{
		public static readonly BossDefinition[] AllBosses = new BossDefinition[23]
		{
			new BossDefinition("malicious_face", "0-1", "Malicious Face (Maurice)", (EnemyType)4, 5f, defaultEnabled: true, isFloating: true),
			new BossDefinition("swordsmachine", "0-2", "Swordsmachine", (EnemyType)7),
			new BossDefinition("cerberus", "0-5", "Cerberus", (EnemyType)0),
			new BossDefinition("cancerous_rodent", "1-2S", "Cancerous Rodent", (EnemyType)23),
			new BossDefinition("very_cancerous_rodent", "1-2S", "Very Cancerous Rodent", (EnemyType)24),
			new BossDefinition("hideous_mass", "1-3", "Hideous Mass", (EnemyType)2),
			new BossDefinition("v2_1", "1-4", "V2 (1st Encounter)", (EnemyType)8),
			new BossDefinition("gabriel_1", "3-2", "Gabriel, Judge of Hell", (EnemyType)16, 7f, defaultEnabled: true, isFloating: true),
			new BossDefinition("sisyphus", "4-2", "Sisyphean Insurrectionist", (EnemyType)19),
			new BossDefinition("mandalore", "4-3S", "Mysterious Druid Knight (& Owl)", (EnemyType)25, 8f, defaultEnabled: true, isFloating: true),
			new BossDefinition("v2_2", "4-4", "V2 (2nd Encounter)", (EnemyType)22),
			new BossDefinition("ferryman", "5-2", "Ferryman", (EnemyType)26),
			new BossDefinition("gabriel_2", "6-2", "Gabriel, Apostate of Hate", (EnemyType)28, 7f, defaultEnabled: true, isFloating: true),
			new BossDefinition("minotaur", "7-1", "Minotaur", (EnemyType)32),
			new BossDefinition("big_johnator", "7-1S", "Big Johnator", (EnemyType)37),
			new BossDefinition("providence", "8-1", "Providence", (EnemyType)38, 6f, defaultEnabled: true, isFloating: true),
			new BossDefinition("mirror_reaper", "8-1", "Mirror Reaper", (EnemyType)41),
			new BossDefinition("power", "8-3", "Power", (EnemyType)40, 7f, defaultEnabled: true, isFloating: true),
			new BossDefinition("geryon", "8-4", "Geryon", (EnemyType)42, 10f, defaultEnabled: true, isFloating: true),
			new BossDefinition("flesh_prison", "P-1", "Flesh Prison", (EnemyType)17, 18f, defaultEnabled: true, isFloating: true),
			new BossDefinition("minos_prime", "P-1", "Minos Prime", (EnemyType)18),
			new BossDefinition("flesh_panopticon", "P-2", "Flesh Panopticon", (EnemyType)30, 20f, defaultEnabled: true, isFloating: true),
			new BossDefinition("sisyphus_prime", "P-2", "Sisyphus Prime", (EnemyType)29)
		};

		private static readonly FieldRef<EndlessGrid, PrefabDatabase> PrefabDbRef = AccessTools.FieldRefAccess<EndlessGrid, PrefabDatabase>("prefabs");

		private static readonly Random JackpotRng = new Random();

		private static Dictionary<EnemyType, GameObject> _spawnableCache;

		private static int _lastRandomIndex = -1;

		private static int _chronologicalIndex = 0;

		public static void ResetProgression()
		{
			_lastRandomIndex = -1;
			_chronologicalIndex = 0;
		}

		public static bool RollAllBossesJackpot()
		{
			if (!ModConfig.EnableAllBossesJackpot)
			{
				return false;
			}
			return JackpotRng.NextDouble() < 1E-05;
		}

		public static List<BossDefinition> GetAvailablePool(EndlessGrid grid)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			List<BossDefinition> list = new List<BossDefinition>();
			BossDefinition[] allBosses = AllBosses;
			foreach (BossDefinition bossDefinition in allBosses)
			{
				if (ModConfig.IsBossEnabled(bossDefinition) && (Object)(object)ResolveEnemyPrefab(grid, bossDefinition.EnemyType) != (Object)null)
				{
					list.Add(bossDefinition);
				}
			}
			if (list.Count == 0)
			{
				allBosses = AllBosses;
				foreach (BossDefinition bossDefinition2 in allBosses)
				{
					if ((Object)(object)ResolveEnemyPrefab(grid, bossDefinition2.EnemyType) != (Object)null)
					{
						list.Add(bossDefinition2);
					}
				}
			}
			return list;
		}

		public static BossDefinition PickBossForWave(EndlessGrid grid)
		{
			List<BossDefinition> availablePool = GetAvailablePool(grid);
			if (availablePool.Count == 0)
			{
				return null;
			}
			if (ModConfig.ChronologicalOrder)
			{
				BossDefinition result = availablePool[_chronologicalIndex % availablePool.Count];
				_chronologicalIndex++;
				return result;
			}
			if (availablePool.Count == 1)
			{
				_lastRandomIndex = 0;
				return availablePool[0];
			}
			int num = Random.Range(0, availablePool.Count);
			if (num == _lastRandomIndex)
			{
				num = (num + Random.Range(1, availablePool.Count)) % availablePool.Count;
			}
			_lastRandomIndex = num;
			return availablePool[num];
		}

		public static GameObject ResolveEnemyPrefab(EndlessGrid grid, EnemyType type)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			DefaultReferenceManager instance = MonoSingleton<DefaultReferenceManager>.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				GameObject val = TryGetFromDefaultReferenceManager(instance, type);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			if ((Object)(object)grid != (Object)null)
			{
				PrefabDatabase val2 = PrefabDbRef.Invoke(grid);
				if ((Object)(object)val2 != (Object)null)
				{
					GameObject val3 = FindInPrefabDatabase(val2, type);
					if ((Object)(object)val3 != (Object)null)
					{
						return val3;
					}
				}
			}
			EnsureSpawnableCache();
			if (_spawnableCache != null && _spawnableCache.TryGetValue(type, out var value))
			{
				return value;
			}
			return null;
		}

		private static GameObject TryGetFromDefaultReferenceManager(DefaultReferenceManager drm, EnemyType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if ((int)type == 42 || (int)type == 41 || (int)type == 40)
			{
				return null;
			}
			return drm.GetEnemyPrefab(type);
		}

		private static GameObject FindInPrefabDatabase(PrefabDatabase pdb, EnemyType type)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			EndlessEnemy[][] array = new EndlessEnemy[4][] { pdb.specialEnemies, pdb.uncommonEnemies, pdb.meleeEnemies, pdb.projectileEnemies };
			foreach (EndlessEnemy[] array2 in array)
			{
				if (array2 == null)
				{
					continue;
				}
				EndlessEnemy[] array3 = array2;
				foreach (EndlessEnemy val in array3)
				{
					if ((Object)(object)val != (Object)null && val.enemyType == type && (Object)(object)val.prefab != (Object)null)
					{
						return val.prefab;
					}
				}
			}
			return null;
		}

		private static void EnsureSpawnableCache()
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			if (_spawnableCache != null)
			{
				return;
			}
			_spawnableCache = new Dictionary<EnemyType, GameObject>();
			SpawnableObjectsDatabase val = null;
			if ((Object)(object)MonoSingleton<CanvasController>.Instance != (Object)null)
			{
				SpawnMenu componentInChildren = ((Component)MonoSingleton<CanvasController>.Instance).GetComponentInChildren<SpawnMenu>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					object? obj = AccessTools.Field(typeof(SpawnMenu), "objects")?.GetValue(componentInChildren);
					val = (SpawnableObjectsDatabase)((obj is SpawnableObjectsDatabase) ? obj : null);
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				SpawnableObjectsDatabase[] array = Resources.FindObjectsOfTypeAll<SpawnableObjectsDatabase>();
				if (array != null && array.Length != 0)
				{
					val = array[0];
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				try
				{
					val = Addressables.LoadAssetAsync<SpawnableObjectsDatabase>((object)"SpawnableObjectsDatabase").WaitForCompletion();
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Could not load SpawnableObjectsDatabase via Addressables: " + ex.Message));
				}
			}
			if ((Object)(object)val == (Object)null || val.enemies == null)
			{
				return;
			}
			SpawnableObject[] enemies = val.enemies;
			foreach (SpawnableObject val2 in enemies)
			{
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2.gameObject != (Object)null && !_spawnableCache.ContainsKey(val2.enemyType))
				{
					_spawnableCache[val2.enemyType] = val2.gameObject;
				}
			}
		}
	}
	internal sealed class BossWaveMarker : MonoBehaviour
	{
		public string BossDisplayName;
	}
	internal sealed class BossWaveTracker : MonoBehaviour
	{
		private EndlessGrid _grid;

		private ActivateNextWave _anw;

		private EnemyIdentifier _eid;

		private Enemy _enemy;

		private BossHealthBar _bhb;

		private string _bossDisplayName;

		private int _waveNumber;

		private bool _deadObserved;

		private float _deadTimer;

		private bool _barDismissed;

		private bool _fallbackCounted;

		private bool _countedNormally;

		private readonly List<GameObject> _extraCleanupObjects = new List<GameObject>();

		public void Initialize(EndlessGrid grid, ActivateNextWave anw, string bossDisplayName, int waveNumber)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			_grid = grid;
			_anw = anw;
			_bossDisplayName = bossDisplayName;
			_waveNumber = waveNumber;
			_eid = ((Component)this).GetComponent<EnemyIdentifier>() ?? ((Component)this).GetComponentInChildren<EnemyIdentifier>(true);
			_enemy = ((Component)this).GetComponent<Enemy>() ?? ((Component)this).GetComponentInChildren<Enemy>(true);
			if ((Object)(object)_eid != (Object)null)
			{
				_eid.onDeath.AddListener(new UnityAction(OnEnemyIdentifierDeath));
			}
		}

		public void AddExtraCleanup(GameObject obj)
		{
			if ((Object)(object)obj != (Object)null)
			{
				_extraCleanupObjects.Add(obj);
			}
		}

		private void OnEnemyIdentifierDeath()
		{
			if ((Object)(object)_enemy != (Object)null && !_eid.dontCountAsKills)
			{
				_countedNormally = true;
			}
		}

		private void Start()
		{
			_bhb = ((Component)this).GetComponent<BossHealthBar>();
			if (ModConfig.ShowBossBar)
			{
				if ((Object)(object)_bhb == (Object)null)
				{
					_bhb = ((Component)this).gameObject.AddComponent<BossHealthBar>();
				}
				if ((Object)(object)_bhb != (Object)null && !string.IsNullOrEmpty(_bossDisplayName))
				{
					_bhb.bossName = _bossDisplayName;
				}
			}
			else if ((Object)(object)_bhb != (Object)null)
			{
				_bhb.DisappearBar();
				((Behaviour)_bhb).enabled = false;
			}
		}

		private void Update()
		{
			if ((Object)(object)_grid == (Object)null || (Object)(object)_anw == (Object)null || _grid.currentWave != _waveNumber)
			{
				return;
			}
			if ((Object)(object)_eid == (Object)null)
			{
				EnsureWaveCompletion();
			}
			else
			{
				if (!_eid.dead)
				{
					return;
				}
				if (!_deadObserved)
				{
					_deadObserved = true;
					_deadTimer = 0f;
					DismissBossBar();
				}
				if (!_countedNormally)
				{
					_deadTimer += Time.deltaTime;
					float num = (((Object)(object)_enemy != (Object)null && _enemy.isMassDeath) ? 6f : 1.5f);
					if (_deadTimer >= num)
					{
						EnsureWaveCompletion();
					}
				}
			}
		}

		private void OnDisable()
		{
			DismissBossBar();
		}

		private void OnDestroy()
		{
			DismissBossBar();
			foreach (GameObject extraCleanupObject in _extraCleanupObjects)
			{
				if ((Object)(object)extraCleanupObject != (Object)null)
				{
					Object.Destroy((Object)(object)extraCleanupObject);
				}
			}
			if ((Object)(object)_grid != (Object)null && (Object)(object)_anw != (Object)null && _grid.currentWave == _waveNumber && !_countedNormally)
			{
				EnsureWaveCompletion();
			}
		}

		private void DismissBossBar()
		{
			if (_barDismissed)
			{
				return;
			}
			_barDismissed = true;
			if (!((Object)(object)_bhb != (Object)null))
			{
				return;
			}
			try
			{
				_bhb.DisappearBar();
			}
			catch (Exception)
			{
			}
		}

		private void EnsureWaveCompletion()
		{
			if (!_fallbackCounted && !((Object)(object)_anw == (Object)null) && !((Object)(object)_grid == (Object)null) && _grid.currentWave == _waveNumber && _anw.deadEnemies < _grid.enemyAmount)
			{
				_fallbackCounted = true;
				Plugin.Log.LogInfo((object)$"BossWaveTracker fallback completing wave {_waveNumber} for {_bossDisplayName}.");
				_anw.AddDeadEnemy();
			}
		}
	}
	internal static class ModConfig
	{
		private static class PluginConfiguratorBridge
		{
			public static void Setup()
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Expected O, but got Unknown
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Expected O, but got Unknown
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Expected O, but got Unknown
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: Expected O, but got Unknown
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Expected O, but got Unknown
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: Expected O, but got Unknown
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Expected O, but got Unknown
				//IL_010e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0118: Expected O, but got Unknown
				//IL_01af: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b5: Expected O, but got Unknown
				//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0205: Expected O, but got Unknown
				PluginConfigurator val = PluginConfigurator.Create("Cyber Grind Boss Waves", "com.yousef.ultrakill.cybergrindbosswaves");
				new ConfigHeader(val.rootPanel, "Cyber Grind Boss Waves", 20);
				BoolField modEnabled = new BoolField(val.rootPanel, "Enable Boss Waves", "mod_enabled", true);
				BoolField chronologicalOrder = new BoolField(val.rootPanel, "Chronological Order (Campaign Level Order)", "chronological_order", false);
				IntField waveInterval = new IntField(val.rootPanel, "Boss Wave Interval", "boss_wave_interval", 5, 1, 100, true);
				IntField firstBossWave = new IntField(val.rootPanel, "First Boss Wave", "first_boss_wave", 5, 1, 100, true);
				BoolField showBossBar = new BoolField(val.rootPanel, "Show Boss Health Bar", "show_boss_bar", true);
				BoolField allBossesJackpot = new BoolField(val.rootPanel, "0.001% All-Bosses-At-Once Jackpot", "all_bosses_jackpot", true);
				BoolField allowRadiant = new BoolField(val.rootPanel, "Allow Radiant Bosses", "allow_radiant", false);
				IntField radiantWave = new IntField(val.rootPanel, "Radiant Boss Start Wave", "radiant_start_wave", 50, 1, 500, true);
				_modEnabledGetter = () => modEnabled.value;
				_chronologicalOrderGetter = () => chronologicalOrder.value;
				_waveIntervalGetter = () => waveInterval.value;
				_firstBossWaveGetter = () => firstBossWave.value;
				_showBossBarGetter = () => showBossBar.value;
				_enableAllBossesJackpotGetter = () => allBossesJackpot.value;
				_allowRadiantBossesGetter = () => allowRadiant.value;
				_radiantStartWaveGetter = () => radiantWave.value;
				ConfigPanel val2 = new ConfigPanel(val.rootPanel, "Boss Pool", "boss_pool_panel");
				new ConfigHeader(val2, "Enabled Bosses (Chronological Order)", 18);
				BossDefinition[] allBosses = BossRoster.AllBosses;
				foreach (BossDefinition bossDefinition in allBosses)
				{
					BoolField field = new BoolField(val2, bossDefinition.ConfigLabel, "boss_" + bossDefinition.Id, bossDefinition.DefaultEnabled);
					_bossEnabledGetters[bossDefinition.Id] = () => field.value;
				}
			}
		}

		private static readonly Dictionary<string, Func<bool>> _bossEnabledGetters = new Dictionary<string, Func<bool>>();

		private static Func<bool> _modEnabledGetter = () => true;

		private static Func<bool> _chronologicalOrderGetter = () => false;

		private static Func<int> _waveIntervalGetter = () => 5;

		private static Func<int> _firstBossWaveGetter = () => 5;

		private static Func<bool> _showBossBarGetter = () => true;

		private static Func<bool> _enableAllBossesJackpotGetter = () => true;

		private static Func<bool> _allowRadiantBossesGetter = () => false;

		private static Func<int> _radiantStartWaveGetter = () => 50;

		public static bool ModEnabled => _modEnabledGetter();

		public static bool ChronologicalOrder => _chronologicalOrderGetter();

		public static int WaveInterval => Math.Max(1, _waveIntervalGetter());

		public static int FirstBossWave => Math.Max(1, _firstBossWaveGetter());

		public static bool ShowBossBar => _showBossBarGetter();

		public static bool EnableAllBossesJackpot => _enableAllBossesJackpotGetter();

		public static bool AllowRadiantBosses => _allowRadiantBossesGetter();

		public static int RadiantStartWave => Math.Max(1, _radiantStartWaveGetter());

		public static bool IsBossEnabled(BossDefinition boss)
		{
			if (!_bossEnabledGetters.TryGetValue(boss.Id, out var value))
			{
				return boss.DefaultEnabled;
			}
			return value();
		}

		public static void Initialize(ConfigFile bepInExConfig, bool usePluginConfigurator)
		{
			if (usePluginConfigurator)
			{
				PluginConfiguratorBridge.Setup();
				return;
			}
			ConfigEntry<bool> modEnabled = bepInExConfig.Bind<bool>("General", "Enabled", true, "Enable Cyber Grind boss waves.");
			ConfigEntry<bool> chronologicalOrder = bepInExConfig.Bind<bool>("General", "ChronologicalOrder", false, "Spawn bosses in campaign level order (Maurice -> Swordsmachine -> Cerberus -> ...).");
			ConfigEntry<int> waveInterval = bepInExConfig.Bind<int>("General", "BossWaveInterval", 5, "Spawn a boss wave every N waves (e.g. 5 = waves 5, 10, 15...).");
			ConfigEntry<int> firstBossWave = bepInExConfig.Bind<int>("General", "FirstBossWave", 5, "First wave number that can be a boss wave.");
			ConfigEntry<bool> showBossBar = bepInExConfig.Bind<bool>("General", "ShowBossHealthBar", true, "Display a boss health bar during boss waves.");
			ConfigEntry<bool> allBossesJackpot = bepInExConfig.Bind<bool>("General", "AllBossesJackpot", true, "0.001% chance on a boss wave to spawn all enabled bosses at once.");
			ConfigEntry<bool> allowRadiant = bepInExConfig.Bind<bool>("General", "AllowRadiantBosses", false, "Allow bosses to become Radiant on high waves.");
			ConfigEntry<int> radiantWave = bepInExConfig.Bind<int>("General", "RadiantStartWave", 50, "Wave at which bosses can become Radiant (if enabled).");
			_modEnabledGetter = () => modEnabled.Value;
			_chronologicalOrderGetter = () => chronologicalOrder.Value;
			_waveIntervalGetter = () => waveInterval.Value;
			_firstBossWaveGetter = () => firstBossWave.Value;
			_showBossBarGetter = () => showBossBar.Value;
			_enableAllBossesJackpotGetter = () => allBossesJackpot.Value;
			_allowRadiantBossesGetter = () => allowRadiant.Value;
			_radiantStartWaveGetter = () => radiantWave.Value;
			BossDefinition[] allBosses = BossRoster.AllBosses;
			foreach (BossDefinition bossDefinition in allBosses)
			{
				ConfigEntry<bool> entry = bepInExConfig.Bind<bool>("BossPool", bossDefinition.Id, bossDefinition.DefaultEnabled, "Allow " + bossDefinition.ConfigLabel + " in Cyber Grind boss waves.");
				_bossEnabledGetters[bossDefinition.Id] = () => entry.Value;
			}
		}
	}
	[HarmonyPatch]
	internal static class Patches
	{
		private static readonly FieldRef<EndlessGrid, int> CurrentPatternNumRef = AccessTools.FieldRefAccess<EndlessGrid, int>("currentPatternNum");

		private static readonly FieldRef<EndlessGrid, float> OffsetRef = AccessTools.FieldRefAccess<EndlessGrid, float>("offset");

		private static readonly FieldRef<EndlessGrid, CyberGrindNavHelper> NavHelperRef = AccessTools.FieldRefAccess<EndlessGrid, CyberGrindNavHelper>("nvmhlpr");

		private static readonly FieldRef<EndlessGrid, List<GameObject>> SpawnedEnemiesRef = AccessTools.FieldRefAccess<EndlessGrid, List<GameObject>>("spawnedEnemies");

		private static readonly FieldRef<EndlessGrid, List<EnemyTypeTracker>> SpawnedEnemyTypesRef = AccessTools.FieldRefAccess<EndlessGrid, List<EnemyTypeTracker>>("spawnedEnemyTypes");

		private static readonly FieldRef<EndlessGrid, int> UsedMeleePositionsRef = AccessTools.FieldRefAccess<EndlessGrid, int>("usedMeleePositions");

		private static readonly FieldRef<EndlessGrid, int> UsedProjectilePositionsRef = AccessTools.FieldRefAccess<EndlessGrid, int>("usedProjectilePositions");

		private static readonly FieldRef<EndlessGrid, int> TotalDeathcatchersRef = AccessTools.FieldRefAccess<EndlessGrid, int>("totalDeathcatchers");

		private static readonly FieldRef<EndlessGrid, int> HideousMassesRef = AccessTools.FieldRefAccess<EndlessGrid, int>("hideousMasses");

		private static readonly FieldInfo V2BossVersionField = AccessTools.Field(typeof(V2), "bossVersion");

		private static readonly FieldInfo MinosPrimeBossVersionField = AccessTools.Field(typeof(MinosPrime), "bossVersion");

		private static readonly FieldInfo SisyphusPrimeBossVersionField = AccessTools.Field(typeof(SisyphusPrime), "bossVersion");

		private static readonly FieldInfo GabrielBossVersionField = AccessTools.Field(typeof(GabrielBase), "bossVersion");

		private static readonly FieldInfo SwordsmachineBossVersionField = AccessTools.Field(typeof(SwordsMachine), "bossVersion");

		private static readonly FieldInfo GeryonRotateAroundField = AccessTools.Field(typeof(Geryon), "rotateAround");

		private static readonly FieldInfo PowerPhysicsArmField = AccessTools.Field(typeof(Power), "physicsArm");

		private static readonly MethodInfo LoadPatternMethod = AccessTools.Method(typeof(EndlessGrid), "LoadPattern", (Type[])null, (Type[])null);

		private static readonly Vector2[] AllBossArenaSpawnPoints = (Vector2[])(object)new Vector2[25]
		{
			new Vector2(7.5f, 7.5f),
			new Vector2(5f, 5f),
			new Vector2(10f, 5f),
			new Vector2(5f, 10f),
			new Vector2(10f, 10f),
			new Vector2(7.5f, 4f),
			new Vector2(7.5f, 11f),
			new Vector2(4f, 7.5f),
			new Vector2(11f, 7.5f),
			new Vector2(6f, 2f),
			new Vector2(9f, 2f),
			new Vector2(6f, 13f),
			new Vector2(9f, 13f),
			new Vector2(2f, 6f),
			new Vector2(2f, 9f),
			new Vector2(13f, 6f),
			new Vector2(13f, 9f),
			new Vector2(6f, 6f),
			new Vector2(9f, 6f),
			new Vector2(6f, 9f),
			new Vector2(9f, 9f),
			new Vector2(7.5f, 1.5f),
			new Vector2(7.5f, 13.5f),
			new Vector2(1.5f, 7.5f),
			new Vector2(13.5f, 7.5f)
		};

		private static bool _usingDummyPowerVoiceController;

		internal static bool IsCurrentWaveBoss { get; private set; }

		internal static bool AnyBossWaveTriggeredThisRun { get; private set; }

		public static bool IsBossWave(int wave)
		{
			if (!ModConfig.ModEnabled || wave < ModConfig.FirstBossWave)
			{
				return false;
			}
			return (wave - ModConfig.FirstBossWave) % ModConfig.WaveInterval == 0;
		}

		[HarmonyPatch(typeof(EndlessGrid), "Start")]
		[HarmonyPrefix]
		private static void EndlessGrid_Start_Prefix()
		{
			IsCurrentWaveBoss = false;
			AnyBossWaveTriggeredThisRun = false;
			_usingDummyPowerVoiceController = false;
			BossRoster.ResetProgression();
		}

		[HarmonyPatch(typeof(EndlessGrid), "NextWave")]
		[HarmonyPrefix]
		private static void EndlessGrid_NextWave_Prefix(EndlessGrid __instance)
		{
			IsCurrentWaveBoss = IsBossWave(__instance.currentWave + 1);
			if (IsCurrentWaveBoss)
			{
				AnyBossWaveTriggeredThisRun = true;
			}
		}

		[HarmonyPatch(typeof(EndlessGrid), "NextWave")]
		[HarmonyPostfix]
		private static void EndlessGrid_NextWave_Postfix(EndlessGrid __instance)
		{
			if (!IsCurrentWaveBoss)
			{
				return;
			}
			CurrentPatternNumRef.Invoke(__instance)--;
			ArenaPattern bossArenaPattern = BossArenaLoader.GetBossArenaPattern();
			if (!((Object)(object)bossArenaPattern == (Object)null))
			{
				((MonoBehaviour)__instance).CancelInvoke("DisplayNoPatternWarning");
				if (__instance.customPatternMode && (__instance.customPatterns == null || __instance.customPatterns.Length == 0))
				{
					LoadPatternMethod.Invoke(__instance, new object[1] { bossArenaPattern });
				}
			}
		}

		[HarmonyPatch(typeof(EndlessGrid), "LoadPattern")]
		[HarmonyPrefix]
		private static void EndlessGrid_LoadPattern_Prefix(ref ArenaPattern pattern)
		{
			if (IsCurrentWaveBoss)
			{
				ArenaPattern bossArenaPattern = BossArenaLoader.GetBossArenaPattern();
				if ((Object)(object)bossArenaPattern != (Object)null)
				{
					pattern = bossArenaPattern;
				}
			}
		}

		[HarmonyPatch(typeof(EndlessGrid), "GetEnemies")]
		[HarmonyPrefix]
		private static bool EndlessGrid_GetEnemies_Prefix(EndlessGrid __instance)
		{
			//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_0147: Unknown result type (might be due to invalid IL or missing references)
			if (!IsCurrentWaveBoss)
			{
				return true;
			}
			__instance.nms.BuildNavMesh();
			CyberGrindNavHelper obj = NavHelperRef.Invoke(__instance);
			if (obj != null)
			{
				obj.GenerateLinks(__instance.cubes);
			}
			__instance.tempEnemyAmount = 0;
			UsedMeleePositionsRef.Invoke(__instance) = 0;
			UsedProjectilePositionsRef.Invoke(__instance) = 0;
			TotalDeathcatchersRef.Invoke(__instance) = 0;
			HideousMassesRef.Invoke(__instance) = 0;
			SpawnedEnemyTypesRef.Invoke(__instance).Clear();
			__instance.deathcatchers.Clear();
			__instance.spawnPartway.Clear();
			__instance.endlessEvents.Clear();
			if (BossRoster.RollAllBossesJackpot())
			{
				int num = SpawnAllBosses(__instance);
				if (num > 0)
				{
					__instance.tempEnemyAmount = num;
					__instance.enemyAmount = num;
					Plugin.Log.LogWarning((object)$"0.001% ALL-BOSSES JACKPOT triggered on wave {__instance.currentWave}! Spawned {num} bosses.");
					if ((Object)(object)MonoSingleton<HudMessageReceiver>.Instance != (Object)null)
					{
						MonoSingleton<HudMessageReceiver>.Instance.SendHudMessage("JACKPOT (0.001%): ALL BOSSES AT ONCE!!", "", "", 0, true, false, true);
					}
					return false;
				}
			}
			BossDefinition bossDefinition = BossRoster.PickBossForWave(__instance);
			if (bossDefinition == null)
			{
				Plugin.Log.LogWarning((object)"No valid boss prefab found; falling back to standard Cyber Grind wave.");
				return true;
			}
			float offset = OffsetRef.Invoke(__instance);
			Vector2 gridPos = PickSingleSpawnGridCoord(__instance, offset, bossDefinition.IsFloating);
			if (!SpawnBoss(__instance, bossDefinition, gridPos))
			{
				Plugin.Log.LogWarning((object)("Failed to spawn boss '" + bossDefinition.DisplayName + "'; falling back to standard Cyber Grind wave."));
				return true;
			}
			__instance.tempEnemyAmount = 1;
			__instance.enemyAmount = 1;
			if ((Object)(object)MonoSingleton<HudMessageReceiver>.Instance != (Object)null)
			{
				MonoSingleton<HudMessageReceiver>.Instance.SendHudMessage("BOSS WAVE: " + bossDefinition.DisplayName.ToUpperInvariant(), "", "", 0, true, false, true);
			}
			return false;
		}

		private static int SpawnAllBosses(EndlessGrid grid)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			List<BossDefinition> availablePool = BossRoster.GetAvailablePool(grid);
			int num = 0;
			for (int i = 0; i < availablePool.Count; i++)
			{
				Vector2 gridPos = AllBossArenaSpawnPoints[i % AllBossArenaSpawnPoints.Length];
				if (SpawnBoss(grid, availablePool[i], gridPos))
				{
					num++;
				}
			}
			return num;
		}

		private static bool SpawnBoss(EndlessGrid grid, BossDefinition boss, Vector2 gridPos)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Invalid comparison between Unknown and I4
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = BossRoster.ResolveEnemyPrefab(grid, boss.EnemyType);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			float num = OffsetRef.Invoke(grid);
			RaycastHit val3 = default(RaycastHit);
			Vector3 val2 = ((!Physics.Raycast(((Component)grid).transform.position + new Vector3(gridPos.x * num, 200f, gridPos.y * num), Vector3.down, ref val3, float.PositiveInfinity, 16777216)) ? (((Component)grid).transform.position + new Vector3(gridPos.x * num, boss.SpawnHeightOffset, gridPos.y * num)) : (((RaycastHit)(ref val3)).point + Vector3.up * (val.transform.position.y + boss.SpawnHeightOffset)));
			Quaternion val4 = val.transform.rotation;
			if ((Object)(object)MonoSingleton<NewMovement>.Instance != (Object)null)
			{
				Vector3 val5 = ((Component)MonoSingleton<NewMovement>.Instance).transform.position - val2;
				val5.y = 0f;
				if (((Vector3)(ref val5)).sqrMagnitude > 0.01f)
				{
					val4 = Quaternion.LookRotation(((Vector3)(ref val5)).normalized);
				}
			}
			if ((int)boss.EnemyType == 40)
			{
				EnsurePowerVoiceController();
			}
			GameObject val6 = Object.Instantiate<GameObject>(val, val2, val4, ((Component)grid).transform);
			if ((Object)(object)val6 == (Object)null)
			{
				return false;
			}
			ConfigureSpawnedBoss(grid, val6, boss, num);
			SpawnedEnemiesRef.Invoke(grid).Add(val6);
			return true;
		}

		private static Vector2 PickSingleSpawnGridCoord(EndlessGrid grid, float offset, bool centerOnly)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			if (centerOnly || (Object)(object)MonoSingleton<NewMovement>.Instance == (Object)null)
			{
				return new Vector2(7.5f, 7.5f);
			}
			Vector3 position = ((Component)MonoSingleton<NewMovement>.Instance).transform.position;
			Vector2[] obj = new Vector2[4]
			{
				new Vector2(7f, 7f),
				new Vector2(7f, 8f),
				new Vector2(8f, 7f),
				new Vector2(8f, 8f)
			};
			Vector2 result = obj[0];
			float num = -1f;
			Vector2[] array = (Vector2[])(object)obj;
			foreach (Vector2 val in array)
			{
				Vector3 val2 = ((Component)grid).transform.position + new Vector3(val.x * offset, 0f, val.y * offset);
				float num2 = val2.x - position.x;
				float num3 = val2.z - position.z;
				float num4 = num2 * num2 + num3 * num3;
				if (num4 > num)
				{
					num = num4;
					result = val;
				}
			}
			return result;
		}

		private static void ConfigureSpawnedBoss(EndlessGrid grid, GameObject bossObj, BossDefinition boss, float offset)
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			bossObj.AddComponent<BossWaveMarker>().BossDisplayName = boss.DisplayName;
			V2 val = default(V2);
			if (bossObj.TryGetComponent<V2>(ref val))
			{
				val.intro = false;
				val.longIntro = false;
				val.dontDie = false;
				val.escapeTarget = null;
				V2BossVersionField?.SetValue(val, false);
			}
			if (ModConfig.AllowRadiantBosses && grid.currentWave >= ModConfig.RadiantStartWave)
			{
				EnemyIdentifier componentInChildren = bossObj.GetComponentInChildren<EnemyIdentifier>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					componentInChildren.HealthBuff();
					componentInChildren.SpeedBuff();
				}
			}
			ActivateNextWave component = ((Component)grid).GetComponent<ActivateNextWave>();
			BossWaveTracker bossWaveTracker = bossObj.AddComponent<BossWaveTracker>();
			bossWaveTracker.Initialize(grid, component, boss.DisplayName, grid.currentWave);
			Geryon obj = default(Geryon);
			if (bossObj.TryGetComponent<Geryon>(ref obj) && GeryonRotateAroundField != null && (Object)/*isinst with value type is only supported in some contexts*/ == (Object)null)
			{
				GameObject val2 = new GameObject("GeryonCyberGrindAnchor");
				val2.transform.SetParent(((Component)grid).transform, true);
				val2.transform.position = ((Component)grid).transform.position + new Vector3(7.5f * offset, 12f, 7.5f * offset);
				GeryonRotateAroundField.SetValue(obj, val2.transform);
				bossWaveTracker.AddExtraCleanup(val2);
			}
			Power obj2 = default(Power);
			if (bossObj.TryGetComponent<Power>(ref obj2) && PowerPhysicsArmField != null)
			{
				object? value = PowerPhysicsArmField.GetValue(obj2);
				Transform val3 = (Transform)((value is Transform) ? value : null);
				if (val3 != null && (Object)(object)val3 != (Object)null)
				{
					bossWaveTracker.AddExtraCleanup(((Component)val3).gameObject);
				}
			}
		}

		private static void EnsurePowerVoiceController()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)MonoSingleton<PowerVoiceController>.Instance != (Object)null)
			{
				return;
			}
			PowerVoiceController[] array = Resources.FindObjectsOfTypeAll<PowerVoiceController>();
			if (array != null && array.Length != 0)
			{
				Scene scene = ((Component)array[0]).gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					return;
				}
			}
			PowerVoiceController obj = new GameObject("CyberGrindPowerVoiceFallback").AddComponent<PowerVoiceController>();
			FieldInfo[] fields = typeof(PowerVoiceController).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.FieldType == typeof(AudioClip[]))
				{
					fieldInfo.SetValue(obj, Array.Empty<AudioClip>());
				}
			}
			_usingDummyPowerVoiceController = true;
		}

		[HarmonyPatch(typeof(Power), "CanPlaySound")]
		[HarmonyPrefix]
		private static bool Power_CanPlaySound_Prefix(ref bool __result)
		{
			if (_usingDummyPowerVoiceController || (Object)(object)MonoSingleton<PowerVoiceController>.Instance == (Object)null)
			{
				__result = false;
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(MinosPrime), "Start")]
		[HarmonyPostfix]
		private static void MinosPrime_Start_Postfix(MinosPrime __instance)
		{
			BossWaveMarker bossWaveMarker = default(BossWaveMarker);
			if (((Component)__instance).TryGetComponent<BossWaveMarker>(ref bossWaveMarker))
			{
				MinosPrimeBossVersionField?.SetValue(__instance, false);
			}
		}

		[HarmonyPatch(typeof(SisyphusPrime), "Start")]
		[HarmonyPostfix]
		private static void SisyphusPrime_Start_Postfix(SisyphusPrime __instance)
		{
			BossWaveMarker bossWaveMarker = default(BossWaveMarker);
			if (((Component)__instance).TryGetComponent<BossWaveMarker>(ref bossWaveMarker))
			{
				SisyphusPrimeBossVersionField?.SetValue(__instance, false);
			}
		}

		[HarmonyPatch(typeof(GabrielBase), "SetValues")]
		[HarmonyPostfix]
		private static void GabrielBase_SetValues_Postfix(GabrielBase __instance)
		{
			BossWaveMarker bossWaveMarker = default(BossWaveMarker);
			if (((Component)__instance).TryGetComponent<BossWaveMarker>(ref bossWaveMarker))
			{
				GabrielBossVersionField?.SetValue(__instance, false);
			}
		}

		[HarmonyPatch(typeof(SwordsMachine), "Start")]
		[HarmonyPostfix]
		private static void SwordsMachine_Start_Postfix(SwordsMachine __instance)
		{
			BossWaveMarker bossWaveMarker = default(BossWaveMarker);
			if (((Component)__instance).TryGetComponent<BossWaveMarker>(ref bossWaveMarker))
			{
				__instance.firstPhase = false;
				SwordsmachineBossVersionField?.SetValue(__instance, false);
			}
		}

		[HarmonyPatch(typeof(MusicManager), "PlayBossMusic")]
		[HarmonyPrefix]
		private static bool MusicManager_PlayBossMusic_Prefix()
		{
			if (IsCurrentWaveBoss && (Object)(object)MonoSingleton<EndlessGrid>.Instance != (Object)null)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(LeaderboardController), "SubmitCyberGrindScore")]
		[HarmonyPrefix]
		private static bool LeaderboardController_SubmitCyberGrindScore_Prefix()
		{
			if (AnyBossWaveTriggeredThisRun)
			{
				Plugin.Log.LogInfo((object)"Blocked Cyber Grind Steam leaderboard submission because boss waves were active this run.");
				return false;
			}
			return true;
		}
	}
	[BepInPlugin("com.yousef.ultrakill.cybergrindbosswaves", "CyberGrindBossWaves", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.yousef.ultrakill.cybergrindbosswaves";

		public const string PluginName = "CyberGrindBossWaves";

		public const string PluginVersion = "1.0.0";

		private const string PluginConfiguratorGuid = "com.eternalUnion.pluginConfigurator";

		private Harmony _harmony;

		internal static ManualLogSource Log { get; private set; }

		internal static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			bool usePluginConfigurator = Chainloader.PluginInfos.ContainsKey("com.eternalUnion.pluginConfigurator") || Chainloader.PluginInfos.ContainsKey("PluginConfigurator");
			ModConfig.Initialize(((BaseUnityPlugin)this).Config, usePluginConfigurator);
			BossArenaLoader.Initialize();
			_harmony = new Harmony("com.yousef.ultrakill.cybergrindbosswaves");
			_harmony.PatchAll();
			Log.LogInfo((object)"CyberGrindBossWaves v1.0.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}