Decompiled source of DeezNuts v1.1.0

DeezNuts.dll

Decompiled a month 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 DeezNuts.Patch;
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("DeezNuts")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("DeezNuts")]
[assembly: AssemblyTitle("DeezNuts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DeezNuts
{
	[BepInPlugin("com.fakemarsh.DeezNuts", "DeezNuts", "1.1.0")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony harmony = new Harmony("DeezNuts");

		public static ManualLogSource logger;

		public static GameObject deez_nuts_button;

		public static Item deez_nuts_item;

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			logger.LogInfo((object)"Plugin DeezNuts is loaded!");
			LoadButton();
			harmony.PatchAll(typeof(DeezPatches));
			harmony.PatchAll(typeof(NetworkPatches));
		}

		private void LoadButton()
		{
			AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "deeznuts"));
			deez_nuts_button = obj.LoadAsset<GameObject>("Assets/DeezNuts/DeezNuts.prefab");
			deez_nuts_item = obj.LoadAsset<Item>("Assets/DeezNuts/DeezNuts.asset");
			logger.LogInfo((object)("custom scrap item loaded into network: " + deez_nuts_item.itemName));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DeezNuts";

		public const string PLUGIN_NAME = "DeezNuts";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace DeezNuts.Patch
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class DeezPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("Awake")]
		public static void DeezNutsButtonPatch(StartOfRound __instance)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			Plugin.logger.LogInfo((object)"inside button patch");
			SelectableLevel[] levels = __instance.levels;
			Type? typeFromHandle = typeof(SpawnableItemWithRarity);
			ConstructorInfo constructor = typeFromHandle.GetConstructor(Type.EmptyTypes);
			ConstructorInfo constructor2 = typeFromHandle.GetConstructor(new Type[2]
			{
				typeof(Item),
				typeof(int)
			});
			int num = 35;
			if (constructor != null)
			{
				SelectableLevel[] array = levels;
				foreach (SelectableLevel val in array)
				{
					SpawnableItemWithRarity val2 = (SpawnableItemWithRarity)constructor.Invoke(null);
					val2.spawnableItem = Plugin.deez_nuts_item;
					val2.rarity = num;
					Plugin.logger.LogInfo((object)("Adding deez nuts button into moon " + ((Object)val).name + "\n"));
					val.spawnableScrap.Add(val2);
				}
			}
			else
			{
				if (!(constructor2 != null))
				{
					Plugin.logger.LogInfo((object)"ERROR: Invalid SpawnableItemWithRarity constructor, DeezNuts doesn't support this LC version");
					return;
				}
				SelectableLevel[] array = levels;
				foreach (SelectableLevel val3 in array)
				{
					SpawnableItemWithRarity item = (SpawnableItemWithRarity)constructor2.Invoke(new object[2]
					{
						Plugin.deez_nuts_item,
						num
					});
					Plugin.logger.LogInfo((object)("Adding deez nuts button into moon " + ((Object)val3).name + "\n"));
					val3.spawnableScrap.Add(item);
				}
			}
			if (!__instance.allItemsList.itemsList.Contains(Plugin.deez_nuts_item))
			{
				__instance.allItemsList.itemsList.Add(Plugin.deez_nuts_item);
			}
		}
	}
	internal class NetworkPatches
	{
		private static GameObject networkPrefab;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void Init(GameNetworkManager __instance)
		{
			Plugin.logger.LogInfo((object)"inside deez nuts network patcher");
			if (!((Object)(object)networkPrefab != (Object)null))
			{
				Plugin.logger.LogInfo((object)"we are adding the deez nuts button to the network!");
				networkPrefab = Plugin.deez_nuts_button;
				((Component)__instance).GetComponent<NetworkManager>().PrefabHandler.AddNetworkPrefab(networkPrefab);
			}
		}
	}
}