Decompiled source of CustomMoonPrices v1.1.5

CustomMoonPrices.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CustomMoonPrices;
using CustomMoonPrices.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using LCCustomMoonPrices;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalLevelLoader;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CustomMoonPrices")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomMoonPrices")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9a728026-3819-4911-81cd-1be3f886290a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCCustomMoonPrices
{
	[Serializable]
	public class SyncedInstance<T>
	{
		private static readonly DataContractSerializer serializer = new DataContractSerializer(typeof(T));

		[NonSerialized]
		protected static int IntSize = 4;

		internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager;

		internal static bool IsClient => NetworkManager.Singleton.IsClient;

		internal static bool IsHost => NetworkManager.Singleton.IsHost;

		public static T Default { get; private set; }

		public static T Instance { get; private set; }

		public static bool Synced { get; internal set; }

		protected void InitInstance(T instance)
		{
			Default = instance;
			Instance = instance;
			IntSize = 4;
		}

		internal static void SyncInstance(byte[] data)
		{
			Instance = DeserializeFromBytes(data);
			Synced = true;
		}

		internal static void RevertSync()
		{
			Instance = Default;
			Synced = false;
		}

		public static byte[] SerializeToBytes(T val)
		{
			using MemoryStream memoryStream = new MemoryStream();
			try
			{
				((XmlObjectSerializer)serializer).WriteObject((Stream)memoryStream, (object)val);
				return memoryStream.ToArray();
			}
			catch (Exception ex)
			{
				CustomMoonPricesMain.CMPLogger.LogError((object)("Error serializing instance: " + ex));
				return null;
			}
		}

		public static T DeserializeFromBytes(byte[] data)
		{
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			using MemoryStream memoryStream = new MemoryStream(data);
			try
			{
				return (T)((XmlObjectSerializer)serializer).ReadObject((Stream)memoryStream);
			}
			catch (Exception ex)
			{
				CustomMoonPricesMain.CMPLogger.LogError((object)("Error deserializing instance: " + ex));
				return default(T);
			}
		}
	}
}
namespace CustomMoonPrices
{
	[Serializable]
	public class Config : SyncedInstance<Config>
	{
		public Dictionary<string, moonData> moonData;

		public Config()
		{
			InitInstance(this);
			moonData = new Dictionary<string, moonData>();
		}

