Decompiled source of EveryEnemyInA5MeterRadiusExplodes v1.0.0

EveryEnemyInA5MeterRadiusExplodes.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
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 UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;

[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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("EveryEnemyInA5MeterRadiusExplodes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Explodes Every Enemy In A 5 Meter Radius")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EveryEnemyInA5MeterRadiusExplodes")]
[assembly: AssemblyTitle("EveryEnemyInA5MeterRadiusExplodes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace EveryEnemyInA5MeterRadiusExplodes
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "EveryEnemyInA5MeterRadiusExplodes";

		public const string PLUGIN_NAME = "EveryEnemyInA5MeterRadiusExplodes";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace EveryEnemyExplodesInA5MeterRadius
{
	[BepInPlugin("EveryEnemyInA5MeterRadiusExplodes", "EveryEnemyInA5MeterRadiusExplodes", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public enum ExplosionType
		{
			MinosPrime,
			RocketHarmless,
			Wave,
			Landmine,
			Big,
			Ferryman,
			Mindflayer,
			Lightning,
			Sand,
			HammerWeak,
			MaliciousRailcannon,
			WaveSisyphus,
			LightningStrikeExplosive,
			Default,
			SisyphusPrime,
			Gutterman,
			WaveEnemy,
			Super,
			Harmless,
			SisyphusPrimeCharged,
			LightningNoLightning
		}

		public ConfigEntry<float> radius;

		public ConfigEntry<bool> IncludeEverything;

		public ConfigEntry<string> explosionPath;

		public GameObject Kaboom;

		public ConfigEntry<float> cooldownTime;

		public ConfigEntry<bool> canHitGameObjectMoreThenOnce;

		public ConfigEntry<bool> RandomTime;

		public ConfigEntry<int> limit;

		public ConfigEntry<bool> JustDupeIt;

		public ConfigEntry<bool> JustKillThem;

		public ConfigEntry<bool> DestroyThem;

		public ConfigEntry<bool> IncludePlayer;

		public ConfigEntry<bool> ShowSphere;

		private float nextExplosionTime;

		public List<GameObject> alreadyExplodedGameObjects = new List<GameObject>();

		private GameObject sphereVisualization;

		private Material PreviewMat;

		public ConfigEntry<ExplosionType> type;

		public static string GetExplosionPath(ExplosionType type)
		{
			switch (type)
			{
			case ExplosionType.MinosPrime:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Minos Prime.prefab";
			case ExplosionType.RocketHarmless:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Rocket Harmless.prefab";
			case ExplosionType.Wave:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Wave.prefab";
			case ExplosionType.Landmine:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Landmine.prefab";
			case ExplosionType.Big:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Big.prefab";
			case ExplosionType.Ferryman:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Ferryman.prefab";
			case ExplosionType.Mindflayer:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Mindflayer.prefab";
			case ExplosionType.Lightning:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Lightning.prefab";
			case ExplosionType.Sand:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Sand.prefab";
			case ExplosionType.HammerWeak:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Hammer Weak.prefab";
			case ExplosionType.MaliciousRailcannon:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Malicious Railcannon.prefab";
			case ExplosionType.WaveSisyphus:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Wave Sisyphus.prefab";
			case ExplosionType.LightningStrikeExplosive:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Lightning Strike Explosive.prefab";
			case ExplosionType.Default:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion.prefab";
			case ExplosionType.SisyphusPrime:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Sisyphus Prime.prefab";
			case ExplosionType.Gutterman:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Gutterman.prefab";
			case ExplosionType.WaveEnemy:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Wave Enemy.prefab";
			case ExplosionType.Super:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Super.prefab";
			case ExplosionType.Harmless:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Harmless.prefab";
			case ExplosionType.SisyphusPrimeCharged:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Sisyphus Prime Charged.prefab";
			case ExplosionType.LightningNoLightning:
				return "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Lightning - No Lightning.prefab";
			default:
				Debug.LogError((object)"nothing lol");
				return null;
			}
		}

		private void Start()
		{
			radius = ((BaseUnityPlugin)this).Config.Bind<float>("ExplosionSettings", "Radius", 5f, (ConfigDescription)null);
			limit = ((BaseUnityPlugin)this).Config.Bind<int>("ExplosionSettings", "Limit", 0, "Limits the amount of targets (0 = infinite)");
			cooldownTime = ((BaseUnityPlugin)this).Config.Bind<float>("ExplosionSettings", "Cooldown Time", 2f, (ConfigDescription)null);
			canHitGameObjectMoreThenOnce = ((BaseUnityPlugin)this).Config.Bind<bool>("ExplosionSettings", "Can Hit Gameobjects more then once", true, "When disabled, it can only explode gameobjects once");
			RandomTime = ((BaseUnityPlugin)this).Config.Bind<bool>("ExplosionSettings", "random time", false, (ConfigDescription)null);
			type = ((BaseUnityPlugin)this).Config.Bind<ExplosionType>("ExplosionSettings", "Preset explosions", ExplosionType.Big, "Only use in game");
			type.SettingChanged += Type_SettingChanged;
			explosionPath = ((BaseUnityPlugin)this).Config.Bind<string>("ExplosionSettings", "Explosion Path", "Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Big.prefab", (ConfigDescription)null);
			explosionPath.SettingChanged += ExplosionPath_SettingChanged;
			IncludeEverything = ((BaseUnityPlugin)this).Config.Bind<bool>("BehaviorToggles", "Include Everything", false, (ConfigDescription)null);
			IncludePlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("BehaviorToggles", "Include Player", false, (ConfigDescription)null);
			JustDupeIt = ((BaseUnityPlugin)this).Config.Bind<bool>("BehaviorToggles", "Duplicate them", false, "Duplicates the objects instead of exploding them");
			DestroyThem = ((BaseUnityPlugin)this).Config.Bind<bool>("BehaviorToggles", "destroy them", false, "destroy the objects instead of exploding them (DONT ENABLE THIS)");
			JustKillThem = ((BaseUnityPlugin)this).Config.Bind<bool>("BehaviorToggles", "InstaKill enemies", false, "instakills the enemies instead of exploding them");
			ShowSphere = ((BaseUnityPlugin)this).Config.Bind<bool>("BehaviorToggles", "Show Sphere", false, "Shows a sphere representing the explosion radius");
			nextExplosionTime = Time.time;
			((MonoBehaviour)this).StartCoroutine(LoadKaboom());
			SceneManager.sceneLoaded += SceneManager_sceneLoaded;
		}

		private void ExplosionPath_SettingChanged(object sender, EventArgs e)
		{
			((MonoBehaviour)this).StartCoroutine(LoadKaboom());
		}

		private void Type_SettingChanged(object sender, EventArgs e)
		{
			explosionPath.Value = GetExplosionPath(type.Value);
		}

		private void CreateSphereVisualization()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			sphereVisualization = GameObject.CreatePrimitive((PrimitiveType)0);
			sphereVisualization.SetActive(false);
			((Object)sphereVisualization).name = "ExplosionRadiusSphere";
			Object.Destroy((Object)(object)sphereVisualization.GetComponent<Collider>());
			Renderer component = sphereVisualization.GetComponent<Renderer>();
			if ((Object)(object)PreviewMat == (Object)null)
			{
				Material val = new Material(Shader.Find("Standard"));
				val.color = new Color(1f, 0f, 0f, 0.3f);
				component.material = val;
			}
			else
			{
				component.material = PreviewMat;
			}
			MeshFilter component2 = sphereVisualization.GetComponent<MeshFilter>();
			Mesh mesh = component2.mesh;
			Vector3[] normals = mesh.normals;
			for (int i = 0; i < normals.Length; i++)
			{
				normals[i] = -normals[i];
			}
			mesh.normals = normals;
			for (int j = 0; j < mesh.subMeshCount; j++)
			{
				int[] triangles = mesh.GetTriangles(j);
				for (int k = 0; k < triangles.Length; k += 3)
				{
					int num = triangles[k];
					triangles[k] = triangles[k + 1];
					triangles[k + 1] = num;
				}
				mesh.SetTriangles(triangles, j);
			}
		}

		private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
		{
			alreadyExplodedGameObjects.Clear();
			if ((Object)(object)Kaboom == (Object)null)
			{
				((MonoBehaviour)this).StartCoroutine(LoadKaboom());
			}
			if ((Object)(object)PreviewMat == (Object)null)
			{
				((MonoBehaviour)this).StartCoroutine(loadPrevMat());
			}
			if ((Object)(object)sphereVisualization == (Object)null)
			{
				CreateSphereVisualization();
			}
		}

		public IEnumerator loadPrevMat()
		{
			AsyncOperationHandle<Material> operationHandle = Addressables.LoadAssetAsync<Material>((object)"Assets/Materials/Preview Object.mat");
			yield return (object)new WaitUntil((Func<bool>)(() => operationHandle.IsDone));
			PreviewMat = operationHandle.Result;
		}

		private void UpdateSphereVisualization(Vector3 center)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)sphereVisualization != (Object)null)
			{
				sphereVisualization.transform.position = center;
				sphereVisualization.transform.localScale = Vector3.one * (radius.Value * 2f);
				sphereVisualization.SetActive(ShowSphere.Value);
			}
			else
			{
				Debug.Log((object)"no spher");
			}
		}

		private void FixedUpdate()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)MonoSingleton<NewMovement>.Instance).transform;
			UpdateSphereVisualization(transform.position);
			if ((Object)(object)Kaboom == (Object)null || Time.time < nextExplosionTime)
			{
				return;
			}
			List<Collider> list = Physics.OverlapSphere(transform.position, radius.Value).ToList();
			if (list.Count <= 0 || !(Time.timeScale > 0f))
			{
				return;
			}
			int num = 0;
			int num2 = ((limit.Value > 0) ? Mathf.Clamp(limit.Value, 1, list.Count) : list.Count);
			foreach (Collider item in list)
			{
				if (num >= num2)
				{
					break;
				}
				if (alreadyExplodedGameObjects.Contains(((Component)item).gameObject) && !canHitGameObjectMoreThenOnce.Value)
				{
					continue;
				}
				if (JustKillThem.Value)
				{
					if (Object.op_Implicit((Object)(object)((Component)item).gameObject.GetComponent<EnemyIdentifier>()))
					{
						((Component)item).gameObject.GetComponent<EnemyIdentifier>().InstaKill();
					}
				}
				else if ((Object.op_Implicit((Object)(object)((Component)item).gameObject.GetComponent<EnemyIdentifier>()) && !((Component)item).gameObject.GetComponent<EnemyIdentifier>().dead && !((Component)item).gameObject.GetComponent<EnemyIdentifier>().blessed && (Object)(object)((Component)item).gameObject.GetComponent<EnemyIdentifier>().idol == (Object)null && ((Object)(object)((Component)item).gameObject.GetComponent<EnemyIdentifier>().spider == (Object)null || ((Object)(object)((Component)item).gameObject.GetComponent<EnemyIdentifier>().spider != (Object)null && ((Component)item).gameObject.GetComponent<EnemyIdentifier>().isGasolined))) || IncludeEverything.Value)
				{
					if (JustDupeIt.Value)
					{
						Object.Instantiate<GameObject>(((Component)item).gameObject, ((Component)item).transform.position, ((Component)item).transform.rotation);
					}
					else if (DestroyThem.Value)
					{
						if (IsParentOfPlayer(((Component)item).gameObject.transform))
						{
							continue;
						}
						Object.Destroy((Object)(object)((Component)item).gameObject);
					}
					else
					{
						Object.Instantiate<GameObject>(Kaboom, ((Component)item).transform.position, Quaternion.identity);
						alreadyExplodedGameObjects.Add(((Component)item).gameObject);
					}
					num++;
				}
				else if (Object.op_Implicit((Object)(object)((Component)item).gameObject.GetComponent<NewMovement>()) && IncludePlayer.Value)
				{
					if (JustDupeIt.Value)
					{
						Object.Instantiate<GameObject>(((Component)item).gameObject, ((Component)item).transform.position, ((Component)item).transform.rotation);
					}
					else
					{
						Object.Instantiate<GameObject>(Kaboom, ((Component)item).transform.position, Quaternion.identity);
						alreadyExplodedGameObjects.Add(((Component)item).gameObject);
					}
					num++;
				}
			}
			float num3 = (RandomTime.Value ? Random.Range(0f, cooldownTime.Value) : cooldownTime.Value);
			nextExplosionTime = Time.time + num3;
		}

		private bool IsParentOfPlayer(Transform child)
		{
			Transform transform = ((Component)MonoSingleton<NewMovement>.Instance).transform;
			Transform parent = child.parent;
			while ((Object)(object)parent != (Object)null || (Object)(object)parent == (Object)(object)transform)
			{
				parent = parent.parent;
			}
			return (Object)(object)parent != (Object)null;
		}

		private IEnumerator LoadKaboom()
		{
			AsyncOperationHandle<GameObject> asyncOperationHandle = Addressables.LoadAssetAsync<GameObject>((object)explosionPath.Value);
			yield return (object)new WaitUntil((Func<bool>)(() => asyncOperationHandle.IsDone));
			Debug.Log((object)"got it");
			Kaboom = asyncOperationHandle.Result;
		}
	}
}