Decompiled source of DeathNote v0.1.1

DeathNote.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using DeathNote;
using DeathNoteMod;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using LethalNetworkAPI;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;

[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("DeathNote")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+14dea81dc5317a1ae29f37af7f56127bb981a9cf")]
[assembly: AssemblyProduct("DeathNote")]
[assembly: AssemblyTitle("DeathNote")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
namespace QuickRestart.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	public class SubmitChatPatch
	{
		[HarmonyPatch("SubmitChat_performed")]
		[HarmonyPrefix]
		private static bool Prefix(HUDManager __instance)
		{
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			string text = __instance.chatTextField.text.ToLower();
			GrabbableObject currentlyHeldObjectServer = localPlayerController.currentlyHeldObjectServer;
			if ((Object)(object)currentlyHeldObjectServer == (Object)null)
			{
				return true;
			}
			if (currentlyHeldObjectServer.itemProperties.itemName == "Death Note" && text.Contains("/deathnote "))
			{
				string[] array = text.Split(" ", 2);
				if (array.Length < 2)
				{
					return true;
				}
				string name = array[1];
				DeathNoteBase.LoggerInstance.LogDebug((object)("Getting player: '" + name + "'"));
				PlayerControllerB val = (from x in StartOfRound.Instance.allPlayerScripts.ToList()
					where x.playerUsername.ToLower() == name
					select x).FirstOrDefault();
				if ((Object)(object)val != (Object)null)
				{
					DeathNoteBase.LoggerInstance.LogDebug((object)("Found player to kill: " + val.playerUsername));
					DeathNoteBase.PlayerToDie = val;
					ResetTextbox(__instance, localPlayerController);
					return false;
				}
				DeathNoteBase.LoggerInstance.LogDebug((object)"Player not found...");
				DeathNoteBase.SendChatMessage("A name was unspecified or doesnt exist. (Use /deathnote playerusername)");
			}
			return true;
		}

		private static void ResetTextbox(HUDManager manager, PlayerControllerB local)
		{
			local.isTypingChat = false;
			manager.chatTextField.text = "";
			EventSystem.current.SetSelectedGameObject((GameObject)null);
			manager.PingHUDElement(manager.Chat, 2f, 1f, 0.2f);
			((Behaviour)manager.typingIndicator).enabled = false;
		}
	}
}
namespace DeathNote
{
	internal class DeathNoteBehavior : PhysicsProp
	{
		private static ManualLogSource logger = DeathNoteBase.LoggerInstance;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (!buttonDown)
			{
				return;
			}
			logger.LogDebug((object)"Using item works!");
			PlayerControllerB playerToDie = DeathNoteBase.PlayerToDie;
			if ((Object)(object)playerToDie != (Object)null)
			{
				if (playerToDie.isPlayerDead)
				{
					DeathNoteBase.SendChatMessage("This player is already dead...");
				}
				NetworkHandler.clientMessage.SendServer(playerToDie.actualClientId);
				DeathNoteBase.SendChatMessage(playerToDie.playerUsername + " has died of a heart attack");
			}
			else
			{
				DeathNoteBase.SendChatMessage("A name was unspecified or doesnt exist. (Use /deathnote playerusername)");
			}
		}
	}
	internal static class NetworkHandler
	{
		private static ManualLogSource logger = DeathNoteBase.LoggerInstance;

		public static LethalServerEvent serverEvent = new LethalServerEvent("event", (Action<ulong>)null);

		public static LethalClientEvent clientEvent = new LethalClientEvent("event", (Action)null, (Action<ulong>)null);

		public static LethalServerMessage<ulong> serverMessage = new LethalServerMessage<ulong>("message", (Action<ulong, ulong>)null);

		public static LethalClientMessage<ulong> clientMessage = new LethalClientMessage<ulong>("message", (Action<ulong>)null, (Action<ulong, ulong>)null);

		public static PlayerControllerB CurrentClient => StartOfRound.Instance.localPlayerController;

		public static void Init()
		{
			clientEvent.OnReceived += RecieveFromServer;
			serverMessage.OnReceived += RecieveFromClient;
		}

		private static void RecieveFromServer()
		{
			//IL_001f: 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)
			logger.LogDebug((object)"In RecieveFromServer");
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			localPlayerController.KillPlayer(default(Vector3), true, (CauseOfDeath)0, 0);
			DeathNoteBase.SendChatMessage("You have died from a sudden heart attack");
		}

		private static void RecieveFromClient(ulong playerToDieId, ulong clientID)
		{
			logger.LogDebug((object)$"In RecieveFromClient: {playerToDieId}");
			serverEvent.InvokeClient(playerToDieId);
		}
	}
}
namespace DeathNoteMod
{
	[BepInPlugin("Snowlance.DeathNote", "DeathNote", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class DeathNoteBase : BaseUnityPlugin
	{
		private const string modGUID = "Snowlance.DeathNote";

		private const string modName = "DeathNote";

		private const string modVersion = "0.1.0";

		public static AssetBundle DNAssetBundle;

		public static PlayerControllerB PlayerToDie;

		public static ManualLogSource LoggerInstance;

		private readonly Harmony harmony = new Harmony("Snowlance.DeathNote");

		public static DeathNoteBase PluginInstance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)PluginInstance == (Object)null)
			{
				PluginInstance = this;
			}
			LoggerInstance = ((BaseUnityPlugin)PluginInstance).Logger;
			LoggerInstance.LogDebug((object)"Plugin DeathNote loaded successfully.");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			DNAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "mod_assets"));
			LoggerInstance.LogDebug((object)("Got DNAssetBundle at: " + Path.Combine(directoryName, "mod_assets")));
			if ((Object)(object)DNAssetBundle == (Object)null)
			{
				LoggerInstance.LogError((object)"Failed to load custom assets.");
				return;
			}
			int num = 5;
			LoggerInstance.LogDebug((object)"Getting item");
			Item val = DNAssetBundle.LoadAsset<Item>("Assets/DeathNote/DeathNoteItem.asset");
			DeathNoteBehavior deathNoteBehavior = val.spawnPrefab.AddComponent<DeathNoteBehavior>();
			((GrabbableObject)deathNoteBehavior).grabbable = true;
			((GrabbableObject)deathNoteBehavior).grabbableToEnemies = true;
			((GrabbableObject)deathNoteBehavior).itemProperties = val;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, num, (LevelTypes)(-1));
			NetworkHandler.Init();
			harmony.PatchAll();
			LoggerInstance.LogInfo((object)"Snowlance.DeathNote v0.1.0 has loaded!");
		}

		public static void SendChatMessage(string message)
		{
			AccessTools.Method(typeof(HUDManager), "AddChatMessage", (Type[])null, (Type[])null)?.Invoke(HUDManager.Instance, new object[2] { message, "" });
		}
	}
}