using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using JetpackHandling.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("JetpackHandlingFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JetpackHandlingFix")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0159EE6F-FC0B-4002-A93B-64BADD4A36B1")]
[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 JetpackHandling
{
[BepInPlugin("silverc.JetpackHandling", "JetpackHandling", "1.0.2.0")]
public class Plugin : BaseUnityPlugin
{
private const string ModGUID = "silverc.JetpackHandling";
private const string ModName = "JetpackHandling";
private const string ModVersion = "1.0.2.0";
private readonly Harmony harmony = new Harmony("silverc.JetpackHandling");
private static Plugin Instance;
private ManualLogSource Logger;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin silverc.JetpackHandling is loaded!");
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(JetpackItemPatch));
harmony.PatchAll(typeof(PlayerControllerBPatch2));
}
}
}
namespace JetpackHandling.Patches
{
[HarmonyPatch(typeof(JetpackItem), "Update")]
internal class JetpackItemPatch
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
Type typeFromHandle = typeof(PlayerControllerB);
MethodInfo method = typeFromHandle.GetMethod("KillPlayer");
ManualLogSource val = new ManualLogSource("jetpackupdate");
Logger.Sources.Add((ILogSource)(object)val);
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Callvirt && CodeInstructionExtensions.Calls(list[i], method))
{
val.LogInfo((object)$"{i}-found opcode: {list[i].opcode}");
for (int j = 0; j < 8; j++)
{
list[i - j].opcode = OpCodes.Nop;
}
}
}
return list;
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch2
{
private static readonly FieldInfo IsJumpingField = typeof(PlayerControllerB).GetField("isJumping", BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly FieldInfo IsFallingFromJumpField = typeof(PlayerControllerB).GetField("isFallingFromJump", BindingFlags.Instance | BindingFlags.NonPublic);
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void JetpackHandlingPatch(PlayerControllerB __instance)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
ManualLogSource item = new ManualLogSource("jetpackhandlingsource");
Logger.Sources.Add((ILogSource)(object)item);
float num = 0f;
bool flag = false;
bool flag2 = false;
bool flag3 = (!__instance.inSpecialInteractAnimation || __instance.inShockingMinigame) && (Object)(object)__instance.currentlyHeldObjectServer != (Object)null && __instance.currentlyHeldObjectServer.itemProperties.itemName == "Jetpack";
if (flag3)
{
if (__instance.jetpackControls && !__instance.disablingJetpackControls)
{
flag2 = true;
}
else
{
flag = true;
}
}
__instance.takingFallDamage = false;
if (flag3)
{
if (flag)
{
num = ((!(__instance.fallValue > 2f)) ? 1f : (__instance.fallValue * 0.5f));
__instance.fallValue = Mathf.MoveTowards(__instance.fallValue, -12f, 7f * Time.deltaTime * num);
__instance.fallValueUncapped = 0f;
}
else if (flag2)
{
__instance.fallValue = Mathf.MoveTowards(__instance.fallValue, -1f, 7f * Time.deltaTime + num);
__instance.fallValueUncapped = 0f;
}
}
else if ((float)__instance.health > 25f && __instance.fallValue < -30f && __instance.thisController.isGrounded)
{
__instance.DamagePlayer(Mathf.Clamp((int)__instance.fallValue, 20, 100), true, true, (CauseOfDeath)2, 0, true, Vector3.ClampMagnitude(__instance.velocityLastFrame, 50f));
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
private static readonly FieldInfo IsJumpingField = typeof(PlayerControllerB).GetField("isJumping", BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly FieldInfo IsFallingFromJumpField = typeof(PlayerControllerB).GetField("isFallingFromJump", BindingFlags.Instance | BindingFlags.NonPublic);
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void JetpackHandlingPatch(PlayerControllerB __instance)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
ManualLogSource val = new ManualLogSource("jetpackhandlingsource");
Logger.Sources.Add((ILogSource)(object)val);
float num = 0f;
bool flag = false;
bool flag2 = true;
bool flag3 = false;
if ((!__instance.inSpecialInteractAnimation || __instance.inShockingMinigame) && (Object)(object)__instance.currentlyHeldObjectServer != (Object)null && __instance.currentlyHeldObjectServer.itemProperties.itemName == "Jetpack")
{
if (__instance.jetpackControls && !__instance.disablingJetpackControls)
{
flag3 = true;
flag2 = false;
}
else
{
flag = true;
flag2 = false;
}
}
__instance.takingFallDamage = false;
if (flag)
{
num = ((!(__instance.fallValue > 2f)) ? 1f : (__instance.fallValue * 0.5f));
__instance.fallValue = Mathf.MoveTowards(__instance.fallValue, -12f, 7f * Time.deltaTime * num);
__instance.fallValueUncapped = 0f;
}
else if (flag2)
{
if ((float)__instance.health > 25f && __instance.fallValue < -30f && __instance.thisController.isGrounded)
{
val.LogInfo((object)"taking damage from fall");
val.LogInfo((object)$"fallValue = {__instance.fallValue}");
val.LogInfo((object)$"fallValueUncapped = {__instance.fallValueUncapped}");
val.LogInfo((object)$"__instance.inSpecialInteractAnimation = {__instance.inSpecialInteractAnimation}");
val.LogInfo((object)$"isJumping = {IsJumpingField.GetValue(__instance)}");
val.LogInfo((object)$"isFallingFromJump = {IsFallingFromJumpField.GetValue(__instance)}");
__instance.DamagePlayer(Mathf.Clamp((int)__instance.fallValue, 20, 100), true, true, (CauseOfDeath)2, 0, true, Vector3.ClampMagnitude(__instance.velocityLastFrame, 50f));
}
if (__instance.thisController.isGrounded || __instance.isClimbingLadder)
{
__instance.fallValue = -7f;
__instance.fallValueUncapped = -7f;
}
}
else if (flag3)
{
__instance.fallValue = Mathf.MoveTowards(__instance.fallValue, -1f, 7f * Time.deltaTime + num);
__instance.fallValueUncapped = 0f;
}
}
}
}