Decompiled source of LightningGrenade v2.0.2

LightningGrenade.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Linq;
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 EZDamage;
using EZLightning;
using HarmonyLib;
using LightningGrenade.Patches;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LightningGrenade")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+230c9308f4b5f29d828ad22703fe6665a7111f7c")]
[assembly: AssemblyProduct("LightningGrenade")]
[assembly: AssemblyTitle("LightningGrenade")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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 LightningGrenade
{
	[BepInPlugin("com.jacobot5.LightningGrenade", "LightningGrenade", "2.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class LightningGrenadeMod : BaseUnityPlugin
	{
		public const string modGUID = "com.jacobot5.LightningGrenade";

		public const string modName = "LightningGrenade";

		public const string modVersion = "2.0.2";

		private readonly Harmony harmony = new Harmony("com.jacobot5.LightningGrenade");

		public static ConfigEntry<float> configLightningVolume;

		public static ConfigEntry<float> configLightningDamageRadius;

		public static LightningGrenadeMod Instance;

		public static ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("com.jacobot5.LightningGrenade");
			mls.LogInfo((object)"LightningGrenade has awoken.");
			configLightningVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Lightning.Thunder", "Volume", 1f, "How loud thunder should be. Default is 1; ranges from 0-1");
			configLightningDamageRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Lightning.Damage", "Radius", 3f, "How close players/enemies must be to a lighting bolt to be killed by it");
			harmony.PatchAll(typeof(LightningGrenadeMod));
			harmony.PatchAll(typeof(StunGrenadeItemPatch));
			harmony.PatchAll(typeof(KickIfModNotInstalled));
		}
	}
}
namespace LightningGrenade.Patches
{
	[HarmonyPatch(typeof(NetworkManager))]
	internal static class KickIfModNotInstalled
	{
		private static readonly string MOD_GUID = "com.jacobot5.LightningGrenade";

		[HarmonyPostfix]
		[HarmonyPatch("SetSingleton")]
		private static void RegisterPrefab()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(MOD_GUID + " Prefab");
			((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
			Object.DontDestroyOnLoad((Object)(object)val);
			NetworkObject obj = val.AddComponent<NetworkObject>();
			typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(obj, GetHash(MOD_GUID));
			NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
			static uint GetHash(string value)
			{
				return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
			}
		}
	}
	[HarmonyPatch(typeof(StunGrenadeItem))]
	internal class StunGrenadeItemPatch
	{
		[HarmonyPatch("ExplodeStunGrenade")]
		[HarmonyPrefix]
		private static bool LightningStrikePatch(StunGrenadeItem __instance)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("LightningGrenade_ThunderAudioSource");
			val.SetActive(true);
			Object.DontDestroyOnLoad((Object)val);
			AudioSource obj = val.AddComponent<AudioSource>();
			obj.spatialBlend = 0f;
			obj.minDistance = 5f;
			obj.maxDistance = 200f;
			obj.rolloffMode = (AudioRolloffMode)0;
			obj.playOnAwake = false;
			obj.loop = false;
			((Behaviour)obj).enabled = true;
			if (__instance.hasExploded)
			{
				return false;
			}
			if ((__instance.chanceToExplode < 100f && !__instance.explodeOnThrow) || (__instance.explodeOnCollision && !StartOfRound.Instance.currentLevel.spawnEnemiesAndScrap && (Object)(object)((GrabbableObject)__instance).parentObject == (Object)(object)Object.FindObjectOfType<DepositItemsDesk>().deskObjectsContainer))
			{
				if ((Object)(object)__instance.playerThrownBy != (Object)null)
				{
					__instance.playerThrownBy.activatingItem = false;
				}
				return false;
			}
			__instance.hasExploded = true;
			if (((GrabbableObject)__instance).isInElevator)
			{
				_ = StartOfRound.Instance.elevatorTransform;
			}
			else
			{
				_ = RoundManager.Instance.mapPropsContainer.transform;
			}
			Vector3 position = ((Component)__instance).transform.position;
			float num = 0f;
			if (GameNetworkManager.Instance.localPlayerController.isInsideFactory)
			{
				Object.FindObjectOfType<RoundManager>().SwitchPower(false);
				num = 80f;
			}
			else
			{
				Bounds bounds = StartOfRound.Instance.shipBounds.bounds;
				if (((Bounds)(ref bounds)).Contains(position))
				{
					num = 9f;
				}
				else
				{
					API.KillEverything(position, LightningGrenadeMod.configLightningDamageRadius.Value, (CauseOfDeath)11);
				}
			}
			API.Strike(position + Vector3.up * num, LightningGrenadeMod.configLightningVolume.Value, 2.5f, -1f, -1, -1f, 0.6f, 1.2f, -1, -1);
			if (__instance.DestroyGrenade)
			{
				((GrabbableObject)__instance).DestroyObjectInHand(__instance.playerThrownBy);
			}
			return false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}