Decompiled source of KeepUnlocks v1.0.4

KeepUnlocks.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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: AssemblyCompany("KeepUnlocks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Saves certain unlockables when the run resets. Configurable to keep suits, furniture, and/or ship upgrades.")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("KeepUnlocks")]
[assembly: AssemblyTitle("KeepUnlocks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.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 KeepUnlocks
{
	internal class KeepThis
	{
		private static List<int> unlocks = new List<int>();

		internal static void FindItemsToKeep()
		{
			unlocks.Clear();
			for (int i = 0; i < StartOfRound.Instance.unlockablesList.unlockables.Count; i++)
			{
				if (StartOfRound.Instance.unlockablesList.unlockables[i].hasBeenUnlockedByPlayer)
				{
					KeepThisItem(i);
				}
			}
		}

		private static void KeepThisItem(int id)
		{
			if (unlocks.Contains(id))
			{
				return;
			}
			UnlockableItem val = StartOfRound.Instance.unlockablesList.unlockables[id];
			if (val.unlockableType == 0)
			{
				if (Plugin.configKeepSuits.Value)
				{
					unlocks.Add(id);
				}
			}
			else if (IsShipUpgrade(val))
			{
				if (Plugin.configKeepUpgrades.Value)
				{
					unlocks.Add(id);
				}
			}
			else if (Plugin.configKeepFurniture.Value)
			{
				unlocks.Add(id);
			}
		}

		internal static IEnumerator RepopulateShipWithUnlocks()
		{
			int num = TimeOfDay.Instance.quotaVariables.startingCredits;
			Terminal val = Object.FindObjectOfType<Terminal>();
			if ((Object)(object)val != (Object)null)
			{
				num = val.groupCredits;
			}
			foreach (int unlock in unlocks)
			{
				StartOfRound.Instance.BuyShipUnlockableServerRpc(unlock, num);
			}
			if (!Plugin.configAutoStore.Value)
			{
				yield break;
			}
			yield return (object)new WaitForSeconds(2f);
			PlaceableShipObject[] array = Object.FindObjectsOfType<PlaceableShipObject>();
			foreach (PlaceableShipObject val2 in array)
			{
				if (unlocks.Contains(val2.unlockableID) && StartOfRound.Instance.unlockablesList.unlockables[val2.unlockableID].canBeStored && !IsShipUpgrade(StartOfRound.Instance.unlockablesList.unlockables[val2.unlockableID]))
				{
					if (!StartOfRound.Instance.unlockablesList.unlockables[val2.unlockableID].spawnPrefab)
					{
						val2.parentObject.disableObject = true;
						Debug.Log((object)"DISABLE OBJECT F");
					}
					ShipBuildModeManager.Instance.StoreObjectServerRpc(NetworkObjectReference.op_Implicit(((Component)val2.parentObject).GetComponent<NetworkObject>()), (int)GameNetworkManager.Instance.localPlayerController.playerClientId);
				}
			}
		}

		private static bool IsShipUpgrade(UnlockableItem item)
		{
			if (!(item.unlockableName == "Teleporter") && !(item.unlockableName == "Signal translator") && !(item.unlockableName == "Loud horn"))
			{
				return item.unlockableName == "Inverse Teleporter";
			}
			return true;
		}
	}
	[BepInPlugin("butterystancakes.lethalcompany.keepunlocks", "Keep Unlocks", "1.0.4")]
	public class Plugin : BaseUnityPlugin
	{
		private const string PLUGIN_GUID = "butterystancakes.lethalcompany.keepunlocks";

		private const string PLUGIN_NAME = "Keep Unlocks";

		private const string PLUGIN_VERSION = "1.0.4";

		public static ConfigEntry<bool> configKeepSuits;

		public static ConfigEntry<bool> configKeepFurniture;

		public static ConfigEntry<bool> configKeepUpgrades;

		public static ConfigEntry<bool> configAutoStore;

		private void Awake()
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			configKeepSuits = ((BaseUnityPlugin)this).Config.Bind<bool>("Cosmetic", "KeepSuits", true, "Retain player suits? (Green suit, Hazard suit, Pajama suit, Purple Suit, Bee Suit, Bunny Suit)");
			configKeepFurniture = ((BaseUnityPlugin)this).Config.Bind<bool>("Cosmetic", "KeepFurniture", true, "Retain misc. furniture? (Television, Shower, etc.)");
			configKeepUpgrades = ((BaseUnityPlugin)this).Config.Bind<bool>("Gameplay", "KeepUpgrades", false, "Retain ship upgrades? (Loud horn, Signal translator, Teleporter, Inverse Teleporter)");
			configAutoStore = ((BaseUnityPlugin)this).Config.Bind<bool>("Miscellaneous", "AutoStore", true, "Automatically place furniture into storage.");
			((BaseUnityPlugin)this).Config.Bind<bool>("Experimental", "AutoStore", false, "Legacy setting, moved to \"Miscellaneous\" section");
			((BaseUnityPlugin)this).Config.Remove(((BaseUnityPlugin)this).Config["Experimental", "AutoStore"].Definition);
			new Harmony("butterystancakes.lethalcompany.keepunlocks").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Keep Unlocks v1.0.4 loaded");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "KeepUnlocks";

		public const string PLUGIN_NAME = "KeepUnlocks";

		public const string PLUGIN_VERSION = "1.0.4";
	}
}
namespace KeepUnlocks.Patches
{
	[HarmonyPatch]
	internal class KeepUnlocksPatches
	{
		[HarmonyPatch(typeof(GameNetworkManager), "ResetSavedGameValues")]
		[HarmonyPrefix]
		private static void PreResetSavedGameValues(GameNetworkManager __instance)
		{
			if (__instance.isHostingGame && !StartOfRound.Instance.isChallengeFile)
			{
				KeepThis.FindItemsToKeep();
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "ResetShip")]
		[HarmonyPostfix]
		private static void PostResetShip(StartOfRound __instance)
		{
			if (((NetworkBehaviour)__instance).IsServer && !__instance.isChallengeFile)
			{
				((MonoBehaviour)__instance).StartCoroutine(KeepThis.RepopulateShipWithUnlocks());
			}
		}
	}
}