		public void updateMoonEnabled(string moonname, bool enabled)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (!SyncedInstance<Config>.IsHost)
			{
				return;
			}
			SyncedInstance<Config>.Instance.moonData[moonname].setEnabled(enabled);
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(30000, (Allocator)2, -1);
			try
			{
				SyncedInstance<Config>.MessageManager.SendNamedMessageToAll("CMP_OSC", val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		public void updateMoonPrice(string moonname, int price)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (!SyncedInstance<Config>.IsHost)
			{
				return;
			}
			SyncedInstance<Config>.Instance.moonData[moonname].setPrice(price);
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(30000, (Allocator)2, -1);
			try
			{
				SyncedInstance<Config>.MessageManager.SendNamedMessageToAll("CMP_OSC", val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		internal static void RequestSync()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (!SyncedInstance<Config>.IsClient)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(30000, (Allocator)2, -1);
			try
			{
				SyncedInstance<Config>.MessageManager.SendNamedMessage("CMP_ORS", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		internal static void OnRequestSync(ulong clientId, FastBufferReader _)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			if (!SyncedInstance<Config>.IsHost)
			{
				return;
			}
			CustomMoonPricesMain.CMPLogger.LogDebug((object)$"Config sync request received from client: {clientId}");
			byte[] array = SyncedInstance<Config>.SerializeToBytes(SyncedInstance<Config>.Instance);
			int num = array.Length;
			int num2 = num + SyncedInstance<Config>.IntSize;
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(num2, (Allocator)2, -1);
			try
			{
				bool flag = ((FastBufferWriter)(ref val)).Capacity > 1000;
				NetworkDelivery val2 = (NetworkDelivery)(flag ? 4 : 2);
				if (flag)
				{
					CustomMoonPricesMain.CMPLogger.LogDebug((object)($"Size of stream ({((FastBufferWriter)(ref val)).Capacity}) was past the max buffer size.\n" + "Config instance will be sent in fragments to avoid overflowing the buffer."));
				}
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteBytesSafe(array, num, 0);
				SyncedInstance<Config>.MessageManager.SendNamedMessage("CMP_ORCS", clientId, val, val2);
			}
			catch (Exception arg)
			{
				CustomMoonPricesMain.CMPLogger.LogDebug((object)$"Error occurred syncing config with client: {clientId}\n{arg}");
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		internal static void OnReceiveSync(ulong _, FastBufferReader reader)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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)
			CustomMoonPricesMain.CMPLogger.LogDebug((object)"Config sync received from host.");
			if (!((FastBufferReader)(ref reader)).TryBeginRead(SyncedInstance<Config>.IntSize))
			{
				CustomMoonPricesMain.CMPLogger.LogError((object)"Config sync error: Could not begin reading buffer.");
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			if (!((FastBufferReader)(ref reader)).TryBeginRead(num))
			{
				CustomMoonPricesMain.CMPLogger.LogError((object)"Config sync error: Host could not sync.");
				return;
			}
			byte[] data = new byte[num];
			((FastBufferReader)(ref reader)).ReadBytesSafe(ref data, num, 0);
			try
			{
				SyncedInstance<Config>.SyncInstance(data);
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(30000, (Allocator)2, -1);
				try
				{
					SyncedInstance<Config>.MessageManager.SendNamedMessage("CMP_SC", 0uL, val, (NetworkDelivery)3);
				}
				finally
				{
					((IDisposable)(FastBufferWriter)(ref val)).Dispose();
				}
			}
			catch (Exception arg)
			{
				CustomMoonPricesMain.CMPLogger.LogError((object)$"Error syncing config instance!\n{arg}");
			}
		}

		internal static void OnSettingChange(ulong _, FastBufferReader reader)
		{
			if (SyncedInstance<Config>.IsClient)
			{
				RequestSync();
			}
		}

		internal static void OnReceivedSync(ulong senderClientId, FastBufferReader messagePayload)
		{
			if (SyncedInstance<Config>.IsHost)
			{
				CustomMoonPricesMain.CMPLogger.LogDebug((object)("Client " + senderClientId + " Succesfully Synced."));
			}
		}
	}
	[BepInPlugin("zz.cursedbreath.custommoonprices", "Custom Moon Prices", "1.1.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("Lethal Company.exe")]
	public class CustomMoonPricesMain : BaseUnityPlugin
	{
		public const string UMID = "zz.cursedbreath.custommoonprices";

		public const string NAME = "Custom Moon Prices";

		public const string VERSION = "1.1.2";

		private Harmony harmony;

		public static CustomMoonPricesMain CustomMoonPricesMainInstance;

		public static ConfigFile LethalConfigSettings;

		public static bool existLethalLevelLoader;

		public static ManualLogSource CMPLogger;

		private void Awake()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			CMPLogger = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("zz.cursedbreath.custommoonprices");
			LethalConfigSettings = ((BaseUnityPlugin)this).Config;
			new Config();
			harmony.PatchAll(typeof(MoonPricePatches));
			harmony.PatchAll(typeof(ConfigSyncPatch));
			foreach (PluginInfo item in Chainloader.PluginInfos.Values.ToList())
			{
				if (item.Metadata.GUID == "imabatby.lethallevelloader")
				{
					existLethalLevelLoader = true;
				}
			}
		}
	}
	[Serializable]
	public class moonData
	{
		private bool enabled;

		private int price;

		public moonData(bool enabled, int price)
		{
			this.enabled = enabled;
			this.price = price;
		}

		public bool getEnabled()
		{
			return enabled;
		}

		public int getPrice()
		{
			return price;
		}

		public void setEnabled(bool enabled)
		{
			this.enabled = enabled;
		}

		public void setPrice(int price)
		{
			this.price = price;
		}
	}
}
namespace CustomMoonPrices.Patches
{
	public class ConfigSyncPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		public static void InitializeLocalPlayer()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			if (SyncedInstance<Config>.IsHost)
			{
				SyncedInstance<Config>.MessageManager.RegisterNamedMessageHandler("CMP_ORS", new HandleNamedMessageDelegate(Config.OnRequestSync));
				SyncedInstance<Config>.MessageManager.RegisterNamedMessageHandler("CMP_SC", new HandleNamedMessageDelegate(Config.OnReceivedSync));
				SyncedInstance<Config>.Synced = true;
			}
			else
			{
				SyncedInstance<Config>.Synced = false;
				SyncedInstance<Config>.MessageManager.RegisterNamedMessageHandler("CMP_OSC", new HandleNamedMessageDelegate(Config.OnSettingChange));
				SyncedInstance<Config>.MessageManager.RegisterNamedMessageHandler("CMP_ORCS", new HandleNamedMessageDelegate(Config.OnReceiveSync));
				Config.RequestSync();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
		public static void PlayerLeave()
		{
			SyncedInstance<Config>.RevertSync();
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	public class MoonPricePatches
	{
		public static Terminal terminal;

		private static int totalCostOfItems = -5;

		private static Dictionary<string, int> defaultMoonPrices = new Dictionary<string, int>();

		internal static string GetNumberlessPlanetName(SelectableLevel selectableLevel)
		{
			if ((Object)(object)selectableLevel != (Object)null)
			{
				return new string(selectableLevel.PlanetName.SkipWhile((char c) => !char.IsLetter(c)).ToArray());
			}
			return string.Empty;
		}

		private static string GetMoonName(string id)
		{
			return id switch
			{
				"8" => "titan", 
				"7" => "dine", 
				"85" => "rend", 
				"61" => "march", 
				"56" => "vow", 
				"220" => "assurance", 
				"41" => "experimentation", 
				"21" => "offense", 
				"5" => "embrion", 
				"68" => "artifice", 
				null => null, 
				_ => null, 
			};
		}

		[HarmonyPriority(100)]
		[HarmonyPatch(typeof(RoundManager), "Start")]
		[HarmonyPostfix]
		internal static void RoundManagerStart_Prefix()
		{
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Expected O, but got Unknown
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			if (!CustomMoonPricesMain.existLethalLevelLoader)
			{
				return;
			}
			try
			{
				foreach (ExtendedLevel customExtendedLevel in PatchedContent.CustomExtendedLevels)
				{
					string configname = customExtendedLevel.NumberlessPlanetName;
					configname = configname.Replace(" ", "").ToLower();
					if (!configname.Contains("gordion"))
					{
						ConfigEntry<bool> val = CustomMoonPricesMain.LethalConfigSettings.Bind<bool>(configname, "Enable", false, "Setting if custom Price for: " + configname + " should be applied.");
						ConfigEntry<int> val2 = CustomMoonPricesMain.LethalConfigSettings.Bind<int>(configname, "Price", 0, "Setting the custom Price for: " + configname + ".");
						val.SettingChanged += delegate
						{
							bool value4 = CustomMoonPricesMain.LethalConfigSettings.Bind<bool>(configname, "Enable", false, "Setting if custom Price for: " + configname + " should be applied.").Value;
							SyncedInstance<Config>.Instance.updateMoonEnabled(configname, value4);
						};
						val2.SettingChanged += delegate
						{
							int value3 = CustomMoonPricesMain.LethalConfigSettings.Bind<int>(configname, "Price", 0, "Setting the custom Price for: " + configname + ".").Value;
							SyncedInstance<Config>.Instance.updateMoonPrice(configname, value3);
						};
						if (SyncedInstance<Config>.Instance.moonData.ContainsKey(configname))
						{
							bool value = CustomMoonPricesMain.LethalConfigSettings.Bind<bool>(configname, "Enable", false, "Setting if custom Price for: " + configname + " should be applied.").Value;
							int value2 = CustomMoonPricesMain.LethalConfigSettings.Bind<int>(configname, "Price", 0, "Setting the custom Price for: " + configname + ".").Value;
							SyncedInstance<Config>.Instance.updateMoonEnabled(configname, value);
							SyncedInstance<Config>.Instance.updateMoonPrice(configname, value2);
						}
						else
						{
							SyncedInstance<Config>.Instance.moonData[configname] = new moonData(val.Value, val2.Value);
						}
						BoolCheckBoxConfigItem val3 = new BoolCheckBoxConfigItem(val);
						IntInputFieldConfigItem val4 = new IntInputFieldConfigItem(val2);
						LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val3);
						LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val4);
						if (!defaultMoonPrices.ContainsKey(configname))
						{
							defaultMoonPrices.Add(configname, customExtendedLevel.RoutePrice);
						}
					}
				}
				CustomMoonPricesMain.LethalConfigSettings.Save();
			}
			catch (Exception ex)
			{
				CustomMoonPricesMain.CMPLogger.LogError((object)("Error in finding Adding Moons to Dictionary: " + ex));
			}
		}

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void FindTerminal()
		{
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Expected O, but got Unknown
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Expected O, but got Unknown
			terminal = Object.FindObjectOfType<Terminal>();
			if ((Object)(object)terminal == (Object)null)
			{
				CustomMoonPricesMain.CMPLogger.LogDebug((object)"Terminal not found!");
			}
			else
			{
				CustomMoonPricesMain.CMPLogger.LogDebug((object)"Terminal found!");
			}
			try
			{
				SelectableLevel[] levels = StartOfRound.Instance.levels;
				foreach (SelectableLevel val in levels)
				{
					if (!((Object)val).name.Contains("Company"))
					{
						string configname = GetNumberlessPlanetName(val).ToLower();
						CustomMoonPricesMain.CMPLogger.LogDebug((object)("ConfigName: " + configname));
						ConfigEntry<bool> val2 = CustomMoonPricesMain.LethalConfigSettings.Bind<bool>(configname, "Enable", false, "Setting if custom Price for: " + configname + " should be applied.");
						ConfigEntry<int> val3 = CustomMoonPricesMain.LethalConfigSettings.Bind<int>(configname, "Price", 0, "Setting the custom Price for: " + configname + ".");
						val2.SettingChanged += delegate
						{
							bool value4 = CustomMoonPricesMain.LethalConfigSettings.Bind<bool>(configname, "Enable", false, "Setting if custom Price for: " + configname + " should be applied.").Value;
							SyncedInstance<Config>.Instance.updateMoonEnabled(configname, value4);
						};
						val3.SettingChanged += delegate
						{
							int value3 = CustomMoonPricesMain.LethalConfigSettings.Bind<int>(configname, "Price", 0, "Setting the custom Price for: " + configname + ".").Value;
							SyncedInstance<Config>.Instance.updateMoonPrice(configname, value3);
						};
						if (SyncedInstance<Config>.Instance.moonData.ContainsKey(configname))
						{
							bool value = CustomMoonPricesMain.LethalConfigSettings.Bind<bool>(configname, "Enable", false, "Setting if custom Price for: " + configname + " should be applied.").Value;
							int value2 = CustomMoonPricesMain.LethalConfigSettings.Bind<int>(configname, "Price", 0, "Setting the custom Price for: " + configname + ".").Value;
							SyncedInstance<Config>.Instance.updateMoonEnabled(configname, value);
							SyncedInstance<Config>.Instance.updateMoonPrice(configname, value2);
						}
						else
						{
							SyncedInstance<Config>.Instance.moonData[configname] = new moonData(val2.Value, val3.Value);
						}
						BoolCheckBoxConfigItem val4 = new BoolCheckBoxConfigItem(val2);
						IntInputFieldConfigItem val5 = new IntInputFieldConfigItem(val3);
						LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val4);
						LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val5);
						if (!defaultMoonPrices.ContainsKey(configname))
						{
							defaultMoonPrices.Add(configname, 0);
						}
						if (!SyncedInstance<Config>.Instance.moonData.ContainsKey(configname))
						{
							SyncedInstance<Config>.Instance.moonData[configname] = new moonData(val2.Value, val3.Value);
						}
					}
				}
				CustomMoonPricesMain.LethalConfigSettings.Save();
			}
			catch (Exception ex)
			{
				CustomMoonPricesMain.CMPLogger.LogError((object)("Error in finding Adding Moons to Dictionary: " + ex));
			}
		}

		[HarmonyPatch("LoadNewNode")]
		[HarmonyPrefix]
		private static void LoadNewNodePatchBefore(ref TerminalNode node)
		{
			if (node.buyRerouteToMoon != -2)
			{
				return;
			}
			Traverse val = Traverse.Create((object)terminal).Field("totalCostOfItems");
			string text = ((Object)node).name;
			if (text.Contains("route"))
			{
				text = text.Replace("route", "");
			}
			if (text.Contains("Route") || text.Contains("Confirm"))
			{
				text = text.Replace("Route", "");
				text = text.Replace("Confirm", "");
			}
			text = ((GetMoonName(text) == null) ? new string(text.SkipWhile((char c) => !char.IsLetter(c)).ToArray()) : GetMoonName(text));
			CustomMoonPricesMain.CMPLogger.LogDebug((object)("Moonname: " + text));
			if (text == null)
			{
				CustomMoonPricesMain.CMPLogger.LogDebug((object)"Moon not found (Just a Reminder when not a moon node)!");
				return;
			}
			if (text.Equals("CompanyMoon"))
			{
				CustomMoonPricesMain.CMPLogger.LogDebug((object)"Company Moon no Costs Possible!");
				return;
			}
			try
			{
				if (defaultMoonPrices[text] == 0)
				{
					defaultMoonPrices[text] = node.itemCost;
				}
				if (SyncedInstance<Config>.Instance.moonData[text].getEnabled())
				{
					totalCostOfItems = (int)val.GetValue();
					val.SetValue((object)SyncedInstance<Config>.Instance.moonData[text].getPrice());
				}
				else
				{
					val.SetValue((object)defaultMoonPrices[text]);
				}
			}
			catch (Exception)
			{
			}
		}

		[HarmonyPatch("LoadNewNode")]
		[HarmonyPostfix]
		private static void LoadNewNodePatchAfter(ref TerminalNode node)
		{
			Traverse val = Traverse.Create((object)terminal).Field("totalCostOfItems");
			if (totalCostOfItems == -5)
			{
				return;
			}
			string text = ((Object)node).name;
			if (text.Contains("route"))
			{
				text = text.Replace("route", "");
			}
			if (text.Contains("Route") || text.Contains("Confirm"))
			{
				text = text.Replace("Route", "");
				text = text.Replace("Confirm", "");
			}
			text = ((GetMoonName(text) == null) ? new string(text.SkipWhile((char c) => !char.IsLetter(c)).ToArray()) : GetMoonName(text));
			CustomMoonPricesMain.CMPLogger.LogDebug((object)("Moonname: " + text));
			if (text == null)
			{
				CustomMoonPricesMain.CMPLogger.LogDebug((object)"Moon not found (Just a Reminder when not a moon node)!");
				return;
			}
			if (text.Equals("CompanyMoon"))
			{
				CustomMoonPricesMain.CMPLogger.LogDebug((object)"Company Moon no Costs Possible!");
				return;
			}
			try
			{
				if (SyncedInstance<Config>.Instance.moonData[text].getEnabled())
				{
					val.SetValue((object)SyncedInstance<Config>.Instance.moonData[text].getPrice());
				}
				else
				{
					val.SetValue((object)defaultMoonPrices[text]);
				}
				totalCostOfItems = -5;
			}
			catch (Exception)
			{
			}
		}

		[HarmonyPatch("LoadNewNodeIfAffordable")]
		[HarmonyPrefix]
		private static void LoadNewNodeIfAffordablePatch(ref TerminalNode node)
		{
			if ((Object)(object)node == (Object)null || node.buyRerouteToMoon == -1)
			{
				return;
			}
			string text = ((Object)node).name;
			if (text.Contains("route"))
			{
				text = text.Replace("route", "");
			}
			if (text.Contains("Route") || text.Contains("Confirm"))
			{
				text = text.Replace("Route", "");
				text = text.Replace("Confirm", "");
			}
			text = ((GetMoonName(text) == null) ? new string(text.SkipWhile((char c) => !char.IsLetter(c)).ToArray()) : GetMoonName(text));
			CustomMoonPricesMain.CMPLogger.LogDebug((object)("Moonname: " + text));
			if (text == null)
			{
				CustomMoonPricesMain.CMPLogger.LogDebug((object)"Moon not found (Just a Reminder when not a moon node)!");
				return;
			}
			if (text.Equals("CompanyMoon"))
			{
				CustomMoonPricesMain.CMPLogger.LogDebug((object)"Company Moon no Costs Possible!");
				return;
			}
			try
			{
				if (SyncedInstance<Config>.Instance.moonData[text].getEnabled())
				{
					node.itemCost = SyncedInstance<Config>.Instance.moonData[text].getPrice();
				}
				else
				{
					node.itemCost = defaultMoonPrices[text];
				}
			}
			catch (Exception)
			{
			}
		}
	}
}