using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Microsoft.CodeAnalysis;
using Noclip.Core;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Noclip.Plugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("Noclip.Plugin")]
[assembly: AssemblyTitle("Noclip.Plugin")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace Noclip.Plugin
{
[HarmonyPatch]
internal static class MovementHooks
{
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerMovementController), "Update")]
private static bool SkipWhileFlying(PlayerMovementController __instance)
{
try
{
return !NoclipDriver.IsFlying(__instance);
}
catch (Exception e)
{
Plugin.Instance?.ReportOnce("movement update hook", e);
return true;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(RootMotionController), "OnAnimatorMove")]
private static bool SkipRootMotionWhileFlying(RootMotionController __instance)
{
try
{
return !NoclipDriver.IsFlying(__instance);
}
catch (Exception e)
{
Plugin.Instance?.ReportOnce("root motion hook", e);
return true;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerCharacter), "RagdollRemotePlayer_Rpc")]
private static bool NoKnockDownWhileFlying(PlayerCharacter __instance)
{
try
{
return !NoclipDriver.IsFlying((CharacterBase)(object)__instance);
}
catch (Exception e)
{
Plugin.Instance?.ReportOnce("knock-down hook", e);
return true;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Car), "OnTriggerEnter")]
private static bool CarsPassThroughWhileFlying(Collider other)
{
try
{
CharacterBase character = default(CharacterBase);
return (Object)(object)other == (Object)null || !HitboxManager.TryGetCharacter(other, ref character) || !NoclipDriver.IsFlying(character);
}
catch (Exception e)
{
Plugin.Instance?.ReportOnce("car hook", e);
return true;
}
}
}
internal sealed class NoclipDriver : MonoBehaviour
{
private const EPlayerMovementLockReason GameTakesOver = (EPlayerMovementLockReason)1056;
private const float MaxFrameSeconds = 0.1f;
private static IntPtr _flying;
private static IntPtr _flyingRootMotion;
private static IntPtr _flyingPlayer;
private PlayerMovementController _movement;
public NoclipDriver(IntPtr pointer)
: base(pointer)
{
}
internal static bool IsFlying(PlayerMovementController movement)
{
if (_flying != IntPtr.Zero && (Object)(object)movement != (Object)null)
{
return ((Il2CppObjectBase)movement).Pointer == _flying;
}
return false;
}
internal static bool IsFlying(CharacterBase character)
{
if (_flyingPlayer != IntPtr.Zero && (Object)(object)character != (Object)null)
{
return ((Il2CppObjectBase)character).Pointer == _flyingPlayer;
}
return false;
}
internal static bool IsFlying(RootMotionController rootMotion)
{
if (_flyingRootMotion != IntPtr.Zero && (Object)(object)rootMotion != (Object)null)
{
return ((Il2CppObjectBase)rootMotion).Pointer == _flyingRootMotion;
}
return false;
}
private void Update()
{
Plugin instance = Plugin.Instance;
if (instance == null)
{
return;
}
try
{
Tick(instance);
}
catch (Exception e)
{
instance.ReportOnce("noclip update", e);
Land();
}
}
private void Tick(Plugin plugin)
{
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
PlayerCharacter local = PlayerCharacter.Local;
PlayerMovementController val = (((Object)(object)local == (Object)null) ? null : local.PlayerMovementController);
if ((Object)(object)_movement != (Object)null && ((Object)(object)val == (Object)null || ((Il2CppObjectBase)val).Pointer != ((Il2CppObjectBase)_movement).Pointer))
{
Forget();
}
if ((Object)(object)val == (Object)null)
{
return;
}
InputSystem inputSystem = local.InputSystem;
if ((Object)(object)_movement != (Object)null && ((val.PlayerMovementLockReason & 0x420) != 0 || local.isHeldByAnotherPlayer))
{
Land();
return;
}
if (TogglePressed(plugin) && !IsTyping())
{
if ((Object)(object)_movement == (Object)null)
{
TakeOff(local, val);
}
else
{
Land();
}
}
if ((Object)(object)_movement != (Object)null)
{
Fly(local, val, inputSystem, plugin.Flight);
}
}
private static bool TogglePressed(Plugin plugin)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
Key value = plugin.ToggleKey.Value;
Keyboard current = Keyboard.current;
if ((int)value != 0 && current != null)
{
return ((ButtonControl)current[value]).wasPressedThisFrame;
}
return false;
}
private static bool IsTyping()
{
EventSystem current = EventSystem.current;
GameObject val = (((Object)(object)current == (Object)null) ? null : current.currentSelectedGameObject);
if ((Object)(object)val == (Object)null)
{
return false;
}
TMP_InputField component = val.GetComponent<TMP_InputField>();
if ((Object)(object)component != (Object)null)
{
return component.isFocused;
}
return false;
}
private void TakeOff(PlayerCharacter player, PlayerMovementController movement)
{
_movement = movement;
_flying = ((Il2CppObjectBase)movement).Pointer;
_flyingPlayer = ((Il2CppObjectBase)player).Pointer;
RootMotionController rootMotionController = player.RootMotionController;
_flyingRootMotion = (((Object)(object)rootMotionController == (Object)null) ? IntPtr.Zero : ((Il2CppObjectBase)rootMotionController).Pointer);
CharacterController characterController = movement.CharacterController;
if ((Object)(object)characterController != (Object)null)
{
((Collider)characterController).enabled = false;
}
if (movement.isCrouching)
{
movement.ForceStopCrouching();
}
movement.DisableRunningVFX();
((BasePlugin)Plugin.Instance).Log.LogInfo((object)"Noclip on");
}
private void Fly(PlayerCharacter player, PlayerMovementController movement, InputSystem input, FlightSettings settings)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: 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_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
CharacterController characterController = movement.CharacterController;
if ((Object)(object)characterController != (Object)null && ((Collider)characterController).enabled)
{
((Collider)characterController).enabled = false;
}
StandStill(movement);
if ((Object)(object)input == (Object)null || (int)movement.PlayerMovementLockReason != 0 || player.IsInBuildingMenu.Value || player.IsInFreeCamera.Value)
{
return;
}
Camera val = (((Object)(object)movement.mainCamera != (Object)null) ? movement.mainCamera : Camera.main);
if (!((Object)(object)val == (Object)null))
{
Transform transform = ((Component)val).transform;
Vector2 move = input.move;
Vec3 val2 = Flight.Velocity(ToVec3(transform.forward), ToVec3(transform.right), new FlightInput(move.x, move.y, input.jump, input.crouch, input.sprint), settings);
if (!(val2 == Vec3.Zero))
{
float num = Mathf.Min(Time.unscaledDeltaTime, 0.1f);
Transform transform2 = ((Component)movement).transform;
transform2.position += new Vector3(((Vec3)(ref val2)).X, ((Vec3)(ref val2)).Y, ((Vec3)(ref val2)).Z) * num;
}
}
}
private static void StandStill(PlayerMovementController movement)
{
movement.speed = 0f;
movement.animationBlend = 0f;
if (movement.runningVFXEnabled)
{
movement.DisableRunningVFX();
}
Animator playerAnimator = movement.PlayerAnimator;
if (movement.hasAnimator && !((Object)(object)playerAnimator == (Object)null))
{
playerAnimator.SetFloat(movement.animIDSpeed, 0f);
playerAnimator.SetFloat(movement.animIDMotionSpeed, 1f);
playerAnimator.SetBool(movement.animIDGrounded, true);
playerAnimator.SetBool(movement.animIDJump, false);
playerAnimator.SetBool(movement.animIDFreeFall, false);
playerAnimator.SetBool(movement.animIDCrouching, false);
}
}
private void Land()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
PlayerMovementController movement = _movement;
Forget();
if (!((Object)(object)movement == (Object)null))
{
float y = ((Component)movement).transform.position.y;
movement.verticalVelocity = 0f;
movement.fallTimeoutDelta = movement.FallTimeout;
movement.HighestYPosThisFall = y;
movement.LowestYPosThisFall = y;
CharacterController characterController = movement.CharacterController;
if ((Object)(object)characterController != (Object)null)
{
((Collider)characterController).enabled = true;
characterController.Move(Vector3.zero);
}
((BasePlugin)Plugin.Instance).Log.LogInfo((object)"Noclip off");
}
}
private void Forget()
{
_movement = null;
_flying = IntPtr.Zero;
_flyingRootMotion = IntPtr.Zero;
_flyingPlayer = IntPtr.Zero;
}
private static Vec3 ToVec3(Vector3 v)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
return new Vec3(v.x, v.y, v.z);
}
}
[BepInPlugin("com.github.kirby1997.noclip", "Noclip", "0.1.0")]
public sealed class Plugin : BasePlugin
{
public const string Id = "com.github.kirby1997.noclip";
public const string Name = "Noclip";
public const string Version = "0.1.0";
private readonly HashSet<string> _reported = new HashSet<string>();
private ConfigEntry<float> _speed;
private ConfigEntry<float> _fastMultiplier;
internal static Plugin Instance { get; private set; }
internal ConfigEntry<Key> ToggleKey { get; private set; }
internal FlightSettings Flight => new FlightSettings(_speed.Value, _fastMultiplier.Value);
public override void Load()
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Expected O, but got Unknown
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Expected O, but got Unknown
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Expected O, but got Unknown
Instance = this;
ToggleKey = ((BasePlugin)this).Config.Bind<Key>("General", "ToggleKey", (Key)28, "Key that turns noclip on and off. None turns the key off. V is the game's camera switch, so avoid it.");
_speed = ((BasePlugin)this).Config.Bind<float>("Flight", "Speed", 10f, new ConfigDescription("Flying speed in metres per second. Walking is about 4 and running about 7.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 200f), Array.Empty<object>()));
_fastMultiplier = ((BasePlugin)this).Config.Bind<float>("Flight", "FastMultiplier", 3f, new ConfigDescription("Speed is multiplied by this while you hold the sprint key. 3 with Speed 10 gives 30 m/s.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 20f), Array.Empty<object>()));
((BasePlugin)this).AddComponent<NoclipDriver>();
new Harmony("com.github.kirby1997.noclip").PatchAll(typeof(MovementHooks));
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(8, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Noclip");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded");
}
log.LogInfo(val);
}
internal void ReportOnce(string what, Exception e)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
if (_reported.Add(what))
{
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(9, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(what);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(e);
}
log.LogError(val);
}
}
}
}