Decompiled source of LethalDeaths v1.0.3

LethalDeaths.dll

Decompiled a year ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalDeaths.Patches;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LethalDeaths")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalDeaths")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2286a8b2-ce93-4e46-8063-5b495e3e1f57")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LethalDeaths
{
	[BepInPlugin("MythicalRev.LethalDeaths", "LethalDeaths", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "MythicalRev.LethalDeaths";

		private const string modName = "LethalDeaths";

		private const string modVersion = "1.0.3";

		private readonly Harmony harmony = new Harmony("MythicalRev.LethalDeaths");

		internal static Plugin Instance;

		public static ManualLogSource mls;

		internal static int maxdeaths = 1;

		public static ConfigEntry<int> deathcountConfSF1;

		public static ConfigEntry<int> deathcountConfSF2;

		public static ConfigEntry<int> deathcountConfSF3;

		public static ConfigEntry<float> deathamountConfSF1;

		public static ConfigEntry<float> deathamountConfSF2;

		public static ConfigEntry<float> deathamountConfSF3;

		public static ConfigEntry<float> deathspeedConfSF1;

		public static ConfigEntry<float> deathspeedConfSF2;

		public static ConfigEntry<float> deathspeedConfSF3;

		public static ConfigEntry<bool> weightIncreaseToggle;

		public static ConfigEntry<bool> healthDecreaseToggle;

		public static ConfigEntry<bool> sprintAmoundDecToggle;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("MythicalRev.LethalDeaths");
			mls.LogInfo((object)"LethalDeaths Enabled");
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(SaveFileUISlotPatch));
			harmony.PatchAll(typeof(DeleteFilePatch));
			mls.LogInfo((object)"LethalDeaths Patched");
			setupConfigs();
		}

		private void setupConfigs()
		{
			weightIncreaseToggle = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "Weight Increase Enabled", true, "Does Your Weight Increase on Death");
			healthDecreaseToggle = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "Health Decrease Enabled", true, "Does Your Health Decrease on Death");
			sprintAmoundDecToggle = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "Sprint Decrease Enabled", true, "Does Your Sprint Decrease on Death");
			deathcountConfSF1 = ((BaseUnityPlugin)this).Config.Bind<int>("Save Data", "Death Value File 1", 10, "Number Of Deaths Left, MIN 10 - MAX 1");
			deathcountConfSF2 = ((BaseUnityPlugin)this).Config.Bind<int>("Save Data", "Death Value File 2", 10, "Number Of Deaths Left, MIN 10 - MAX 1");
			deathcountConfSF3 = ((BaseUnityPlugin)this).Config.Bind<int>("Save Data", "Death Value File 3", 10, "Number Of Deaths Left, MIN 10 - MAX 1");
			deathamountConfSF1 = ((BaseUnityPlugin)this).Config.Bind<float>("Save Data", "Death Amount File 1", 0f, "Death Count Number, Min 0 - Max 100");
			deathamountConfSF2 = ((BaseUnityPlugin)this).Config.Bind<float>("Save Data", "Death Amount File 2", 0f, "Death Count Number, Min 0 - Max 100");
			deathamountConfSF3 = ((BaseUnityPlugin)this).Config.Bind<float>("Save Data", "Death Amount File 3", 0f, "Death Count Number, Min 0 - Max 100");
			deathspeedConfSF1 = ((BaseUnityPlugin)this).Config.Bind<float>("Save Data", "Death Amount File Sprint 1", 1f, "Death Count Number Sprint, Min 1 - Max 0");
			deathspeedConfSF2 = ((BaseUnityPlugin)this).Config.Bind<float>("Save Data", "Death Amount File Sprint 2", 1f, "Death Count Number Sprint, Min 1 - Max 0");
			deathspeedConfSF3 = ((BaseUnityPlugin)this).Config.Bind<float>("Save Data", "Death Amount File Sprint 3", 1f, "Death Count Number Sprint, Min 1 - Max 1000");
		}
	}
}
namespace LethalDeaths.Patches
{
	[HarmonyPatch(typeof(DeleteFileButton))]
	internal class DeleteFilePatch
	{
		[HarmonyPatch("DeleteFile")]
		[HarmonyPostfix]
		public static void resetDeathOnFileDel(ref int ___fileToDelete)
		{
			if (___fileToDelete == 0)
			{
				Plugin.deathcountConfSF1.Value = 10;
				Plugin.deathamountConfSF1.Value = 0f;
				Plugin.deathspeedConfSF1.Value = 1f;
			}
			else if (___fileToDelete == 1)
			{
				Plugin.deathcountConfSF2.Value = 10;
				Plugin.deathamountConfSF2.Value = 0f;
				Plugin.deathspeedConfSF2.Value = 1f;
			}
			else if (___fileToDelete == 2)
			{
				Plugin.deathcountConfSF3.Value = 10;
				Plugin.deathamountConfSF3.Value = 0f;
				Plugin.deathspeedConfSF3.Value = 1f;
			}
		}
	}
	[HarmonyPatch(typeof(SaveFileUISlot))]
	internal class SaveFileUISlotPatch
	{
		[HarmonyPatch("OnEnable")]
		[HarmonyPostfix]
		public static void setSaveInfoText(ref TextMeshProUGUI ___fileStatsText, ref string ___fileString)
		{
			if (ES3.FileExists(___fileString))
			{
				int num = ES3.Load<int>("GroupCredits", ___fileString, 30);
				int num2 = ES3.Load<int>("Stats_DaysSpent", ___fileString, 0);
				((TMP_Text)___fileStatsText).fontSize = 8f;
				if (___fileString == "LCSaveFile1")
				{
					((TMP_Text)___fileStatsText).text = $"${num}\nDays: {num2}\nHP: {Plugin.deathcountConfSF1.Value * 10}";
				}
				else if (___fileString == "LCSaveFile2")
				{
					((TMP_Text)___fileStatsText).text = $"${num}\nDays: {num2}\nHP: {Plugin.deathcountConfSF2.Value * 10}";
				}
				else if (___fileString == "LCSaveFile3")
				{
					((TMP_Text)___fileStatsText).text = $"${num}\nDays: {num2}\nHP: {Plugin.deathcountConfSF3.Value * 10}";
				}
				else
				{
					Plugin.mls.LogError((object)"No SaveData Found");
				}
			}
			else
			{
				((TMP_Text)___fileStatsText).text = "";
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		internal static bool debounce = true;

		[HarmonyPatch("KillPlayer")]
		[HarmonyPostfix]
		public static void setDeathCountOnDeath()
		{
			GameNetworkManager instance = GameNetworkManager.Instance;
			int saveFileNum = instance.saveFileNum;
			if (debounce)
			{
				return;
			}
			debounce = true;
			switch (saveFileNum)
			{
			case 0:
				if (Plugin.sprintAmoundDecToggle.Value)
				{
					ConfigEntry<float> deathspeedConfSF2 = Plugin.deathspeedConfSF1;
					deathspeedConfSF2.Value -= 0.1f;
				}
				if (Plugin.weightIncreaseToggle.Value)
				{
					ConfigEntry<float> deathamountConfSF2 = Plugin.deathamountConfSF1;
					deathamountConfSF2.Value += 0.1f;
				}
				if (Plugin.healthDecreaseToggle.Value)
				{
					if (Plugin.deathcountConfSF1.Value != 0)
					{
						ConfigEntry<int> deathcountConfSF2 = Plugin.deathcountConfSF1;
						deathcountConfSF2.Value -= 1;
					}
					else
					{
						Plugin.deathcountConfSF1.Value = Plugin.maxdeaths;
					}
				}
				break;
			case 1:
				if (Plugin.sprintAmoundDecToggle.Value)
				{
					ConfigEntry<float> deathspeedConfSF3 = Plugin.deathspeedConfSF2;
					deathspeedConfSF3.Value -= 0.1f;
				}
				if (Plugin.weightIncreaseToggle.Value)
				{
					ConfigEntry<float> deathamountConfSF3 = Plugin.deathamountConfSF2;
					deathamountConfSF3.Value += 0.1f;
				}
				if (Plugin.healthDecreaseToggle.Value)
				{
					if (Plugin.deathcountConfSF2.Value != 0)
					{
						ConfigEntry<int> deathcountConfSF3 = Plugin.deathcountConfSF2;
						deathcountConfSF3.Value -= 1;
					}
					else
					{
						Plugin.deathcountConfSF2.Value = Plugin.maxdeaths;
					}
				}
				break;
			case 2:
				if (Plugin.sprintAmoundDecToggle.Value)
				{
					ConfigEntry<float> deathspeedConfSF = Plugin.deathspeedConfSF3;
					deathspeedConfSF.Value -= 0.1f;
				}
				if (Plugin.weightIncreaseToggle.Value)
				{
					ConfigEntry<float> deathamountConfSF = Plugin.deathamountConfSF3;
					deathamountConfSF.Value += 0.1f;
				}
				if (Plugin.healthDecreaseToggle.Value)
				{
					if (Plugin.deathcountConfSF3.Value != 0)
					{
						ConfigEntry<int> deathcountConfSF = Plugin.deathcountConfSF3;
						deathcountConfSF.Value -= 1;
					}
					else
					{
						Plugin.deathcountConfSF3.Value = Plugin.maxdeaths;
					}
				}
				break;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void maxSprintSet(ref float ___sprintMeter)
		{
			GameNetworkManager instance = GameNetworkManager.Instance;
			switch (instance.saveFileNum)
			{
			case 0:
				if (___sprintMeter > Plugin.deathspeedConfSF1.Value)
				{
					___sprintMeter = Plugin.deathspeedConfSF1.Value;
				}
				break;
			case 1:
				if (___sprintMeter > Plugin.deathspeedConfSF2.Value)
				{
					___sprintMeter = Plugin.deathspeedConfSF2.Value;
				}
				break;
			case 2:
				if (___sprintMeter > Plugin.deathspeedConfSF3.Value)
				{
					___sprintMeter = Plugin.deathspeedConfSF3.Value;
				}
				break;
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("StartGame")]
		[HarmonyPostfix]
		public static void updatePlayerStartHealth()
		{
			GameNetworkManager instance = GameNetworkManager.Instance;
			int saveFileNum = instance.saveFileNum;
			if (PlayerControllerBPatch.debounce)
			{
				PlayerControllerBPatch.debounce = false;
				switch (saveFileNum)
				{
				case 0:
				{
					PlayerControllerB localPlayerController3 = GameNetworkManager.Instance.localPlayerController;
					localPlayerController3.health = Plugin.deathcountConfSF1.Value * 10;
					localPlayerController3.carryWeight += Plugin.deathamountConfSF1.Value;
					localPlayerController3.sprintMeter = Plugin.deathspeedConfSF1.Value;
					break;
				}
				case 1:
				{
					PlayerControllerB localPlayerController2 = GameNetworkManager.Instance.localPlayerController;
					localPlayerController2.health = Plugin.deathcountConfSF2.Value * 10;
					localPlayerController2.carryWeight += Plugin.deathamountConfSF2.Value;
					localPlayerController2.sprintMeter = Plugin.deathspeedConfSF2.Value;
					break;
				}
				case 2:
				{
					PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
					localPlayerController.health = Plugin.deathcountConfSF3.Value * 10;
					localPlayerController.carryWeight += Plugin.deathamountConfSF3.Value;
					localPlayerController.sprintMeter = Plugin.deathspeedConfSF3.Value;
					break;
				}
				}
			}
		}

		[HarmonyPatch("ResetShip")]
		[HarmonyPostfix]
		public static void resetDeathCount()
		{
			GameNetworkManager instance = GameNetworkManager.Instance;
			int saveFileNum = instance.saveFileNum;
			PlayerControllerBPatch.debounce = true;
			switch (saveFileNum)
			{
			case 0:
				Plugin.deathcountConfSF1.Value = 10;
				Plugin.deathamountConfSF1.Value = 0f;
				Plugin.deathspeedConfSF1.Value = 1f;
				break;
			case 1:
				Plugin.deathcountConfSF2.Value = 10;
				Plugin.deathamountConfSF2.Value = 0f;
				Plugin.deathspeedConfSF2.Value = 1f;
				break;
			case 2:
				Plugin.deathcountConfSF3.Value = 10;
				Plugin.deathamountConfSF3.Value = 0f;
				Plugin.deathspeedConfSF3.Value = 1f;
				break;
			}
		}
	}
}