Decompiled source of CrouchGrabHeal v1.0.1

CrouchGrabHeal.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Photon.Pun;
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("CrouchGrabHeal")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d099211c28f215ee922bb73bf72ec1c32c55789f")]
[assembly: AssemblyProduct("CrouchGrabHeal")]
[assembly: AssemblyTitle("CrouchGrabHeal")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomHealthTransfer;

[BepInPlugin("SharkLucas.REPO.CrouchGrabHeal", "R.E.P.O. Crouch Grab Heal", "1.0.0")]
public class CrouchGrabHealPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(PlayerHealthGrab), "Update")]
	public class PlayerHealthGrabUpdatePatch
	{
		private static bool Prefix(PlayerHealthGrab __instance, ref float ___grabbingTimer)
		{
			//IL_00ab: 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_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsMasterClient)
			{
				return true;
			}
			if (isTumblingRef.Invoke(__instance.playerAvatar) || SemiFunc.RunIsShop() || SemiFunc.RunIsArena())
			{
				if (hideLerpRef.Invoke(__instance) < 1f)
				{
					hideLerpRef.Invoke(__instance) += Time.deltaTime * 5f;
					hideLerpRef.Invoke(__instance) = Mathf.Clamp(hideLerpRef.Invoke(__instance), 0f, 1f);
					__instance.hideTransform.localScale = new Vector3(1f, __instance.hideCurve.Evaluate(hideLerpRef.Invoke(__instance)), 1f);
					if (hideLerpRef.Invoke(__instance) >= 1f)
					{
						((Component)__instance.hideTransform).gameObject.SetActive(false);
					}
				}
			}
			else if (hideLerpRef.Invoke(__instance) > 0f)
			{
				if (!((Component)__instance.hideTransform).gameObject.activeSelf)
				{
					((Component)__instance.hideTransform).gameObject.SetActive(true);
				}
				hideLerpRef.Invoke(__instance) -= Time.deltaTime * 2f;
				hideLerpRef.Invoke(__instance) = Mathf.Clamp(hideLerpRef.Invoke(__instance), 0f, 1f);
				__instance.hideTransform.localScale = new Vector3(1f, __instance.hideCurve.Evaluate(hideLerpRef.Invoke(__instance)), 1f);
			}
			bool flag = true;
			if (isDisabledRef.Invoke(__instance.playerAvatar) || hideLerpRef.Invoke(__instance) > 0f)
			{
				flag = false;
			}
			if (colliderActiveRef.Invoke(__instance) != flag)
			{
				colliderActiveRef.Invoke(__instance) = flag;
				physColliderRef.Invoke(__instance).enabled = colliderActiveRef.Invoke(__instance);
			}
			((Component)__instance).transform.position = __instance.followTransform.position;
			((Component)__instance).transform.rotation = __instance.followTransform.rotation;
			if (colliderActiveRef.Invoke(__instance) && (!GameManager.Multiplayer() || PhotonNetwork.IsMasterClient))
			{
				if (staticGrabObjectRef.Invoke(__instance).playerGrabbing.Count > 0)
				{
					___grabbingTimer += Time.deltaTime;
					foreach (PhysGrabber item in staticGrabObjectRef.Invoke(__instance).playerGrabbing)
					{
						bool flag2 = IsPlayerCrouching(item.playerAvatar);
						float num = (flag2 ? Instance.CustomTransferInterval.Value : 1f);
						if (!(___grabbingTimer >= num))
						{
							continue;
						}
						PlayerAvatar playerAvatar = item.playerAvatar;
						if (healthRef.Invoke(__instance.playerAvatar.playerHealth) != maxHealthRef.Invoke(__instance.playerAvatar.playerHealth))
						{
							int num2 = (flag2 ? Instance.CustomHealAmount.Value : 10);
							int num3 = (flag2 ? Instance.CustomDamageAmount.Value : 10);
							if (healthRef.Invoke(playerAvatar.playerHealth) > num3)
							{
								__instance.playerAvatar.playerHealth.HealOther(num2, true);
								playerAvatar.playerHealth.HurtOther(num3, Vector3.zero, false, -1);
								playerAvatar.HealedOther();
								___grabbingTimer = 0f;
							}
						}
					}
				}
				else
				{
					___grabbingTimer = 0f;
				}
			}
			return false;
		}
	}

	public ConfigEntry<float> CustomTransferInterval;

	public ConfigEntry<int> CustomHealAmount;

	public ConfigEntry<int> CustomDamageAmount;

	public ConfigEntry<bool> ShowIndicator;

	private static readonly FieldRef<PlayerHealthGrab, bool> colliderActiveRef = AccessTools.FieldRefAccess<PlayerHealthGrab, bool>("colliderActive");

	private static readonly FieldRef<PlayerHealthGrab, StaticGrabObject> staticGrabObjectRef = AccessTools.FieldRefAccess<PlayerHealthGrab, StaticGrabObject>("staticGrabObject");

	private static readonly FieldRef<PlayerHealthGrab, float> hideLerpRef = AccessTools.FieldRefAccess<PlayerHealthGrab, float>("hideLerp");

	private static readonly FieldRef<PlayerHealthGrab, Collider> physColliderRef = AccessTools.FieldRefAccess<PlayerHealthGrab, Collider>("physCollider");

	private static readonly FieldRef<PlayerHealth, int> healthRef = AccessTools.FieldRefAccess<PlayerHealth, int>("health");

	private static readonly FieldRef<PlayerHealth, int> maxHealthRef = AccessTools.FieldRefAccess<PlayerHealth, int>("maxHealth");

	private static readonly FieldRef<PlayerAvatar, bool> isCrouchingRef = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isCrouching");

	private static readonly FieldRef<PlayerAvatar, bool> isTumblingRef = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isTumbling");

	private static readonly FieldRef<PlayerAvatar, bool> isDisabledRef = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isDisabled");

	public static CrouchGrabHealPlugin Instance { get; private set; }

	private void Awake()
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		CustomTransferInterval = ((BaseUnityPlugin)this).Config.Bind<float>("settings", "interval", 0.5f, "Interval for grab heal while crouching (in seconds) | 蹲下治疗的间隔时间(秒)");
		CustomHealAmount = ((BaseUnityPlugin)this).Config.Bind<int>("settings", "heal", 3, "Health amount healed each time while crouching | 蹲下治疗治疗队友的生命值");
		CustomDamageAmount = ((BaseUnityPlugin)this).Config.Bind<int>("settings", "damage", 0, "Health amount deducted each time while crouching | 蹲下治疗扣除自己的生命值");
		new Harmony("REPO.CrouchGrabHeal").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"CrouchGrabHeal loded!");
	}

	private static bool IsPlayerCrouching(PlayerAvatar avatar)
	{
		return isCrouchingRef.Invoke(avatar);
	}
}