Decompiled source of RebalancedMineshaft v0.1.0

RebalancedMineshaft.dll

Decompiled 5 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using DunGen;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("RebalancedMineshaft")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Rebalances the Mineshaft interior to be more akin to how Factory and Mansion are balanced.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("RebalancedMineshaft")]
[assembly: AssemblyTitle("RebalancedMineshaft")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RebalancedMineshaft
{
	[BepInPlugin("RebalancedMineshaft", "RebalancedMineshaft", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("RebalancedMineshaft");

		public static Plugin Instance;

		private void Awake()
		{
			if (Instance == null)
			{
				Instance = this;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin RebalancedMineshaft is loaded!");
			harmony.PatchAll(typeof(MineshaftPatch));
		}

		public static void Log(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg);
		}

		public static void LogDebug(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogDebug((object)msg);
		}

		public static void LogWarning(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogWarning((object)msg);
		}
	}
	public class MineshaftPatch
	{
		private class Functions
		{
			internal static GameObject CreateItemSpawn(Transform transform, Vector3 localPosition, string spawn, int range, bool copy)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: 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)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Expected O, but got Unknown
				GameObject val = new GameObject
				{
					name = "AddedItemSpawn_" + spawn
				};
				val.transform.SetParent(transform);
				val.transform.localPosition = localPosition;
				RandomScrapSpawn obj = val.AddComponent<RandomScrapSpawn>();
				obj.spawnableItems = GetItemGroupFromString(spawn);
				obj.itemSpawnRange = range;
				obj.spawnedItemsCopyPosition = copy;
				return val;
			}

			internal static GameObject ConvertToRandomSpawn(Transform transform, float mainWeight, float branchWeight)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Expected O, but got Unknown
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Expected O, but got Unknown
				GameObject val = new GameObject();
				((Object)val).name = "AddedRandomSpawn_" + ((Object)transform).name;
				val.transform.SetParent(transform.parent);
				transform.SetParent(val.transform);
				LocalPropSet obj = val.AddComponent<LocalPropSet>();
				GameObjectChance val2 = new GameObjectChance();
				val2.Value = ((Component)transform).gameObject;
				val2.MainPathWeight = mainWeight;
				val2.BranchPathWeight = branchWeight;
				obj.Props.Weights.Add(val2);
				obj.PropCount.Min = 0;
				obj.PropCount.Max = 1;
				return val;
			}

			internal static ItemGroup GetItemGroupFromString(string str)
			{
				ItemGroup[] array = Resources.FindObjectsOfTypeAll<ItemGroup>();
				foreach (ItemGroup val in array)
				{
					if (((Object)val).name == str)
					{
						return val;
					}
				}
				return null;
			}
		}

		[HarmonyPatch(typeof(Dungeon), "PreGenerateDungeon")]
		[HarmonyPostfix]
		private static void PreGenerateDungeonPostfix(Dungeon __instance)
		{
			if (((Object)__instance.DungeonFlow).name == "Level3Flow")
			{
				Plugin.LogDebug(((Object)__instance.DungeonFlow).name + " detected, changing generation size.");
				__instance.DungeonFlow.Length.Min = 11;
				__instance.DungeonFlow.Length.Max = 14;
				__instance.DungeonFlow.Lines[0].Length = 0.35f;
				__instance.DungeonFlow.Lines[1].Position = 0.35f;
				__instance.DungeonFlow.Lines[1].Length = 0.3f;
				__instance.DungeonFlow.Lines[2].Position = 0.65f;
				__instance.DungeonFlow.Lines[2].Length = 0.35f;
				__instance.DungeonFlow.Lines[0].DungeonArchetypes[0].BranchCount.Min = 9;
				__instance.DungeonFlow.Lines[0].DungeonArchetypes[0].BranchCount.Max = 13;
				__instance.DungeonFlow.Lines[1].DungeonArchetypes[0].BranchCount.Min = 4;
				__instance.DungeonFlow.Lines[1].DungeonArchetypes[0].BranchCount.Max = 6;
			}
		}

		[HarmonyPatch(typeof(Dungeon), "PostGenerateDungeon")]
		[HarmonyPostfix]
		private static void PostGenerateDungeonPostfix(Dungeon __instance)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)__instance.DungeonFlow).name != "Level3Flow")
			{
				return;
			}
			foreach (Tile allTile in __instance.AllTiles)
			{
				string name = ((Object)allTile).name;
				if (!(name == "CaveSmallIntersectTile(Clone)"))
				{
					if (name == "CaveCrampedIntersectTile(Clone)")
					{
						Transform obj = ((Component)allTile).transform.Find("GeneralScrapSpawn");
						Transform val = ((obj != null) ? ((Component)obj).transform : null);
						if ((Object)(object)val != (Object)null)
						{
							Plugin.LogDebug("Converting to random spawn at " + val.position.x + ", " + val.position.y + ", " + val.position.z);
							Functions.ConvertToRandomSpawn(val, 0.15f, 0.25f);
						}
					}
				}
				else
				{
					Transform obj2 = ((Component)allTile).transform.Find("GeneralScrapSpawn");
					Transform val = ((obj2 != null) ? ((Component)obj2).transform : null);
					if ((Object)(object)val != (Object)null)
					{
						Plugin.LogDebug("Converting to random spawn at " + val.position.x + ", " + val.position.y + ", " + val.position.z);
						Functions.ConvertToRandomSpawn(val, 0.15f, 0.25f);
					}
				}
			}
		}

		[HarmonyPatch(typeof(DungeonGenerator), "ProcessGlobalProps")]
		[HarmonyPostfix]
		private static void ProcessGlobalPropsPostfix(DungeonGenerator __instance)
		{
			//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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: 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_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			if (((Object)__instance.DungeonFlow).name != "Level3Flow")
			{
				return;
			}
			foreach (Tile allTile in __instance.CurrentDungeon.AllTiles)
			{
				switch (((Object)allTile).name)
				{
				case "TunnelSplit(Clone)":
				{
					Transform obj3 = ((Component)allTile).transform.Find("SouthWallProps/Shelf1 (14)");
					Transform val2 = ((obj3 != null) ? ((Component)obj3).transform : null);
					if ((Object)(object)val2 != (Object)null)
					{
						Plugin.LogDebug("Found a shelf at " + val2.position.x + ", " + val2.position.y + ", " + val2.position.z);
						Functions.CreateItemSpawn(val2, new Vector3(-7.68f, -6.6f, 1.79f), "SmallItems", 15, copy: true);
					}
					Transform obj4 = ((Component)allTile).transform.Find("Props/PropSet2/WoodPalletPile2x");
					val2 = ((obj4 != null) ? ((Component)obj4).transform : null);
					if ((Object)(object)val2 != (Object)null)
					{
						Plugin.LogDebug("Found a pallet at " + val2.position.x + ", " + val2.position.y + ", " + val2.position.z);
						Functions.CreateItemSpawn(val2, new Vector3(0.3f, 0.04f, 2.54f), "TabletopItems", 3, copy: false);
					}
					Transform obj5 = ((Component)allTile).transform.Find("Props/PropSet2/Minecart (1)");
					val2 = ((obj5 != null) ? ((Component)obj5).transform : null);
					if ((Object)(object)val2 != (Object)null)
					{
						Plugin.LogDebug("Found a minecart at " + val2.position.x + ", " + val2.position.y + ", " + val2.position.z);
						GameObject obj6 = Functions.CreateItemSpawn(val2, new Vector3(-0.74f, 1.22f, 4.11f), "SmallItems", 1, copy: false);
						Transform val3 = ((obj6 != null) ? obj6.transform : null);
						if ((Object)(object)val3 != (Object)null)
						{
							Functions.ConvertToRandomSpawn(val3, 0.25f, 0.8f);
						}
					}
					break;
				}
				case "TunnelSplitEndTile(Clone)":
				{
					Transform obj7 = ((Component)allTile).transform.Find("SouthWallProps/Shelf1 (14)");
					Transform val2 = ((obj7 != null) ? ((Component)obj7).transform : null);
					if ((Object)(object)val2 != (Object)null)
					{
						Plugin.LogDebug("Found a shelf at " + val2.position.x + ", " + val2.position.y + ", " + val2.position.z);
						Functions.CreateItemSpawn(val2, new Vector3(-7.68f, -6.6f, 1.79f), "SmallItems", 15, copy: true);
					}
					break;
				}
				case "CaveCrampedIntersectTile(Clone)":
				{
					Transform obj2 = ((Component)allTile).transform.Find("TablePropSpawn");
					GameObject val = ((obj2 != null) ? ((Component)obj2).gameObject : null);
					if ((Object)(object)val != (Object)null)
					{
						Plugin.LogDebug("Destroying table prop spawn at " + val.transform.position.x + ", " + val.transform.position.y + ", " + val.transform.position.z);
						Object.Destroy((Object)(object)val);
					}
					break;
				}
				case "CaveWaterTile(Clone)":
				{
					Transform obj = ((Component)allTile).transform.Find("MapHazardSpawnType1");
					GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
					if ((Object)(object)val != (Object)null)
					{
						Plugin.LogDebug("Destroying hazard spawn at " + val.transform.position.x + ", " + val.transform.position.y + ", " + val.transform.position.z);
						Object.Destroy((Object)(object)val);
					}
					break;
				}
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPostfix]
		private static void ChangeManeaterData(StartOfRound __instance)
		{
			EnemyType[] array = Resources.FindObjectsOfTypeAll<EnemyType>();
			foreach (EnemyType val in array)
			{
				if (((Object)val).name == "CaveDweller")
				{
					val.increasedChanceInterior = -1;
					break;
				}
			}
		}

		[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> ChangeMineshaftAmount(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: 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_0035: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(RoundManager), "currentDungeonType"), (string)null)
			}).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_6, (object)null, (string)null)
			}).SetInstruction(new CodeInstruction(OpCodes.Ldc_I4_0, (object)null))
				.InstructionEnumeration();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "RebalancedMineshaft";

		public const string PLUGIN_NAME = "RebalancedMineshaft";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}