Decompiled source of LightningGrenade v1.0.0

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 DigitalRuby.ThunderAndLightning;
using GameNetcodeStuff;
using HarmonyLib;
using LightningGrenade.Patches;
using LightningGrenade.Scripts;
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+1b150105e559e95dca1a9acad2c9d3ecc5a1e153")]
[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", "1.0.0")]
	public class LightningGrenadeMod : BaseUnityPlugin
	{
		public const string modGUID = "com.jacobot5.LightningGrenade";

		public const string modName = "LightningGrenade";

		public const string modVersion = "1.0.0";

		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.Scripts
{
	public class DamageAndKillScript
	{
		public static void DamageOrKillInRadius(Vector3 center, float radius, int damage, CauseOfDeath causeOfDeath)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			int num = 1084754248;
			Collider[] array = Physics.OverlapSphere(center, radius, num, (QueryTriggerInteraction)2);
			foreach (Collider val in array)
			{
				PlayerControllerB component = ((Component)val).GetComponent<PlayerControllerB>();
				if ((Object)(object)component != (Object)null && !component.isPlayerDead && (Object)(object)component == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					if (damage == 0)
					{
						component.KillPlayer(Vector3.down * 17f, true, causeOfDeath, 0, default(Vector3));
					}
					else
					{
						component.DamagePlayer(damage, true, true, causeOfDeath, 0, false, Vector3.down * 17f);
					}
					continue;
				}
				EnemyAICollisionDetect component2 = ((Component)val).GetComponent<EnemyAICollisionDetect>();
				if (!((Object)(object)component2 != (Object)null) || !((Object)(object)component2.mainScript != (Object)null))
				{
					continue;
				}
				EnemyAI mainScript = component2.mainScript;
				if (!((NetworkBehaviour)mainScript).IsOwner || mainScript.isEnemyDead || !mainScript.enemyType.canDie)
				{
					continue;
				}
				if (damage == 0)
				{
					mainScript.KillEnemyOnOwnerClient(false);
					continue;
				}
				IHittable val2 = (IHittable)(object)((mainScript is IHittable) ? mainScript : null);
				if (val2 != null)
				{
					int num2 = Mathf.Clamp(damage / 25, 1, 5);
					val2.Hit(num2, Vector3.down, GameNetworkManager.Instance.localPlayerController, true, -1);
				}
			}
		}
	}
	public class LightningStrikeScript
	{
		public static StormyWeather? stormyWeather;

		public static void SpawnLightningBolt(Vector3 strikePosition, float lightningCutoff, AudioSource lightningAudio, float strikeVolume)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_0139: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor((float)Random.Range(-32, 32), 0f, (float)Random.Range(-32, 32));
			Vector3 position = strikePosition + Vector3.up * 160f + val;
			if ((Object)(object)stormyWeather == (Object)null)
			{
				stormyWeather = Object.FindObjectOfType<StormyWeather>(true);
			}
			LightningBoltPrefabScript obj = Object.Instantiate<LightningBoltPrefabScript>(stormyWeather.targetedThunder);
			((Behaviour)obj).enabled = true;
			((LightningBoltPrefabScriptBase)obj).GlowWidthMultiplier = 2.5f;
			((LightningBoltPrefabScriptBase)obj).DurationRange = new RangeOfFloats
			{
				Minimum = 0.6f,
				Maximum = 1.2f
			};
			((LightningBoltPrefabScriptBase)obj).TrunkWidthRange = new RangeOfFloats
			{
				Minimum = 0.6f,
				Maximum = 1.2f
			};
			((LightningBoltScript)obj).Camera = GameNetworkManager.Instance.localPlayerController.gameplayCamera;
			obj.Source.transform.position = position;
			obj.Destination.transform.position = strikePosition + Vector3.up * lightningCutoff;
			((LightningBoltPrefabScriptBase)obj).AutomaticModeSeconds = 0.2f;
			((LightningBoltPrefabScriptBase)obj).Generations = 8;
			((LightningBoltPrefabScriptBase)obj).CreateLightningBoltsNow();
			((Component)lightningAudio).transform.position = strikePosition;
			lightningAudio.volume = strikeVolume;
			stormyWeather.PlayThunderEffects(strikePosition, lightningAudio);
		}
	}
}
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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: 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 val2 = val.AddComponent<AudioSource>();
			val2.spatialBlend = 0f;
			val2.minDistance = 5f;
			val2.maxDistance = 200f;
			val2.rolloffMode = (AudioRolloffMode)0;
			val2.playOnAwake = false;
			val2.loop = false;
			((Behaviour)val2).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 lightningCutoff = 0f;
			if (GameNetworkManager.Instance.localPlayerController.isInsideFactory)
			{
				Object.FindObjectOfType<RoundManager>().SwitchPower(false);
				lightningCutoff = 80f;
			}
			else
			{
				Bounds bounds = StartOfRound.Instance.shipBounds.bounds;
				if (((Bounds)(ref bounds)).Contains(position))
				{
					lightningCutoff = 9f;
				}
				else
				{
					DamageAndKillScript.DamageOrKillInRadius(position, LightningGrenadeMod.configLightningDamageRadius.Value, 0, (CauseOfDeath)11);
				}
			}
			LightningStrikeScript.SpawnLightningBolt(position, lightningCutoff, val2, LightningGrenadeMod.configLightningVolume.Value);
			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)
		{
		}
	}
}