Decompiled source of Selenes Choice v2.4.3

Selene's Choice/Selenes_Choice.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.Serialization;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CSync.Extensions;
using CSync.Lib;
using HarmonyLib;
using LethalLevelLoader;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using WeatherRegistry;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("Selenes_Choice")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+576d3a18986067fdc9e71d47bced8850d6daba06")]
[assembly: AssemblyProduct("Selenes_Choice")]
[assembly: AssemblyTitle("Selenes_Choice")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Selenes_Choice;

public static class CommonShuffle
{
	public static int FreeMoonsPicked;

	public static int RareMoonsPicked;

	public static int PaidMoonsPicked;

	public static int RandomMoonsPicked;

	public static string FreMNs;

	public static string RarMNs;

	public static string PaiMNs;

	public static string RanMNs;

	public static void ShuffleMoons(int Seed)
	{
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0646: Unknown result type (might be due to invalid IL or missing references)
		Selenes_Choice.LastUsedSeed = Seed;
		ES3.Save<int>("LastUsedSeed", Selenes_Choice.LastUsedSeed, GameNetworkManager.Instance.currentSaveFileName);
		PriceManager.ResetPrices();
		UpdateConfig.Instance.BracketMoons();
		List<ExtendedLevel> source = PatchedContent.ExtendedLevels.Where((ExtendedLevel level) => !ListProcessor.Instance.ExclusionList.Split(',').Any((string b) => level.NumberlessPlanetName.Equals(b))).ToList();
		List<ExtendedLevel> list = source.Where((ExtendedLevel level) => !UpdateConfig.RecentlyVisitedMoons.Contains(level)).ToList();
		foreach (ExtendedLevel item in list)
		{
			item.IsRouteLocked = false;
			item.IsRouteHidden = true;
		}
		List<ExtendedLevel> list2 = list.Where((ExtendedLevel level) => level.RoutePrice == 0).ToList();
		List<ExtendedLevel> list3 = list.Where((ExtendedLevel level) => level.RoutePrice != 0).ToList();
		List<ExtendedLevel> list4 = list3.Where((ExtendedLevel level) => level.RoutePrice >= SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.ValueThreshold)).ToList();
		ExtendedLevel val = null;
		ExtendedLevel val2 = null;
		ExtendedLevel val3 = null;
		ExtendedLevel val4 = null;
		Selenes_Choice.instance.mls.LogInfo((object)("Seed " + Seed));
		Random random = new Random(Seed);
		if (UpdateConfig.freeMoonCount > 0)
		{
			int index = random.Next(list2.Count);
			val = list2[index];
			val.IsRouteHidden = false;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.ClearWeather))
			{
				if (WeatherRegistryCompatibility.enabled)
				{
					WeatherRegistryCompatibility.ClearWeatherWithWR(val);
				}
				else
				{
					val.SelectableLevel.currentWeather = (LevelWeatherType)(-1);
				}
			}
			list2.Remove(val);
			list.Remove(val);
			FreeMoonsPicked++;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberMoons))
			{
				UpdateConfig.RecentlyVisitedMoons.Add(val);
			}
			Selenes_Choice.PreviousSafetyMoon = val;
			Selenes_Choice.instance.mls.LogInfo((object)("Free Safety Moon: " + val.SelectableLevel.PlanetName));
			FreMNs = FreMNs + val.NumberlessPlanetName + ",";
			UpdateConfig.freeMoonCount--;
			Selenes_Choice.SafetyType = 0;
		}
		else if (UpdateConfig.randomMoonCount > 0)
		{
			int index2 = random.Next(list.Count);
			val2 = list[index2];
			val2.IsRouteHidden = false;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.ClearWeather))
			{
				if (WeatherRegistryCompatibility.enabled)
				{
					WeatherRegistryCompatibility.ClearWeatherWithWR(val2);
				}
				else
				{
					val2.SelectableLevel.currentWeather = (LevelWeatherType)(-1);
				}
			}
			list.Remove(val2);
			list3.Remove(val2);
			list4.Remove(val2);
			RandomMoonsPicked++;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberMoons))
			{
				UpdateConfig.RecentlyVisitedMoons.Add(val2);
			}
			Selenes_Choice.PreviousSafetyMoon = val2;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.DiscountMoons))
			{
				PriceManager.originalPrices[val2] = val2.RoutePrice;
				int seed = Seed + Selenes_Choice.glump;
				Random random2 = new Random(seed);
				int num = random.Next(UpdateConfig.minDiscount, UpdateConfig.maxDiscount + 1);
				int num2 = 100 - num;
				float num3 = (float)num2 / 100f;
				val2.RoutePrice = (int)((float)val2.RoutePrice * num3);
				Selenes_Choice.glump++;
			}
			Selenes_Choice.instance.mls.LogInfo((object)("Random Safety Moon: " + val2.SelectableLevel.PlanetName));
			RanMNs = RanMNs + val2.NumberlessPlanetName + ",";
			UpdateConfig.randomMoonCount--;
			Selenes_Choice.SafetyType = 1;
		}
		else if (UpdateConfig.paidMoonCount > 0)
		{
			int index3 = random.Next(list3.Count);
			val3 = list3[index3];
			val3.IsRouteHidden = false;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.ClearWeather))
			{
				if (WeatherRegistryCompatibility.enabled)
				{
					WeatherRegistryCompatibility.ClearWeatherWithWR(val3);
				}
				else
				{
					val3.SelectableLevel.currentWeather = (LevelWeatherType)(-1);
				}
			}
			list.Remove(val3);
			list3.Remove(val3);
			list4.Remove(val3);
			PaidMoonsPicked++;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberMoons))
			{
				UpdateConfig.RecentlyVisitedMoons.Add(val3);
			}
			Selenes_Choice.PreviousSafetyMoon = val3;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.DiscountMoons))
			{
				PriceManager.originalPrices[val3] = val3.RoutePrice;
				int seed2 = Seed + Selenes_Choice.glump;
				Random random3 = new Random(seed2);
				int num4 = random.Next(UpdateConfig.minDiscount, UpdateConfig.maxDiscount + 1);
				int num5 = 100 - num4;
				float num6 = (float)num5 / 100f;
				val3.RoutePrice = (int)((float)val3.RoutePrice * num6);
				Selenes_Choice.glump++;
			}
			Selenes_Choice.instance.mls.LogInfo((object)("Paid Safety Moon: " + val3.SelectableLevel.PlanetName));
			PaiMNs = PaiMNs + val3.NumberlessPlanetName + ",";
			UpdateConfig.paidMoonCount--;
			Selenes_Choice.SafetyType = 2;
		}
		else if (UpdateConfig.rareMoonCount > 0)
		{
			int index4 = random.Next(list4.Count);
			val4 = list4[index4];
			val4.IsRouteHidden = false;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.ClearWeather))
			{
				if (WeatherRegistryCompatibility.enabled)
				{
					WeatherRegistryCompatibility.ClearWeatherWithWR(val4);
				}
				else
				{
					val4.SelectableLevel.currentWeather = (LevelWeatherType)(-1);
				}
			}
			list.Remove(val4);
			list3.Remove(val4);
			list4.Remove(val4);
			RareMoonsPicked++;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberMoons))
			{
				UpdateConfig.RecentlyVisitedMoons.Add(val4);
			}
			Selenes_Choice.PreviousSafetyMoon = val4;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.DiscountMoons))
			{
				PriceManager.originalPrices[val4] = val4.RoutePrice;
				int seed3 = Seed + Selenes_Choice.glump;
				Random random4 = new Random(seed3);
				int num7 = random.Next(UpdateConfig.minDiscount, UpdateConfig.maxDiscount + 1);
				int num8 = 100 - num7;
				float num9 = (float)num8 / 100f;
				val4.RoutePrice = (int)((float)val4.RoutePrice * num9);
				Selenes_Choice.glump++;
			}
			Selenes_Choice.instance.mls.LogInfo((object)("Rare Safety Moon: " + val4.SelectableLevel.PlanetName));
			RarMNs = RarMNs + val4.NumberlessPlanetName + ",";
			UpdateConfig.rareMoonCount--;
			Selenes_Choice.SafetyType = 3;
		}
		else
		{
			Selenes_Choice.instance.mls.LogInfo((object)"You gotta have at least one moon in the shuffle foo");
		}
		if (UpdateConfig.freeMoonCount > 0)
		{
			for (int i = 0; i < UpdateConfig.freeMoonCount; i++)
			{
				int index5 = random.Next(list2.Count);
				ExtendedLevel val5 = list2[index5];
				val5.IsRouteHidden = false;
				list2.Remove(val5);
				list.Remove(val5);
				FreeMoonsPicked++;
				if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberMoons) && SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberAll))
				{
					UpdateConfig.RecentlyVisitedMoons.Add(val5);
				}
				FreMNs = FreMNs + val5.NumberlessPlanetName + ",";
			}
		}
		if (UpdateConfig.rareMoonCount > 0)
		{
			for (int j = 0; j < UpdateConfig.rareMoonCount; j++)
			{
				int index6 = random.Next(list4.Count);
				ExtendedLevel val6 = list4[index6];
				val6.IsRouteHidden = false;
				list4.Remove(val6);
				list3.Remove(val6);
				list.Remove(val6);
				RareMoonsPicked++;
				if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberMoons) && SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberAll))
				{
					UpdateConfig.RecentlyVisitedMoons.Add(val6);
				}
				if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.DiscountMoons))
				{
					PriceManager.originalPrices[val6] = val6.RoutePrice;
					int seed4 = Seed + Selenes_Choice.glump;
					Random random5 = new Random(seed4);
					int num10 = random.Next(UpdateConfig.minDiscount, UpdateConfig.maxDiscount + 1);
					int num11 = 100 - num10;
					float num12 = (float)num11 / 100f;
					val6.RoutePrice = (int)((float)val6.RoutePrice * num12);
					Selenes_Choice.glump++;
				}
				RarMNs = RarMNs + val6.NumberlessPlanetName + ",";
			}
		}
		if (UpdateConfig.paidMoonCount > 0)
		{
			for (int k = 0; k < UpdateConfig.paidMoonCount; k++)
			{
				int index7 = random.Next(list3.Count);
				ExtendedLevel val7 = list3[index7];
				val7.IsRouteHidden = false;
				list3.Remove(val7);
				list.Remove(val7);
				PaidMoonsPicked++;
				if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberMoons) && SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberAll))
				{
					UpdateConfig.RecentlyVisitedMoons.Add(val7);
				}
				if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.DiscountMoons))
				{
					PriceManager.originalPrices[val7] = val7.RoutePrice;
					int seed5 = Seed + Selenes_Choice.glump;
					Random random6 = new Random(seed5);
					int num13 = random.Next(UpdateConfig.minDiscount, UpdateConfig.maxDiscount + 1);
					int num14 = 100 - num13;
					float num15 = (float)num14 / 100f;
					val7.RoutePrice = (int)((float)val7.RoutePrice * num15);
					Selenes_Choice.glump++;
				}
				PaiMNs = PaiMNs + val7.NumberlessPlanetName + ",";
			}
		}
		if (UpdateConfig.randomMoonCount > 0)
		{
			for (int l = 0; l < UpdateConfig.randomMoonCount; l++)
			{
				int index8 = random.Next(list.Count);
				ExtendedLevel val8 = list[index8];
				val8.IsRouteHidden = false;
				list.Remove(val8);
				RandomMoonsPicked++;
				if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberMoons) && SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RememberAll))
				{
					UpdateConfig.RecentlyVisitedMoons.Add(val8);
				}
				if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.DiscountMoons))
				{
					PriceManager.originalPrices[val8] = val8.RoutePrice;
					int seed6 = Seed + Selenes_Choice.glump;
					Random random7 = new Random(seed6);
					int num16 = random.Next(UpdateConfig.minDiscount, UpdateConfig.maxDiscount + 1);
					int num17 = 100 - num16;
					float num18 = (float)num17 / 100f;
					val8.RoutePrice = (int)((float)val8.RoutePrice * num18);
					Selenes_Choice.glump++;
				}
				RanMNs = RanMNs + val8.NumberlessPlanetName + ",";
			}
		}
		Selenes_Choice.glump = 0;
		foreach (ExtendedLevel item2 in list)
		{
			if (item2.IsRouteHidden)
			{
				item2.IsRouteLocked = true;
			}
		}
		Selenes_Choice.instance.mls.LogInfo((object)$"Picked Moons:\n                                 Free Count = {FreeMoonsPicked}\n                                 Free Names: {FreMNs}\n                                 Rare Count = {RareMoonsPicked}\n                                 Rare Names: {RarMNs}\n                                 Paid Count = {PaidMoonsPicked}\n                                 Paid Names: {PaiMNs}\n                                 Random Count = {RandomMoonsPicked}\n                                 Random Names: {RanMNs}");
		FreeMoonsPicked = 0;
		RareMoonsPicked = 0;
		PaidMoonsPicked = 0;
		RandomMoonsPicked = 0;
		FreMNs = "";
		RarMNs = "";
		PaiMNs = "";
		RanMNs = "";
	}
}
public class ShareSnT : NetworkBehaviour
{
	[Serializable]
	public class SerializableList : INetworkSerializable
	{
		public List<string> RVMString = new List<string>();

