Decompiled source of WobblyPhysgun v1.1.0

plugins/WobblyPhysgun.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Wobbly Physgun")]
[assembly: AssemblyDescription("Standalone no-HUD Physgun for Wobbly Life")]
[assembly: AssemblyCompany("Zappyix")]
[assembly: AssemblyProduct("Wobbly Physgun")]
[assembly: ComVisible(false)]
[assembly: Guid("06C70A1B-9FCB-41B2-8D52-3C3773D3D913")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace Zappyix.WobblyLife.Physgun;

internal sealed class FrozenRigidbodyState
{
	internal Rigidbody Body { get; private set; }

	internal bool OriginalIsKinematic { get; private set; }

	internal RigidbodyConstraints OriginalConstraints { get; private set; }

	internal bool OriginalDetectCollisions { get; private set; }

	internal bool OriginalUseGravity { get; private set; }

	internal FrozenRigidbodyState(Rigidbody body, bool originalIsKinematic, RigidbodyConstraints originalConstraints, bool originalDetectCollisions, bool originalUseGravity)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		Body = body;
		OriginalIsKinematic = originalIsKinematic;
		OriginalConstraints = originalConstraints;
		OriginalDetectCollisions = originalDetectCollisions;
		OriginalUseGravity = originalUseGravity;
	}
}
internal sealed class FrozenObjectMarker : MonoBehaviour
{
	private readonly List<FrozenRigidbodyState> states = new List<FrozenRigidbodyState>();

	internal void SaveWholeObjectState(Transform root, Rigidbody specialBody, bool specialIsKinematic, RigidbodyConstraints specialConstraints, bool specialDetectCollisions, bool specialUseGravity)
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		states.Clear();
		if ((Object)(object)root == (Object)null)
		{
			return;
		}
		Rigidbody[] componentsInChildren = ((Component)root).GetComponentsInChildren<Rigidbody>(true);
		foreach (Rigidbody val in componentsInChildren)
		{
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)val == (Object)(object)specialBody)
				{
					states.Add(new FrozenRigidbodyState(val, specialIsKinematic, specialConstraints, specialDetectCollisions, specialUseGravity));
				}
				else
				{
					states.Add(new FrozenRigidbodyState(val, val.isKinematic, val.constraints, val.detectCollisions, val.useGravity));
				}
			}
		}
	}

	internal void FreezeWholeObject()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < states.Count; i++)
		{
			Rigidbody body = states[i].Body;
			if (!((Object)(object)body == (Object)null))
			{
				body.velocity = Vector3.zero;
				body.angularVelocity = Vector3.zero;
				body.detectCollisions = true;
				body.useGravity = false;
				body.isKinematic = false;
				body.constraints = (RigidbodyConstraints)126;
			}
		}
		Physics.SyncTransforms();
	}

	internal void RestoreWholeObject()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < states.Count; i++)
		{
			FrozenRigidbodyState frozenRigidbodyState = states[i];
			Rigidbody body = frozenRigidbodyState.Body;
			if (!((Object)(object)body == (Object)null))
			{
				body.isKinematic = frozenRigidbodyState.OriginalIsKinematic;
				body.constraints = frozenRigidbodyState.OriginalConstraints;
				body.detectCollisions = frozenRigidbodyState.OriginalDetectCollisions;
				body.useGravity = frozenRigidbodyState.OriginalUseGravity;
				body.WakeUp();
			}
		}
		Physics.SyncTransforms();
	}
}
public static class PhysgunBetterWLHubPage
{
	private sealed class UiStyles
	{
		internal readonly GUIStyle Root;

		internal readonly GUIStyle Header;

		internal readonly GUIStyle Panel;

		internal readonly GUIStyle PanelBorder;

		internal readonly GUIStyle AccentBar;

		internal readonly GUIStyle Eyebrow;

		internal readonly GUIStyle Title;

		internal readonly GUIStyle Subtitle;

		internal readonly GUIStyle VersionBadge;

		internal readonly GUIStyle BadgeActive;

		internal readonly GUIStyle BadgeStandby;

		internal readonly GUIStyle BadgeUnavailable;

		internal readonly GUIStyle SectionTitle;

		internal readonly GUIStyle Body;

		internal readonly GUIStyle Muted;

		internal readonly GUIStyle FieldLabel;

		internal readonly GUIStyle FieldValue;

		internal readonly GUIStyle PrimaryButton;

		internal readonly GUIStyle DangerButton;

		internal readonly GUIStyle Segment;

		internal readonly GUIStyle SegmentSelected;

		internal readonly GUIStyle Slider;

		internal readonly GUIStyle SliderThumb;

		internal readonly GUIStyle ToggleRow;

		internal readonly GUIStyle ToggleLabel;

		internal readonly GUIStyle SwitchOn;

		internal readonly GUIStyle SwitchOff;

		internal readonly GUIStyle SwitchKnob;

		internal readonly GUIStyle ControlItem;

		internal readonly GUIStyle ControlKey;

		internal readonly GUIStyle ControlAction;

		internal readonly GUIStyle Info;

