Decompiled source of ZetasMoonTweaks v1.1.12

ZetasMoonTweaks.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CSync.Extensions;
using CSync.Lib;
using Dawn;
using Dawn.Internal;
using DunGen;
using DunGen.Graph;
using Dusk;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLevelLoader;
using LethalModDataLib.Attributes;
using LethalModDataLib.Features;
using LethalModDataLib.Helpers;
using LethalNetworkAPI;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using WeatherRegistry;
using WeatherTweaks.Definitions;
using ZetasMoonTweaks.NetcodePatcher;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ZetasMoonTweaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+88490b0c466f6df0f4cdda93326f42ba5ffb5ece")]
[assembly: AssemblyProduct("ZetasMoonTweaks")]
[assembly: AssemblyTitle("ZetasMoonTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: NetcodePatchedAssembly]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
[HarmonyPatch(typeof(NetworkManager))]
internal static class NetworkPrefabPatch2
{
	[HarmonyPostfix]
	[HarmonyPatch("SetSingleton")]
	private static void RegisterPrefab()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("ZetaArcade.ZetasMoonTweaks Prefab");
		((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
		Object.DontDestroyOnLoad((Object)(object)val);
		NetworkObject obj = val.AddComponent<NetworkObject>();
		FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
		field.SetValue(obj, GetHash("ZetaArcade.ZetasMoonTweaks"));
		NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
		static uint GetHash(string value)
		{
			return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
		}
	}
}
namespace ZetasMoonTweaks
{
	public class ConfigHandler : SyncedConfig2<ConfigHandler>
	{
		public enum OxydeLockModes
		{
			None,
			OddOnly,
			EvenOnly,
			Threshold,
			Rng
		}

		public enum Gamemode
		{
			Normal,
			QuotaIronman,
			DayIronman,
			SMHQ,
			RandomMoons
		}

		[SyncedEntryField]
		public SyncedEntry<bool> ApplyBuyingChanges;

		[SyncedEntryField]
		public SyncedEntry<float> NormalSellRate;

		[SyncedEntryField]
		public SyncedEntry<float> ZeroDaysSellRate;

		[SyncedEntryField]
		public SyncedEntry<bool> AutoCompanyBuilding;

		[SyncedEntryField]
		public SyncedEntry<bool> noFirstDayShopSales;

		[SyncedEntryField]
		public SyncedEntry<bool> bodies0Value;

		[SyncedEntryField]
		public SyncedEntry<Gamemode> gamemode;

		[SyncedEntryField]
		public SyncedEntry<bool> apparatusScale;

		[SyncedEntryField]
		public SyncedEntry<float> apparatusValueScaler;

		[SyncedEntryField]
		public SyncedEntry<bool> interiorNamePopup;

		[SyncedEntryField]
		public SyncedEntry<string> interiorNamePrefix;

		[SyncedEntryField]
		public SyncedEntry<string> interiorTitlePopup;

		[SyncedEntryField]
		public SyncedEntry<bool> fixInteriorNames;

		public ConfigEntry<string> interiorsAndOverrides;

		[SyncedEntryField]
		public SyncedEntry<bool> addPercentageInfo;

		[SyncedEntryField]
		public SyncedEntry<bool> ApplyDiscountChanges;

		[SyncedEntryField]
		public SyncedEntry<int> FreeThreshold;

		[SyncedEntryField]
		public SyncedEntry<int> FreeThresholdCap;

		[SyncedEntryField]
		public SyncedEntry<int> DowngradeCost;

		[SyncedEntryField]
		public SyncedEntry<int> UpgradeThreshold;

		public ConfigEntry<string> IronmanMoons;

		public ConfigEntry<string> SMHQMoons;

		[SyncedEntryField]
		public SyncedEntry<bool> IronmanRestrictRouting;

		[SyncedEntryField]
		public SyncedEntry<bool> IronmanAutoRoute;

		[SyncedEntryField]
		public SyncedEntry<bool> shouldIronmanLoop;

		[SyncedEntryField]
		public SyncedEntry<int> randomMoonAmount;

		public ConfigEntry<string> RandomMoons;

		[SyncedEntryField]
		public SyncedEntry<bool> ApplyRiskLevelChanges;

		[SyncedEntryField]
		public SyncedEntry<float> DefaultWeatherRiskLevelIncrease;

		public ConfigEntry<string> WeathersAndRiskLevels;

		[SyncedEntryField]
		public SyncedEntry<bool> RelockOxydeOnEject;

		[SyncedEntryField]
		public SyncedEntry<bool> OxydeTabletForceUnlocksOxyde;

		[SyncedEntryField]
		public SyncedEntry<OxydeLockModes> OxydeLockMode;

		[SyncedEntryField]
		public SyncedEntry<int> OxydeUnlockThreshold;

		[SyncedEntryField]
		public SyncedEntry<int> OxydeUnlockChance;

		[SyncedEntryField]
		public SyncedEntry<int> ZeroDaysOxydeCost;

		[SyncedEntryField]
		public SyncedEntry<int> OneDayOxydeCost;

		[SyncedEntryField]
		public SyncedEntry<int> TwoDayOxydeCost;

		[SyncedEntryField]
		public SyncedEntry<int> ThreeDayOxydeCost;

		[SyncedEntryField]
		public SyncedEntry<bool> DestroyOxydeSellScrapsInOrbit;

		[SyncedEntryField]
		public SyncedEntry<bool> PreventSellScrapsOnOxyde;

		public ConfigHandler(ConfigFile cfg)
			: base("ZetaArcade.ZetasMoonTweaks")
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Expected O, but got Unknown
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Expected O, but got Unknown
			//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Expected O, but got Unknown
			AutoCompanyBuilding = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "General", "Auto Company Building", true, "If true, when there are 0 days left to the Deadline, automatically route the ship back to the Company.");
			noFirstDayShopSales = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "General", "No First Day Shop Sales", false, "If true, no store items will have sales on them during the first day on the first quota. This prevents reloading to generate an advantageous Day 1 sale on something essential like Shovels.");
			bodies0Value = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "General", "Bodies 0 Value", false, "If true, player bodies will be worth 0 credits instead of 5. Prevents infinite selling exploits.");
			apparatusScale = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "General", "Apparatus Scale Value with Moon Scrap Value Multiplier", true, "If true, the Apparatus value will be patched to have it's value multiplied by the current moon scrap value multiplier, useful for mods like LunarConfig.");
			apparatusValueScaler = SyncedBindingExtensions.BindSyncedEntry<float>(cfg, "General", "Apparatus Value Exponent", 1f, new ConfigDescription("If 'Apparatus Scale Value with Moon Scrap Value Multiplier' is enabled, this controls how strongly the scrap value scales with the moon's scrap value multiplier. Higher values provide increasingly larger bonuses on moons with higher multipliers. 1.0 = no scaling, 1.585 = 3x value on a 2x moon, 2.0 = 4x value on a 2x moon etc. In short, big multipliers get even bigger, small multipliers don't increase much!", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 20f), Array.Empty<object>()));
			interiorNamePopup = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Interior Name Popup", "Toggle Interior Name Popup", true, "If true, a popup will be shown with the name of the interior when you first enter each day.");
			addPercentageInfo = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Interior Name Popup", "Add Percentage Info", true, "If true, the interior name popup will also display the chance of that interior appearing at the end.");
			interiorNamePrefix = SyncedBindingExtensions.BindSyncedEntry<string>(cfg, "Interior Name Popup", "Interior Name Prefix", "Interior:", "A prefix to add to the interior names. A space is added after by default.");
			interiorTitlePopup = SyncedBindingExtensions.BindSyncedEntry<string>(cfg, "Interior Name Popup", "Popup Title", "Current Interior", "The text at the top of the popup, acting as a Title/Header.");
			fixInteriorNames = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Interior Name Popup", "Fix Interior Names", true, "If true, interior names will be cleaned up to remove words like 'Flow' and 'Dungeon', seperate PascalCase etc. Overriden by the name overrides config. Disable this if you want to get the original interior names, which can then be used inside the override config to change to whatever you want.");
			interiorsAndOverrides = cfg.Bind<string>("Interior Name Popup", "Interiors and Overrides", "", "A list of interiors paired with their override names, in the format InteriorName@OverrideName; e.g. Level1Flow@Facility;ResearchStationFlow@ACF Facility;");
			ApplyBuyingChanges = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Buying Rate Changes", "Toggle Buying Rate Changes", true, "If true, the below 2 configs will be applied to the Company Buying Rate (How many credits you get for selling things)");
			NormalSellRate = SyncedBindingExtensions.BindSyncedEntry<float>(cfg, "Buying Rate Changes", "Normal Selling Rate", 1f, new ConfigDescription("The selling rate at the company on all days except the final day, where 1f = 100%, 0.5f = 50% etc.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			ZeroDaysSellRate = SyncedBindingExtensions.BindSyncedEntry<float>(cfg, "Buying Rate Changes", "Zero Days Selling Rate", 1f, new ConfigDescription("The selling rate at the company on the final day, where 1f = 100%, 0.5f = 50% etc.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			ApplyDiscountChanges = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Discount Settings", "Toggle Moon Discounts", true, "If true, the below configs will be applied to moons");
			FreeThreshold = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Discount Settings", "Free Threshold", 300, "When at Moon A, if Moon B is this amount cheaper (or even cheaper!) it becomes free to route to. E.g. with the default value of 300, if Moon A costs 800 and you route to it, then any moons that cost 500 or less are free to route to.");
			FreeThresholdCap = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Discount Settings", "Free Threshold Cap", 1000, "A Cap for the above config, where if a moon costs this amount or more, then other moons cannot route down to it for free. Note moons that are $3500 cheaper than the current moon or more are set to free anyways, bypassing this config");
			DowngradeCost = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Discount Settings", "Downgrade Cost", 50, "When at Moon A, if Moon B is cheaper but isn't cheap enough to become free with the above config (or costs the same amount as Moon A), then it will be this route price instead.");
			UpgradeThreshold = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Discount Settings", "Upgrade Threshold", 500, "When at Moon A, if Moon B is more expensive, then if it's within the range of this config then you can route 'up' to it, only paying the difference in cost to route. E.g. (with default config at 500) if Moon A costs 400, Moon B costs 800, and Moon C costs 1200, then you can route from Moon A to B for 400 (Since its less than 500 in difference), but Moon C will cost the full 1200.");
			gamemode = SyncedBindingExtensions.BindSyncedEntry<Gamemode>(cfg, "General", "Gamemode", Gamemode.Normal, "Which Gamemode to be on. Normal = No changes, QuotaIronman = You are restricted to 1 pair of moons from the Ironman config per quota, DayIronman = Same as QuotaIronman, except you advance through each pair each day rather than upon beating a Quota, SMHQ = 'Single Moon High Quota' means you are restricted to just the moon(s) named in the SMHQ config, and it is free to route to, RandomMoons = A random amount of moons are chosen each quota, which will always be free to route to, with everything else restricted.");
			IronmanRestrictRouting = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Ironman Settings", "Restrict Routing", false, "When true, you can only route to the current pair of moons, based on the current Quota No. rather than route to any pairing you like.");
			IronmanAutoRoute = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Ironman Settings", "Auto Routing", false, "When true, if Restrict Routing is enabled too, the ship will automatically route to the next pair of moons upon Quota completion. It will also route to the Company on Deadline day.");
			shouldIronmanLoop = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Ironman Settings", "Loop Ironman Moons", false, "When true, if you reach the end of the Ironman Moon List, it will loop back to the start of the list. If false, then when you reach the end of the list, you will remain there.");
			IronmanMoons = cfg.Bind<string>("Ironman Settings", "Ironman Moon List", "", "List of groups of moons, starting with a price for that group of moons, in the format of: Price@[email protected]. ; e.g. 0@Exp@Vow;300@Assurance@Solace; Only works if Ironman is the Gamemode.");
			SMHQMoons = cfg.Bind<string>("SMHQ Settings", "SMHQ Moon List", "", "List of moons that are available in SMHQ mode, in the format of: [email protected]. ; e.g. Exp@Vow;Assurance@Solace; All other moons will be impossible to route to. Only works if SMHQ is the Gamemode.");
			randomMoonAmount = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Random Moons Settings", "Random Moon Amount", 3, "How many moons should be randomly chosen to be available each Quota. Only works if RandomMoons is the Gamemode.");
			RandomMoons = cfg.Bind<string>("Random Moons Settings", "Random Moon List", "", "List of moons that can be randomly chosen to be available in Random Moons mode, in the format of: Moon1;Moon2; ..etc. ; e.g. Exp;Vow;Assurance;Solace; Only works if RandomMoons is the Gamemode.");
			ApplyRiskLevelChanges = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Dynamic Risk Level Settings", "Toggle Risk Level Changes", false, "If true, a moon's risk level will change depending on the current weather and below settings.");
			DefaultWeatherRiskLevelIncrease = SyncedBindingExtensions.BindSyncedEntry<float>(cfg, "Dynamic Risk Level Settings", "Default Weather Risk Level Increase", 0.5f, "The default difficulty increase for a weather where unspecified below.");
			WeathersAndRiskLevels = cfg.Bind<string>("Dynamic Risk Level Settings", "Weathers and Risk Levels", "", "A list of weathers paired with how much they should increase the difficulty rating, in the format WeatherName@DifficultyIncreaseAmount; e.g. None@0;[email protected]; Be careful to not include any whitespace unless it's a part of the weather name!");
			RelockOxydeOnEject = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Oxyde Settings", "Relock Oxyde on Eject", true, "If true, then when an ejection occurs, Oxyde will be Locked again for the save file. This is a bug fix for CodeRebirth.");
			OxydeTabletForceUnlocksOxyde = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Oxyde Settings", "Oxyde Tablet Force Unlocks Oxyde", true, "If true, then when an Oxyde Tablet is used, Oxyde will be guaranteed to be unlocked for this Quota, regardless of the Lock Mode, making the Tablet still useful after Oxyde is initially discovered.");
			DestroyOxydeSellScrapsInOrbit = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Oxyde Settings", "Destroy Selling Scraps when leaving", true, "If true, then when the ship is leaving Oxyde, any Shredded Scraps / Compacted Cubes will be destroyed to prevent bringing them into orbit, which prevents cheesing the sell process by amassing these scraps early.");
			PreventSellScrapsOnOxyde = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Oxyde Settings", "Prevent Extra Loot on Oxyde", false, "If true, this patches it so Vanilla Nutcrackers/Butlers weapons, SellBodiesFixed Bodies and MoreCounterplay Coilhead Heads do not drop on Oxyde, to prevent infinite farming exploits. Warning: May be incompatible with other spawning methods on Oxyde, such as storage mods retrieving those items or debug mods trying to spawn them in.");
			OxydeLockMode = SyncedBindingExtensions.BindSyncedEntry<OxydeLockModes>(cfg, "Oxyde Settings", "Oxyde Lock Mode", OxydeLockModes.None, "Different ways to control when Oxyde is 'Locked' by setting the Route cost to 99999. 'None' = No changes, 'OddOnly' / 'EvenOnly' = Oxyde will only be available on Odd/Even numbered Quotas respectively, 'Threshold' = The quota must reach a certain threshold for Oxyde to become available, 'Rng' = Oxyde has a random chance to be available each Quota.");
			OxydeUnlockThreshold = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Oxyde Settings", "Oxyde Unlock Threshold", 3000, "How high the Quota should be before Oxyde becomes available, if 'Oxyde Lock Mode' is set to 'Threshold'");
			OxydeUnlockChance = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Oxyde Settings", "Oxyde Unlock Chance", 75, new ConfigDescription("How likely Oxyde will be available for that Quota, if 'Oxyde Lock Mode' is set to 'Rng'. 100 = 100 % chance.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			ZeroDaysOxydeCost = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Oxyde Settings", "0 Days Oxyde Cost", -1, "How much Oxyde should cost when there are 0 days left for the Quota. Leave as -1 to not change it.");
			OneDayOxydeCost = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Oxyde Settings", "1 Days Oxyde Cost", -1, "How much Oxyde should cost when there are 1 days left for the Quota. Leave as -1 to not change it.");
			TwoDayOxydeCost = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Oxyde Settings", "2 Days Oxyde Cost", -1, "How much Oxyde should cost when there are 2 days left for the Quota. Leave as -1 to not change it.");
			ThreeDayOxydeCost = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Oxyde Settings", "3 Days Oxyde Cost", -1, "How much Oxyde should cost when there are 3 days (or more!) left for the Quota. Leave as -1 to not change it.");
			ConfigManager.Register<ConfigHandler>((SyncedConfig2<ConfigHandler>)(object)this);
		}
	}
	[BepInPlugin("ZetaArcade.ZetasMoonTweaks", "ZetasMoonTweaks", "1.1.12")]
	[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("com.sigurd.csync", "5.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ZMTBase : BaseUnityPlugin
	{
		internal class LevelPairedWithPrice
		{
			public ExtendedLevel Level;

			public int OriginalPrice;
		}

		internal class LevelPairedWithRisk
		{
			public ExtendedLevel Level;

			public string OriginalRiskLevel;
		}

		private readonly Harmony harmony = new Harmony("ZetaArcade.ZetasMoonTweaks");

		public static ManualLogSource Logger;

		public static ZMTBase Instance;

		internal static ConfigHandler Config;

		internal static ModData ModDataInstance;

		public int groupCredits;

		public bool displayedOxydeAlertForQuota;

		public bool hasRoutedForThisQuota = false;

		private List<LevelPairedWithPrice> MoonDefaultCosts = new List<LevelPairedWithPrice>();

		private List<LevelPairedWithRisk> MoonDefaultRiskLevels = new List<LevelPairedWithRisk>();

		public List<string> currentlySelectedRandomMoons = new List<string>();

		public int lastRandomMoonsQuota = -1;

		private static readonly PropertyInfo CostProperty = AccessTools.Property(typeof(DawnPurchaseInfo), "Cost");

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Logger = ((BaseUnityPlugin)this).Logger;
			Config = new ConfigHandler(((BaseUnityPlugin)this).Config);
			ModDataInstance = new ModData();
			ModDataHandler.RegisterInstance((object)ModDataInstance, "ZMTModDataInstance");
			ZMTNetwork.Init();
			try
			{
				harmony.PatchAll();
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Harmony patching failed: {arg}");
			}
			Logger.LogInfo((object)"Plugin is loaded!");
			MethodInfo methodInfo = AccessTools.Method(typeof(EntranceTeleport), "TeleportPlayer", (Type[])null, (Type[])null);
			Patches patchInfo = Harmony.GetPatchInfo((MethodBase)methodInfo);
			Logger.LogDebug((object)$"TeleportPlayer found: {methodInfo != null}");
			Logger.LogDebug((object)$"TeleportPlayer patched: {patchInfo != null}");
			if (patchInfo == null)
			{
				return;
			}
			foreach (Patch postfix in patchInfo.Postfixes)
			{
				Logger.LogDebug((object)("Postfix owner: " + postfix.owner));
			}
		}

		public void RollNewSeed()
		{
			if (NetworkManager.Singleton.IsHost)
			{
				if (!ModDataInstance.seedSetForQuota)
				{
					int num = Random.Range(0, 100);
					SetNewSeed(num);
					ZMTNetwork.SendNewSeed(num);
				}
				else
				{
					Logger.LogDebug((object)("Seed already set as: " + ModDataInstance.currentQuotaRoll));
				}
			}
		}

		public void ResetRandomMoons()
		{
			Logger.LogDebug((object)"Resetting Random Moons after ejection");
			currentlySelectedRandomMoons.Clear();
			lastRandomMoonsQuota = -1;
			ModDataInstance.selectedRandomMoons = "";
			ModDataInstance.lastRandomMoonsQuota = -1;
			ModDataInstance.ZMTSaveData();
		}

		public void SetNewSeed(int newQuotaRoll)
		{
			Logger.LogDebug((object)("New seed set as: " + newQuotaRoll));
			ModDataInstance.currentQuotaRoll = newQuotaRoll;
			ModDataInstance.seedSetForQuota = true;
			ModDataInstance.ZMTSaveData();
		}

		public void CheckForScrapsToDestroy()
		{
			if (((NetworkBehaviour)StartOfRound.Instance).IsHost)
			{
				List<GrabbableObject> list = (from o in Object.FindObjectsOfType<GrabbableObject>()
					where !o.isHeld && o.isInShipRoom && Object.op_Implicit((Object)(object)o.itemProperties) && (o.itemProperties.itemName == "Normal Shredded Scraps" || o.itemProperties.itemName == "Sally Cube")
					select o).ToList();
				Logger.LogDebug((object)("Destroying " + list.Count + " scraps when in the ship when Orbiting"));
				for (int num = 0; num < list.Count; num++)
				{
					((NetworkBehaviour)list[num]).NetworkObject.Despawn(true);
				}
			}
			PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
			Dictionary<int, GrabbableObject> dictionary = new Dictionary<int, GrabbableObject>();
			if ((Object)(object)localPlayerController != (Object)null)
			{
				for (int num2 = 0; num2 < localPlayerController.ItemSlots.Length; num2++)
				{
					dictionary[num2] = localPlayerController.ItemSlots[num2];
				}
			}
			foreach (int key in dictionary.Keys)
			{
				if (!((Object)(object)dictionary[key] == (Object)null) && (dictionary[key].itemProperties.itemName == "Normal Shredded Scraps" || dictionary[key].itemProperties.itemName == "Sally Cube"))
				{
					Logger.LogDebug((object)("Destroying banned scrap in slot " + key + " scraps when Orbiting"));
					ZMTNetwork.SendItemDestroy(StartOfRound.Instance.localPlayerController.playerClientId, key);
				}
			}
		}

		public void DestroyScrapInSlot(ulong playerClientID, int slot)
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			PlayerControllerB val = ((IEnumerable<PlayerControllerB>)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB p) => p.playerClientId == playerClientID));
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			GrabbableObject val2 = val.ItemSlots[slot];
			if (!((Object)(object)val2 == (Object)null))
			{
				val.carryWeight = Mathf.Clamp(val.carryWeight - (val2.itemProperties.weight - 1f), 1f, 10f);
				val.DestroyItemInSlot(slot);
				if ((Object)(object)HUDManager.Instance != (Object)null)
				{
					((Behaviour)HUDManager.Instance.itemSlotIcons[slot]).enabled = false;
				}
			}
		}

		public void ModifyBuyingRate()
		{
			if (Config.ApplyBuyingChanges.Value && Object.op_Implicit((Object)(object)TimeOfDay.Instance) && Object.op_Implicit((Object)(object)StartOfRound.Instance))
			{
				if (TimeOfDay.Instance.daysUntilDeadline != 0)
				{
					StartOfRound.Instance.companyBuyingRate = Config.NormalSellRate.Value;
				}
				else
				{
					StartOfRound.Instance.companyBuyingRate = Config.ZeroDaysSellRate.Value;
				}
			}
		}

		public void rerouteShip(GameNetworkManager networkManager, bool toCompany)
		{
			if (!Object.op_Implicit((Object)(object)StartOfRound.Instance) || !Object.op_Implicit((Object)(object)StartOfRound.Instance.currentLevel) || !networkManager.isHostingGame)
			{
				return;
			}
			int num = -1;
			if (toCompany)
			{
				num = 3;
				if (StartOfRound.Instance.currentLevelID == 3)
				{
					ModDataInstance.hasReroutedCompany = true;
				}
			}
			else
			{
				if (Config.gamemode.Value == ConfigHandler.Gamemode.QuotaIronman)
				{
					num = GetNextQuotaMoonID();
				}
				else if (Config.gamemode.Value == ConfigHandler.Gamemode.DayIronman)
				{
					num = GetNextDayMoonID();
				}
				else if (Config.gamemode.Value == ConfigHandler.Gamemode.SMHQ)
				{
					num = GetSMHQMoonID();
				}
				else if (Config.gamemode.Value == ConfigHandler.Gamemode.RandomMoons)
				{
					num = GetRandomMoonID();
				}
				if (StartOfRound.Instance.currentLevelID == num)
				{
					ModDataInstance.hasReroutedMoonPair = true;
				}
			}
			if (num == -1)
			{
				return;
			}
			if (toCompany)
			{
				if (StartOfRound.Instance.CanChangeLevels() && !ModDataInstance.hasReroutedCompany && TimeOfDay.Instance.daysUntilDeadline == 0 && Config.AutoCompanyBuilding.Value && TimeOfDay.Instance.quotaFulfilled < TimeOfDay.Instance.profitQuota)
				{
					StartOfRound.Instance.ChangeLevelServerRpc(num, groupCredits);
					StartOfRound.Instance.ChangeLevel(num);
					hasRoutedForThisQuota = true;
					ModDataInstance.hasReroutedCompany = true;
					ModDataInstance.ZMTSaveData();
				}
				else
				{
					ModDataInstance.hasReroutedCompany = false;
				}
			}
			else if (StartOfRound.Instance.CanChangeLevels() && !ModDataInstance.hasReroutedMoonPair && Config.IronmanAutoRoute.Value && TimeOfDay.Instance.quotaFulfilled < TimeOfDay.Instance.profitQuota)
			{
				StartOfRound.Instance.ChangeLevelServerRpc(num, groupCredits);
				StartOfRound.Instance.ChangeLevel(num);
				ModDataInstance.hasReroutedMoonPair = true;
				ModDataInstance.ZMTSaveData();
			}
			else
			{
				ModDataInstance.hasReroutedMoonPair = false;
			}
		}

		public void SetDawnPrice(ExtendedLevel levelRef, int newPrice)
		{
			Logger.LogDebug((object)("Trying to set DawnPrice of " + levelRef.NumberlessPlanetName + " to " + newPrice));
			try
			{
				DawnMoonInfo dawnInfo = SelectableLevelExtensions.GetDawnInfo(levelRef.SelectableLevel);
			}
			catch (Exception ex)
			{
				Logger.LogError((object)ex);
			}
			DawnMoonInfo dawnInfo2 = SelectableLevelExtensions.GetDawnInfo(levelRef.SelectableLevel);
			if (dawnInfo2 != null)
			{
				try
				{
					CostProperty.SetValue(dawnInfo2.DawnPurchaseInfo, new SimpleProvider<int>(newPrice));
				}
				catch (Exception ex2)
				{
					Logger.LogError((object)ex2);
				}
				if ((Object)(object)dawnInfo2.RouteNode != (Object)null)
				{
					dawnInfo2.RouteNode.itemCost = newPrice;
				}
				if ((Object)(object)dawnInfo2.ReceiptNode != (Object)null)
				{
					dawnInfo2.ReceiptNode.itemCost = newPrice;
				}
			}
		}

		public int GetNextQuotaMoonID()
		{
			int result = -1;
			if (!Object.op_Implicit((Object)(object)StartOfRound.Instance))
			{
				return -1;
			}
			if (!Object.op_Implicit((Object)(object)StartOfRound.Instance.currentLevel))
			{
				return -1;
			}
			int num = TimeOfDay.Instance.timesFulfilledQuota + 1;
			string[] array = Config.IronmanMoons.Value.ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
			int num2 = 0;
			if ((Object)(object)TimeOfDay.Instance != (Object)null)
			{
				num = TimeOfDay.Instance.timesFulfilledQuota + 1;
				Logger.LogDebug((object)("Current quota number is: " + num));
			}
			if (array.Length != 0)
			{
				num = ((!Config.shouldIronmanLoop.Value) ? Mathf.Clamp(num, 1, array.Length) : ((num - 1) % array.Length + 1));
				Logger.LogDebug((object)$"Ironman selected quota group is: {num}");
			}
			string[] array2 = array;
			foreach (string text in array2)
			{
				num2++;
				string[] array3 = text.Split(new char[1] { '@' }, StringSplitOptions.RemoveEmptyEntries);
				int num3 = 0;
				bool flag = false;
				string[] array4 = array3;
				foreach (string pair in array4)
				{
					if (num3 != 0)
					{
						bool flag2 = false;
						try
						{
							ExtendedLevel val = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => (Object)(object)x.SelectableLevel == (Object)(object)ConfigHelper.ConvertStringToLevels(pair)[0]);
							flag2 = true;
						}
						catch (Exception)
						{
							Logger.LogError((object)("Error when trying to parse " + pair + " in the ExtendedLevels list"));
						}
						if (flag2 && !flag)
						{
							ExtendedLevel val2 = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => (Object)(object)x.SelectableLevel == (Object)(object)ConfigHelper.ConvertStringToLevels(pair)[0]);
							if ((Object)(object)val2 != (Object)null && int.TryParse(array3[0].ToString(), out var _) && num == num2)
							{
								result = val2.SelectableLevel.levelID;
								flag = true;
							}
						}
					}
					num3++;
				}
			}
			return result;
		}

		public int GetNextDayMoonID()
		{
			if (StartOfRound.Instance?.gameStats == null)
			{
				return -1;
			}
			int num = StartOfRound.Instance.gameStats.daysSpent + 1 - TimeOfDay.Instance.timesFulfilledQuota;
			string[] array = Config.IronmanMoons.Value.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
			if (array.Length == 0)
			{
				Logger.LogDebug((object)"DayIronman has no configured moon groups!");
				return -1;
			}
			int num2 = (num - 1) % array.Length;
			string[] array2 = array[num2].Split(new char[1] { '@' }, StringSplitOptions.RemoveEmptyEntries);
			if (array2.Length < 2)
			{
				return -1;
			}
			try
			{
				SelectableLevel selectableLevel = ConfigHelper.ConvertStringToLevels(array2[1].Trim())[0];
				ExtendedLevel val = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => (Object)(object)x.SelectableLevel == (Object)(object)selectableLevel);
				if ((Object)(object)val == (Object)null)
				{
					return -1;
				}
				Logger.LogDebug((object)("DayIronman routing to " + val.NumberlessPlanetName));
				return val.SelectableLevel.levelID;
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"DayIronman could not resolve moon: {arg}");
				return -1;
			}
		}

		public int GetSMHQMoonID()
		{
			string[] array = Config.SMHQMoons.Value.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
			string[] array2 = array;
			foreach (string text in array2)
			{
				try
				{
					SelectableLevel selectableLevel = ConfigHelper.ConvertStringToLevels(text.Trim())[0];
					ExtendedLevel val = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => (Object)(object)x.SelectableLevel == (Object)(object)selectableLevel);
					if ((Object)(object)val != (Object)null)
					{
						Logger.LogDebug((object)("SMHQ routing to " + val.NumberlessPlanetName));
						return val.SelectableLevel.levelID;
					}
				}
				catch (Exception arg)
				{
					Logger.LogError((object)$"SMHQ could not resolve moon {text}: {arg}");
				}
			}
			return -1;
		}

		public int GetRandomMoonID()
		{
			if (currentlySelectedRandomMoons.Count == 0)
			{
				Logger.LogWarning((object)"Random Moons has no selected moons to route to!");
				return -1;
			}
			foreach (string moonName in currentlySelectedRandomMoons)
			{
				ExtendedLevel val = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => x.NumberlessPlanetName == moonName);
				if ((Object)(object)val != (Object)null)
				{
					Logger.LogDebug((object)("Random Moons automatically routing to " + val.NumberlessPlanetName));
					return val.SelectableLevel.levelID;
				}
			}
			Logger.LogWarning((object)"Random Moons could not find a valid moon to route to!");
			return -1;
		}

		public void UpdateOxydeTabletStatus(bool newUnlockStatus)
		{
			ModDataInstance.isOxydeOveride = newUnlockStatus;
			displayedOxydeAlertForQuota = false;
			ModDataInstance.ZMTSaveData();
		}

		public void SetOxydeCostFromConfigs()
		{
			int num = TimeOfDay.Instance.timesFulfilledQuota + 1;
			ExtendedLevel val = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => x.NumberlessPlanetName == "Oxyde");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogWarning((object)"Couldnt find Oxyde, no changes will be made to the price");
				return;
			}
			bool flag = num % 2 == 0;
			if (ModDataInstance.isOxydeOveride)
			{
				SetOxydeCostFromDeadline(val);
				OxydeHUDAlert(denied: false, "Oxyde has been unlocked for this Quota, thanks to the Oxyde Tablet!");
				return;
			}
			switch (Config.OxydeLockMode.Value)
			{
			case ConfigHandler.OxydeLockModes.None:
				SetOxydeCostFromDeadline(val);
				break;
			case ConfigHandler.OxydeLockModes.EvenOnly:
				if (flag)
				{
					SetOxydeCostFromDeadline(val);
					OxydeHUDAlert(denied: false, "Oxyde has been unlocked for this Quota, since the Quota # is an Even Number!");
				}
				else
				{
					val.RoutePrice = 9999;
					SetDawnPrice(val, 9999);
					OxydeHUDAlert(denied: true, "Oxyde has been locked for this Quota, since the Quota # isn't an Even Number!");
				}
				break;
			case ConfigHandler.OxydeLockModes.OddOnly:
				if (!flag)
				{
					SetOxydeCostFromDeadline(val);
					OxydeHUDAlert(denied: false, "Oxyde has been unlocked for this Quota, since the Quota # is an Odd Number!");
				}
				else
				{
					val.RoutePrice = 9999;
					SetDawnPrice(val, 9999);
					OxydeHUDAlert(denied: true, "Oxyde has been locked for this Quota, since the Quota # isn't an Odd Number!");
				}
				break;
			case ConfigHandler.OxydeLockModes.Threshold:
				if (TimeOfDay.Instance.profitQuota >= Config.OxydeUnlockThreshold.Value)
				{
					SetOxydeCostFromDeadline(val);
					OxydeHUDAlert(denied: false, "Oxyde has been unlocked for this Quota, since the Quota is above $" + Config.OxydeUnlockThreshold.Value + "!");
				}
				else
				{
					val.RoutePrice = 9999;
					SetDawnPrice(val, 9999);
					OxydeHUDAlert(denied: true, "Oxyde has been locked for this Quota, since the Quota isn't at $" + Config.OxydeUnlockThreshold.Value + " yet!");
				}
				break;
			case ConfigHandler.OxydeLockModes.Rng:
				if (!ModDataInstance.seedSetForQuota)
				{
					val.RoutePrice = 9999;
					SetDawnPrice(val, 9999);
					RollNewSeed();
				}
				else if (ModDataInstance.currentQuotaRoll <= Config.OxydeUnlockChance.Value)
				{
					SetOxydeCostFromDeadline(val);
					OxydeHUDAlert(denied: false, "Oxyde has been unlocked due to good luck for this Quota! (A " + Config.OxydeUnlockChance.Value + "% chance of happening!)");
				}
				else
				{
					val.RoutePrice = 9999;
					SetDawnPrice(val, 9999);
					OxydeHUDAlert(denied: true, "Oxyde has been locked due to bad luck for this Quota! (A " + (100 - Config.OxydeUnlockChance.Value) + "% chance of happening!)");
				}
				break;
			}
		}

		public void OxydeHUDAlert(bool denied, string reason)
		{
			if ((Object)(object)HUDManager.Instance != (Object)null && (Object)(object)StartOfRound.Instance != (Object)null && !((Object)(object)StartOfRound.Instance.localPlayerController == (Object)null) && !displayedOxydeAlertForQuota && StartOfRound.Instance.localPlayerController.isPlayerControlled && StartOfRound.Instance.inShipPhase)
			{
				displayedOxydeAlertForQuota = true;
				HUDManager.Instance.DisplayTip("Oxyde Update", reason, denied, false, "LC_Tip1");
			}
		}

		public void SetOxydeCostFromDeadline(ExtendedLevel OxydeRef)
		{
			int num = -1;
			num = TimeOfDay.Instance.daysUntilDeadline switch
			{
				0 => SyncedEntry<int>.op_Implicit(Config.ZeroDaysOxydeCost), 
				1 => SyncedEntry<int>.op_Implicit(Config.OneDayOxydeCost), 
				2 => SyncedEntry<int>.op_Implicit(Config.TwoDayOxydeCost), 
				3 => SyncedEntry<int>.op_Implicit(Config.ThreeDayOxydeCost), 
				_ => SyncedEntry<int>.op_Implicit(Config.ThreeDayOxydeCost), 
			};
			if (num > -1)
			{
				OxydeRef.RoutePrice = num;
				SetDawnPrice(OxydeRef, num);
				return;
			}
			OxydeRef.RoutePrice = MoonDefaultCosts.Find((LevelPairedWithPrice x) => (Object)(object)x.Level == (Object)(object)OxydeRef).OriginalPrice;
			SetDawnPrice(OxydeRef, OxydeRef.RoutePrice);
		}

		public void CalculateMoonPrices()
		{
			if (!Config.ApplyDiscountChanges.Value && Config.gamemode.Value == ConfigHandler.Gamemode.Normal)
			{
				return;
			}
			Logger.LogDebug((object)"Attempting CalculateMoonPrices");
			if (MoonDefaultCosts.Count < 1 && Config.gamemode.Value == ConfigHandler.Gamemode.Normal)
			{
				Logger.LogDebug((object)"Default moon prices have not been set, skipping Calculation of moon prices");
				return;
			}
			Logger.LogDebug((object)"Default moon prices been set, continuing");
			if (!Object.op_Implicit((Object)(object)StartOfRound.Instance) || !Object.op_Implicit((Object)(object)StartOfRound.Instance.currentLevel))
			{
				return;
			}
			SelectableLevel currentLevel = StartOfRound.Instance.currentLevel;
			ExtendedLevel val = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => (Object)(object)x.SelectableLevel == (Object)(object)currentLevel);
			if (Config.gamemode.Value == ConfigHandler.Gamemode.Normal)
			{
				foreach (ExtendedLevel level in PatchedContent.ExtendedLevels)
				{
					level.RoutePrice = MoonDefaultCosts.Find((LevelPairedWithPrice x) => (Object)(object)x.Level == (Object)(object)level).OriginalPrice;
					SetDawnPrice(level, level.RoutePrice);
				}
				if (val.NumberlessPlanetName == "Gordion" || val.NumberlessPlanetName == "Galetry" || val.NumberlessPlanetName == "Oxyde" || val.RoutePrice == 0)
				{
					Logger.LogDebug((object)("Current moon " + val.NumberlessPlanetName + " is free/company/oxyde, so no discounts will be applied except for Oxyde Route Cost changes"));
					return;
				}
				Logger.LogDebug((object)("Current moon " + val.NumberlessPlanetName + " is not free/company/oxyde, so discounts will be applied"));
				{
					foreach (ExtendedLevel level2 in PatchedContent.ExtendedLevels)
					{
						if (level2.NumberlessPlanetName == "Gordion" || level2.NumberlessPlanetName == "Oxyde" || level2.NumberlessPlanetName == "Galetry" || level2.NumberlessPlanetName == val.NumberlessPlanetName || level2.RoutePrice == 0)
						{
							level2.RoutePrice = MoonDefaultCosts.Find((LevelPairedWithPrice x) => (Object)(object)x.Level == (Object)(object)level2).OriginalPrice;
							SetDawnPrice(level2, level2.RoutePrice);
							continue;
						}
						int num = val.RoutePrice - level2.RoutePrice;
						if ((num >= Config.FreeThreshold.Value && level2.RoutePrice < Config.FreeThresholdCap.Value) || num >= 3500)
						{
							level2.RoutePrice = 0;
							SetDawnPrice(level2, 0);
							Logger.LogDebug((object)("Current moon " + val.NumberlessPlanetName + "(" + val.RoutePrice + ") --> " + level2.NumberlessPlanetName + "(" + level2.RoutePrice + ") Meets the free discount criteria"));
							continue;
						}
						if (level2.RoutePrice <= Config.DowngradeCost.Value)
						{
							Logger.LogDebug((object)("Current moon " + val.NumberlessPlanetName + "(" + val.RoutePrice + ") --> " + level2.NumberlessPlanetName + "(" + level2.RoutePrice + ") Meets the downgrade discount criteria but is so cheap it will stay the same price"));
							continue;
						}
						if (level2.RoutePrice <= val.RoutePrice)
						{
							level2.RoutePrice = Config.DowngradeCost.Value;
							SetDawnPrice(level2, level2.RoutePrice);
							Logger.LogDebug((object)("Current moon " + val.NumberlessPlanetName + "(" + val.RoutePrice + ") --> " + level2.NumberlessPlanetName + "(" + level2.RoutePrice + ") Meets the downgrade discount criteria"));
							continue;
						}
						num = level2.RoutePrice - val.RoutePrice;
						if (num <= Config.UpgradeThreshold.Value)
						{
							level2.RoutePrice = num;
							SetDawnPrice(level2, level2.RoutePrice);
							Logger.LogDebug((object)("Current moon " + val.NumberlessPlanetName + "(" + val.RoutePrice + ") --> " + level2.NumberlessPlanetName + "(" + level2.RoutePrice + ") Meets the upgrade discount criteria"));
							continue;
						}
						level2.RoutePrice = MoonDefaultCosts.Find((LevelPairedWithPrice x) => (Object)(object)x.Level == (Object)(object)level2).OriginalPrice;
						SetDawnPrice(level2, level2.RoutePrice);
						Logger.LogDebug((object)("Current moon " + val.NumberlessPlanetName + "(" + val.RoutePrice + ") --> " + level2.NumberlessPlanetName + "(" + level2.RoutePrice + ") Does not meet any discount criteria"));
					}
					return;
				}
			}
			if (Config.gamemode.Value == ConfigHandler.Gamemode.QuotaIronman || Config.gamemode.Value == ConfigHandler.Gamemode.DayIronman)
			{
				Logger.LogDebug((object)"Ironman Mode Detected");
				if (val.NumberlessPlanetName == "Gordion" || val.NumberlessPlanetName == "Galetry" || val.NumberlessPlanetName == "Oxyde")
				{
					Logger.LogDebug((object)"Ironman Is Company");
					string[] array = Config.IronmanMoons.Value.ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
					int num2 = 0;
					int num3 = 0;
					if (array.Length != 0 && SyncedEntry<bool>.op_Implicit(Config.shouldIronmanLoop))
					{
						num3 = (num3 - 1) % array.Length + 1;
					}
					else if (array.Length != 0 && !SyncedEntry<bool>.op_Implicit(Config.shouldIronmanLoop))
					{
						num3 = Mathf.Clamp(num3, 1, array.Length);
					}
					if ((Object)(object)TimeOfDay.Instance != (Object)null)
					{
						if (Config.gamemode.Value == ConfigHandler.Gamemode.QuotaIronman)
						{
							num3 = TimeOfDay.Instance.timesFulfilledQuota + 1;
							Logger.LogDebug((object)("Current quota number is: " + num3));
						}
						else if (Config.gamemode.Value == ConfigHandler.Gamemode.DayIronman)
						{
							num3 = StartOfRound.Instance.gameStats.daysSpent + 1 - TimeOfDay.Instance.timesFulfilledQuota;
							Logger.LogDebug((object)("Current day number is: " + num3));
						}
					}
					string[] array2 = array;
					foreach (string text in array2)
					{
						num2++;
						Logger.LogDebug((object)("Ironman currently on entry " + text));
						string[] array3 = text.Split(new char[1] { '@' }, StringSplitOptions.RemoveEmptyEntries);
						int num5 = 0;
						string[] array4 = array3;
						foreach (string pair in array4)
						{
							Logger.LogDebug((object)("Ironman currently on pair " + pair));
							if (num5 != 0)
							{
								bool flag = false;
								try
								{
									ExtendedLevel val2 = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => (Object)(object)x.SelectableLevel == (Object)(object)ConfigHelper.ConvertStringToLevels(pair)[0]);
									flag = true;
								}
								catch (Exception)
								{
									Logger.LogError((object)("Error when trying to parse " + pair + " in the ExtendedLevels list"));
								}
								if (flag)
								{
									ExtendedLevel val3 = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => (Object)(object)x.SelectableLevel == (Object)(object)ConfigHelper.ConvertStringToLevels(pair)[0]);
									if ((Object)(object)val3 != (Object)null)
									{
										if (int.TryParse(array3[0].ToString(), out var result))
										{
											Logger.LogDebug((object)("Setting " + val3.NumberlessPlanetName + " route price to " + result));
											if (Config.IronmanRestrictRouting.Value)
											{
												if (num3 == num2)
												{
													val3.IsRouteLocked = false;
													val3.IsRouteHidden = false;
													Logger.LogDebug((object)("Moon " + val3.NumberlessPlanetName + " is not locked because it is from pair " + num2 + " and the current quota/day is " + num3));
													if (Config.IronmanAutoRoute.Value)
													{
														val3.RoutePrice = 0;
														SetDawnPrice(val3, val3.RoutePrice);
													}
													else
													{
														val3.RoutePrice = result;
														SetDawnPrice(val3, val3.RoutePrice);
													}
												}
												else
												{
													val3.IsRouteLocked = true;
													val3.IsRouteHidden = true;
													val3.RoutePrice = 9999;
													SetDawnPrice(val3, val3.RoutePrice);
													Logger.LogDebug((object)("Moon " + val3.NumberlessPlanetName + " is locked because it is from pair " + num2 + " and the current quota/day is " + num3));
												}
											}
											else
											{
												val3.RoutePrice = result;
												SetDawnPrice(val3, val3.RoutePrice);
												val3.IsRouteLocked = false;
												val3.IsRouteHidden = false;
											}
										}
									}
									else
									{
										Logger.LogError((object)("Ironman could not find a matching level for " + pair + " in the ExtendedLevels list"));
									}
								}
							}
							num5++;
						}
					}
					return;
				}
				Logger.LogDebug((object)"Ironman is a normal moon");
				bool flag2 = false;
				List<string> list = new List<string>();
				string[] array5 = Config.IronmanMoons.Value.ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
				int num7 = 0;
				if (Config.gamemode.Value == ConfigHandler.Gamemode.QuotaIronman)
				{
					if ((Object)(object)TimeOfDay.Instance != (Object)null)
					{
						num7 = TimeOfDay.Instance.timesFulfilledQuota + 1;
						Logger.LogDebug((object)$"Current quota number is: {num7}");
					}
				}
				else if (Config.gamemode.Value == ConfigHandler.Gamemode.DayIronman && StartOfRound.Instance?.gameStats != null)
				{
					num7 = StartOfRound.Instance.gameStats.daysSpent + 1 - TimeOfDay.Instance.timesFulfilledQuota;
					Logger.LogDebug((object)$"Current day number is: {num7}");
				}
				int num8 = 0;
				string[] array6 = array5;
				foreach (string text2 in array6)
				{
					num8++;
					if (num8 != num7)
					{
						continue;
					}
					Logger.LogDebug((object)("Ironman current group is: " + text2));
					string[] array7 = text2.Split(new char[1] { '@' }, StringSplitOptions.RemoveEmptyEntries);
					int num10 = 0;
					string[] array8 = array7;
					foreach (string text3 in array8)
					{
						if (num10 != 0)
						{
							try
							{
								SelectableLevel selectableLevel = ConfigHelper.ConvertStringToLevels(text3.Trim())[0];
								ExtendedLevel val4 = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => (Object)(object)x.SelectableLevel == (Object)(object)selectableLevel);
								if ((Object)(object)val4 != (Object)null)
								{
									Logger.LogDebug((object)("Ironman adding moon " + val4.NumberlessPlanetName + " " + $"from group {num8}"));
									list.Add(val4.NumberlessPlanetName);
								}
								else
								{
									Logger.LogError((object)("Ironman could not find a matching level for " + text3));
								}
							}
							catch (Exception arg)
							{
								Logger.LogError((object)$"Ironman error when trying to parse {text3}: {arg}");
							}
						}
						num10++;
					}
					break;
				}
				{
					foreach (ExtendedLevel extendedLevel in PatchedContent.ExtendedLevels)
					{
						if (!(extendedLevel.NumberlessPlanetName != "Gordion") || !(extendedLevel.NumberlessPlanetName != "Galetry") || !(extendedLevel.NumberlessPlanetName != "Oxyde"))
						{
							continue;
						}
						bool flag3 = false;
						foreach (string item in list)
						{
							Logger.LogDebug((object)("Ironman current level checked is " + extendedLevel.NumberlessPlanetName + " vs. " + item));
							if (extendedLevel.NumberlessPlanetName == item)
							{
								Logger.LogDebug((object)"Ironman they are a match");
								flag3 = true;
							}
							else
							{
								Logger.LogDebug((object)"Ironman they are not a match");
							}
						}
						if (!flag3)
						{
							extendedLevel.RoutePrice = 9999;
							SetDawnPrice(extendedLevel, extendedLevel.RoutePrice);
							extendedLevel.IsRouteLocked = true;
							extendedLevel.IsRouteHidden = false;
						}
						else
						{
							extendedLevel.RoutePrice = 0;
							SetDawnPrice(extendedLevel, extendedLevel.RoutePrice);
							extendedLevel.IsRouteLocked = false;
							extendedLevel.IsRouteHidden = false;
						}
					}
					return;
				}
			}
			if (Config.gamemode.Value == ConfigHandler.Gamemode.SMHQ)
			{
				Logger.LogDebug((object)"SMHQ Mode Detected");
				string[] array9 = Config.SMHQMoons.Value.ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
				List<string> list2 = new List<string>();
				string[] array10 = array9;
				foreach (string text4 in array10)
				{
					Logger.LogDebug((object)("SMHQ currently on entry " + text4));
					try
					{
						SelectableLevel selectableLevel2 = ConfigHelper.ConvertStringToLevels(text4.Trim())[0];
						ExtendedLevel val5 = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => (Object)(object)x.SelectableLevel == (Object)(object)selectableLevel2);
						if ((Object)(object)val5 != (Object)null)
						{
							Logger.LogDebug((object)("SMHQ allowing moon " + val5.NumberlessPlanetName));
							list2.Add(val5.NumberlessPlanetName);
							val5.RoutePrice = 0;
							SetDawnPrice(val5, val5.RoutePrice);
							val5.IsRouteLocked = false;
							val5.IsRouteHidden = false;
						}
						else
						{
							Logger.LogError((object)("SMHQ could not find a matching level for " + text4));
						}
					}
					catch (Exception ex2)
					{
						Logger.LogError((object)("SMHQ error when trying to parse " + text4 + ": " + ex2));
					}
				}
				{
					foreach (ExtendedLevel extendedLevel2 in PatchedContent.ExtendedLevels)
					{
						if (extendedLevel2.NumberlessPlanetName == "Gordion" || extendedLevel2.NumberlessPlanetName == "Galetry" || extendedLevel2.NumberlessPlanetName == "Oxyde")
						{
							continue;
						}
						bool flag4 = false;
						foreach (string item2 in list2)
						{
							Logger.LogDebug((object)("SMHQ current level checked is " + extendedLevel2.NumberlessPlanetName + " vs. " + item2));
							if (extendedLevel2.NumberlessPlanetName == item2)
							{
								Logger.LogDebug((object)"SMHQ they are a match");
								flag4 = true;
								break;
							}
						}
						if (!flag4)
						{
							Logger.LogDebug((object)("SMHQ locking moon " + extendedLevel2.NumberlessPlanetName));
							extendedLevel2.RoutePrice = 9999;
							SetDawnPrice(extendedLevel2, extendedLevel2.RoutePrice);
							extendedLevel2.IsRouteLocked = true;
							extendedLevel2.IsRouteHidden = true;
						}
						else
						{
							Logger.LogDebug((object)("SMHQ unlocking moon " + extendedLevel2.NumberlessPlanetName));
							extendedLevel2.RoutePrice = 0;
							SetDawnPrice(extendedLevel2, extendedLevel2.RoutePrice);
							extendedLevel2.IsRouteLocked = false;
							extendedLevel2.IsRouteHidden = false;
						}
					}
					return;
				}
			}
			if (Config.gamemode.Value != ConfigHandler.Gamemode.RandomMoons)
			{
				return;
			}
			Logger.LogDebug((object)"Random Moons Mode Detected");
			RollRandomMoons();
			List<string> list3 = currentlySelectedRandomMoons;
			if (list3.Count == 0)
			{
				Logger.LogWarning((object)"Random Moons has no selected moons, skipping route restrictions");
				return;
			}
			foreach (ExtendedLevel extendedLevel3 in PatchedContent.ExtendedLevels)
			{
				if (extendedLevel3.NumberlessPlanetName == "Gordion" || extendedLevel3.NumberlessPlanetName == "Galetry" || extendedLevel3.NumberlessPlanetName == "Oxyde")
				{
					continue;
				}
				bool flag5 = false;
				foreach (string item3 in list3)
				{
					Logger.LogDebug((object)("Random Moons current level checked is " + extendedLevel3.NumberlessPlanetName + " and " + item3));
					if (extendedLevel3.NumberlessPlanetName == item3)
					{
						Logger.LogDebug((object)"Random Moons they are a match");
						flag5 = true;
						break;
					}
				}
				if (!flag5)
				{
					Logger.LogDebug((object)("Random Moons locking moon " + extendedLevel3.NumberlessPlanetName));
					extendedLevel3.RoutePrice = 9999;
					SetDawnPrice(extendedLevel3, extendedLevel3.RoutePrice);
					extendedLevel3.IsRouteLocked = true;
					extendedLevel3.IsRouteHidden = true;
				}
				else
				{
					Logger.LogDebug((object)("Random Moons unlocking moon " + extendedLevel3.NumberlessPlanetName));
					extendedLevel3.RoutePrice = 0;
					SetDawnPrice(extendedLevel3, extendedLevel3.RoutePrice);
					extendedLevel3.IsRouteLocked = false;
					extendedLevel3.IsRouteHidden = false;
				}
			}
		}

		public void CalculateMoonRiskLevels()
		{
			Logger.LogDebug((object)"Attempting CalculateMoonRiskLevels");
			if (MoonDefaultRiskLevels.Count < 1 || !Config.ApplyRiskLevelChanges.Value)
			{
				Logger.LogDebug((object)"Default moon risk levels have not been set or the option is disabled, skipping Calculation of moon risk levels");
				return;
			}
			Logger.LogDebug((object)"Default moon risk levels have been set, continuing");
			if (!Object.op_Implicit((Object)(object)StartOfRound.Instance) || !Object.op_Implicit((Object)(object)StartOfRound.Instance.currentLevel))
			{
				return;
			}
			Logger.LogDebug((object)"Got current level ref");
			if (!Config.ApplyRiskLevelChanges.Value)
			{
				return;
			}
			foreach (ExtendedLevel level in PatchedContent.ExtendedLevels)
			{
				level.SelectableLevel.riskLevel = MoonDefaultRiskLevels.Find((LevelPairedWithRisk x) => (Object)(object)x.Level == (Object)(object)level).OriginalRiskLevel;
				if (level.NumberlessPlanetName == "Gordion" || level.NumberlessPlanetName == "Galetry" || level.NumberlessPlanetName == "Oxyde")
				{
					Logger.LogDebug((object)("Current moon " + level.NumberlessPlanetName + " is company/oxyde, so no risk level changes will be applied"));
					continue;
				}
				Logger.LogDebug((object)("Current moon " + level.NumberlessPlanetName + " is not company/oxyde, so risk level changes will be applied"));
				bool isCombined;
				float floatRiskLevel = Utils.ConvertRiskLevelToFloat(level.SelectableLevel.riskLevel) + GetWeatherRiskLevelFloat(WeatherManager.GetCurrentWeather(level.SelectableLevel), out isCombined);
				level.SelectableLevel.riskLevel = Utils.ConvertFloatToRiskLevel(floatRiskLevel);
				if (isCombined)
				{
					SelectableLevel selectableLevel = level.SelectableLevel;
					selectableLevel.riskLevel += "?";
				}
			}
		}

		public void RollRandomMoons()
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null || !GameNetworkManager.Instance.isHostingGame || (Object)(object)TimeOfDay.Instance == (Object)null)
			{
				return;
			}
			Logger.LogDebug((object)"Attempting to roll Random Moons");
			int timesFulfilledQuota = TimeOfDay.Instance.timesFulfilledQuota;
			if (ModDataInstance.lastRandomMoonsQuota == timesFulfilledQuota && !string.IsNullOrEmpty(ModDataInstance.selectedRandomMoons))
			{
				if (lastRandomMoonsQuota != timesFulfilledQuota || currentlySelectedRandomMoons.Count == 0)
				{
					Logger.LogDebug((object)"Random Moons restoring existing selection for this quota");
					SetRandomMoons(ModDataInstance.selectedRandomMoons, ModDataInstance.lastRandomMoonsQuota);
				}
				return;
			}
			if (lastRandomMoonsQuota == timesFulfilledQuota && currentlySelectedRandomMoons.Count > 0)
			{
				Logger.LogDebug((object)"Random Moons have already been rolled for this quota");
				return;
			}
			string[] array = Config.RandomMoons.Value.ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
			List<ExtendedLevel> list = new List<ExtendedLevel>();
			string[] array2 = array;
			foreach (string text in array2)
			{
				Logger.LogDebug((object)("Random Moons currently on entry " + text));
				try
				{
					SelectableLevel selectableLevel = ConfigHelper.ConvertStringToLevels(text.Trim())[0];
					ExtendedLevel val = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => (Object)(object)x.SelectableLevel == (Object)(object)selectableLevel);
					if ((Object)(object)val != (Object)null)
					{
						if (!(val.NumberlessPlanetName == "Gordion") && !(val.NumberlessPlanetName == "Galetry") && !(val.NumberlessPlanetName == "Oxyde") && !list.Contains(val))
						{
							Logger.LogDebug((object)("Random Moons adding possible moon " + val.NumberlessPlanetName));
							list.Add(val);
						}
					}
					else
					{
						Logger.LogError((object)("Random Moons could not find a matching level for " + text));
					}
				}
				catch (Exception ex)
				{
					Logger.LogError((object)("Random Moons error when trying to parse " + text + ": " + ex));
				}
			}
			if (list.Count == 0)
			{
				Logger.LogWarning((object)"Random Moons has no valid moons to select!");
				return;
			}
			List<string> list2 = new List<string>();
			int num = Mathf.Min(Config.randomMoonAmount.Value, list.Count);
			for (int num2 = 0; num2 < num; num2++)
			{
				int index = Random.Range(0, list.Count);
				ExtendedLevel val2 = list[index];
				Logger.LogDebug((object)("Random Moons selected moon " + val2.NumberlessPlanetName));
				list2.Add(val2.NumberlessPlanetName);
				list.RemoveAt(index);
			}
			string selectedMoons = string.Join(";", list2);
			SetRandomMoons(selectedMoons, timesFulfilledQuota);
			ModDataInstance.ZMTSaveData();
			ZMTNetwork.SendRandomMoons(selectedMoons, timesFulfilledQuota);
			Logger.LogInfo((object)($"Random Moons rolled for quota {timesFulfilledQuota + 1}: " + ", " + list2));
		}

		public void SetRandomMoons(string selectedMoons, int quotaNumber)
		{
			currentlySelectedRandomMoons = new List<string>(selectedMoons.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries));
			lastRandomMoonsQuota = quotaNumber;
			ModDataInstance.selectedRandomMoons = selectedMoons;
			ModDataInstance.lastRandomMoonsQuota = quotaNumber;
			Logger.LogInfo((object)("Random Moons selection set to: " + currentlySelectedRandomMoons));
			if ((Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)StartOfRound.Instance.currentLevel != (Object)null)
			{
				CalculateMoonPrices();
			}
		}

		public void LoadRandomMoonsFromSave()
		{
			Logger.LogDebug((object)"Attempting to load Random Moons from save");
			if (ModDataInstance != null)
			{
				if (string.IsNullOrEmpty(ModDataInstance.selectedRandomMoons))
				{
					Logger.LogDebug((object)"No saved Random Moons selection found");
					return;
				}
				SetRandomMoons(ModDataInstance.selectedRandomMoons, ModDataInstance.lastRandomMoonsQuota);
				Logger.LogInfo((object)"Loaded Random Moons selection from save");
			}
		}

		public float GetWeatherRiskLevelFloat(Weather weather, out bool isCombined)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Invalid comparison between Unknown and I4
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Invalid comparison between Unknown and I4
			isCombined = false;
			float num = 0f;
			WeatherTweaksWeather val = (WeatherTweaksWeather)(object)((weather is WeatherTweaksWeather) ? weather : null);
			if (val != null)
			{
				float num2 = 0f;
				float num3 = 0f;
				float num4 = 0f;
				float num5 = 0f;
				float num6 = 0f;
				float num7 = 0f;
				List<string> list = new List<string>();
				for (int i = 0; i < val.WeatherTypes.Count; i++)
				{
					float num8 = ConvertWeatherNameToRiskFloat(val.WeatherTypes[i].WeatherName);
					num3 += num8;
					if ((int)val.CustomType == 1)
					{
						if (!list.Contains(val.WeatherTypes[i].WeatherName))
						{
							list.Add(val.WeatherTypes[i].WeatherName);
							if (val.WeatherTypes[i].WeatherName != "None" || val.WeatherTypes[i].WeatherName != "Clear" || val.WeatherTypes[i].WeatherName != "Cloudy" || val.WeatherTypes[i].WeatherName != "NightShift")
							{
								float num9 = 0.5f;
								float num10 = num9 * num8;
								num5 += num10;
							}
						}
					}
					else
					{
						float num11 = num8 / (float)val.WeatherTypes.Count;
						num5 += num11;
					}
					if (num2 < num8)
					{
						num2 = num8;
					}
				}
				num4 = num3 / (float)val.WeatherTypes.Count;
				num6 = num2 + num4 + num5;
				num7 = num5;
				num = (((int)val.CustomType != 1) ? num7 : num6);
				isCombined = true;
			}
			else
			{
				num = ConvertWeatherNameToRiskFloat(weather.Name);
			}
			return num;
		}

		public float ConvertWeatherNameToRiskFloat(string weatherName)
		{
			Logger.LogDebug((object)"Started converting weather name to risk");
			float num = 0f;
			Dictionary<string, float> dictionary = new Dictionary<string, float>();
			string[] array = Config.WeathersAndRiskLevels.Value.ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split(new char[1] { '@' }, StringSplitOptions.RemoveEmptyEntries);
				float num2 = 0f;
				if (float.TryParse(array3[1], out var result))
				{
					Logger.LogDebug((object)("Succesfully parsed " + text + "'s second part as a float (" + result + ")"));
					num2 = result;
				}
				else
				{
					Logger.LogDebug((object)("Couldn't parse " + text + "'s second part as a float, so setting to default value instead"));
					num2 = Config.DefaultWeatherRiskLevelIncrease.Value;
				}
				Logger.LogDebug((object)("Now trying to parse weather " + array3[0] + " in the ConfigHelper"));
				List<Weather> list = new List<Weather>();
				try
				{
					list = ConfigHelper.ResolveStringToWeathers(array3[0]);
				}
				catch (Exception)
				{
					Logger.LogDebug((object)("Exception caught, Could not resolve weather " + text + " in the ConfigHelper"));
				}
				bool flag = false;
				string text2 = "";
				foreach (Weather weather in list)
				{
					try
					{
						WeatherManager.Weathers.Find((Weather x) => x.Name == weather.name);
						Logger.LogDebug((object)("Found weather " + text + " in the WeatherManager"));
						flag = true;
						text2 = weather.Name;
					}
					catch (Exception)
					{
						Logger.LogDebug((object)("Exception caught, could not find " + text + " in the WeatherManager"));
					}
				}
				if (flag)
				{
					try
					{
						dictionary.Add(text2, num2);
						Logger.LogDebug((object)("Added " + text2 + " to the Config Dictionary, with a value of " + num2));
					}
					catch (ArgumentException)
					{
						Logger.LogDebug((object)("Couldn't add weather " + array3[0] + " to Config Dictionary as it is already in there"));
					}
				}
				else
				{
					Logger.LogDebug((object)("Couldn't find weather " + array3[0] + ", so it will not be added to the Config Dictionary"));
				}
			}
			float value = Config.DefaultWeatherRiskLevelIncrease.Value;
			if (dictionary.TryGetValue(ConfigHelper.ResolveStringToWeather(weatherName).Name, out value))
			{
				Logger.LogDebug((object)("Found weather " + weatherName + " in Dictionary of weathers from config, outputting it's risk level"));
				return value;
			}
			Logger.LogDebug((object)("Could not find weather " + weatherName + " in Dictionary of weathers from config, risk level will be default"));
			return Config.DefaultWeatherRiskLevelIncrease.Value;
		}

		public void SaveDefaultMoonRiskLevels()
		{
			Logger.LogDebug((object)"Attempting to save moon default difficulty ratings");
			if (MoonDefaultRiskLevels.Count > 1)
			{
				Logger.LogDebug((object)"Default difficulty levels have already have been set, skipping");
				return;
			}
			int num = 0;
			foreach (ExtendedLevel extendedLevel in PatchedContent.ExtendedLevels)
			{
				LevelPairedWithRisk levelPairedWithRisk = new LevelPairedWithRisk();
				levelPairedWithRisk.Level = extendedLevel;
				levelPairedWithRisk.OriginalRiskLevel = extendedLevel.SelectableLevel.riskLevel;
				MoonDefaultRiskLevels.Add(levelPairedWithRisk);
				Logger.LogDebug((object)("Saved " + extendedLevel.NumberlessPlanetName + " default difficulty level as " + extendedLevel.SelectableLevel.riskLevel));
				num++;
			}
			Logger.LogDebug((object)"Finished setting moon default risk levels");
		}

		public void SaveDefaultMoonPrices()
		{
			Logger.LogDebug((object)"Attempting to save moon default prices");
			Logger.LogDebug((object)("ExtendedLevels Count is: " + PatchedContent.ExtendedLevels.Count));
			if (MoonDefaultCosts.Count > 1)
			{
				Logger.LogDebug((object)"Default prices already have been set, skipping");
				return;
			}
			int num = 0;
			foreach (ExtendedLevel extendedLevel in PatchedContent.ExtendedLevels)
			{
				Logger.LogDebug((object)"In loop");
				Logger.LogDebug((object)("Looping through level, current is: " + extendedLevel.NumberlessPlanetName));
				LevelPairedWithPrice levelPairedWithPrice = new LevelPairedWithPrice();
				levelPairedWithPrice.Level = extendedLevel;
				levelPairedWithPrice.OriginalPrice = extendedLevel.RoutePrice;
				MoonDefaultCosts.Add(levelPairedWithPrice);
				Logger.LogDebug((object)("Saved " + extendedLevel.NumberlessPlanetName + " default price as " + extendedLevel.RoutePrice));
				num++;
			}
			Logger.LogDebug((object)"Finished setting moon default prices");
		}
	}
	public class ModData
	{
		[ModData(/*Could not decode attribute arguments.*/)]
		public bool hasReroutedCompany;

		[ModData(/*Could not decode attribute arguments.*/)]
		public bool hasReroutedMoonPair;

		[ModData(/*Could not decode attribute arguments.*/)]
		public int currentQuotaRoll;

		[ModData(/*Could not decode attribute arguments.*/)]
		public bool seedSetForQuota;

		[ModData(/*Could not decode attribute arguments.*/)]
		public string selectedRandomMoons = "";

		[ModData(/*Could not decode attribute arguments.*/)]
		public int lastRandomMoonsQuota = -1;

		[ModData(/*Could not decode attribute arguments.*/)]
		public bool isOxydeOveride;

		public void ZMTSaveData()
		{
			SaveLoadHandler.SaveData(ModDataHelper.GetModDataKey((object)this, "currentQuotaRoll"));
			SaveLoadHandler.SaveData(ModDataHelper.GetModDataKey((object)this, "seedSetForQuota"));
			SaveLoadHandler.SaveData(ModDataHelper.GetModDataKey((object)this, "hasReroutedCompany"));
			SaveLoadHandler.SaveData(ModDataHelper.GetModDataKey((object)this, "hasReroutedMoonPair"));
			SaveLoadHandler.SaveData(ModDataHelper.GetModDataKey((object)this, "isOxydeOveride"));
			SaveLoadHandler.SaveData(ModDataHelper.GetModDataKey((object)this, "selectedRandomMoons"));
			SaveLoadHandler.SaveData(ModDataHelper.GetModDataKey((object)this, "lastRandomMoonsQuota"));
		}

		public void ZMTLoadData()
		{
			SaveLoadHandler.LoadData(ModDataHelper.GetModDataKey((object)this, "currentQuotaRoll"));
			SaveLoadHandler.LoadData(ModDataHelper.GetModDataKey((object)this, "seedSetForQuota"));
			SaveLoadHandler.LoadData(ModDataHelper.GetModDataKey((object)this, "hasReroutedCompany"));
			SaveLoadHandler.LoadData(ModDataHelper.GetModDataKey((object)this, "hasReroutedMoonPair"));
			SaveLoadHandler.LoadData(ModDataHelper.GetModDataKey((object)this, "isOxydeOveride"));
			SaveLoadHandler.LoadData(ModDataHelper.GetModDataKey((object)this, "selectedRandomMoons"));
			SaveLoadHandler.LoadData(ModDataHelper.GetModDataKey((object)this, "lastRandomMoonsQuota"));
		}
	}
	internal class Patches
	{
		private delegate void SetFromServerDelegate(ProgressivePredicate instance, bool isUnlocked, bool isHidden);

		[HarmonyPatch(typeof(GrabbableObject), "ItemActivate")]
		public static class OxydeTabletActivatePatch
		{
			public static void Postfix(GrabbableObject __instance)
			{
				if (ZMTBase.Config.OxydeTabletForceUnlocksOxyde.Value && !((Object)(object)__instance.itemProperties == (Object)null) && !(__instance.itemProperties.itemName != "Oxyde Tablet"))
				{
					ZMTNetwork.SendOxydeTablet(newUnlockStatus: true);
				}
			}
		}

		[HarmonyPatch(typeof(Terminal))]
		internal class TerminalPatch
		{
			[HarmonyPatch("SetItemSales")]
			[HarmonyPostfix]
			[HarmonyPriority(0)]
			private static void SetItemSalesPatch(Terminal __instance)
			{
				if (ZMTBase.Config.noFirstDayShopSales.Value && TimeOfDay.Instance.timesFulfilledQuota < 1 && TimeOfDay.Instance.daysUntilDeadline >= 3)
				{
					for (int i = 0; i < __instance.itemSalesPercentages.Length; i++)
					{
						__instance.itemSalesPercentages[i] = 100;
					}
				}
			}

			[HarmonyPatch("Start")]
			[HarmonyPostfix]
			private static void TerminalStartPatch(ref Terminal __instance)
			{
				Logger.LogDebug((object)"Terminal patch detected");
				ZMTBase.Instance.displayedOxydeAlertForQuota = false;
				ZMTBase.Instance.SaveDefaultMoonPrices();
				ZMTBase.Instance.SaveDefaultMoonRiskLevels();
				ZMTBase.Instance.CalculateMoonPrices();
				ZMTBase.Instance.CalculateMoonRiskLevels();
				ZMTBase.Instance.SetOxydeCostFromConfigs();
			}

			[HarmonyPatch("BeginUsingTerminal")]
			[HarmonyPostfix]
			private static void TerminalBeginUsePatch(ref Terminal __instance)
			{
				Logger.LogDebug((object)"Terminal begin use patch detected");
				ZMTBase.Instance.CalculateMoonPrices();
				ZMTBase.Instance.CalculateMoonRiskLevels();
				ZMTBase.Instance.SetOxydeCostFromConfigs();
			}

			[HarmonyPatch("Update")]
			[HarmonyPostfix]
			private static void gatherGroupCreditsValue(ref int ___groupCredits)
			{
				ZMTBase.Instance.groupCredits = ___groupCredits;
			}
		}

		[HarmonyPatch(typeof(EntranceTeleport))]
		internal class InteriorNamePatch
		{
			public static bool shownToday = false;

			private static int lastShownDay = -1;

			[HarmonyPatch("TeleportPlayerClientRpc")]
			[HarmonyPostfix]
			private static void TeleportPlayerClientRPCPatch(EntranceTeleport __instance, int playerObj)
			{
				if (ZMTBase.Config.interiorNamePopup.Value && __instance.isEntranceToBuilding && !((Object)(object)StartOfRound.Instance == (Object)null))
				{
					int daysSpent = StartOfRound.Instance.gameStats.daysSpent;
					if (lastShownDay != daysSpent)
					{
						shownToday = false;
						lastShownDay = daysSpent;
						Logger.LogDebug((object)$"InteriorName: Reset popup for day {daysSpent}");
					}
					if (!shownToday && !((Object)(object)GameNetworkManager.Instance == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && !((Object)(object)__instance.playersManager == (Object)null) && __instance.playersManager.allPlayerScripts != null && playerObj >= 0 && playerObj < __instance.playersManager.allPlayerScripts.Length && !((Object)(object)__instance.playersManager.allPlayerScripts[playerObj] != (Object)(object)GameNetworkManager.Instance.localPlayerController))
					{
						Logger.LogDebug((object)"InteriorName: Local player entered through entrance");
						((MonoBehaviour)ZMTBase.Instance).StartCoroutine(ShowInteriorPopupDelayed(__instance));
					}
				}
			}

			private static void HandlePopup(EntranceTeleport __instance)
			{
				if (!__instance.isEntranceToBuilding || shownToday)
				{
					return;
				}
				string text = Utils.GetCurrentInteriorName();
				if (string.IsNullOrEmpty(text))
				{
					Logger.LogWarning((object)"InteriorName: Could not determine the current interior name!");
					return;
				}
				Logger.LogInfo((object)("Interior default name is " + text));
				string[] array = ZMTBase.Config.interiorsAndOverrides.Value.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
				bool flag = false;
				string[] array2 = array;
				foreach (string text2 in array2)
				{
					string[] array3 = text2.Split(new char[1] { '@' }, StringSplitOptions.RemoveEmptyEntries);
					if (array3.Length == 2 && array3[0].Trim().Equals(text, StringComparison.OrdinalIgnoreCase))
					{
						text = array3[1].Trim();
						flag = true;
						Logger.LogWarning((object)"Interior name found in config");
						break;
					}
				}
				if (ZMTBase.Config.fixInteriorNames.Value && !flag)
				{
					text = Utils.CleanInteriorName(text);
					Logger.LogInfo((object)("Interior name is now " + text));
				}
				string text3 = "";
				if (ZMTBase.Config.addPercentageInfo.Value)
				{
					DawnDungeonInfo currentDungeonInfo = Utils.GetCurrentDungeonInfo();
					float interiorChance = Utils.GetInteriorChance(currentDungeonInfo);
					if (interiorChance >= 0f)
					{
						text3 = $"(Interior Chance: {interiorChance:0.##}%)";
					}
				}
				Logger.LogInfo((object)("InteriorName: Displaying popup for " + text));
				HUDManager.Instance.DisplayTip(ZMTBase.Config.interiorTitlePopup.Value, ZMTBase.Config.interiorNamePrefix.Value + " " + text + " " + text3, false, false, "LC_Tip1");
				shownToday = true;
			}

			private static IEnumerator ShowInteriorPopupDelayed(EntranceTeleport entrance)
			{
				yield return (object)new WaitForSeconds(0.2f);
				if (shownToday)
				{
					yield break;
				}
				try
				{
					HandlePopup(entrance);
				}
				catch (Exception arg)
				{
					Logger.LogError((object)$"InteriorName: Error displaying popup: {arg}");
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound))]
		internal class StartOfRoundPatch
		{
			private static int lastAutoRoutedDay = -1;

			private static bool hasRequestedRandomMoons = false;

			private static bool isRequestingRandomMoons = false;

			internal static void RandomMoonsSyncReceived()
			{
				hasRequestedRandomMoons = true;
			}

			internal static void ResetRandomMoonsSync()
			{
				hasRequestedRandomMoons = false;
			}

			[HarmonyPatch("StartGame")]
			[HarmonyPrefix]
			private static void Prefix()
			{
				InteriorNamePatch.shownToday = false;
			}

			[HarmonyPatch("EndPlayersFiredSequenceClientRpc")]
			[HarmonyPostfix]
			private static void ResetHasRerouted()
			{
				ZMTBase.Instance.hasRoutedForThisQuota = false;
				ZMTBase.Instance.displayedOxydeAlertForQuota = false;
				ZMTBase.ModDataInstance.hasReroutedCompany = false;
				ZMTBase.ModDataInstance.hasReroutedMoonPair = false;
				ZMTBase.ModDataInstance.seedSetForQuota = false;
				ZMTBase.ModDataInstance.isOxydeOveride = false;
				ZMTBase.ModDataInstance.ZMTSaveData();
				if (ZMTBase.Config.RelockOxydeOnEject.Value)
				{
					ExtendedLevel val = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => x.NumberlessPlanetName == "Oxyde");
					if ((Object)(object)val != (Object)null)
					{
						LockMoon(val.SelectableLevel);
						Logger.LogInfo((object)"Oxyde is now re-locked!");
					}
				}
				if (ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.RandomMoons)
				{
					if (NetworkManager.Singleton.IsHost)
					{
						ZMTBase.Instance.ResetRandomMoons();
						ZMTBase.Instance.RollRandomMoons();
					}
					else
					{
						ResetRandomMoonsSync();
					}
				}
			}

			[HarmonyPatch("PassTimeToNextDay")]
			[HarmonyPostfix]
			private static void PassTimeToNextDay()
			{
				Logger.LogDebug((object)"PassTimeToNextDay patch detected");
				ZMTBase.Instance.CalculateMoonPrices();
				ZMTBase.Instance.CalculateMoonRiskLevels();
				ZMTBase.Instance.SetOxydeCostFromConfigs();
				if (ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.DayIronman && ZMTBase.Config.IronmanAutoRoute.Value && (Object)(object)GameNetworkManager.Instance != (Object)null && GameNetworkManager.Instance.isHostingGame && (Object)(object)StartOfRound.Instance != (Object)null && StartOfRound.Instance.CanChangeLevels() && TimeOfDay.Instance.quotaFulfilled < TimeOfDay.Instance.profitQuota)
				{
					ZMTBase.ModDataInstance.hasReroutedMoonPair = false;
					ZMTBase.Instance.rerouteShip(GameNetworkManager.Instance, toCompany: false);
				}
			}

			[HarmonyPatch("ArriveAtLevel")]
			[HarmonyPostfix]
			private static void ArriveAtLevelPatch()
			{
				Logger.LogDebug((object)"ArriveAtLevel patch detected");
				ZMTBase.Instance.CalculateMoonPrices();
				ZMTBase.Instance.CalculateMoonRiskLevels();
				ZMTBase.Instance.SetOxydeCostFromConfigs();
			}

			[HarmonyPatch("Update")]
			[HarmonyPostfix]
			private static void AutoShipToCompanyBuilding(StartOfRound __instance)
			{
				if (!Object.op_Implicit((Object)(object)StartOfRound.Instance) || !Object.op_Implicit((Object)(object)StartOfRound.Instance.currentLevel) || (Object)(object)GameNetworkManager.Instance == (Object)null || !GameNetworkManager.Instance.isHostingGame || (Object)(object)TimeOfDay.Instance == (Object)null || !StartOfRound.Instance.CanChangeLevels())
				{
					return;
				}
				bool flag = ZMTBase.Config.AutoCompanyBuilding.Value && TimeOfDay.Instance.daysUntilDeadline == 0 && TimeOfDay.Instance.quotaFulfilled < TimeOfDay.Instance.profitQuota;
				if (ZMTBase.Config.AutoCompanyBuilding.Value && !ZMTBase.Instance.hasRoutedForThisQuota && !ZMTBase.ModDataInstance.hasReroutedCompany && TimeOfDay.Instance.daysUntilDeadline == 0 && TimeOfDay.Instance.quotaFulfilled < TimeOfDay.Instance.profitQuota)
				{
					Logger.LogDebug((object)"Trying to reroute ship");
					ZMTBase.Instance.rerouteShip(GameNetworkManager.Instance, toCompany: true);
				}
				if (!flag && ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.DayIronman && ZMTBase.Config.IronmanAutoRoute.Value && TimeOfDay.Instance.quotaFulfilled < TimeOfDay.Instance.profitQuota)
				{
					int num = StartOfRound.Instance.gameStats.daysSpent + 1 - TimeOfDay.Instance.timesFulfilledQuota;
					if (lastAutoRoutedDay != num)
					{
						Logger.LogDebug((object)$"DayIronman attempting automatic routing for day {num + 1}");
						ZMTBase.ModDataInstance.hasReroutedMoonPair = false;
						ZMTBase.Instance.rerouteShip(GameNetworkManager.Instance, toCompany: false);
						lastAutoRoutedDay = num;
					}
				}
			}

			[HarmonyPatch("Update")]
			[HarmonyPostfix]
			private static void RequestRandomMoonsIfNeeded()
			{
				if (ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.RandomMoons && NetworkManager.Singleton.IsConnectedClient && !NetworkManager.Singleton.IsHost && !((Object)(object)ZMTBase.Instance == (Object)null) && !hasRequestedRandomMoons && !isRequestingRandomMoons)
				{
					((MonoBehaviour)ZMTBase.Instance).StartCoroutine(RequestRandomMoonsCoroutine());
				}
			}

			private static IEnumerator RequestRandomMoonsCoroutine()
			{
				isRequestingRandomMoons = true;
				while (!hasRequestedRandomMoons && NetworkManager.Singleton.IsConnectedClient && !NetworkManager.Singleton.IsHost)
				{
					ZMTNetwork.RequestRandomMoons();
					yield return (object)new WaitForSecondsRealtime(3f);
				}
				isRequestingRandomMoons = false;
			}

			[HarmonyPatch("ShipHasLeft")]
			[HarmonyPostfix]
			private static void ShipHasLeftPatch()
			{
				if (ZMTBase.Config.DestroyOxydeSellScrapsInOrbit.Value)
				{
					ZMTBase.Instance.CheckForScrapsToDestroy();
				}
			}

			[HarmonyPatch("Start")]
			[HarmonyPostfix]
			private static void StartOfRoundStartPatch()
			{
				if (ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.RandomMoons && NetworkManager.Singleton.IsListening && !NetworkManager.Singleton.IsHost)
				{
					Logger.LogDebug((object)"Random Moons client joined, requesting selection");
					ZMTNetwork.RequestRandomMoons();
				}
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager))]
		internal class GameNetworkManagerPatch
		{
			[HarmonyPatch("StartHost")]
			[HarmonyPostfix]
			private static void StartsHostPatch()
			{
				ZMTBase.Instance.hasRoutedForThisQuota = false;
				ZMTBase.ModDataInstance.hasReroutedCompany = false;
				ZMTBase.ModDataInstance.hasReroutedMoonPair = false;
				if (!ZMTBase.ModDataInstance.seedSetForQuota)
				{
					ZMTBase.Instance?.RollNewSeed();
				}
				ZMTBase.Instance.displayedOxydeAlertForQuota = false;
				if (ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.RandomMoons)
				{
					ZMTBase.Instance.LoadRandomMoonsFromSave();
				}
			}

			[HarmonyPatch("SaveGame")]
			[HarmonyPostfix]
			private static void SaveGameValuesPatch()
			{
				ZMTBase.Instance.CalculateMoonPrices();
				ZMTBase.Instance.CalculateMoonRiskLevels();
				ZMTBase.Instance.SetOxydeCostFromConfigs();
			}

			[HarmonyPatch("ResetSavedGameValues")]
			[HarmonyPostfix]
			private static void ResetSavedGameValuesPatch()
			{
				ZMTBase.Instance.CalculateMoonPrices();
				ZMTBase.Instance.CalculateMoonRiskLevels();
				ZMTBase.Instance.SetOxydeCostFromConfigs();
			}
		}

		[HarmonyPatch(typeof(TimeOfDay))]
		internal class TimeOfDayPatch
		{
			[HarmonyPatch("SetNewProfitQuota")]
			[HarmonyPrefix]
			private static void SetNewProfitQuotaPatchPre()
			{
				ZMTBase.Instance.hasRoutedForThisQuota = false;
				ZMTBase.Instance.displayedOxydeAlertForQuota = false;
				ZMTBase.ModDataInstance.seedSetForQuota = false;
				ZMTBase.ModDataInstance.isOxydeOveride = false;
				ZMTBase.ModDataInstance.hasReroutedCompany = false;
				ZMTBase.ModDataInstance.hasReroutedMoonPair = false;
				ZMTBase.ModDataInstance.ZMTSaveData();
				ZMTBase.Instance.RollNewSeed();
				if (ZMTBase.Config.gamemode.Value != ConfigHandler.Gamemode.RandomMoons)
				{
					ZMTBase.Instance.CalculateMoonPrices();
				}
				ZMTBase.Instance.CalculateMoonRiskLevels();
			}

			[HarmonyPostfix]
			[HarmonyPatch("SetNewProfitQuota")]
			private static void SetNewProfitQuotaPatchPost()
			{
				ZMTBase.Instance.SetOxydeCostFromConfigs();
				if (ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.RandomMoons)
				{
					if (NetworkManager.Singleton.IsHost)
					{
						Logger.LogDebug((object)"Random Moons new quota detected");
						ZMTBase.Instance.RollRandomMoons();
					}
					else
					{
						StartOfRoundPatch.ResetRandomMoonsSync();
					}
					ZMTBase.Instance.CalculateMoonPrices();
				}
			}

			[HarmonyPostfix]
			[HarmonyPatch("SetBuyingRateForDay")]
			private static void SetBuyingRateForDayPatch()
			{
				ZMTBase.Instance.ModifyBuyingRate();
			}

			[HarmonyPostfix]
			[HarmonyPatch("UpdateProfitQuotaCurrentTime")]
			private static void UpdateProfitQuotaCurrentTimePatch()
			{
				if (Object.op_Implicit((Object)(object)StartOfRound.Instance) && Object.op_Implicit((Object)(object)StartOfRound.Instance.currentLevel) && !((Object)(object)GameNetworkManager.Instance == (Object)null) && GameNetworkManager.Instance.isHostingGame && !((Object)(object)TimeOfDay.Instance == (Object)null))
				{
					bool flag = ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.QuotaIronman || ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.SMHQ || ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.RandomMoons;
					bool flag2 = ZMTBase.Config.AutoCompanyBuilding.Value && TimeOfDay.Instance.daysUntilDeadline == 0 && TimeOfDay.Instance.quotaFulfilled < TimeOfDay.Instance.profitQuota;
					if (ZMTBase.Config.IronmanAutoRoute.Value && flag && !flag2 && StartOfRound.Instance.CanChangeLevels() && !ZMTBase.ModDataInstance.hasReroutedMoonPair && TimeOfDay.Instance.quotaFulfilled < TimeOfDay.Instance.profitQuota)
					{
						Logger.LogDebug((object)"Attempting automatic moon routing");
						ZMTBase.Instance.rerouteShip(GameNetworkManager.Instance, toCompany: false);
					}
				}
			}
		}

		[HarmonyPatch(typeof(LungProp))]
		private static class LungPropPatch
		{
			[HarmonyPatch("Start")]
			[HarmonyPrefix]
			[HarmonyPriority(0)]
			private static void StartPatch(LungProp __instance)
			{
				if (ZMTBase.Config.apparatusScale.Value)
				{
					float scrapValueMultiplier = WeatherManager.GetCurrentWeather(RoundManager.Instance.currentLevel).ScrapValueMultiplier;
					float num = RoundManager.Instance.scrapValueMultiplier / (0.4f * scrapValueMultiplier);
					float num2 = Mathf.Pow(num, ZMTBase.Config.apparatusValueScaler.Value);
					((GrabbableObject)__instance).SetScrapValue(Mathf.RoundToInt((float)((GrabbableObject)__instance).scrapValue * num2));
				}
			}
		}

		[HarmonyPatch(typeof(NetworkObject))]
		internal class PreventSellScrapsOnOxydePatch
		{
			private static readonly HashSet<string> BlockedItems = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
			{
				"Shotgun", "Kitchen knife", "Coilless Coilhead", "Bracken Remains", "Cadaver Flower", "Cartridge", "Cartridge [Glitched]", "Cartridge [Racing into the Night]", "CartridgeRDA", "Cartridge [ReDreaming Angel]",
				"CartridgeRITN", "Clay Surgeon Scissors", "Coil-Head Core", "Common Enemy Remains", "Dead Baboon Hawk", "Dead Backwater Gunkfish", "Dead Bunker Spider", "Dead Hoarder Bug", "Dead Hygrodere", "Dead Maneater",
				"Dead Manticoil", "Dead Nutcracker", "Dead Snare Flea", "Dead Spore Lizard", "Dead Thumper", "Dead Tulip Snake", "Eyeless Dog Teeth", "Feiopar Head", "Forest Keeper Sapling", "Jester Box",
				"Kidnapper Fox Tail", "Old Bird Core", "Rare Enemy Remains", "Strange Device", "UltraRare Enemy Remains", "Vials of Ectoplasm"
			};

			[HarmonyPostfix]
			[HarmonyPatch(typeof(NetworkObject), "Spawn")]
			private static void NetworkObjectSpawnPost(NetworkObject __instance)
			{
				if (!ZMTBase.Config.PreventSellScrapsOnOxyde.Value || !NetworkManager.Singleton.IsServer || (Object)(object)StartOfRound.Instance?.currentLevel == (Object)null)
				{
					return;
				}
				ExtendedLevel val = PatchedContent.ExtendedLevels.Find((ExtendedLevel x) => (Object)(object)x.SelectableLevel == (Object)(object)StartOfRound.Instance.currentLevel);
				if ((Object)(object)val == (Object)null || val.NumberlessPlanetName != "Oxyde")
				{
					return;
				}
				GrabbableObject component = ((Component)__instance).GetComponent<GrabbableObject>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.itemProperties == (Object)null))
				{
					string text = component.itemProperties.itemName?.Trim();
					if (!string.IsNullOrEmpty(text) && (component is ShotgunItem || BlockedItems.Contains(text)))
					{
						((MonoBehaviour)ZMTBase.Instance).StartCoroutine(DespawnBlockedItem(__instance, component));
					}
				}
			}

			private static IEnumerator DespawnBlockedItem(NetworkObject networkObject, GrabbableObject grabbable)
			{
				yield return (object)new WaitForSeconds(0.25f);
				if (!networkObject.IsSpawned || !NetworkManager.Singleton.IsServer || (Object)(object)grabbable == (Object)null)
				{
					yield break;
				}
				ShotgunItem shotgun = (ShotgunItem)(object)((grabbable is ShotgunItem) ? grabbable : null);
				if (shotgun != null)
				{
					NutcrackerEnemyAI[] nutcrackers = Object.FindObjectsOfType<NutcrackerEnemyAI>();
					NutcrackerEnemyAI[] array = nutcrackers;
					foreach (NutcrackerEnemyAI nutcracker in array)
					{
						if ((Object)(object)nutcracker != (Object)null && !((EnemyAI)nutcracker).isEnemyDead && (Object)(object)nutcracker.gun == (Object)(object)shotgun)
						{
							Logger.LogDebug((object)"Preserving Nutcracker shotgun");
							yield break;
						}
					}
				}
				Logger.LogWarning((object)("Removing " + grabbable.itemProperties.itemName + " on Oxyde"));
				networkObject.Despawn(true);
			}
		}

		[HarmonyPatch(typeof(RagdollGrabbableObject))]
		internal static class PlayerBodyValuePatch
		{
			[HarmonyPatch("Start")]
			[HarmonyPostfix]
			private static void StartPostPatch(RagdollGrabbableObject __instance)
			{
				if (ZMTBase.Config.bodies0Value.Value)
				{
					((GrabbableObject)__instance).SetScrapValue(0);
				}
			}
		}

		public static ManualLogSource Logger = ZMTBase.Logger;

		private static readonly SetFromServerDelegate? SetFromServer = AccessTools.MethodDelegate<SetFromServerDelegate>(AccessTools.Method(typeof(ProgressivePredicate), "SetFromServer", (Type[])null, (Type[])null), (object)null, true);

		private static void LockMoon(SelectableLevel level)
		{
			DawnMoonInfo dawnInfo = SelectableLevelExtensions.GetDawnInfo(level);
			ITerminalPurchasePredicate obj = ((dawnInfo != null) ? dawnInfo.DawnPurchaseInfo.PurchasePredicate : null);
			ProgressivePredicate val = (ProgressivePredicate)(object)((obj is ProgressivePredicate) ? obj : null);
			if (!((Object)(object)val == (Object)null))
			{
				if (SetFromServer == null)
				{
					Logger.LogError((object)"Could not find ProgressivePredicate.SetFromServer!");
				}
				else
				{
					SetFromServer(val, isUnlocked: false, val.ProgressiveStates.IsHidden);
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string modGUID = "ZetaArcade.ZetasMoonTweaks";

		public const string modName = "ZetasMoonTweaks";

		public const string modVersion = "1.1.12";
	}
	internal static class Utils
	{
		public static float SwapLetterForRiskFloat(char target)
		{
			float num = 0f;
			return target switch
			{
				'X' => 10f, 
				'S' => 6f, 
				'A' => 5f, 
				'B' => 4f, 
				'C' => 3f, 
				'D' => 2f, 
				'E' => 1f, 
				'F' => 0f, 
				_ => 0f, 
			};
		}

		public static float SwapSymbolsForRiskFloat(string target)
		{
			float num = 0f;
			return target switch
			{
				"-" => 0.31f, 
				"+" => 0.66f, 
				"++" => 0.76f, 
				"*" => 0.86f, 
				_ => 0.5f, 
			};
		}

		public static string SwapIntForRiskLetter(int riskInt)
		{
			string text = "";
			if (riskInt > 9)
			{
				return "X";
			}
			if (riskInt > 5)
			{
				return "S";
			}
			return riskInt switch
			{
				0 => "F", 
				1 => "E", 
				2 => "D", 
				3 => "C", 
				4 => "B", 
				5 => "A", 
				6 => "S", 
				10 => "X", 
				_ => "?", 
			};
		}

		public static string SwapFloatDecimalsForRiskSymbol(float riskFloat)
		{
			float num = riskFloat - (float)Math.Floor(riskFloat);
			if (num >= 0.81f)
			{
				return "*";
			}
			if (num >= 0.71f)
			{
				return "++";
			}
			if (num >= 0.58f)
			{
				return "+";
			}
			if (num >= 0.405f)
			{
				return "";
			}
			return "-";
		}

		public static float ConvertRiskLevelToFloat(string riskLevel)
		{
			float num = 0f;
			float num2 = 0f;
			float num3 = 0f;
			char[] array = riskLevel.ToCharArray();
			num2 = SwapLetterForRiskFloat(array[0]);
			string text = riskLevel.TrimStart(array[0]);
			num3 = ((text.Length <= 0) ? 0.5f : SwapSymbolsForRiskFloat(text));
			ZMTBase.Logger.LogDebug((object)("Converted " + riskLevel + " to " + num2 + " + " + num3));
			return num2 + num3;
		}

		public static string ConvertFloatToRiskLevel(float floatRiskLevel)
		{
			string text = "";
			string text2 = SwapIntForRiskLetter((int)floatRiskLevel);
			string text3 = SwapFloatDecimalsForRiskSymbol(floatRiskLevel);
			return text2 + text3;
		}

		public static string CleanInteriorName(string interiorName)
		{
			interiorName = interiorName.Replace("(Clone)", "").Replace("DungeonFlow", "").Replace("Flow", "")
				.Replace("Dungeon", "")
				.Trim();
			interiorName = Regex.Replace(interiorName, "([a-z])([A-Z])", "$1 $2");
			interiorName = Regex.Replace(interiorName, "\\s+", " ").Trim();
			return interiorName;
		}

		public static string? GetCurrentInteriorName()
		{
			RuntimeDungeon val = RoundManager.Instance?.dungeonGenerator;
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			DungeonGenerator generator = val.Generator;
			object result;
			if (generator == null)
			{
				result = null;
			}
			else
			{
				DungeonFlow dungeonFlow = generator.DungeonFlow;
				result = ((dungeonFlow != null) ? ((Object)dungeonFlow).name : null);
			}
			return (string?)result;
		}

		public static DawnDungeonInfo? GetCurrentDungeonInfo()
		{
			DungeonFlow val = RoundManager.Instance?.dungeonGenerator?.Generator?.DungeonFlow;
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			return DungeonFlowExtensions.GetDawnInfo(val);
		}

		public static float GetInteriorChance(DawnDungeonInfo? selectedDungeon)
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			if (selectedDungeon == null)
			{
				return -1f;
			}
			SelectableLevel currentLevel = StartOfRound.Instance.currentLevel;
			if ((Object)(object)currentLevel == (Object)null)
			{
				return -1f;
			}
			DawnMoonInfo val = ((Registry<DawnMoonInfo>)(object)LethalContent.Moons).Values.FirstOrDefault((Func<DawnMoonInfo, bool>)((DawnMoonInfo m) => (Object)(object)m.Level == (Object)(object)currentLevel));
			if (val == null)
			{
				return -1f;
			}
			WeatherEffect currentWeatherEffect = TimeOfDayRefs.GetCurrentWeatherEffect(val.Level);
			DawnWeatherEffectInfo val2 = null;
			if (currentWeatherEffect != null)
			{
				MethodInfo method = typeof(WeatherEffectExtensions).GetMethod("GetDawnInfo", BindingFlags.Static | BindingFlags.NonPublic);
				if (method != null)
				{
					object? obj = method.Invoke(null, new object[1] { currentWeatherEffect });
					val2 = (DawnWeatherEffectInfo)((obj is DawnWeatherEffectInfo) ? obj : null);
				}
			}
			SpawnWeightContext val3 = new SpawnWeightContext(val, (DawnDungeonInfo)null, val2);
			SpawnWeightContext val4 = ((SpawnWeightContext)(ref val3)).WithExtra<int>(SpawnWeightExtraKeys.RoutingPriceKey, val.DawnPurchaseInfo.Cost.Provide());
			float num = 0f;
			float num2 = 0f;
			foreach (DawnDungeonInfo value in ((Registry<DawnDungeonInfo>)(object)LethalContent.Dungeons).Values)
			{
				float num3 = ((float?)value.Weights.GetFor(val, ref val4)) ?? 0f;
				if (!(num3 <= 0f))
				{
					num += num3;
					if (value == selectedDungeon)
					{
						num2 = num3;
					}
				}
			}
			if (num <= 0f || num2 <= 0f)
			{
				return -1f;
			}
			return num2 / num * 100f;
		}
	}
	internal class ZMTNetwork
	{
		public class SeedMessage
		{
			public int seed;
		}

		public class ItemPickup
		{
			public ulong playerID;

			public int slot;
		}

		public class OxydeTablet
		{
			public bool NewUnlockStatus;
		}

		public class RandomMoonsMessage
		{
			public string selectedMoons;

			public int quotaNumber;
		}

		public class RandomMoonsRequest
		{
			public bool requestSelection;
		}

		public static LNetworkMessage<SeedMessage> NewSeedMessage;

		public static LNetworkMessage<ItemPickup> ItemDestroyMessage;

		public static LNetworkMessage<OxydeTablet> OxydeTabletMessage;

		public static LNetworkMessage<RandomMoonsMessage> RandomMoonsNetworkMessage;

		public static LNetworkMessage<RandomMoonsRequest> RandomMoonsRequestMessage;

		public static void Init()
		{
			NewSeedMessage = LNetworkMessage<SeedMessage>.Create("SeedSent", (Action<SeedMessage, ulong>)null, (Action<SeedMessage>)OnNewSeed, (Action<SeedMessage, ulong>)null);
			ItemDestroyMessage = LNetworkMessage<ItemPickup>.Create("ItemDestroy", (Action<ItemPickup, ulong>)OnItemDestroy, (Action<ItemPickup>)null, (Action<ItemPickup, ulong>)null);
			OxydeTabletMessage = LNetworkMessage<OxydeTablet>.Create("OxydeTablet", (Action<OxydeTablet, ulong>)OnOxydeTablet, (Action<OxydeTablet>)null, (Action<OxydeTablet, ulong>)null);
			RandomMoonsNetworkMessage = LNetworkMessage<RandomMoonsMessage>.Create("RandomMoonsSent", (Action<RandomMoonsMessage, ulong>)null, (Action<RandomMoonsMessage>)OnRandomMoonsReceived, (Action<RandomMoonsMessage, ulong>)null);
			RandomMoonsRequestMessage = LNetworkMessage<RandomMoonsRequest>.Create("RandomMoonsRequest", (Action<RandomMoonsRequest, ulong>)OnRandomMoonsRequest, (Action<RandomMoonsRequest>)null, (Action<RandomMoonsRequest, ulong>)null);
		}

		private static void OnNewSeed(SeedMessage message)
		{
			if (!((Object)(object)ZMTBase.Instance == (Object)null))
			{
				ZMTBase.Instance.SetNewSeed(message.seed);
			}
		}

		public static void SendNewSeed(int seed)
		{
			if (NetworkManager.Singleton.IsListening && NetworkManager.Singleton.IsHost)
			{
				NewSeedMessage.SendClients(new SeedMessage
				{
					seed = seed
				});
			}
		}

		private static void OnOxydeTablet(OxydeTablet message, ulong senderClientId)
		{
			if (NetworkManager.Singleton.IsHost && !((Object)(object)ZMTBase.Instance == (Object)null))
			{
				ZMTBase.Instance.UpdateOxydeTabletStatus(message.NewUnlockStatus);
				OxydeTabletMessage.SendClients(new OxydeTablet
				{
					NewUnlockStatus = message.NewUnlockStatus
				});
			}
		}

		public static void SendOxydeTablet(bool newUnlockStatus)
		{
			if (NetworkManager.Singleton.IsListening)
			{
				OxydeTabletMessage.SendServer(new OxydeTablet
				{
					NewUnlockStatus = newUnlockStatus
				});
			}
		}

		private static void OnItemDestroy(ItemPickup message, ulong senderClientId)
		{
			if (NetworkManager.Singleton.IsHost && !((Object)(object)ZMTBase.Instance == (Object)null))
			{
				ZMTBase.Instance.DestroyScrapInSlot(message.playerID, message.slot);
			}
		}

		public static void SendItemDestroy(ulong playerID, int slot)
		{
			if (NetworkManager.Singleton.IsListening)
			{
				ItemDestroyMessage.SendServer(new ItemPickup
				{
					playerID = playerID,
					slot = slot
				});
			}
		}

		private static void OnRandomMoonsReceived(RandomMoonsMessage message)
		{
			if (!NetworkManager.Singleton.IsHost && !((Object)(object)ZMTBase.Instance == (Object)null) && ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.RandomMoons && !string.IsNullOrWhiteSpace(message.selectedMoons))
			{
				ZMTBase.Logger.LogInfo((object)("Received Random Moons selection from host: " + $"Quota {message.quotaNumber + 1}, Moons: {message.selectedMoons}"));
				ZMTBase.Instance.SetRandomMoons(message.selectedMoons, message.quotaNumber);
				Patches.StartOfRoundPatch.RandomMoonsSyncReceived();
			}
		}

		private static void OnRandomMoonsRequest(RandomMoonsRequest message, ulong senderClientId)
		{
			if (NetworkManager.Singleton.IsHost && !((Object)(object)ZMTBase.Instance == (Object)null) && ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.RandomMoons)
			{
				if (ZMTBase.Instance.currentlySelectedRandomMoons.Count == 0)
				{
					ZMTBase.Logger.LogWarning((object)$"Random Moons request received from client {senderClientId}, but no moons have been selected!");
					return;
				}
				string text = string.Join(";", ZMTBase.Instance.currentlySelectedRandomMoons);
				int lastRandomMoonsQuota = ZMTBase.Instance.lastRandomMoonsQuota;
				ZMTBase.Logger.LogInfo((object)($"Sending Random Moons selection to client {senderClientId}: " + $"Quota {lastRandomMoonsQuota + 1}, Moons: {text}"));
				RandomMoonsNetworkMessage.SendClient(new RandomMoonsMessage
				{
					selectedMoons = text,
					quotaNumber = lastRandomMoonsQuota
				}, senderClientId);
			}
		}

		public static void RequestRandomMoons()
		{
			if (NetworkManager.Singleton.IsListening && !NetworkManager.Singleton.IsHost && ZMTBase.Config.gamemode.Value == ConfigHandler.Gamemode.RandomMoons)
			{
				ZMTBase.Logger.LogDebug((object)"Requesting Random Moons selection from host");
				RandomMoonsRequestMessage.SendServer(new RandomMoonsRequest
				{
					requestSelection = true
				});
			}
		}

		public static void SendRandomMoons(string selectedMoons, int quotaNumber)
		{
			if (NetworkManager.Singleton.IsListening && NetworkManager.Singleton.IsHost)
			{
				RandomMoonsNetworkMessage.SendClients(new RandomMoonsMessage
				{
					selectedMoons = selectedMoons,
					quotaNumber = quotaNumber
				});
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace ZetasMoonTweaks.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}