Decompiled source of MetalRecharging v1.0.0

MetalRecharging.dll

Decompiled a year ago
using System;
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 System.Threading.Tasks;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MetalRecharging")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allows you to charge metal objects")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MetalRecharging")]
[assembly: AssemblyTitle("MetalRecharging")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MetalRecharging
{
	[BepInPlugin("MetalRecharging", "MetalRecharging", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin MetalRecharging is loaded!");
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MetalRecharging";

		public const string PLUGIN_NAME = "MetalRecharging";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MetalRecharging.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class ChatPatch
	{
		private static bool _justExploded;

		private static SpawnableMapObject? _landmine;

		[HarmonyPatch("AddPlayerChatMessageServerRpc")]
		[HarmonyPatch("AddChatMessage")]
		[HarmonyPostfix]
		private static void OnServerMessageAdded(HUDManager __instance, ref string chatMessage)
		{
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			if (_justExploded || (Object)(object)((NetworkBehaviour)__instance).NetworkManager == (Object)null || !chatMessage.Contains("iexplode"))
			{
				return;
			}
			string[] array = chatMessage.Split('-');
			if (array.Length != 3)
			{
				return;
			}
			ulong playerId = ulong.Parse(array[1]);
			PlayerControllerB val = ((IEnumerable<PlayerControllerB>)__instance.playersManager.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB x) => x.playerClientId == playerId));
			if (_landmine == null)
			{
				_landmine = __instance.playersManager?.levels?.SelectMany((SelectableLevel x) => x.spawnableMapObjects).FirstOrDefault((Func<SpawnableMapObject, bool>)((SpawnableMapObject x) => ((Object)x.prefabToSpawn).name == "Landmine"));
			}
			if (!((Object)(object)val == (Object)null) && _landmine != null)
			{
				if (!((NetworkBehaviour)__instance).NetworkManager.IsHost && !((NetworkBehaviour)__instance).NetworkManager.IsServer)
				{
					LandminePatch.LastExplosionWasCharger = true;
					return;
				}
				LandminePatch.LastExplosionWasCharger = true;
				Debug.Log((object)"Explisuion time.");
				_justExploded = true;
				Vector3 val2 = ((Component)val).transform.position - new Vector3(0f, 0.25f, 0f);
				GameObject obj = Object.Instantiate<GameObject>(_landmine.prefabToSpawn, val2, Quaternion.identity, RoundManager.Instance.mapPropsContainer.transform);
				Landmine componentInChildren = obj.GetComponentInChildren<Landmine>();
				obj.GetComponent<NetworkObject>().Spawn(true);
				componentInChildren.ExplodeMineServerRpc();
				Unexplode();
			}
		}

		private static async Task Unexplode()
		{
			await Task.Delay(200);
			_justExploded = false;
		}

		public static void SendExplosionChat()
		{
			if (!((Object)(object)GameNetworkManager.Instance == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null))
			{
				int num = (int)GameNetworkManager.Instance.localPlayerController.playerClientId;
				HUDManager.Instance.AddTextToChatOnServer("<size=0>-" + num + "-iexplode</size>", num);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class InteractPerformedPatch
	{
		private static bool _swappingTwoHandedValue;

		[HarmonyPatch("Interact_performed")]
		[HarmonyPrefix]
		internal static void InteractPerformedPrefix(PlayerControllerB __instance)
		{
			if (!((Object)(object)__instance.hoveringOverTrigger == (Object)null) && __instance.twoHanded)
			{
				Transform parent = ((Component)__instance.hoveringOverTrigger).transform.parent;
				if (!((Object)(object)parent == (Object)null) && !(((Object)((Component)parent).gameObject).name != "ChargeStationTrigger"))
				{
					_swappingTwoHandedValue = true;
					__instance.twoHanded = false;
				}
			}
		}

		[HarmonyPatch("Interact_performed")]
		[HarmonyPostfix]
		internal static void InteractPerformedPostfix(PlayerControllerB __instance)
		{
			if (_swappingTwoHandedValue)
			{
				_swappingTwoHandedValue = false;
				__instance.twoHanded = true;
			}
		}
	}
	[HarmonyPatch(typeof(ItemCharger))]
	internal class ItemChargerPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static bool ItemChargerUpdate(ItemCharger __instance, ref float ___updateInterval, ref InteractTrigger ___triggerScript)
		{
			if ((Object)(object)NetworkManager.Singleton == (Object)null)
			{
				return false;
			}
			if (___updateInterval > 1f)
			{
				___updateInterval = 0f;
				if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
				{
					GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
					if ((Object)(object)currentlyHeldObjectServer == (Object)null || (!currentlyHeldObjectServer.itemProperties.isConductiveMetal && !currentlyHeldObjectServer.itemProperties.requiresBattery))
					{
						___triggerScript.interactable = false;
						___triggerScript.disabledHoverTip = "(Requires battery-powered or metal item)";
					}
					else
					{
						___triggerScript.interactable = true;
					}
					___triggerScript.twoHandedItemAllowed = true;
					return false;
				}
			}
			___updateInterval += Time.deltaTime;
			return false;
		}

		[HarmonyPatch("ChargeItem")]
		[HarmonyPostfix]
		private static void ItemChargerCharge(ItemCharger __instance)
		{
			GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
			if ((Object)(object)currentlyHeldObjectServer != (Object)null && !currentlyHeldObjectServer.itemProperties.requiresBattery && currentlyHeldObjectServer.itemProperties.isConductiveMetal)
			{
				LandminePatch.LastExplosionWasLocalPlayer = true;
				ChatPatch.SendExplosionChat();
			}
		}
	}
	[HarmonyPatch(typeof(Landmine))]
	internal class LandminePatch
	{
		public static bool LastExplosionWasLocalPlayer;

		public static bool LastExplosionWasCharger;

		[HarmonyPatch("SpawnExplosion")]
		[HarmonyPrefix]
		private static bool SpawnExplosion(Vector3 explosionPosition, bool spawnExplosionEffect = false, float killRange = 1f, float damageRange = 1f)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0076: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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)
			Debug.Log((object)"Spawning explosion");
			Debug.Log((object)"Charger:");
			Debug.Log((object)LastExplosionWasCharger);
			Debug.Log((object)LastExplosionWasLocalPlayer);
			if (!LastExplosionWasCharger)
			{
				return true;
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			Vector3 val = (((Component)localPlayerController.gameplayCamera).transform.position - explosionPosition) * 80f / Vector3.Distance(((Component)localPlayerController.gameplayCamera).transform.position, explosionPosition);
			if (LastExplosionWasLocalPlayer)
			{
				localPlayerController.KillPlayer(val, true, (CauseOfDeath)3, 0);
			}
			LastExplosionWasCharger = false;
			LastExplosionWasLocalPlayer = false;
			int num = ~LayerMask.GetMask(new string[1] { "Room" });
			num = ~LayerMask.GetMask(new string[1] { "Colliders" });
			Collider[] array = Physics.OverlapSphere(explosionPosition, 10f, num);
			for (int i = 0; i < array.Length; i++)
			{
				Rigidbody component = ((Component)array[i]).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					component.AddExplosionForce(70f, explosionPosition, 10f);
				}
			}
			return false;
		}
	}
}