Decompiled source of SpringManKamikaze v1.1.4

SpringManKamikaze.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RuntimeNetcodeRPCValidator;
using SpringManKamikaze.MonoBehaviours;
using SpringManKamikaze.Patches;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v7.0", FrameworkDisplayName = ".NET 7.0")]
[assembly: AssemblyCompany("SpringManKamikaze")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+48cda283b10aa5376c24dd775c93368807f26ac1")]
[assembly: AssemblyProduct("SpringManKamikaze")]
[assembly: AssemblyTitle("SpringManKamikaze")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : System.Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class NullableAttribute : System.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]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class NullableContextAttribute : System.Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class RefSafetyRulesAttribute : System.Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SpringManKamikaze
{
	[BepInPlugin("coolcat0.SpringManKamikaze", "SpringManKamikaze", "1.1.4")]
	[BepInDependency("NicholaScott.BepInEx.RuntimeNetcodeRPCValidator", "0.2.5")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "coolcat0.SpringManKamikaze";

		private const string modName = "SpringManKamikaze";

		private const string modVersion = "1.1.4";

		private readonly Harmony harmony = new Harmony("coolcat0.SpringManKamikaze");

		public static Plugin instance;

		public static ManualLogSource mls;

		private NetcodeValidator netcodeValidator;

		private void Awake()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			instance = this;
			netcodeValidator = new NetcodeValidator("coolcat0.SpringManKamikaze");
			netcodeValidator.PatchAll();
			netcodeValidator.BindToPreExistingObjectByBehaviour<SmkNetworkManager, Terminal>();
			harmony.PatchAll(typeof(EnemyAIPatch));
			harmony.PatchAll(typeof(SpringManAIPatch));
			mls = Logger.CreateLogSource("coolcat0.SpringManKamikaze");
			mls.LogInfo((object)"SpringManKamikaze version 1.1.4 has been loaded");
		}
	}
}
namespace SpringManKamikaze.Patches
{
	[HarmonyPatch(typeof(EnemyAI))]
	internal class EnemyAIPatch
	{
		[HarmonyPatch("HitEnemyOnLocalClient")]
		[HarmonyPostfix]
		private static void HitEnemyOnLocalClientPostfix(EnemyAI __instance)
		{
			SpringManAI val = (SpringManAI)(object)((__instance is SpringManAI) ? __instance : null);
			if (val != null && !((EnemyAI)val).isEnemyDead)
			{
				SpringManAIPatch.ExplodeSpringMan(val);
			}
		}
	}
	[HarmonyPatch(typeof(SpringManAI))]
	internal class SpringManAIPatch
	{
		[HarmonyPatch("OnCollideWithPlayer")]
		[HarmonyPrefix]
		private static bool OnCollideWithPlayerPrefix(SpringManAI __instance)
		{
			ExplodeSpringMan(__instance);
			return false;
		}

		public static void ExplodeSpringMan(SpringManAI springManAI)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)springManAI).KillEnemyServerRpc(true);
			((EnemyAI)springManAI).isEnemyDead = true;
			SerializableVector3 position = new SerializableVector3(((Component)springManAI).transform.position);
			SmkNetworkManager.instance.SpawnExplosionServerRpc(position);
		}
	}
}
namespace SpringManKamikaze.MonoBehaviours
{
	public class SmkNetworkManager : NetworkBehaviour
	{
		public static SmkNetworkManager instance;

		private void Awake()
		{
			instance = this;
		}

		[ServerRpc(RequireOwnership = false)]
		public void SpawnExplosionServerRpc(SerializableVector3 position)
		{
			SpawnExplosionClientRpc(position);
		}

		[ClientRpc]
		private void SpawnExplosionClientRpc(SerializableVector3 position)
		{
			//IL_0003: 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)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			SpawnExplosion(position.ToVector3() + Vector3.up);
		}

		public void SpawnExplosion(Vector3 explosionPosition, float damageRadius = 6f, float minDamage = 50f, float maxDamage = 100f)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			Plugin.mls.LogInfo((object)("Spawning explosion at position = " + ((object)(Vector3)(ref explosionPosition)).ToString()));
			Object.Instantiate<GameObject>(StartOfRound.Instance.explosionPrefab, explosionPosition, Quaternion.Euler(-90f, 0f, 0f), RoundManager.Instance.mapPropsContainer.transform).SetActive(true);
			float num = Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, explosionPosition);
			if (num < 14f)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			}
			else if (num < 25f)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
			}
			Collider[] array = Physics.OverlapSphere(explosionPosition, damageRadius, 2621448, (QueryTriggerInteraction)2);
			foreach (Collider val in array)
			{
				float num2 = Vector3.Distance(explosionPosition, ((Component)val).transform.position);
				if (num2 > 4f && Physics.Linecast(explosionPosition, ((Component)val).transform.position + Vector3.up * 0.3f, 256, (QueryTriggerInteraction)1))
				{
					continue;
				}
				if (((Component)val).gameObject.layer == 3)
				{
					PlayerControllerB component = ((Component)val).gameObject.GetComponent<PlayerControllerB>();
					if ((Object)(object)component != (Object)null && ((NetworkBehaviour)component).IsOwner)
					{
						float num3 = Mathf.Lerp(minDamage, maxDamage, num2 / damageRadius);
						component.DamagePlayer(Mathf.RoundToInt(num3), true, true, (CauseOfDeath)0, 0, false, default(Vector3));
					}
				}
				else if (((Component)val).gameObject.layer == 21)
				{
					Landmine componentInChildren = ((Component)val).gameObject.GetComponentInChildren<Landmine>();
					if ((Object)(object)componentInChildren != (Object)null && !componentInChildren.hasExploded && num2 < damageRadius)
					{
						Plugin.mls.LogInfo((object)"Setting off other mine");
						componentInChildren.ExplodeMineServerRpc();
					}
				}
				else if (((Component)val).gameObject.layer == 19)
				{
					EnemyAICollisionDetect componentInChildren2 = ((Component)val).gameObject.GetComponentInChildren<EnemyAICollisionDetect>();
					if ((Object)(object)componentInChildren2 != (Object)null && ((NetworkBehaviour)componentInChildren2.mainScript).IsOwner && num2 < damageRadius * 0.75f)
					{
						componentInChildren2.mainScript.HitEnemyOnLocalClient(6, default(Vector3), (PlayerControllerB)null, false);
					}
				}
			}
			int num4 = ~LayerMask.GetMask(new string[1] { "Colliders" });
			array = Physics.OverlapSphere(explosionPosition, 10f, num4);
			for (int j = 0; j < array.Length; j++)
			{
				Rigidbody component2 = ((Component)array[j]).GetComponent<Rigidbody>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.AddExplosionForce(70f, explosionPosition, 10f);
				}
			}
		}
	}
	[Serializable]
	public class SerializableVector3
	{
		public float x;

		public float y;

		public float z;

		public SerializableVector3(Vector3 vec3)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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)
			x = vec3.x;
			y = vec3.y;
			z = vec3.z;
		}

		public Vector3 ToVector3()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(x, y, z);
		}
	}
}