Decompiled source of KarmaForBeingAnnoying UPDATED v1.1.0

KarmaForBeingAnnoying_UPDATED.dll

Decompiled 5 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
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: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("KarmaForBeingAnnoying_UPDATED")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Updated version of the mod \"KarmaForBeingAnnoying\"")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("KarmaForBeingAnnoying_UPDATED")]
[assembly: AssemblyTitle("KarmaForBeingAnnoying_UPDATED")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace KarmaForBeingAnnoying_UPDATED
{
	[BepInPlugin("KarmaForBeingAnnoying_UPDATED", "KarmaForBeingAnnoying_UPDATED", "1.1.0")]
	public class Main : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("KarmaForBeingAnnoying_UPDATED");

		private static Main Instance;

		internal static ConfigEntry<bool> AnnoyingItemSetting;

		internal static ConfigEntry<float> ProbabilitySetting;

		internal static ConfigEntry<float> ProbabilityRemoteSetting;

		internal static ConfigEntry<float> ProbabilityAirhornSetting;

		internal static ConfigEntry<float> ProbabilityClownhornSetting;

		internal static ConfigEntry<float> ProbabilityCashRegisterSetting;

		internal static ConfigEntry<float> ProbabilityHairDryerSetting;

		internal static ConfigEntry<float> DelaySetting;

		internal static ConfigEntry<float> KillRangeSetting;

		internal static ConfigEntry<float> DamageRangeSetting;

		internal static ConfigEntry<bool> RemoteSetting;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			if ((Object)Instance == (Object)null)
			{
				Instance = this;
			}
			SetCFG();
			harmony.PatchAll(typeof(Patches));
		}

		private static void SetCFG()
		{
			AnnoyingItemSetting = ((BaseUnityPlugin)Instance).Config.Bind<bool>("KarmaForBeingAnnoying Settings", "ON OFF switch", true, "Turns functionality on or off");
			ProbabilitySetting = ((BaseUnityPlugin)Instance).Config.Bind<float>("Probability Settings", "General Probability", 0.1f, "Set probability of exploding");
			ProbabilityRemoteSetting = ((BaseUnityPlugin)Instance).Config.Bind<float>("Probability Settings", "Remote Probability", 0.1f, "Set probability of exploding when using Remote");
			ProbabilityAirhornSetting = ((BaseUnityPlugin)Instance).Config.Bind<float>("Probability Settings", "Airhorn Probability", 0.1f, "Set probability of exploding when using Airhorn");
			ProbabilityClownhornSetting = ((BaseUnityPlugin)Instance).Config.Bind<float>("Probability Settings", "Clownhorn Probability", 0.1f, "Set probability of exploding when using Clownhorn");
			ProbabilityCashRegisterSetting = ((BaseUnityPlugin)Instance).Config.Bind<float>("Probability Settings", "Cashregister Probability", 0.1f, "Set probability of exploding when using Cashregister");
			ProbabilityHairDryerSetting = ((BaseUnityPlugin)Instance).Config.Bind<float>("Probability Settings", "Hairdryer Probability", 0.1f, "Set probability of exploding when using Hairdryer");
			DelaySetting = ((BaseUnityPlugin)Instance).Config.Bind<float>("Delay Settings", "General Delay", 0.5f, "Set delay of explosion");
			KillRangeSetting = ((BaseUnityPlugin)Instance).Config.Bind<float>("Kill Range Settings", "General Kill Range", 10f, "Set kill range of explosion");
			DamageRangeSetting = ((BaseUnityPlugin)Instance).Config.Bind<float>("Damage Range Settings", "General Damage Range", 1f, "Set damage range of explosion");
			RemoteSetting = ((BaseUnityPlugin)Instance).Config.Bind<bool>("KarmaForBeingAnnoying Settings", "UseOnRemote", true, "Defines if Remote sets off explosion based on params");
		}
	}
	public class Patches
	{
		private static IEnumerator DelayedExplosion(Vector3 position, bool effect, float killrange, float damagerange, float delay)
		{
			//IL_0007: 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)
			yield return (object)new WaitForSeconds(delay);
			Landmine.SpawnExplosion(position, effect, killrange, damagerange, 50, 0f, (GameObject)null, false);
		}

		[HarmonyPatch(typeof(NoisemakerProp), "ItemActivate")]
		[HarmonyPostfix]
		private static void NoiseMakerPropItemActivatePatch(ref PlayerControllerB ___playerHeldBy, ref NoisemakerProp __instance)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			NetworkBehaviour val = (NetworkBehaviour)___playerHeldBy;
			if ((Main.AnnoyingItemSetting.Value && val.IsOwner && ___playerHeldBy.isPlayerControlled && (!val.IsServer || ___playerHeldBy.isHostPlayerObject)) || ___playerHeldBy.isTestingPlayer)
			{
				float value = Main.ProbabilitySetting.Value;
				switch (((Object)__instance).name.Replace("(Clone)", "").ToLower())
				{
				case "airhorn":
					value = Main.ProbabilityAirhornSetting.Value;
					break;
				case "clownhorn":
					value = Main.ProbabilityClownhornSetting.Value;
					break;
				case "cashregisteritem":
					value = Main.ProbabilityCashRegisterSetting.Value;
					break;
				case "hairdryer":
					value = Main.ProbabilityHairDryerSetting.Value;
					break;
				}
				if (Random.value < value)
				{
					((MonoBehaviour)__instance).StartCoroutine(DelayedExplosion(((Component)val).transform.position, effect: true, Main.KillRangeSetting.Value, Main.DamageRangeSetting.Value, Main.DelaySetting.Value));
				}
			}
		}

		[HarmonyPatch(typeof(RemoteProp), "ItemActivate")]
		[HarmonyPostfix]
		private static void RemotePropPatch(ref PlayerControllerB ___playerHeldBy, ref RemoteProp __instance)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkBehaviour val = (NetworkBehaviour)__instance;
			if (((Main.RemoteSetting.Value && val.IsOwner && ___playerHeldBy.isPlayerControlled && (!val.IsServer || ___playerHeldBy.isHostPlayerObject)) || ___playerHeldBy.isTestingPlayer) && Random.value < Main.ProbabilityRemoteSetting.Value)
			{
				((MonoBehaviour)__instance).StartCoroutine(DelayedExplosion(((Component)val).transform.position, effect: true, Main.KillRangeSetting.Value, Main.DamageRangeSetting.Value, Main.DelaySetting.Value));
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "KarmaForBeingAnnoying_UPDATED";

		public const string PLUGIN_NAME = "KarmaForBeingAnnoying_UPDATED";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}