Decompiled source of HelloNeighborKey v1.0.0

Terabit.HelloNeighborKey.dll

Decompiled 16 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("Terabit.HelloNeighborKey")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HelloNeighborKeyMod")]
[assembly: AssemblyTitle("Terabit.HelloNeighborKey")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[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 HelloNeighborKeyMod
{
	[BepInPlugin("Terabit.HelloNeighborKey", "HelloNeighborKeyMod", "1.0.0")]
	public class HelloNeighborKeyMod : BaseUnityPlugin
	{
		public static AssetBundle HelloNeighborKey;

		private bool hasLoggedUpdate;

		public static HelloNeighborKeyMod Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			HelloNeighborKey = AssetBundle.LoadFromFile(Path.Combine(directoryName, "modassets"));
			if ((Object)(object)HelloNeighborKey == (Object)null)
			{
				Logger.LogError((object)"Failed to load the keys.");
				return;
			}
			Patch();
			Logger.LogInfo((object)"Terabit.HelloNeighborKey v1.0.0 just spawned in.");
			Logger.LogInfo((object)"\r\n                                ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⠉⠉⠉⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣤⣤⣤⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣿⣿⣿⣿⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣶⣿⣿⣿⣿⣿⣿⣿⣿⣶⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⡿⠋⠉⠉⠙⢿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⡏⠀⠀⠀⠀⠀⠀⢹⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⠸⣿⣿⣿⣷⣄⣀⣀⣠⣾⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀\r\n⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀");
			Logger.LogInfo((object)$"Component active: {((Component)this).gameObject.activeInHierarchy}, enabled: {((Behaviour)this).enabled}");
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Terabit.HelloNeighborKey");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Terabit.HelloNeighborKey";

		public const string PLUGIN_NAME = "HelloNeighborKeyMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace HelloNeighborKeyMod.Patches
{
	[HarmonyPatch(typeof(TVScript))]
	public class ExampleTVPatch
	{
		[HarmonyPatch("SwitchTVLocalClient")]
		[HarmonyPrefix]
		private static void SwitchTVPrefix(TVScript __instance)
		{
			StartOfRound.Instance.shipRoomLights.SetShipLightsBoolean(__instance.tvOn);
		}
	}
	[HarmonyPatch(typeof(GrabbableObject), "Start")]
	internal class KeyReplacementPatch
	{
		private const float ScaleMultiplier = 0.002f;

		[HarmonyPostfix]
		private static void Postfix(GrabbableObject __instance)
		{
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance.itemProperties == (Object)null || __instance.itemProperties.itemName != "Key")
			{
				return;
			}
			GameObject val = HelloNeighborKeyMod.HelloNeighborKey.LoadAsset<GameObject>("HelloNeighborKey");
			if ((Object)(object)val == (Object)null)
			{
				HelloNeighborKeyMod.Logger.LogError((object)"Custom key is not found in the bundle. St00pid");
				return;
			}
			MeshFilter component = val.GetComponent<MeshFilter>();
			MeshRenderer component2 = val.GetComponent<MeshRenderer>();
			if ((Object)(object)__instance.mainObjectRenderer != (Object)null && (Object)(object)component2 != (Object)null)
			{
				((Renderer)__instance.mainObjectRenderer).sharedMaterials = ((Renderer)component2).sharedMaterials;
				MeshFilter component3 = ((Component)__instance.mainObjectRenderer).GetComponent<MeshFilter>();
				if ((Object)(object)component3 != (Object)null)
				{
					Mesh val2 = (component3.mesh = ScaleMesh(component.sharedMesh, 0.002f));
					BoxCollider component4 = ((Component)__instance).GetComponent<BoxCollider>();
					if ((Object)(object)component4 != (Object)null)
					{
						Bounds bounds = val2.bounds;
						component4.center = ((Bounds)(ref bounds)).center;
						bounds = val2.bounds;
						component4.size = ((Bounds)(ref bounds)).size;
					}
				}
			}
			__instance.itemProperties.positionOffset = new Vector3(-0.4f, 0.05f, 0.05f);
			__instance.itemProperties.rotationOffset = new Vector3(0f, 95f, -95f);
			__instance.itemProperties.restingRotation = new Vector3(0f, 0f, 5f);
			Sprite val4 = HelloNeighborKeyMod.HelloNeighborKey.LoadAsset<Sprite>("KeyLethalCompanyHUDIcon");
			if ((Object)(object)val4 != (Object)null)
			{
				__instance.itemProperties.itemIcon = val4;
			}
			else
			{
				HelloNeighborKeyMod.Logger.LogWarning((object)"Custom key icon not found in the foreseeable universe.");
			}
			HelloNeighborKeyMod.Logger.LogDebug((object)"Successfully stole all of Mr Peterson's keys.");
		}

		private static Mesh ScaleMesh(Mesh source, float scale)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = Object.Instantiate<Mesh>(source);
			Vector3[] vertices = val.vertices;
			for (int i = 0; i < vertices.Length; i++)
			{
				ref Vector3 reference = ref vertices[i];
				reference *= scale;
			}
			val.vertices = vertices;
			val.RecalculateBounds();
			return val;
		}
	}
}