		internal UiStyles(float scale)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: 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_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Expected O, but got Unknown
			//IL_046d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Expected O, but got Unknown
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Expected O, but got Unknown
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Expected O, but got Unknown
			//IL_050b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0531: Unknown result type (might be due to invalid IL or missing references)
			//IL_0546: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_0593: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_061a: Unknown result type (might be due to invalid IL or missing references)
			Color color = Rgb(235, 242, 250);
			Color val = Rgb(143, 159, 178);
			Color color2 = Rgb(73, 226, byte.MaxValue);
			Color color3 = Rgb(107, 235, byte.MaxValue);
			Color val2 = Rgb(86, 234, 154);
			Color textColor = Rgb(byte.MaxValue, 105, 125);
			Texture2D background = Texture(Rgb(10, 16, 24));
			Texture2D background2 = Texture(Rgb(15, 25, 37));
			Texture2D background3 = Texture(Rgb(17, 27, 40));
			Texture2D background4 = Texture(Rgb(42, 60, 78));
			Texture2D val3 = Texture(color2);
			Texture2D val4 = Texture(color3);
			Texture2D val5 = Texture(Rgb(42, 188, 218));
			Texture2D val6 = Texture(Rgb(154, 55, 71));
			Texture2D hover = Texture(Rgb(185, 65, 83));
			Texture2D val7 = Texture(Rgb(29, 43, 59));
			Texture2D val8 = Texture(Rgb(38, 55, 73));
			Texture2D val9 = Texture(Rgb(12, 20, 30));
			Texture2D background5 = Texture(Rgb(39, 55, 72));
			Texture2D background6 = Texture(Rgb(240, 247, 252));
			Texture2D background7 = Texture(Rgba(40, 123, 82, 230));
			Texture2D background8 = Texture(Rgb(43, 56, 72));
			Texture2D background9 = Texture(Rgb(74, 48, 56));
			Root = BoxStyle(background);
			Header = BoxStyle(background2);
			Panel = BoxStyle(background3);
			PanelBorder = BoxStyle(background4);
			AccentBar = BoxStyle(val3);
			Eyebrow = LabelStyle(Mathf.RoundToInt(10f * scale), color2, (FontStyle)1, (TextAnchor)3);
			Title = LabelStyle(Mathf.RoundToInt(24f * scale), color, (FontStyle)1, (TextAnchor)3);
			Subtitle = LabelStyle(Mathf.RoundToInt(12f * scale), val, (FontStyle)0, (TextAnchor)3);
			VersionBadge = BadgeStyle(val7, Rgb(187, 202, 218), Mathf.RoundToInt(11f * scale));
			BadgeActive = BadgeStyle(background7, val2, Mathf.RoundToInt(11f * scale));
			BadgeStandby = BadgeStyle(background8, Rgb(174, 188, 203), Mathf.RoundToInt(11f * scale));
			BadgeUnavailable = BadgeStyle(background9, textColor, Mathf.RoundToInt(10f * scale));
			SectionTitle = LabelStyle(Mathf.RoundToInt(12f * scale), Rgb(183, 201, 219), (FontStyle)1, (TextAnchor)3);
			Body = LabelStyle(Mathf.RoundToInt(13f * scale), Rgb(188, 202, 217), (FontStyle)0, (TextAnchor)3);
			Body.wordWrap = true;
			Muted = LabelStyle(Mathf.RoundToInt(12f * scale), val, (FontStyle)2, (TextAnchor)3);
			FieldLabel = LabelStyle(Mathf.RoundToInt(10f * scale), val, (FontStyle)1, (TextAnchor)3);
			FieldValue = LabelStyle(Mathf.RoundToInt(12f * scale), color2, (FontStyle)1, (TextAnchor)5);
			PrimaryButton = ButtonStyle(val3, val4, val5, Rgb(7, 28, 36), Mathf.RoundToInt(12f * scale));
			DangerButton = ButtonStyle(val6, hover, val6, Rgb(byte.MaxValue, 235, 239), Mathf.RoundToInt(12f * scale));
			Segment = ButtonStyle(val9, val8, val7, val, Mathf.RoundToInt(11f * scale));
			SegmentSelected = ButtonStyle(val3, val4, val5, Rgb(7, 28, 36), Mathf.RoundToInt(11f * scale));
			Slider = new GUIStyle(GUI.skin.horizontalSlider);
			Slider.normal.background = background5;
			Slider.fixedHeight = Mathf.Max(5f, Mathf.Round(5f * scale));
			Slider.margin = new RectOffset(0, 0, 0, 0);
			Slider.padding = new RectOffset(0, 0, 0, 0);
			SliderThumb = new GUIStyle(GUI.skin.horizontalSliderThumb);
			SliderThumb.normal.background = val3;
			SliderThumb.hover.background = val4;
			SliderThumb.active.background = val5;
			SliderThumb.fixedWidth = Mathf.Round(14f * scale);
			SliderThumb.fixedHeight = Mathf.Round(18f * scale);
			ToggleRow = ButtonStyle(val9, val8, val8, Color.clear, Mathf.RoundToInt(11f * scale));
			ToggleRow.normal.textColor = Color.clear;
			ToggleRow.hover.textColor = Color.clear;
			ToggleRow.active.textColor = Color.clear;
			ToggleLabel = LabelStyle(Mathf.RoundToInt(12f * scale), Rgb(207, 220, 233), (FontStyle)0, (TextAnchor)3);
			SwitchOn = BoxStyle(Texture(val2));
			SwitchOff = BoxStyle(background5);
			SwitchKnob = BoxStyle(background6);
			ControlItem = BoxStyle(val9);
			ControlKey = LabelStyle(Mathf.RoundToInt(10f * scale), color2, (FontStyle)1, (TextAnchor)4);
			ControlAction = LabelStyle(Mathf.RoundToInt(10f * scale), val, (FontStyle)0, (TextAnchor)4);
			Info = LabelStyle(Mathf.RoundToInt(11f * scale), Rgb(140, 190, 213), (FontStyle)0, (TextAnchor)3);
		}

