Decompiled source of GravityControl v2.1.1

GravityControl.dll

Decompiled 2 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("GravityControl")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GravityControl")]
[assembly: AssemblyTitle("GravityControl")]
[assembly: AssemblyVersion("1.0.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 GravityControl
{
	[BepInPlugin("tim.peak.gravitycontrol", "Gravity Control", "2.1.0")]
	public class GravityControlPlugin : BaseUnityPlugin
	{
		private const string PluginGuid = "tim.peak.gravitycontrol";

		private const string PluginName = "Gravity Control";

		private const string PluginVersion = "2.1.0";

		private ConfigEntry<KeyCode> _toggleKeyConfig;

		private ConfigEntry<float> _minMultiplierConfig;

		private ConfigEntry<float> _maxMultiplierConfig;

		private bool _menuOpen;

		private Rect _windowRect = new Rect(24f, 24f, 300f, 190f);

		private float _gravityMultiplier = 1f;

		private CharacterMovement _movementTarget;

		private float _origJumpGravity;

		private float _origMaxGravity;

		private bool _hasSnapshot;

		private CursorLockMode _previousCursorLockMode;

		private bool _previousCursorVisible;

		private bool _cursorOverridden;

		private GUISkin _skin;

		private void Awake()
		{
			//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)
			_toggleKeyConfig = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)105, "Key that opens/closes the Gravity Control window. Edit this in the .cfg file (or with a config-manager mod) - it is intentionally not a control inside the window itself.");
			_minMultiplierConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MinGravityMultiplier", -1f, "Lowest value the slider can reach. Negative values reverse gravity.");
			_maxMultiplierConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxGravityMultiplier", 1f, "Highest value the slider can reach.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Gravity Control v2.1.0 loaded. Toggle key: " + ((object)_toggleKeyConfig.Value/*cast due to .constrained prefix*/).ToString()));
		}

		private void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(_toggleKeyConfig.Value))
			{
				_menuOpen = !_menuOpen;
				if (!_menuOpen)
				{
					RestoreCursorState();
				}
			}
			ApplyGravityTuning();
		}

		private void LateUpdate()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (_menuOpen)
			{
				if (!_cursorOverridden)
				{
					_previousCursorLockMode = Cursor.lockState;
					_previousCursorVisible = Cursor.visible;
					_cursorOverridden = true;
				}
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
		}

		private void OnDestroy()
		{
			RestoreGravityDefaults();
			RestoreCursorState();
		}

		private void OnGUI()
		{
			//IL_0015: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//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)
			if (_menuOpen)
			{
				EnsureSkin();
				GUI.depth = 0;
				GUI.backgroundColor = Color.white;
				GUI.color = Color.white;
				GUISkin skin = GUI.skin;
				GUI.skin = _skin;
				_windowRect = GUI.Window(869271, _windowRect, new WindowFunction(DrawWindow), "GRAVITY CONTROL");
				((Rect)(ref _windowRect)).x = Mathf.Clamp(((Rect)(ref _windowRect)).x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref _windowRect)).width));
				((Rect)(ref _windowRect)).y = Mathf.Clamp(((Rect)(ref _windowRect)).y, 0f, Mathf.Max(0f, (float)Screen.height - ((Rect)(ref _windowRect)).height));
				GUI.skin = skin;
			}
		}

		private void DrawWindow(int windowId)
		{
			float num = Mathf.Min(_minMultiplierConfig.Value, _maxMultiplierConfig.Value);
			float num2 = Mathf.Max(_minMultiplierConfig.Value, _maxMultiplierConfig.Value);
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.Space(4f);
			GUILayout.Label($"Multiplier: {_gravityMultiplier:F2}x", _skin.label, Array.Empty<GUILayoutOption>());
			_gravityMultiplier = GUILayout.HorizontalSlider(_gravityMultiplier, num, num2, Array.Empty<GUILayoutOption>());
			GUILayout.Space(10f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("1x", Array.Empty<GUILayoutOption>()))
			{
				_gravityMultiplier = 1f;
			}
			if (GUILayout.Button("0.75x", Array.Empty<GUILayoutOption>()))
			{
				_gravityMultiplier = 0.75f;
			}
			if (GUILayout.Button("0.5x", Array.Empty<GUILayoutOption>()))
			{
				_gravityMultiplier = 0.5f;
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(4f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("0.25x", Array.Empty<GUILayoutOption>()))
			{
				_gravityMultiplier = 0.25f;
			}
			if (GUILayout.Button("0x", Array.Empty<GUILayoutOption>()))
			{
				_gravityMultiplier = 0f;
			}
			if (GUILayout.Button("-1x", Array.Empty<GUILayoutOption>()))
			{
				_gravityMultiplier = -1f;
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(8f);
			GUILayout.Label("v2.1.0", _skin.customStyles[0], Array.Empty<GUILayoutOption>());
			GUILayout.EndVertical();
			GUI.DragWindow();
		}

		private void ApplyGravityTuning()
		{
			Character localCharacter = GetLocalCharacter();
			CharacterMovement val = (((Object)(object)localCharacter != (Object)null) ? localCharacter.refs.movement : null);
			if ((Object)(object)val == (Object)null)
			{
				RestoreGravityDefaults();
				return;
			}
			if ((Object)(object)val != (Object)(object)_movementTarget)
			{
				RestoreGravityDefaults();
				_movementTarget = val;
				_origJumpGravity = val.jumpGravity;
				_origMaxGravity = val.maxGravity;
				_hasSnapshot = true;
			}
			val.jumpGravity = _origJumpGravity * _gravityMultiplier;
			val.maxGravity = _origMaxGravity * _gravityMultiplier;
		}

		private void RestoreGravityDefaults()
		{
			if ((Object)(object)_movementTarget != (Object)null && _hasSnapshot)
			{
				_movementTarget.jumpGravity = _origJumpGravity;
				_movementTarget.maxGravity = _origMaxGravity;
			}
			_movementTarget = null;
			_hasSnapshot = false;
		}

		private static Character GetLocalCharacter()
		{
			if ((Object)(object)Character.localCharacter != (Object)null)
			{
				return Character.localCharacter;
			}
			if (!((Object)(object)Player.localPlayer != (Object)null))
			{
				return null;
			}
			return Player.localPlayer.character;
		}

		private void RestoreCursorState()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (_cursorOverridden)
			{
				Cursor.lockState = _previousCursorLockMode;
				Cursor.visible = _previousCursorVisible;
				_cursorOverridden = false;
			}
		}

		private void EnsureSkin()
		{
			if ((Object)(object)_skin == (Object)null || _skin.window == null || (Object)(object)_skin.window.normal.background == (Object)null)
			{
				_skin = BuildPurpleSkin();
			}
		}

		private static Texture2D MakeTex(int width, int height, Color color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, false);
			((Object)val).hideFlags = (HideFlags)61;
			Color[] array = (Color[])(object)new Color[width * height];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = color;
			}
			val.SetPixels(array);
			val.Apply();
			return val;
		}

		private static Texture2D MakeBorderedTex(Color fill, Color border)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0042: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(8, 8, (TextureFormat)4, false);
			((Object)val).hideFlags = (HideFlags)61;
			Color[] array = (Color[])(object)new Color[64];
			for (int i = 0; i < 8; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					bool flag = j == 0 || i == 0 || j == 7 || i == 7;
					array[i * 8 + j] = (flag ? border : fill);
				}
			}
			val.SetPixels(array);
			val.Apply();
			return val;
		}

		private GUISkin BuildPurpleSkin()
		{
			//IL_0087: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_00e8: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Expected O, but got Unknown
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Expected O, but got Unknown
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Expected O, but got Unknown
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: 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_02bc: Expected O, but got Unknown
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Expected O, but got Unknown
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Expected O, but got Unknown
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Expected O, but got Unknown
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			Color fill = default(Color);
			((Color)(ref fill))..ctor(0.1f, 0.07f, 0.16f, 0.97f);
			Color val = default(Color);
			((Color)(ref val))..ctor(0.58f, 0.36f, 0.95f, 1f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.4f, 0.24f, 0.62f, 1f);
			Color fill2 = default(Color);
			((Color)(ref fill2))..ctor(0.19f, 0.13f, 0.28f, 1f);
			Color fill3 = default(Color);
			((Color)(ref fill3))..ctor(0.3f, 0.19f, 0.46f, 1f);
			Color fill4 = val;
			Color textColor = default(Color);
			((Color)(ref textColor))..ctor(0.9f, 0.85f, 1f, 1f);
			GUISkin val3 = ScriptableObject.CreateInstance<GUISkin>();
			((Object)val3).hideFlags = (HideFlags)61;
			val3.font = GUI.skin.font;
			val3.window = new GUIStyle(GUI.skin.window);
			val3.window.normal.background = MakeBorderedTex(fill, val);
			val3.window.onNormal.background = val3.window.normal.background;
			val3.window.border = new RectOffset(3, 3, 22, 3);
			val3.window.padding = new RectOffset(12, 12, 22, 10);
			val3.window.normal.textColor = textColor;
			val3.window.fontStyle = (FontStyle)1;
			val3.window.fontSize = 13;
			val3.window.alignment = (TextAnchor)1;
			val3.label = new GUIStyle(GUI.skin.label);
			val3.label.normal.textColor = textColor;
			val3.label.fontStyle = (FontStyle)1;
			val3.label.fontSize = 12;
			val3.button = new GUIStyle(GUI.skin.button);
			val3.button.normal.background = MakeBorderedTex(fill2, val2);
			val3.button.hover.background = MakeBorderedTex(fill3, val);
			val3.button.active.background = MakeBorderedTex(fill4, val);
			val3.button.onNormal.background = val3.button.normal.background;
			val3.button.border = new RectOffset(2, 2, 2, 2);
			val3.button.normal.textColor = textColor;
			val3.button.hover.textColor = Color.white;
			val3.button.active.textColor = Color.white;
			val3.button.fontStyle = (FontStyle)1;
			val3.button.padding = new RectOffset(4, 4, 6, 6);
			val3.horizontalSlider = new GUIStyle(GUI.skin.horizontalSlider);
			val3.horizontalSlider.normal.background = MakeBorderedTex(fill2, val2);
			val3.horizontalSlider.fixedHeight = 10f;
			val3.horizontalSliderThumb = new GUIStyle(GUI.skin.horizontalSliderThumb);
			val3.horizontalSliderThumb.normal.background = MakeTex(14, 18, val);
			val3.horizontalSliderThumb.hover.background = MakeTex(14, 18, Color.white);
			val3.horizontalSliderThumb.fixedWidth = 14f;
			val3.horizontalSliderThumb.fixedHeight = 18f;
			GUIStyle val4 = new GUIStyle(GUI.skin.label);
			val4.fontSize = 9;
			val4.normal.textColor = val2;
			val4.alignment = (TextAnchor)8;
			val3.customStyles = (GUIStyle[])(object)new GUIStyle[1] { val4 };
			return val3;
		}
	}
}