		public unsafe void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			int count = RVMString.Count;
			((BufferSerializer<int>*)(&serializer))->SerializeValue<int>(ref count, default(ForPrimitives));
			if (serializer.IsReader)
			{
				RVMString = new List<string>(count);
			}
			for (int i = 0; i < count; i++)
			{
				string text = ((i < RVMString.Count) ? RVMString[i] : string.Empty);
				serializer.SerializeValue(ref text, false);
				if (serializer.IsReader)
				{
					if (i < RVMString.Count)
					{
						RVMString[i] = text;
					}
					else
					{
						RVMString.Add(text);
					}
				}
			}
		}
	}

	[Serializable]
	public class SerializableDictionary : INetworkSerializable
	{
		public Dictionary<string, int> DRVString = new Dictionary<string, int>();

		public unsafe void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			int count = DRVString.Count;
			((BufferSerializer<int>*)(&serializer))->SerializeValue<int>(ref count, default(ForPrimitives));
			if (serializer.IsReader)
			{
				DRVString = new Dictionary<string, int>(count);
			}
			List<string> list = new List<string>(DRVString.Keys);
			List<int> list2 = new List<int>(DRVString.Values);
			for (int i = 0; i < count; i++)
			{
				string key = ((i < list.Count) ? list[i] : string.Empty);
				int value = ((i < list2.Count) ? list2[i] : 0);
				serializer.SerializeValue(ref key, false);
				((BufferSerializer<int>*)(&serializer))->SerializeValue<int>(ref value, default(ForPrimitives));
				if (serializer.IsReader)
				{
					DRVString[key] = value;
				}
			}
		}
	}

	public int lastUsedSeedPrev;

	public ManualResetEvent dataReceivedEvent = new ManualResetEvent(initialState: false);

	[Tooltip("HostSnT")]
	public string MessageName = "Host Seed And Game Overs Count";

	public static ShareSnT Instance { get; private set; }

	private void Awake()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected O, but got Unknown
		Instance = this;
		((NetworkBehaviour)this).NetworkManager.CustomMessagingManager.RegisterNamedMessageHandler(MessageName, new HandleNamedMessageDelegate(OnMessageReceived));
	}

	public void RequestData()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		if (!NetworkManager.Singleton.IsHost)
		{
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(0, (Allocator)2, -1);
			((NetworkBehaviour)this).NetworkManager.CustomMessagingManager.SendNamedMessage(MessageName, 0uL, val, (NetworkDelivery)3);
		}
	}

	public void UpdateAndSendData()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(1024, (Allocator)2, -1);
		try
		{
			SerializableList serializableList = new SerializableList
			{
				RVMString = UpdateConfig.RVMString
			};
			SerializableDictionary serializableDictionary = new SerializableDictionary
			{
				DRVString = UpdateConfig.DRVString
			};
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref lastUsedSeedPrev, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<SerializableList>(ref serializableList, default(ForNetworkSerializable));
			((FastBufferWriter)(ref val)).WriteValueSafe<SerializableDictionary>(ref serializableDictionary, default(ForNetworkSerializable));
			((NetworkBehaviour)this).NetworkManager.CustomMessagingManager.SendNamedMessage(MessageName, ((NetworkBehaviour)this).NetworkManager.ConnectedClientsIds, val, (NetworkDelivery)3);
		}
		finally
		{
			((IDisposable)(FastBufferWriter)(ref val)).Dispose();
		}
	}

	private void OnMessageReceived(ulong clientId, FastBufferReader reader)
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		if (NetworkManager.Singleton.IsHost && clientId != 0)
		{
			lastUsedSeedPrev = Selenes_Choice.LastUsedSeed;
			dataReceivedEvent.Set();
			UpdateAndSendData();
			Selenes_Choice.instance.mls.LogInfo((object)"Host received message");
		}
		else if (!NetworkManager.Singleton.IsHost)
		{
			int lastUsedSeed = default(int);
			((FastBufferReader)(ref reader)).ReadValue<int>(ref lastUsedSeed, default(ForPrimitives));
			Selenes_Choice.LastUsedSeed = lastUsedSeed;
			SerializableList serializableList = default(SerializableList);
			((FastBufferReader)(ref reader)).ReadValueSafe<SerializableList>(ref serializableList, default(ForNetworkSerializable));
			SerializableDictionary serializableDictionary = default(SerializableDictionary);
			((FastBufferReader)(ref reader)).ReadValueSafe<SerializableDictionary>(ref serializableDictionary, default(ForNetworkSerializable));
			UpdateConfig.RVMString = serializableList.RVMString;
			UpdateConfig.DRVString = serializableDictionary.DRVString;
			dataReceivedEvent.Set();
			Selenes_Choice.instance.mls.LogInfo((object)"Client received message");
		}
	}

	private void Update()
	{
		if (NetworkManager.Singleton.IsHost && Selenes_Choice.LastUsedSeed != lastUsedSeedPrev)
		{
			UpdateAndSendData();
			lastUsedSeedPrev = Selenes_Choice.LastUsedSeed;
			Selenes_Choice.instance.mls.LogInfo((object)("Host has saved new seed, " + lastUsedSeedPrev));
		}
	}
}
[HarmonyPatch(typeof(HangarShipDoor), "Start")]
public static class AnchorTheShare
{
	private static void Postfix(HangarShipDoor __instance)
	{
		if ((Object)(object)((Component)__instance).gameObject.GetComponent<ShareSnT>() == (Object)null)
		{
			((Component)__instance).gameObject.AddComponent<ShareSnT>();
		}
	}
}
public class UpdateConfig
{
	[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
	public static class ResetSaveStatusOnDC
	{
		private static void Postfix()
		{
			LoadedSaveData = false;
			IncreaseDays = false;
			RecentlyVisitedMoons.Clear();
			DaysOnRecentlyVisitedList.Clear();
			RVMString.Clear();
			DRVString.Clear();
			levelsToRemove.Clear();
			ListStatus.Clear();
			IntegratedPM = false;
		}
	}

	private static readonly UpdateConfig _instance = new UpdateConfig();

	public static int freeMoonCount = SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.FreeMoonCount);

