using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("StackLimits")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StackLimits")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e1eed1dd-765c-465b-956d-6bb006ca326f")]
[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 StackLimits;
[BepInPlugin("FlightFixes", "Flight Fixes", "1.0.0")]
public class FlightFixes : BaseUnityPlugin
{
[HarmonyPatch(typeof(PlayerFirstPersonController), "CheckOutOfBounds")]
private static class OutOfBoundsFix
{
private static uint delay;
private static bool inGroundLastCheck;
private static bool Prefix(ref PlayerFirstPersonController __instance, ref bool ___outOfBoundsLastFrame)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
//IL_001c: 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_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: 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)
if ((int)Player.instance.cheats.freeCameraMode != 1)
{
Bounds bounds = __instance.playerCollider.bounds;
if (VoxelManager.instance.bottomBoundaryYPos != float.MaxValue && !__instance.m_IsGrounded && ((Component)__instance).transform.position.y < VoxelManager.instance.bottomBoundaryYPos)
{
if (___outOfBoundsLastFrame)
{
___outOfBoundsLastFrame = false;
__instance.Respawn();
return false;
}
___outOfBoundsLastFrame = true;
return false;
}
Vector3 position = ((Component)__instance).transform.position;
position.y = ((Bounds)(ref bounds)).max.y;
if (SandVolume.UnderSand(VoxelManager.curStrataNum, position))
{
if (___outOfBoundsLastFrame)
{
___outOfBoundsLastFrame = false;
__instance.Respawn();
return false;
}
___outOfBoundsLastFrame = true;
return false;
}
delay++;
if (delay >= checkOutofBoundsDelay)
{
delay = 0u;
HashSet<Vector3Int> voxelsInBounds = VoxelManager.GetVoxelsInBounds(bounds, checkOutofBoundsRange);
bool flag = true;
foreach (Vector3Int item in voxelsInBounds)
{
Vector3Int current = item;
if ((Object)(object)VoxelManager.instance.GetVoxelType(ref current, ref VoxelManager.curStrataNum) == (Object)null)
{
flag = false;
}
}
if (flag)
{
if (inGroundLastCheck)
{
inGroundLastCheck = false;
__instance.Respawn();
return false;
}
inGroundLastCheck = true;
return false;
}
}
}
___outOfBoundsLastFrame = false;
return false;
}
}
[HarmonyPatch(typeof(PlayerFirstPersonController), "Move")]
private static class HoverDisableFix
{
private static void Prefix(PlayerFirstPersonController __instance, bool ___m_IsGrounded, ref float ___m_VerticalSpeed)
{
if (Player.instance.equipment.hoverPack.active && ___m_IsGrounded)
{
___m_VerticalSpeed = 0f;
}
}
}
private const string PluginName = "Flight Fixes";
private const string pluginGuid = "FlightFixes";
private const string VersionString = "1.0.0";
private Harmony harmony = new Harmony("Flight Fixes");
public static int checkOutofBoundsDelay;
public static float checkOutofBoundsRange;
private void Awake()
{
if (((BaseUnityPlugin)this).Config.Bind<bool>("OutOfBoundsRespawnReduction", "Enabled", true, "If enabled, increases the amount you can be inside ground voxels without the game respawning you. Also give you 1-2 seconds time to get out again rather than 2 frames.").Value)
{
harmony.PatchAll(typeof(OutOfBoundsFix));
}
checkOutofBoundsDelay = Convert.ToInt32(50f / ((BaseUnityPlugin)this).Config.Bind<float>("OutOfBoundsRespawnReduction", "CheckInterval", 1f, "Every how many seconds the game will check if you are out of bounds. After two consecutive out of bounds (inside ground) checks you are forced to respawn. 0.02 would be vanilla").Value);
checkOutofBoundsRange = ((BaseUnityPlugin)this).Config.Bind<float>("OutOfBoundsRespawnReduction", "CheckRange", 2f, "How far the game will check if there are still air blocks near you. Higher values lead to later respawn enforces. Vanilla would be 0.25. Very high values may impact performance (especially if used with low CheckInterval)").Value;
if (((BaseUnityPlugin)this).Config.Bind<bool>("HoverpackChanges", "Enabled", true, "If enabled, hoverpack will no longer disable unless you press space. That means, you will no longer start falling when nearing an edge because the game thinks you are on ground but at the same time lets you fall down....").Value)
{
harmony.PatchAll(typeof(HoverDisableFix));
}
harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Flight Fixes Version 1.0.0 has loaded.");
}
}