Decompiled source of BaconFixer v1.2.0

BepInEx/plugins/BaconFixer.dll

Decompiled 10 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLevelLoader;
using Microsoft.CodeAnalysis;
using MrovLib.ContentType;
using TMPro;
using TerminalUtils;
using TerminalUtils.Definitions;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.UI;
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("BaconFixer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BaconFixer")]
[assembly: AssemblyTitle("BaconFixer")]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "Code generated with Claude Code, Anthropic's AI coding agent")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "Anthropic")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 BaconFixer
{
	internal static class ChameleonSupport
	{
		private const int VanillaCaves = -1;

		private const int IceCaves = 0;

		private const int AmethystCaves = 1;

		private const int DesertCaves = 2;

		private const int MesaCaves = 3;

		private const int GravelCaves = 4;

		private const int SaltCaves = 5;

		private const int SlateCaves = 6;

		private static readonly Color DefaultLight = new Color(0.490566f, 0.4165709f, 0.3355286f);

		private static readonly Color SnowLight = new Color(0.4845f, 0.4986666f, 0.51f);

		private static readonly Color AmethystLight = new Color(0.4901961f, 0.3714178f, 0.3578431f);

		private static readonly Color DimLight = new Color(0.3f, 0.3f, 0.33f);

		private static readonly Color FoggyLight = new Color(0.42f, 0.42f, 0.42f);

		private static readonly Color GreenLight = new Color(0.4901961f, 0.4693464f, 32f / 85f);

		private static FieldInfo _interior;

		private static FieldInfo _cosmeticInfo;

		private static FieldInfo _lightBehindDoor;

		private static FieldInfo _doorLightColor;

		private static Dictionary<string, IntWithRarity[]> _caveLists;

		internal static void Apply(Harmony h)
		{
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Expected O, but got Unknown
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Expected O, but got Unknown
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Expected O, but got Unknown
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Expected O, but got Unknown
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Expected O, but got Unknown
			if (Chainloader.PluginInfos.TryGetValue("butterystancakes.lethalcompany.chameleon", out var value) && value.Instance != null)
			{
				Assembly assembly = ((object)value.Instance).GetType().Assembly;
				Type type = assembly.GetType("Chameleon.Common", throwOnError: false);
				Type type2 = assembly.GetType("Chameleon.Overrides.Interior.DoorLightColorer", throwOnError: false);
				Type? type3 = assembly.GetType("Chameleon.Overrides.Interior.RetextureCaverns", throwOnError: false);
				_interior = AccessTools.Field(type, "interior");
				_cosmeticInfo = AccessTools.Field(type, "currentLevelCosmeticInfo");
				_lightBehindDoor = AccessTools.Field(type2, "lightBehindDoor");
				_doorLightColor = AccessTools.Field(type2, "doorLightColor");
				_caveLists = AccessTools.Field(type3, "cavernWeightLists")?.GetValue(null) as Dictionary<string, IntWithRarity[]>;
				MethodInfo methodInfo = AccessTools.Method(assembly.GetType("Chameleon.Overrides.Interior.ManorWindows", throwOnError: false), "Apply", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(type3, "Apply", (Type[])null, (Type[])null);
				MethodInfo methodInfo3 = AccessTools.Method(type2, "Apply", (Type[])null, (Type[])null);
				MethodInfo methodInfo4 = AccessTools.Method(assembly.GetType("Chameleon.Info.Queries", throwOnError: false), "IsSnowLevel", (Type[])null, (Type[])null);
				if (_interior == null || _cosmeticInfo == null || _lightBehindDoor == null || _doorLightColor == null || _caveLists == null || methodInfo == null || methodInfo2 == null || methodInfo3 == null || methodInfo4 == null)
				{
					Plugin.Log.LogWarning((object)"ChameleonSupport: Chameleon layout changed, skipping");
					return;
				}
				HarmonyMethod val = new HarmonyMethod(typeof(ChameleonSupport), "RestoreInterior", (Type[])null);
				h.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(ChameleonSupport), "WindowsPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null);
				h.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(ChameleonSupport), "CavesPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null);
				h.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(ChameleonSupport), "DoorLightPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				h.Patch((MethodBase)methodInfo4, (HarmonyMethod)null, new HarmonyMethod(typeof(ChameleonSupport), "SnowPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Plugin.Log.LogInfo((object)"ChameleonSupport: windows in Spooky Manor, caves in Aquatic Dungeon, door lights and snow checks for modded moons");
			}
		}

		private static void WindowsPrefix(out string __state)
		{
			PassAs("SpookyManorFlow", "Level2Flow", out __state);
		}

		private static void CavesPrefix(out string __state)
		{
			PassAs("AquaticDungeonFlow", "Level3Flow", out __state);
		}

		private static void PassAs(string modded, string vanilla, out string real)
		{
			real = (string)_interior.GetValue(null);
			if (real == modded)
			{
				_interior.SetValue(null, vanilla);
			}
		}

		private static void RestoreInterior(string __state)
		{
			_interior.SetValue(null, __state);
		}

		private static void DoorLightPostfix()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_003c: Invalid comparison between Unknown and I4
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Invalid comparison between Unknown and I4
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Invalid comparison between Unknown and I4
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between Unknown and I4
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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)
			object? value = _lightBehindDoor.GetValue(null);
			SpriteRenderer val = (SpriteRenderer)((value is SpriteRenderer) ? value : null);
			if ((Object)(object)val == (Object)null || _cosmeticInfo.GetValue(null) != null)
			{
				return;
			}
			SelectableLevel currentLevel = StartOfRound.Instance.currentLevel;
			LevelWeatherType currentWeather = currentLevel.currentWeather;
			if ((int)currentWeather != 5 && (int)currentWeather != 2 && (int)currentWeather != 4)
			{
				int? num = MainCaveType(currentLevel);
				if (num.HasValue)
				{
					Color val2 = (((int)currentWeather == 3) ? FoggyLight : LightFor(num.Value));
					_doorLightColor.SetValue(null, val2);
					val.color = val2;
				}
			}
		}

		private static void SnowPostfix(ref bool __result)
		{
			if (__result)
			{
				int? num = MainCaveType(StartOfRound.Instance.currentLevel);
				if (num == 2 || num == 3)
				{
					__result = false;
				}
			}
		}

		private static Color LightFor(int cave)
		{
			//IL_002a: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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)
			switch (cave)
			{
			case -1:
				return GreenLight;
			case 0:
			case 5:
				return SnowLight;
			case 1:
				return AmethystLight;
			case 4:
				return FoggyLight;
			case 6:
				return DimLight;
			default:
				return DefaultLight;
			}
		}

		private static int? MainCaveType(SelectableLevel level)
		{
			if ((Object)(object)level == (Object)null || !_caveLists.TryGetValue(((Object)level).name, out var value) || value.Length == 0)
			{
				return null;
			}
			IntWithRarity val = value[0];
			IntWithRarity[] array = value;
			foreach (IntWithRarity val2 in array)
			{
				if (val2.rarity > val.rarity)
				{
					val = val2;
				}
			}
			return val.id;
		}
	}
	internal static class DestroyedLightsFix
	{
		internal static void Apply(Harmony h)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			HarmonyMethod val = new HarmonyMethod(typeof(DestroyedLightsFix), "RemoveDestroyedLights", (Type[])null);
			string[] array = new string[2] { "turnOnLights", "FlickerPoweredLights" };
			foreach (string text in array)
			{
				h.Patch((MethodBase)AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(RoundManager), text, (Type[])null, (Type[])null)), val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static void RemoveDestroyedLights()
		{
			RoundManager.Instance?.allPoweredLightsAnimators?.RemoveAll((Animator animator) => (Object)(object)animator == (Object)null);
		}
	}
	internal static class DestroyItemFix
	{
		private const string DestroyItemInSlotFix = "JacobG5.DestroyItemInSlotFix";

		private const string DawnLib = "com.github.teamxiaolan.dawnlib";

		internal static void Apply(Harmony h)
		{
			if (Chainloader.PluginInfos.ContainsKey("JacobG5.DestroyItemInSlotFix") && Chainloader.PluginInfos.ContainsKey("com.github.teamxiaolan.dawnlib"))
			{
				h.Unpatch((MethodBase)AccessTools.Method(typeof(PlayerControllerB), "DestroyItemInSlot", (Type[])null, (Type[])null), (HarmonyPatchType)3, "JacobG5.DestroyItemInSlotFix");
				Plugin.Log.LogInfo((object)"DestroyItemFix: removed DestroyItemInSlotFix's patch so DawnLib's can finish");
			}
		}
	}
	[HarmonyPatch(typeof(NetworkPrefabs), "AddPrefabRegistration")]
	internal static class DuplicatePrefabFix
	{
		[HarmonyPrefix]
		private static bool Prefix(NetworkPrefabs __instance, NetworkPrefab networkPrefab, ref bool __result)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			if (networkPrefab == null || (int)networkPrefab.Override != 0)
			{
				return true;
			}
			GameObject prefab = networkPrefab.Prefab;
			NetworkObject val = default(NetworkObject);
			if ((Object)(object)prefab == (Object)null || !prefab.TryGetComponent<NetworkObject>(ref val))
			{
				return true;
			}
			uint sourcePrefabGlobalObjectIdHash = networkPrefab.SourcePrefabGlobalObjectIdHash;
			if (!__instance.NetworkPrefabOverrideLinks.TryGetValue(sourcePrefabGlobalObjectIdHash, out var value))
			{
				return true;
			}
			string text = (((Object)(object)value?.Prefab != (Object)null) ? ((Object)value.Prefab).name : "(unknown)");
			if (text == ((Object)prefab).name)
			{
				Plugin.Log.LogInfo((object)$"Skipped duplicate network prefab '{((Object)prefab).name}' (hash {sourcePrefabGlobalObjectIdHash})");
			}
			else
			{
				Plugin.Log.LogWarning((object)$"Network hash {sourcePrefabGlobalObjectIdHash} is shared by '{text}' and '{((Object)prefab).name}'. Keeping '{text}'.");
			}
			__result = false;
			return false;
		}
	}
	internal static class FacilityMeltdownFix
	{
		internal static void Apply(Harmony h)
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			if (Chainloader.PluginInfos.TryGetValue("me.loaforc.facilitymeltdown", out var value) && value.Instance != null)
			{
				MethodInfo methodInfo = ((object)value.Instance).GetType().Assembly.GetType("FacilityMeltdown.MeltdownSequence.Behaviours.MeltdownHandler", throwOnError: false)?.GetNestedTypes(AccessTools.all).SelectMany((Type type) => AccessTools.GetDeclaredMethods(type)).FirstOrDefault((MethodInfo method) => method.Name.Contains("HandleEnemies") && method.ReturnType == typeof(bool) && method.GetParameters().FirstOrDefault()?.ParameterType == typeof(SpawnableEnemyWithRarity));
				if (methodInfo == null)
				{
					Plugin.Log.LogWarning((object)"FacilityMeltdownFix: FacilityMeltdown's layout changed, skipping");
					return;
				}
				h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(FacilityMeltdownFix), "LeaveEnemyOut", (Type[])null), (HarmonyMethod)null);
				Plugin.Log.LogInfo((object)"FacilityMeltdownFix: enemies DawnLib doesn't know are left out of meltdowns");
			}
		}

		private static Exception LeaveEnemyOut(Exception __exception, ref bool __result)
		{
			if (!(__exception is NullReferenceException))
			{
				return __exception;
			}
			__result = false;
			return null;
		}
	}
	internal enum Difficulty
	{
		Easy,
		Normal,
		Hard,
		Custom
	}
	internal sealed class SlotSetup
	{
		internal readonly ConfigEntry<Difficulty> Preset;

		internal readonly ConfigEntry<int> Credits;

		internal readonly ConfigEntry<int> Quota;

		internal readonly ConfigEntry<int> GrowthPercent;

		internal readonly ConfigEntry<int> DaysPerQuota;

		internal readonly ConfigEntry<int> DayLengthPercent;

		internal readonly ConfigEntry<int> ScrapAmountPercent;

		internal readonly ConfigEntry<int> ScrapValuePercent;

		internal readonly ConfigEntry<int> EnemyPercent;

		internal SlotSetup(ConfigFile file, int slot)
		{
			string text = $"File {slot + 1}";
			Preset = file.Bind<Difficulty>(text, "Difficulty", Difficulty.Normal, "Easy, Normal, Hard or Custom. Normal leaves the game's values alone.");
			Credits = file.Bind<int>(text, "Starting credits", 60, "Credits on a new save.");
			Quota = file.Bind<int>(text, "Starting quota", 130, "First quota on a new save.");
			GrowthPercent = file.Bind<int>(text, "Quota growth percent", 100, "How fast the quota grows. 100 is the game's speed.");
			DaysPerQuota = file.Bind<int>(text, "Days per quota", 3, "Days the crew gets to reach each quota.");
			DayLengthPercent = file.Bind<int>(text, "Day length percent", 0, "How much longer or shorter each day is. 0 is the game's length, 20 is 20% longer, -20 is 20% shorter.");
			ScrapAmountPercent = file.Bind<int>(text, "Scrap amount percent", 100, "How much scrap spawns, on top of weather bonuses. 100 is normal.");
			ScrapValuePercent = file.Bind<int>(text, "Scrap value percent", 100, "What scrap sells for, on top of weather bonuses. 100 is normal.");
			EnemyPercent = file.Bind<int>(text, "Enemies percent", 100, "How many enemies a moon can hold at once. 100 is normal.");
		}

		internal void Choose(Difficulty preset)
		{
			Preset.Value = preset;
			switch (preset)
			{
			case Difficulty.Easy:
				Set(150, 100, 75, 4, 20, 75);
				break;
			case Difficulty.Normal:
				Set(60, 130, 100, 3, 0, 100);
				break;
			case Difficulty.Hard:
				Set(30, 200, 150, 3, -10, 125);
				break;
			}
		}

		private void Set(int credits, int quota, int growthPercent, int days, int dayLengthPercent, int enemyPercent)
		{
			Credits.Value = credits;
			Quota.Value = quota;
			GrowthPercent.Value = growthPercent;
			DaysPerQuota.Value = days;
			DayLengthPercent.Value = dayLengthPercent;
			ScrapAmountPercent.Value = 100;
			ScrapValuePercent.Value = 100;
			EnemyPercent.Value = enemyPercent;
		}
	}
	internal static class GameSetup
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__ReceiveDaySpeed;
		}

		internal const int NormalCredits = 60;

		internal const int NormalQuota = 130;

		internal const int NormalDays = 3;

		internal const int NormalDaySeconds = 700;

		private const string DaySpeedMessage = "BaconFixer.DaySpeed";

		private const float MinDaySpeed = 0.2f;

		private const float MaxDaySpeed = 4f;

		private const float SendInterval = 5f;

		private static readonly SlotSetup[] Slots = new SlotSetup[3];

		private static bool _rulesActive;

		private static bool _dayLengthChanged;

		private static int _daysPerQuota;

		private static float _nextSend;

		private static float _enemyFactor = 1f;

		internal static float ScrapAmountFactor { get; private set; } = 1f;

		internal static float ScrapValueFactor { get; private set; } = 1f;

		internal static void Apply(Harmony h)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			ConfigFile file = new ConfigFile(Path.Combine(Paths.ConfigPath, "baconfixer.gamesetup.cfg"), true);
			for (int i = 0; i < Slots.Length; i++)
			{
				Slots[i] = new SlotSetup(file, i);
			}
			h.PatchAll(typeof(GameSetup));
		}

		internal static SlotSetup ForSlot(int slot)
		{
			if (slot < 0 || slot >= Slots.Length)
			{
				return null;
			}
			return Slots[slot];
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TimeOfDay), "Awake")]
		private static void ApplyRules(TimeOfDay __instance)
		{
			_rulesActive = (_dayLengthChanged = false);
			_enemyFactor = (ScrapAmountFactor = (ScrapValueFactor = 1f));
			GameNetworkManager instance = GameNetworkManager.Instance;
			SlotSetup slotSetup = (((Object)(object)instance != (Object)null && instance.isHostingGame) ? ForSlot(instance.saveFileNum) : null);
			QuotaSettings quotaVariables = __instance.quotaVariables;
			if (slotSetup != null && quotaVariables != null && slotSetup.Preset.Value != Difficulty.Normal)
			{
				quotaVariables.startingCredits = slotSetup.Credits.Value;
				quotaVariables.startingQuota = slotSetup.Quota.Value;
				quotaVariables.baseIncrease *= (float)slotSetup.GrowthPercent.Value / 100f;
				quotaVariables.deadlineDaysAmount = slotSetup.DaysPerQuota.Value;
				_daysPerQuota = slotSetup.DaysPerQuota.Value;
				_dayLengthChanged = slotSetup.DayLengthPercent.Value != 0;
				__instance.globalTimeSpeedMultiplier *= 100f / (float)(100 + slotSetup.DayLengthPercent.Value);
				ScrapAmountFactor = (float)slotSetup.ScrapAmountPercent.Value / 100f;
				ScrapValueFactor = (float)slotSetup.ScrapValuePercent.Value / 100f;
				_enemyFactor = (float)slotSetup.EnemyPercent.Value / 100f;
				_rulesActive = true;
				Plugin.Log.LogInfo((object)$"GameSetup: {slotSetup.Preset.Value} on file {instance.saveFileNum + 1}: {quotaVariables.startingCredits} credits, {quotaVariables.startingQuota} quota, {slotSetup.GrowthPercent.Value}% growth, {quotaVariables.deadlineDaysAmount} days, day length {slotSetup.DayLengthPercent.Value:+0;-0;0}% (clock speed {__instance.globalTimeSpeedMultiplier:0.###}), scrap {slotSetup.ScrapAmountPercent.Value}% amount {slotSetup.ScrapValuePercent.Value}% value, enemies {slotSetup.EnemyPercent.Value}%");
			}
		}

		[HarmonyPrefix]
		[HarmonyPriority(0)]
		[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
		private static void ApplyScrapRules(RoundManager __instance, out Vector2 __state)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			__state = new Vector2(__instance.scrapAmountMultiplier, __instance.scrapValueMultiplier);
			__instance.scrapAmountMultiplier *= ScrapAmountFactor;
			__instance.scrapValueMultiplier *= ScrapValueFactor;
		}

		[HarmonyPostfix]
		[HarmonyPriority(800)]
		[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
		private static void RestoreScrapRules(RoundManager __instance, Vector2 __state)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			__instance.scrapAmountMultiplier = __state.x;
			__instance.scrapValueMultiplier = __state.y;
		}

		[HarmonyPostfix]
		[HarmonyPriority(0)]
		[HarmonyPatch(typeof(RoundManager), "RefreshEnemiesList")]
		private static void ApplyEnemyRules(RoundManager __instance)
		{
			if (_rulesActive && ((NetworkBehaviour)__instance).IsServer)
			{
				__instance.currentMaxInsidePower *= _enemyFactor;
				__instance.currentMaxOutsidePower *= _enemyFactor;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TimeOfDay), "Start")]
		private static void ListenForDaySpeed()
		{
			//IL_0029: 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_0034: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			if (singleton == null)
			{
				return;
			}
			CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
			if (customMessagingManager != null)
			{
				object obj = <>O.<0>__ReceiveDaySpeed;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = ReceiveDaySpeed;
					<>O.<0>__ReceiveDaySpeed = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("BaconFixer.DaySpeed", (HandleNamedMessageDelegate)obj);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TimeOfDay), "SyncTimeClientRpc")]
		private unsafe static void SendDaySpeed(TimeOfDay __instance)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (!_dayLengthChanged || !((NetworkBehaviour)__instance).IsServer || Time.unscaledTime < _nextSend)
			{
				return;
			}
			_nextSend = Time.unscaledTime + 5f;
			float globalTimeSpeedMultiplier = __instance.globalTimeSpeedMultiplier;
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref globalTimeSpeedMultiplier, default(ForPrimitives));
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessageToAll("BaconFixer.DaySpeed", val, (NetworkDelivery)2);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void ReceiveDaySpeed(ulong sender, FastBufferReader message)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			((FastBufferReader)(ref message)).ReadValueSafe<float>(ref num, default(ForPrimitives));
			TimeOfDay instance = TimeOfDay.Instance;
			if ((Object)(object)instance != (Object)null && !((NetworkBehaviour)instance).IsServer)
			{
				instance.globalTimeSpeedMultiplier = Mathf.Clamp(num, 0.2f, 4f);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TimeOfDay), "SetNewProfitQuota")]
		private static void SyncDeadline(TimeOfDay __instance)
		{
			if (_rulesActive && ((NetworkBehaviour)__instance).IsServer)
			{
				__instance.SyncTimeClientRpc(__instance.globalTime, (int)(__instance.totalTime * (float)_daysPerQuota));
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TimeOfDay), "SetBuyingRateForDay")]
		private static void SyncBuyingRate(TimeOfDay __instance)
		{
			StartOfRound instance = StartOfRound.Instance;
			if (_rulesActive && (Object)(object)instance != (Object)null && ((NetworkBehaviour)__instance).IsServer && ((NetworkBehaviour)instance).IsSpawned)
			{
				instance.SyncCompanyBuyingRateClientRpc(instance.companyBuyingRate);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MenuManager), "Start")]
		private static void BuildPanel(MenuManager __instance)
		{
			GameSetupPanel.Build(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MenuManager), "ClickHostButton")]
		private static void RefreshOnHostScreen()
		{
			GameSetupPanel.Close();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SaveFileUISlot), "SetFileToThis")]
		private static void OpenOnFileChosen()
		{
			GameSetupPanel.Open();
		}
	}
	internal static class GameSetupPanel
	{
		private const float WindowWidth = 730f;

		private const float ColumnGap = 18f;

		private const float RulesWidth = 400f;

		private const float ButtonHeight = 14f;

		private const float StepperWidth = 15f;

		private const float ValueWidth = 78f;

		private const float PresetWidth = 62f;

		private const float TitleSize = 13f;

		private const float HeadingSize = 10f;

		private const float TextSize = 9f;

		private const float SmallSize = 7.5f;

		private static readonly Color Orange = new Color(1f, 0.42f, 0.13f);

		private static readonly Color Dim = new Color(1f, 0.55f, 0.32f, 0.85f);

		private static readonly Color Fill = new Color(0.085f, 0.012f, 0.01f, 0.98f);

		private static readonly Color Border = new Color(0.72f, 0.05f, 0.04f);

		private static readonly Color Shade = new Color(0f, 0f, 0f, 0.6f);

		private static readonly Color ButtonOff = new Color(1f, 0.42f, 0.13f, 0.14f);

		private static readonly Color ButtonHover = new Color(1f, 0.42f, 0.13f, 0.38f);

		private static GameObject _window;

		private static GameObject _bar;

		private static TMP_FontAsset _font;

		private static TextMeshProUGUI _title;

		private static TextMeshProUGUI _summary;

		private static TextMeshProUGUI _note;

		private static TextMeshProUGUI _moons;

		private static readonly Dictionary<Difficulty, Button> PresetButtons = new Dictionary<Difficulty, Button>();

		private static readonly List<Action<SlotSetup>> RowUpdates = new List<Action<SlotSetup>>();

		private static SlotSetup Current => GameSetup.ForSlot(((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.saveFileNum : (-1));

		internal static void Build(MenuManager menu)
		{
			if (!((Object)(object)menu.HostSettingsScreen == (Object)null) && !((Object)(object)menu.lobbyNameInputField == (Object)null))
			{
				PresetButtons.Clear();
				RowUpdates.Clear();
				_font = menu.lobbyNameInputField.textComponent.font;
				BuildBar(menu.HostSettingsScreen.transform);
				BuildWindow(menu.HostSettingsScreen.transform);
				Close();
			}
		}

		internal static void Open()
		{
			if ((Object)(object)_window == (Object)null || Current == null)
			{
				Close();
				return;
			}
			_window.SetActive(true);
			_window.transform.SetAsLastSibling();
			Refresh();
		}

		internal static void Close()
		{
			if ((Object)(object)_window != (Object)null)
			{
				_window.SetActive(false);
			}
			Refresh();
		}

		private static void Refresh()
		{
			if ((Object)(object)_bar == (Object)null)
			{
				return;
			}
			SlotSetup current = Current;
			_bar.SetActive(current != null);
			if (current == null)
			{
				return;
			}
			int num = GameNetworkManager.Instance.saveFileNum + 1;
			((TMP_Text)_summary).text = $"FILE {num} RULES: {current.Preset.Value.ToString().ToUpperInvariant()}   ${current.Credits.Value}   Quota ${current.Quota.Value}   {current.DaysPerQuota.Value} days   Day {DayLengthText(current.DayLengthPercent.Value)}";
			((TMP_Text)_title).text = $"GAME RULES: FILE {num}";
			foreach (KeyValuePair<Difficulty, Button> presetButton in PresetButtons)
			{
				Paint(presetButton.Value, presetButton.Key == current.Preset.Value);
			}
			foreach (Action<SlotSetup> rowUpdate in RowUpdates)
			{
				rowUpdate(current);
			}
			((TMP_Text)_moons).text = (Chainloader.PluginInfos.ContainsKey("imabatby.lethallevelloader") ? RouteDetails.MoonClocks(current.DayLengthPercent.Value) : "");
			bool flag = File.Exists(Path.Combine(Application.persistentDataPath, GameNetworkManager.Instance.currentSaveFileName));
			((TMP_Text)_note).text = (flag ? "THIS SAVE HAS STARTED. Day length, scrap and enemies apply right away, and quota growth and days from its next quota. Starting credits and quota only apply if the crew gets fired." : "NEW SAVE. All of these apply when you host it. You can change them again each time you host.");
		}

		private static void BuildBar(Transform parent)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_00bc: 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)
			_bar = NewObject("BaconFixer Rules Bar", parent);
			RectTransform val = (RectTransform)_bar.transform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(1f, 0f);
			val.pivot = val2;
			Vector2 anchorMin = (val.anchorMax = val2);
			val.anchorMin = anchorMin;
			val.anchoredPosition = new Vector2(-36f, 6f);
			MakeFrame(_bar);
			HorizontalLayoutGroup obj = _bar.AddComponent<HorizontalLayoutGroup>();
			((LayoutGroup)obj).padding = new RectOffset(8, 6, 4, 4);
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 10f;
			((LayoutGroup)obj).childAlignment = (TextAnchor)3;
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = childControlWidth;
			childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false);
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = childControlWidth;
			ContentSizeFitter obj2 = _bar.AddComponent<ContentSizeFitter>();
			FitMode horizontalFit = (FitMode)2;
			obj2.verticalFit = (FitMode)2;
			obj2.horizontalFit = horizontalFit;
			_summary = NewText(_bar.transform, "", 8f, Orange);
			NewButton(_bar.transform, "EDIT RULES", 66f, Open);
		}

		private static void BuildWindow(Transform parent)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_002a: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00f7: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_054f: Unknown result type (might be due to invalid IL or missing references)
			_window = NewObject("BaconFixer Game Rules", parent);
			RectTransform val = (RectTransform)_window.transform;
			val.anchorMin = Vector2.zero;
			val.anchorMax = Vector2.one;
			val.offsetMin = new Vector2(-100f, -100f);
			val.offsetMax = new Vector2(100f, 100f);
			((Graphic)_window.AddComponent<Image>()).color = Shade;
			GameObject val2 = NewObject("Window", _window.transform);
			RectTransform val3 = (RectTransform)val2.transform;
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(0.5f, 0.5f);
			val3.pivot = val4;
			Vector2 anchorMin = (val3.anchorMax = val4);
			val3.anchorMin = anchorMin;
			val3.sizeDelta = new Vector2(730f, 0f);
			MakeFrame(val2);
			VerticalLayoutGroup val6 = NewVertical(val2, 7f);
			((LayoutGroup)val6).padding = new RectOffset(14, 14, 10, 10);
			val2.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			Transform parent2 = NewRow(val2.transform, 4f);
			_title = NewText(parent2, "GAME RULES", 13f, Orange);
			((Component)_title).gameObject.AddComponent<LayoutElement>().flexibleWidth = 1f;
			foreach (Difficulty value in Enum.GetValues(typeof(Difficulty)))
			{
				Difficulty choice = value;
				PresetButtons[value] = NewButton(parent2, value.ToString().ToUpperInvariant(), 62f, delegate
				{
					Current?.Choose(choice);
					Refresh();
				});
			}
			Transform obj = NewRow(val2.transform, 18f);
			((LayoutGroup)((Component)obj).GetComponent<HorizontalLayoutGroup>()).childAlignment = (TextAnchor)0;
			float width = 730f - (float)((LayoutGroup)val6).padding.horizontal - 18f - 400f;
			Transform parent3 = NewColumn(obj, 400f, 4f);
			Transform parent4 = NewColumn(obj, width, 5f);
			AddRule(parent3, "Starting credits", "Credits a new save starts with.", (SlotSetup setup) => setup.Credits, 20, 0, 100000, (int value) => $"${value}");
			AddRule(parent3, "Starting quota", "The first quota on a new save.", (SlotSetup setup) => setup.Quota, 20, 20, 100000, (int value) => $"${value}");
			AddRule(parent3, "Quota growth", "How fast the quota rises after each deadline.", (SlotSetup setup) => setup.GrowthPercent, 5, 25, 500, (int value) => $"{value}%");
			AddRule(parent3, "Days per quota", "Days you get to reach each quota before the deadline.", (SlotSetup setup) => setup.DaysPerQuota, 1, 1, 10, (int value) => value.ToString());
			AddRule(parent3, "Day length", "How long each day lasts in real time. See how time works.", (SlotSetup setup) => setup.DayLengthPercent, 10, -50, 200, DayLengthText);
			AddRule(parent3, "Scrap amount", "How much scrap spawns, on top of weather bonuses.", (SlotSetup setup) => setup.ScrapAmountPercent, 10, 10, 500, (int value) => $"{value}%");
			AddRule(parent3, "Scrap value", "What scrap sells for, on top of weather bonuses.", (SlotSetup setup) => setup.ScrapValuePercent, 10, 10, 500, (int value) => $"{value}%");
			AddRule(parent3, "Enemies", "How many enemies a moon can hold at once.", (SlotSetup setup) => setup.EnemyPercent, 25, 25, 400, (int value) => $"{value}%");
			NewText(parent4, "HOW TIME WORKS", 10f, Orange);
			NewWrappedText(parent4, "A normal day is " + Minutes(0) + " minutes from landing to midnight at +0%. Day length makes the clock run slower or faster, and the ship still leaves at the same clock time.");
			NewWrappedText(parent4, "Scrap doesn't change, and enemies still arrive by clock time. So a longer day is more real time to loot, not more enemies, and a shorter day is the opposite.");
			NewText(parent4, "MOONS WITH THEIR OWN CLOCK", 10f, Orange);
			_moons = NewWrappedText(parent4, "");
			NewText(parent4, "THIS SAVE", 10f, Orange);
			_note = NewWrappedText(parent4, "");
			Transform val7 = NewRow(val2.transform, 4f);
			((LayoutGroup)((Component)val7).GetComponent<HorizontalLayoutGroup>()).childAlignment = (TextAnchor)5;
			NewObject("Space", val7).AddComponent<LayoutElement>().flexibleWidth = 1f;
			NewButton(val7, "DONE", 80f, Close);
		}

		private static string DayLengthText(int percent)
		{
			return $"{percent:+0;-0;+0}% ({Minutes(percent)} min)";
		}

		private static string Minutes(int percent)
		{
			return ((float)(700 * (100 + percent)) / 100f / 60f).ToString("0.#", CultureInfo.InvariantCulture);
		}

		private static void AddRule(Transform parent, string label, string description, Func<SlotSetup, ConfigEntry<int>> entry, int step, int min, int max, Func<int, string> format)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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)
			GameObject obj = NewObject("Rule", parent);
			NewVertical(obj, 0f);
			Transform parent2 = NewRow(obj.transform, 3f);
			((Component)NewText(parent2, label, 9f, Orange)).gameObject.AddComponent<LayoutElement>().flexibleWidth = 1f;
			NewButton(parent2, "-", 15f, delegate
			{
				Change(-1);
			});
			TextMeshProUGUI value = NewText(parent2, "", 9f, Orange);
			((TMP_Text)value).alignment = (TextAlignmentOptions)514;
			LayoutElement obj2 = ((Component)value).gameObject.AddComponent<LayoutElement>();
			float preferredWidth = (obj2.minWidth = 78f);
			obj2.preferredWidth = preferredWidth;
			NewButton(parent2, "+", 15f, delegate
			{
				Change(1);
			});
			RowUpdates.Add(delegate(SlotSetup setup)
			{
				((TMP_Text)value).text = format(entry(setup).Value);
			});
			NewText(obj.transform, description, 7.5f, Dim);
			void Change(int direction)
			{
				SlotSetup current = Current;
				if (current != null)
				{
					entry(current).Value = Mathf.Clamp(entry(current).Value + direction * step, min, max);
					current.Preset.Value = Difficulty.Custom;
					Refresh();
				}
			}
		}

		private static GameObject NewObject(string name, Transform parent)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0038: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) })
			{
				layer = ((Component)parent).gameObject.layer
			};
			val.transform.SetParent(parent, false);
			return val;
		}

		private static void MakeFrame(GameObject target)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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)
			((Graphic)target.AddComponent<Image>()).color = Fill;
			Outline obj = target.AddComponent<Outline>();
			((Shadow)obj).effectColor = Border;
			((Shadow)obj).effectDistance = new Vector2(1f, -1f);
		}

		private static VerticalLayoutGroup NewVertical(GameObject target, float spacing)
		{
			VerticalLayoutGroup obj = target.AddComponent<VerticalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = spacing;
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = childControlWidth;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
			return obj;
		}

		private static Transform NewColumn(Transform parent, float width, float spacing)
		{
			GameObject obj = NewObject("Column", parent);
			NewVertical(obj, spacing);
			LayoutElement obj2 = obj.AddComponent<LayoutElement>();
			float preferredWidth = (obj2.minWidth = width);
			obj2.preferredWidth = preferredWidth;
			return obj.transform;
		}

		private static Transform NewRow(Transform parent, float spacing)
		{
			GameObject obj = NewObject("Row", parent);
			HorizontalLayoutGroup obj2 = obj.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj2).spacing = spacing;
			((LayoutGroup)obj2).childAlignment = (TextAnchor)3;
			bool childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = true);
			((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = childControlWidth;
			childControlWidth = (((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false);
			((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = childControlWidth;
			return obj.transform;
		}

		private static TextMeshProUGUI NewText(Transform parent, string text, float size, Color color)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = NewObject("Text", parent).AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).font = _font;
			((TMP_Text)obj).fontSize = size;
			((Graphic)obj).color = color;
			((TMP_Text)obj).text = text;
			((Graphic)obj).raycastTarget = false;
			((TMP_Text)obj).enableWordWrapping = false;
			return obj;
		}

		private static TextMeshProUGUI NewWrappedText(Transform parent, string text)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = NewText(parent, text, 7.5f, Dim);
			((TMP_Text)obj).enableWordWrapping = true;
			return obj;
		}

		private static Button NewButton(Transform parent, string text, float width, Action onClick)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = NewObject("Button", parent);
			Button obj = val.AddComponent<Button>();
			((Selectable)obj).targetGraphic = (Graphic)(object)val.AddComponent<Image>();
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				onClick();
			});
			LayoutElement obj2 = val.AddComponent<LayoutElement>();
			float preferredHeight = (obj2.minHeight = 14f);
			obj2.preferredHeight = preferredHeight;
			preferredHeight = (obj2.minWidth = width);
			obj2.preferredWidth = preferredHeight;
			TextMeshProUGUI obj3 = NewText(val.transform, text, 9f, Orange);
			((TMP_Text)obj3).alignment = (TextAlignmentOptions)514;
			RectTransform val2 = (RectTransform)((TMP_Text)obj3).transform;
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			Vector2 offsetMin = (val2.offsetMax = Vector2.zero);
			val2.offsetMin = offsetMin;
			Paint(obj, selected: false);
			return obj;
		}

		private static void Paint(Button button, bool selected)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0024: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			ColorBlock colors = ((Selectable)button).colors;
			((ColorBlock)(ref colors)).normalColor = (selected ? Orange : ButtonOff);
			Color highlightedColor = (((ColorBlock)(ref colors)).selectedColor = (selected ? Orange : ButtonHover));
			((ColorBlock)(ref colors)).highlightedColor = highlightedColor;
			((ColorBlock)(ref colors)).pressedColor = Orange;
			((ColorBlock)(ref colors)).colorMultiplier = 1f;
			((Selectable)button).colors = colors;
			((Graphic)((Component)button).GetComponentInChildren<TextMeshProUGUI>()).color = (selected ? Fill : Orange);
		}
	}
	internal static class ImmersiveEntranceFix
	{
		private delegate bool TryGetViewBlocker(Transform parent, out Transform result);

		private const string ImmersiveEntrance = "com.github.zehsteam.ImmersiveEntrance";

		private const int LastVanillaLevelId = 12;

		private const float MaxPlaneDistance = 5f;

		private const float MaxDoorSize = 6f;

		private const string MuseumDoorPart = "WallDoor";

		private static TryGetViewBlocker _tryGetViewBlocker;

		internal static void Apply(Harmony h)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			if (Chainloader.PluginInfos.TryGetValue("com.github.zehsteam.ImmersiveEntrance", out var value) && value.Instance != null)
			{
				Assembly assembly = ((object)value.Instance).GetType().Assembly;
				Type type = assembly.GetType("com.github.zehsteam.ImmersiveEntrance.Helpers.EntranceObjectsHelper", throwOnError: false);
				Type? type2 = assembly.GetType("com.github.zehsteam.ImmersiveEntrance.MonoBehaviours.DoorPortal", throwOnError: false);
				MethodInfo methodInfo = AccessTools.Method(type, "GetViewBlocker", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(type, "TryGetViewBlockerFromParent", (Type[])null, (Type[])null);
				MethodInfo methodInfo3 = AccessTools.Method(type2, "SetDynamicPivot", (Type[])null, (Type[])null);
				if (methodInfo == null || methodInfo2 == null || methodInfo3 == null)
				{
					Plugin.Log.LogWarning((object)"ImmersiveEntranceFix: ImmersiveEntrance's layout changed, skipping");
					return;
				}
				_tryGetViewBlocker = AccessTools.MethodDelegate<TryGetViewBlocker>(methodInfo2, (object)null, true);
				h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(ImmersiveEntranceFix), "FindPlaneBesideDoors", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				h.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(ImmersiveEntranceFix), "FitScreenToDoor", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Plugin.Log.LogInfo((object)"ImmersiveEntranceFix: door portals work on modded moons and interiors");
			}
		}

		private static void FindPlaneBesideDoors(Transform visualDoorsContainer, ref GameObject __result)
		{
			//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)
			Transform result;
			if ((Object)(object)visualDoorsContainer.Find("WallDoor") != (Object)null)
			{
				__result = null;
			}
			else if ((!((Object)(object)__result != (Object)null) || !(Vector3.Distance(__result.transform.position, visualDoorsContainer.position) < 5f)) && (Object)(object)visualDoorsContainer.parent != (Object)null && _tryGetViewBlocker(visualDoorsContainer.parent, out result))
			{
				__result = ((Component)result).gameObject;
			}
		}

		private static bool FitScreenToDoor(Component __instance, Transform ____pivot, MeshRenderer ____screen)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: 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_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: 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_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)__instance);
			Traverse val2 = val.Property("MainEntrance", (object[])null);
			Traverse val3 = val2.Property("EntranceObjects", (object[])null);
			bool value = val3.Field("IsOutside").GetValue<bool>();
			if (value && StartOfRound.Instance.currentLevel.levelID <= 12)
			{
				return true;
			}
			if (val.Property("PortalSettings", (object[])null).Property("PivotPositionOffset", (object[])null).GetValue<Vector3>() != Vector3.zero)
			{
				return true;
			}
			Transform transform = val3.Field("DoorLeft").GetValue<GameObject>().transform;
			Transform transform2 = val3.Field("DoorRight").GetValue<GameObject>().transform;
			MeshFilter[] array = (from filter in ((IEnumerable<Transform>)(object)new Transform[2] { transform, transform2 }).SelectMany((Transform leaf) => ((Component)leaf).GetComponentsInChildren<MeshFilter>())
				where ((Object)filter).name.StartsWith("DoorMesh") && (Object)(object)filter.sharedMesh != (Object)null
				select filter).ToArray();
			if (array.Length == 0)
			{
				return true;
			}
			Vector3 val4 = (transform.position + transform2.position) / 2f;
			Vector3 val5 = transform2.position - transform.position;
			Vector3 normalized = ((Vector3)(ref val5)).normalized;
			val5 = Vector3.ProjectOnPlane(MostUprightAxis(((Component)array[0]).transform), normalized);
			Vector3 normalized2 = ((Vector3)(ref val5)).normalized;
			Rect val6 = Measure(array, val4, normalized, normalized2);
			if (((Rect)(ref val6)).width <= 0f || ((Rect)(ref val6)).width > 6f || ((Rect)(ref val6)).height <= 0f || ((Rect)(ref val6)).height > 6f)
			{
				return true;
			}
			Vector3 val7 = Vector3.Cross(normalized, normalized2);
			if (Vector3.Dot(val2.Property("EntranceTeleport", (object[])null).GetValue<EntranceTeleport>().entrancePoint.position - val4, val7) > 0f)
			{
				val7 = -val7;
			}
			Transform transform3 = val3.Field("ViewBlocker").GetValue<GameObject>().transform;
			float num = Vector3.Dot(transform3.position - val4, val7);
			Vector3 val8 = val4 + normalized * ((Rect)(ref val6)).center.x + normalized2 * ((Rect)(ref val6)).center.y + val7 * num;
			____pivot.SetPositionAndRotation(val8, Quaternion.LookRotation(val7, normalized2));
			Vector3 lossyScale = ((Component)____screen).transform.lossyScale;
			float num2 = Mathf.Max(new float[3]
			{
				1f,
				((Rect)(ref val6)).width / lossyScale.x,
				((Rect)(ref val6)).height / lossyScale.y
			});
			Transform transform4 = ((Component)____screen).transform;
			transform4.localScale *= num2;
			lossyScale *= num2;
			float num3 = CropFor(lossyScale.x, ((Rect)(ref val6)).width);
			float num4 = CropFor(lossyScale.y, ((Rect)(ref val6)).height);
			val.Method("SetScreenCrop", new object[4] { num3, num3, num4, num4 }).GetValue();
			Plugin.Log.LogDebug((object)(string.Format("ImmersiveEntranceFix: {0} door {1:0.00} x {2:0.00} m, ", value ? "outside" : "inside", ((Rect)(ref val6)).width, ((Rect)(ref val6)).height) + $"leaning {Vector3.Angle(normalized2, Vector3.up):0.0} degrees, screen behind the hinges by {num:0.000} m at {((Object)transform3).name}, screen size {lossyScale.x:0.00}"));
			return false;
		}

		private static Vector3 MostUprightAxis(Transform slab)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (from world in ((IEnumerable<Vector3>)(object)new Vector3[3]
				{
					Vector3.right,
					Vector3.up,
					Vector3.forward
				}).Select(delegate(Vector3 local)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_000f: Unknown result type (might be due to invalid IL or missing references)
					Vector3 val2 = slab.TransformVector(local);
					return ((Vector3)(ref val2)).normalized;
				})
				orderby Mathf.Abs(world.y) descending
				select world).First();
			if (!(val.y < 0f))
			{
				return val;
			}
			return -val;
		}

		private static float CropFor(float screen, float door)
		{
			return Mathf.Max(0f, (screen - door) / 2f / screen);
		}

		private static Rect Measure(MeshFilter[] slabs, Vector3 hinges, Vector3 across, Vector3 up)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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)
			float num = float.MaxValue;
			float num2 = float.MinValue;
			float num3 = float.MaxValue;
			float num4 = float.MinValue;
			Vector3 val2 = default(Vector3);
			foreach (MeshFilter val in slabs)
			{
				Bounds bounds = val.sharedMesh.bounds;
				for (int j = 0; j < 8; j++)
				{
					((Vector3)(ref val2))..ctor((float)((j & 1) * 2 - 1), (float)((j & 2) - 1), (float)((j & 4) / 2 - 1));
					Vector3 val3 = ((Component)val).transform.TransformPoint(((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, val2)) - hinges;
					float num5 = Vector3.Dot(val3, across);
					float num6 = Vector3.Dot(val3, up);
					num = Mathf.Min(num, num5);
					num2 = Mathf.Max(num2, num5);
					num3 = Mathf.Min(num3, num6);
					num4 = Mathf.Max(num4, num6);
				}
			}
			return Rect.MinMaxRect(num, num3, num2, num4);
		}
	}
	internal static class ModDataFix
	{
		private static MethodInfo _registerOne;

		internal static void Apply(Harmony h)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			Type type = null;
			if (Chainloader.PluginInfos.TryGetValue("MaxWasUnavailable.LethalModDataLib", out var value) && value.Instance != null)
			{
				type = ((object)value.Instance).GetType().Assembly.GetType("LethalModDataLib.Features.ModDataAttributeCollector", throwOnError: false);
			}
			if (!(type == null))
			{
				MethodInfo methodInfo = AccessTools.Method(type, "RegisterModDataAttributes", Type.EmptyTypes, (Type[])null);
				_registerOne = AccessTools.Method(type, "RegisterModDataAttributes", new Type[4]
				{
					typeof(string),
					typeof(Type),
					typeof(object),
					typeof(string)
				}, (Type[])null);
				if (methodInfo == null || _registerOne == null)
				{
					Plugin.Log.LogWarning((object)"ModDataFix: LethalModDataLib layout changed, skipping");
					return;
				}
				h.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(ModDataFix), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Plugin.Log.LogInfo((object)"ModDataFix: patched LethalModDataLib attribute registration");
			}
		}

		private static bool Prefix()
		{
			int num = 0;
			int num2 = 0;
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				object obj = ((value != null) ? value.Instance : null);
				if (obj == null)
				{
					num2++;
					continue;
				}
				IEnumerable<Type> enumerable;
				try
				{
					enumerable = obj.GetType().Assembly.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					enumerable = ex.Types.Where((Type t) => t != null);
				}
				catch
				{
					num2++;
					continue;
				}
				foreach (Type item in enumerable)
				{
					try
					{
						_registerOne.Invoke(null, new object[4]
						{
							value.Metadata.GUID,
							item,
							null,
							null
						});
					}
					catch
					{
					}
				}
				num++;
			}
			Plugin.Log.LogInfo((object)$"ModDataFix: scanned {num} plugin(s), skipped {num2} that failed to load");
			return false;
		}
	}
	[HarmonyPatch(typeof(EnemyAI), "DoAIInterval")]
	internal static class OffNavMeshLogFix
	{
		private static readonly HashSet<string> Reported = new HashSet<string>();

		[HarmonyPrefix]
		private static void Prefix(EnemyAI __instance, out bool __state)
		{
			NavMeshAgent agent = __instance.agent;
			__state = __instance.moveTowardsDestination && (Object)(object)agent != (Object)null && ((Behaviour)agent).enabled && !agent.isOnNavMesh;
			if (__state)
			{
				__instance.moveTowardsDestination = false;
				string text = (((Object)(object)__instance.enemyType != (Object)null) ? __instance.enemyType.enemyName : ((Object)__instance).name);
				if (Reported.Add(text))
				{
					Plugin.Log.LogInfo((object)("OffNavMeshLogFix: '" + text + "' is off the nav mesh, so it can't path until it's back on."));
				}
			}
		}

		[HarmonyFinalizer]
		private static void Finalizer(EnemyAI __instance, bool __state)
		{
			if (__state)
			{
				__instance.moveTowardsDestination = true;
			}
		}
	}
	[BepInPlugin("baconfixer", "BaconFixer", "1.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal const string Guid = "baconfixer";

		internal const string Version = "1.2.0";

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony h = new Harmony("baconfixer");
			Apply("TypeByNameFix", delegate
			{
				TypeByNameFix.Apply(h);
			});
			Apply("StorePriceFix", delegate
			{
				h.PatchAll(typeof(StorePriceFix));
			});
			Apply("ModDataFix", delegate
			{
				ModDataFix.Apply(h);
			});
			Apply("WeatherMultiplierDisplay", delegate
			{
				WeatherMultiplierDisplay.Apply(h);
			});
			Apply("DuplicatePrefabFix", delegate
			{
				h.PatchAll(typeof(DuplicatePrefabFix));
			});
			Apply("DestroyedLightsFix", delegate
			{
				DestroyedLightsFix.Apply(h);
			});
			Apply("SoftDependencyFix", SoftDependencyFix.Apply);
			Apply("ChameleonSupport", delegate
			{
				ChameleonSupport.Apply(h);
			});
			Apply("SortBonus", delegate
			{
				ApplySortBonus(h);
			});
			Apply("OffNavMeshLogFix", delegate
			{
				h.PatchAll(typeof(OffNavMeshLogFix));
			});
			Apply("TerminalHelp", delegate
			{
				h.PatchAll(typeof(TerminalHelp));
			});
			Apply("GameSetup", delegate
			{
				GameSetup.Apply(h);
			});
			Apply("TerminalQuality", delegate
			{
				TerminalQuality.Apply(h, ((BaseUnityPlugin)this).Config);
			});
			Apply("FacilityMeltdownFix", delegate
			{
				FacilityMeltdownFix.Apply(h);
			});
			Apply("DestroyItemFix", delegate
			{
				DestroyItemFix.Apply(h);
			});
			Apply("ImmersiveEntranceFix", delegate
			{
				ImmersiveEntranceFix.Apply(h);
			});
			Log.LogInfo((object)"BaconFixer 1.2.0 loaded");
		}

		private static void ApplySortBonus(Harmony h)
		{
			if (Chainloader.PluginInfos.ContainsKey("mrov.TerminalUtils") && Chainloader.PluginInfos.ContainsKey("mrov.WeatherRegistry"))
			{
				PatchSortBonus(h);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void PatchSortBonus(Harmony h)
		{
			SortBonus.Apply(h);
		}

		private static void Apply(string name, Action fix)
		{
			try
			{
				fix();
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)(name + " failed: " + ex.Message));
			}
		}
	}
	internal static class RouteDetails
	{
		private const float ScrapValueScale = 0.4f;

		private const int MinInteriorPercent = 1;

		private const string CompanyLevel = "CompanyBuildingLevel";

		private const string GaletryLevel = "GaletryLevel";

		private const string CompanyHeader = "The Company // Buying at";

		private const string CompanyAndGaletryHeader = "The Company and Galetry // Buying at";

		internal static string Selling(SelectableLevel level)
		{
			if (((Object)level).name != "CompanyBuildingLevel" && ((Object)level).name != "GaletryLevel")
			{
				return null;
			}
			return $"SELLS SCRAP: buying at {Mathf.RoundToInt(StartOfRound.Instance.companyBuyingRate * 100f)}%";
		}

		internal static string NameSellingMoons(string text)
		{
			if (!StartOfRound.Instance.levels.Any((SelectableLevel level) => (Object)(object)level != (Object)null && ((Object)level).name == "GaletryLevel"))
			{
				return text;
			}
			return text.Replace("The Company // Buying at", "The Company and Galetry // Buying at");
		}

		internal static string Loot(SelectableLevel level, float valueBonus, float amountBonus)
		{
			if (level.spawnableScrap == null || level.maxScrap <= 0)
			{
				return null;
			}
			float num = 0f;
			float num2 = 0f;
			foreach (SpawnableItemWithRarity item in level.spawnableScrap)
			{
				if (!((Object)(object)item?.spawnableItem == (Object)null) && item.rarity > 0)
				{
					num += (float)item.rarity;
					num2 += (float)(item.rarity * (item.spawnableItem.minValue + item.spawnableItem.maxValue)) / 2f;
				}
			}
			if (num <= 0f)
			{
				return null;
			}
			float num3 = (float)(level.minScrap + level.maxScrap) / 2f * amountBonus;
			int num4 = Mathf.RoundToInt(num3 * (num2 / num) * 0.4f * valueBonus / 10f) * 10;
			return $"LOOT: about ${num4} ({Mathf.RoundToInt(num3)} items)";
		}

		internal static string Interiors(SelectableLevel level)
		{
			ExtendedLevel val = default(ExtendedLevel);
			if (!LevelManager.TryGetExtendedLevel(level, ref val, (ContentType)2))
			{
				return null;
			}
			List<ExtendedDungeonFlowWithRarity> validExtendedDungeonFlows = DungeonManager.GetValidExtendedDungeonFlows(val, false);
			long num = ((IEnumerable<ExtendedDungeonFlowWithRarity>)validExtendedDungeonFlows).Sum((Func<ExtendedDungeonFlowWithRarity, long>)((ExtendedDungeonFlowWithRarity flow) => flow.rarity));
			if (num <= 0)
			{
				return null;
			}
			List<string> list = new List<string>();
			int num2 = 100;
			foreach (ExtendedDungeonFlowWithRarity item in validExtendedDungeonFlows.OrderByDescending((ExtendedDungeonFlowWithRarity flow) => flow.rarity))
			{
				int num3 = (int)Math.Round(100.0 * (double)item.rarity / (double)num);
				if (num3 < 1)
				{
					break;
				}
				list.Add($"{item.extendedDungeonFlow.DungeonName.Trim()} {num3}%");
				num2 -= num3;
			}
			if (num2 > 0)
			{
				list.Add($"others {num2}%");
			}
			return "INTERIOR: " + string.Join(", ", list);
		}

		internal static string DayLength(SelectableLevel level)
		{
			TimeOfDay instance = TimeOfDay.Instance;
			if ((Object)(object)instance == (Object)null || level.DaySpeedMultiplier <= 0f || instance.globalTimeSpeedMultiplier <= 0f)
			{
				return null;
			}
			if (!level.planetHasTime)
			{
				return "DAY LENGTH: no clock here";
			}
			return "DAY LENGTH: " + ((instance.totalTime - 100f - level.OffsetFromGlobalTime) / level.DaySpeedMultiplier / instance.globalTimeSpeedMultiplier / 60f).ToString("0.#", CultureInfo.InvariantCulture) + " min";
		}

		internal static string MoonClocks(int dayLengthPercent)
		{
			List<string> list = (from level in PatchedContent.ExtendedLevels
				where (Object)(object)level.SelectableLevel != (Object)null && level.SelectableLevel.planetHasTime && level.SelectableLevel.DaySpeedMultiplier > 0f && !Mathf.Approximately(level.SelectableLevel.DaySpeedMultiplier, 1f)
				orderby level.SelectableLevel.DaySpeedMultiplier
				select level).Select(delegate(ExtendedLevel level)
			{
				float num = (float)(700 * (100 + dayLengthPercent)) / 100f / level.SelectableLevel.DaySpeedMultiplier / 60f;
				return level.NumberlessPlanetName + " " + num.ToString("0.#", CultureInfo.InvariantCulture) + " min";
			}).ToList();
			if (list.Count != 0)
			{
				return "These run at a different speed, shown here at this day length: " + string.Join(", ", list) + ".";
			}
			return "Every moon runs at normal speed.";
		}
	}
	internal static class SoftDependencyFix
	{
		internal static void Apply()
		{
			if (!Chainloader.PluginInfos.TryGetValue("me.loaforc.soundapi", out var value) || value.Instance == null)
			{
				return;
			}
			Type type = ((object)value.Instance).GetType().Assembly.GetType("loaforcsSoundAPI.SoundPacks.SoundPackLoadPipeline", throwOnError: false);
			if (!(((type == null) ? null : AccessTools.Field(type, "mappings"))?.GetValue(null) is Dictionary<string, List<string>> dictionary))
			{
				Plugin.Log.LogWarning((object)"SoftDependencyFix: SoundAPI layout changed, skipping");
				return;
			}
			string[] array = new string[2] { "FacilityMeltdown:warning_voice", "FacilityMeltdown:music" };
			foreach (string key in array)
			{
				if (!dictionary.ContainsKey(key))
				{
					dictionary[key] = new List<string>();
				}
			}
		}
	}
	internal sealed class SortBonus : SortInfoType<SelectableLevel>
	{
		private SortBonus()
			: base("Bonus")
		{
		}

		public override List<SelectableLevel> Sort(List<SelectableLevel> inputList)
		{
			return inputList.OrderByDescending(Score).ToList();
		}

		private static float Score(SelectableLevel level)
		{
			Weather val = WeatherMultiplierDisplay.Current(level);
			if (val != null)
			{
				return val.ScrapValueMultiplier * val.ScrapAmountMultiplier;
			}
			return 1f;
		}

		internal static void Apply(Harmony h)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(TerminalManager), "RegisterLocalInfoTypes", (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				Plugin.Log.LogWarning((object)"SortBonus: TerminalUtils layout changed, skipping");
			}
			else
			{
				h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(SortBonus), "Register", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static void Register()
		{
			TerminalManager.SortInfoTypes["Bonus"] = new SortBonus();
		}
	}
	internal static class StorePriceFix
	{
		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static void FixPrice(BuyableUnlockable __instance)
		{
			if (((BuyableThing)__instance).Price > 0)
			{
				return;
			}
			int num = 0;
			RelatedNodes nodes = ((BuyableThing)__instance).Nodes;
			if (nodes != null)
			{
				if ((Object)(object)nodes.Node != (Object)null)
				{
					num = Mathf.Max(num, nodes.Node.itemCost);
				}
				if ((Object)(object)nodes.NodeConfirm != (Object)null)
				{
					num = Mathf.Max(num, nodes.NodeConfirm.itemCost);
				}
			}
			UnlockableItem unlockable = __instance.Unlockable;
			if (unlockable != null && (Object)(object)unlockable.shopSelectionNode != (Object)null)
			{
				num = Mathf.Max(num, unlockable.shopSelectionNode.itemCost);
			}
			if (num <= 0)
			{
				Terminal val = Object.FindObjectOfType<Terminal>();
				int num2 = (((Object)(object)nodes?.Node != (Object)null) ? nodes.Node.shipUnlockableID : (-1));
				if ((Object)(object)val != (Object)null && num2 >= 0)
				{
					TerminalKeyword[] allKeywords = val.terminalNodes.allKeywords;
					foreach (TerminalKeyword val2 in allKeywords)
					{
						if (val2?.compatibleNouns == null)
						{
							continue;
						}
						CompatibleNoun[] compatibleNouns = val2.compatibleNouns;
						foreach (CompatibleNoun val3 in compatibleNouns)
						{
							if ((Object)(object)val3?.result != (Object)null && val3.result.shipUnlockableID == num2)
							{
								num = Mathf.Max(num, val3.result.itemCost);
							}
						}
					}
				}
			}
			if (num > 0)
			{
				AccessTools.Property(typeof(BuyableThing), "Price").SetValue(__instance, num);
				Plugin.Log.LogInfo((object)$"Fixed store price for '{((BuyableThing)__instance).Name}': ${num}");
			}
		}
	}
	[HarmonyPatch(typeof(Terminal), "Start")]
	internal static class TerminalHelp
	{
		private const string Marker = "SORT BONUS";

		private const string Text = ">SORT BONUS\nTo list moons with the best weather bonus first. SORT NONE puts the order back.\n\n>MOON NAME\nTo see a moon's weather bonus, likely loot and interiors, day length and dangers. Then CONFIRM or DENY.";

		[HarmonyPostfix]
		private static void AddToOtherPage(Terminal __instance)
		{
			TerminalKeyword[] allKeywords = __instance.terminalNodes.allKeywords;
			foreach (TerminalKeyword val in allKeywords)
			{
				if (!((Object)(object)val == (Object)null) && string.Equals(val.word, "other", StringComparison.OrdinalIgnoreCase))
				{
					TerminalNode specialKeywordResult = val.specialKeywordResult;
					if ((Object)(object)specialKeywordResult != (Object)null && !specialKeywordResult.displayText.Contains("SORT BONUS"))
					{
						specialKeywordResult.displayText = specialKeywordResult.displayText.TrimEnd() + "\n\n>SORT BONUS\nTo list moons with the best weather bonus first. SORT NONE puts the order back.\n\n>MOON NAME\nTo see a moon's weather bonus, likely loot and interiors, day length and dangers. Then CONFIRM or DENY.\n\n";
					}
					break;
				}
			}
		}
	}
	internal enum TerminalQualityLevel
	{
		Normal,
		High,
		Max
	}
	internal static class TerminalQuality
	{
		private const string Caption = "Terminal quality:";

		private const float HighScale = 1.5f;

		private const float RowBelowMotionBlur = -145f;

		private static ConfigEntry<TerminalQualityLevel> _level;

		private static int _normalWidth;

		private static int _normalHeight;

		internal static void Apply(Harmony h, ConfigFile config)
		{
			_level = config.Bind<TerminalQualityLevel>("Terminal", "Quality", TerminalQualityLevel.Normal, "How sharp the terminal is drawn. Normal is the game's own size, High is 1.5 times that, and Max matches your screen's height. Higher costs more frames while the terminal is open. It's also in the game's Settings menu.");
			h.PatchAll(typeof(TerminalQuality));
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Terminal), "BeginUsingTerminal")]
		private static void Sharpen(Terminal __instance)
		{
			RenderTexture playerScreenTexHighRes = __instance.playerScreenTexHighRes;
			if (_normalHeight == 0)
			{
				_normalWidth = ((Texture)playerScreenTexHighRes).width;
				_normalHeight = ((Texture)playerScreenTexHighRes).height;
			}
			SetSize(playerScreenTexHighRes, ChosenScale());
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Terminal), "QuitTerminal")]
		private static void PutBackOnQuit(Terminal __instance)
		{
			PutBack(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Terminal), "Start")]
		private static void PutBackOnStart(Terminal __instance)
		{
			PutBack(__instance);
		}

		private static void PutBack(Terminal terminal)
		{
			if (_normalHeight != 0)
			{
				SetSize(terminal.playerScreenTexHighRes, 1f);
			}
		}

		private static float ChosenScale()
		{
			float num = Mathf.Max(1f, (float)Screen.height / (float)_normalHeight);
			return _level.Value switch
			{
				TerminalQualityLevel.High => Mathf.Min(1.5f, num), 
				TerminalQualityLevel.Max => num, 
				_ => 1f, 
			};
		}

		private static void SetSize(RenderTexture texture, float scale)
		{
			int num = Mathf.RoundToInt((float)_normalWidth * scale);
			int num2 = Mathf.RoundToInt((float)_normalHeight * scale);
			if (((Texture)texture).width != num || ((Texture)texture).height != num2)
			{
				texture.Release();
				((Texture)texture).width = num;
				((Texture)texture).height = num2;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(MenuManager), "Start")]
		private static void AddToMainMenu()
		{
			AddToSettings();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(QuickMenuManager), "Start")]
		private static void AddToPauseMenu()
		{
			AddToSettings();
		}

		private static void AddToSettings()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			SettingsOption val = ((IEnumerable<SettingsOption>)Object.FindObjectsOfType<SettingsOption>(true)).FirstOrDefault((Func<SettingsOption, bool>)((SettingsOption option) => (int)option.optionType == 15));
			if (!((Object)(object)val == (Object)null))
			{
				GameObject obj = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent);
				((Object)obj).name = "BaconFixer Terminal Quality";
				Object.DestroyImmediate((Object)(object)obj.GetComponent<SettingsOption>());
				RectTransform val2 = (RectTransform)obj.transform;
				val2.anchoredPosition += new Vector2(0f, -145f);
				obj.transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
				Transform obj2 = obj.transform.Find("Label2");
				TMP_Text val3 = ((obj2 != null) ? ((Component)obj2).GetComponent<TMP_Text>() : null);
				if ((Object)(object)val3 != (Object)null)
				{
					val3.text = "Terminal quality:";
				}
				TMP_Dropdown component = obj.GetComponent<TMP_Dropdown>();
				component.onValueChanged = new DropdownEvent();
				component.ClearOptions();
				component.AddOptions(Enum.GetNames(typeof(TerminalQualityLevel)).ToList());
				component.SetValueWithoutNotify((int)_level.Value);
				((UnityEvent<int>)(object)component.onValueChanged).AddListener((UnityAction<int>)delegate(int value)
				{
					_level.Value = (TerminalQualityLevel)value;
				});
			}
		}
	}
	internal static class TypeByNameFix
	{
		private static readonly Dictionary<string, Type> Cache = new Dictionary<string, Type>();

		private static readonly object Lock = new object();

		internal static void Apply(Harmony h)
		{
			//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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_0072: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(AccessTools), "TypeByName", new Type[1] { typeof(string) }, (Type[])null);
			if (!(methodInfo == null))
			{
				h.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(TypeByNameFix), "Prefix", (Type[])null)
				{
					priority = 800
				}, new HarmonyMethod(typeof(TypeByNameFix), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Plugin.Log.LogInfo((object)"TypeByNameFix: AccessTools.TypeByName is now cached");
			}
		}

		internal static Type Find(string name)
		{
			Type type = Type.GetType(name, throwOnError: false);
			if (type != null)
			{
				return type;
			}
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					type = assembly.GetType(name, throwOnError: false);
				}
				catch
				{
					type = null;
				}
				if (type != null)
				{
					return type;
				}
			}
			return null;
		}

		private static bool Prefix(string name, ref Type __result, out bool __state)
		{
			__state = false;
			if (string.IsNullOrEmpty(name))
			{
				return true;
			}
			lock (Lock)
			{
				if (Cache.TryGetValue(name, out var value))
				{
					__result = value;
					return false;
				}
			}
			Type type = Find(name);
			if (type != null || name.IndexOf('.') >= 0)
			{
				lock (Lock)
				{
					Cache[name] = type;
				}
				__result = type;
				return false;
			}
			__state = true;
			return true;
		}

		private static void Postfix(string name, Type __result, bool __state)
		{
			if (!__state || string.IsNullOrEmpty(name))
			{
				return;
			}
			lock (Lock)
			{
				Cache[name] = __result;
			}
		}
	}
	internal static class WeatherMultiplierDisplay
	{
		private static readonly Dictionary<string, string> Info = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
		{
			{ "Rainy", "Mud slows you down, watch for quicksand." },
			{ "Foggy", "Thick fog, very low visibility outside." },
			{ "Stormy", "Lightning strikes metal items outside." },
			{ "Flooded", "Water rises during the day, can drown." },
			{ "Eclipsed", "Many more enemies spawn from the start." },
			{ "DustClouds", "Dust storm, low visibility outside." },
			{ "Dust Clouds", "Dust storm, low visibility outside." },
			{ "Earthquakes", "Roof collapses inside crush players." },
			{ "Forsaken", "Blood rain. Wail inside, Emma at 2PM." },
			{ "Hallowed", "Scrap heads bite for 99, new enemies." },
			{ "Hurricane", "Falling trees deal 50 and knock back." },
			{ "Minefield", "Beeping mines outside. Blasts can kill." }
		};

		private const string BonusColor = "#8CFF8C";

		private const string LootColor = "#FFD24D";

		private const string InteriorColor = "#6BD9FF";

		private const string TimeColor = "#C9A6FF";

		private const string DangerColor = "#FF6B6B";

		private const int LongWeatherName = 16;

		private static MethodInfo _resolveRoute;

		private static MethodInfo _resolveRouteAfter;

		internal static void Apply(Harmony h)
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.ContainsKey("mrov.WeatherRegistry"))
			{
				return;
			}
			if (Chainloader.PluginInfos.TryGetValue("mrov.TerminalUtils", out var value) && value.Instance != null)
			{
				Type type = ((object)value.Instance).GetType().Assembly.GetType("TerminalUtils.Utils.GetWeatherName", throwOnError: false);
				MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "GetWeather", new Type[2]
				{
					typeof(SelectableLevel),
					typeof(bool)
				}, (Type[])null));
				if (methodInfo != null)
				{
					h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(WeatherMultiplierDisplay), "WeatherNamePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			if (Chainloader.PluginInfos.TryGetValue("TerminalFormatter", out var value2) && value2.Instance != null)
			{
				Assembly assembly = ((object)value2.Instance).GetType().Assembly;
				_resolveRoute = PatchRoutePage(h, assembly.GetType("TerminalFormatter.Nodes.Route", throwOnError: false), "RoutePostfix");
				_resolveRouteAfter = PatchRoutePage(h, assembly.GetType("TerminalFormatter.Nodes.RouteAfter", throwOnError: false), "RouteAfterPostfix");
				Type type2 = assembly.GetType("TerminalFormatter.Nodes.Moons", throwOnError: false);
				MethodInfo methodInfo2 = ((type2 == null) ? null : AccessTools.Method(type2, "GetNodeText", new Type[1] { typeof(TerminalNode) }, (Type[])null));
				if (methodInfo2 != null)
				{
					h.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(WeatherMultiplierDisplay), "MoonsPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			Plugin.Log.LogInfo((object)"WeatherMultiplierDisplay: weather multipliers + info shown in terminal");
		}

		private static MethodInfo PatchRoutePage(Harmony h, Type t, string postfix)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			if (t == null)
			{
				return null;
			}
			MethodInfo methodInfo = AccessTools.Method(t, "GetNodeText", new Type[1] { typeof(TerminalNode) }, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(t, "ResolveNodeIntoRoute", new Type[1] { typeof(TerminalNode) }, (Type[])null);
			if (methodInfo == null || methodInfo2 == null)
			{
				return null;
			}
			h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(WeatherMultiplierDisplay), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return methodInfo2;
		}

		private static string F(float v)
		{
			return v.ToString("0.##", CultureInfo.InvariantCulture);
		}

		private static bool NotOne(float v)
		{
			return Math.Abs(v - 1f) > 0.001f;
		}

		internal static Weather Current(SelectableLevel level)
		{
			try
			{
				Weather val = (((Object)(object)level == (Object)null) ? null : WeatherManager.GetCurrentWeather(level));
				return (val != null && WeatherManager.GetCurrentWeatherName(level, false) == val.Name) ? val : null;
			}
			catch
			{
				return null;
			}
		}

		internal static string BonusText(float value, float amount)
		{
			List<string> list = new List<string>(2);
			AddPercent(list, "value", value);
			AddPercent(list, "items", amount);
			return string.Join(" ", list);
		}

		private static void AddPercent(List<string> parts, string label, float multiplier)
		{
			int num = (int)Math.Round((multiplier - 1f) * 100f, MidpointRounding.AwayFromZero);
			if (num != 0)
			{
				parts.Add(label + num.ToString("+0;-0", CultureInfo.InvariantCulture) + "%");
			}
		}

		private static void WeatherNamePostfix(SelectableLevel level, ref string __result)
		{
			try
			{
				if (string.IsNullOrEmpty(__result))
				{
					return;
				}
				Weather val = Current(level);
				if (val != null)
				{
					if (__result.Length >= 16)
					{
						__result = val.NameShort;
					}
					string text = BonusText(val.ScrapValueMultiplier, val.ScrapAmountMultiplier);
					if (text.Length > 0)
					{
						__result = __result + " <size=70%><color=#8CFF8C>" + text + "</color></size>";
					}
				}
			}
			catch
			{
			}
		}

		private static void MoonsPostfix(ref string __result)
		{
			__result = RouteDetails.NameSellingMoons(__result);
			int num = __result.IndexOf("Buying at", StringComparison.Ordinal);
			int num2 = ((num < 0) ? (-1) : __result.IndexOf('\n', num));
			if (num2 >= 0)
			{
				__result = __result.Insert(num2 + 1, " <size=70%>Weather bonus: value = what scrap sells for, items = how much spawns. Type SORT BONUS for the best-paying moons.</size>\n");
			}
		}

		private static void RoutePostfix(object __instance, TerminalNode node, ref string __result)
		{
			AppendInfo(__instance, _resolveRoute, node, ref __result);
		}

		private static void RouteAfterPostfix(object __instance, TerminalNode node, ref string __result)
		{
			AppendInfo(__instance, _resolveRouteAfter, node, ref __result);
		}

		private static void AppendInfo(object instance, MethodInfo resolve, TerminalNode node, ref string text)
		{
			try
			{
				if (resolve == null || string.IsNullOrEmpty(text))
				{
					return;
				}
				object? obj = resolve.Invoke(instance, new object[1] { node });
				SelectableLevel val = ((Route)(((obj is Route) ? obj : null)?)).Level;
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				Weather val2 = Current(val);
				bool flag = val2 != null && !string.Equals(val2.Name, "None", StringComparison.OrdinalIgnoreCase);
				List<string> list = new List<string>();
				if (flag)
				{
					if (NotOne(val2.ScrapValueMultiplier) || NotOne(val2.ScrapAmountMultiplier))
					{
						List<string> list2 = new List<string>();
						if (NotOne(val2.ScrapValueMultiplier))
						{
							list2.Add("items worth x" + F(val2.ScrapValueMultiplier));
						}
						if (NotOne(val2.ScrapAmountMultiplier))
						{
							list2.Add("x" + F(val2.ScrapAmountMultiplier) + " more items");
						}
						list.Add(Colored("#8CFF8C", "SCRAP BONUS: " + string.Join(", ", list2)));
					}
					else
					{
						list.Add(Colored("#8CFF8C", "SCRAP BONUS: none"));
					}
				}
				list.Add(Colored("#8CFF8C", RouteDetails.Selling(val)));
				if (val.spawnEnemiesAndScrap)
				{
					float valueBonus = (flag ? val2.ScrapValueMultiplier : 1f) * GameSetup.ScrapValueFactor;
					float amountBonus = (flag ? val2.ScrapAmountMultiplier : 1f) * GameSetup.ScrapAmountFactor;
					list.Add(Colored("#FFD24D", RouteDetails.Loot(val, valueBonus, amountBonus)));
					if (Chainloader.PluginInfos.ContainsKey("imabatby.lethallevelloader"))
					{
						list.Add(Colored("#6BD9FF", RouteDetails.Interiors(val)));
					}
				}
				list.Add(Colored("#C9A6FF", RouteDetails.DayLength(val)));
				if (flag)
				{
					list.Add(Colored("#FF6B6B", DangerLine(val2.Name)));
				}
				list.RemoveAll(string.IsNullOrEmpty);
				if (list.Count > 0)
				{
					text = text.TrimEnd() + "\n\n" + string.Join("\n", list) + "\n\n";
				}
			}
			catch
			{
			}
		}

		private static string DangerLine(string weatherName)
		{
			List<string> list = (from part in weatherName.Split('+', '>')
				select part.Trim()).Where(Info.ContainsKey).ToList();
			if (list.Count == 0)
			{
				return null;
			}
			return "DANGER: " + ((list.Count == 1) ? Info[list[0]] : string.Join(" ", list.Select((string part) => part + ": " + Info[part])));
		}

		private static string Colored(string color, string line)
		{
			int num = line?.IndexOf(':') ?? (-1);
			if (num >= 0)
			{
				return "<color=" + color + ">" + line.Substring(0, num + 1) + "</color>" + line.Substring(num + 1);
			}
			return line;
		}
	}
}

