Decompiled source of UnlockOnStart v0.6.5

UnlockOnStart.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("UnlockOnStart")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Set stuff to unlock on a new save.")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyInformationalVersion("0.4.0+396f34fe3c3995d2ae9360657c2bd75cf8a5fc64")]
[assembly: AssemblyProduct("UnlockOnStart")]
[assembly: AssemblyTitle("UnlockOnStart")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace UnlockOnStart
{
	public class ConfigManager
	{
		public static ConfigManager Instance { get; private set; }

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

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

		public static ConfigFile configFile { get; private set; }

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

		private ConfigManager(ConfigFile config)
		{
			configFile = config;
			Debug = config.Bind<bool>("General", "Debugging", true, "Enable debug logging.");
			Money = config.Bind<int>("Money", "Money", 60, "How much money to unlock on new save.");
		}
	}
	public class DecorationsConfigManager
	{
		public static DecorationsConfigManager Instance { 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> DiscoBall { get; private set; }

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

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

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

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

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

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

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

		private DecorationsConfigManager(ConfigFile config)
		{
			CozyLights = config.Bind<bool>("Decorations", "Cozy Lights", false, "Unlock the cozy lights on new save.");
			DiscoBall = config.Bind<bool>("Decorations", "Disco Ball", false, "Unlock the disco ball on new save.");
			Goldfish = config.Bind<bool>("Decorations", "Goldfish", false, "Unlock the goldfish on new save.");
			JackOLantern = config.Bind<bool>("Decorations", "Jack-O-Lantern", false, "Unlock the jack-o-lantern on new save.");
			PlushiePajama = config.Bind<bool>("Decorations", "Plushie Pajama", false, "Unlock the plushie pajama on new save.");
			RecordPlayer = config.Bind<bool>("Decorations", "Record Player", false, "Unlock the record player on new save.");
			RomanticTable = config.Bind<bool>("Decorations", "Romantic Table", false, "Unlock the romantic table on new save.");
			Shower = config.Bind<bool>("Decorations", "Shower", false, "Unlock the shower on new save.");
			Table = config.Bind<bool>("Decorations", "Table", false, "Unlock the table on new save.");
			Television = config.Bind<bool>("Decorations", "Television", false, "Unlock the television on new save.");
			Toilet = config.Bind<bool>("Decorations", "Toilet", false, "Unlock the toilet on new save.");
			WelcomeMat = config.Bind<bool>("Decorations", "Welcome Mat", false, "Unlock the welcome mat on new save.");
			HazardSuit = config.Bind<bool>("Suits", "Hazard Suit", false, "Unlock the hazmat suit on new save.");
			GreenSuit = config.Bind<bool>("Suits", "Green Suit", false, "Unlock the green suit on new save.");
			PajamaSuit = config.Bind<bool>("Suits", "Pajama Suit", false, "Unlock the pajama suit on new save.");
			PurpleSuit = config.Bind<bool>("Suits", "Purple Suit", false, "Unlock the purple suit on new save.");
			BeeSuit = config.Bind<bool>("Suits", "Bee Suit", false, "Unlock the bee suit on new save.");
			BunnySuit = config.Bind<bool>("Suits", "Bunny Suit", false, "Unlock the bunny suit on new save.");
		}
	}
	public class ItemsConfigManager
	{
		public static ItemsConfigManager Instance { 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> Boombox { 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<int> Keys { get; private set; }

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

		private ItemsConfigManager(ConfigFile config)
		{
			Boombox = config.Bind<int>("Items", "Boombox", 0, "How many boomboxes to unlock on new save.");
			ExtensionLadders = config.Bind<int>("Items", "Extension Ladder", 0, "How many extension ladders to unlock on new save.");
			Flashlights = config.Bind<int>("Items", "Flashlight", 0, "How many flashlights to unlock on new save.");
			Inhalants = config.Bind<int>("Items", "TZP-Inhalant", 0, "How many inhalants to unlock on new save.");
			Jetpacks = config.Bind<int>("Items", "Jetpack", 0, "How many jetpacks to unlock on new save.");
			Keys = config.Bind<int>("Items", "Key", 0, "How many keys to unlock on new save.");
			LockPickers = config.Bind<int>("Items", "Lockpicker", 0, "How many lockpickers to unlock on new save.");
			ProFlashlights = config.Bind<int>("Items", "Pro-flashlight", 0, "How many pro-flashlights to unlock on new save.");
			RadarBoosters = config.Bind<int>("Items", "Radar Booster", 0, "How many radar boosters to unlock on new save.");
			Shotgun = config.Bind<int>("Items", "Shotgun", 0, "How many shotguns to unlock on new save.");
			ShotgunShells = config.Bind<int>("Items", "Shotgun Shells", 0, "How many shotgun shells to unlock on new save.");
			Shovels = config.Bind<int>("Items", "Shovel", 0, "How many shovels to unlock on new save.");
			SprayPaints = config.Bind<int>("Items", "Spray Paint", 0, "How many spray paints to unlock on new save.");
			StunGrenades = config.Bind<int>("Items", "Stun Grenade", 0, "How many stun grenades to unlock on new save.");
			WalkieTalkies = config.Bind<int>("Items", "Walkie-Talkie", 0, "How many walkie-talkies to unlock on new save.");
			ZapGuns = config.Bind<int>("Items", "Zap Gun", 0, "How many zap guns to unlock on new save.");
		}
	}
	public class ShipUpgradesConfigManager
	{
		public static ShipUpgradesConfigManager Instance { 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 void Init(ConfigFile config)
		{
			Instance = new ShipUpgradesConfigManager(config);
		}

		private ShipUpgradesConfigManager(ConfigFile config)
		{
			Teleporter = config.Bind<bool>("Teleporter", "Teleporter", false, "Unlock the teleporter on new save.");
			InverseTeleporter = config.Bind<bool>("Inverse Teleporter", "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.");
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class NewSaveStartPatch
	{
		[HarmonyPatch("firstDayAnimation")]
		[HarmonyPostfix]
		internal static void LoadUnlockablesFromConfig()
		{
			if (StartOfRound.Instance.gameStats.daysSpent == 0 && !StartOfRound.Instance.isChallengeFile)
			{
				Plugin.logger.LogInfo((object)"New save detected, loading unlockables from config.");
				TimeOfDay.Instance.quotaVariables.startingCredits = ConfigManager.Money.Value;
				if (!GameNetworkManager.Instance.isHostingGame)
				{
					return;
				}
				List<UnlockableItem> unlockables = StartOfRound.Instance.unlockablesList.unlockables;
				foreach (UnlockableItem item in unlockables)
				{
					string unlockableName = item.unlockableName;
					int num = unlockables.IndexOf(item);
					if (ConfigManager.Debug.Value)
					{
						Plugin.logger.LogDebug((object)$"Unlockable ID: {num} / Unlockable name: {unlockableName}");
					}
					bool flag = CheckInDictionary(Unlockables.ShipUpgradesDictionary, num, unlockableName);
					bool flag2 = CheckInDictionary(Unlockables.SuitDictionary, num, unlockableName);
					bool flag3 = CheckInDictionary(Unlockables.DecorationDictionary, num, unlockableName);
					if (!(flag || flag2 || flag3) && !flag && !flag2 && !flag3)
					{
						if (ConfigManager.Debug.Value)
						{
							Plugin.logger.LogDebug((object)("Unlockable |" + unlockableName + "| not found in config."));
						}
						if (!Unlockables.ItemsToIgnore.Contains(unlockableName) && ConfigManager.configFile.Bind<bool>("Modded", unlockableName, false, "Unlock " + unlockableName + " on new save.").Value)
						{
							UnlockShipItem(StartOfRound.Instance, num, unlockableName);
						}
					}
				}
				SpawnItemsFromConfig();
			}
			else
			{
				Plugin.logger.LogInfo((object)"Not a new save, not loading unlockables from config.");
			}
		}

		internal static void SpawnItemsFromConfig()
		{
			List<Item> itemsList = StartOfRound.Instance.allItemsList.itemsList;
			List<string> list = itemsList.Select((Item x) => x.itemName).Distinct().ToList();
			foreach (Item item in itemsList)
			{
				string itemName = item.itemName;
				int num = itemsList.IndexOf(item);
				bool flag = Unlockables.ItemsDictionary.ContainsKey(itemName);
				Plugin.logger.LogDebug((object)$"Item ID: {num} / Item name: {itemName} / Is scrap: {item.isScrap}");
				Plugin.logger.LogDebug((object)$"Is in dictionary: {flag}");
				if (!list.Contains(itemName) || (item.isScrap && !flag) || Unlockables.ItemsToIgnore.Contains(itemName))
				{
					continue;
				}
				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++)
					{
						SpawnItem(StartOfRound.Instance, item);
					}
				}
				else
				{
					int value = ConfigManager.configFile.Bind<int>("Modded.Items", itemName, 0, "How many " + itemName + " to unlock on new save.").Value;
					if (value == 0)
					{
						continue;
					}
					Plugin.logger.LogInfo((object)$"Unlocking {itemName} * {value}.");
					for (int j = 0; j < value; j++)
					{
						SpawnItem(StartOfRound.Instance, item);
					}
					if (ConfigManager.Debug.Value)
					{
						Plugin.logger.LogDebug((object)("Unlockable |" + itemName + "| not found in config."));
					}
				}
				list.Remove(itemName);
			}
		}

		private static bool CheckInDictionary(Dictionary<string, bool> dictionary, int unlockableID, string itemName)
		{
			if (dictionary.ContainsKey(itemName))
			{
				if (!dictionary[itemName])
				{
					return true;
				}
				Plugin.logger.LogInfo((object)("Unlocking " + itemName + "."));
				UnlockShipItem(StartOfRound.Instance, unlockableID, itemName);
				return true;
			}
			return false;
		}

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

		private static void SpawnItem(StartOfRound instance, Item item)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			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 val = Object.Instantiate<GameObject>(item.spawnPrefab, position, Quaternion.identity, StartOfRound.Instance.elevatorTransform).GetComponent<GrabbableObject>();
			val.fallTime = 1f;
			val.hasHitGround = false;
			val.scrapPersistedThroughRounds = true;
			val.isInElevator = true;
			val.isInShipRoom = true;
			if (item.itemName == "Shotgun")
			{
				ShotgunItem val2 = (ShotgunItem)(object)((val is ShotgunItem) ? val : null);
				val2.shellsLoaded = 0;
				val2.safetyOn = true;
				val = (GrabbableObject)(object)val2;
			}
			try
			{
				Plugin.logger.LogDebug((object)$"Spawning {item.itemName} at {position}.");
				((NetworkBehaviour)val).NetworkObject.Spawn(false);
			}
			catch (Exception arg)
			{
				Plugin.logger.LogError((object)$"Could not spawn {item.itemName}: {arg}");
			}
		}
	}
	[BepInPlugin("UnlockOnStart", "UnlockOnStart", "0.4.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource logger;

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

		private void Awake()
		{
			ConfigManager.Init(((BaseUnityPlugin)this).Config);
			ShipUpgradesConfigManager.Init(((BaseUnityPlugin)this).Config);
			ItemsConfigManager.Init(((BaseUnityPlugin)this).Config);
			DecorationsConfigManager.Init(((BaseUnityPlugin)this).Config);
			logger = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin UnlockOnStart is loaded!");
		}
	}
	public class Unlockables
	{
		public static Dictionary<string, bool> ShipUpgradesDictionary = new Dictionary<string, bool>
		{
			{
				"Teleporter",
				ShipUpgradesConfigManager.Teleporter.Value
			},
			{
				"Inverse Teleporter",
				ShipUpgradesConfigManager.InverseTeleporter.Value
			},
			{
				"Loud horn",
				ShipUpgradesConfigManager.LoudHorn.Value
			},
			{
				"Signal translator",
				ShipUpgradesConfigManager.SignalTranslator.Value
			}
		};

		public static Dictionary<string, bool> SuitDictionary = new Dictionary<string, bool>
		{
			{
				"Green suit",
				DecorationsConfigManager.GreenSuit.Value
			},
			{
				"Hazard suit",
				DecorationsConfigManager.HazardSuit.Value
			},
			{
				"Pajama suit",
				DecorationsConfigManager.PajamaSuit.Value
			},
			{
				"Purple Suit",
				DecorationsConfigManager.PurpleSuit.Value
			},
			{
				"Bee Suit",
				DecorationsConfigManager.BeeSuit.Value
			},
			{
				"Bunny Suit",
				DecorationsConfigManager.BunnySuit.Value
			}
		};

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

		public static Dictionary<string, int> ItemsDictionary = new Dictionary<string, int>
		{
			{
				"Flashlight",
				ItemsConfigManager.Flashlights.Value
			},
			{
				"Pro-flashlight",
				ItemsConfigManager.ProFlashlights.Value
			},
			{
				"Walkie-talkie",
				ItemsConfigManager.WalkieTalkies.Value
			},
			{
				"Lockpicker",
				ItemsConfigManager.LockPickers.Value
			},
			{
				"Extension ladder",
				ItemsConfigManager.ExtensionLadders.Value
			},
			{
				"Radar-booster",
				ItemsConfigManager.RadarBoosters.Value
			},
			{
				"Spray paint",
				ItemsConfigManager.SprayPaints.Value
			},
			{
				"Shovel",
				ItemsConfigManager.Shovels.Value
			},
			{
				"Stun grenade",
				ItemsConfigManager.StunGrenades.Value
			},
			{
				"Zap gun",
				ItemsConfigManager.ZapGuns.Value
			},
			{
				"Shotgun",
				ItemsConfigManager.Shotgun.Value
			},
			{
				"Ammo",
				ItemsConfigManager.ShotgunShells.Value
			},
			{
				"Shell",
				ItemsConfigManager.ShotgunShells.Value
			},
			{
				"Key",
				ItemsConfigManager.Keys.Value
			},
			{
				"Jetpack",
				ItemsConfigManager.Jetpacks.Value
			},
			{
				"TZP-Inhalant",
				ItemsConfigManager.Inhalants.Value
			},
			{
				"Boombox",
				ItemsConfigManager.Boombox.Value
			}
		};

		public static string[] ItemsToIgnore = new string[8] { "Binoculars", "box", "Bunkbeds", "Terminal", "Cupboard", "File Cabinet", "Light switch", "Orange suit" };
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "UnlockOnStart";

		public const string PLUGIN_NAME = "UnlockOnStart";

		public const string PLUGIN_VERSION = "0.4.0";
	}
}