Decompiled source of MushShop v1.0.0

BepInEx/plugins/BetterShop.dll

Decompiled 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 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("BetterShop")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterShop")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9def6854-605e-49c6-be88-10d3a82f92e5")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Shop
{
	public class ConfigManager
	{
		public static ConfigManager Instance { get; private set; }

		public static ConfigEntry<bool> Radio { get; private set; }

		public static ConfigEntry<bool> Teleporter { get; private set; }

		public static ConfigEntry<bool> InverseTeleporter { get; private set; }

		public static ConfigEntry<bool> LoudHorn { get; private set; }

		public static ConfigEntry<bool> SignalTranslator { get; private set; }

		public static ConfigEntry<int> Flashlights { get; private set; }

		public static ConfigEntry<int> ProFlashlights { get; private set; }

		public static ConfigEntry<int> WalkieTalkies { get; private set; }

		public static ConfigEntry<int> LockPickers { get; private set; }

		public static ConfigEntry<int> ExtensionLadders { get; private set; }

		public static ConfigEntry<int> RadarBoosters { get; private set; }

		public static ConfigEntry<int> SprayPaints { get; private set; }

		public static ConfigEntry<int> Jetpacks { get; private set; }

		public static ConfigEntry<int> Inhalants { get; private set; }

		public static ConfigEntry<int> Shovels { get; private set; }

		public static ConfigEntry<int> StunGrenades { get; private set; }

		public static ConfigEntry<int> ZapGuns { get; private set; }

		public static ConfigEntry<int> Shotgun { get; private set; }

		public static ConfigEntry<int> ShotgunShells { get; private set; }

		public static ConfigEntry<bool> CozyLights { get; private set; }

		public static ConfigEntry<bool> Television { get; private set; }

		public static ConfigEntry<bool> Toilet { get; private set; }

		public static ConfigEntry<bool> Shower { get; private set; }

		public static ConfigEntry<bool> RecordPlayer { get; private set; }

		public static ConfigEntry<bool> Table { get; private set; }

		public static ConfigEntry<bool> RomanticTable { get; private set; }

		public static ConfigEntry<bool> JackOLantern { get; private set; }

		public static ConfigEntry<bool> WelcomeMat { get; private set; }

		public static ConfigEntry<bool> Goldfish { get; private set; }

		public static ConfigEntry<bool> PlushiePajama { get; private set; }

		public static ConfigEntry<bool> Suits { get; private set; }

		public static ConfigEntry<bool> Debug { get; private set; }

		public static void Init(ConfigFile config)
		{
			Instance = new ConfigManager(config);
		}

		private ConfigManager(ConfigFile config)
		{
			Radio = config.Bind<bool>("Ship upgrades", "Radio", true, "Unlock the radio on new save.");
			Teleporter = config.Bind<bool>("Teleporters", "Teleporter", false, "Unlock the teleporter on new save.");
			InverseTeleporter = config.Bind<bool>("Teleporters", "Inverse Teleporter", false, "Unlock the inverse teleporter on new save.");
			LoudHorn = config.Bind<bool>("Ship upgrades", "Loud Horn", false, "Unlock the loud horn on new save.");
			SignalTranslator = config.Bind<bool>("Ship upgrades", "Signal Translator", false, "Unlock the signal translator on new save.");
			Flashlights = config.Bind<int>("Flashlights", "Flashlight", 0, "How many flashlights to unlock on new save.");
			ProFlashlights = config.Bind<int>("Flashlights", "Pro-flashlight", 0, "How many pro-flashlights to unlock on new save.");
			WalkieTalkies = config.Bind<int>("Tools", "Walkie-Talkie", 0, "How many walkie-talkies to unlock on new save.");
			LockPickers = config.Bind<int>("Tools", "Lockpicker", 0, "How many lockpickers to unlock on new save.");
			ExtensionLadders = config.Bind<int>("Tools", "Extension Ladder", 0, "How many extension ladders to unlock on new save.");
			RadarBoosters = config.Bind<int>("Tools", "Radar Booster", 0, "How many radar boosters to unlock on new save.");
			SprayPaints = config.Bind<int>("Tools", "Spray Paint", 0, "How many spray paints to unlock on new save.");
			Jetpacks = config.Bind<int>("Tools", "Jetpack", 0, "How many jetpacks to unlock on new save.");
			Inhalants = config.Bind<int>("Consumables", "TZP-Inhalant", 0, "How many inhalants to unlock on new save.");
			Shovels = config.Bind<int>("Weapons", "Shovel", 0, "How many shovels to unlock on new save.");
			StunGrenades = config.Bind<int>("Weapons", "Stun Grenade", 0, "How many stun grenades to unlock on new save.");
			ZapGuns = config.Bind<int>("Weapons", "Zap Gun", 0, "How many zap guns to unlock on new save.");
			Shotgun = config.Bind<int>("Weapons", "Shotgun", 0, "How many shotguns to unlock on new save.");
			ShotgunShells = config.Bind<int>("Weapons", "Shotgun Shells", 0, "How many shotgun shells to unlock on new save.");
			CozyLights = config.Bind<bool>("Decorations", "Cozy Lights", false, "Unlock the cozy lights on new save.");
			Television = config.Bind<bool>("Decorations", "Television", true, "Unlock the television on new save.");
			Toilet = config.Bind<bool>("Decorations", "Toilet", false, "Unlock the toilet on new save.");
			Shower = config.Bind<bool>("Decorations", "Shower", false, "Unlock the shower on new save.");
			RecordPlayer = config.Bind<bool>("Decorations", "Record Player", false, "Unlock the record player on new save.");
			Table = config.Bind<bool>("Decorations", "Table", false, "Unlock the table on new save.");
			RomanticTable = config.Bind<bool>("Decorations", "Romantic Table", false, "Unlock the romantic table on new save.");
			JackOLantern = config.Bind<bool>("Decorations", "Jack-O-Lantern", false, "Unlock the jack-o-lantern on new save.");
			WelcomeMat = config.Bind<bool>("Decorations", "Welcome Mat", false, "Unlock the welcome mat on new save.");
			Goldfish = config.Bind<bool>("Decorations", "Goldfish", false, "Unlock the goldfish on new save.");
			PlushiePajama = config.Bind<bool>("Decorations", "Plushie Pajama", false, "Unlock the plushie pajama on new save.");
			Suits = config.Bind<bool>("Suits", "Suits", false, "Unlock all suits on new save.");
			Debug = config.Bind<bool>("Debug", "Debugging", true, "Enable debug logging.");
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class NewSaveStartPatch
	{
		[HarmonyPatch("firstDayAnimation")]
		[HarmonyPrefix]
		internal static void LoadUnlockablesFromConfig()
		{
			if (!GameNetworkManager.Instance.isHostingGame)
			{
				return;
			}
			List<UnlockableItem> unlockables = StartOfRound.Instance.unlockablesList.unlockables;
			foreach (UnlockableItem item in unlockables)
			{
				string unlockableName = item.unlockableName;
				int unlockableID = unlockables.IndexOf(item);
				checkInDictionary(Unlockables.ShipUpgradesDictionary, unlockableID, unlockableName);
				checkInDictionary(Unlockables.SuitDictionary, unlockableID, unlockableName);
				checkInDictionary(Unlockables.DecorationDictionary, unlockableID, unlockableName);
			}
			SpawnItemsFromConfig();
		}

		internal static void SpawnItemsFromConfig()
		{
			//IL_009e: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			List<Item> itemsList = StartOfRound.Instance.allItemsList.itemsList;
			foreach (Item item in itemsList)
			{
				string itemName = item.itemName;
				itemsList.IndexOf(item);
				if (Unlockables.ItemsDictionary.ContainsKey(itemName))
				{
					if (Unlockables.ItemsDictionary[itemName] == 0)
					{
						continue;
					}
					Plugin.logger.LogInfo((object)$"Unlocking {itemName} * {Unlockables.ItemsDictionary[itemName]}.");
					for (int i = 0; i < Unlockables.ItemsDictionary[itemName]; i++)
					{
						Vector3 position = StartOfRound.Instance.playerSpawnPositions[1].position;
						position.x += Random.Range(-0.7f, 0.7f);
						position.z += Random.Range(2f, 2f);
						position.y += 0.5f;
						GrabbableObject component = Object.Instantiate<GameObject>(item.spawnPrefab, position, Quaternion.identity, StartOfRound.Instance.elevatorTransform).GetComponent<GrabbableObject>();
						component.fallTime = 1f;
						component.hasHitGround = false;
						component.scrapPersistedThroughRounds = true;
						component.isInElevator = true;
						component.isInShipRoom = true;
						try
						{
							Plugin.logger.LogDebug((object)$"Spawning {itemName} at {position}.");
							((NetworkBehaviour)component).NetworkObject.Spawn(false);
						}
						catch (Exception arg)
						{
							Plugin.logger.LogError((object)$"Could not spawn {itemName}: {arg}");
						}
					}
				}
				else if (ConfigManager.Debug.Value)
				{
					Plugin.logger.LogDebug((object)("Unlockable |" + itemName + "| not found in config."));
				}
			}
		}

		private static void checkInDictionary(Dictionary<string, bool> dictionary, int unlockableID, string itemName)
		{
			if (dictionary.ContainsKey(itemName) && dictionary[itemName])
			{
				Plugin.logger.LogInfo((object)("Unlocking " + itemName + "."));
				unlockShipItem(StartOfRound.Instance, unlockableID, itemName);
			}
		}

		private static void unlockShipItem(StartOfRound instance, int unlockableID, string name)
		{
			try
			{
				if (ConfigManager.Debug.Value)
				{
					Plugin.logger.LogInfo((object)("Attempting to unlock " + name));
				}
				((object)instance).GetType().GetMethod("UnlockShipObject", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(instance, new object[1] { unlockableID });
			}
			catch (NullReferenceException arg)
			{
				Plugin.logger.LogError((object)$"Could not invoke UnlockShipObject method: {arg}");
			}
		}
	}
	[BepInPlugin("MushShop", "MushShop", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource logger;

		private readonly Harmony harmony = new Harmony("MushShop");

		private void Awake()
		{
			ConfigManager.Init(((BaseUnityPlugin)this).Config);
			logger = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin MushShop is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "MushShop";

		public const string PLUGIN_NAME = "MushShop";

		public const string PLUGIN_VERSION = "0.0.1";
	}
	public class Unlockables
	{
		public static Dictionary<string, bool> ShipUpgradesDictionary = new Dictionary<string, bool>
		{
			{
				"Radio",
				ConfigManager.Radio.Value
			},
			{
				"Teleporter",
				ConfigManager.Teleporter.Value
			},
			{
				"Inverse Teleporter",
				ConfigManager.InverseTeleporter.Value
			},
			{
				"Loud horn",
				ConfigManager.LoudHorn.Value
			},
			{
				"Signal translator",
				ConfigManager.SignalTranslator.Value
			}
		};

		public static Dictionary<string, bool> SuitDictionary = new Dictionary<string, bool>
		{
			{
				"Green suit",
				ConfigManager.Suits.Value
			},
			{
				"Hazard suit",
				ConfigManager.Suits.Value
			},
			{
				"Pajama suit",
				ConfigManager.Suits.Value
			}
		};

		public static Dictionary<string, bool> DecorationDictionary = new Dictionary<string, bool>
		{
			{
				"Cozy lights",
				ConfigManager.CozyLights.Value
			},
			{
				"Television",
				ConfigManager.Television.Value
			},
			{
				"Toilet",
				ConfigManager.Toilet.Value
			},
			{
				"Shower",
				ConfigManager.Shower.Value
			},
			{
				"Record player",
				ConfigManager.RecordPlayer.Value
			},
			{
				"Table",
				ConfigManager.Table.Value
			},
			{
				"Romantic table",
				ConfigManager.RomanticTable.Value
			},
			{
				"JackOLantern",
				ConfigManager.JackOLantern.Value
			},
			{
				"Welcome mat",
				ConfigManager.WelcomeMat.Value
			},
			{
				"Goldfish",
				ConfigManager.Goldfish.Value
			},
			{
				"Plushie pajama",
				ConfigManager.PlushiePajama.Value
			}
		};

		public static Dictionary<string, int> ItemsDictionary = new Dictionary<string, int>
		{
			{
				"Flashlight",
				ConfigManager.Flashlights.Value
			},
			{
				"Pro-flashlight",
				ConfigManager.ProFlashlights.Value
			},
			{
				"Walkie-talkie",
				ConfigManager.WalkieTalkies.Value
			},
			{
				"Lockpicker",
				ConfigManager.LockPickers.Value
			},
			{
				"Extension ladder",
				ConfigManager.ExtensionLadders.Value
			},
			{
				"Radar-booster",
				ConfigManager.RadarBoosters.Value
			},
			{
				"Spray paint",
				ConfigManager.SprayPaints.Value
			},
			{
				"Shovel",
				ConfigManager.Shovels.Value
			},
			{
				"Stun grenade",
				ConfigManager.StunGrenades.Value
			},
			{
				"Zap gun",
				ConfigManager.ZapGuns.Value
			}
		};
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute([In] int obj0)
		{
			Version = obj0;
		}
	}
}