Decompiled source of RebalancedMoonsBeta v1.0.0

RebalancedMoons.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using LethalLevelLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
using WeatherRegistry;

[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("RebalancedMoons")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Rebalances the vanilla moons.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e5abafc249e0a1c105dbebd1bba9baac21b01f02")]
[assembly: AssemblyProduct("RebalancedMoons")]
[assembly: AssemblyTitle("RebalancedMoons")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RebalancedMoons
{
	[BepInPlugin("dopadream.lethalcompany.rebalancedmoons", "RebalancedMoons", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch]
		private class RebalancedMoonsPatches
		{
			[HarmonyPatch(typeof(QuickMenuManager), "Start")]
			[HarmonyPostfix]
			[HarmonyPriority(800)]
			private static void QuickMenuManagerStartPostFix(StartOfRound __instance)
			{
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Expected O, but got Unknown
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dc: Expected O, but got Unknown
				//IL_0113: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Expected O, but got Unknown
				//IL_0174: Unknown result type (might be due to invalid IL or missing references)
				//IL_017b: Expected O, but got Unknown
				foreach (ExtendedLevel vanillaExtendedLevel in PatchedContent.VanillaExtendedLevels)
				{
					switch (vanillaExtendedLevel.NumberlessPlanetName)
					{
					case "Dine":
						ApplyRebalance(vanillaExtendedLevel, reDineExtended);
						vanillaExtendedLevel.SceneSelections.Clear();
						vanillaExtendedLevel.SceneSelections.Add(new StringWithRarity("ReDineScene", 100));
						Logger.LogDebug((object)"Dine level overwritten!");
						break;
					case "March":
						ApplyRebalance(vanillaExtendedLevel, reMarchExtended);
						vanillaExtendedLevel.SceneSelections.Clear();
						vanillaExtendedLevel.SceneSelections.Add(new StringWithRarity("ReMarchScene", 100));
						Logger.LogDebug((object)"March level overwritten!");
						break;
					case "Offense":
						ApplyRebalance(vanillaExtendedLevel, reOffenseExtended);
						vanillaExtendedLevel.SceneSelections.Clear();
						vanillaExtendedLevel.SceneSelections.Add(new StringWithRarity("ReOffenseScene", 100));
						Logger.LogDebug((object)"Offense level overwritten!");
						break;
					case "Assurance":
						ApplyRebalance(vanillaExtendedLevel, reAssuranceExtended);
						break;
					case "Titan":
						foreach (Item items in StartOfRound.Instance.allItemsList.itemsList)
						{
							if (items.itemName == "Gold bar")
							{
								SpawnableItemWithRarity val = new SpawnableItemWithRarity();
								val.spawnableItem = items;
								val.rarity = 20;
								vanillaExtendedLevel.SelectableLevel.spawnableScrap.Add(val);
								vanillaExtendedLevel.SelectableLevel.factorySizeMultiplier = 2f;
								Logger.LogDebug((object)"Titan rebalances applied!");
								break;
							}
						}
						break;
					}
				}
				if (Chainloader.PluginInfos.ContainsKey("mrov.WeatherRegistry"))
				{
					applyWeatherRegistryCompat();
					Logger.LogDebug((object)"Attempted weather change!");
				}
			}

			[HarmonyPatch(typeof(StartOfRound), "ArriveAtLevel")]
			[HarmonyPostfix]
			[HarmonyAfter(new string[] { "mrov.WeatherRegistry", "imabatby.lethallevelloader" })]
			private static void StartOfRoundChangeLevelPostfix(StartOfRound __instance)
			{
				if (Chainloader.PluginInfos.ContainsKey("mrov.WeatherRegistry"))
				{
					applyWeatherRegistryCompat();
					Logger.LogDebug((object)"Attempted weather change!");
				}
			}

			[HarmonyPatch(typeof(StartOfRound), "PassTimeToNextDay")]
			[HarmonyPostfix]
			[HarmonyAfter(new string[] { "mrov.WeatherRegistry", "imabatby.lethallevelloader" })]
			private static void StartOfRoundPassTimePostFix(StartOfRound __instance)
			{
				if (Chainloader.PluginInfos.ContainsKey("mrov.WeatherRegistry"))
				{
					applyWeatherRegistryCompat();
					Logger.LogDebug((object)"Attempted weather change!");
				}
			}

			[HarmonyPatch(typeof(TimeOfDay), "Update")]
			[HarmonyPostfix]
			private static void TimeOfDayPostUpdate(TimeOfDay __instance)
			{
				if (__instance.currentLevel.sceneName == "ReMarchScene" && ((!GameNetworkManager.Instance.localPlayerController.isInsideFactory && !GameNetworkManager.Instance.localPlayerController.isPlayerDead) || ((Object)(object)GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript != (Object)null && !GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript.isInsideFactory)))
				{
					__instance.effects[1].effectEnabled = true;
				}
			}

			[HarmonyPatch(typeof(ExtendedLevel), "SetExtendedDungeonFlowMatches")]
			[HarmonyPostfix]
			[HarmonyPriority(800)]
			private static void ExtendedLevelSetFlowsPostFix(ExtendedLevel __instance)
			{
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Expected O, but got Unknown
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Expected O, but got Unknown
				//IL_017f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0189: Expected O, but got Unknown
				//IL_0146: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Expected O, but got Unknown
				foreach (ExtendedDungeonFlow extendedDungeonFlow in PatchedContent.ExtendedDungeonFlows)
				{
					switch (((Object)extendedDungeonFlow.DungeonFlow).name)
					{
					case "Level1Flow3Exits":
					{
						for (int j = 0; j < extendedDungeonFlow.LevelMatchingProperties.planetNames.Count; j++)
						{
							if (extendedDungeonFlow.LevelMatchingProperties.planetNames[j].Name.Equals("March"))
							{
								extendedDungeonFlow.LevelMatchingProperties.planetNames.RemoveAt(j);
							}
						}
						break;
					}
					case "Level1Flow":
						extendedDungeonFlow.LevelMatchingProperties.planetNames.Add(new StringWithRarity("March", 300));
						break;
					case "Level2Flow":
						extendedDungeonFlow.LevelMatchingProperties.planetNames.Add(new StringWithRarity("March", 5));
						break;
					case "Level3Flow":
					{
						for (int i = 0; i < extendedDungeonFlow.LevelMatchingProperties.planetNames.Count; i++)
						{
							if (extendedDungeonFlow.LevelMatchingProperties.planetNames[i].Name.Equals("Dine"))
							{
								extendedDungeonFlow.LevelMatchingProperties.planetNames.RemoveAt(i);
								extendedDungeonFlow.LevelMatchingProperties.planetNames.Add(new StringWithRarity("Dine", 80));
							}
						}
						extendedDungeonFlow.LevelMatchingProperties.planetNames.Add(new StringWithRarity("March", 160));
						break;
					}
					}
				}
			}
		}

		private const string PLUGIN_GUID = "dopadream.lethalcompany.rebalancedmoons";

		private const string PLUGIN_NAME = "RebalancedMoons";

		private const string PLUGIN_VERSION = "1.0.0";

		private const string WEATHER_REGISTRY = "mrov.WeatherRegistry";

		internal static ManualLogSource Logger;

		internal static ExtendedLevel reDineExtended;

		internal static ExtendedLevel reMarchExtended;

		internal static ExtendedLevel reOffenseExtended;

		internal static ExtendedLevel reAssuranceExtended;

		internal static ExtendedMod rebalancedMoonsMod;

		private void Awake()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			AssetBundleLoader.AddOnExtendedModLoadedListener((Action<ExtendedMod>)OnExtendedModRegistered, "dopadream", "RebalancedMoons");
			new Harmony("dopadream.lethalcompany.rebalancedmoons").PatchAll();
			Logger.LogInfo((object)"RebalancedMoons v1.0.0 loaded");
		}

		internal static void applyWeatherRegistryCompat()
		{
			foreach (ExtendedLevel extendedLevel in PatchedContent.ExtendedLevels)
			{
				switch (extendedLevel.SelectableLevel.sceneName)
				{
				case "ReDineScene":
					foreach (ExtendedLevel extendedLevel2 in PatchedContent.ExtendedLevels)
					{
						if (extendedLevel2.NumberlessPlanetName == "Dine")
						{
							Weather currentWeather4 = WeatherManager.GetCurrentWeather(extendedLevel2.SelectableLevel);
							WeatherController.ChangeWeather(extendedLevel.SelectableLevel, currentWeather4);
							break;
						}
					}
					break;
				case "ReMarchScene":
					foreach (ExtendedLevel extendedLevel3 in PatchedContent.ExtendedLevels)
					{
						if (extendedLevel3.NumberlessPlanetName == "March")
						{
							Weather currentWeather3 = WeatherManager.GetCurrentWeather(extendedLevel3.SelectableLevel);
							WeatherController.ChangeWeather(extendedLevel.SelectableLevel, currentWeather3);
							break;
						}
					}
					break;
				case "ReOffenseScene":
					foreach (ExtendedLevel extendedLevel4 in PatchedContent.ExtendedLevels)
					{
						if (extendedLevel4.NumberlessPlanetName == "Offense")
						{
							Weather currentWeather2 = WeatherManager.GetCurrentWeather(extendedLevel4.SelectableLevel);
							WeatherController.ChangeWeather(extendedLevel.SelectableLevel, currentWeather2);
							break;
						}
					}
					break;
				case "Level2Assurance":
					foreach (ExtendedLevel extendedLevel5 in PatchedContent.ExtendedLevels)
					{
						if (extendedLevel5.NumberlessPlanetName == "Assurance")
						{
							Weather currentWeather = WeatherManager.GetCurrentWeather(extendedLevel5.SelectableLevel);
							WeatherController.ChangeWeather(reAssuranceExtended.SelectableLevel, currentWeather);
							break;
						}
					}
					break;
				}
			}
		}

		internal static void OnExtendedModRegistered(ExtendedMod extendedMod)
		{
			if (!((Object)(object)extendedMod == (Object)null))
			{
				rebalancedMoonsMod = extendedMod;
				reAssuranceExtended = rebalancedMoonsMod.ExtendedLevels[0];
				reDineExtended = rebalancedMoonsMod.ExtendedLevels[1];
				reMarchExtended = rebalancedMoonsMod.ExtendedLevels[2];
				reOffenseExtended = rebalancedMoonsMod.ExtendedLevels[3];
				Logger.LogDebug((object)(reDineExtended.NumberlessPlanetName + reMarchExtended.NumberlessPlanetName + reOffenseExtended.NumberlessPlanetName + reAssuranceExtended.NumberlessPlanetName));
			}
		}

		internal static void ApplyRebalance(ExtendedLevel input, ExtendedLevel output)
		{
			input.RoutePrice = output.RoutePrice;
			input.SelectableLevel.Enemies = output.SelectableLevel.Enemies;
			input.SelectableLevel.OutsideEnemies = output.SelectableLevel.OutsideEnemies;
			input.SelectableLevel.DaytimeEnemies = output.SelectableLevel.DaytimeEnemies;
			input.SelectableLevel.maxEnemyPowerCount = output.SelectableLevel.maxEnemyPowerCount;
			input.SelectableLevel.maxOutsideEnemyPowerCount = output.SelectableLevel.maxOutsideEnemyPowerCount;
			input.SelectableLevel.maxDaytimeEnemyPowerCount = output.SelectableLevel.maxDaytimeEnemyPowerCount;
			input.SelectableLevel.spawnProbabilityRange = output.SelectableLevel.spawnProbabilityRange;
			input.SelectableLevel.enemySpawnChanceThroughoutDay = output.SelectableLevel.enemySpawnChanceThroughoutDay;
			input.SelectableLevel.daytimeEnemiesProbabilityRange = output.SelectableLevel.daytimeEnemiesProbabilityRange;
			input.SelectableLevel.daytimeEnemySpawnChanceThroughDay = output.SelectableLevel.daytimeEnemySpawnChanceThroughDay;
			input.SelectableLevel.minScrap = output.SelectableLevel.minScrap;
			input.SelectableLevel.maxScrap = output.SelectableLevel.maxScrap;
			input.SelectableLevel.minTotalScrapValue = output.SelectableLevel.minTotalScrapValue;
			input.SelectableLevel.maxTotalScrapValue = output.SelectableLevel.maxTotalScrapValue;
			input.SelectableLevel.spawnableScrap.Clear();
			input.SelectableLevel.spawnableScrap.AddRange(output.SelectableLevel.spawnableScrap);
			input.SelectableLevel.spawnableMapObjects = output.SelectableLevel.spawnableMapObjects;
			input.SelectableLevel.spawnableOutsideObjects = output.SelectableLevel.spawnableOutsideObjects;
			input.SelectableLevel.riskLevel = output.SelectableLevel.riskLevel;
			input.RouteNode.displayPlanetInfo = output.RouteNode.displayPlanetInfo;
			input.RouteConfirmNode.buyRerouteToMoon = output.RouteConfirmNode.buyRerouteToMoon;
			Logger.LogDebug((object)("Rebalances applied for " + ((object)input)?.ToString() + "!"));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "RebalancedMoons";

		public const string PLUGIN_NAME = "RebalancedMoons";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}