Decompiled source of FreeeeeeMoooooons v1.0.1

BepInEx/plugins/FreeMoons.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("FreeMoons")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FreeMoons")]
[assembly: AssemblyTitle("FreeMoons")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
namespace SRH.Mods.LC
{
	[BepInPlugin("SlushyRH.LethalCompany.FreeMoons", "FreeMoons", "1.0.1")]
	public class FreeMoonsPlugin : BaseUnityPlugin
	{
		private const string GUID = "SlushyRH.LethalCompany.FreeMoons";

		private const string NAME = "FreeMoons";

		private const string VERSION = "1.0.1";

		private readonly Harmony harmony = new Harmony("SlushyRH.LethalCompany.FreeMoons");

		public static FreeMoonsPlugin Instance { get; private set; }

		public ManualLogSource Log { get; private set; }

		private void Awake()
		{
			Log = Logger.CreateLogSource("SlushyRH.LethalCompany.FreeMoons");
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			harmony.PatchAll(typeof(MoonPricePatch));
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class MoonPricePatch
	{
		private static Terminal terminal = null;

		private static int totalCostOfItems = -5;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void FindTerminal()
		{
			FreeMoonsPlugin.Instance.Log.LogInfo((object)"Finding terminal object!");
			terminal = Object.FindObjectOfType<Terminal>();
			if ((Object)(object)terminal == (Object)null)
			{
				FreeMoonsPlugin.Instance.Log.LogError((object)"Failed to find terminal object!");
			}
			else
			{
				FreeMoonsPlugin.Instance.Log.LogInfo((object)"Found terminal object!");
			}
		}

		[HarmonyPatch("LoadNewNode")]
		[HarmonyPrefix]
		private static void LoadNewNodePatchBefore(ref TerminalNode node)
		{
			if ((!((Object)(object)terminal == (Object)null) || !((Object)(object)node == (Object)null)) && node.buyRerouteToMoon == -2)
			{
				Traverse val = Traverse.Create((object)terminal).Field("totalCostOfItems");
				totalCostOfItems = (int)val.GetValue();
				val.SetValue((object)0);
			}
		}

		[HarmonyPatch("LoadNewNode")]
		[HarmonyPostfix]
		private static void LoadNewNodePatchAfter(ref TerminalNode node)
		{
			if ((!((Object)(object)terminal == (Object)null) || !((Object)(object)node == (Object)null)) && totalCostOfItems != -5)
			{
				Traverse val = Traverse.Create((object)terminal).Field("totalCostOfItems");
				val.SetValue((object)0);
				totalCostOfItems = -5;
			}
		}

		[HarmonyPatch("LoadNewNodeIfAffordable")]
		[HarmonyPrefix]
		private static void LoadNewNodeIfAffordablePatch(ref TerminalNode node)
		{
			if (!((Object)(object)node == (Object)null) && node.buyRerouteToMoon != -1)
			{
				node.itemCost = 0;
			}
		}
	}
}