		private static GUIStyle LabelStyle(int fontSize, Color color, FontStyle fontStyle, TextAnchor alignment)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_0081: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				fontSize = Mathf.Max(9, fontSize),
				fontStyle = fontStyle,
				alignment = alignment
			};
			val.normal.textColor = color;
			val.hover.textColor = color;
			val.focused.textColor = color;
			val.active.textColor = color;
			val.clipping = (TextClipping)1;
			val.padding = new RectOffset(0, 0, 0, 0);
			val.margin = new RectOffset(0, 0, 0, 0);
			return val;
		}

		private static GUIStyle BoxStyle(Texture2D background)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0061: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.box);
			val.normal.background = background;
			val.hover.background = background;
			val.active.background = background;
			val.border = new RectOffset(0, 0, 0, 0);
			val.padding = new RectOffset(0, 0, 0, 0);
			val.margin = new RectOffset(0, 0, 0, 0);
			return val;
		}

		private static GUIStyle BadgeStyle(Texture2D background, Color textColor, int fontSize)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle obj = BoxStyle(background);
			obj.fontSize = Mathf.Max(9, fontSize);
			obj.fontStyle = (FontStyle)1;
			obj.alignment = (TextAnchor)4;
			obj.normal.textColor = textColor;
			return obj;
		}

		private static GUIStyle ButtonStyle(Texture2D normal, Texture2D hover, Texture2D active, Color textColor, int fontSize)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0087: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00de: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.button);
			val.normal.background = normal;
			val.hover.background = hover;
			val.active.background = active;
			val.focused.background = normal;
			val.onNormal.background = active;
			val.onHover.background = hover;
			val.onActive.background = active;
			val.normal.textColor = textColor;
			val.hover.textColor = textColor;
			val.active.textColor = textColor;
			val.focused.textColor = textColor;
			val.fontSize = Mathf.Max(9, fontSize);
			val.fontStyle = (FontStyle)1;
			val.alignment = (TextAnchor)4;
			val.border = new RectOffset(0, 0, 0, 0);
			val.padding = new RectOffset(6, 6, 3, 3);
			val.margin = new RectOffset(0, 0, 0, 0);
			return val;
		}

		private static Texture2D Texture(Color color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false)
			{
				name = "WobblyPhysgunUi",
				hideFlags = (HideFlags)61
			};
			val.SetPixel(0, 0, color);
			val.Apply(false, true);
			return val;
		}

		private static Color Rgb(byte red, byte green, byte blue)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return Color32.op_Implicit(new Color32(red, green, blue, byte.MaxValue));
		}

		private static Color Rgba(byte red, byte green, byte blue, byte alpha)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			return Color32.op_Implicit(new Color32(red, green, blue, alpha));
		}
	}

	public const string BetterWLHubId = "Zap62d6y2ix98987";

	public const string BetterWLModGuid = "zappyix.wobblylife.betterwl.physgun";

	public const string BetterWLPageId = "physgun";

	public const string BetterWLTitle = "Physgun";

	public const int BetterWLOrder = 20;

	private static Vector2 scrollPosition;

	private static UiStyles styles;

	private static GUISkin styleSkin;

	private static float styleScale = -1f;

	public static void DrawBetterWLHubPage(Rect rect, float scale)
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		EnsureStyles(scale);
		float num = Mathf.Max(360f, ((Rect)(ref rect)).width);
		float num2 = Mathf.Max(260f, ((Rect)(ref rect)).height);
		bool flag = num < Px(700f);
		float num3 = (flag ? Px(742f) : Px(570f));
		float num4 = ((num3 > num2) ? Px(18f) : 0f);
		GUI.BeginGroup(rect);
		GUI.Box(new Rect(0f, 0f, num, num2), GUIContent.none, styles.Root);
		Rect val = new Rect(0f, 0f, num, num2);
		Rect val2 = default(Rect);
		((Rect)(ref val2))..ctor(0f, 0f, num - num4, Mathf.Max(num2, num3));
		scrollPosition = GUI.BeginScrollView(val, scrollPosition, val2, false, num3 > num2);
		DrawContent(val2, flag);
		GUI.EndScrollView();
		GUI.EndGroup();
	}

	private static void DrawContent(Rect content, bool compact)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		float num = Px(20f);
		float num2 = Px(12f);
		float num3 = num;
		float num4 = num;
		float num5 = ((Rect)(ref content)).width - num * 2f;
		DrawHeader(new Rect(num3, num4, num5, Px(92f)));
		num4 += Px(92f) + num2;
		DrawPowerCard(new Rect(num3, num4, num5, Px(92f)));
		num4 += Px(92f) + num2;
		if (compact)
		{
			DrawTuningCard(new Rect(num3, num4, num5, Px(166f)));
			num4 += Px(166f) + num2;
			DrawMultiplayerCard(new Rect(num3, num4, num5, Px(166f)));
			num4 += Px(166f) + num2;
		}
		else
		{
			float num6 = (num5 - num2) * 0.5f;
			DrawTuningCard(new Rect(num3, num4, num6, Px(166f)));
			DrawMultiplayerCard(new Rect(num3 + num6 + num2, num4, num6, Px(166f)));
			num4 += Px(166f) + num2;
		}
		DrawControlsCard(new Rect(num3, num4, num5, Px(146f)));
	}

	private static void DrawHeader(Rect rect)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: 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_00c9: 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_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		DrawPanel(rect, styles.Header);
		GUI.Box(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, Px(5f), ((Rect)(ref rect)).height), GUIContent.none, styles.AccentBar);
		float num = ((Rect)(ref rect)).x + Px(22f);
		GUI.Label(new Rect(num, ((Rect)(ref rect)).y + Px(14f), Px(126f), Px(20f)), "PHYSICS TOOL", styles.Eyebrow);
		GUI.Label(new Rect(num, ((Rect)(ref rect)).y + Px(34f), ((Rect)(ref rect)).width - Px(220f), Px(32f)), "WOBBLY PHYSGUN", styles.Title);
		GUI.Label(new Rect(num, ((Rect)(ref rect)).y + Px(67f), ((Rect)(ref rect)).width - Px(210f), Px(18f)), "Precision object control  •  No extra HUD", styles.Subtitle);
		GUI.Box(new Rect(((Rect)(ref rect)).xMax - Px(78f), ((Rect)(ref rect)).y + Px(15f), Px(58f), Px(24f)), "v1.1.0", styles.VersionBadge);
		WobblyPhysgunPlugin instance = WobblyPhysgunPlugin.Instance;
		bool flag = (Object)(object)instance != (Object)null && instance.PhysgunEnabled;
		GUI.Box(new Rect(((Rect)(ref rect)).xMax - Px(118f), ((Rect)(ref rect)).y + Px(51f), Px(98f), Px(25f)), ((Object)(object)instance == (Object)null) ? "UNAVAILABLE" : (flag ? "●  ACTIVE" : "○  STANDBY"), ((Object)(object)instance == (Object)null) ? styles.BadgeUnavailable : (flag ? styles.BadgeActive : styles.BadgeStandby));
	}

	private static void DrawPowerCard(Rect rect)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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_011b: Unknown result type (might be due to invalid IL or missing references)
		DrawPanel(rect, styles.Panel);
		WobblyPhysgunPlugin instance = WobblyPhysgunPlugin.Instance;
		GUI.Label(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(14f), Px(170f), Px(20f)), "MAIN POWER", styles.SectionTitle);
		string text = (((Object)(object)instance == (Object)null) ? "Plugin instance is not available." : ((!instance.PhysgunEnabled) ? "Standby — enable it here or press Ctrl + 0 in game." : "Ready — aim at an object to grab it automatically."));
		GUI.Label(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(42f), ((Rect)(ref rect)).width - Px(236f), Px(36f)), text, styles.Body);
		Rect val = new Rect(((Rect)(ref rect)).xMax - Px(205f), ((Rect)(ref rect)).y + Px(22f), Px(185f), Px(48f));
		bool enabled = GUI.enabled;
		GUI.enabled = (Object)(object)instance != (Object)null;
		bool flag = (Object)(object)instance != (Object)null && instance.PhysgunEnabled;
		if (GUI.Button(val, flag ? "DISABLE PHYSGUN" : "ENABLE PHYSGUN", flag ? styles.DangerButton : styles.PrimaryButton))
		{
			instance.SetPhysgunEnabled(!instance.PhysgunEnabled);
		}
		GUI.enabled = enabled;
	}

	private static void DrawTuningCard(Rect rect)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		DrawPanel(rect, styles.Panel);
		WobblyPhysgunPlugin instance = WobblyPhysgunPlugin.Instance;
		GUI.Label(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(13f), ((Rect)(ref rect)).width - Px(36f), Px(21f)), "TUNING", styles.SectionTitle);
		if ((Object)(object)instance == (Object)null)
		{
			GUI.Label(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(53f), ((Rect)(ref rect)).width - Px(36f), Px(24f)), "Settings unavailable", styles.Muted);
			return;
		}
		DrawSlider(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(45f), ((Rect)(ref rect)).width - Px(36f), Px(43f)), "CAPTURE DISTANCE", instance.CaptureDistance, 10f, 200f, instance.CaptureDistance.ToString("0") + " m", instance.SetCaptureDistance);
		DrawSlider(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(101f), ((Rect)(ref rect)).width - Px(36f), Px(43f)), "ROTATION SPEED", instance.RotationSpeed, 1f, 12f, instance.RotationSpeed.ToString("0.0") + "×", instance.SetRotationSpeed);
	}

	private static void DrawSlider(Rect rect, string label, float value, float minimum, float maximum, string formattedValue, Action<float> setter)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		GUI.Label(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - Px(72f), Px(18f)), label, styles.FieldLabel);
		GUI.Label(new Rect(((Rect)(ref rect)).xMax - Px(72f), ((Rect)(ref rect)).y, Px(72f), Px(18f)), formattedValue, styles.FieldValue);
		float num = GUI.HorizontalSlider(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y + Px(25f), ((Rect)(ref rect)).width, Px(18f)), value, minimum, maximum, styles.Slider, styles.SliderThumb);
		if (Mathf.Abs(num - value) > 0.001f)
		{
			setter(num);
		}
	}

	private static void DrawMultiplayerCard(Rect rect)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		DrawPanel(rect, styles.Panel);
		WobblyPhysgunPlugin instance = WobblyPhysgunPlugin.Instance;
		GUI.Label(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(13f), ((Rect)(ref rect)).width - Px(36f), Px(21f)), "MULTIPLAYER", styles.SectionTitle);
		if ((Object)(object)instance == (Object)null)
		{
			GUI.Label(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(53f), ((Rect)(ref rect)).width - Px(36f), Px(24f)), "Settings unavailable", styles.Muted);
			return;
		}
		GUI.Label(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(43f), ((Rect)(ref rect)).width - Px(36f), Px(18f)), "MOVEMENT MODE", styles.FieldLabel);
		float num = (((Rect)(ref rect)).width - Px(36f) - Px(4f)) * 0.5f;
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(66f), num, Px(34f));
		Rect val2 = new Rect(((Rect)(ref val)).xMax + Px(4f), ((Rect)(ref val)).y, num, ((Rect)(ref val)).height);
		if (GUI.Button(val, "HOST", instance.NonHostMode ? styles.Segment : styles.SegmentSelected))
		{
			instance.SetNonHostMode(value: false);
		}
		if (GUI.Button(val2, "NON-HOST", instance.NonHostMode ? styles.SegmentSelected : styles.Segment))
		{
			instance.SetNonHostMode(value: true);
		}
		DrawToggleRow(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(111f), ((Rect)(ref rect)).width - Px(36f), Px(38f)), "Grab other players", instance.AllowPlayers, instance.SetAllowPlayers);
	}

	private static void DrawToggleRow(Rect rect, string label, bool value, Action<bool> setter)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: 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_011d: Unknown result type (might be due to invalid IL or missing references)
		if (GUI.Button(rect, GUIContent.none, styles.ToggleRow))
		{
			value = !value;
			setter(value);
		}
		GUI.Label(new Rect(((Rect)(ref rect)).x + Px(10f), ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - Px(72f), ((Rect)(ref rect)).height), label, styles.ToggleLabel);
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((Rect)(ref rect)).xMax - Px(51f), ((Rect)(ref rect)).y + Px(9f), Px(41f), Px(20f));
		GUI.Box(val, GUIContent.none, value ? styles.SwitchOn : styles.SwitchOff);
		GUI.Box(new Rect(value ? (((Rect)(ref val)).xMax - Px(18f)) : (((Rect)(ref val)).x + Px(3f)), ((Rect)(ref val)).y + Px(3f), Px(14f), Px(14f)), GUIContent.none, styles.SwitchKnob);
	}

	private static void DrawControlsCard(Rect rect)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: 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)
		DrawPanel(rect, styles.Panel);
		GUI.Label(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(13f), Px(180f), Px(21f)), "QUICK CONTROLS", styles.SectionTitle);
		float num = ((Rect)(ref rect)).width - Px(36f);
		float num2 = Px(8f);
		float num3 = (num - num2 * 4f) / 5f;
		string[] array = new string[5] { "CTRL + 0", "RMB", "CTRL + 8", "TAB + WHEEL", "R + MOUSE" };
		string[] array2 = new string[5] { "Toggle", "Release", "Freeze", "Distance", "Rotate" };
		Rect val = default(Rect);
		for (int i = 0; i < array.Length; i++)
		{
			((Rect)(ref val))..ctor(((Rect)(ref rect)).x + Px(18f) + (float)i * (num3 + num2), ((Rect)(ref rect)).y + Px(43f), num3, Px(54f));
			GUI.Box(val, GUIContent.none, styles.ControlItem);
			GUI.Label(new Rect(((Rect)(ref val)).x + Px(4f), ((Rect)(ref val)).y + Px(7f), ((Rect)(ref val)).width - Px(8f), Px(18f)), array[i], styles.ControlKey);
			GUI.Label(new Rect(((Rect)(ref val)).x + Px(4f), ((Rect)(ref val)).y + Px(28f), ((Rect)(ref val)).width - Px(8f), Px(18f)), array2[i], styles.ControlAction);
		}
		WobblyPhysgunPlugin instance = WobblyPhysgunPlugin.Instance;
		string text = (((Object)(object)instance != (Object)null && instance.NonHostMode) ? "NON-HOST moves only the hit Rigidbody to reduce snap-back." : "HOST moves the complete object root for stable physics.");
		GUI.Label(new Rect(((Rect)(ref rect)).x + Px(18f), ((Rect)(ref rect)).y + Px(109f), ((Rect)(ref rect)).width - Px(36f), Px(22f)), "ⓘ  " + text, styles.Info);
	}

	private static void DrawPanel(Rect rect, GUIStyle panelStyle)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		GUI.Box(rect, GUIContent.none, styles.PanelBorder);
		GUI.Box(new Rect(((Rect)(ref rect)).x + 1f, ((Rect)(ref rect)).y + 1f, ((Rect)(ref rect)).width - 2f, ((Rect)(ref rect)).height - 2f), GUIContent.none, panelStyle);
	}

	private static float Px(float value)
	{
		return Mathf.Round(value * styleScale);
	}

	private static void EnsureStyles(float scale)
	{
		float num = Mathf.Clamp((scale <= 0f) ? 1f : scale, 0.82f, 1.25f);
		if (styles == null || !((Object)(object)styleSkin == (Object)(object)GUI.skin) || !(Mathf.Abs(styleScale - num) < 0.02f))
		{
			styleScale = num;
			styleSkin = GUI.skin;
			styles = new UiStyles(styleScale);
		}
	}
}
internal sealed class PhysgunEngine
{
	private const float MinimumHoldDistance = 1f;

