Decompiled source of GravityFlux v1.0.3

GravityFlux.dll

Decompiled 2 months 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("xrroman")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Silksong mod for adjusting gravity strength and adding a configurable random gravity mode.")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+d5a80b4ccf3ab989e9d9f80f6db7e637334fa81c")]
[assembly: AssemblyProduct("GravityFlux")]
[assembly: AssemblyTitle("GravityFlux")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/xrroman/Silksong-GravityFlux")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Silksong
{
	public static class GravityLogic
	{
		public static bool _initialized = false;

		private static float _modifiedGravityScale = 1f;

		private static bool _isGravityInverted = false;

		private static float _baseGravityScale;

		private static float _baseMaxFallVelocity;

		private static float _baseDefaultGravity;

		private static float _baseAirHangGravity;

		public static bool GetIsGravityInverted => _isGravityInverted;

		public static float GetGravityScale => _modifiedGravityScale;

		public static void Init()
		{
			HeroController instance = HeroController.instance;
			if (!((Object)(object)instance == (Object)null) && !_initialized)
			{
				_baseGravityScale = instance.rb2d.gravityScale;
				_baseMaxFallVelocity = instance.MAX_FALL_VELOCITY;
				_baseDefaultGravity = instance.DEFAULT_GRAVITY;
				_baseAirHangGravity = instance.AIR_HANG_GRAVITY;
				_initialized = true;
			}
		}

		private static void ApplyGravity()
		{
			if (!_initialized)
			{
				Init();
			}
			HeroController instance = HeroController.instance;
			if (!((Object)(object)instance == (Object)null))
			{
				instance.rb2d.gravityScale = _baseGravityScale * _modifiedGravityScale;
				instance.MAX_FALL_VELOCITY = _baseMaxFallVelocity * _modifiedGravityScale;
				instance.DEFAULT_GRAVITY = _baseDefaultGravity * _modifiedGravityScale;
				instance.AIR_HANG_GRAVITY = _baseAirHangGravity * _modifiedGravityScale;
			}
		}

		public static void ResetGravity()
		{
			_modifiedGravityScale = 1f;
			ApplyGravity();
		}

		public static void IncrementGravity()
		{
			_modifiedGravityScale += 0.5f;
			ApplyGravity();
		}

		public static void DecrementGravity()
		{
			if (_modifiedGravityScale <= 0.5f)
			{
				float num = _modifiedGravityScale / 2f;
				_modifiedGravityScale -= num;
			}
			else
			{
				_modifiedGravityScale -= 0.5f;
			}
			ApplyGravity();
		}

		public static void SetRandomGravity()
		{
			ResetGravity();
			_modifiedGravityScale = Random.Range(0.2f, 3f);
			ApplyGravity();
		}
	}
	public class GravityMenu : MonoBehaviour
	{
		private Rect _windowRect = new Rect(100f, 100f, 280f, 420f);

		private bool _randomModeActive;

		private float _timer;

		private float _randomInterval = 10f;

		private string _intervalInput = "10";

		private GUIStyle _highlightStyle;

		public bool IsVisible { get; private set; }

		public void Toggle()
		{
			IsVisible = !IsVisible;
			Cursor.visible = IsVisible;
			Cursor.lockState = (CursorLockMode)((!IsVisible) ? 1 : 0);
		}

		private void Update()
		{
			if (_randomModeActive)
			{
				_timer += Time.deltaTime;
				if (!(_timer < _randomInterval))
				{
					GravityLogic.SetRandomGravity();
					_timer = 0f;
				}
			}
		}

		private void OnGUI()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_007c: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_003c: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (IsVisible)
			{
				if (_highlightStyle == null)
				{
					_highlightStyle = new GUIStyle(GUI.skin.box)
					{
						fontSize = 18,
						fontStyle = (FontStyle)1,
						alignment = (TextAnchor)4
					};
					_highlightStyle.normal.textColor = Color.white;
				}
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)0;
				GUI.depth = 0;
				_windowRect = GUI.Window(0, _windowRect, new WindowFunction(DrawWindow), "GRAVITY CONTROL PANEL");
			}
		}

		private void DrawWindow(int windowID)
		{
			//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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			GUI.backgroundColor = Color.black;
			GUILayout.Space(10f);
			GUILayout.Box($"SCALE: {GravityLogic.GetGravityScale:F2}x", _highlightStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(50f) });
			if (_randomModeActive)
			{
				GUI.color = Color.yellow;
				GUILayout.Label($"Next change in: {_randomInterval - _timer:F1}s", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(20f) });
				GUI.color = Color.white;
			}
			GUILayout.Space(15f);
			if (GUILayout.Button("Increase Gravity", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				GravityLogic.IncrementGravity();
			}
			if (GUILayout.Button("Decrease Gravity", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				GravityLogic.DecrementGravity();
			}
			if (GUILayout.Button("Reset to Default", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				GravityLogic.ResetGravity();
			}
			GUILayout.Space(15f);
			GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
			GUILayout.Label("Interval (s):", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
			_intervalInput = GUILayout.TextField(_intervalInput, 5, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
			if (float.TryParse(_intervalInput, out var result))
			{
				_randomInterval = Mathf.Max(0.5f, result);
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(10f);
			GUI.backgroundColor = (_randomModeActive ? Color.green : Color.grey);
			if (GUILayout.Button(_randomModeActive ? "STOP RANDOM MODE" : "START RANDOM MODE", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(45f) }))
			{
				_randomModeActive = !_randomModeActive;
				if (_randomModeActive)
				{
					_timer = 0f;
					GravityLogic.SetRandomGravity();
				}
			}
			GUILayout.FlexibleSpace();
			GUI.backgroundColor = Color.red;
			if (GUILayout.Button("CLOSE", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(30f) }))
			{
				Toggle();
			}
			GUI.DragWindow();
		}
	}
	[BepInPlugin("io.github.xrroman.GravityFlux", "GravityFlux", "1.0.0")]
	public class SilksongPlugin : BaseUnityPlugin
	{
		public static SilksongPlugin Instance;

		private GravityMenu _menu;

		public const string Id = "io.github.xrroman.GravityFlux";

		public static string Name => "GravityFlux";

		public static string Version => "1.0.0";

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			_menu = ((Component)this).gameObject.AddComponent<GravityMenu>();
			new Harmony("io.github.xrroman.GravityFlux").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Silksong Gravity Mod Loaded!");
		}

		private void Update()
		{
			if (Input.GetKeyDown((KeyCode)284) || (_menu.IsVisible && Input.GetKeyDown((KeyCode)27)))
			{
				_menu.Toggle();
			}
		}
	}
}