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.3")] 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; private static bool Scared = false; private static float nextFearCheck = 0f; private const float fearCheckInterval = 1f; private static void WriteToPort(int x) { try { if (Plugin.serialPort != null && Plugin.serialPort.IsOpen) { Plugin.serialPort.WriteLine(x.ToString()); } else { Debug.LogWarning((object)"The port isn't open dumbass"); } } catch (Exception arg) { Debug.LogError((object)$"Failed to write to serial port: {arg}"); } } [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) { int num = lastHealth - __instance.health; Debug.Log((object)$"DAMAGE DETECTED {num}"); WriteToPort(num); } if (__instance.isPlayerDead && !WasDead) { WriteToPort(150); Debug.Log((object)"150 Death Damage Sent, don't die next time stupid fucking chud"); WasDead = true; } if (!__instance.isPlayerDead && WasDead) { WasDead = false; } lastHealth = __instance.health; if (!(Time.time >= nextFearCheck)) { return; } nextFearCheck = Time.time + 1f; if (!((Object)(object)StartOfRound.Instance == (Object)null)) { float fearLevel = StartOfRound.Instance.fearLevel; if (fearLevel >= 1f && !Scared) { WriteToPort(100); Scared = true; Debug.Log((object)"ahh ghost ahh scared"); } else if (fearLevel < 1f && Scared) { Debug.Log((object)"chill coz"); Scared = false; } } } catch (Exception ex) { Debug.LogError((object)ex); } } } }