Decompiled source of DumbWaysToDie v1.1.2

DumbWaysToDie.dll

Decompiled 5 months ago
#define DEBUG
using System;
using System.Collections;
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.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[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("TestAccount666.DumbWaysToDie")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Plays Dumb Ways To Die on certain deaths")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: AssemblyProduct("DumbWaysToDie")]
[assembly: AssemblyTitle("TestAccount666.DumbWaysToDie")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.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.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;
		}
	}
	[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 DumbWaysToDie
{
	public class ConfigHandler
	{
		[CompilerGenerated]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private ConfigFile <config>P;

		internal ConfigEntry<bool> playAtLandmineDeath;

		internal ConfigEntry<bool> playAtTurretDeath;

		internal ConfigEntry<bool> playAtShotgunNutcrackerDeath;

		internal ConfigEntry<bool> playAtShotgunMurderDeath;

		internal ConfigEntry<bool> playAtShotgunAccidentDeath;

		internal ConfigEntry<bool> playAtDropShipDeath;

		internal ConfigEntry<bool> playAtAnyDeath;

		internal ConfigEntry<int> volume;

		public ConfigHandler(ConfigFile config)
		{
			<config>P = config;
			playAtLandmineDeath = null;
			playAtTurretDeath = null;
			playAtShotgunNutcrackerDeath = null;
			playAtShotgunMurderDeath = null;
			playAtShotgunAccidentDeath = null;
			playAtDropShipDeath = null;
			playAtAnyDeath = null;
			volume = null;
			base..ctor();
		}

		internal void HandleConfig()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Expected O, but got Unknown
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Expected O, but got Unknown
			playAtLandmineDeath = <config>P.Bind<bool>("General", "Play at landmine death", true, new ConfigDescription("If true, will play Dumb Ways To Die at death by a landmine", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { false, true }), Array.Empty<object>()));
			playAtTurretDeath = <config>P.Bind<bool>("General", "Play at turret death", true, new ConfigDescription("If true, will play Dumb Ways To Die at death by a turret", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { false, true }), Array.Empty<object>()));
			playAtShotgunNutcrackerDeath = <config>P.Bind<bool>("General", "Play at nutcracker shotgun death", true, new ConfigDescription("If true, will play Dumb Ways To Die at death by a nutcracker's shotgun", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { false, true }), Array.Empty<object>()));
			playAtShotgunMurderDeath = <config>P.Bind<bool>("General", "Play at murder shotgun death", true, new ConfigDescription("If true, will play Dumb Ways To Die at death by a player's shotgun", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { false, true }), Array.Empty<object>()));
			playAtShotgunAccidentDeath = <config>P.Bind<bool>("General", "Play at accident shotgun death", true, new ConfigDescription("If true, will play Dumb Ways To Die at death by a shotgun misfire", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { false, true }), Array.Empty<object>()));
			playAtDropShipDeath = <config>P.Bind<bool>("General", "Play at dropship death", true, new ConfigDescription("If true, will play Dumb Ways To Die at death by the dropship", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { false, true }), Array.Empty<object>()));
			volume = <config>P.Bind<int>("General", "Volume", 100, new ConfigDescription("Set the volume", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			playAtAnyDeath = <config>P.Bind<bool>("Special", "Play at any death", false, new ConfigDescription("If true, will always play Dumb Ways To Die no matter the death cause", (AcceptableValueBase)(object)new AcceptableValueList<bool>(new bool[2] { false, true }), Array.Empty<object>()));
		}
	}
	[BepInPlugin("TestAccount666.DumbWaysToDie", "DumbWaysToDie", "1.1.2")]
	public class DumbWaysToDie : BaseUnityPlugin
	{
		public static DumbWaysToDie Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		internal static AudioClip AudioClip { get; private set; }

		internal static ConfigHandler ConfigHandler { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			Debug.Assert(directoryName != null, "assemblyLocation != null");
			string uriString = Path.Combine(directoryName, "song.wav");
			((MonoBehaviour)this).StartCoroutine(LoadAudioClipFromFile(new Uri(uriString), "DumbWaysToDie"));
			ConfigHandler = new ConfigHandler(((BaseUnityPlugin)this).Config);
			ConfigHandler.HandleConfig();
			Patch();
			Logger.LogInfo((object)"TestAccount666.DumbWaysToDie v1.1.2 has loaded!");
		}

		private static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("TestAccount666.DumbWaysToDie");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		private static IEnumerator LoadAudioClipFromFile(Uri filePath, string name)
		{
			UnityWebRequest unityWebRequest = UnityWebRequestMultimedia.GetAudioClip(filePath, (AudioType)20);
			try
			{
				yield return unityWebRequest.SendWebRequest();
				if ((int)unityWebRequest.result != 1)
				{
					Logger.LogError((object)("Failed to load AudioClip: " + unityWebRequest.error));
					yield break;
				}
				AudioClip = DownloadHandlerAudioClip.GetContent(unityWebRequest);
				((Object)AudioClip).name = name;
				Logger.LogInfo((object)("Loaded clip '" + name + "'!"));
			}
			finally
			{
				((IDisposable)unityWebRequest)?.Dispose();
			}
		}
	}
	[HarmonyPatch]
	public static class PlayerDeathPatch
	{
		private const float MAX_BULLET_FLY_DISTANCE = 31f;

		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
		[HarmonyPostfix]
		public static void OnPlayerDeath(PlayerControllerB __instance)
		{
			if (!DumbWaysToDie.ConfigHandler.playAtAnyDeath.Value)
			{
				return;
			}
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			StartOfRound playersManager = instance.playersManager;
			if (!((Object)(object)playersManager == (Object)null))
			{
				PlayerControllerB localPlayerController = playersManager.localPlayerController;
				if (!((Object)(object)localPlayerController == (Object)null) && localPlayerController.isPlayerDead && !((Object)(object)localPlayerController != (Object)(object)__instance))
				{
					PlaySound();
				}
			}
		}

		[HarmonyPatch(typeof(Landmine), "SpawnExplosion")]
		[HarmonyPostfix]
		public static void OnMineExplosion(Vector3 explosionPosition, float killRange, float damageRange)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Invalid comparison between Unknown and I4
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			if (DumbWaysToDie.ConfigHandler.playAtAnyDeath.Value)
			{
				return;
			}
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			StartOfRound playersManager = instance.playersManager;
			if ((Object)(object)playersManager == (Object)null)
			{
				return;
			}
			PlayerControllerB localPlayerController = playersManager.localPlayerController;
			if (!((Object)(object)localPlayerController == (Object)null) && localPlayerController.isPlayerDead && (int)localPlayerController.causeOfDeath == 3)
			{
				float num = Vector3.Distance(explosionPosition, localPlayerController.oldPlayerPosition);
				if ((!(num > killRange) || !(num > damageRange)) && DumbWaysToDie.ConfigHandler.playAtLandmineDeath.Value)
				{
					PlaySound();
				}
			}
		}

		[HarmonyPatch(typeof(ShotgunItem), "ShootGun")]
		[HarmonyPostfix]
		public static void OnPlayerMurder(ShotgunItem __instance)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Invalid comparison between Unknown and I4
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (DumbWaysToDie.ConfigHandler.playAtAnyDeath.Value)
			{
				return;
			}
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			StartOfRound playersManager = instance.playersManager;
			if ((Object)(object)playersManager == (Object)null)
			{
				return;
			}
			PlayerControllerB localPlayerController = playersManager.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null || !localPlayerController.isPlayerDead || (int)localPlayerController.causeOfDeath != 7)
			{
				return;
			}
			float num = Vector3.Distance(((Component)__instance).gameObject.transform.position, localPlayerController.oldPlayerPosition);
			if (!(num > 31f))
			{
				if (((GrabbableObject)__instance).isHeldByEnemy && DumbWaysToDie.ConfigHandler.playAtShotgunNutcrackerDeath.Value)
				{
					PlaySound();
				}
				else if ((!((GrabbableObject)__instance).isHeld || __instance.misfireTimer <= 0f) && DumbWaysToDie.ConfigHandler.playAtShotgunAccidentDeath.Value)
				{
					PlaySound();
				}
				else if (DumbWaysToDie.ConfigHandler.playAtShotgunMurderDeath.Value)
				{
					PlaySound();
				}
			}
		}

		[HarmonyPatch(typeof(KillLocalPlayer), "KillPlayer")]
		[HarmonyPostfix]
		public static void OnDropShipDeath(PlayerControllerB playerWhoTriggered)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Invalid comparison between Unknown and I4
			if (DumbWaysToDie.ConfigHandler.playAtAnyDeath.Value)
			{
				return;
			}
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			StartOfRound playersManager = instance.playersManager;
			if (!((Object)(object)playersManager == (Object)null))
			{
				PlayerControllerB localPlayerController = playersManager.localPlayerController;
				if (!((Object)(object)localPlayerController == (Object)null) && !((Object)(object)localPlayerController != (Object)(object)playerWhoTriggered) && localPlayerController.isPlayerDead && (int)localPlayerController.causeOfDeath == 8 && DumbWaysToDie.ConfigHandler.playAtDropShipDeath.Value)
				{
					PlaySound();
				}
			}
		}

		[HarmonyPatch(typeof(Turret), "Update")]
		[HarmonyPostfix]
		public static void OnTurretDeath(Turret __instance)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Invalid comparison between Unknown and I4
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Invalid comparison between Unknown and I4
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if (DumbWaysToDie.ConfigHandler.playAtAnyDeath.Value)
			{
				return;
			}
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			StartOfRound playersManager = instance.playersManager;
			if ((Object)(object)playersManager == (Object)null)
			{
				return;
			}
			PlayerControllerB localPlayerController = playersManager.localPlayerController;
			if (!((Object)(object)localPlayerController == (Object)null) && localPlayerController.isPlayerDead && (int)localPlayerController.causeOfDeath == 7 && ((int)__instance.turretMode == 2 || (int)__instance.turretMode == 3))
			{
				float num = Vector3.Distance(((Component)__instance).gameObject.transform.position, localPlayerController.oldPlayerPosition);
				if (!(num > 31f) && DumbWaysToDie.ConfigHandler.playAtTurretDeath.Value)
				{
					PlaySound();
				}
			}
		}

		private static void PlaySound()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			if (!ReviveTrackerPatch.PlayedThisRound)
			{
				ReviveTrackerPatch.PlayedThisRound = true;
				GameObject val = new GameObject("TemporaryAudio");
				AudioSource val2 = val.AddComponent<AudioSource>();
				val2.clip = DumbWaysToDie.AudioClip;
				val2.volume = (float)DumbWaysToDie.ConfigHandler.volume.Value / 100f;
				val2.Play();
				Object.Destroy((Object)(object)val, DumbWaysToDie.AudioClip.length);
			}
		}
	}
	[HarmonyPatch]
	public class ReviveTrackerPatch
	{
		public static bool PlayedThisRound { get; internal set; }

		[HarmonyPatch(typeof(StartOfRound), "AllPlayersHaveRevivedClientRpc")]
		[HarmonyPostfix]
		public static void OnRevive()
		{
			PlayedThisRound = false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "TestAccount666.DumbWaysToDie";

		public const string PLUGIN_NAME = "DumbWaysToDie";

		public const string PLUGIN_VERSION = "1.1.2";
	}
}