HowToFish.Fly.dll

Decompiled 7 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[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("HowToFish.Fly")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("HowToFish.Fly")]
[assembly: AssemblyTitle("HowToFish.Fly")]
[assembly: AssemblyVersion("0.1.0.0")]
[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 HowToFish.Fly
{
	[BepInPlugin("community.howtofish.fly", "Fly", "0.1.0")]
	[BepInProcess("How to Fish.exe")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(PlayerMovement), "FixedUpdate")]
		private static class PatchFly
		{
			private static void Postfix(PlayerMovement __instance)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected O, but got Unknown
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Expected O, but got Unknown
				//IL_019a: Unknown result type (might be due to invalid IL or missing references)
				//IL_019f: Unknown result type (might be due to invalid IL or missing references)
				//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
				Player val = (Player)AccessTools.Field(typeof(PlayerMovement), "_player").GetValue(__instance);
				if ((Object)(object)val == (Object)null || (Object)(object)val != (Object)(object)Player.LocalPlayer)
				{
					return;
				}
				Keyboard current = Keyboard.current;
				if (current != null && ((ButtonControl)current.spaceKey).wasPressedThisFrame)
				{
					if (Time.time - _lastTap < DoubleTapWindow.Value)
					{
						_flying = !_flying;
						_lastTap = -10f;
						Plugin instance = Instance;
						if (instance != null)
						{
							((BaseUnityPlugin)instance).Logger.LogInfo((object)("[Fly] " + (_flying ? "飞行开启" : "飞行关闭")));
						}
					}
					else
					{
						_lastTap = Time.time;
					}
				}
				Rigidbody val2 = (Rigidbody)AccessTools.Field(typeof(PlayerMovement), "_rig").GetValue(__instance);
				if ((Object)(object)val2 == (Object)null)
				{
					return;
				}
				if (!_flying)
				{
					if (!val2.useGravity)
					{
						val2.useGravity = true;
					}
					return;
				}
				val2.useGravity = false;
				float num = 0f;
				if (current != null)
				{
					if (((ButtonControl)current.spaceKey).isPressed)
					{
						num += FlySpeed.Value;
					}
					if (((ButtonControl)current.leftCtrlKey).isPressed || ((ButtonControl)current.cKey).isPressed)
					{
						num -= FlySpeed.Value;
					}
				}
				Vector3 linearVelocity = val2.linearVelocity;
				linearVelocity.y = num;
				val2.linearVelocity = linearVelocity;
			}
		}

		private static ConfigEntry<float> FlySpeed;

		private static ConfigEntry<float> DoubleTapWindow;

		internal static Plugin Instance;

		private static bool _flying;

		private static float _lastTap = -10f;

		private void Awake()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			Instance = this;
			FlySpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Fly", "FlySpeed", 10f, new ConfigDescription("飞行垂直速度", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 40f), Array.Empty<object>()));
			DoubleTapWindow = ((BaseUnityPlugin)this).Config.Bind<float>("Fly", "DoubleTapWindow", 0.3f, new ConfigDescription("双击空格判定窗口(秒)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			Harmony val = new Harmony("community.howtofish.fly");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Fly loaded. 双击空格切换飞行。");
		}
	}
}