Decompiled source of Client Cannon Pull v1.0.0

ClientCannonPull.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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("ClientCannonPull")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ClientCannonPull")]
[assembly: AssemblyTitle("ClientCannonPull")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ClientCannonPull
{
	[BepInProcess("PEAK.exe")]
	[BepInPlugin("com.daedo.clientcannonpull", "Client Cannon Pull", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Id = "com.daedo.clientcannonpull";

		public const string Name = "Client Cannon Pull";

		public const string Version = "1.0.0";

		internal static ConfigEntry<bool> EnablePull;

		internal static ConfigEntry<bool> PullWhenUnclaimed;

		internal static ConfigEntry<bool> EnablePush;

		internal static ManualLogSource Log { get; private set; }

		internal static bool PullEnabled
		{
			get
			{
				if (EnablePull != null)
				{
					return EnablePull.Value;
				}
				return true;
			}
		}

		internal static bool UnclaimedPull
		{
			get
			{
				if (PullWhenUnclaimed != null)
				{
					return PullWhenUnclaimed.Value;
				}
				return true;
			}
		}

		internal static bool PushEnabled
		{
			get
			{
				if (EnablePush != null)
				{
					return EnablePush.Value;
				}
				return true;
			}
		}

		private void Awake()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			EnablePull = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnablePull", true, "Pull you into the Scout Cannon when you are not the host, using the same force the host gets in vanilla.");
			PullWhenUnclaimed = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PullWhenUnclaimed", true, "Pull you in as soon as you reach the cannon's mouth, even before the host has picked who is inside. Makes up for network delay.");
			EnablePush = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnablePush", true, "Push you out if someone else is already inside the cannon, just like vanilla does for the host.");
			try
			{
				new Harmony("com.daedo.clientcannonpull").PatchAll();
				Log.LogInfo((object)("Client Cannon Pull v1.0.0 loaded (pull: " + (PullEnabled ? "on" : "off") + ", pull when unclaimed: " + (UnclaimedPull ? "on" : "off") + ", push: " + (PushEnabled ? "on" : "off") + ")."));
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to apply patches: " + ex));
			}
		}
	}
	[HarmonyPatch(typeof(ScoutCannon), "FixedUpdate")]
	internal static class PullPatch
	{
		private static void Postfix(ScoutCannon __instance)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			if ((!Plugin.PullEnabled && !Plugin.PushEnabled) || PhotonNetwork.IsMasterClient)
			{
				return;
			}
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter == (Object)null || localCharacter.refs == null || (Object)(object)localCharacter.refs.ragdoll == (Object)null || (Object)(object)localCharacter.data == (Object)null)
			{
				return;
			}
			Transform entry = __instance.entry;
			Transform tube = __instance.tube;
			if ((Object)(object)entry == (Object)null || (Object)(object)tube == (Object)null)
			{
				return;
			}
			float num = 1f;
			if (Vector3.Distance(localCharacter.Center, entry.position) >= num)
			{
				return;
			}
			Character target = __instance.target;
			if ((Object)(object)target == (Object)(object)localCharacter || (Plugin.UnclaimedPull && (Object)(object)target == (Object)null))
			{
				if (Plugin.PullEnabled)
				{
					ApplyVanillaPull(__instance, localCharacter, entry, tube);
				}
			}
			else if (Plugin.PushEnabled && !((Object)(object)target == (Object)null))
			{
				RaycastHit val = HelperFunctions.LineCheck(tube.position, localCharacter.Center, (LayerType)3, 0f, (QueryTriggerInteraction)1);
				if ((Object)(object)((RaycastHit)(ref val)).transform == (Object)null)
				{
					Vector3 val2 = tube.position - localCharacter.Center;
					((Vector3)(ref val2)).Normalize();
					localCharacter.AddForce(-val2 * __instance.pushForce, 1f, 1f);
				}
			}
		}

		private static void ApplyVanillaPull(ScoutCannon cannon, Character character, Transform entry, Transform tube)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Invalid comparison between Unknown and I4
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Invalid comparison between Unknown and I4
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Invalid comparison between Unknown and I4
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Invalid comparison between Unknown and I4
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Invalid comparison between Unknown and I4
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Invalid comparison between Unknown and I4
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			if (character.data.sinceJump < 0.5f)
			{
				return;
			}
			List<Bodypart> partList = character.refs.ragdoll.partList;
			if (partList == null)
			{
				return;
			}
			foreach (Bodypart item in partList)
			{
				if ((Object)(object)item == (Object)null || (Object)(object)item.Rig == (Object)null)
				{
					continue;
				}
				BodypartType partType = item.partType;
				if ((int)partType == 7 || (int)partType == 10 || (int)partType == 6 || (int)partType == 9 || (int)partType == 5 || (int)partType == 8)
				{
					continue;
				}
				Vector3 val = item.transform.position - tube.position;
				val = Vector3.Project(val, tube.forward);
				Vector3 val2 = tube.position + val - item.transform.position;
				val2 = Vector3.ClampMagnitude(val2, 1f);
				item.Rig.AddForce(val2 * cannon.pullForce, (ForceMode)5);
				if (entry.InverseTransformPoint(item.transform.position).z < 0f)
				{
					RaycastHit val3 = HelperFunctions.LineCheck(entry.position, item.transform.position, (LayerType)3, 0f, (QueryTriggerInteraction)1);
					if (Object.op_Implicit((Object)(object)((RaycastHit)(ref val3)).transform))
					{
						item.Rig.AddForce(entry.forward * cannon.pullForce, (ForceMode)5);
					}
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}