using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
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("freshpolakke_doublejump")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("freshpolakke_doublejump")]
[assembly: AssemblyTitle("freshpolakke_doublejump")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
namespace DoubleJumpMod
{
[BepInPlugin("freshpolakke.doublejump", "Double Jump", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
new Harmony("freshpolakke.doublejump").PatchAll();
Log.LogInfo((object)"Double Jump loaded!");
}
}
[HarmonyPatch(typeof(Player), "Update")]
public static class DoubleJumpPatch
{
private static bool usedDoubleJump;
private static bool warnedGrounded;
private static Rigidbody[] bodies;
private static Player cachedPlayer;
private const float JumpForce = 20f;
private static void Postfix(Player __instance)
{
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
if (!IsLocalPlayer(__instance))
{
return;
}
if ((Object)(object)cachedPlayer != (Object)(object)__instance || bodies == null)
{
cachedPlayer = __instance;
bodies = ((Component)__instance).GetComponentsInChildren<Rigidbody>();
Plugin.Log.LogInfo((object)$"{bodies.Length} Rigidbodies found.");
}
if (IsGrounded(__instance))
{
usedDoubleJump = false;
}
else
{
if (Keyboard.current == null || !((ButtonControl)Keyboard.current.spaceKey).wasPressedThisFrame || usedDoubleJump)
{
return;
}
usedDoubleJump = true;
Rigidbody[] array = bodies;
foreach (Rigidbody val in array)
{
if (!((Object)(object)val == (Object)null))
{
Vector3 velocity = val.velocity;
val.velocity = new Vector3(velocity.x, 0f, velocity.z);
val.AddForce(Vector3.up * 20f, (ForceMode)2);
}
}
}
}
private static bool IsLocalPlayer(Player p)
{
Traverse val = Traverse.Create((object)p);
Traverse val2 = val.Property("IsLocal", (object[])null);
if (val2.PropertyExists())
{
return val2.GetValue<bool>();
}
Traverse val3 = val.Field("IsLocal");
if (val3.FieldExists())
{
return val3.GetValue<bool>();
}
return true;
}
private static bool IsGrounded(Player p)
{
Traverse val = Traverse.Create((object)p).Field("data");
Traverse val2 = val.Field("isGrounded");
if (val2.FieldExists())
{
return val2.GetValue<bool>();
}
if (!warnedGrounded)
{
warnedGrounded = true;
Plugin.Log.LogWarning((object)"the Field data.isGrounded not found - go ask freshpolakke.");
}
return false;
}
}
}