using System; using System.Diagnostics; using System.IO.Ports; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Threading; using BepInEx; using BepInEx.Configuration; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")] [assembly: AssemblyCompany("DamageDetector")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("DamageDetector")] [assembly: AssemblyTitle("DamageDetector")] [assembly: AssemblyVersion("1.0.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 DamageDetector { [BepInPlugin("com.thatmanwhousesgithub.damagedetector", "Damage Detector", "1.0.2")] public class Plugin : BaseUnityPlugin { public static SerialPort serialPort; public static ConfigEntry comPort; public static ConfigEntry baudRate; private void Awake() { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Expected O, but got Unknown comPort = ((BaseUnityPlugin)this).Config.Bind("Serial", "COM Port", "COM3", "The COM port used for the Arduino (e.g. COM3, COM4, /dev/ttyUSB0)"); baudRate = ((BaseUnityPlugin)this).Config.Bind("Serial", "Baud Rate", 9600, "Set to same comms speed as arduino"); ((BaseUnityPlugin)this).Logger.LogInfo((object)"PLUGIN LOADED"); try { serialPort = new SerialPort(comPort.Value, baudRate.Value); serialPort.Open(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"SERIAL OPENED"); Thread.Sleep(3000); serialPort.Write("1"); ((BaseUnityPlugin)this).Logger.LogInfo((object)"TEST SENT"); Harmony val = new Harmony("com.thatmanwhousesgithub.damagedetector"); val.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"PATCHED"); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)ex); } } } [HarmonyPatch(typeof(PlayerControllerB), "Update")] internal class DamagePatch { private static int lastHealth = -1; private static bool WasDead = false; [HarmonyPostfix] private static void Postfix(PlayerControllerB __instance) { try { if ((Object)(object)__instance == (Object)null || (Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null || (Object)(object)__instance != (Object)(object)GameNetworkManager.Instance.localPlayerController) { return; } if (lastHealth == -1) { lastHealth = __instance.health; return; } if (__instance.health < lastHealth) { Debug.Log((object)"DAMAGE DETECTED"); int num = lastHealth - __instance.health; if (Plugin.serialPort != null && Plugin.serialPort.IsOpen) { Plugin.serialPort.Write(num.ToString()); Debug.Log((object)$"SENT TO ARDUINO {num}"); } } if (__instance.isPlayerDead && !WasDead && Plugin.serialPort != null && Plugin.serialPort.IsOpen) { Plugin.serialPort.Write(150.ToString()); Debug.Log((object)$"SENT TO ARDUINO {150} LOLOLO enjoy the pain"); WasDead = true; } if (!__instance.isPlayerDead && WasDead) { WasDead = false; } lastHealth = __instance.health; } catch (Exception ex) { Debug.LogError((object)ex); } } } }