Decompiled source of FriendlyFired v1.0.0

FriendlyFired.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BoplFixedMath;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("FriendlyFired")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FriendlyFired")]
[assembly: AssemblyTitle("FriendlyFired")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FriendlyFired
{
	[BepInPlugin("com.maxgamertyper1.friendlyfired", "Friendly Fired", "1.0.0")]
	public class FriendlyFirePlugin : BaseUnityPlugin
	{
		internal static ConfigFile config;

		internal static ConfigEntry<bool> MissilePatch;

		internal static ConfigEntry<bool> ArrowPatch;

		internal static ConfigEntry<bool> TeslaPatch;

		internal static ConfigEntry<bool> BlachHolePatch;

		internal static ConfigEntry<bool> SpikePatch;

		internal static ConfigEntry<bool> ExplosionPatch;

		private void Log(string message)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)message);
		}

		private void Awake()
		{
			Log("Plugin FriendlyFired is loaded!");
			DoPatching();
		}

		private void DoPatching()
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Expected O, but got Unknown
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Expected O, but got Unknown
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Expected O, but got Unknown
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Expected O, but got Unknown
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Expected O, but got Unknown
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Expected O, but got Unknown
			config = ((BaseUnityPlugin)this).Config;
			MissilePatch = config.Bind<bool>("Explosion Patches", "Missile Patch", true, "Make it so your Missile explosions wont kill you");
			ExplosionPatch = config.Bind<bool>("Explosion Patches", "Explosion Patch", true, "Make it so your: [Grenade, Smoke Grenade, Mine] explosions wont kill you");
			TeslaPatch = config.Bind<bool>("Physical Patches", "Tesla Coil Patch", true, "Make it so your Tesla Coil wont kill you");
			SpikePatch = config.Bind<bool>("Physical Patches", "Spike Patch", true, "Make it so your Spike wont kill you");
			ArrowPatch = config.Bind<bool>("Other Patches", "Arrow Patch", true, "Make it so your Arrows wont kill you");
			BlachHolePatch = config.Bind<bool>("Other Patches", "Black Hole Patch", true, "Make it so your Black Holes wont kill you or apply gravity to you");
			Harmony val = new Harmony("com.maxgamertyper1.tethered");
			if (MissilePatch.Value)
			{
				val.Patch((MethodBase)AccessTools.Method(typeof(Missile), "OnCollide", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "MissileKillPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (ExplosionPatch.Value)
			{
				val.Patch((MethodBase)AccessTools.Method(typeof(Explosion), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Patches), "OwnerExplosionPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (TeslaPatch.Value)
			{
				val.Patch((MethodBase)AccessTools.Method(typeof(StretchableLightning), "InitLightning", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Patches), "TeslaCoilPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				val.Patch((MethodBase)AccessTools.Method(typeof(PlaceSparkNode), "Place", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "TeslaHeadPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (SpikePatch.Value)
			{
				val.Patch((MethodBase)AccessTools.Method(typeof(Spike), "CastSpike", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "SpikeKillPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (ArrowPatch.Value)
			{
				val.Patch((MethodBase)AccessTools.Method(typeof(BowTransform), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Patches), "ArrowFirePatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			if (BlachHolePatch.Value)
			{
				val.Patch((MethodBase)AccessTools.Method(typeof(BlackHole), "OnCollide", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Patches), "BlackHoleKillPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				val.Patch((MethodBase)AccessTools.Method(typeof(BlackHole), "GravityForce", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "BlackHoleGravityPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private void OnDestroy()
		{
			Log("Bye Bye From FriendlyFired");
		}
	}
	public class Patches
	{
		public static bool ArrowFirePatch(ref BowTransform __instance)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Traverse.Create((object)__instance).Field("TimeBeforeArrowsHurtOwner").SetValue((object)(Fix)10000L);
			return true;
		}

		public static bool OwnerExplosionPatch(ref Explosion __instance)
		{
			__instance.canHurtOwner = false;
			return true;
		}

		public static void TeslaCoilPatch(ref StretchableLightning __instance, ref int id)
		{
			Transform parent = ((Component)__instance).transform.parent;
			if (!((Object)(object)parent == (Object)null))
			{
				Explosion component = ((Component)parent).GetComponent<Explosion>();
				component.canHurtOwner = false;
				component.PlayerOwnerId = id;
			}
		}

		public static void TeslaHeadPatch(ref PlaceSparkNode __instance, ref GameObject __result, ref int playerId)
		{
			Explosion component = __result.GetComponent<Explosion>();
			component.PlayerOwnerId = playerId;
			component.canHurtOwner = false;
		}

		public static void BlackHoleGravityPatch(ref BlackHole __instance, ref Fix __result, ref FixTransform fixTrans)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)fixTrans == (Object)null)
			{
				return;
			}
			Transform parent = ((Component)fixTrans).transform.parent;
			if ((Object)(object)parent == (Object)null)
			{
				return;
			}
			int num = (int)Traverse.Create((object)__instance).Field("ownerId").GetValue();
			Player player = PlayerHandler.Get().GetPlayer(num);
			if (((Object)fixTrans).name == "Player(Clone)")
			{
				PlayerPhysics component = ((Component)fixTrans).GetComponent<PlayerPhysics>();
				object value = Traverse.Create((object)component).Field("playerIdHolder").GetValue();
				IPlayerIdHolder val = (IPlayerIdHolder)((value is IPlayerIdHolder) ? value : null);
				int playerId = val.GetPlayerId();
				if (playerId == num)
				{
					__result = (Fix)0L;
				}
			}
			if (((Object)parent).name == "Player")
			{
				PlayerPhysics component2 = ((Component)parent).GetComponent<PlayerPhysics>();
				object value2 = Traverse.Create((object)component2).Field("playerIdHolder").GetValue();
				IPlayerIdHolder val2 = (IPlayerIdHolder)((value2 is IPlayerIdHolder) ? value2 : null);
				int playerId2 = val2.GetPlayerId();
				if (playerId2 == num)
				{
					__result = (Fix)0L;
				}
			}
		}

		public static bool BlackHoleKillPatch(ref BlackHole __instance, ref CollisionInformation collision)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			int num = (int)Traverse.Create((object)__instance).Field("playerLayer").GetValue();
			if (collision.layer == num)
			{
				PlayerCollision component = ((Component)collision.colliderPP.fixTrans).gameObject.GetComponent<PlayerCollision>();
				if ((Object)(object)component != (Object)null)
				{
					IPlayerIdHolder val = (IPlayerIdHolder)Traverse.Create((object)component).Field("playerIdHolder").GetValue();
					if (val == null)
					{
						return true;
					}
					int playerId = val.GetPlayerId();
					if (playerId == __instance.OwnerId)
					{
						return false;
					}
				}
			}
			return true;
		}

		public static void SpikeKillPatch(ref Spike __instance)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			PlayerInfo val = (PlayerInfo)Traverse.Create((object)__instance).Field("playerInfo").GetValue();
			int playerId = val.playerId;
			SpikeAttack val2 = (SpikeAttack)Traverse.Create((object)__instance).Field("currentSpike").GetValue();
			Explosion component = ((Component)val2).GetComponent<Explosion>();
			component.PlayerOwnerId = playerId;
			component.canHurtOwner = false;
		}

		public static void MissileKillPatch(ref Missile __instance)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			Item val = (Item)Traverse.Create((object)__instance).Field("item").GetValue();
			int ownerId = val.OwnerId;
			Explosion[] array = Object.FindObjectsOfType<Explosion>();
			if (array == null)
			{
				return;
			}
			BoplBody val2 = (BoplBody)Traverse.Create((object)__instance).Field("body").GetValue();
			Vec2 position = val2.position;
			Explosion[] array2 = array;
			foreach (Explosion val3 in array2)
			{
				if (!((Object)(object)val3 == (Object)null) && ((Component)val3).GetComponent<FixTransform>().position == position)
				{
					Explosion component = ((Component)val3).GetComponent<Explosion>();
					component.PlayerOwnerId = ownerId;
					component.canHurtOwner = false;
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FriendlyFired";

		public const string PLUGIN_NAME = "FriendlyFired";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}