	public static int paidMoonCount = SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.PaidMoonCount);

	public static int randomMoonCount = SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.RandomMoonCount);

	public static int rareMoonCount = SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.RareMoonCount);

	public static int minDiscount = SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.MinDiscount);

	public static int maxDiscount = SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.MaxDiscount);

	public static List<ExtendedLevel> RecentlyVisitedMoons = new List<ExtendedLevel>();

	public static Dictionary<ExtendedLevel, int> DaysOnRecentlyVisitedList = new Dictionary<ExtendedLevel, int>();

	public static List<string> RVMString = new List<string>();

	public static Dictionary<string, int> DRVString = new Dictionary<string, int>();

	public static List<ExtendedLevel> levelsToRemove = new List<ExtendedLevel>();

	public static Dictionary<ExtendedLevel, int> ListStatus = new Dictionary<ExtendedLevel, int>();

	public static bool LoadedSaveData = false;

	public static bool IntegratedPM = false;

	public static bool IncreaseDays = false;

	public static string MoonStatusUpdate = "RVL Status:";

	public static UpdateConfig Instance => _instance;

	private UpdateConfig()
	{
	}

	public void BracketMoons()
	{
		if (!LoadedSaveData)
		{
			if (NetworkManager.Singleton.IsHost)
			{
				if (ES3.KeyExists("RecentlyVisitedMoonsList", GameNetworkManager.Instance.currentSaveFileName) && ES3.KeyExists("DaysSinceLastVisit", GameNetworkManager.Instance.currentSaveFileName))
				{
					RVMString = ES3.Load<List<string>>("RecentlyVisitedMoonsList", GameNetworkManager.Instance.currentSaveFileName);
					DRVString = ES3.Load<Dictionary<string, int>>("DaysSinceLastVisit", GameNetworkManager.Instance.currentSaveFileName);
					RecentlyVisitedMoons.Clear();
					DaysOnRecentlyVisitedList.Clear();
					List<ExtendedLevel> extendedLevels = PatchedContent.ExtendedLevels;
					foreach (ExtendedLevel item in extendedLevels)
					{
						if (RVMString.Contains(item.NumberlessPlanetName))
						{
							RecentlyVisitedMoons.Add(item);
							if (DRVString.ContainsKey(item.NumberlessPlanetName))
							{
								DaysOnRecentlyVisitedList[item] = DRVString[item.NumberlessPlanetName];
							}
							else
							{
								DaysOnRecentlyVisitedList[item] = 0;
							}
						}
					}
					RVMString.Clear();
					DRVString.Clear();
					Selenes_Choice.instance.mls.LogInfo((object)"Loaded Saved RVL data.");
				}
			}
			else
			{
				RecentlyVisitedMoons.Clear();
				DaysOnRecentlyVisitedList.Clear();
				List<ExtendedLevel> extendedLevels2 = PatchedContent.ExtendedLevels;
				foreach (ExtendedLevel item2 in extendedLevels2)
				{
					if (RVMString.Contains(item2.NumberlessPlanetName))
					{
						RecentlyVisitedMoons.Add(item2);
						if (DRVString.ContainsKey(item2.NumberlessPlanetName))
						{
							DaysOnRecentlyVisitedList[item2] = DRVString[item2.NumberlessPlanetName];
						}
						else
						{
							DaysOnRecentlyVisitedList[item2] = 0;
						}
					}
				}
				RVMString.Clear();
				DRVString.Clear();
				Selenes_Choice.instance.mls.LogInfo((object)"Loaded Saved RVL data.");
			}
			LoadedSaveData = true;
		}
		foreach (ExtendedLevel recentlyVisitedMoon in RecentlyVisitedMoons)
		{
			recentlyVisitedMoon.IsRouteLocked = true;
			recentlyVisitedMoon.IsRouteHidden = true;
			if (recentlyVisitedMoon.NumberlessPlanetName == "Gordion")
			{
				levelsToRemove.Add(recentlyVisitedMoon);
			}
			if (!ListStatus.ContainsKey(recentlyVisitedMoon))
			{
				ListStatus[recentlyVisitedMoon] = -1;
			}
			if (IncreaseDays)
			{
				if (DaysOnRecentlyVisitedList.ContainsKey(recentlyVisitedMoon) && LevelManager.CurrentExtendedLevel.NumberlessPlanetName != "Gordion")
				{
					DaysOnRecentlyVisitedList[recentlyVisitedMoon]++;
					DRVString[recentlyVisitedMoon.NumberlessPlanetName]++;
					ListStatus[recentlyVisitedMoon] = 0;
				}
				if (DaysOnRecentlyVisitedList.ContainsKey(recentlyVisitedMoon) && LevelManager.CurrentExtendedLevel.NumberlessPlanetName == "Gordion")
				{
					ListStatus[recentlyVisitedMoon] = 4;
				}
				if (!DaysOnRecentlyVisitedList.ContainsKey(recentlyVisitedMoon))
				{
					DaysOnRecentlyVisitedList[recentlyVisitedMoon] = 0;
					ListStatus[recentlyVisitedMoon] = 1;
				}
				if (TimeOfDay.Instance.daysUntilDeadline < 0 && ListStatus[recentlyVisitedMoon] == 1)
				{
					levelsToRemove.Add(recentlyVisitedMoon);
					ListStatus[recentlyVisitedMoon] = -1;
				}
				if (DaysOnRecentlyVisitedList.ContainsKey(recentlyVisitedMoon) && DaysOnRecentlyVisitedList[recentlyVisitedMoon] >= SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.DaysToRemember))
				{
					levelsToRemove.Add(recentlyVisitedMoon);
					ListStatus[recentlyVisitedMoon] = 2;
				}
			}
			else
			{
				ListStatus[recentlyVisitedMoon] = 3;
			}
		}
		foreach (ExtendedLevel item3 in levelsToRemove)
		{
			RecentlyVisitedMoons.Remove(item3);
			DaysOnRecentlyVisitedList.Remove(item3);
			RVMString.Remove(item3.NumberlessPlanetName);
			DRVString.Remove(item3.NumberlessPlanetName);
		}
		levelsToRemove.Clear();
		List<ExtendedLevel> list = (from level in RecentlyVisitedMoons
			orderby DaysOnRecentlyVisitedList[level], level.NumberlessPlanetName
			select level).ToList();
		foreach (ExtendedLevel item4 in list)
		{
			if (ListStatus[item4] == 0)
			{
				if (DaysOnRecentlyVisitedList[item4] != 1)
				{
					MoonStatusUpdate += $"\nMoon: {item4.NumberlessPlanetName} has now been on the RVL for {DaysOnRecentlyVisitedList[item4]} days.";
				}
				else
				{
					MoonStatusUpdate += $"\nMoon: {item4.NumberlessPlanetName} has now been on the RVL for {DaysOnRecentlyVisitedList[item4]} day.";
				}
			}
			if (ListStatus[item4] == 1)
			{
				MoonStatusUpdate += $"\nMoon: {item4.NumberlessPlanetName} is new to the RVL, starting it at {DaysOnRecentlyVisitedList[item4]} days.";
			}
			if (ListStatus[item4] == 2)
			{
				if (Selenes_Choice.Config.DaysToRemember.Value != 1)
				{
					MoonStatusUpdate += $"\nMoon: {item4.NumberlessPlanetName} is no longer on the RVL list. It has been in purgatory for {Selenes_Choice.Config.DaysToRemember.Value} days.";
				}
				else
				{
					MoonStatusUpdate += $"\nMoon: {item4.NumberlessPlanetName} is no longer on the RVL list. It has been in purgatory for {Selenes_Choice.Config.DaysToRemember.Value} day.";
				}
			}
			if (ListStatus[item4] == 3)
			{
				if (DaysOnRecentlyVisitedList[item4] != 1)
				{
					MoonStatusUpdate += $"\nMoon: {item4.NumberlessPlanetName} has been reloaded, keeping its previous day count of {DaysOnRecentlyVisitedList[item4]} days.";
				}
				else
				{
					MoonStatusUpdate += $"\nMoon: {item4.NumberlessPlanetName} has been reloaded, keeping its previous day count of {DaysOnRecentlyVisitedList[item4]} day.";
				}
			}
			if (ListStatus[item4] == 4)
			{
				if (DaysOnRecentlyVisitedList[item4] != 1)
				{
					MoonStatusUpdate += $"\nMoon: {item4.NumberlessPlanetName} remains at {DaysOnRecentlyVisitedList[item4]} days, the current level is Gordion.";
				}
				else
				{
					MoonStatusUpdate += $"\nMoon: {item4.NumberlessPlanetName} remains at {DaysOnRecentlyVisitedList[item4]} day, the current level is Gordion.";
				}
			}
			ListStatus[item4] = -1;
		}
		if (MoonStatusUpdate != "RVL Status:")
		{
			Selenes_Choice.instance.mls.LogInfo((object)MoonStatusUpdate);
			MoonStatusUpdate = "RVL Status:";
		}
		foreach (ExtendedLevel item5 in levelsToRemove)
		{
			RecentlyVisitedMoons.Remove(item5);
			DaysOnRecentlyVisitedList.Remove(item5);
			RVMString.Remove(item5.NumberlessPlanetName);
			DRVString.Remove(item5.NumberlessPlanetName);
		}
		levelsToRemove.Clear();
		List<ExtendedLevel> source = PatchedContent.ExtendedLevels.Where((ExtendedLevel level) => !ListProcessor.Instance.ExclusionList.Split(',').Any((string b) => level.NumberlessPlanetName.Equals(b))).ToList();
		List<ExtendedLevel> list2 = source.Where((ExtendedLevel level) => !RecentlyVisitedMoons.Contains(level)).ToList();
		if (NetworkManager.Singleton.IsHost)
		{
			if (!IntegratedPM && PermanentMoonsCompatibility.enabled)
			{
				Dictionary<string, object> dictionary = PermanentMoonsCompatibility.GrabPMList();
				if (dictionary.ContainsKey("UnlockedMoons"))
				{
					List<string> list3 = (List<string>)dictionary["UnlockedMoons"];
					foreach (string item6 in list3)
					{
						foreach (ExtendedLevel item7 in list2)
						{
							if (item6 == item7.SelectableLevel.PlanetName.ToLower())
							{
								item7.RoutePrice = 0;
								Selenes_Choice.instance.mls.LogInfo((object)("Made level: " + item7.SelectableLevel.PlanetName + " free"));
							}
						}
					}
				}
				else
				{
					Selenes_Choice.instance.mls.LogInfo((object)"No PM data");
				}
				IntegratedPM = true;
			}
			else
			{
				Selenes_Choice.instance.mls.LogInfo((object)"PM not installed (or integrated already)");
			}
		}
		List<ExtendedLevel> list4 = list2.Where((ExtendedLevel level) => level.RoutePrice == 0).ToList();
		List<ExtendedLevel> list5 = RecentlyVisitedMoons.Where((ExtendedLevel level) => level.RoutePrice == 0).ToList();
		if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.ReturnFrees) && list5.Count != 0)
		{
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.ReturnMany))
			{
				if (list4.Count <= 0)
				{
					string text = "No Free Moons were found, reusing RV free moon(s): ";
					foreach (ExtendedLevel item8 in list5)
					{
						list4.Add(item8);
						list2.Add(item8);
						levelsToRemove.Add(item8);
						text = text + item8.NumberlessPlanetName + ", ";
					}
					if (text.Contains(",") && text.LastIndexOf(", ") == text.Length - 2)
					{
						text = text.Remove(text.LastIndexOf(", "), 2);
						text += ".";
					}
					Selenes_Choice.instance.mls.LogInfo((object)text);
					foreach (ExtendedLevel item9 in levelsToRemove)
					{
						RecentlyVisitedMoons.Remove(item9);
						DaysOnRecentlyVisitedList.Remove(item9);
						RVMString.Remove(item9.NumberlessPlanetName);
						DRVString.Remove(item9.NumberlessPlanetName);
					}
					levelsToRemove.Clear();
				}
			}
			else if (list4.Count <= 0)
			{
				string text2 = "No Free Moons were found, reusing one RV free moon: ";
				List<ExtendedLevel> list6 = new List<ExtendedLevel>();
				foreach (ExtendedLevel recentlyVisitedMoon2 in RecentlyVisitedMoons)
				{
					if (recentlyVisitedMoon2.RoutePrice == 0)
					{
						list6.Add(recentlyVisitedMoon2);
					}
				}
				Random random = new Random(StartOfRound.Instance.randomMapSeed);
				ExtendedLevel val = list6[random.Next(list6.Count)];
				list4.Add(val);
				list2.Add(val);
				text2 = text2 + val.NumberlessPlanetName + ".";
				Selenes_Choice.instance.mls.LogInfo((object)text2);
				RecentlyVisitedMoons.Remove(val);
				DaysOnRecentlyVisitedList.Remove(val);
				RVMString.Remove(val.NumberlessPlanetName);
				DRVString.Remove(val.NumberlessPlanetName);
			}
		}
		else if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.ReturnMany))
		{
			if (list2.Count <= 0)
			{
				string text3 = "No Moons were found, reusing RV moons: ";
				foreach (ExtendedLevel recentlyVisitedMoon3 in RecentlyVisitedMoons)
				{
					list2.Add(recentlyVisitedMoon3);
					levelsToRemove.Add(recentlyVisitedMoon3);
					text3 = text3 + recentlyVisitedMoon3.NumberlessPlanetName + ", ";
				}
				if (text3.Contains(",") && text3.LastIndexOf(", ") == text3.Length - 2)
				{
					text3 = text3.Remove(text3.LastIndexOf(", "), 2);
					text3 += ".";
				}
				Selenes_Choice.instance.mls.LogInfo((object)text3);
				foreach (ExtendedLevel item10 in levelsToRemove)
				{
					RecentlyVisitedMoons.Remove(item10);
					DaysOnRecentlyVisitedList.Remove(item10);
					RVMString.Remove(item10.NumberlessPlanetName);
					DRVString.Remove(item10.NumberlessPlanetName);
				}
				levelsToRemove.Clear();
			}
		}
		else if (list2.Count <= 0)
		{
			string text4 = "No Moons were found, reusing one RV moon: ";
			List<ExtendedLevel> list7 = new List<ExtendedLevel>();
			foreach (ExtendedLevel recentlyVisitedMoon4 in RecentlyVisitedMoons)
			{
				list7.Add(recentlyVisitedMoon4);
			}
			Random random2 = new Random(StartOfRound.Instance.randomMapSeed);
			ExtendedLevel val2 = list7[random2.Next(list7.Count)];
			list2.Add(val2);
			text4 = text4 + val2.NumberlessPlanetName + ".";
			Selenes_Choice.instance.mls.LogInfo((object)text4);
			RecentlyVisitedMoons.Remove(val2);
			DaysOnRecentlyVisitedList.Remove(val2);
			RVMString.Remove(val2.NumberlessPlanetName);
			DRVString.Remove(val2.NumberlessPlanetName);
		}
		foreach (ExtendedLevel recentlyVisitedMoon5 in RecentlyVisitedMoons)
		{
			if (!DRVString.ContainsKey(recentlyVisitedMoon5.NumberlessPlanetName))
			{
				RVMString.Add(recentlyVisitedMoon5.NumberlessPlanetName);
				DRVString.Add(recentlyVisitedMoon5.NumberlessPlanetName, DaysOnRecentlyVisitedList[recentlyVisitedMoon5]);
			}
		}
		if (NetworkManager.Singleton.IsHost)
		{
			ES3.Save<List<string>>("RecentlyVisitedMoonsList", RVMString, GameNetworkManager.Instance.currentSaveFileName);
			ES3.Save<Dictionary<string, int>>("DaysSinceLastVisit", DRVString, GameNetworkManager.Instance.currentSaveFileName);
		}
		Selenes_Choice.instance.mls.LogInfo((object)("allLevels " + list2.Count));
		Selenes_Choice.instance.mls.LogInfo((object)("freeLevels " + list4.Count));
		List<ExtendedLevel> list8 = list2.Where((ExtendedLevel level) => level.RoutePrice != 0).ToList();
		Selenes_Choice.instance.mls.LogInfo((object)("paid levels " + list8.Count));
		List<ExtendedLevel> list9 = list8.Where((ExtendedLevel level) => level.RoutePrice >= SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.ValueThreshold)).ToList();
		Selenes_Choice.instance.mls.LogInfo((object)("rare levels " + list9.Count));
		int num = freeMoonCount;
		int num2 = paidMoonCount;
		int num3 = randomMoonCount;
		int num4 = rareMoonCount;
		if (Selenes_Choice.SafetyType == 0)
		{
			num++;
		}
		if (Selenes_Choice.SafetyType == 1)
		{
			num3++;
		}
		if (Selenes_Choice.SafetyType == 2)
		{
			num2++;
		}
		if (Selenes_Choice.SafetyType == 3)
		{
			num4++;
		}
		freeMoonCount = SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.FreeMoonCount);
		if (freeMoonCount < 0)
		{
			freeMoonCount = 0;
		}
		rareMoonCount = SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.RareMoonCount);
		if (rareMoonCount < 0)
		{
			rareMoonCount = 0;
		}
		paidMoonCount = SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.PaidMoonCount);
		if (paidMoonCount < 0)
		{
			paidMoonCount = 0;
		}
		randomMoonCount = SyncedEntry<int>.op_Implicit(Selenes_Choice.Config.RandomMoonCount);
		if (randomMoonCount < 0)
		{
			randomMoonCount = 0;
		}
		int num5 = freeMoonCount + paidMoonCount + randomMoonCount + rareMoonCount;
		if (num5 == 0)
		{
			freeMoonCount = 1;
		}
		int num6 = list2.Count - num5;
		if (num6 < 0)
		{
			num5 = list2.Count;
			num6 = 0;
		}
		if (freeMoonCount > list4.Count)
		{
			freeMoonCount = list4.Count;
		}
		num5 -= freeMoonCount;
		if (rareMoonCount > list9.Count)
		{
			rareMoonCount = list9.Count;
		}
		num5 -= rareMoonCount;
		if (paidMoonCount > list8.Count - rareMoonCount)
		{
			paidMoonCount = list8.Count - rareMoonCount;
		}
		num5 -= paidMoonCount;
		if (randomMoonCount > num6)
		{
			randomMoonCount = num6;
		}
		num5 -= randomMoonCount;
		if (num5 > 0 && SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.RollOverMoons))
		{
			randomMoonCount += num5;
		}
		if (num != freeMoonCount)
		{
			Selenes_Choice.instance.mls.LogInfo((object)("freeMoonCount changed from " + num + " to " + freeMoonCount));
		}
		if (num2 != paidMoonCount)
		{
			Selenes_Choice.instance.mls.LogInfo((object)("paidMoonCount changed from " + num2 + " to " + paidMoonCount));
		}
		if (num4 != rareMoonCount)
		{
			Selenes_Choice.instance.mls.LogInfo((object)("rareMoonCount changed from " + num4 + " to " + rareMoonCount));
		}
		if (num3 != randomMoonCount)
		{
			Selenes_Choice.instance.mls.LogInfo((object)("randomMoonCount changed from " + num3 + " to " + randomMoonCount));
		}
		int num7 = minDiscount;
		int num8 = maxDiscount;
		minDiscount = Mathf.Clamp(minDiscount, 0, 100);
		maxDiscount = Mathf.Clamp(maxDiscount, minDiscount, 100);
		if (num7 != minDiscount)
		{
			Selenes_Choice.instance.mls.LogInfo((object)("minDiscount changed from " + num7 + " to " + minDiscount));
		}
		if (num8 != maxDiscount)
		{
			Selenes_Choice.instance.mls.LogInfo((object)("maxDiscount changed from " + num8 + " to " + maxDiscount));
		}
		IncreaseDays = true;
	}
}
public class ListProcessor
{
	private static readonly ListProcessor _instance = new ListProcessor();

