Decompiled source of Loom Kidnapper v1.0.1

EmpressLoomEX.dll

Decompiled 16 hours 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.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EmpressLoomEX")]
[assembly: AssemblyTitle("EmpressLoomEX")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Empress.ShadowGrabber
{
	[BepInPlugin("Empress.ShadowGrabber", "Empress Shadow Grabber", "1.5.2")]
	public class ShadowGrabberPlugin : BaseUnityPlugin, IOnEventCallback
	{
		public const string PluginGuid = "Empress.ShadowGrabber";

		public const string PluginName = "Empress Shadow Grabber";

		public const string PluginVersion = "1.5.2";

		public static ShadowGrabberPlugin Instance;

		public static ManualLogSource Log;

		public const byte GrabEventCode = 85;

		public static HashSet<int> HeldPlayerIDs = new HashSet<int>();

		private bool callbacksRegistered;

		public static bool PhotonReady => PhotonNetwork.IsConnected && PhotonNetwork.InRoom && !SemiFunc.RunIsLobby() && !SemiFunc.RunIsLobbyMenu() && !SemiFunc.IsMainMenu() && !SemiFunc.IsSplashScreen();

		private void Awake()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony val = new Harmony("Empress.ShadowGrabber");
			val.PatchAll();
			Log.LogInfo((object)"[ShadowGrabber] Loaded");
		}

		private void Update()
		{
			if (!callbacksRegistered && PhotonReady)
			{
				PhotonNetwork.AddCallbackTarget((object)this);
				callbacksRegistered = true;
				Log.LogInfo((object)"[ShadowGrabber] Photon callbacks registered");
			}
			if (callbacksRegistered && !PhotonReady)
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
				callbacksRegistered = false;
				HeldPlayerIDs.Clear();
				Log.LogInfo((object)"[ShadowGrabber] Photon callbacks unregistered");
			}
		}

		public void OnEvent(EventData photonEvent)
		{
			if (PhotonReady && photonEvent.Code == 85 && photonEvent.CustomData is object[] array && array.Length >= 3)
			{
				int shadowID = (int)array[0];
				int playerID = (int)array[1];
				bool isGrabbing = (bool)array[2];
				HandleGrabEvent(shadowID, playerID, isGrabbing);
			}
		}

		private void HandleGrabEvent(int shadowID, int playerID, bool isGrabbing)
		{
			PhotonView val = PhotonView.Find(shadowID);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			ShadowGrabberController component = ((Component)val).GetComponent<ShadowGrabberController>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			if (isGrabbing)
			{
				PhotonView val2 = PhotonView.Find(playerID);
				if (!((Object)(object)val2 == (Object)null))
				{
					PlayerAvatar component2 = ((Component)val2).GetComponent<PlayerAvatar>();
					if (!((Object)(object)component2 == (Object)null))
					{
						component.GrabPlayer(component2, syncToOthers: false);
					}
				}
			}
			else
			{
				component.ReleasePlayer(syncToOthers: false);
			}
		}
	}
	public class ShadowGrabberController : MonoBehaviour
	{
		public EnemyShadow shadow;

		public PlayerAvatar heldPlayer;

		public bool isHolding;

		private void Awake()
		{
			shadow = ((Component)this).GetComponent<EnemyShadow>();
		}

		private void Start()
		{
			if (SemiFunc.RunIsLobby() || SemiFunc.RunIsLobbyMenu() || SemiFunc.IsMainMenu() || SemiFunc.IsSplashScreen())
			{
				Object.Destroy((Object)(object)this);
			}
		}

		private void Update()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Invalid comparison between Unknown and I4
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Invalid comparison between Unknown and I4
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Invalid comparison between Unknown and I4
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Invalid comparison between Unknown and I4
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			if (ShadowGrabberPlugin.PhotonReady && SemiFunc.IsMasterClientOrSingleplayer() && isHolding)
			{
				if ((Object)(object)heldPlayer == (Object)null || heldPlayer.isDisabled || heldPlayer.deadSet)
				{
					ReleasePlayer();
				}
				else if ((int)shadow.currentState == 2 || (int)shadow.currentState == 4)
				{
					ReleasePlayer();
				}
				else if ((int)shadow.currentState != 3 && (int)shadow.currentState != 8)
				{
					shadow.currentState = (State)3;
				}
			}
		}

		private void FixedUpdate()
		{
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: 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_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: 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)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			if (ShadowGrabberPlugin.PhotonReady && isHolding && (Object)(object)heldPlayer != (Object)null && !heldPlayer.isDisabled && (Object)(object)heldPlayer.tumble != (Object)null)
			{
				if (!heldPlayer.tumble.isTumbling)
				{
					heldPlayer.tumble.TumbleRequest(true, false);
				}
				heldPlayer.tumble.TumbleOverrideTime(1f);
				heldPlayer.FallDamageResetSet(0.1f);
				heldPlayer.tumble.physGrabObject.OverrideMass(1f, 0.1f);
				heldPlayer.tumble.physGrabObject.OverrideAngularDrag(2f, 0.1f);
				heldPlayer.tumble.physGrabObject.OverrideDrag(1f, 0.1f);
				heldPlayer.tumble.OverrideEnemyHurt(0.1f);
				Vector3 val = ((Component)shadow).transform.position + ((Component)shadow).transform.forward * 1.2f + Vector3.up * 1.5f;
				Quaternion val2 = ((Component)shadow).transform.rotation * Quaternion.Euler(0f, 0f, 180f);
				float num = 1f;
				if (heldPlayer.tumble.physGrabObject.playerGrabbing.Count > 0)
				{
					num = 0.5f;
				}
				Vector3 val3 = SemiFunc.PhysFollowPosition(((Component)heldPlayer.tumble).transform.position, val, heldPlayer.tumble.rb.velocity, 10f * num);
				heldPlayer.tumble.rb.AddForce(val3 * (10f * Time.fixedDeltaTime * num), (ForceMode)1);
				Vector3 val4 = SemiFunc.PhysFollowRotation(((Component)heldPlayer.tumble).transform, val2, heldPlayer.tumble.rb, 0.2f * num);
				heldPlayer.tumble.rb.AddTorque(val4 * (1f * Time.fixedDeltaTime * num), (ForceMode)1);
			}
		}

		private void LateUpdate()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//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_00b9: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
			if (!ShadowGrabberPlugin.PhotonReady || !isHolding || (Object)(object)heldPlayer == (Object)null)
			{
				return;
			}
			Vector3 val = ((Component)shadow).transform.position + ((Component)shadow).transform.forward * 1.2f + Vector3.up * 1.5f;
			Vector3 val2 = val + ((Component)shadow).transform.right * 0.25f;
			Vector3 val3 = val - ((Component)shadow).transform.right * 0.25f;
			if ((Object)(object)shadow.rightWristPivot != (Object)null)
			{
				shadow.rightWristPivot.position = val2;
				shadow.rightWristPivot.rotation = ((Component)shadow).transform.rotation * Quaternion.Euler(0f, 0f, 90f);
				shadow.rightWristPivot.localScale = Vector3.one;
				BotSystemSpringPoseAnimator springPoseAnimator = shadow.springPoseAnimator;
				if (springPoseAnimator != null)
				{
					springPoseAnimator.StretchLimbToPoint("Right Arm", val2);
				}
			}
			if ((Object)(object)shadow.leftWristPivot != (Object)null)
			{
				shadow.leftWristPivot.position = val3;
				shadow.leftWristPivot.rotation = ((Component)shadow).transform.rotation * Quaternion.Euler(0f, 0f, -90f);
				shadow.leftWristPivot.localScale = Vector3.one;
				BotSystemSpringPoseAnimator springPoseAnimator2 = shadow.springPoseAnimator;
				if (springPoseAnimator2 != null)
				{
					springPoseAnimator2.StretchLimbToPoint("Left Arm", val3);
				}
			}
		}

		public void GrabPlayer(PlayerAvatar player, bool syncToOthers = true)
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_0119: Expected O, but got Unknown
			if (ShadowGrabberPlugin.PhotonReady && !((Object)(object)player == (Object)null))
			{
				if (isHolding)
				{
					ReleasePlayer(syncToOthers);
				}
				heldPlayer = player;
				isHolding = true;
				if ((Object)(object)player.photonView != (Object)null)
				{
					ShadowGrabberPlugin.HeldPlayerIDs.Add(player.photonView.ViewID);
				}
				if ((Object)(object)heldPlayer.tumble != (Object)null)
				{
					heldPlayer.tumble.TumbleRequest(true, false);
				}
				if (syncToOthers && SemiFunc.IsMasterClientOrSingleplayer() && (Object)(object)shadow.photonView != (Object)null && (Object)(object)player.photonView != (Object)null)
				{
					PhotonNetwork.RaiseEvent((byte)85, (object)new object[3]
					{
						shadow.photonView.ViewID,
						player.photonView.ViewID,
						true
					}, new RaiseEventOptions
					{
						Receivers = (ReceiverGroup)0
					}, SendOptions.SendReliable);
				}
			}
		}

		public void ReleasePlayer(bool syncToOthers = true)
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_00fc: Expected O, but got Unknown
			if (!ShadowGrabberPlugin.PhotonReady)
			{
				return;
			}
			if ((Object)(object)heldPlayer != (Object)null)
			{
				if ((Object)(object)heldPlayer.photonView != (Object)null)
				{
					ShadowGrabberPlugin.HeldPlayerIDs.Remove(heldPlayer.photonView.ViewID);
				}
				PlayerTumble tumble = heldPlayer.tumble;
				if (tumble != null)
				{
					tumble.TumbleRequest(false, false);
				}
				if (syncToOthers && SemiFunc.IsMasterClientOrSingleplayer() && (Object)(object)shadow.photonView != (Object)null && (Object)(object)heldPlayer.photonView != (Object)null)
				{
					PhotonNetwork.RaiseEvent((byte)85, (object)new object[3]
					{
						shadow.photonView.ViewID,
						heldPlayer.photonView.ViewID,
						false
					}, new RaiseEventOptions
					{
						Receivers = (ReceiverGroup)0
					}, SendOptions.SendReliable);
				}
			}
			heldPlayer = null;
			isHolding = false;
		}

		private void OnDestroy()
		{
			ReleasePlayer(syncToOthers: false);
		}
	}
	[HarmonyPatch(typeof(EnemyShadow))]
	public static class EnemyShadowPatches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void AwakePatch(EnemyShadow __instance)
		{
			if (!SemiFunc.RunIsLobby() && !SemiFunc.RunIsLobbyMenu() && !SemiFunc.IsMainMenu() && !SemiFunc.IsSplashScreen() && (Object)(object)((Component)__instance).GetComponent<ShadowGrabberController>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<ShadowGrabberController>();
			}
		}

		[HarmonyPatch("HandLogic")]
		[HarmonyPrefix]
		public static bool HandLogicPatch(EnemyShadow __instance)
		{
			if (!ShadowGrabberPlugin.PhotonReady)
			{
				return true;
			}
			ShadowGrabberController component = ((Component)__instance).GetComponent<ShadowGrabberController>();
			return (Object)(object)component == (Object)null || !component.isHolding;
		}

		[HarmonyPatch("Slap")]
		[HarmonyPrefix]
		public static bool SlapPatch(EnemyShadow __instance)
		{
			if (!ShadowGrabberPlugin.PhotonReady)
			{
				return true;
			}
			ShadowGrabberController component = ((Component)__instance).GetComponent<ShadowGrabberController>();
			return (Object)(object)component == (Object)null || !component.isHolding;
		}

		[HarmonyPatch("EnableHurtCollider")]
		[HarmonyPrefix]
		public static bool EnableHurtColliderPatch(EnemyShadow __instance, Vector3 _pos)
		{
			//IL_0092: 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)
			if (!ShadowGrabberPlugin.PhotonReady)
			{
				return true;
			}
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				return true;
			}
			ShadowGrabberController component = ((Component)__instance).GetComponent<ShadowGrabberController>();
			if ((Object)(object)component == (Object)null || component.isHolding)
			{
				return false;
			}
			object? obj = AccessTools.Field(typeof(EnemyShadow), "playerTarget")?.GetValue(__instance);
			PlayerAvatar val = (PlayerAvatar)((obj is PlayerAvatar) ? obj : null);
			if ((Object)(object)val != (Object)null && !val.isDisabled && !val.deadSet && Vector3.Distance(((Component)__instance).transform.position, ((Component)val).transform.position) < 4.5f)
			{
				component.GrabPlayer(val);
				return false;
			}
			return true;
		}

		[HarmonyPatch("OnDeath")]
		[HarmonyPrefix]
		public static void OnDeathPatch(EnemyShadow __instance)
		{
			if (ShadowGrabberPlugin.PhotonReady && SemiFunc.IsMasterClientOrSingleplayer())
			{
				((Component)__instance).GetComponent<ShadowGrabberController>()?.ReleasePlayer();
			}
		}
	}
}