using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using ClimbAnything;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ClimbAnything")]
[assembly: AssemblyDescription("Allows the player to climb on any surface.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Waspothegreat")]
[assembly: AssemblyProduct("ClimbAnything")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("12345678-1234-1234-1234-123456789012")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: MelonInfo(typeof(Main), "ClimbAnything", "1.0.0", "Waspothegreat", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ClimbAnything;
public class Main : MelonMod
{
private class HandState
{
public Hand Hand;
public GameObject ClimbPoint;
public bool IsClimbing;
}
public static MelonPreferences_Category Prefs;
public static MelonPreferences_Entry<bool> EnabledEntry;
private HandState _leftHandState;
private HandState _rightHandState;
public static bool IsEnabled
{
get
{
return EnabledEntry.Value;
}
set
{
EnabledEntry.Value = value;
}
}
public override void OnInitializeMelon()
{
Prefs = MelonPreferences.CreateCategory("Climb Anything");
EnabledEntry = Prefs.CreateEntry<bool>("Enabled", true, "Enabled", "Toggle the Climb Anything mod", false, false, (ValueValidator)null, (string)null);
SetupMenu();
}
private void SetupMenu()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
Page.Root.CreatePage("Climb Anything", Color.green, 0, true).CreateBool("Enabled", Color.green, IsEnabled, (Action<bool>)delegate(bool val)
{
IsEnabled = val;
Prefs.SaveToFile(false);
});
}
public override void OnUpdate()
{
if (IsEnabled && !((Object)(object)Player.RigManager == (Object)null) && !((Object)(object)Player.PhysicsRig == (Object)null))
{
if (_leftHandState == null)
{
_leftHandState = new HandState
{
Hand = Player.LeftHand
};
}
if (_rightHandState == null)
{
_rightHandState = new HandState
{
Hand = Player.RightHand
};
}
UpdateHand(_leftHandState);
UpdateHand(_rightHandState);
}
}
private void UpdateHand(HandState state)
{
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_031f: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_038e: Unknown result type (might be due to invalid IL or missing references)
//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
//IL_026f: Unknown result type (might be due to invalid IL or missing references)
//IL_027c: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_029d: Unknown result type (might be due to invalid IL or missing references)
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
if (state == _leftHandState && (Object)(object)Player.LeftHand != (Object)(object)state.Hand)
{
state.Hand = Player.LeftHand;
}
if (state == _rightHandState && (Object)(object)Player.RightHand != (Object)(object)state.Hand)
{
state.Hand = Player.RightHand;
}
if ((Object)(object)state.Hand == (Object)null)
{
return;
}
float num = 0f;
if (Player.ControllersExist)
{
if ((Object)(object)state.Hand == (Object)(object)Player.LeftHand && (Object)(object)Player.LeftController != (Object)null)
{
num = Player.LeftController.GetGripForce();
}
else if ((Object)(object)state.Hand == (Object)(object)Player.RightHand && (Object)(object)Player.RightController != (Object)null)
{
num = Player.RightController.GetGripForce();
}
}
bool num2 = num > 0.01f;
if (state.IsClimbing && (Object)(object)state.ClimbPoint == (Object)null)
{
StopClimbing(state);
}
if (num2)
{
if (state.IsClimbing || (Object)(object)state.Hand.AttachedReceiver != (Object)null)
{
return;
}
float num3 = 0.2f;
float num4 = 0.15f;
Collider[] array2;
if ((Object)(object)Player.RigManager != (Object)null && (Object)(object)Player.RigManager.avatar != (Object)null)
{
float num5 = Player.RigManager.avatar.handSize.y;
float y = ((Component)Player.RigManager.avatar).transform.localScale.y;
if (num5 < 0.01f)
{
num5 = Player.RigManager.avatar.height * 0.1f;
}
float num6 = num5 * y;
Vector3 position = ((Component)state.Hand).transform.position;
_ = position + ((Component)state.Hand).transform.forward * (num6 * 0.5f);
_ = position + ((Component)state.Hand).transform.forward * num6;
num3 = num6 * 1.5f;
if (num3 < 0.2f)
{
num3 = 0.2f;
}
num4 = 0.08f;
Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(position, num3));
Collider val = null;
float num7 = float.MaxValue;
array2 = array;
foreach (Collider val2 in array2)
{
if (val2.isTrigger || (Object)(object)((Component)val2).transform.root == (Object)(object)((Component)Player.PhysicsRig).transform.root || (Object)(object)((Component)val2).GetComponentInParent<Grip>() != (Object)null)
{
continue;
}
float num8 = float.MaxValue;
_ = position + ((Component)state.Hand).transform.rotation * new Vector3(0f, 0f, num6 * 0.5f);
float num9 = Vector3.Distance(position, val2.ClosestPoint(position));
if (!(num9 > num6 + 0.04f))
{
num8 = num9;
if (num8 < num7)
{
num7 = num8;
val = val2;
}
}
}
if ((Object)(object)val != (Object)null)
{
StartClimbing(state, val);
}
return;
}
if (num4 < 0.05f)
{
num4 = 0.1f;
}
if (num3 < 0.1f)
{
num3 = 0.1f;
}
Collider[] array3 = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(((Component)state.Hand).transform.position, num3));
Collider val3 = null;
float num10 = float.MaxValue;
array2 = array3;
foreach (Collider val4 in array2)
{
if (!val4.isTrigger && !((Object)(object)((Component)val4).transform.root == (Object)(object)((Component)Player.PhysicsRig).transform.root) && !((Object)(object)((Component)val4).GetComponentInParent<Grip>() != (Object)null))
{
float num11 = Vector3.Distance(((Component)state.Hand).transform.position, val4.ClosestPoint(((Component)state.Hand).transform.position));
if (!(num11 > num4) && num11 < num10)
{
num10 = num11;
val3 = val4;
}
}
}
if ((Object)(object)val3 != (Object)null)
{
StartClimbing(state, val3);
}
}
else if (state.IsClimbing)
{
StopClimbing(state);
}
}
private void StartClimbing(HandState state, Collider surfaceCol)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//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_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
Vector3 position = ((Component)state.Hand).transform.position;
Quaternion rotation = ((Component)state.Hand).transform.rotation;
GameObject val = new GameObject("SpiderMonke_ClimbPoint_" + ((Object)state.Hand).name);
val.transform.position = position;
val.transform.rotation = rotation;
val.transform.SetParent(((Component)surfaceCol).transform, true);
val.AddComponent<Rigidbody>().isKinematic = true;
SphereCollider obj = val.AddComponent<SphereCollider>();
obj.radius = 0.15f;
((Collider)obj).isTrigger = true;
state.ClimbPoint = val;
state.IsClimbing = true;
FixedJoint obj2 = val.AddComponent<FixedJoint>();
((Joint)obj2).connectedBody = ((Component)state.Hand).GetComponent<Rigidbody>();
((Joint)obj2).breakForce = float.PositiveInfinity;
((Joint)obj2).breakTorque = float.PositiveInfinity;
((Joint)obj2).autoConfigureConnectedAnchor = true;
((Joint)obj2).enableCollision = false;
}
private void StopClimbing(HandState state)
{
if ((Object)(object)state.ClimbPoint != (Object)null)
{
Object.Destroy((Object)(object)state.ClimbPoint);
}
state.ClimbPoint = null;
state.IsClimbing = false;
}
}