Decompiled source of FreeeeStoooore v1.0.1

FreeeeStoooore.dll

Decompiled 9 months ago
using System;
using System.Collections.Generic;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.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 FreeeeStoooore
{
	[BepInPlugin("bmatusiask.FreeeeStoooore", "FreeeeStoooore", "1.0.1.0")]
	public class FreeeeStoooorePlugin : BaseUnityPlugin
	{
		private const string modGUID = "bmatusiask.FreeeeStoooore";

		private const string modName = "FreeeeStoooore";

		private const string modVersion = "1.0.1.0";

		private readonly Harmony harmony = new Harmony("bmatusiask.FreeeeStoooore");

		public static FreeeeStoooorePlugin Instance { get; private set; }

		public ManualLogSource Log { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Log = Logger.CreateLogSource("FreeeeStoooore");
			Log.LogInfo((object)"Patching");
			harmony.PatchAll(typeof(FreeeeStoooorePatch));
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class FreeeeStoooorePatch
	{
		private static Terminal terminal = null;

		private static int totalCostOfItems = -5;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void FindTerminal()
		{
			FreeeeStoooorePlugin.Instance.Log.LogInfo((object)"Finding terminal object!");
			terminal = Object.FindObjectOfType<Terminal>();
			if ((Object)(object)terminal == (Object)null)
			{
				FreeeeStoooorePlugin.Instance.Log.LogError((object)"Failed to find terminal object!");
			}
			else
			{
				FreeeeStoooorePlugin.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 obj = Traverse.Create((object)terminal).Field("totalCostOfItems");
				totalCostOfItems = (int)obj.GetValue();
				obj.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.Create((object)terminal).Field("totalCostOfItems").SetValue((object)0);
				totalCostOfItems = -5;
			}
		}

		[HarmonyPatch("LoadNewNodeIfAffordable")]
		[HarmonyPrefix]
		private static void changeDecorationPrices(TerminalNode node, ref List<TerminalNode> ___ShipDecorSelection)
		{
			if (!((Object)(object)node == (Object)null))
			{
				for (int i = 0; i < terminal.buyableItemsList.Length; i++)
				{
					terminal.buyableItemsList[i].creditsWorth = 0;
				}
				node.itemCost = 0;
			}
		}

		[HarmonyPatch("RotateShipDecorSelection")]
		[HarmonyPostfix]
		private static void changeShownDecorationPrices(ref List<TerminalNode> ___ShipDecorSelection)
		{
			___ShipDecorSelection.Clear();
			for (int i = 0; i < StartOfRound.Instance.unlockablesList.unlockables.Count; i++)
			{
				UnlockableItem val = StartOfRound.Instance.unlockablesList.unlockables[i];
				if ((Object)(object)val.shopSelectionNode != (Object)null && !val.alwaysInStock)
				{
					___ShipDecorSelection.Add(val.shopSelectionNode);
				}
			}
			foreach (TerminalNode item in ___ShipDecorSelection)
			{
				FreeeeStoooorePlugin.Instance.Log.LogInfo((object)("Overriding the price of ship decoration (" + ((object)item).ToString() + ")"));
				item.itemCost = 0;
			}
			for (int j = 0; j < terminal.buyableItemsList.Length; j++)
			{
				terminal.buyableItemsList[j].creditsWorth = 0;
			}
		}
	}
}