Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of HardcoreDeath v1.4.1
HardcoreDeath.dll
Decompiled 6 months agousing System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Utils; 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("HardcoreDeath")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("HardcoreDeath")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")] [assembly: AssemblyFileVersion("0.0.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.1.0")] namespace HardcoreDeath; public static class Configs { public static ConfigEntry<bool> EnableMod; public static ConfigEntry<bool> RemoveBackups; public static ConfigEntry<bool> RemoveWorld; public static ConfigEntry<bool> EnableMercifulDeath; public static ConfigEntry<int> MercifulDeathCooldown; public static ConfigEntry<int> MercifulDeathDuration; public static ConfigEntry<int> MercifulDeathMinHealth; public static ConfigurationManagerAttributes IsAdminOnly = new ConfigurationManagerAttributes { IsAdminOnly = true }; public static void SetupConfigs(ConfigFile config) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Expected O, but got Unknown //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Expected O, but got Unknown //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Expected O, but got Unknown //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Expected O, but got Unknown EnableMod = config.Bind<bool>("General", GenerateConfigKey("EnableMod"), true, new ConfigDescription("Determines if the mod should run at all. This is important for when switching characters!", (AcceptableValueBase)null, new object[1] { SetOrder(6) })); RemoveBackups = config.Bind<bool>("General", GenerateConfigKey("RemoveBackups"), true, new ConfigDescription("Enable this to also delete the backups.", (AcceptableValueBase)null, new object[1] { SetOrder(5) })); RemoveWorld = config.Bind<bool>("General", GenerateConfigKey("RemoveWorld"), false, new ConfigDescription("Enable this to also delete the world on death.", (AcceptableValueBase)null, new object[1] { SetOrder(4) })); EnableMercifulDeath = config.Bind<bool>("General", GenerateConfigKey("EnableMercifulDeath"), true, new ConfigDescription("If enabled, when receiving a final blow, your health will go down to 1 point instead. Can only be triggered once in a while.", (AcceptableValueBase)null, new object[1] { SetOrder(3) })); MercifulDeathCooldown = config.Bind<int>("General", GenerateConfigKey("MercifulDeathCooldown", "min"), 10, new ConfigDescription("How often, in minutes, the merciful death effect can be triggered (only if enabled).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 60), new object[1] { SetOrder(2) })); MercifulDeathDuration = config.Bind<int>("General", GenerateConfigKey("MercifulDeathDuration", "sec"), 2, new ConfigDescription("Duration, in seconds, you will avoid death once the merciful death effect has been triggered (only if enabled).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 5), new object[1] { SetOrder(1) })); MercifulDeathMinHealth = config.Bind<int>("General", GenerateConfigKey("MercifulDeathMinHealth", "%"), 50, new ConfigDescription("Minimum health, in percentage, a single hit must take from the player in order to trigger merciful death effect.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), new object[1] { SetOrder(0) })); } public static string GenerateConfigKey(string key) { return GenerateConfigKey(key, null); } public static string GenerateConfigKey(string key, string unit) { key = string.Concat(key.Select((char x) => char.IsUpper(x) ? (" " + x) : x.ToString())).TrimStart(new char[1] { ' ' }); if (!string.IsNullOrEmpty(unit)) { key += $" ({unit})"; } return key; } public static ConfigurationManagerAttributes SetOrder(int order, bool isAdvanced = false, bool isAdminOnly = true) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown return new ConfigurationManagerAttributes { Order = order, IsAdvanced = isAdvanced, IsAdminOnly = isAdminOnly }; } } [BepInPlugin("HardcoreDeath", "HardcoreDeath", "1.4.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class HardcoreDeath : BaseUnityPlugin { [HarmonyPatch(typeof(Character), "CustomFixedUpdate")] public static class Character_CustomFixedUpdate_Patch { public static void Postfix(Character __instance) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && (Object)(object)ZNetScene.instance != (Object)null) { if (mercifulDeathCooldown > 0f) { mercifulDeathCooldown -= Time.deltaTime; } if (mercifulDeathDuration > 0f) { mercifulDeathDuration -= Time.deltaTime; } lastHealth = __instance.GetHealth(); } } } [HarmonyPatch(typeof(Player), "OnDeath")] public static class Player_OnDeath_Patch { public static bool Prefix(Player __instance) { if (Configs.EnableMod.Value && Configs.EnableMercifulDeath.Value && (Object)(object)__instance == (Object)(object)Player.m_localPlayer) { if (mercifulDeathCooldown <= 0f) { mercifulDeathCooldown = Configs.MercifulDeathCooldown.Value * 60; mercifulDeathDuration = Configs.MercifulDeathDuration.Value; AvoidDeath(__instance, showMessage: true); return false; } if (mercifulDeathDuration > 0f) { AvoidDeath(__instance); return false; } } return true; } public static void Postfix(Player __instance) { if (!Configs.EnableMod.Value || !((Object)(object)Player.m_localPlayer != (Object)null) || !((Object)(object)Player.m_localPlayer == (Object)(object)__instance)) { return; } if (justTriggeredMercifulDeath) { justTriggeredMercifulDeath = false; return; } characterToRemove = __instance.GetPlayerName(); Logger.LogInfo((object)$"Player '{characterToRemove}' has died. All save files will be deleted..."); if (Configs.RemoveWorld.Value) { worldToRemove = ZNet.World.m_name; Logger.LogInfo((object)$"World '{worldToRemove}' will also be deleted."); } if (Configs.RemoveBackups.Value) { Logger.LogInfo((object)"Backup files will also be removed."); } Game.instance.Logout(false, true); } } [HarmonyPatch(typeof(FejdStartup), "Start")] public static class FejdStartup_Start_Patch { public static void Prefix() { if (!Configs.EnableMod.Value || characterToRemove == null) { return; } SaveWithBackups val = default(SaveWithBackups); if (SaveSystem.TryGetSaveByName(characterToRemove, (SaveDataType)1, ref val) && !val.IsDeleted) { SaveFile[] backupFiles = val.BackupFiles; SaveFile[] allFiles = val.AllFiles; foreach (SaveFile val2 in allFiles) { if (!backupFiles.Contains(val2) || Configs.RemoveBackups.Value) { if (SaveSystem.Delete(val2)) { Logger.LogInfo((object)$"File '{val2.FileName}' deleted."); } else { Logger.LogError((object)$"Error when attempting to delete file '{val2.FileName}'."); } } } if (Configs.RemoveWorld.Value && worldToRemove != null) { SaveWithBackups val3 = default(SaveWithBackups); if (SaveSystem.TryGetSaveByName(worldToRemove, (SaveDataType)0, ref val3) && !val3.IsDeleted) { SaveFile[] backupFiles2 = val3.BackupFiles; SaveFile[] allFiles2 = val3.AllFiles; foreach (SaveFile val4 in allFiles2) { if (!backupFiles2.Contains(val4) || Configs.RemoveBackups.Value) { if (SaveSystem.Delete(val4)) { Logger.LogInfo((object)$"File '{val4.FileName}' deleted."); } else { Logger.LogError((object)$"Error when attempting to delete file '{val4.FileName}'."); } } } } else { Logger.LogError((object)$"Error when attempting to delete world's save data '{worldToRemove}'."); } } } else { Logger.LogError((object)$"Error when attempting to delete player's save data '{characterToRemove}'."); } characterToRemove = null; worldToRemove = null; } } public const string PluginGUID = "HardcoreDeath"; public const string PluginName = "HardcoreDeath"; public const string PluginVersion = "1.4.1"; private static Harmony harmony; private static string characterToRemove = null; private static string worldToRemove = null; private static float lastHealth = -1f; private static float mercifulDeathCooldown = -1f; private static float mercifulDeathDuration = -1f; private static bool justTriggeredMercifulDeath = false; private void Awake() { Configs.SetupConfigs(((BaseUnityPlugin)this).Config); harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "HardcoreDeath"); } private void OnDestroy() { Harmony obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } private static bool CanAvoidDeath(Player player) { if (Configs.EnableMercifulDeath.Value && lastHealth / ((Character)player).GetMaxHealth() >= (float)Configs.MercifulDeathMinHealth.Value / 100f) { return true; } return false; } private static void AvoidDeath(Player player, bool showMessage = false) { if (showMessage) { ((Character)player).Message((MessageType)2, "$msg_softdeath", 0, (Sprite)null); } ((Character)player).GetSEMan().RemoveStatusEffect(SEMan.s_statusEffectLightning, false); ((Character)player).GetSEMan().RemoveStatusEffect(SEMan.s_statusEffectBurning, false); ((Character)player).GetSEMan().RemoveStatusEffect(SEMan.s_statusEffectPoison, false); ((Character)player).GetSEMan().RemoveStatusEffect(SEMan.s_statusEffectFrost, false); ((Character)player).SetHealth(1f); justTriggeredMercifulDeath = true; } }