watermod.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DunGen;
using DunGen.Graph;
using HarmonyLib;
using LethalLevelLoader;
using Unity.Netcode;
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("watermod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("watermod")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("09bfd390-c977-4ea2-8460-6b5fdeb84117")]
[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 watermod
{
	[BepInPlugin("ZGAF.WaterDungeonMod", "ZGAF Water Dungeon", "0.0.1")]
	public class WaterModBase : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(RoundManager))]
		internal class RoundManagerPatch
		{
			[HarmonyPatch("GenerateNewFloor")]
			[HarmonyPostfix]
			private static void FixTeleportDoors(ref RuntimeDungeon ___dungeonGenerator)
			{
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e4: 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_0132: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_0201: Unknown result type (might be due to invalid IL or missing references)
				//IL_0206: Unknown result type (might be due to invalid IL or missing references)
				//IL_0245: Unknown result type (might be due to invalid IL or missing references)
				//IL_0247: Unknown result type (might be due to invalid IL or missing references)
				if (((Object)___dungeonGenerator.Generator.DungeonFlow).name != "dungeonflow")
				{
					return;
				}
				GameObject val = GameObject.Find("DungeonEntranceTeleport");
				NetworkManager val2 = Object.FindObjectOfType<NetworkManager>();
				if (!Object.op_Implicit((Object)(object)val))
				{
					Instance.mls.LogInfo((object)"++++++++++++++ Dungeon Door Not Found. ");
					return;
				}
				Vector3 position = val.transform.position;
				NetworkPrefab val3 = val2.NetworkConfig.Prefabs.Prefabs.First((NetworkPrefab x) => ((Object)x.Prefab).name == "EntranceTeleportA");
				if (val3 == null)
				{
					Instance.mls.LogInfo((object)"++++++++++++++ Unable to find instance of building entrance.");
					return;
				}
				Instance.mls.LogInfo((object)"++++++++++++++ Found DungeonEntranceTeleportA placeholder, swapping with network prefab...");
				Object.Instantiate<GameObject>(val3.Prefab, position, Quaternion.identity);
				GameObject val4 = GameObject.Find("DungeonFireExitTeleport");
				if (!Object.op_Implicit((Object)(object)val4))
				{
					Instance.mls.LogInfo((object)"++++++++++++++ Fire Exit Not Found. ");
					return;
				}
				Vector3 position2 = val4.transform.position;
				NetworkPrefab val5 = val2.NetworkConfig.Prefabs.Prefabs.First((NetworkPrefab x) => ((Object)x.Prefab).name == "EntranceTeleportB");
				if (val5 == null)
				{
					Instance.mls.LogInfo((object)"++++++++++++++ Unable to find instance of fire exit entrance.");
					return;
				}
				Instance.mls.LogInfo((object)"++++++++++++++ Found DungeonEntranceTeleportB placeholder, swapping with network prefab...");
				Object.Instantiate<GameObject>(val5.Prefab, position2, Quaternion.identity);
				IEnumerable<GameObject> enumerable = from obj in Resources.FindObjectsOfTypeAll<GameObject>()
					where ((Object)obj).name == "VentDummy"
					select obj;
				foreach (GameObject item in enumerable)
				{
					Vector3 position3 = item.transform.position;
					NetworkPrefab val6 = val2.NetworkConfig.Prefabs.Prefabs.First((NetworkPrefab x) => ((Object)x.Prefab).name == "VentEntrance");
					Object.Instantiate<GameObject>(val6.Prefab, position3, Quaternion.identity);
				}
			}

			[HarmonyPatch("SpawnScrapInLevel")]
			[HarmonyPrefix]
			private static bool SetItemSpawnPoints(ref SelectableLevel ___currentLevel, ref RuntimeDungeon ___dungeonGenerator)
			{
				if (((Object)___dungeonGenerator.Generator.DungeonFlow).name != "dungeonflow")
				{
					return true;
				}
				SpawnableItemWithRarity val = ___currentLevel.spawnableScrap.Find((SpawnableItemWithRarity x) => x.spawnableItem.itemName == "Bottles");
				if (val == null)
				{
					Instance.mls.LogError((object)"Failed to find bottle bin item for reference snatching; is this a custom moon without the bottle bin item?");
					return true;
				}
				SpawnableItemWithRarity val2 = ___currentLevel.spawnableScrap.Find((SpawnableItemWithRarity x) => x.spawnableItem.itemName == "Golden cup");
				ItemGroup spawnableItems = val.spawnableItem.spawnPositionTypes.Find((ItemGroup x) => ((Object)x).name == "GeneralItemClass");
				ItemGroup val3 = val.spawnableItem.spawnPositionTypes.Find((ItemGroup x) => ((Object)x).name == "TabletopItems");
				ItemGroup spawnableItems2 = (ItemGroup)((val2 == null) ? ((object)val3) : ((object)val2.spawnableItem.spawnPositionTypes.Find((ItemGroup x) => ((Object)x).name == "SmallItems")));
				GameObject[] array = GameObject.FindGameObjectsWithTag("ScrapSpawn");
				if (!array.Any())
				{
					Instance.mls.LogInfo((object)"!!!!!!!!!!!!!!! Could Not Find Scrap Spawn Locations");
					return true;
				}
				GameObject[] array2 = array;
				foreach (GameObject val4 in array2)
				{
					switch (((Object)val4).name)
					{
					case "GeneralItemClassDummy":
					{
						Instance.mls.LogInfo((object)"++++++++++++++++ Creating General Scrap Spawn");
						RandomScrapSpawn val7 = val4.AddComponent<RandomScrapSpawn>();
						val7.spawnableItems = spawnableItems;
						val7.itemSpawnRange = 3f;
						val7.spawnedItemsCopyPosition = false;
						val7.spawnUsed = false;
						break;
					}
					case "TabletopItemsDummy":
					{
						Instance.mls.LogInfo((object)"++++++++++++++++ Creating Table Scrap Spawn");
						RandomScrapSpawn val6 = val4.AddComponent<RandomScrapSpawn>();
						val6.spawnableItems = val3;
						val6.itemSpawnRange = 2f;
						val6.spawnedItemsCopyPosition = false;
						val6.spawnUsed = false;
						break;
					}
					case "SmallItemsDummy":
					{
						Instance.mls.LogInfo((object)"++++++++++++++++ Creating Small Scrap Spawn");
						RandomScrapSpawn val5 = val4.AddComponent<RandomScrapSpawn>();
						val5.spawnableItems = spawnableItems2;
						val5.itemSpawnRange = 2f;
						val5.spawnedItemsCopyPosition = false;
						val5.spawnUsed = false;
						break;
					}
					}
				}
				return true;
			}

			[HarmonyPatch("SpawnSyncedProps")]
			[HarmonyPrefix]
			private static bool SpawnMapHazard(ref RuntimeDungeon ___dungeonGenerator)
			{
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				if (((Object)___dungeonGenerator.Generator.DungeonFlow).name != "dungeonflow")
				{
					return true;
				}
				NetworkManager val = Object.FindObjectOfType<NetworkManager>();
				GameObject[] array = Object.FindObjectsOfType<GameObject>();
				NetworkPrefab val2 = val.NetworkConfig.Prefabs.Prefabs.First((NetworkPrefab x) => ((Object)x.Prefab).name == "TurretContainer");
				NetworkPrefab val3 = val.NetworkConfig.Prefabs.Prefabs.First((NetworkPrefab x) => ((Object)x.Prefab).name == "Landmine");
				List<GameObject> spawnablePrefabs = new List<GameObject> { val2.Prefab, val3.Prefab };
				GameObject[] array2 = array;
				foreach (GameObject val4 in array2)
				{
					string name = ((Object)val4).name;
					string text = name;
					if (text == "MapHazardSpawnType1")
					{
						RandomMapObject val5 = val4.AddComponent<RandomMapObject>();
						val5.spawnablePrefabs = spawnablePrefabs;
						(string, Vector3) tuple = ($"++++++++++++++++ Created Hazard Spawn at {0}", ((Component)val5).transform.position);
						Instance.mls.LogInfo((object)tuple);
					}
				}
				return true;
			}

			[HarmonyPatch("SpawnSyncedProps")]
			[HarmonyPrefix]
			private static bool SpawnAsaparagus(ref RuntimeDungeon ___dungeonGenerator)
			{
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				if (((Object)___dungeonGenerator.Generator.DungeonFlow).name != "dungeonflow")
				{
					return true;
				}
				NetworkManager val = Object.FindObjectOfType<NetworkManager>();
				GameObject val2 = GameObject.Find("LungSpawn");
				if ((Object)(object)val2 == (Object)null)
				{
					Instance.mls.LogInfo((object)"++++++++++++++++ Asparagus spawn location not found!");
					return true;
				}
				SpawnSyncedObject val3 = val2.AddComponent<SpawnSyncedObject>();
				NetworkPrefab val4 = val.NetworkConfig.Prefabs.Prefabs.First((NetworkPrefab x) => ((Object)x.Prefab).name == "LungApparatus");
				val3.spawnPrefab = val4.Prefab;
				if ((Object)(object)val3.spawnPrefab == (Object)null)
				{
					Instance.mls.LogInfo((object)"++++++++++++++++ Asparagus prefab not found!");
					return true;
				}
				(string, Vector3) tuple = ($"++++++++++++++++ Spawned Asparagus at {0}", ((Component)val3).transform.position);
				Instance.mls.LogInfo((object)tuple);
				return true;
			}
		}

		private const string modGUID = "ZGAF.WaterDungeonMod";

		private const string modName = "ZGAF Water Dungeon";

		private const string modVersion = "0.0.1";

		private readonly Harmony harmony = new Harmony("ZGAF.WaterDungeonMod");

		private static WaterModBase Instance;

		internal ManualLogSource mls;

		private ConfigEntry<int> configWDRarity;

		private ConfigEntry<string> configMoons;

		private ConfigEntry<bool> configGuaranteedWD;

		private string[] MoonConfigs = new string[5] { "vanilla", "modded", "all", "paid", "titan" };

		private void Awake()
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("ZGAF.WaterDungeonMod");
			mls.LogInfo((object)"ZGAF Water Dungeon v0.0.1");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(directoryName, "waterdungeon"));
			if ((Object)(object)val == (Object)null)
			{
				mls.LogError((object)"Failed to load Water Dungeon Assets");
				return;
			}
			harmony.PatchAll(typeof(WaterModBase));
			harmony.PatchAll(typeof(RoundManagerPatch));
			configWDRarity = ((BaseUnityPlugin)this).Config.Bind<int>("General", "WDRarity", 100, new ConfigDescription("How rare it is for the foundation to be chosen. Higher values increases the chance of spawning the foundation.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 300), Array.Empty<object>()));
			configMoons = ((BaseUnityPlugin)this).Config.Bind<string>("General", "WDMoons", "all", new ConfigDescription("The moon(s) that the foundation can spawn on, from the given presets.", (AcceptableValueBase)(object)new AcceptableValueList<string>(MoonConfigs), Array.Empty<object>()));
			configGuaranteedWD = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "WDGuaranteed", true, new ConfigDescription("If enabled, the foundation will be effectively guaranteed to spawn. Only recommended for debugging/sightseeing purposes.", (AcceptableValueBase)null, Array.Empty<object>()));
			mls.LogInfo((object)"Loaded zgaf waterdungeon moon config!");
			DungeonFlow val2 = val.LoadAsset<DungeonFlow>("assets/Mods/waterdungeon/dungeonscripts/dungeonflow.asset");
			if ((Object)(object)val2 == (Object)null)
			{
				mls.LogError((object)"Failed to load WaterDungeon Flow.");
				return;
			}
			ExtendedDungeonFlow val3 = ScriptableObject.CreateInstance<ExtendedDungeonFlow>();
			val3.dungeonFlow = val2;
			val3.dungeonFirstTimeAudio = null;
			val3.dungeonDefaultRarity = 0;
			int num = (configGuaranteedWD.Value ? 99999 : configWDRarity.Value);
			val3.manualContentSourceNameReferenceList.Add(new StringWithRarity("Lethal Company", num));
			val3.manualContentSourceNameReferenceList.Add(new StringWithRarity("Custom", num));
			Instance.mls.LogInfo((object)"Registered dungeon interior on all moons, including modded.");
			AssetBundleLoader.RegisterExtendedDungeonFlow(val3);
			mls.LogInfo((object)"WaterDungeon for Lethal Company [Version 0.0.1] successfully loaded.");
		}
	}
}
namespace watermod.Patches
{
	[HarmonyPatch(typeof(CurrentLevelValues))]
	internal class CurrentLevelValues
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void maxScrapPatch(ref float ___maxScrap)
		{
			___maxScrap = 0f;
		}
	}
}