	public string ExclusionList { get; private set; }

	public static ListProcessor Instance => _instance;

	private ListProcessor()
	{
	}

	public void ProcessLists()
	{
		string text = SyncedEntry<string>.op_Implicit(Selenes_Choice.Config.IgnoreMoons);
		string text2 = SyncedEntry<string>.op_Implicit(Selenes_Choice.Config.BlacklistMoons);
		string text3 = SyncedEntry<string>.op_Implicit(Selenes_Choice.Config.TreasureMoons);
		ExclusionList = string.Join(",", text, text2, text3);
		if (Selenes_Choice.Config.StoryMoonCompat.Value)
		{
			string text4 = "Penumbra,Sector-0";
			ExclusionList = string.Join(",", ExclusionList, text4);
		}
		string text5 = "Assurаncе,Mаrch,Offеnsе,Adаmance,Dіne,Tіtan,Embrіon,Assurance(RM),March(RM),Offense(RM),Adamance(RM),Dine(RM),Titan(RM),Embrion(RM)";
		ExclusionList = string.Join(",", ExclusionList, text5);
		string IgnoreList = SyncedEntry<string>.op_Implicit(Selenes_Choice.Config.IgnoreMoons);
		List<ExtendedLevel> list = PatchedContent.ExtendedLevels.Where((ExtendedLevel level) => IgnoreList.Split(',').Any((string b) => level.NumberlessPlanetName.Equals(b))).ToList();
		foreach (ExtendedLevel item in list)
		{
			if (item.NumberlessPlanetName.Equals("Gordion"))
			{
				item.IsRouteLocked = false;
				item.IsRouteHidden = true;
			}
			else
			{
				item.IsRouteLocked = false;
				item.IsRouteHidden = false;
			}
		}
		string BlackList = SyncedEntry<string>.op_Implicit(Selenes_Choice.Config.BlacklistMoons);
		List<ExtendedLevel> list2 = PatchedContent.ExtendedLevels.Where((ExtendedLevel level) => BlackList.Split(',').Any((string b) => level.NumberlessPlanetName.Equals(b))).ToList();
		foreach (ExtendedLevel item2 in list2)
		{
			item2.IsRouteLocked = true;
			item2.IsRouteHidden = true;
		}
		string TreasureList = SyncedEntry<string>.op_Implicit(Selenes_Choice.Config.TreasureMoons);
		List<ExtendedLevel> list3 = PatchedContent.ExtendedLevels.Where((ExtendedLevel level) => TreasureList.Split(',').Any((string b) => level.NumberlessPlanetName.Equals(b))).ToList();
		foreach (ExtendedLevel item3 in list3)
		{
			item3.IsRouteLocked = false;
			item3.IsRouteHidden = true;
			if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.TreasureBool))
			{
				item3.SelectableLevel.minScrap = (int)((float)item3.SelectableLevel.minScrap * SyncedEntry<float>.op_Implicit(Selenes_Choice.Config.TreasureBonus));
				item3.SelectableLevel.maxScrap = (int)((float)item3.SelectableLevel.maxScrap * SyncedEntry<float>.op_Implicit(Selenes_Choice.Config.TreasureBonus));
			}
		}
	}
}
public static class GlobalVariables
{
	public static int RemainingScrapInLevel;
}
[HarmonyPatch(typeof(StartOfRound), "ShipLeave")]
public class ShipleaveCalc
{
	[HarmonyPostfix]
	public static void Postfix()
	{
		GlobalVariables.RemainingScrapInLevel = CalculateRemainingScrapInLevel();
	}

