Decompiled source of Karma v0.0.1

KarmaReborn/KarmaReborn.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using KarmaReborn.Patches;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("KarmaReborn")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KarmaReborn")]
[assembly: AssemblyTitle("KarmaReborn")]
[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 KarmaReborn
{
	[BepInPlugin("Exavi.KarmaReborn", "Karma Reborn", "1.0.1")]
	public class KarmaReborn : BaseUnityPlugin
	{
		private const string modGUID = "Exavi.KarmaReborn";

		private const string modName = "Karma Reborn";

		private const string modVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("Exavi.KarmaReborn");

		internal static KarmaReborn 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()
		{
			//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;
			}
			mls = Logger.CreateLogSource("Exavi.KarmaReborn");
			mls.LogInfo((object)"KarmaReborn mod has loaded!");
			harmony.PatchAll(typeof(KarmaReborn));
			SetCFG();
			harmony.PatchAll(typeof(NoisemakerPropPatch));
		}

		private static void SetCFG()
		{
			AnnoyingItemSetting = ((BaseUnityPlugin)Instance).Config.Bind<bool>("KarmaReborn 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>("KarmaReborn Settings", "UseOnRemote", true, "Defines if Remote sets off explosion based on params");
		}
	}
}
namespace KarmaReborn.Patches
{
	internal class NoisemakerPropPatch
	{
		private static ManualLogSource logger = KarmaReborn.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, 50, 0f, (GameObject)null, false);
			logger.LogInfo((object)"Boom");
		}

		[HarmonyPatch(typeof(NoisemakerProp), "ItemActivate")]
		[HarmonyPostfix]
		private static void NoiseMakerPropItemActivatePatch(ref PlayerControllerB ___playerHeldBy, ref NoisemakerProp __instance)
		{
			//IL_010c: 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 ((KarmaReborn.AnnoyingItemSetting.Value && val.IsOwner && ___playerHeldBy.isPlayerControlled && (!val.IsServer || ___playerHeldBy.isHostPlayerObject)) || ___playerHeldBy.isTestingPlayer)
			{
				float value = KarmaReborn.ProbabilitySetting.Value;
				switch (((Object)__instance).name.Replace("(Clone)", "").ToLower())
				{
				case "airhorn":
					value = KarmaReborn.ProbabilityAirhornSetting.Value;
					break;
				case "clownhorn":
					value = KarmaReborn.ProbabilityClownhornSetting.Value;
					break;
				case "cashregisteritem":
					value = KarmaReborn.ProbabilityCashRegisterSetting.Value;
					break;
				case "hairdryer":
					value = KarmaReborn.ProbabilityHairDryerSetting.Value;
					break;
				}
				if (Random.value < value)
				{
					((MonoBehaviour)__instance).StartCoroutine(DelayedExplosion(((Component)val).transform.position, effect: true, KarmaReborn.KillRangeSetting.Value, KarmaReborn.DamageRangeSetting.Value, KarmaReborn.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 (((KarmaReborn.RemoteSetting.Value && val.IsOwner && ___playerHeldBy.isPlayerControlled && (!val.IsServer || ___playerHeldBy.isHostPlayerObject)) || ___playerHeldBy.isTestingPlayer) && Random.value < KarmaReborn.ProbabilityRemoteSetting.Value)
			{
				((MonoBehaviour)__instance).StartCoroutine(DelayedExplosion(((Component)val).transform.position, effect: true, KarmaReborn.KillRangeSetting.Value, KarmaReborn.DamageRangeSetting.Value, KarmaReborn.DelaySetting.Value));
				logger.LogInfo((object)"Karma");
			}
		}
	}
}