Decompiled source of NoClip v1.0.4

BigWalk.NoClip.dll

Decompiled 14 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppSystem.Collections.Generic;
using LobbyNetworking;
using Mirror;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("BigWalk.NoClip")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("Big Walk NoClip")]
[assembly: AssemblyTitle("BigWalk.NoClip")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
namespace BigWalk.NoClip;

public class NoClipController : MonoBehaviour
{
	private bool _active;

	private PlayerCharacter _target;

	private bool _savedUseGravity = true;

	private bool _savedDetectCollisions = true;

	private bool _savedMoverBypassFixed;

	private bool _savedIgnoreAirbourne;

	private GUIStyle _hudStyle;

	private void Update()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		try
		{
			if (Input.GetKeyDown(Plugin.ToggleKey.Value))
			{
				Toggle();
			}
			if (_active && !IsLobbyHost())
			{
				Plugin.Log.LogWarning((object)"NoClip: disabled because you are not the lobby host.");
				SetNoClip(enabled: false);
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NoClip Update failed: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
			}
			log.LogError(val);
		}
	}

	private void LateUpdate()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		if (!_active)
		{
			return;
		}
		try
		{
			if (!IsLobbyHost())
			{
				SetNoClip(enabled: false);
			}
			else
			{
				Fly();
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(26, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NoClip LateUpdate failed: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
			}
			log.LogError(val);
		}
	}

	private void OnGUI()
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		if (_active && Plugin.ShowHud.Value)
		{
			if (_hudStyle == null)
			{
				_hudStyle = new GUIStyle(GUI.skin.box)
				{
					fontSize = 14,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				_hudStyle.normal.textColor = Color.cyan;
			}
			GUI.Box(new Rect(16f, (float)Screen.height - 48f, 280f, 32f), $"NOCLIP  [{Plugin.ToggleKey.Value}]  Shift=fast", _hudStyle);
		}
	}

	private void OnDisable()
	{
		if (_active)
		{
			SetNoClip(enabled: false);
		}
	}

	private void Toggle()
	{
		if (!IsLobbyHost())
		{
			Plugin.Log.LogWarning((object)"NoClip: only the lobby host can use this.");
			return;
		}
		PlayerCharacter val = FindLocalPlayer();
		if ((Object)(object)val == (Object)null)
		{
			Plugin.Log.LogWarning((object)"NoClip: local PlayerCharacter not found yet.");
		}
		else
		{
			SetNoClip(!_active, val);
		}
	}

	private void SetNoClip(bool enabled, PlayerCharacter pc = null)
	{
		if (enabled)
		{
			if (IsLobbyHost())
			{
				_target = pc ?? FindLocalPlayer();
				if (!((Object)(object)_target == (Object)null))
				{
					CaptureAndSoftDisable(_target);
					_active = true;
					Plugin.Log.LogInfo((object)"NoClip ON");
				}
			}
		}
		else
		{
			Restore();
			_active = false;
			_target = null;
			Plugin.Log.LogInfo((object)"NoClip OFF");
		}
	}

	private void CaptureAndSoftDisable(PlayerCharacter pc)
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Expected O, but got Unknown
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		bool flag = default(bool);
		try
		{
			Rigidbody rb = pc.rb;
			if ((Object)(object)rb != (Object)null)
			{
				_savedUseGravity = rb.useGravity;
				_savedDetectCollisions = rb.detectCollisions;
				rb.velocity = Vector3.zero;
				rb.useGravity = false;
				rb.detectCollisions = false;
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = Plugin.Log;
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NoClip rigidbody setup: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
			}
			log.LogWarning(val);
		}
		try
		{
			if (pc.mover != null)
			{
				_savedMoverBypassFixed = pc.mover.bypassFixedUpdate;
				_savedIgnoreAirbourne = pc.mover.ignoreAirbourneVelocity;
				pc.mover.bypassFixedUpdate = true;
				pc.mover.bypassUpdate = false;
				pc.mover.ignoreAirbourneVelocity = true;
			}
		}
		catch (Exception ex2)
		{
			ManualLogSource log2 = Plugin.Log;
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(20, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NoClip mover setup: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
			}
			log2.LogWarning(val);
		}
		try
		{
			if (pc.head != null)
			{
				pc.head.bypassUpdate = false;
			}
			pc.bypassUpdate = false;
			pc.bypassLateUpdate = false;
		}
		catch
		{
		}
	}

	private void Restore()
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		PlayerCharacter target = _target;
		if ((Object)(object)target == (Object)null)
		{
			return;
		}
		try
		{
			Rigidbody rb = target.rb;
			if ((Object)(object)rb != (Object)null)
			{
				rb.useGravity = _savedUseGravity;
				rb.detectCollisions = _savedDetectCollisions;
				rb.velocity = Vector3.zero;
			}
		}
		catch
		{
		}
		try
		{
			if (target.mover != null)
			{
				target.mover.bypassFixedUpdate = _savedMoverBypassFixed;
				target.mover.ignoreAirbourneVelocity = _savedIgnoreAirbourne;
			}
		}
		catch
		{
		}
	}

	private void Fly()
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: 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_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: 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_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		PlayerCharacter val = _target ?? FindLocalPlayer();
		if ((Object)(object)val == (Object)null)
		{
			SetNoClip(enabled: false);
			return;
		}
		_target = val;
		try
		{
			if (val.head != null)
			{
				val.head.bypassUpdate = false;
			}
			if (val.mover != null)
			{
				val.mover.bypassUpdate = false;
				val.mover.bypassFixedUpdate = true;
			}
		}
		catch
		{
		}
		Camera main = Camera.main;
		if ((Object)(object)main == (Object)null)
		{
			return;
		}
		Vector3 val2 = Vector3.zero;
		Transform transform = ((Component)main).transform;
		if (Input.GetKey((KeyCode)119))
		{
			val2 += transform.forward;
		}
		if (Input.GetKey((KeyCode)115))
		{
			val2 -= transform.forward;
		}
		if (Input.GetKey((KeyCode)97))
		{
			val2 -= transform.right;
		}
		if (Input.GetKey((KeyCode)100))
		{
			val2 += transform.right;
		}
		if (Input.GetKey((KeyCode)32) || Input.GetKey((KeyCode)101))
		{
			val2 += Vector3.up;
		}
		if (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)113))
		{
			val2 -= Vector3.up;
		}
		try
		{
			Rigidbody rb = val.rb;
			if ((Object)(object)rb != (Object)null)
			{
				rb.useGravity = false;
				rb.detectCollisions = false;
				rb.velocity = Vector3.zero;
			}
		}
		catch
		{
		}
		if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
		{
			return;
		}
		((Vector3)(ref val2)).Normalize();
		float num = Plugin.Speed.Value;
		if (Input.GetKey((KeyCode)304))
		{
			num *= Plugin.FastMultiplier.Value;
		}
		Vector3 val3 = ((Component)val).transform.position + val2 * num * Time.deltaTime;
		((Component)val).transform.position = val3;
		try
		{
			Rigidbody rb2 = val.rb;
			if ((Object)(object)rb2 != (Object)null)
			{
				rb2.position = val3;
			}
		}
		catch
		{
		}
		try
		{
			HouseNetworkTransform houseNetworkTransform = val.houseNetworkTransform;
			if ((Object)(object)houseNetworkTransform != (Object)null)
			{
				houseNetworkTransform.targetPosition = val3;
			}
		}
		catch
		{
		}
	}

	private static PlayerCharacter FindLocalPlayer()
	{
		try
		{
			List<PlayerCharacter> allPlayerCharacters = PlayerCharacter.allPlayerCharacters;
			if (allPlayerCharacters == null)
			{
				return null;
			}
			for (int i = 0; i < allPlayerCharacters.Count; i++)
			{
				PlayerCharacter val = allPlayerCharacters[i];
				if ((Object)(object)val != (Object)null && ((NetworkBehaviour)val).isLocalPlayer)
				{
					return val;
				}
			}
		}
		catch
		{
		}
		return null;
	}

	private static bool IsLobbyHost()
	{
		try
		{
			if (NetworkServer.active || NetworkClient.activeHost || NetworkClient.isHostClient)
			{
				return true;
			}
		}
		catch
		{
		}
		try
		{
			PlayerCharacter val = FindLocalPlayer();
			if ((Object)(object)val != (Object)null && ((NetworkBehaviour)val).isLocalPlayer && (Object)(object)val.playerNetworking != (Object)null && val.playerNetworking.isHost)
			{
				return true;
			}
		}
		catch
		{
		}
		return false;
	}
}
[BepInPlugin("BigWalk.NoClip", "Big Walk NoClip", "1.0.4")]
[BepInProcess("Big Walk.exe")]
public class Plugin : BasePlugin
{
	internal static Plugin Instance;