	public static int CalculateRemainingScrapInLevel()
	{
		GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
		int num = 0;
		for (int i = 0; i < array.Length; i++)
		{
			if (array[i].itemProperties.isScrap && !array[i].isInShipRoom && !array[i].isInElevator && !array[i].scrapPersistedThroughRounds)
			{
				num += array[i].scrapValue;
			}
		}
		return num;
	}
}
[HarmonyPatch(typeof(HUDManager), "FillEndGameStats")]
public class HUDManagerPatch
{
	[HarmonyPostfix]
	public static void FillEndGameStatsPostfix(HUDManager __instance, int scrapCollected)
	{
		float num = scrapCollected + GlobalVariables.RemainingScrapInLevel;
		((TMP_Text)__instance.statsUIElements.quotaDenominator).text = num.ToString();
	}
}
public static class PriceManager
{
	public static Dictionary<ExtendedLevel, int> originalPrices = new Dictionary<ExtendedLevel, int>();

	public static void ResetPrices()
	{
		foreach (KeyValuePair<ExtendedLevel, int> originalPrice in originalPrices)
		{
			originalPrice.Key.RoutePrice = originalPrice.Value;
		}
		originalPrices.Clear();
	}
}
[HarmonyPatch(typeof(StartOfRound), "PassTimeToNextDay")]
public class HideMoonsOnDayChange
{
	private static void Postfix()
	{
		((MonoBehaviour)ShareSnT.Instance).StartCoroutine(WaitOnDay());
	}