	private const float MaximumHoldDistance = 30f;

	private readonly WobblyPhysgunPlugin plugin;

	private readonly object manipulationInputHandle = new object();

	private Rigidbody heldBody;

	private Transform heldRoot;

	private Vector3 heldLocalOffsetFromRoot;

	private bool heldOriginalIsKinematic;

	private RigidbodyConstraints heldOriginalConstraints;

	private bool heldOriginalDetectCollisions;

	private bool heldOriginalUseGravity;

	private float holdDistance = 3f;

	private bool manipulationInputLocked;

	private PlayerControllerInputManager lockedInputManager;

	private int releasedRootInstanceId;

	internal PhysgunEngine(WobblyPhysgunPlugin plugin)
	{
		this.plugin = plugin;
	}

	internal void Tick()
	{
		if (WobblyPhysgunPlugin.IsFreezeShortcutPressed())
		{
			ToggleFreezeTargetOrHeldObject();
			return;
		}
		if (Input.GetMouseButtonDown(1))
		{
			RememberReleasedRoot();
			ReleaseHeldObject();
			return;
		}
		if ((Object)(object)heldBody == (Object)null)
		{
			SetManipulationInputLocked(locked: false);
			TryAutoPickObjectUnderAim();
			return;
		}
		bool flag = Input.GetKey((KeyCode)9) || Input.GetKey((KeyCode)114);
		SetManipulationInputLocked(flag);
		HandleDistanceChange();
		MoveHeldObject();
		HandleRotation();
	}

