using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CreativeFlight.Patches;
using EquinoxsModUtils;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CreativeFlight")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CreativeFlight")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a80e7664-9d15-4b04-8455-6ea1c6f5595b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CreativeFlight
{
public static class Jetpack
{
public static bool isFlying;
public static bool shouldDebug => CreativeFlightPlugin.shouldDebug;
public static void StartFlight()
{
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
isFlying = true;
ModUtils.SetPrivateField<PlayerFirstPersonController>("m_VerticalSpeed", Player.instance.fpcontroller, (object)0f);
ModUtils.SetPrivateField<Stilts>("_stiltHeight", Player.instance.equipment.hoverPack, (object)0f);
Player.instance.fpcontroller.m_Rigidbody.velocity = Vector3.zero;
Player.instance.fpcontroller.maxWalkSpeed = 10f;
Player.instance.fpcontroller.maxRunSpeed = 16f;
if (shouldDebug)
{
Debug.Log((object)"Started Flying");
}
}
public static void StopFlight()
{
isFlying = false;
Player.instance.fpcontroller.maxWalkSpeed = 5f;
Player.instance.fpcontroller.maxRunSpeed = 8f;
if (shouldDebug)
{
Debug.Log((object)"Stopped Flying");
}
}
}
[BepInPlugin("com.equinox.CreativeFlight", "CreativeFlight", "1.0.1")]
public class CreativeFlightPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.equinox.CreativeFlight";
private const string PluginName = "CreativeFlight";
private const string VersionString = "1.0.1";
private static readonly Harmony Harmony = new Harmony("com.equinox.CreativeFlight");
public static ManualLogSource Log = new ManualLogSource("CreativeFlight");
public static ConfigEntry<int> DoubleTapThreshold;
public static ConfigEntry<float> HorizontalThrust;
public static ConfigEntry<float> VerticalThrust;
public static ConfigEntry<float> Friction;
public static bool shouldDebug = false;
public static bool isEnabled = true;
public static float sSinceLastAscendPress;
public static float sSinceLastDescendPress;
private static float doubleTapThresholdSeconds => 0.001f * (float)DoubleTapThreshold.Value;
private void Awake()
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Expected O, but got Unknown
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Expected O, but got Unknown
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: CreativeFlight, VersionString: 1.0.1 is loading...");
Harmony.PatchAll();
DoubleTapThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Double Tap Threshold", 300, new ConfigDescription("The time interval in milliseconds during which two key presses are registered as a double tap", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 500), Array.Empty<object>()));
HorizontalThrust = ((BaseUnityPlugin)this).Config.Bind<float>("Forces", "Horizontal Thrust", 10f, new ConfigDescription("Controls horizontal acceleration while flying", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, float.MaxValue), Array.Empty<object>()));
VerticalThrust = ((BaseUnityPlugin)this).Config.Bind<float>("Forces", "Vertical Thrust", 150f, new ConfigDescription("Controls vertical acceleration while flying", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, float.MaxValue), Array.Empty<object>()));
Friction = ((BaseUnityPlugin)this).Config.Bind<float>("Forces", "Friction", 0.15f, new ConfigDescription("Controls how quickly you slow to a stop while flying", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 0.9f), Array.Empty<object>()));
Harmony.CreateAndPatchAll(typeof(PlayerFirstPersonControllerPatch), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: CreativeFlight, VersionString: 1.0.1 is loaded.");
Log = ((BaseUnityPlugin)this).Logger;
}
private void Update()
{
sSinceLastAscendPress += Time.deltaTime;
sSinceLastDescendPress += Time.deltaTime;
if (UnityInput.Current.GetKeyDown((KeyCode)32))
{
if (sSinceLastAscendPress < doubleTapThresholdSeconds && !Jetpack.isFlying)
{
Jetpack.StartFlight();
}
sSinceLastAscendPress = 0f;
}
else if (UnityInput.Current.GetKeyDown((KeyCode)99) && !UnityInput.Current.GetKeyDown((KeyCode)306))
{
if (sSinceLastDescendPress < doubleTapThresholdSeconds && Jetpack.isFlying)
{
Jetpack.StopFlight();
}
sSinceLastDescendPress = 0f;
}
}
}
}
namespace CreativeFlight.Patches
{
internal class PlayerFirstPersonControllerPatch
{
private static bool ascend => UnityInput.Current.GetKey((KeyCode)32);
private static bool descend
{
get
{
if (UnityInput.Current.GetKey((KeyCode)99))
{
return !UnityInput.Current.GetKeyDown((KeyCode)306);
}
return false;
}
}
private static float hThrust => CreativeFlightPlugin.HorizontalThrust.Value;
private static float vThrust => CreativeFlightPlugin.VerticalThrust.Value;
private static float friction => CreativeFlightPlugin.Friction.Value;
[HarmonyPatch(typeof(PlayerFirstPersonController), "CalculateHorizontalMovement")]
[HarmonyPrefix]
private static bool RecalcHorizontalMovement(PlayerFirstPersonController __instance)
{
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
if (ShouldUseDefault(__instance))
{
return true;
}
float num = (float)ModUtils.GetPrivateField<PlayerFirstPersonController>("m_HorizontalSpeed", Player.instance.fpcontroller);
num *= 1f - friction;
if (UnityInput.Current.GetKey((KeyCode)119) || UnityInput.Current.GetKey((KeyCode)115) || UnityInput.Current.GetKey((KeyCode)97) || UnityInput.Current.GetKey((KeyCode)100))
{
num += hThrust;
}
Vector3 forward = ((Component)__instance.cam).transform.forward;
forward.y = 0f;
((Vector3)(ref forward)).Normalize();
float num2 = (float)typeof(PlayerFirstPersonController).GetProperty("encumbranceSlowDownMultiplier", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Player.instance.fpcontroller);
float num3 = (Player.instance.fpcontroller.isRunning ? 1.5f : 1f);
Vector2 moveAxes = InputHandler.instance.MoveAxes;
Vector3 val = Quaternion.LookRotation(forward, Vector3.up) * new Vector3(moveAxes.x, 0f, moveAxes.y) * num * num2 * num3;
ModUtils.SetPrivateField<PlayerFirstPersonController>("m_DesiredHorizontalVelocity", Player.instance.fpcontroller, (object)val);
return false;
}
[HarmonyPatch(typeof(PlayerFirstPersonController), "CalculateVerticalMovement")]
[HarmonyPrefix]
private static bool RecalcVerticalMovement(PlayerFirstPersonController __instance)
{
if (ShouldUseDefault(__instance))
{
return true;
}
ModUtils.SetPrivateField<Stilts>("_active", Player.instance.equipment.hoverPack, (object)false);
float num = (float)ModUtils.GetPrivateField<PlayerFirstPersonController>("m_VerticalSpeed", Player.instance.fpcontroller);
num *= 1f - friction;
float num2 = (float)typeof(PlayerFirstPersonController).GetProperty("encumbranceSlowDownMultiplier", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Player.instance.fpcontroller);
float num3 = (Player.instance.fpcontroller.isRunning ? 1.5f : 1f);
if (ascend)
{
num += vThrust * num2 * num3 * Time.deltaTime;
}
if (descend)
{
num -= vThrust * Time.deltaTime;
}
ModUtils.SetPrivateField<PlayerFirstPersonController>("m_VerticalSpeed", Player.instance.fpcontroller, (object)num);
return false;
}
private static bool ShouldUseDefault(PlayerFirstPersonController __instance)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Invalid comparison between Unknown and I4
if (!CreativeFlightPlugin.isEnabled)
{
return true;
}
if ((int)(ControlState)ModUtils.GetPrivateField<PlayerFirstPersonController>("curControls", __instance) == 3)
{
return true;
}
if (!Jetpack.isFlying)
{
return true;
}
return false;
}
[HarmonyPatch(typeof(PlayerFirstPersonController), "AutoCrouch")]
[HarmonyPrefix]
private static bool BlockAutoCrouch()
{
if (ShouldUseDefault(Player.instance.fpcontroller))
{
return true;
}
return false;
}
[HarmonyPatch(typeof(PlayerFirstPersonController), "UpdateHoverPackStatus")]
[HarmonyPrefix]
public static bool AdjustStiltsHeight(PlayerFirstPersonController __instance)
{
if (!CreativeFlightPlugin.isEnabled)
{
return true;
}
return false;
}
[HarmonyPatch(typeof(PlayerFirstPersonController), "DeactivateHoverPack")]
[HarmonyPrefix]
public static bool BlockDeactivateHoverpack()
{
if (!CreativeFlightPlugin.isEnabled)
{
return true;
}
return false;
}
}
}