	private static IEnumerator WaitOnDay()
	{
		yield return (object)new WaitForSeconds(2f);
		ProcessData();
	}

	private static void ProcessData()
	{
		if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.DailyOrQuota))
		{
			return;
		}
		CommonShuffle.ShuffleMoons(StartOfRound.Instance.randomMapSeed);
		int num = -1;
		if (!NetworkManager.Singleton.IsHost)
		{
			return;
		}
		if (TimeOfDay.Instance.daysUntilDeadline == 0)
		{
			ExtendedLevel val = ((IEnumerable<ExtendedLevel>)PatchedContent.ExtendedLevels).FirstOrDefault((Func<ExtendedLevel, bool>)((ExtendedLevel level) => level.NumberlessPlanetName.Equals("Gordion")));
			int levelID = val.SelectableLevel.levelID;
			if ((Object)(object)val != (Object)(object)LevelManager.CurrentExtendedLevel)
			{
				StartOfRound.Instance.ChangeLevelClientRpc(levelID, Object.FindObjectOfType<Terminal>().groupCredits);
				num = levelID;
			}
		}
		else if ((Object)(object)Selenes_Choice.PreviousSafetyMoon != (Object)null && (Object)(object)Selenes_Choice.PreviousSafetyMoon != (Object)(object)LevelManager.CurrentExtendedLevel)
		{
			int levelID2 = Selenes_Choice.PreviousSafetyMoon.SelectableLevel.levelID;
			StartOfRound.Instance.ChangeLevelClientRpc(levelID2, Object.FindObjectOfType<Terminal>().groupCredits);
			num = levelID2;
		}
		if (num != -1)
		{
			ES3.Save<int>("CurrentPlanetID", num, GameNetworkManager.Instance.currentSaveFileName);
		}
	}
}
[HarmonyPatch(typeof(StartOfRound), "PassTimeToNextDay")]
public class KeepWeather
{
	private static void Postfix()
	{
		if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.DailyOrQuota))
		{
			((MonoBehaviour)ShareSnT.Instance).StartCoroutine(WaitOnWeather());
		}
	}

	private static IEnumerator WaitOnWeather()
	{
		yield return (object)new WaitForSeconds(2f);
		SetTheWeather();
	}

	private static void SetTheWeather()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.ClearWeather))
		{
			if (WeatherRegistryCompatibility.enabled)
			{
				WeatherRegistryCompatibility.ClearWeatherWithWR(Selenes_Choice.PreviousSafetyMoon);
			}
			Selenes_Choice.PreviousSafetyMoon.SelectableLevel.currentWeather = (LevelWeatherType)(-1);
			StartOfRound.Instance.SetMapScreenInfoToCurrentLevel();
		}
	}
}
[HarmonyPatch(typeof(StartOfRound), "PassTimeToNextDay")]
public class AutoRouteToCompany
{
	private static void Postfix()
	{
		if (SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.DailyOrQuota))
		{
			((MonoBehaviour)ShareSnT.Instance).StartCoroutine(WaitOnDay());
		}
	}

	private static IEnumerator WaitOnDay()
	{
		yield return (object)new WaitForSeconds(2f);
		GoToCompany();
	}

	private static void GoToCompany()
	{
		if (NetworkManager.Singleton.IsHost && TimeOfDay.Instance.daysUntilDeadline == 0)
		{
			ExtendedLevel val = ((IEnumerable<ExtendedLevel>)PatchedContent.ExtendedLevels).FirstOrDefault((Func<ExtendedLevel, bool>)((ExtendedLevel level) => level.NumberlessPlanetName.Equals("Gordion")));
			int levelID = val.SelectableLevel.levelID;
			if ((Object)(object)val != (Object)(object)LevelManager.CurrentExtendedLevel)
			{
				StartOfRound.Instance.ChangeLevelClientRpc(levelID, Object.FindObjectOfType<Terminal>().groupCredits);
			}
			ES3.Save<int>("CurrentPlanetID", levelID, GameNetworkManager.Instance.currentSaveFileName);
		}
	}
}
[HarmonyPatch(typeof(StartOfRound), "ChangeLevelClientRpc")]
public class SaveAfterRouting
{
	private static void Postfix()
	{
		if (NetworkManager.Singleton.IsHost)
		{
			ES3.Save<int>("CurrentPlanetID", StartOfRound.Instance.currentLevelID, GameNetworkManager.Instance.currentSaveFileName);
		}
	}
}
[HarmonyPatch(typeof(StartOfRound), "ResetShip")]
public class HideMoonsOnGameOver
{
	private static void Postfix()
	{
		((MonoBehaviour)ShareSnT.Instance).StartCoroutine(WaitOnDeath());
	}

	private static IEnumerator WaitOnDeath()
	{
		yield return (object)new WaitForSeconds(2f);
		ProcessData();
	}

	private static void ProcessData()
	{
		CommonShuffle.ShuffleMoons(StartOfRound.Instance.randomMapSeed);
		int num = -1;
		if (TimeOfDay.Instance.daysUntilDeadline == 0)
		{
			ExtendedLevel val = ((IEnumerable<ExtendedLevel>)PatchedContent.ExtendedLevels).FirstOrDefault((Func<ExtendedLevel, bool>)((ExtendedLevel level) => level.NumberlessPlanetName.Equals("Gordion")));
			int levelID = val.SelectableLevel.levelID;
			if ((Object)(object)val != (Object)(object)LevelManager.CurrentExtendedLevel)
			{
				StartOfRound.Instance.ChangeLevel(levelID);
				StartOfRound.Instance.ChangePlanet();
				num = levelID;
			}
		}
		else if ((Object)(object)Selenes_Choice.PreviousSafetyMoon != (Object)null && (Object)(object)Selenes_Choice.PreviousSafetyMoon != (Object)(object)LevelManager.CurrentExtendedLevel)
		{
			int levelID2 = Selenes_Choice.PreviousSafetyMoon.SelectableLevel.levelID;
			StartOfRound.Instance.ChangeLevel(levelID2);
			StartOfRound.Instance.ChangePlanet();
			num = levelID2;
		}
		if (num != -1 && NetworkManager.Singleton.IsHost)
		{
			ES3.Save<int>("CurrentPlanetID", num, GameNetworkManager.Instance.currentSaveFileName);
		}
	}
}
[HarmonyPatch(typeof(HUDManager), "rackUpNewQuotaText")]
public class HideMoonsOnNewQuota
{
	private static void Postfix()
	{
		((MonoBehaviour)ShareSnT.Instance).StartCoroutine(WaitOnQuota());
	}

