Decompiled source of ExplodingHorns v1.1.0

ExplodingHorns.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExplodingHorns.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using LethalNetworkAPI;
using LethalSettings.UI;
using LethalSettings.UI.Components;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ExplodingHorns")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ExplodingHorns")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6b3d5f35-02d0-4b46-964d-46ebee750fa0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace ExplodingHorns
{
	internal static class LethalSettingsIntegration
	{
		internal static void TryRegister()
		{
			if (!Chainloader.PluginInfos.ContainsKey("com.willis.lc.lethalsettings"))
			{
				Plugin.Log.LogInfo((object)"LethalSettings non détecté — configuration via le .cfg uniquement.");
				return;
			}
			try
			{
				Register();
				Plugin.Log.LogInfo((object)"Menu LethalSettings enregistré pour ExplodingHorns.");
			}
			catch (Exception arg)
			{
				Plugin.Log.LogWarning((object)$"Impossible d'enregistrer le menu LethalSettings : {arg}");
			}
		}

		private static void Register()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Expected O, but got Unknown
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Expected O, but got Unknown
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Expected O, but got Unknown
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Expected O, but got Unknown
			ModSettingsConfig val = new ModSettingsConfig();
			val.Name = "ExplodingHorns";
			val.Id = "ota.explodinghorns";
			val.Version = "1.0.0";
			val.Description = "Chance que l'airhorn / clown horn explose (+ foudre) à l'usage.";
			val.MenuComponents = (MenuComponent[])(object)new MenuComponent[7]
			{
				(MenuComponent)new SliderComponent
				{
					Text = "Chance d'explosion (%)",
					Value = Plugin.ExplosionChance.Value * 100f,
					MinValue = 0f,
					MaxValue = 100f,
					OnValueChanged = delegate(SliderComponent self, float value)
					{
						Plugin.ExplosionChance.Value = value / 100f;
					}
				},
				(MenuComponent)new SliderComponent
				{
					Text = "Rayon de dégâts min (m)",
					Value = Plugin.MinDamageRadius.Value,
					MinValue = 0f,
					MaxValue = 20f,
					OnValueChanged = delegate(SliderComponent self, float value)
					{
						Plugin.MinDamageRadius.Value = value;
					}
				},
				(MenuComponent)new SliderComponent
				{
					Text = "Rayon de dégâts max (m)",
					Value = Plugin.MaxDamageRadius.Value,
					MinValue = 0f,
					MaxValue = 30f,
					OnValueChanged = delegate(SliderComponent self, float value)
					{
						Plugin.MaxDamageRadius.Value = value;
					}
				},
				(MenuComponent)new SliderComponent
				{
					Text = "Dégâts",
					Value = Plugin.DamageAmount.Value,
					MinValue = 0f,
					MaxValue = 150f,
					OnValueChanged = delegate(SliderComponent self, float value)
					{
						Plugin.DamageAmount.Value = (int)value;
					}
				},
				(MenuComponent)new ToggleComponent
				{
					Text = "Détruire le horn après explosion",
					Value = Plugin.DestroyHornOnExplosion.Value,
					OnValueChanged = delegate(ToggleComponent self, bool value)
					{
						Plugin.DestroyHornOnExplosion.Value = value;
					}
				},
				(MenuComponent)new ToggleComponent
				{
					Text = "Activer la foudre autour de l'explosion",
					Value = Plugin.LightningEnabled.Value,
					OnValueChanged = delegate(ToggleComponent self, bool value)
					{
						Plugin.LightningEnabled.Value = value;
					}
				},
				(MenuComponent)new SliderComponent
				{
					Text = "Rayon de la foudre (m)",
					Value = Plugin.LightningRadius.Value,
					MinValue = 0f,
					MaxValue = 40f,
					OnValueChanged = delegate(SliderComponent self, float value)
					{
						Plugin.LightningRadius.Value = value;
					}
				}
			};
			ModMenu.RegisterMod(val);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("ota.explodinghorns", "ExplodingHorns", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "ota.explodinghorns";

		public const string PluginName = "ExplodingHorns";

		public const string PluginVersion = "1.0.0";

		public const string LethalSettingsGuid = "com.willis.lc.lethalsettings";

		public static ConfigEntry<float> ExplosionChance;

		public static ConfigEntry<float> MinDamageRadius;

		public static ConfigEntry<float> MaxDamageRadius;

		public static ConfigEntry<int> DamageAmount;

		public static ConfigEntry<bool> DestroyHornOnExplosion;

		public static ConfigEntry<bool> LightningEnabled;

		public static ConfigEntry<float> LightningRadius;

		internal static ManualLogSource Log;

		private readonly Harmony harmony = new Harmony("ota.explodinghorns");

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			ExplosionChance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ExplosionChance", 0.1f, "Probabilité (entre 0 et 1) que l'airhorn / clown horn explose à chaque utilisation. 0.10 = 10%.");
			MinDamageRadius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MinDamageRadius", 2f, "Rayon (en mètres) dans lequel les dégâts de l'explosion sont maximaux.");
			MaxDamageRadius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxDamageRadius", 6f, "Rayon (en mètres) au-delà duquel l'explosion ne fait plus de dégâts.");
			DamageAmount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "DamageAmount", 60, "Dégâts infligés par l'explosion (le porteur du horn les reçoit toujours, même hors du rayon).");
			DestroyHornOnExplosion = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DestroyHornOnExplosion", true, "Si vrai, le horn est détruit quand il explose.");
			LightningEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Lightning", "LightningEnabled", true, "Si vrai, la foudre s'abat aussi sur les joueurs à proximité de l'explosion. Ne fonctionne que si la météo du jour est orageuse (StormyWeather).");
			LightningRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Lightning", "LightningRadius", 15f, "Rayon (en mètres) autour de l'explosion dans lequel les joueurs sont frappés par la foudre.");
			harmony.PatchAll(typeof(HornExplosionPatch));
			LethalSettingsIntegration.TryRegister();
			Log.LogInfo((object)string.Format("{0} {1} chargé — chance d'explosion : {2}%", "ExplodingHorns", "1.0.0", ExplosionChance.Value * 100f));
		}
	}
}
namespace ExplodingHorns.Patches
{
	[HarmonyPatch(typeof(NoisemakerProp), "ItemActivate")]
	internal static class HornExplosionPatch
	{
		private static readonly LNetworkMessage<Vector3> ExplosionMessage = LNetworkMessage<Vector3>.Connect("ExplodingHorns_Explosion", (Action<Vector3, ulong>)delegate(Vector3 position, ulong senderId)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			ExplosionMessage.SendClients(position);
		}, (Action<Vector3>)SpawnExplosionLocally, (Action<Vector3, ulong>)null);