BepInEx/patchers/BaconFixer.Preloader.dll

Decompiled 10 hours 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.Versioning;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Collections.Generic;

[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("BaconFixer.Preloader")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BaconFixer.Preloader")]
[assembly: AssemblyTitle("BaconFixer.Preloader")]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "Code generated with Claude Code, Anthropic's AI coding agent")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "Anthropic")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 BaconFixer.Preloader
{
	public static class DunGenForwarder
	{
		private const string KeepUnforwarded = "DunGen.TileConnectionRule";

		private static readonly ManualLogSource Log = Logger.CreateLogSource("BaconFixer.Preloader");

		public static IEnumerable<string> TargetDLLs { get; } = new string[1] { "Assembly-CSharp.dll" };

		public static void Patch(AssemblyDefinition assembly)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			ModuleDefinition mainModule = assembly.MainModule;
			AssemblyNameReference val = ((IEnumerable<AssemblyNameReference>)mainModule.AssemblyReferences).FirstOrDefault((Func<AssemblyNameReference, bool>)((AssemblyNameReference r) => r.Name == "DunGen"));
			string text = Path.Combine(Paths.ManagedPath, "DunGen.dll");
			if (val == null || !File.Exists(text))
			{
				Log.LogWarning((object)"DunGen.dll not found or not referenced. Nothing to forward.");
				return;
			}
			int num = 0;
			AssemblyDefinition val2 = AssemblyDefinition.ReadAssembly(text);
			try
			{
				Enumerator<TypeDefinition> enumerator = val2.MainModule.Types.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						TypeDefinition current = enumerator.Current;
						if (current.IsPublic && !(((MemberReference)current).FullName == "DunGen.TileConnectionRule") && mainModule.GetType(((MemberReference)current).FullName) == null)
						{
							mainModule.ExportedTypes.Add(new ExportedType(((TypeReference)current).Namespace, ((MemberReference)current).Name, mainModule, (IMetadataScope)(object)val)
							{
								IsForwarder = true
							});
							num++;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
				}
			}
			finally
			{
				((IDisposable)val2)?.Dispose();
			}
			Log.LogInfo((object)$"Forwarding {num} DunGen types from Assembly-CSharp to DunGen.dll");
		}
	}
}