Decompiled source of AF PitRescue v1.0.0

AF_PitRescue.dll

Decompiled a day ago
using System;
using System.Collections;
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 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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("Kuraputi")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AF_PitRescue")]
[assembly: AssemblyTitle("AF_PitRescue")]
[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.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]
	[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;
		}
	}
	[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 AF_PitRescue
{
	[BepInPlugin("Kuraputi.AF_PitRescue", "AF_PitRescue", "1.0.0")]
	public class AF_PitRescue : BaseUnityPlugin
	{
		internal static ConfigEntry<int> DamagePercent;

		internal static AF_PitRescue Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			BindConfig();
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		private void BindConfig()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			DamagePercent = ((BaseUnityPlugin)this).Config.Bind<int>("Rescue", "DamagePercent", 25, new ConfigDescription("ピットに落ちた際に受ける、最大HPに対する割合ダメージ(%)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		}

		internal void Patch()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0025: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
	internal class PitRescueFlight : MonoBehaviour
	{
		private const float FlightTime = 1.2f;

		private const float ArcHeight = 4f;

		private const float LandGuard = 0.5f;

		internal static bool Flying { get; private set; }

		internal static void Launch(Vector3 goal)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			PlayerController instance = PlayerController.instance;
			PitRescueFlight pitRescueFlight = ((Component)instance).GetComponent<PitRescueFlight>();
			if ((Object)(object)pitRescueFlight == (Object)null)
			{
				pitRescueFlight = ((Component)instance).gameObject.AddComponent<PitRescueFlight>();
			}
			((MonoBehaviour)pitRescueFlight).StopAllCoroutines();
			((MonoBehaviour)pitRescueFlight).StartCoroutine(pitRescueFlight.Fly(goal));
		}

		private IEnumerator Fly(Vector3 goal)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			Flying = true;
			PlayerController pc = PlayerController.instance;
			Rigidbody rb = pc.rb;
			Vector3 start = rb.position;
			float num = Mathf.Max(start.y, goal.y) + 4f;
			float ctrlY = num * 2f - (start.y + goal.y) / 2f;
			WaitForFixedUpdate wait = new WaitForFixedUpdate();
			for (float t = 0f; t < 1.2f; t += Time.fixedDeltaTime)
			{
				float num2 = t / 1.2f;
				Vector3 position = Vector3.Lerp(start, goal, num2);
				position.y = (1f - num2) * (1f - num2) * start.y + 2f * num2 * (1f - num2) * ctrlY + num2 * num2 * goal.y;
				rb.position = position;
				rb.velocity = Vector3.zero;
				pc.CollisionController.OverrideDisableFalling();
				yield return wait;
			}
			rb.position = goal;
			rb.velocity = Vector3.zero;
			for (float t = 0f; t < 0.5f; t += Time.deltaTime)
			{
				pc.CollisionController.OverrideDisableFalling();
				yield return null;
			}
			pc.CollisionController.ResetFalling();
			Flying = false;
		}

		private void OnDisable()
		{
			Flying = false;
		}
	}
	[HarmonyPatch(typeof(HurtCollider), "PlayerHurt")]
	internal static class PitRescuePatch
	{
		private static bool Prefix(HurtCollider __instance, PlayerAvatar _player)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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)
			if (!__instance.deathPit || !__instance.playerKill)
			{
				return true;
			}
			if (GameManager.Multiplayer() && !_player.photonView.IsMine)
			{
				return true;
			}
			if (PitRescueFlight.Flying)
			{
				return false;
			}
			PlayerHealth playerHealth = _player.playerHealth;
			if (_player.deadSet || playerHealth.health <= 0)
			{
				return true;
			}
			Vector3 lastNavmeshPosition = _player.LastNavmeshPosition;
			if (lastNavmeshPosition == Vector3.zero)
			{
				return true;
			}
			int num = Mathf.CeilToInt((float)(playerHealth.maxHealth * AF_PitRescue.DamagePercent.Value) / 100f);
			if (num >= playerHealth.health)
			{
				return true;
			}
			if ((Object)(object)_player.tumble != (Object)null && _player.tumble.isTumbling)
			{
				_player.tumble.TumbleRequest(false, false);
			}
			if (num > 0)
			{
				playerHealth.Hurt(num, false, -1, false);
			}
			playerHealth.InvincibleSet(2f);
			PitRescueFlight.Launch(lastNavmeshPosition + Vector3.up * 0.2f);
			AF_PitRescue.Logger.LogInfo((object)$"[Rescue] Hit {((Object)__instance).name} (damage {num}, hp {playerHealth.health}, goal {lastNavmeshPosition})");
			return false;
		}
	}
}