		private static AudioClip cachedExplosionClip;

		[HarmonyPostfix]
		private static void Postfix(NoisemakerProp __instance, bool used, bool buttonDown)
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			if (!buttonDown || !((NetworkBehaviour)__instance).IsOwner)
			{
				return;
			}
			string text = (((Object)(object)((GrabbableObject)__instance).itemProperties != (Object)null) ? ((Object)((GrabbableObject)__instance).itemProperties).name : null);
			Plugin.Log.LogDebug((object)("NoisemakerProp activé : nom d'objet = \"" + text + "\""));
			if ((!(text != "Airhorn") || !(text != "ClownHorn")) && Random.value <= Plugin.ExplosionChance.Value)
			{
				Vector2 insideUnitCircle = Random.insideUnitCircle;
				Vector2 val = ((Vector2)(ref insideUnitCircle)).normalized * 1.2f;
				Vector3 val2 = ((Component)__instance).transform.position + new Vector3(val.x, 0f, val.y);
				Plugin.Log.LogInfo((object)string.Format("BOOM — {0} explose en {1}", ((GrabbableObject)__instance).itemProperties?.itemName ?? "horn", val2));
				if (Plugin.LightningEnabled.Value)
				{
					StrikeLightningNearby(val2, Plugin.LightningRadius.Value);
				}
				if (Plugin.DestroyHornOnExplosion.Value)
				{
					((GrabbableObject)__instance).DestroyObjectInHand(((GrabbableObject)__instance).playerHeldBy);
				}
				ExplosionMessage.SendServer(val2);
			}
		}

		private static void SpawnExplosionLocally(Vector3 position)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			PlayExplosionSound(position);
			Landmine.SpawnExplosion(position, true, Plugin.MinDamageRadius.Value, Plugin.MaxDamageRadius.Value, Plugin.DamageAmount.Value, 0f, (GameObject)null, false);
		}

		private static void PlayExplosionSound(Vector3 position)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)cachedExplosionClip == (Object)null)
			{
				Landmine val = Object.FindObjectOfType<Landmine>();
				cachedExplosionClip = (((Object)(object)val != (Object)null) ? val.mineDetonate : null);
			}
			if ((Object)(object)cachedExplosionClip != (Object)null)
			{
				AudioSource.PlayClipAtPoint(cachedExplosionClip, position);
			}
			else
			{
				Plugin.Log.LogDebug((object)"Pas de mine trouvée sur ce niveau, donc pas de son d'explosion disponible pour le horn.");
			}
		}

		private static void StrikeLightningNearby(Vector3 origin, float radius)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			PlayerControllerB[] array = allPlayerScripts;
			foreach (PlayerControllerB val in array)
			{
				if (!((Object)(object)val == (Object)null) && !val.isPlayerDead)
				{
					float num = Vector3.Distance(((Component)val).transform.position, origin);
					if (num <= radius)
					{
						Plugin.Log.LogInfo((object)("⚡ La foudre s'abat sur " + val.playerUsername + " !"));
						RoundManager.Instance.LightningStrikeServerRpc(((Component)val).transform.position);
					}
				}
			}
		}
	}
}