Decompiled source of AllDecorAlways v1.1.0

AllDecorAlways.dll

Decompiled 10 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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("AllDecorAlways")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AllDecorAlways")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2fe88052-1b99-41b3-85bc-6fea62ae8851")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AllDecorAlways
{
	[BepInPlugin("stormytuna.AllDecorAlways", "AllDecorAlways", "1.1.0")]
	public class AllDecorAlwaysBase : BaseUnityPlugin
	{
		public const string ModGUID = "stormytuna.AllDecorAlways";

		public const string ModName = "AllDecorAlways";

		public const string ModVersion = "1.1.0";

		public static ManualLogSource Log = Logger.CreateLogSource("stormytuna.AllDecorAlways");

		public static AllDecorAlwaysBase Instance;

		private readonly Harmony harmony = new Harmony("stormytuna.AllDecorAlways");

		public static ConfigEntry<bool> UnlockAllDecor;

		private void Awake()
		{
			if (Instance == null)
			{
				Instance = this;
			}
			Log.LogInfo((object)"All Decor Always has awoken!");
			LoadConfigs();
			harmony.PatchAll();
		}

		private void LoadConfigs()
		{
			UnlockAllDecor = ((BaseUnityPlugin)this).Config.Bind<bool>("Cheats", "UnlockAllDecor", false, "Whether or not all decor should be unlocked immediately rather than having to be bought");
		}
	}
}
namespace AllDecorAlways.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("LoadUnlockables")]
		public static void UnlockAllDecor(UnlockablesList ___unlockablesList)
		{
			if (!AllDecorAlwaysBase.UnlockAllDecor.Value)
			{
				return;
			}
			for (int i = 0; i < ___unlockablesList.unlockables.Count; i++)
			{
				UnlockableItem val = ___unlockablesList.unlockables[i];
				if (!val.hasBeenUnlockedByPlayer && !val.alreadyUnlocked && !((Object)(object)val.shopSelectionNode == (Object)null) && !val.alwaysInStock)
				{
					AllDecorAlwaysBase.Log.LogInfo((object)("Unlocking " + val.unlockableName + "!"));
					val.hasBeenUnlockedByPlayer = true;
					if (val.unlockableType == 0)
					{
						MethodInfo method = typeof(StartOfRound).GetMethod("SpawnUnlockable", BindingFlags.Instance | BindingFlags.NonPublic);
						method.Invoke(StartOfRound.Instance, new object[1] { i });
					}
					else
					{
						val.inStorage = true;
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	public class TerminalPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("RotateShipDecorSelection")]
		public static bool AddAllShipDecor(Terminal __instance)
		{
			IEnumerable<TerminalNode> enumerable = from u in StartOfRound.Instance.unlockablesList.unlockables
				where (Object)(object)u.shopSelectionNode != (Object)null && !u.alwaysInStock && !u.hasBeenUnlockedByPlayer && !u.alreadyUnlocked
				select u.shopSelectionNode;
			foreach (TerminalNode item in enumerable)
			{
				AllDecorAlwaysBase.Log.LogInfo((object)("Thing is " + ((Object)item).name));
			}
			__instance.ShipDecorSelection = enumerable.ToList();
			AllDecorAlwaysBase.Log.LogInfo((object)"Decor for everyone!");
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		public static void ChangeDecorHeading(Terminal __instance)
		{
			TerminalNode specialKeywordResult = __instance.terminalNodes.allKeywords.First((TerminalKeyword kw) => ((Object)kw).name == "Store").specialKeywordResult;
			List<string> list = specialKeywordResult.displayText.Split(new char[1] { '\n' }).ToList();
			int num = list.IndexOf("[unlockablesSelectionList]");
			if (num < 0)
			{
				AllDecorAlwaysBase.Log.LogError((object)"Failed to find decor start index in store node display text!");
				return;
			}
			list[num - 2] = "The Company appreciates your hard work, all ship decor is available:";
			specialKeywordResult.displayText = string.Join("\n", list);
		}
	}
}