	internal static ManualLogSource Log;

	public static ConfigEntry<KeyCode> ToggleKey;

	public static ConfigEntry<float> Speed;

	public static ConfigEntry<float> FastMultiplier;

	public static ConfigEntry<bool> ShowHud;

	public override void Load()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Expected O, but got Unknown
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Expected O, but got Unknown
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Expected O, but got Unknown
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BasePlugin)this).Log;
		ToggleKey = ((BasePlugin)this).Config.Bind<KeyCode>("NoClip", "ToggleKey", (KeyCode)110, "Key that toggles noclip on/off. Host only.");
		Speed = ((BasePlugin)this).Config.Bind<float>("NoClip", "Speed", 8f, new ConfigDescription("Base fly speed (units/sec).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 50f), Array.Empty<object>()));
		FastMultiplier = ((BasePlugin)this).Config.Bind<float>("NoClip", "FastMultiplier", 3f, new ConfigDescription("Speed multiplier while holding Left Shift.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
		ShowHud = ((BasePlugin)this).Config.Bind<bool>("NoClip", "ShowHud", true, "Show a small on-screen indicator while noclip is active.");
		((BasePlugin)this).AddComponent<NoClipController>();
		ManualLogSource log = Log;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(46, 3, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Big Walk NoClip");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.4");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded. Host-only. Press ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<KeyCode>(ToggleKey.Value);
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" to toggle noclip.");
		}
		log.LogInfo(val);
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "BigWalk.NoClip";

	public const string PLUGIN_NAME = "Big Walk NoClip";

	public const string PLUGIN_VERSION = "1.0.4";
}