Decompiled source of FlatPlayerPlus v2.0.0

Mods/FlatPlayerPlus.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using FieldInjector;
using FlatPlayer;
using FlatPlayerPlus;
using FlatPlayerPlus.MonoBehaviours;
using Il2CppSLZ.Bonelab.SaveData;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Input;
using Il2CppSLZ.Marrow.Pool;
using Il2CppSLZ.VRMK;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Mod), "FlatPlayerPlus", "2.0.0", "HL2H0", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("FlatPlayerPlus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6f5dac3c863f4f4853c6a859f15dcef0a1770eb1")]
[assembly: AssemblyProduct("FlatPlayerPlus")]
[assembly: AssemblyTitle("FlatPlayerPlus")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FlatPlayerPlus
{
	public class Mod : MelonMod
	{
		private enum ReloadHand
		{
			Right,
			Left
		}

		private static Page _mainPage;

		private static Page _graphicsPage;

		private static Page _togglesPage;

		private static Page _uiPage;

		private static Page _flatPlayerPage;

		private static ReloadHand _reloadHand;

		public static EnumElement FullscreenModeElement;

		public static BoolElement VSyncElement;

		public static FloatElement FOVElement;

		public static IntElement FPSLimit;

		public static BoolElement ToggleRightGripElement;

		public static BoolElement ToggleLeftGripElement;

		public static EnumElement HealthBarPositionElement;

		public static EnumElement AmmoPositionElement;

		public static FloatElement HandsExtendSensitivity;

		public static FloatElement CameraSmoothness;

		private static bool _rightGripToggled;

		private static bool _leftGripToggled;

		private static GameObject _uiPrefab;

		private static GameObject _ui;

		public static FPP_UI_Handler UIHandler;

		private static void ReloadGun(ReloadHand reloadHand)
		{
			switch (reloadHand)
			{
			case ReloadHand.Right:
			{
				Gun componentInHand3 = Player.GetComponentInHand<Gun>(Player.RightHand);
				Magazine componentInHand4 = Player.GetComponentInHand<Magazine>(Player.LeftHand);
				if (Object.op_Implicit((Object)(object)componentInHand3) && Object.op_Implicit((Object)(object)componentInHand4) && !componentInHand3.HasMagazine())
				{
					((SpawnEvents)componentInHand4).Despawn();
					componentInHand3.InstantLoadAsync();
					componentInHand3.CompleteSlidePull();
					componentInHand3.CompleteSlideReturn();
				}
				break;
			}
			case ReloadHand.Left:
			{
				Gun componentInHand = Player.GetComponentInHand<Gun>(Player.LeftHand);
				Magazine componentInHand2 = Player.GetComponentInHand<Magazine>(Player.RightHand);
				if ((Object)(object)componentInHand2 != (Object)null && !componentInHand.HasMagazine())
				{
					((SpawnEvents)componentInHand2).Despawn();
					componentInHand.InstantLoadAsync();
					componentInHand.CompleteSlidePull();
					componentInHand.CompleteSlideReturn();
				}
				break;
			}
			}
		}

		private void SetupBoneMenu()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			FPSLimit = new IntElement("FPS Limit", Color.white, 60, 1, 0, int.MaxValue, (Action<int>)delegate(int v)
			{
				Application.targetFrameRate = v;
				ModPreferences.SavePreferences();
			});
			_mainPage = Page.Root.CreatePage("FlatPlayerPlus", Color.green, 0, true);
			_togglesPage = _mainPage.CreatePage("Toggles", Color.yellow, 0, true);
			ToggleRightGripElement = _togglesPage.CreateBool("Toggle Right Grip", Color.white, false, (Action<bool>)delegate
			{
				ModPreferences.SavePreferences();
			});
			ToggleLeftGripElement = _togglesPage.CreateBool("Toggle Left Grip", Color.white, false, (Action<bool>)null);
			_uiPage = _mainPage.CreatePage("UI", Color.magenta, 0, true);
			HealthBarPositionElement = _uiPage.CreateEnum("Health Bar Position", Color.white, (Enum)FPP_UI_Handler.HealthBarUIPosition, (Action<Enum>)delegate(Enum v)
			{
				UIHandler.UpdateUIPosition((FPP_UI_Handler.UIPosition)(object)v, (FPP_UI_Handler.UIPosition)(object)AmmoPositionElement.Value);
			});
			AmmoPositionElement = _uiPage.CreateEnum("Ammo Position", Color.white, (Enum)FPP_UI_Handler.AmmoUIPosition, (Action<Enum>)delegate(Enum v)
			{
				UIHandler.UpdateUIPosition((FPP_UI_Handler.UIPosition)(object)HealthBarPositionElement.Value, (FPP_UI_Handler.UIPosition)(object)v);
			});
			_flatPlayerPage = _mainPage.CreatePage("FlatPlayer Settings", Color.yellow, 0, true);
			HandsExtendSensitivity = _flatPlayerPage.CreateFloat("Hand Extend Sensitivity", Color.white, 0.1f, 0.1f, 0f, 2.1474836E+09f, (Action<float>)delegate
			{
				ModPreferences.SavePreferences();
				FlatBooter.Instance.ReloadConfig();
			});
			CameraSmoothness = _flatPlayerPage.CreateFloat("Camera Smoothness", Color.white, 0.3f, 0.1f, 0f, 1f, (Action<float>)delegate
			{
				ModPreferences.SavePreferences();
				FlatBooter.Instance.ReloadConfig();
			});
			_graphicsPage = _mainPage.CreatePage("Graphics", Color.green, 0, true);
			FOVElement = _graphicsPage.CreateFloat("FOV", Color.white, 90f, 1f, 0f, 2.1474836E+09f, (Action<float>)delegate(float v)
			{
				FlatBooter.MainCamera.fieldOfView = v;
				ModPreferences.SavePreferences();
			});
			FullscreenModeElement = _graphicsPage.CreateEnum("Full Screen Mode", Color.white, (Enum)(object)Screen.fullScreenMode, (Action<Enum>)delegate(Enum v)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				Screen.fullScreenMode = (FullScreenMode)(object)v;
				ModPreferences.SavePreferences();
			});
			VSyncElement = _graphicsPage.CreateBool("V-Sync", Color.white, false, (Action<bool>)delegate(bool v)
			{
				QualitySettings.vSyncCount = (v ? 1 : 0);
				if (v)
				{
					_mainPage.Remove((Element)(object)FPSLimit);
				}
				else
				{
					_mainPage.Add((Element)(object)FPSLimit);
					Application.targetFrameRate = FPSLimit.Value;
				}
				ModPreferences.SavePreferences();
			});
		}

		private static void InitializeBundles()
		{
			SerialisationHandler.Inject<FPP_UI_Handler>(0);
			string text = "FlatPlayerPlus.Resources.flatplayerplus.pack";
			_uiPrefab = HelperMethods.LoadPersistentAsset<GameObject>(HelperMethods.LoadEmbeddedAssetBundle(Assembly.GetExecutingAssembly(), text), "FP+ UI");
		}

		public override void OnInitializeMelon()
		{
			SetupBoneMenu();
			InitializeBundles();
			ModPreferences.CreatePreferences();
			Hooking.OnUIRigCreated += HookingOnOnUIRigCreated;
			Hooking.OnSwitchAvatarPostfix += OnAvatarSwitch;
			((MelonBase)this).LoggerInstance.Msg("FlatPlayer+ 2.0.0 Initialized.");
		}

		private static void OnAvatarSwitch(Avatar obj)
		{
			UIHandler.MaxHealth = Player.RigManager.health.max_Health;
		}

		private static void HookingOnOnUIRigCreated()
		{
			if ((Object)(object)_uiPrefab != (Object)null)
			{
				_ui = Object.Instantiate<GameObject>(_uiPrefab);
				UIHandler = _ui.GetComponent<FPP_UI_Handler>();
				UIHandler.MaxHealth = Player.RigManager.health.max_Health;
				ModPreferences.LoadPreferences();
			}
		}

		public override void OnUpdate()
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			((MelonBase)this).OnLateUpdate();
			if (FlatBooter.IsReady)
			{
				UIHandler.CurrHealth = Player.RigManager.health.curr_Health;
				int lightAmmo = AmmoInventory.Instance._groupCounts["light"];
				int mediumAmmo = AmmoInventory.Instance._groupCounts["medium"];
				int heavyAmmo = AmmoInventory.Instance._groupCounts["heavy"];
				UIHandler.UpdateAmmoText(lightAmmo, mediumAmmo, heavyAmmo);
				_reloadHand = (DataManager.ActiveSave.PlayerSettings.BeltLocationRight ? ReloadHand.Left : ReloadHand.Right);
				if (Input.GetKeyDown(ModPreferences.ReloadKey.Value))
				{
					ReloadGun(_reloadHand);
				}
				if (Input.GetKey(ModPreferences.DriveForwardKey.Value) && Object.op_Implicit((Object)(object)Player.RigManager.activeSeat))
				{
					Player.RightController._thumbstickAxis = new Vector2(0f, 1f);
					Player.LeftController._thumbstickAxis = new Vector2(0f, -1f);
				}
				if (Input.GetKeyDown(ModPreferences.RagdollKey.Value))
				{
					Player.LeftController._thumbstickDown = true;
				}
			}
		}

		public override void OnLateUpdate()
		{
			((MelonBase)this).OnLateUpdate();
			if (FlatBooter.IsReady)
			{
				if (Input.GetMouseButtonDown(0))
				{
					_leftGripToggled = !_leftGripToggled;
				}
				if (Input.GetMouseButtonDown(1))
				{
					_rightGripToggled = !_rightGripToggled;
				}
				int num = (_rightGripToggled ? 1 : 0);
				int num2 = (_leftGripToggled ? 1 : 0);
				if (ToggleRightGripElement.Value)
				{
					((XRController)FlatBooter.RightController).Grip = num;
				}
				if (ToggleLeftGripElement.Value)
				{
					((XRController)FlatBooter.LeftController).Grip = num2;
				}
			}
		}
	}
	public class ModPreferences
	{
		private static MelonPreferences_Category _category;

		private static MelonPreferences_Category _fpCategory;

		private static MelonPreferences_Entry<float> _fpCameraFOV;

		private static MelonPreferences_Entry<float> _fpHandsExtendSensitivity;

		private static MelonPreferences_Entry<float> _fpCameraSmoothness;

		private static MelonPreferences_Entry<FPP_UI_Handler.UIPosition> _healthBarPosition;

		private static MelonPreferences_Entry<FPP_UI_Handler.UIPosition> _ammoPosition;

		private static MelonPreferences_Entry<bool> _toggleLeftGrip;

		private static MelonPreferences_Entry<bool> _toggleRightGrip;

		private static MelonPreferences_Entry<int> _fpsLimit;

		private static MelonPreferences_Entry<FullScreenMode> _fullscreenMode;

		private static MelonPreferences_Entry<bool> _vSync;

		public static MelonPreferences_Entry<KeyCode> ReloadKey;

		public static MelonPreferences_Entry<KeyCode> DriveForwardKey;

		public static MelonPreferences_Entry<KeyCode> RagdollKey;

		public static void CreatePreferences()
		{
			_category = MelonPreferences.CreateCategory("FlatPlayerPlus");
			_fpCategory = MelonPreferences.GetCategory("FlatPlayer");
			_healthBarPosition = _category.CreateEntry<FPP_UI_Handler.UIPosition>("healthBarPosition", FPP_UI_Handler.UIPosition.Top, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_ammoPosition = _category.CreateEntry<FPP_UI_Handler.UIPosition>("ammoPosition", FPP_UI_Handler.UIPosition.Bottom, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_toggleLeftGrip = _category.CreateEntry<bool>("toggleLeftGrip", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_toggleRightGrip = _category.CreateEntry<bool>("toggleRightGrip", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_fpsLimit = _category.CreateEntry<int>("fpsLimit", 60, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_fullscreenMode = _category.CreateEntry<FullScreenMode>("fullscreenMode", (FullScreenMode)1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_vSync = _category.CreateEntry<bool>("vSyncEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			ReloadKey = _category.CreateEntry<KeyCode>("ReloadKey", (KeyCode)114, (string)null, "For more info about key names, go to https://docs.unity3d.com/2021.3/Documentation/ScriptReference/KeyCode.html", false, false, (ValueValidator)null, (string)null);
			DriveForwardKey = _category.CreateEntry<KeyCode>("DriveForward", (KeyCode)119, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			RagdollKey = _category.CreateEntry<KeyCode>("RagdollKey", (KeyCode)306, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_fpCameraFOV = _fpCategory.GetEntry<float>("CameraFOV");
			_fpHandsExtendSensitivity = _fpCategory.GetEntry<float>("HandsExtendSensitivity");
			_fpCameraSmoothness = _fpCategory.GetEntry<float>("CameraSmoothness");
		}

		public static void SavePreferences()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			_healthBarPosition.Value = (FPP_UI_Handler.UIPosition)(object)Mod.HealthBarPositionElement.Value;
			_ammoPosition.Value = (FPP_UI_Handler.UIPosition)(object)Mod.AmmoPositionElement.Value;
			_toggleLeftGrip.Value = Mod.ToggleLeftGripElement.Value;
			_toggleRightGrip.Value = Mod.ToggleRightGripElement.Value;
			_fpsLimit.Value = Mod.FPSLimit.Value;
			_fullscreenMode.Value = (FullScreenMode)(object)Mod.FullscreenModeElement.Value;
			_vSync.Value = Mod.VSyncElement.Value;
			_fpCameraFOV.Value = Mod.FOVElement.Value;
			_fpHandsExtendSensitivity.Value = Mod.HandsExtendSensitivity.Value;
			_fpCameraSmoothness.Value = Mod.CameraSmoothness.Value;
			_fpCategory.SaveToFile(false);
			_category.SaveToFile(false);
		}

		public static void LoadPreferences()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			Mod.HealthBarPositionElement.Value = _healthBarPosition.Value;
			Mod.AmmoPositionElement.Value = _ammoPosition.Value;
			Mod.ToggleLeftGripElement.Value = _toggleLeftGrip.Value;
			Mod.ToggleRightGripElement.Value = _toggleRightGrip.Value;
			Mod.FPSLimit.Value = _fpsLimit.Value;
			Mod.FullscreenModeElement.Value = (Enum)(object)_fullscreenMode.Value;
			Mod.FOVElement.Value = _fpCameraFOV.Value;
			Mod.VSyncElement.Value = _vSync.Value;
			Mod.HandsExtendSensitivity.Value = _fpHandsExtendSensitivity.Value;
			Mod.CameraSmoothness.Value = _fpCameraFOV.Value;
			Mod.UIHandler.UpdateUIPosition(_healthBarPosition.Value, _ammoPosition.Value);
			QualitySettings.vSyncCount = (_vSync.Value ? 1 : 0);
			if (_vSync.Value)
			{
				Application.targetFrameRate = _fpsLimit.Value;
			}
			Screen.fullScreenMode = _fullscreenMode.Value;
			FlatBooter.MainCamera.fieldOfView = _fpCameraFOV.Value;
			FlatBooter.Instance.ReloadConfig();
		}
	}
}
namespace FlatPlayerPlus.MonoBehaviours
{
	public class FPP_UI_Handler : MonoBehaviour
	{
		public enum UIPosition
		{
			Top,
			Bottom
		}

		public TextMeshProUGUI ammoTextSmall;

		public TextMeshProUGUI ammoTextMedium;

		public TextMeshProUGUI ammoTextLarge;

		public TextMeshProUGUI healthText;

		public Image healthBar;

		public GameObject healthBarUIParent;

		public GameObject ammoUIParent;

		public static UIPosition HealthBarUIPosition { get; set; } = UIPosition.Bottom;


		public static UIPosition AmmoUIPosition { get; set; } = UIPosition.Top;


		public float CurrHealth { get; set; }

		public float MaxHealth { get; set; }

		private void Start()
		{
			((TMP_Text)ammoTextSmall).text = "0";
			((TMP_Text)ammoTextMedium).text = "0";
			((TMP_Text)ammoTextLarge).text = "0";
			CurrHealth = 0f;
		}

		private void Update()
		{
			int num = Mathf.FloorToInt((MaxHealth > 0f) ? (CurrHealth / MaxHealth * 100f) : 0f);
			num = Mathf.Clamp(num, 0, 100);
			((TMP_Text)healthText).text = $"{num}%";
			healthBar.fillAmount = Mathf.Lerp(healthBar.fillAmount, CurrHealth / MaxHealth, Time.deltaTime * 5f);
		}

		public void UpdateAmmoText(int lightAmmo, int mediumAmmo, int heavyAmmo)
		{
			((TMP_Text)ammoTextSmall).text = $"{lightAmmo}";
			((TMP_Text)ammoTextMedium).text = $"{mediumAmmo}";
			((TMP_Text)ammoTextLarge).text = $"{heavyAmmo}";
		}

		public void UpdateUIPosition(UIPosition healthBarPosition, UIPosition ammoPosition)
		{
			//IL_0047: 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_0097: 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)
			switch (healthBarPosition)
			{
			case UIPosition.Bottom:
				healthBarUIParent.transform.localPosition = new Vector3(-840f, -450f, 0f);
				break;
			case UIPosition.Top:
				healthBarUIParent.transform.localPosition = new Vector3(-840f, 510f, 0f);
				break;
			}
			switch (ammoPosition)
			{
			case UIPosition.Bottom:
				ammoUIParent.transform.localPosition = new Vector3(750f, -450f, 0f);
				break;
			case UIPosition.Top:
				ammoUIParent.transform.localPosition = new Vector3(750f, 440f, 0f);
				break;
			}
		}
	}
}