Decompiled source of VitalShift v1.0.1

Mods/VitalShift.dll

Decompiled 3 hours 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 BoneLib.Notifications;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSystem;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using VitalShift;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "VitalShift", "1.0.1", "jorink", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("VitalShift")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a8eb24cc55830c66ec3cd0afcede55e3130e1dc5")]
[assembly: AssemblyProduct("VitalShift")]
[assembly: AssemblyTitle("VitalShift")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 VitalShift
{
	public class Core : MelonMod
	{
		private MelonPreferences_Category category;

		private MelonPreferences_Entry<bool> EnableModEntry;

		private MelonPreferences_Entry<bool> KnockedEntry;

		private MelonPreferences_Entry<float> KnockedDurationEntry;

		private MelonPreferences_Entry<string> SavedAvatarHigh;

		private MelonPreferences_Entry<string> SavedAvatarMedium;

		private MelonPreferences_Entry<string> SavedAvatarLow;

		private Barcode AvatarHigh;

		private Barcode AvatarMedium;

		private Barcode AvatarLow;

		private Barcode CurrentAvatarSet;

		private float HighHealthThreshold;

		private float MediumHealthThreshold;

		private bool IsKnocked;

		private bool IsDead;

		private bool RagdollingKnocked;

		private bool RagdollingDead;

		private float RagdollKnockedStart;

		private float RagdollDeadStart;

		public override void OnInitializeMelon()
		{
			SetupMelonPreferences();
			SetupBoneMenu();
		}

		private void SetupBoneMenu()
		{
			//IL_000a: 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_002d: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			Page obj = Page.Root.CreatePage("Jorink", Color.magenta, 0, true).CreatePage("VitalShift", Color.red, 0, true);
			obj.CreateBool("Enable Mod", Color.blue, EnableModEntry.Value, (Action<bool>)delegate(bool a)
			{
				EnableModEntry.Value = a;
			});
			obj.CreateBool("Knocked on Death", Color.cyan, KnockedEntry.Value, (Action<bool>)delegate(bool a)
			{
				KnockedEntry.Value = a;
			});
			obj.CreateFloat("Knocked Duration", Color.yellow, KnockedDurationEntry.Value, 1f, 1f, 10f, (Action<float>)delegate(float a)
			{
				KnockedDurationEntry.Value = a;
			});
			obj.CreateFunction("Set High HP Avatar", Color.green, (Action)delegate
			{
				SetAvatarHigh();
			});
			obj.CreateFunction("Set Medium HP Avatar", Color.yellow, (Action)delegate
			{
				SetAvatarMedium();
			});
			obj.CreateFunction("Set Low HP Avatar", Color.red, (Action)delegate
			{
				SetAvatarLow();
			});
			obj.CreateFunction("Save Settings", Color.cyan, (Action)delegate
			{
				MelonPreferences.Save();
			});
		}

		private void SetupMelonPreferences()
		{
			category = MelonPreferences.CreateCategory("VitalShift");
			EnableModEntry = category.CreateEntry<bool>("Enable Mod", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			KnockedEntry = category.CreateEntry<bool>("Knocked on Death", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			KnockedDurationEntry = category.CreateEntry<float>("Knocked Duration", 5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			SavedAvatarHigh = category.CreateEntry<string>("Avatar High", "SLZ.BONELAB.Content.Avatar.FordBW", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			SavedAvatarMedium = category.CreateEntry<string>("Avatar Medium", "SLZ.BONELAB.Content.Avatar.FordBW", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			SavedAvatarLow = category.CreateEntry<string>("Avatar Low", "SLZ.BONELAB.Content.Avatar.FordBW", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			MelonPreferences.Save();
			category.SaveToFile(true);
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			((MelonMod)this).OnSceneWasLoaded(buildIndex, sceneName);
			AvatarHigh = new Barcode(SavedAvatarHigh.Value);
			AvatarMedium = new Barcode(SavedAvatarMedium.Value);
			AvatarLow = new Barcode(SavedAvatarLow.Value);
		}

		public override void OnUpdate()
		{
			((MelonBase)this).OnUpdate();
			if (EnableModEntry.Value)
			{
				SetAvatar();
				Knocked();
				KnockedHandling();
				Unragdoll();
			}
		}

		private void Knocked()
		{
			if (KnockedEntry.Value && !((Object)(object)Player.RigManager == (Object)null) && !IsKnocked && !IsDead && Player.RigManager.health.curr_Health <= 0f)
			{
				Player.RigManager.health.Respawn();
				IsKnocked = true;
			}
		}

		private void KnockedHandling()
		{
			if (IsKnocked)
			{
				RagdollKnocked();
			}
			if (IsDead)
			{
				RagdollDead();
			}
		}

		private void RagdollDead()
		{
			if (!RagdollingDead)
			{
				RagdollingDead = true;
				RagdollDeadStart = Time.time;
				Player.PhysicsRig.ShutdownRig();
				Player.PhysicsRig.RagdollRig();
			}
		}

		private void RagdollKnocked()
		{
			if (Player.RigManager.health.curr_Health <= 0f)
			{
				Player.RigManager.health.Dying(5f);
				IsDead = true;
			}
			if (!RagdollingKnocked)
			{
				RagdollingKnocked = true;
				RagdollKnockedStart = Time.time;
				Player.RigManager.health.curr_Health = MediumHealthThreshold / 2f;
				Player.PhysicsRig.RagdollRig();
				Player.PhysicsRig.DisableBallLoco();
				Player.PhysicsRig.PhysicalLegs();
				Player.PhysicsRig.legLf.ShutdownLimb();
				Player.PhysicsRig.legRt.ShutdownLimb();
			}
		}

		private void Unragdoll()
		{
			//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_0069: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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)
			//IL_0125: 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_0127: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			if (RagdollingDead && Time.time - RagdollDeadStart > 5f)
			{
				Transform transform = Player.PhysicsRig.feet.transform;
				Transform transform2 = Player.PhysicsRig.knee.transform;
				Transform transform3 = ((Component)((Rig)Player.PhysicsRig).m_pelvis).transform;
				Player.PhysicsRig.TurnOnRig();
				Player.PhysicsRig.UnRagdollRig();
				Vector3 position = transform3.position;
				Quaternion rotation = transform3.rotation;
				transform2.SetPositionAndRotation(position, rotation);
				transform.SetPositionAndRotation(position, rotation);
				RagdollingDead = false;
				RagdollingKnocked = false;
				IsDead = false;
				IsKnocked = false;
				Player.RigManager.health.Respawn();
			}
			if (RagdollingKnocked && Time.time - RagdollKnockedStart > KnockedDurationEntry.Value && !IsDead)
			{
				Transform transform4 = Player.PhysicsRig.feet.transform;
				Transform transform5 = Player.PhysicsRig.knee.transform;
				Transform transform6 = ((Component)((Rig)Player.PhysicsRig).m_pelvis).transform;
				Player.PhysicsRig.TurnOnRig();
				Player.PhysicsRig.UnRagdollRig();
				Vector3 position2 = transform6.position;
				Quaternion rotation2 = transform6.rotation;
				transform5.SetPositionAndRotation(position2, rotation2);
				transform4.SetPositionAndRotation(position2, rotation2);
				RagdollingKnocked = false;
				IsKnocked = false;
				Player.RigManager.health.Respawn();
			}
		}

		private void SetAvatar()
		{
			if (!((Object)(object)Player.RigManager == (Object)null) && AvatarHigh.ID != null)
			{
				HighHealthThreshold = Player.RigManager.health.max_Health * 0.7f;
				MediumHealthThreshold = Player.RigManager.health.max_Health * 0.3f;
				Barcode val = null;
				val = ((Player.RigManager.health.curr_Health >= HighHealthThreshold) ? AvatarHigh : ((!(Player.RigManager.health.curr_Health >= MediumHealthThreshold)) ? AvatarLow : AvatarMedium));
				if (CurrentAvatarSet != val)
				{
					Player.RigManager.SwapAvatarCrate(val, false, (Action<bool>)null);
					CurrentAvatarSet = val;
				}
			}
		}

		private void SetAvatarHigh()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0044: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			if (!((Object)(object)Player.RigManager == (Object)null))
			{
				AvatarHigh = ((ScannableReference)Player.RigManager.AvatarCrate).Barcode;
				Notifier.Send(new Notification
				{
					Title = NotificationText.op_Implicit("High avatar set to:"),
					Message = NotificationText.op_Implicit(AvatarHigh.ID),
					Type = (NotificationType)3,
					PopupLength = 1.25f,
					ShowTitleOnPopup = true
				});
				SavedAvatarHigh.Value = ((Object)AvatarHigh).ToString();
				MelonPreferences.Save();
			}
		}

		private void SetAvatarMedium()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0044: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			if (!((Object)(object)Player.RigManager == (Object)null))
			{
				AvatarMedium = ((ScannableReference)Player.RigManager.AvatarCrate).Barcode;
				Notifier.Send(new Notification
				{
					Title = NotificationText.op_Implicit("Medium avatar set to:"),
					Message = NotificationText.op_Implicit(AvatarMedium.ID),
					Type = (NotificationType)3,
					PopupLength = 1.25f,
					ShowTitleOnPopup = true
				});
				SavedAvatarMedium.Value = ((Object)AvatarMedium).ToString();
				MelonPreferences.Save();
			}
		}

		private void SetAvatarLow()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0044: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			if (!((Object)(object)Player.RigManager == (Object)null))
			{
				AvatarLow = ((ScannableReference)Player.RigManager.AvatarCrate).Barcode;
				Notifier.Send(new Notification
				{
					Title = NotificationText.op_Implicit("Low avatar set to:"),
					Message = NotificationText.op_Implicit(AvatarLow.ID),
					Type = (NotificationType)3,
					PopupLength = 1.25f,
					ShowTitleOnPopup = true
				});
				SavedAvatarLow.Value = ((Object)AvatarLow).ToString();
				MelonPreferences.Save();
			}
		}
	}
}