Decompiled source of RescueClawItemPull v1.0.1

RescueClawItemPull.dll

Decompiled 2 weeks 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.UI;

[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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BackpackMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BackpackMod")]
[assembly: AssemblyTitle("BackpackMod")]
[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 RescueClawExpanded
{
	[BepInPlugin("com.gedisu.rescueclawitempull", "Rescue Claw item pull", "1.0.1")]
	public class RescueClawExpanded : BaseUnityPlugin
	{
		private const string HarmonyId = "RescueClawExpanded.Harmony";

		private static Harmony _harmony;

		private void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			_harmony = new Harmony("RescueClawExpanded.Harmony");
			AcceptableValueRange<int> val = new AcceptableValueRange<int>(0, 255);
			ConfigEntry<int> configR = ((BaseUnityPlugin)this).Config.Bind<int>("Visuals", "ReticleItemColorR", 51, new ConfigDescription("Red channel (0-255) of the reticle color when pointing at a grabbable item.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			ConfigEntry<int> configG = ((BaseUnityPlugin)this).Config.Bind<int>("Visuals", "ReticleItemColorG", 255, new ConfigDescription("Green channel (0-255) of the reticle color when pointing at a grabbable item.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			ConfigEntry<int> configB = ((BaseUnityPlugin)this).Config.Bind<int>("Visuals", "ReticleItemColorB", 51, new ConfigDescription("Blue channel (0-255) of the reticle color when pointing at a grabbable item.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			ApplyColor();
			configR.SettingChanged += delegate
			{
				ApplyColor();
			};
			configG.SettingChanged += delegate
			{
				ApplyColor();
			};
			configB.SettingChanged += delegate
			{
				ApplyColor();
			};
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"RescueClawExpanded initialized");
			void ApplyColor()
			{
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				RescueClawShared.reticleColorItem = new Color((float)configR.Value / 255f, (float)configG.Value / 255f, (float)configB.Value / 255f);
			}
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.gedisu.rescueclawitempull";

		public const string PLUGIN_NAME = "Rescue Claw item pull";

		public const string PLUGIN_VERSION = "1.0.1";
	}
	[HarmonyPatch(typeof(RescueHook), "GetHit")]
	internal static class FixRescueClawHighlightOcclusion
	{
		private static void Postfix(RescueHook __instance, RaycastHit __result)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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)
			bool flag = false;
			bool pointingAtItem = false;
			Character val = default(Character);
			if ((Object)(object)((RaycastHit)(ref __result)).rigidbody != (Object)null && CharacterRagdoll.TryGetCharacterFromCollider(((RaycastHit)(ref __result)).collider, ref val) && (Object)(object)val != (Object)(object)((ItemComponent)__instance).item.holderCharacter)
			{
				flag = true;
			}
			if (!flag)
			{
				float curRange = __instance.curRange;
				Ray val2 = (Ray)RescueClawShared.m_getMiddleScreenRay.Invoke(__instance, null);
				RaycastHit[] array = Physics.RaycastAll(val2, curRange, -1);
				Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
				RaycastHit[] array2 = array;
				for (int num = 0; num < array2.Length; num++)
				{
					RaycastHit val3 = array2[num];
					if ((Object)(object)((RaycastHit)(ref __result)).transform != (Object)null && ((RaycastHit)(ref val3)).distance >= ((RaycastHit)(ref __result)).distance)
					{
						break;
					}
					if (!((Object)(object)((RaycastHit)(ref val3)).rigidbody == (Object)null))
					{
						Item component = ((Component)((RaycastHit)(ref val3)).rigidbody).GetComponent<Item>();
						if (!((Object)(object)component == (Object)null) && !((Object)(object)component.holderCharacter != (Object)null))
						{
							pointingAtItem = true;
							break;
						}
					}
				}
			}
			((ItemComponent)__instance).item.raycastingCharacter = flag;
			RescueClawShared.pointingAtItem = pointingAtItem;
		}
	}
	public static class RescueClawShared
	{
		public class ItemPullState
		{
			public Rigidbody targetBody;

			public PhotonView targetView;

			public bool active;

			public bool isKinematicGrab;
		}

		public static readonly FieldInfo f_isPulling = AccessTools.Field(typeof(RescueHook), "isPulling");

		public static readonly FieldInfo f_sinceFire = AccessTools.Field(typeof(RescueHook), "sinceFire");

		public static readonly FieldInfo f_currentDistance = AccessTools.Field(typeof(RescueHook), "currentDistance");

		public static readonly FieldInfo f_dragPoint = AccessTools.Field(typeof(RescueHook), "dragPoint");

		public static readonly FieldInfo f_stopPullDistance = AccessTools.Field(typeof(RescueHook), "stopPullDistance");

		public static readonly FieldInfo f_maxWallHookTime = AccessTools.Field(typeof(RescueHook), "maxWallHookTime");

		public static readonly FieldInfo f_pullCurve = AccessTools.Field(typeof(RescueHook), "pulLStrengthCurve");

		public static readonly FieldInfo f_targetPlayer = AccessTools.Field(typeof(RescueHook), "targetPlayer");

		public static readonly FieldInfo f_somethingBroke = AccessTools.Field(typeof(RescueHook), "SOMETHING_BROKE");

		public static readonly MethodInfo m_getHit = AccessTools.Method(typeof(RescueHook), "GetHit", (Type[])null, (Type[])null);

		public static readonly MethodInfo m_getMiddleScreenRay = AccessTools.Method(typeof(RescueHook), "GetMiddleScreenRay", (Type[])null, (Type[])null);

		public static readonly FieldInfo f_targetPos = AccessTools.Field(typeof(RescueHook), "targetPos");

		public static bool pointingAtItem;

		public static Color reticleColorItem = Color.hotPink;

		public static readonly ConditionalWeakTable<RescueHook, ItemPullState> states = new ConditionalWeakTable<RescueHook, ItemPullState>();

		public const float pullForce = 320f;

		public const float liftForce = 100f;

		public static ItemPullState GetState(RescueHook hook)
		{
			return states.GetOrCreateValue(hook);
		}
	}
	[HarmonyPatch(typeof(GUIManager), "UpdateReticle")]
	internal static class RescueClawReticleColorPatch
	{
		private static void Postfix(GUIManager __instance)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Character localCharacter = Character.localCharacter;
			Item val = ((localCharacter != null) ? localCharacter.data.currentItem : null);
			if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).GetComponent<RescueHook>() == (Object)null) && RescueClawShared.pointingAtItem)
			{
				((Graphic)__instance.reticleShootImage).color = RescueClawShared.reticleColorItem;
			}
		}
	}
	[HarmonyPatch(typeof(RescueHook), "Fire")]
	internal static class RescueClawFirePatch
	{
		private static readonly FieldInfo f_curRange = AccessTools.Field(typeof(RescueHook), "curRange");

		private static bool Prefix(RescueHook __instance)
		{
			//IL_0009: 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)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			object[] parameters = new object[1] { Vector3.zero };
			RaycastHit val = (RaycastHit)RescueClawShared.m_getHit.Invoke(__instance, parameters);
			if ((bool)RescueClawShared.f_somethingBroke.GetValue(__instance))
			{
				return false;
			}
			if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).transform))
			{
				return true;
			}
			float num = (float)f_curRange.GetValue(__instance);
			Ray val2 = (Ray)AccessTools.Method(typeof(RescueHook), "GetMiddleScreenRay", (Type[])null, (Type[])null).Invoke(__instance, null);
			RaycastHit[] array = Physics.RaycastAll(val2, num, -1);
			Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
			RaycastHit[] array2 = array;
			for (int num2 = 0; num2 < array2.Length; num2++)
			{
				RaycastHit val3 = array2[num2];
				if (((RaycastHit)(ref val3)).distance >= ((RaycastHit)(ref val)).distance)
				{
					break;
				}
				if ((Object)(object)((RaycastHit)(ref val3)).rigidbody == (Object)null)
				{
					continue;
				}
				Item component = ((Component)((RaycastHit)(ref val3)).rigidbody).GetComponent<Item>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.holderCharacter != (Object)null))
				{
					PhotonView component2 = ((Component)component).GetComponent<PhotonView>();
					if (!((Object)(object)component2 == (Object)null))
					{
						((MonoBehaviourPun)__instance).photonView.RPC("RPCA_RescueItem", (RpcTarget)0, new object[1] { component2 });
						return false;
					}
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(RescueHook), "RPCA_RescueItem")]
	internal static class RescueClawRpcPatch
	{
		private static void Postfix(RescueHook __instance, PhotonView objectView)
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)objectView == (Object)null)
			{
				return;
			}
			Rigidbody component = ((Component)objectView).GetComponent<Rigidbody>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			if (component.isKinematic)
			{
				RescueClawShared.ItemPullState state = RescueClawShared.GetState(__instance);
				if (!state.active)
				{
					state.targetBody = component;
					state.targetView = objectView;
					state.active = true;
					state.isKinematicGrab = true;
					RescueClawShared.f_isPulling.SetValue(__instance, true);
					RescueClawShared.f_sinceFire.SetValue(__instance, 0f);
					RescueClawShared.f_targetPlayer.SetValue(__instance, null);
					RescueClawShared.f_targetPos.SetValue(__instance, component.position);
				}
				return;
			}
			RescueClawShared.ItemPullState state2 = RescueClawShared.GetState(__instance);
			if (!state2.active)
			{
				state2.targetBody = component;
				state2.targetView = objectView;
				state2.active = true;
				if (((MonoBehaviourPun)__instance).photonView.IsMine && !objectView.IsMine)
				{
					objectView.TransferOwnership(PhotonNetwork.LocalPlayer);
				}
				RescueClawShared.f_isPulling.SetValue(__instance, true);
				RescueClawShared.f_sinceFire.SetValue(__instance, 0f);
				RescueClawShared.f_targetPlayer.SetValue(__instance, null);
				RescueClawShared.f_targetPos.SetValue(__instance, component.position);
			}
		}
	}
	[HarmonyPatch(typeof(RescueHook), "FixedUpdate")]
	internal static class RescueClawFixedUpdatePatch
	{
		private static bool Prefix(RescueHook __instance)
		{
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Expected O, but got Unknown
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: 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)
			//IL_01df: 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_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Expected O, but got Unknown
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: 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_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			RescueClawShared.ItemPullState state = RescueClawShared.GetState(__instance);
			if (!state.active)
			{
				return true;
			}
			if (!(bool)RescueClawShared.f_isPulling.GetValue(__instance))
			{
				state.active = false;
				return true;
			}
			float num = (float)RescueClawShared.f_sinceFire.GetValue(__instance) + Time.fixedDeltaTime;
			RescueClawShared.f_sinceFire.SetValue(__instance, num);
			if ((Object)(object)state.targetBody == (Object)null)
			{
				state.active = false;
				state.isKinematicGrab = false;
				return false;
			}
			if (state.isKinematicGrab)
			{
				if (num > 0.7f && ((MonoBehaviourPun)__instance).photonView.IsMine)
				{
					Item component = ((Component)state.targetView).GetComponent<Item>();
					Character holderCharacter = ((ItemComponent)__instance).item.holderCharacter;
					if ((Object)(object)component != (Object)null && (Object)(object)holderCharacter != (Object)null)
					{
						Action_ReduceUses component2 = ((Component)__instance).GetComponent<Action_ReduceUses>();
						if ((Object)(object)component2 != (Object)null)
						{
							((ItemActionBase)component2).RunAction();
						}
						component.Interact(holderCharacter);
					}
					state.active = false;
					state.isKinematicGrab = false;
					((MonoBehaviourPun)__instance).photonView.RPC("RPCA_LetGo", (RpcTarget)0, Array.Empty<object>());
				}
				return false;
			}
			if (state.targetBody.isKinematic)
			{
				state.active = false;
				return false;
			}
			RescueClawShared.f_targetPos.SetValue(__instance, state.targetBody.position);
			if (num > 0.25f && (Object)(object)state.targetView != (Object)null && state.targetView.IsMine)
			{
				Character holderCharacter2 = ((ItemComponent)__instance).item.holderCharacter;
				Vector3 val = (((Object)(object)holderCharacter2 != (Object)null) ? holderCharacter2.Center : ((Component)__instance).transform.position);
				val += Vector3.down * 0.5f;
				RaycastHit val2 = default(RaycastHit);
				if (Physics.Raycast(val + Vector3.up * 0.5f, Vector3.down, ref val2, 2f, LayerMask.op_Implicit(HelperFunctions.GetMask((LayerType)7))))
				{
					val = ((RaycastHit)(ref val2)).point + Vector3.up * 0.1f;
				}
				Vector3 val3 = ((Component)__instance).transform.position - state.targetBody.position;
				float magnitude = ((Vector3)(ref val3)).magnitude;
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				AnimationCurve val4 = (AnimationCurve)RescueClawShared.f_pullCurve.GetValue(__instance);
				float num2 = ((val4 != null) ? val4.Evaluate(magnitude) : 1f);
				state.targetBody.linearVelocity = normalized * 65f * num2;
			}
			Transform val5 = (Transform)RescueClawShared.f_dragPoint.GetValue(__instance);
			float num3 = (float)RescueClawShared.f_stopPullDistance.GetValue(__instance);
			float num4 = (float)RescueClawShared.f_maxWallHookTime.GetValue(__instance);
			float num5 = Vector3.Distance(val5.position, state.targetBody.position);
			RescueClawShared.f_currentDistance.SetValue(__instance, num5);
			if ((num5 < num3 || num > num4) && ((MonoBehaviourPun)__instance).photonView.IsMine)
			{
				state.active = false;
				RescueClawShared.f_isPulling.SetValue(__instance, false);
				state.targetBody.linearVelocity = Vector3.zero;
				state.targetBody.useGravity = true;
				((MonoBehaviourPun)__instance).photonView.RPC("RPCA_LetGo", (RpcTarget)0, Array.Empty<object>());
			}
			return false;
		}
	}
}