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 DamageMonitor v1.0.2
DamageMonitor.dll
Decompiled 2 years agousing System; using System.Collections; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using GameNetcodeStuff; using HarmonyLib; using TMPro; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("LethalPlugin")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("LethalPlugin")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("0e442c44-8597-4d85-abe7-d8d3cc7d1e3f")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")] [assembly: AssemblyVersion("1.0.0.0")] namespace LethalPlugin; [BepInPlugin("Vrtua.LethalPlugin.pluginX.DamageMonitor", "DamageMonitor", "1.0.1")] public class DamageMonitor : BaseUnityPlugin { private void Awake() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) ((BaseUnityPlugin)this).Logger.LogInfo((object)"Successfully load Patch"); new Harmony("Vrtua.LethalPlugin.plugin.DamageMonitor"); new Harmony("Vrtua.LethalPlugin.pluginX.DamageMonitor").PatchAll(); } } public class GlobalsVar { public static string LastCollideEnemy = "?"; public static int spawnBody; public static Vector3 position = default(Vector3); public static CauseOfDeath cause = (CauseOfDeath)0; } [HarmonyPatch(typeof(PlayerControllerB))] [HarmonyPatch("DamagePlayer", new Type[] { typeof(int), typeof(bool), typeof(bool), typeof(CauseOfDeath), typeof(int), typeof(bool), typeof(Vector3) })] internal class DamagePatch { public static void Postfix(ref int damageNumber, ref bool hasDamageSFX, ref bool callRPC, ref CauseOfDeath causeOfDeath, ref int deathAnimation, ref bool fallDamage, ref Vector3 force) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) new utils().MakeMessageOnClient(GlobalsVar.LastCollideEnemy, damageNumber, fallDamage, causeOfDeath, Dead: false, spawnbody: false, GameNetworkManager.Instance.localPlayerController.thisPlayerBody.position); } } [HarmonyPatch(typeof(PlayerControllerB))] [HarmonyPatch("KillPlayer")] internal class KillPatch { public static bool Prefix(ref Vector3 bodyVelocity, ref bool spawnBody, ref CauseOfDeath causeOfDeath, ref int deathAnimation, ref Vector3 positionOffset) { //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_000d: Unknown result type (might be due to invalid IL or missing references) GlobalsVar.position = bodyVelocity; GlobalsVar.cause = causeOfDeath; if (spawnBody) { GlobalsVar.spawnBody = 1; } else if (!spawnBody) { GlobalsVar.spawnBody = 0; } return true; } public static void Postfix(PlayerControllerB __instance) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) utils utils2 = new utils(); bool spawnbody = false; if (GlobalsVar.spawnBody == 1) { spawnbody = true; } else if (GlobalsVar.spawnBody == 0) { spawnbody = false; } if (__instance.playerSteamId == GameNetworkManager.Instance.localPlayerController.playerSteamId && GlobalsVar.spawnBody != 2) { utils2.MakeMessageOnClient(GlobalsVar.LastCollideEnemy, 0, isFallDamage: false, GlobalsVar.cause, Dead: true, spawnbody, GlobalsVar.position); } else { GlobalsVar.spawnBody = 2; } } } [HarmonyPatch(typeof(EnemyAI))] [HarmonyPatch("OnCollideWithPlayer")] internal class Patch { public static void Postfix(EnemyAI __instance) { GlobalsVar.LastCollideEnemy = ((Object)((Component)__instance).gameObject).name; if (GlobalsVar.LastCollideEnemy.EndsWith("(Clone)")) { GlobalsVar.LastCollideEnemy = GlobalsVar.LastCollideEnemy.Substring(0, GlobalsVar.LastCollideEnemy.Length - "(Clone)".Length); } ((MonoBehaviour)__instance).StartCoroutine(CheckLastCollideEnemy()); } private static IEnumerator CheckLastCollideEnemy() { string lastEnemy = GlobalsVar.LastCollideEnemy; float checkDuration = 1f; float checkInterval = 0.1f; float elapsedTime = 0f; while (elapsedTime < checkDuration) { yield return (object)new WaitForSeconds(checkInterval); elapsedTime += checkInterval; if (GlobalsVar.LastCollideEnemy != lastEnemy) { yield break; } } GlobalsVar.LastCollideEnemy = "?"; } } internal class utils { public void MakeMessageOnClient(string enemyName, int damage, bool isFallDamage, CauseOfDeath causeOfDeath, bool Dead, bool spawnbody, Vector3 vec) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) HUDManager.Instance.PingHUDElement(HUDManager.Instance.Chat, 4f, 1f, 0.2f); if (HUDManager.Instance.ChatMessageHistory.Count >= 6) { ((TMP_Text)HUDManager.Instance.chatText).text = ((TMP_Text)HUDManager.Instance.chatText).text.Remove(0, HUDManager.Instance.ChatMessageHistory[0].Length); HUDManager.Instance.ChatMessageHistory.RemoveAt(0); } string text = CauseParser(causeOfDeath); string text2; if (Dead) { text2 = "<color=#FF0000>Cause of Death: " + text + "</color>"; text2 = text2 + "\n<color=#00FF00>Spawn Body:</color> <color=#FFFF00>" + (spawnbody ? "Yes" : "No") + "</color>"; text2 += $"\n<color=#00FFFF>X:</color> <color=#FF00FF>{vec.x}</color>, "; text2 += $"<color=#00FFFF>Y:</color> <color=#FF00FF>{vec.y}</color>, "; text2 += $"<color=#00FFFF>Z:</color> <color=#FF00FF>{vec.z}</color>"; } else if (isFallDamage) { text2 = $"<color=#FF4500>Fall damage:</color> <color=#FFD700>{damage}</color>"; } else { int health = GameNetworkManager.Instance.localPlayerController.health; if (health == 0) { return; } text2 = $"<color=#32CD32>{enemyName}</color> <color=#FFA500>dealt:</color> <color=#FFD700>{damage}</color> | <color=#FFB6C1>{health}</color>hp remain"; } int num = (int)(TimeOfDay.Instance.normalizedTimeOfDay * (60f * (float)TimeOfDay.Instance.numberOfHours)) + 360; int num2 = (int)Mathf.Floor((float)(num / 60)); int num3 = num % 60; string text3 = $"{num2:00}:{num3:00}".TrimStart(new char[1] { '0' }); StringBuilder stringBuilder = new StringBuilder(text2); string item = "<size=10><color=#0000FF>[" + text3 + "]</color><color=#00FF00> " + stringBuilder.ToString() + "</color></size>"; HUDManager.Instance.ChatMessageHistory.Add(item); ((TMP_Text)HUDManager.Instance.chatText).text = ""; for (int i = 0; i < HUDManager.Instance.ChatMessageHistory.Count; i++) { TextMeshProUGUI chatText = HUDManager.Instance.chatText; ((TMP_Text)chatText).text = ((TMP_Text)chatText).text + "\n" + HUDManager.Instance.ChatMessageHistory[i]; } GlobalsVar.LastCollideEnemy = "?"; } public bool allow2() { if (!StartOfRound.Instance.allowLocalPlayerDeath) { return false; } if ((Object)(object)GameNetworkManager.Instance.localPlayerController.playersManager.testRoom == (Object)null) { if (StartOfRound.Instance.timeSinceRoundStarted < 2f) { return false; } if (!GameNetworkManager.Instance.localPlayerController.playersManager.shipDoorsEnabled) { return false; } } return true; } private string CauseParser(CauseOfDeath causeOfDeath) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected I4, but got Unknown return (int)causeOfDeath switch { 0 => "Killed by Enemy/Player.", 1 => "Death by bludgeoning.", 2 => "Death by gravity.", 3 => "Death by blast.", 4 => "Death by strangulation.", 5 => "Death by suffocation.", 6 => "Death by mauling.", 7 => "Death by gunshots.", 8 => "Death by crushing.", 9 => "Death by drowning.", 10 => "Abandoned.", 11 => "Death by electrocution.", 12 => "Death by kicking.", 13 => "Death by burning.", 14 => "Death by stabbing.", 15 => "Death by fan.", 16 => "Death by inertia.", 17 => "Death by being snipped.", _ => "Invalid cause of death.", }; } }