	internal void Shutdown()
	{
		releasedRootInstanceId = 0;
		ReleaseHeldObject();
		SetManipulationInputLocked(locked: false);
	}

	internal void ReleaseHeldObject()
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)heldBody == (Object)null)
		{
			heldBody = null;
			heldRoot = null;
			SetManipulationInputLocked(locked: false);
			return;
		}
		Rigidbody val = heldBody;
		if ((Object)(object)FindFrozenMarker(val) == (Object)null)
		{
			val.isKinematic = heldOriginalIsKinematic;
			val.constraints = heldOriginalConstraints;
			val.detectCollisions = heldOriginalDetectCollisions;
			val.useGravity = heldOriginalUseGravity;
			val.WakeUp();
			Physics.SyncTransforms();
		}
		heldBody = null;
		heldRoot = null;
		SetManipulationInputLocked(locked: false);
	}

	private void TryAutoPickObjectUnderAim()
	{
		//IL_0092: 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_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: 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_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: 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_0120: Unknown result type (might be due to invalid IL or missing references)
		Vector3 hitPoint;
		Rigidbody val = TryGetBodyUnderAim(out hitPoint);
		if ((Object)(object)val == (Object)null)
		{
			releasedRootInstanceId = 0;
			return;
		}
		Transform val2 = FindObjectRoot(((Component)val).transform);
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		if (releasedRootInstanceId != 0)
		{
			if (((Object)val2).GetInstanceID() == releasedRootInstanceId)
			{
				return;
			}
			releasedRootInstanceId = 0;
		}
		if (!((Object)(object)FindFrozenMarker(val) != (Object)null))
		{
			heldBody = val;
			heldRoot = val2;
			heldLocalOffsetFromRoot = (((Object)(object)heldRoot == (Object)null) ? Vector3.zero : heldRoot.InverseTransformPoint(((Component)val).transform.position));
			heldOriginalIsKinematic = val.isKinematic;
			heldOriginalConstraints = val.constraints;
			heldOriginalDetectCollisions = val.detectCollisions;
			heldOriginalUseGravity = val.useGravity;
			Camera val3 = TryGetLocalPlayerCamera();
			holdDistance = (((Object)(object)val3 == (Object)null) ? 3f : Vector3.Distance(((Component)val3).transform.position, hitPoint));
			holdDistance = Mathf.Clamp(holdDistance, 1f, 30f);
			val.velocity = Vector3.zero;
			val.angularVelocity = Vector3.zero;
			val.detectCollisions = true;
			val.useGravity = false;
			val.isKinematic = true;
			Physics.SyncTransforms();
		}
	}

	private void HandleDistanceChange()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKey((KeyCode)9))
		{
			float y = Input.mouseScrollDelta.y;
			if (Mathf.Abs(y) > 0.01f)
			{
				holdDistance = Mathf.Clamp(holdDistance + y, 1f, 30f);
			}
		}
	}

	private void MoveHeldObject()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)heldBody == (Object)null))
		{
			Camera val = TryGetLocalPlayerCamera();
			if (!((Object)(object)val == (Object)null))
			{
				Vector3 targetPosition = ((Component)val).transform.position + ((Component)val).transform.forward * holdDistance;
				MoveHeldObjectRoot(targetPosition);
				Physics.SyncTransforms();
			}
		}
	}

	private void HandleRotation()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)heldBody == (Object)null) && Input.GetKey((KeyCode)114))
		{
			float num = Input.GetAxis("Mouse X") * plugin.RotationSpeed;
			float num2 = (0f - Input.GetAxis("Mouse Y")) * plugin.RotationSpeed;
			Quaternion val = Quaternion.AngleAxis(num, Vector3.up) * Quaternion.AngleAxis(num2, Vector3.right);
			if ((Object)(object)heldRoot != (Object)null && !plugin.NonHostMode)
			{
				heldRoot.rotation = val * heldRoot.rotation;
			}
			else
			{
				heldBody.MoveRotation(val * heldBody.rotation);
			}
			Physics.SyncTransforms();
		}
	}

	private void ToggleFreezeTargetOrHeldObject()
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		Rigidbody val = heldBody;
		if ((Object)(object)val == (Object)null)
		{
			val = TryGetBodyUnderAim(out var _);
		}
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Transform val2 = FindObjectRoot(((Component)val).transform);
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		FrozenObjectMarker component = ((Component)val2).GetComponent<FrozenObjectMarker>();
		if ((Object)(object)component == (Object)null)
		{
			component = ((Component)val2).gameObject.AddComponent<FrozenObjectMarker>();
			if ((Object)(object)val == (Object)(object)heldBody)
			{
				component.SaveWholeObjectState(val2, heldBody, heldOriginalIsKinematic, heldOriginalConstraints, heldOriginalDetectCollisions, heldOriginalUseGravity);
			}
			else
			{
				component.SaveWholeObjectState(val2, null, specialIsKinematic: false, (RigidbodyConstraints)0, specialDetectCollisions: true, specialUseGravity: true);
			}
			component.FreezeWholeObject();
			if ((Object)(object)val == (Object)(object)heldBody)
			{
				heldBody = null;
				heldRoot = null;
				SetManipulationInputLocked(locked: false);
			}
		}
		else
		{
			component.RestoreWholeObject();
			Object.Destroy((Object)(object)component);
		}
	}

	private Rigidbody TryGetBodyUnderAim(out Vector3 hitPoint)
	{
		//IL_0001: 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_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: 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)
		hitPoint = Vector3.zero;
		Camera val = TryGetLocalPlayerCamera();
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		RaycastHit[] array = Physics.RaycastAll(val.ScreenPointToRay(new Vector3((float)Screen.width / 2f, (float)Screen.height / 2f, 0f)), plugin.CaptureDistance);
		Array.Sort(array, (RaycastHit left, RaycastHit right) => ((RaycastHit)(ref left)).distance.CompareTo(((RaycastHit)(ref right)).distance));
		for (int num = 0; num < array.Length; num++)
		{
			RaycastHit val2 = array[num];
			if ((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null)
			{
				continue;
			}
			PlayerCharacter componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<PlayerCharacter>();
			if (!((Object)(object)componentInParent != (Object)null) || (plugin.AllowPlayers && !IsLocalPlayerCharacter(componentInParent)))
			{
				Rigidbody rigidbody = ((RaycastHit)(ref val2)).rigidbody;
				if (!((Object)(object)rigidbody == (Object)null))
				{
					hitPoint = ((RaycastHit)(ref val2)).point;
					return rigidbody;
				}
			}
		}
		return null;
	}

	private void MoveHeldObjectRoot(Vector3 targetPosition)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: 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)
		if (!((Object)(object)heldBody == (Object)null))
		{
			if (plugin.NonHostMode)
			{
				heldBody.MovePosition(targetPosition);
				return;
			}
			if ((Object)(object)heldRoot == (Object)null || (Object)(object)heldRoot == (Object)(object)((Component)heldBody).transform)
			{
				heldBody.MovePosition(targetPosition);
				return;
			}
			Vector3 val = heldRoot.TransformPoint(heldLocalOffsetFromRoot);
			Vector3 val2 = targetPosition - val;
			Transform obj = heldRoot;
			obj.position += val2;
			heldBody.MovePosition(targetPosition);
		}
	}

	private static Transform FindObjectRoot(Transform target)
	{
		if ((Object)(object)target == (Object)null)
		{
			return null;
		}
		PlayerCharacter componentInParent = ((Component)target).GetComponentInParent<PlayerCharacter>();
		if ((Object)(object)componentInParent != (Object)null)
		{
			return ((Component)componentInParent).transform;
		}
		WorldDynamicObject componentInParent2 = ((Component)target).GetComponentInParent<WorldDynamicObject>();
		if ((Object)(object)componentInParent2 != (Object)null)
		{
			return ((Component)componentInParent2).transform;
		}
		Transform val = target;
		while ((Object)(object)val != (Object)null)
		{
			if ((Object)(object)((Component)val).GetComponent("WorldDynamicObject") != (Object)null)
			{
				return val;
			}
			val = val.parent;
		}
		return target;
	}

	private static FrozenObjectMarker FindFrozenMarker(Rigidbody body)
	{
		if ((Object)(object)body == (Object)null)
		{
			return null;
		}
		Transform val = FindObjectRoot(((Component)body).transform);
		if (!((Object)(object)val == (Object)null))
		{
			return ((Component)val).GetComponent<FrozenObjectMarker>();
		}
		return null;
	}

	private static bool IsLocalPlayerCharacter(PlayerCharacter playerCharacter)
	{
		if ((Object)(object)playerCharacter == (Object)null)
		{
			return false;
		}
		PlayerController[] array = Object.FindObjectsOfType<PlayerController>();
		foreach (PlayerController val in array)
		{
			if ((Object)(object)val != (Object)null && val.IsLocal() && (Object)(object)val.GetPlayerCharacter() == (Object)(object)playerCharacter)
			{
				return true;
			}
		}
		return false;
	}

	private void SetManipulationInputLocked(bool locked)
	{
		if (manipulationInputLocked == locked)
		{
			return;
		}
		if (locked)
		{
			PlayerControllerInputManager val = TryGetLocalPlayerInputManager();
			if (!((Object)(object)val == (Object)null))
			{
				val.DisablePlayerTransformInput(manipulationInputHandle);
				val.DisableGameplayCameraInput(manipulationInputHandle);
				lockedInputManager = val;
				manipulationInputLocked = true;
			}
		}
		else
		{
			if ((Object)(object)lockedInputManager != (Object)null)
			{
				lockedInputManager.EnablePlayerTransformInput(manipulationInputHandle);
				lockedInputManager.EnableGameplayCameraInput(manipulationInputHandle);
			}
			lockedInputManager = null;
			manipulationInputLocked = false;
		}
	}

	private static PlayerControllerInputManager TryGetLocalPlayerInputManager()
	{
		PlayerController val = FindLocalPlayerController();
		if (!((Object)(object)val == (Object)null))
		{
			return val.GetPlayerControllerInputManager();
		}
		return null;
	}

	private static Camera TryGetLocalPlayerCamera()
	{
		PlayerController val = FindLocalPlayerController();
		if ((Object)(object)val != (Object)null)
		{
			GameplayCamera gameplayCamera = val.GetGameplayCamera();
			if ((Object)(object)gameplayCamera != (Object)null)
			{
				Camera camera = gameplayCamera.GetCamera();
				if ((Object)(object)camera != (Object)null)
				{
					return camera;
				}
			}
		}
		if ((Object)(object)Camera.main != (Object)null && ((Behaviour)Camera.main).enabled && ((Component)Camera.main).gameObject.activeInHierarchy)
		{
			return Camera.main;
		}
		Camera[] allCameras = Camera.allCameras;
		foreach (Camera val2 in allCameras)
		{
			if ((Object)(object)val2 != (Object)null && ((Behaviour)val2).enabled && ((Component)val2).gameObject.activeInHierarchy && !val2.orthographic)
			{
				return val2;
			}
		}
		return null;
	}

	private static PlayerController FindLocalPlayerController()
	{
		PlayerController[] array = Object.FindObjectsOfType<PlayerController>();
		foreach (PlayerController val in array)
		{
			if ((Object)(object)val != (Object)null && val.IsLocal())
			{
				return val;
			}
		}
		return null;
	}

	private void RememberReleasedRoot()
	{
		if ((Object)(object)heldRoot != (Object)null)
		{
			releasedRootInstanceId = ((Object)heldRoot).GetInstanceID();
		}
		else if ((Object)(object)heldBody != (Object)null)
		{
			releasedRootInstanceId = ((Object)((Component)heldBody).transform).GetInstanceID();
		}
	}
}
[BepInPlugin("zappyix.wobblylife.betterwl.physgun", "Wobbly Physgun", "1.1.0")]
public sealed class WobblyPhysgunPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "zappyix.wobblylife.betterwl.physgun";

	public const string PluginName = "Wobbly Physgun";

	public const string PluginVersion = "1.1.0";

	private ConfigEntry<bool> enabledOnStart;

	private ConfigEntry<float> captureDistance;

	private ConfigEntry<float> rotationSpeed;

	private ConfigEntry<bool> allowPlayers;

	private ConfigEntry<bool> nonHostMode;

	private PhysgunEngine engine;

	private bool physgunEnabled;

	internal static WobblyPhysgunPlugin Instance { get; private set; }

	internal bool PhysgunEnabled => physgunEnabled;

	internal float CaptureDistance
	{
		get
		{
			if (captureDistance != null)
			{
				return captureDistance.Value;
			}
			return 100f;
		}
	}

	internal float RotationSpeed
	{
		get
		{
			if (rotationSpeed != null)
			{
				return rotationSpeed.Value;
			}
			return 4f;
		}
	}

	internal bool AllowPlayers
	{
		get
		{
			if (allowPlayers != null)
			{
				return allowPlayers.Value;
			}
			return true;
		}
	}

	internal bool NonHostMode
	{
		get
		{
			if (nonHostMode != null)
			{
				return nonHostMode.Value;
			}
			return false;
		}
	}

	private void Awake()
	{
		Instance = this;
		enabledOnStart = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnabledOnStart", false, "Enable Wobbly Physgun when the game starts.");
		captureDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Physgun", "CaptureDistance", 100f, "Maximum capture distance.");
		rotationSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Physgun", "RotationSpeed", 4f, "Mouse rotation multiplier.");
		allowPlayers = ((BaseUnityPlugin)this).Config.Bind<bool>("Physgun", "AllowOtherPlayers", true, "Allow Physgun to grab other players. The local player is always ignored.");
		nonHostMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Multiplayer", "NonHostMode", false, "Move only the hit Rigidbody instead of the whole WorldDynamicObject root.");
		engine = new PhysgunEngine(this);
		SetPhysgunEnabled(enabledOnStart.Value);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Wobbly Physgun 1.1.0 loaded. Toggle: Ctrl + 0. Freeze: Ctrl + 8.");
	}

	private void Update()
	{
		if (IsToggleShortcutPressed())
		{
			SetPhysgunEnabled(!physgunEnabled);
		}
		if (!physgunEnabled || engine == null)
		{
			return;
		}
		try
		{
			engine.Tick();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Physgun tick failed: " + ex));
			SetPhysgunEnabled(enabled: false);
		}
	}

	private void OnDisable()
	{
		if (engine != null)
		{
			engine.Shutdown();
		}
	}

	private void OnDestroy()
	{
		if (engine != null)
		{
			engine.Shutdown();
		}
		if ((Object)(object)Instance == (Object)(object)this)
		{
			Instance = null;
		}
	}

	private static bool IsToggleShortcutPressed()
	{
		bool num = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
		bool flag = Input.GetKeyDown((KeyCode)48) || Input.GetKeyDown((KeyCode)256);
		return num && flag;
	}

	internal static bool IsFreezeShortcutPressed()
	{
		bool num = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
		bool flag = Input.GetKeyDown((KeyCode)56) || Input.GetKeyDown((KeyCode)264);
		return num && flag;
	}

	internal void SetPhysgunEnabled(bool enabled)
	{
		if (physgunEnabled != enabled)
		{
			physgunEnabled = enabled;
			if (!enabled && engine != null)
			{
				engine.Shutdown();
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Wobbly Physgun " + (enabled ? "enabled." : "disabled.")));
		}
	}

	internal void SetCaptureDistance(float value)
	{
		captureDistance.Value = Mathf.Clamp(value, 10f, 200f);
	}

	internal void SetRotationSpeed(float value)
	{
		rotationSpeed.Value = Mathf.Clamp(value, 1f, 12f);
	}

	internal void SetAllowPlayers(bool value)
	{
		allowPlayers.Value = value;
		if (engine != null)
		{
			engine.ReleaseHeldObject();
		}
	}

	internal void SetNonHostMode(bool value)
	{
		nonHostMode.Value = value;
		if (engine != null)
		{
			engine.ReleaseHeldObject();
		}
	}

	internal void SaveConfiguration()
	{
		((BaseUnityPlugin)this).Config.Save();
	}
}