	private static IEnumerator WaitOnQuota()
	{
		yield return (object)new WaitForSeconds(2f);
		ProcessData();
	}

	private static void ProcessData()
	{
		if (!SyncedEntry<bool>.op_Implicit(Selenes_Choice.Config.DailyOrQuota))
		{
			return;
		}
		CommonShuffle.ShuffleMoons(StartOfRound.Instance.randomMapSeed);
		int num = -1;
		if (NetworkManager.Singleton.IsHost)
		{
			if ((Object)(object)Selenes_Choice.PreviousSafetyMoon != (Object)null && (Object)(object)Selenes_Choice.PreviousSafetyMoon != (Object)(object)LevelManager.CurrentExtendedLevel)
			{
				int levelID = Selenes_Choice.PreviousSafetyMoon.SelectableLevel.levelID;
				StartOfRound.Instance.ChangeLevelClientRpc(levelID, Object.FindObjectOfType<Terminal>().groupCredits);
				num = levelID;
			}
			if (num != -1)
			{
				ES3.Save<int>("CurrentPlanetID", num, GameNetworkManager.Instance.currentSaveFileName);
			}
		}
	}
}
[HarmonyPatch(typeof(HangarShipDoor), "Start")]
public class HideMoonsOnStart
{
	public static bool OldSave;

	public static int StartSeed;

	private static void Postfix()
	{
		ListProcessor.Instance.ProcessLists();
		if (!NetworkManager.Singleton.IsHost)
		{
			ShareSnT.Instance.RequestData();
			((MonoBehaviour)ShareSnT.Instance).StartCoroutine(WaitAndProcessData());
			return;
		}
		if (ES3.KeyExists("LastUsedSeed", GameNetworkManager.Instance.currentSaveFileName))
		{
			Selenes_Choice.LastUsedSeed = ES3.Load<int>("LastUsedSeed", GameNetworkManager.Instance.currentSaveFileName);
			StartSeed = Selenes_Choice.LastUsedSeed;
		}
		else
		{
			StartSeed = Random.Range(1, 100000000);
		}
		((MonoBehaviour)ShareSnT.Instance).StartCoroutine(WaitOnStart());
	}

	private static IEnumerator WaitAndProcessData()
	{
		yield return (object)new WaitUntil((Func<bool>)(() => ShareSnT.Instance.dataReceivedEvent.WaitOne(0)));
		StartSeed = Selenes_Choice.LastUsedSeed;
		((MonoBehaviour)ShareSnT.Instance).StartCoroutine(WaitOnStart());
	}

	private static IEnumerator WaitOnStart()
	{
		yield return (object)new WaitForSeconds(2f);
		ProcessData();
	}

