Decompiled source of KarmaForBeingAnnoying v1.1.0

KarmaForBeingAnnoying.dll

Decompiled 11 months ago
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using KarmaForBeingAnnoying.Patches;
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("KarmaForBeingAnnoying")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KarmaForBeingAnnoying")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("06f7acd4-c565-4c95-829c-d167f1aee2c2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace KarmaForBeingAnnoying
{
	[BepInPlugin("Chrigi.KarmaForBeingAnnoyingMod", "Karma For Being Annoying Mod", "1.1.0")]
	public class KarmaForBeingAnnoyingModBase : BaseUnityPlugin
	{
		private const string modGUID = "Chrigi.KarmaForBeingAnnoyingMod";

		private const string modName = "Karma For Being Annoying Mod";

		private const string modVersion = "1.1.0";

		private readonly Harmony harmony = new Harmony("Chrigi.KarmaForBeingAnnoyingMod");

		private static KarmaForBeingAnnoyingModBase 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;

		public static ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Chrigi.KarmaForBeingAnnoyingMod");
			mls.LogInfo((object)"________________\nKarma is a bitch!\n________________");
			SetCFG();
			harmony.PatchAll(typeof(NoisemakerPropPatch));
		}

		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");
		}
	}
}
namespace KarmaForBeingAnnoying.Patches
{
	internal class NoisemakerPropPatch
	{
		private static ManualLogSource logger = KarmaForBeingAnnoyingModBase.mls;

		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)
			logger.LogInfo((object)"C'ya");
			yield return (object)new WaitForSeconds(delay);
			Landmine.SpawnExplosion(position, effect, killrange, damagerange);
			logger.LogInfo((object)"Boom");
		}

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

		[HarmonyPatch(typeof(RemoteProp), "ItemActivate")]
		[HarmonyPostfix]
		private static void RemotePropPatch(ref PlayerControllerB ___playerHeldBy, ref RemoteProp __instance)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			logger.LogInfo((object)"RemotePropPatch ACTIVATED BRUHHHHH");
			NetworkBehaviour val = (NetworkBehaviour)(object)__instance;
			if (((KarmaForBeingAnnoyingModBase.RemoteSetting.Value && val.IsOwner && ___playerHeldBy.isPlayerControlled && (!val.IsServer || ___playerHeldBy.isHostPlayerObject)) || ___playerHeldBy.isTestingPlayer) && Random.value < KarmaForBeingAnnoyingModBase.ProbabilityRemoteSetting.Value)
			{
				((MonoBehaviour)__instance).StartCoroutine(DelayedExplosion(((Component)val).transform.position, effect: true, KarmaForBeingAnnoyingModBase.KillRangeSetting.Value, KarmaForBeingAnnoyingModBase.DamageRangeSetting.Value, KarmaForBeingAnnoyingModBase.DelaySetting.Value));
				logger.LogInfo((object)"Karma");
			}
		}
	}
}