Decompiled source of RemoveTheAnnoying v1.0.1

RemoveTheAnnoying.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using RemoveTheAnnoying.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RemoveTheAnnoying")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RemoveTheAnnoying")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5445ad29-c98f-47fc-82e3-f3aeb564b4a7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RemoveTheAnnoying
{
	[BepInPlugin("Kyoshi.RemoveAnnoyingStuff", "Remove Annoying Mechanics", "1.0.1")]
	public class RemoveAnnoyingBase : BaseUnityPlugin
	{
		private const string modGUID = "Kyoshi.RemoveAnnoyingStuff";

		private const string modName = "Remove Annoying Mechanics";

		private const string modVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("Kyoshi.RemoveAnnoyingStuff");

		public static RemoveAnnoyingBase Instance;

		public static ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Kyoshi.RemoveAnnoyingStuff");
			mls.LogInfo((object)"Patching some QoL files!");
			harmony.PatchAll(typeof(RemoveAnnoyingBase));
			harmony.PatchAll(typeof(ChooseNewRandomMapSeedPatch));
			harmony.PatchAll(typeof(DisableBadEnemySpawningPatch));
			mls.LogInfo((object)"The game is now more playable!");
		}
	}
	public enum InteriorType
	{
		Factory = 0,
		Manor = 1,
		Mineshaft = 4
	}
}
namespace RemoveTheAnnoying.Patches
{
	[HarmonyPatch(typeof(StartOfRound), "ChooseNewRandomMapSeed")]
	public class ChooseNewRandomMapSeedPatch
	{
		[HarmonyPatch(typeof(RoundManager), "GenerateNewFloor")]
		public class GenerateNewFloorPatch
		{
			private static bool Prefix(RoundManager __instance)
			{
				__instance.currentLevel.dungeonFlowTypes = __instance.currentLevel.dungeonFlowTypes.Where((IntWithRarity dungeonFlowType) => dungeonFlowType.id != 4).ToArray();
				Logger.LogInfo((object)("Removed mineshaft generation of " + ((object)__instance.currentLevel)?.ToString() + "."));
				return true;
			}
		}

		private static readonly ManualLogSource Logger = RemoveAnnoyingBase.mls;

		private static void Postfix(StartOfRound __instance)
		{
			int randomMapSeed = __instance.randomMapSeed;
			RoundManager instance = RoundManager.Instance;
			InteriorType? interiorType = DetermineType(randomMapSeed, instance);
			if (((Object)instance.currentLevel).name.Equals("Gordion") || instance.currentLevel.PlanetName.Equals("Gordion") || __instance.currentLevel.PlanetName.Equals("Gordion") || ((Object)__instance.currentLevel).name.Equals("Gordion"))
			{
				Logger.LogInfo((object)"The Company Building Detected.");
			}
			else
			{
				if (!interiorType.HasValue)
				{
					return;
				}
				interiorType = interiorType.Value;
				Logger.LogInfo((object)$"Seed: {randomMapSeed} is a {interiorType}.");
				if (interiorType.GetValueOrDefault() != InteriorType.Mineshaft)
				{
					Logger.LogInfo((object)"No need to regenerate seed.");
					return;
				}
				Logger.LogInfo((object)"Mineshaft seed identified, trying to regenerate...");
				instance.hasInitializedLevelRandomSeed = false;
				instance.InitializeRandomNumberGenerators();
				for (int i = 0; i < 1000; i++)
				{
					randomMapSeed = NewSeed();
					interiorType = DetermineType(randomMapSeed, instance);
					Logger.LogDebug((object)$"Attempt {i + 1} - Seed: {randomMapSeed} Interior: {interiorType}");
					if (!interiorType.HasValue)
					{
						Logger.LogWarning((object)"Detected unknown interior.");
						return;
					}
					if (new InteriorType?(interiorType.Value).GetValueOrDefault() != InteriorType.Mineshaft)
					{
						__instance.randomMapSeed = randomMapSeed;
						Logger.LogInfo((object)$"Generated new map seed: {randomMapSeed} after {i + 1} attempts.");
						return;
					}
				}
				Logger.LogWarning((object)"Regeneration failed after 1000 attempts");
			}
		}

		private static InteriorType? DetermineType(int seed, RoundManager manager)
		{
			if (((Object)manager.currentLevel).name.Equals("Gordion") || manager.currentLevel.PlanetName.Equals("Gordion"))
			{
				Logger.LogInfo((object)"The Company Building Detected.");
				return null;
			}
			if (manager.currentLevel.dungeonFlowTypes == null || manager.currentLevel.dungeonFlowTypes.Length == 0)
			{
				return null;
			}
			Random random = new Random(seed);
			List<int> list = manager.currentLevel.dungeonFlowTypes.Select((IntWithRarity flow) => flow.rarity).ToList();
			Logger.LogDebug((object)("List: " + string.Join(", ", list)));
			int randomWeightedIndex = manager.GetRandomWeightedIndex(list.ToArray(), random);
			Logger.LogDebug((object)$"Weight: {randomWeightedIndex}");
			int id = manager.currentLevel.dungeonFlowTypes[randomWeightedIndex].id;
			if (Enum.IsDefined(typeof(InteriorType), id))
			{
				return (InteriorType)id;
			}
			return null;
		}

		private static int NewSeed()
		{
			return new Random().Next(1, 100000000);
		}
	}
	[HarmonyPatch(typeof(RoundManager), "LoadNewLevel")]
	public class DisableBadEnemySpawningPatch
	{
		private static readonly ManualLogSource Logger = RemoveAnnoyingBase.mls;

		private static void Prefix(SelectableLevel newLevel)
		{
			foreach (SpawnableEnemyWithRarity enemy in newLevel.Enemies)
			{
				if (((Object)enemy.enemyType).name.Equals("ClaySurgeon"))
				{
					DisableEnemy(enemy);
				}
				if (((Object)enemy.enemyType).name.Equals("CaveDweller"))
				{
					DisableEnemy(enemy);
				}
			}
		}

		private static void DisableEnemy(SpawnableEnemyWithRarity enemy)
		{
			enemy.rarity = 0;
			Logger.LogInfo((object)("Spawning of " + ((Object)enemy.enemyType).name + " disabled."));
		}
	}
}