	private static void ProcessData()
	{
		CommonShuffle.ShuffleMoons(StartSeed);
		int num = -1;
		if (!NetworkManager.Singleton.IsHost)
		{
			return;
		}
		if (TimeOfDay.Instance.daysUntilDeadline == 0)
		{
			ExtendedLevel val = ((IEnumerable<ExtendedLevel>)PatchedContent.ExtendedLevels).FirstOrDefault((Func<ExtendedLevel, bool>)((ExtendedLevel level) => level.NumberlessPlanetName.Equals("Gordion")));
			int levelID = val.SelectableLevel.levelID;
			if ((Object)(object)val != (Object)(object)LevelManager.CurrentExtendedLevel)
			{
				StartOfRound.Instance.ChangeLevelClientRpc(levelID, Object.FindObjectOfType<Terminal>().groupCredits);
				num = levelID;
			}
		}
		else
		{
			if (ES3.KeyExists("OldSave", GameNetworkManager.Instance.currentSaveFileName))
			{
				OldSave = ES3.Load<bool>("OldSave", GameNetworkManager.Instance.currentSaveFileName);
				Selenes_Choice.instance.mls.LogInfo((object)"Save Exists");
			}
			else
			{
				OldSave = false;
				Selenes_Choice.instance.mls.LogInfo((object)"Save does not exist yet");
			}
			if ((Object)(object)Selenes_Choice.PreviousSafetyMoon != (Object)null && (Object)(object)Selenes_Choice.PreviousSafetyMoon != (Object)(object)LevelManager.CurrentExtendedLevel && !OldSave)
			{
				int levelID2 = Selenes_Choice.PreviousSafetyMoon.SelectableLevel.levelID;
				StartOfRound.Instance.ChangeLevelClientRpc(levelID2, Object.FindObjectOfType<Terminal>().groupCredits);
				num = levelID2;
			}
		}
		if (num != -1)
		{
			ES3.Save<int>("CurrentPlanetID", num, GameNetworkManager.Instance.currentSaveFileName);
		}
	}
}
[HarmonyPatch(typeof(StartOfRound), "ChangeLevelClientRpc")]
public class MarkAsSaved
{
	private static void Postfix()
	{
		if (NetworkManager.Singleton.IsHost && !ES3.KeyExists("OldSave", GameNetworkManager.Instance.currentSaveFileName))
		{
			ES3.Save<bool>("OldSave", true, GameNetworkManager.Instance.currentSaveFileName);
			Selenes_Choice.instance.mls.LogInfo((object)"Saving Save");
		}
	}
}
[BepInPlugin("impulse.Selenes_Choice", "SelenesChoice", "2.4.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Selenes_Choice : BaseUnityPlugin
{
	private const string modGUID = "impulse.Selenes_Choice";

	private const string modName = "SelenesChoice";

	private const string modVersion = "2.4.3";

	private readonly Harmony harmony = new Harmony("impulse.Selenes_Choice");

	public ManualLogSource mls;

	public static Selenes_Choice instance;

	public static int LastUsedSeed;

	public static int glump;

	public static ExtendedLevel PreviousSafetyMoon;

	public static int SafetyType = -1;

	public static SyncConfig Config;

	private void Awake()
	{
		instance = this;
		Config = new SyncConfig(((BaseUnityPlugin)this).Config);
		mls = Logger.CreateLogSource("impulse.Selenes_Choice");
		harmony.PatchAll(typeof(ShareSnT));
		harmony.PatchAll(typeof(AnchorTheShare));
		harmony.PatchAll(typeof(ListProcessor));
		harmony.PatchAll(typeof(UpdateConfig));
		harmony.PatchAll(typeof(HideMoonsOnStart));
		harmony.PatchAll(typeof(HideMoonsOnGameOver));
		harmony.PatchAll(typeof(GlobalVariables));
		harmony.PatchAll(typeof(ShipleaveCalc));
		harmony.PatchAll(typeof(HUDManagerPatch));
		harmony.PatchAll(typeof(UpdateConfig.ResetSaveStatusOnDC));
		harmony.PatchAll(typeof(HideMoonsOnDayChange));
		harmony.PatchAll(typeof(HideMoonsOnNewQuota));
		harmony.PatchAll(typeof(AutoRouteToCompany));
		harmony.PatchAll(typeof(KeepWeather));
		harmony.PatchAll(typeof(SaveAfterRouting));
		harmony.PatchAll(typeof(MarkAsSaved));
		if (WeatherRegistryCompatibility.enabled)
		{
			WeatherRegistryCompatibility.ChangeWeatherClearer();
		}
		else
		{
			instance.mls.LogInfo((object)"Weather Registry not detected, using default weather clearer...");
		}
		Type[] types = Assembly.GetExecutingAssembly().GetTypes();
		Type[] array = types;
		foreach (Type type in array)
		{
			MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
			MethodInfo[] array2 = methods;
			foreach (MethodInfo methodInfo in array2)
			{
				object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
				if (customAttributes.Length != 0)
				{
					methodInfo.Invoke(null, null);
				}
			}
		}
	}
}
[DataContract]
public class SyncConfig : SyncedConfig2<SyncConfig>
{
	[DataMember]
	public SyncedEntry<int> FreeMoonCount { get; private set; }

	[DataMember]
	public SyncedEntry<int> RandomMoonCount { get; private set; }

	[DataMember]
	public SyncedEntry<bool> DailyOrQuota { get; private set; }

	[DataMember]
	public SyncedEntry<string> IgnoreMoons { get; private set; }

	[DataMember]
	public SyncedEntry<string> BlacklistMoons { get; private set; }

	[DataMember]
	public SyncedEntry<string> TreasureMoons { get; private set; }

	[DataMember]
	public SyncedEntry<bool> TreasureBool { get; private set; }

	[DataMember]
	public SyncedEntry<float> TreasureBonus { get; private set; }

	[DataMember]
	public SyncedEntry<int> PaidMoonCount { get; private set; }

	[DataMember]
	public SyncedEntry<bool> RollOverMoons { get; private set; }

	[DataMember]
	public SyncedEntry<bool> StoryMoonCompat { get; private set; }

	[DataMember]
	public SyncedEntry<bool> ClearWeather { get; private set; }

	[DataMember]
	public SyncedEntry<bool> DiscountMoons { get; private set; }

	[DataMember]
	public SyncedEntry<int> MinDiscount { get; private set; }

	[DataMember]
	public SyncedEntry<int> MaxDiscount { get; private set; }

	[DataMember]
	public SyncedEntry<bool> RememberMoons { get; private set; }

	[DataMember]
	public SyncedEntry<bool> RememberAll { get; private set; }

	[DataMember]
	public SyncedEntry<int> DaysToRemember { get; private set; }

	[DataMember]
	public SyncedEntry<bool> ReturnMany { get; private set; }

	[DataMember]
	public SyncedEntry<bool> ReturnFrees { get; private set; }

	[DataMember]
	public SyncedEntry<int> ValueThreshold { get; private set; }

	[DataMember]
	public SyncedEntry<int> RareMoonCount { get; private set; }

	public SyncConfig(ConfigFile cfg)
		: base("Selenes_Choice")
	{
		ConfigManager.Register<SyncConfig>((SyncedConfig2<SyncConfig>)this);
		FreeMoonCount = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "_General_", "Free Moon Count", 1, "How many guaranteed free moons should be included?");
		PaidMoonCount = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "_General_", "Paid Moon Count", 1, "How many guaranteed paid moons should be included?");
		RandomMoonCount = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "_General_", "Extra Moon Count", 1, "How many additional moons should be included? (These can be free or paid)");
		RareMoonCount = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "_General_", "Rare Moon Count", 0, "How many paid moons above the threshold value below should be included?");
		ValueThreshold = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "_General_", "Rare Moon Threshold", 650, "Moons equal or higher than this value will be used for the Rare Moon Count.");
		RollOverMoons = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "_General_", "Roll Over Moons", true, "If this is true and the current number of available free or paid moons do not exceed or reach the Free Moon Count/Paid Moon Count, they will be rolled over into the Random Moon Count.\nFor Example, if you have free/paid/random counts of 5/5/5 but there are only 3 paid moons then it will become 5/3/7 so there are still 15 moons generated.");
		DailyOrQuota = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "_General_", "New Moons Only on New Quota", false, "If set to true, the moons will reshuffle only after a new quota is assigned, not daily.");
		ClearWeather = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "_General_", "Clear Weather on the Safety Moon?", false, "If set to true, the first free moon selected and the one that will be auto-routed to will always have clear weather.");
		RememberMoons = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "_Remember Moons_", "Remember Moons?", true, "If set to true, the 'safety moon' is removed from the shuffle for x days (see settings below).");
		RememberAll = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "_Remember Moons_", "Remember All?", false, "If set to true, all moons that were included in a last shuffle will be removed for x days in addition to the 'safety moon' (setting above must also be true).");
		DaysToRemember = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "_Remember Moons_", "Days to Remember", 3, "The number of days that remembered moons will be excluded from the shuffle for.");
		ReturnMany = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "_Remember Moons_", "Return Many Moons?", false, "If set to true, instead of 'forgetting' just one random moon when they all become locked by the Remembrance, it will 'forget' all currenly remembered moons (clear the RVM List).");
		ReturnFrees = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "_Remember Moons_", "Only Return Free Moons?", false, "If set to true, instead of waiting for all moons to be 'remembered' before 'forgetting' them, it will 'forget' a random free moon once there are no free moons remaining (or all free moons if this and the above setting are true).");
		IgnoreMoons = SyncedBindingExtensions.BindSyncedEntry<string>(cfg, "Lists", "Ignore Moons", "Gordion", "Any moons listed here will not be touched by this mod, they cannot be part of the random moon shuffle. Use this to have moons that are constant, they will always be unhidden and unlocked. Moon names must be spelled exactly and correctly. For example, ‘Experimentation,Assurance,Vow’ would be counted, but ‘Experimentatio’ would not. (This is to avoid moon name mix-ups)");
		BlacklistMoons = SyncedBindingExtensions.BindSyncedEntry<string>(cfg, "Lists", "Blacklist Moons", "Liquidation", "Any moons listed here will be indefinitely hidden and locked, any moons here will also be excluded from the shuffle. Moon names must be spelled exactly and correctly. For example, ‘Experimentation,Assurance,Vow’ would be counted, but ‘Experimentatio’ would not. (This is to avoid moon name mix-ups).");
		TreasureMoons = SyncedBindingExtensions.BindSyncedEntry<string>(cfg, "Lists", "Treasure(?) Moons", "Embrion,StarlancerZero,Cosmocos", "Any moons listed here will remain hidden but still be routable (if you know the routing key *winky face*) Just as the other two lists, these are not in the shuffle. The config section below allows you to make them be 'Treasure Moons.' Moon names must be spelled exactly and correctly. For example, ‘Experimentation,Assurance,Vow’ would be counted, but ‘Experimentatio’ would not. (This is to avoid moon name mix-ups)");
		TreasureBool = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Treasure", "Bonus For Secret Moons?", false, "If set to true, moons from the Treasure Moons list will have a bonus value applied.");
		TreasureBonus = SyncedBindingExtensions.BindSyncedEntry<float>(cfg, "Treasure", "Treasure Bonus", 1.25f, "This multiplier is applied to the scrap value and count on treasure moons if the setting above is true.");
		StoryMoonCompat = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Compat", "Story Log Unlock Compat", true, "If set to true, certain moons will be excluded from the shuffle and untouched by this mod. Currently, this only includes two moons from Rosie's Moons.");
		DiscountMoons = SyncedBindingExtensions.BindSyncedEntry<bool>(cfg, "Discounts", "Enable Moon Discounts?", false, "If set to true, paid moons selected by the shuffle with have a discount based on the next two settings.");
		MinDiscount = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Discounts", "Min Discount", 40, "Minimum percent for a moon to have its price reduced by. Must be less than the max.");
		MaxDiscount = SyncedBindingExtensions.BindSyncedEntry<int>(cfg, "Discounts", "Max Discount", 60, "Maximum percent for a moon to have its price reduced by. Must be more than the min.");
	}
}
public static class WeatherRegistryCompatibility
{
	private static bool? _enabled;

	public static bool enabled
	{
		get
		{
			if (!_enabled.HasValue)
			{
				_enabled = Chainloader.PluginInfos.ContainsKey("mrov.WeatherRegistry");
			}
			return _enabled.Value;
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static void ChangeWeatherClearer()
	{
		Selenes_Choice.instance.mls.LogInfo((object)"Detected Weather Registry, changing weather clearer...");
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static void ClearWeatherWithWR(ExtendedLevel level)
	{
		WeatherController.ChangeWeather(level.SelectableLevel, (LevelWeatherType)(-1));
	}
}
public static class PermanentMoonsCompatibility
{
	private static bool? _enabled;

	public static bool enabled
	{
		get
		{
			if (!_enabled.HasValue)
			{
				_enabled = Chainloader.PluginInfos.ContainsKey("BULLETBOT.PermanentMoons");
			}
			return _enabled.Value;
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static Dictionary<string, object> GrabPMList()
	{
		return Plugin.GetSave();
	}
}