Decompiled source of FlatPlayerPlus v2.1.0

Mods/FlatPlayerPlus.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using FieldInjector;
using FlatPlayer;
using FlatPlayerPlus;
using FlatPlayerPlus.MonoBehaviours;
using Il2CppSLZ.Bonelab;
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 RagdollPlayer;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Mod), "FlatPlayerPlus", "2.1.0", "HL2H0", "https://thunderstore.io/c/bonelab/p/HL2H0/FlatPlayerPlus/")]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "RagdollPlayer" })]
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HL2H0")]
[assembly: AssemblyProduct("FlatPlayerPlus")]
[assembly: AssemblyFileVersion("2.1.0")]
[assembly: AssemblyInformationalVersion("2.1.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("2.1.0.0")]
[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
	{
		public enum HandLocation
		{
			Right,
			Left
		}

		public const string Version = "2.1.0";

		private static GameObject _uiPrefab;

		public static Page MainPage { get; private set; }

		public static Page GraphicsPage { get; private set; }

		public static Page TogglesPage { get; private set; }

		public static Page UIPage { get; private set; }

		public static Page FlatPlayerPage { get; private set; }

		public static HandLocation ReloadHand
		{
			get
			{
				Save activeSave = DataManager.ActiveSave;
				bool? obj;
				if (activeSave == null)
				{
					obj = null;
				}
				else
				{
					PlayerSettings playerSettings = activeSave.PlayerSettings;
					obj = ((playerSettings != null) ? new bool?(!playerSettings.BeltLocationRight) : null);
				}
				bool? flag = obj;
				return (!flag.GetValueOrDefault(true)) ? HandLocation.Left : HandLocation.Right;
			}
		}

		public static EnumElement FullscreenModeElement { get; private set; }

		public static BoolElement VSyncElement { get; private set; }

		public static FloatElement FOVElement { get; private set; }

		public static IntElement FPSLimit { get; private set; }

		public static BoolElement ToggleRightGripElement { get; private set; }

		public static BoolElement ToggleLeftGripElement { get; private set; }

		public static EnumElement HealthBarPositionElement { get; private set; }

		public static EnumElement AmmoPositionElement { get; private set; }

		public static FloatElement HandsExtendSensitivity { get; private set; }

		public static FloatElement CameraSmoothness { get; private set; }

		public static bool RightGripToggled { get; private set; }

		public static bool LeftGripToggled { get; private set; }

		private static GameObject UI { get; set; }

		public static FPP_UI_Handler UIHandler { get; set; }

		public static bool HasRagdollPlayer => MelonBase.FindMelon("Ragdoll Player", "Lakatrazz") != null;

		private static void ReloadGun()
		{
			Gun componentInHand = Player.GetComponentInHand<Gun>(GetHand());
			Magazine componentInHand2 = Player.GetComponentInHand<Magazine>(GetHand(inverse: true));
			if (Object.op_Implicit((Object)(object)componentInHand) && Object.op_Implicit((Object)(object)componentInHand2) && !componentInHand.HasMagazine())
			{
				((SpawnEvents)componentInHand2).Despawn();
				componentInHand.InstantLoadAsync();
				componentInHand.CompleteSlidePull();
				componentInHand.CompleteSlideReturn();
			}
		}

		private static Hand GetHand(bool inverse = false)
		{
			if (inverse)
			{
				return (ReloadHand == HandLocation.Right) ? Player.LeftHand : Player.RightHand;
			}
			return (ReloadHand == HandLocation.Right) ? Player.RightHand : Player.LeftHand;
		}

		private static void SetupBoneMenu()
		{
			//IL_0006: 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_003d: Expected O, but got Unknown
			//IL_0048: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: 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>)delegate
			{
				ModPreferences.SavePreferences();
			});
			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);
				ModPreferences.SavePreferences();
			});
			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);
				ModPreferences.SavePreferences();
			});
			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_0002: 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);
			AssetBundle val = HelperMethods.LoadEmbeddedAssetBundle(Assembly.GetExecutingAssembly(), "FlatPlayerPlus.Resources.flatplayerplus.pack");
			_uiPrefab = HelperMethods.LoadPersistentAsset<GameObject>(val, "FP+ UI");
		}

		public override void OnInitializeMelon()
		{
			if (MelonBase.FindMelon("FlatPlayer", "LlamasHere") == null)
			{
				((MelonBase)this).LoggerInstance.Warning("FlatPlayer not found! Deinitializing...");
				((MelonBase)this).Unregister("FlatPlayer is required for FlatPlayerPlus to work!", true);
				return;
			}
			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_0085: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			((MelonBase)this).OnLateUpdate();
			if (!FlatBooter.IsReady)
			{
				return;
			}
			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);
			if (Input.GetKeyDown(ModPreferences.ReloadKey.Value))
			{
				ReloadGun();
			}
			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))
			{
				if (HasRagdollPlayer)
				{
					Ragdoll();
				}
				else
				{
					((MelonBase)this).LoggerInstance.Warning("RagdollPlayer not found! It is required for the ragdoll functionality to work");
				}
			}
		}

		private static void Ragdoll()
		{
			RigManager rigManager = Player.RigManager;
			if (!Object.op_Implicit((Object)(object)((rigManager != null) ? rigManager.activeSeat : null)) && !UIRig.Instance.popUpMenu.m_IsCursorShown)
			{
				PhysicsRig physicsRig = Player.PhysicsRig;
				if (!physicsRig.torso.shutdown && physicsRig.ballLocoEnabled)
				{
					RagdollPlayerMod.RagdollRig(rigManager);
				}
				else
				{
					RagdollPlayerMod.UnragdollRig(rigManager);
				}
			}
		}

		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 static 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 { get; private set; }

		public static MelonPreferences_Entry<KeyCode> DriveForwardKey { get; private set; }

		public static MelonPreferences_Entry<KeyCode> RagdollKey { get; private set; }

		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_0083: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_0087: 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;
			}
		}
	}
}