Decompiled source of StartingTeleporters v1.0.1

BepInEX/plugins/StartingTeleporter.dll

Decompiled a year ago
using System;
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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("StartingTeleporter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("StartingTeleporter")]
[assembly: AssemblyTitle("StartingTeleporter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 StartingTeleporter
{
	[BepInPlugin("StartingTeleporter", "StartingTeleporter", "1.0.0")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public static STConfig modConfig;

		public static ManualLogSource log;

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			log = ((BaseUnityPlugin)this).Logger;
			log.LogInfo((object)"Loading StartingTeleporter");
			modConfig = new STConfig(((BaseUnityPlugin)this).Config);
			Harmony val = new Harmony("StartingTeleporter");
			MethodInfo methodInfo = AccessTools.Method(typeof(StartOfRound), "SetDiscordStatusDetails", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(STPatches), "discordPatch", (Type[])null, (Type[])null);
			val.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}
	public class STConfig
	{
		private static readonly string CATEGORY = "General";

		private ConfigFile config;

		private ConfigEntry<bool> configStartingTeleporter;

		private ConfigEntry<bool> configStartingInverseTeleporter;

		public STConfig(ConfigFile config)
		{
			this.config = config;
			configStartingTeleporter = this.config.Bind<bool>(CATEGORY, "StartingTeleporter", true, "Start the game with a normal Teleporter.");
			configStartingInverseTeleporter = this.config.Bind<bool>(CATEGORY, "StartingInverseTeleporter", false, "Start the game with an Inverse Teleporter");
		}

		public bool startWithTeleporter()
		{
			return configStartingTeleporter.Value;
		}

		public bool startWithInverseTeleporter()
		{
			return configStartingInverseTeleporter.Value;
		}
	}
	internal class STPatches
	{
		private static readonly string TELEPORTER_NAME = "Teleporter";

		private static readonly string INVERSE_NAME = "Inverse Teleporter";

		private static bool idsInitialized;

		private static bool stLoaded;

		private static int teleporterID = -1;

		private static int inverseTeleporterID = -1;

		internal static void discordPatch(ref StartOfRound __instance)
		{
			if (stLoaded || !((NetworkBehaviour)__instance).IsHost)
			{
				return;
			}
			if (!idsInitialized)
			{
				getTeleporterIDs(__instance);
			}
			try
			{
				if (Plugin.modConfig.startWithTeleporter() && teleporterID != -1)
				{
					unlockShipItem(__instance, teleporterID, TELEPORTER_NAME);
				}
				if (Plugin.modConfig.startWithInverseTeleporter() && inverseTeleporterID != -1)
				{
					unlockShipItem(__instance, inverseTeleporterID, INVERSE_NAME);
				}
				stLoaded = true;
			}
			catch (Exception arg)
			{
				Plugin.log.LogError((object)$"Failed to unlock items: \n{arg}");
			}
		}

		private static void getTeleporterIDs(StartOfRound instance)
		{
			Plugin.log.LogInfo((object)"Getting item IDs");
			for (int i = 0; i < instance.unlockablesList.unlockables.Count; i++)
			{
				UnlockableItem val = instance.unlockablesList.unlockables[i];
				string text = val.unlockableName.ToLower();
				if (text.Equals(TELEPORTER_NAME.ToLower()))
				{
					Plugin.log.LogInfo((object)$"{TELEPORTER_NAME} ID: {i}");
					teleporterID = i;
				}
				else if (text.Equals(INVERSE_NAME.ToLower()))
				{
					Plugin.log.LogInfo((object)$"{INVERSE_NAME} ID: {i}");
					inverseTeleporterID = i;
				}
			}
			idsInitialized = true;
		}

		private static void unlockShipItem(StartOfRound instance, int unlockableID, string name)
		{
			try
			{
				Plugin.log.LogInfo((object)("Attempting to unlock " + name));
				MethodInfo method = ((object)instance).GetType().GetMethod("UnlockShipObject", BindingFlags.Instance | BindingFlags.NonPublic);
				method.Invoke(instance, new object[1] { unlockableID });
				Plugin.log.LogInfo((object)("Spawning " + name));
			}
			catch (NullReferenceException arg)
			{
				Plugin.log.LogError((object)$"Could not invoke UnlockShipObject method: {arg}");
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "StartingTeleporter";

		public const string PLUGIN_NAME = "StartingTeleporter";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}