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 RepoEventsBhaptics v2.0.0
RepoEventsBhaptics.dll
Decompiled 3 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Photon.Pun; using UnityEngine; using tact_csharp2; [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 = ".NET Framework 4.8")] [assembly: AssemblyCompany("RepoEventsBhaptics")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("RepoEventsBhaptics")] [assembly: AssemblyTitle("RepoEventsBhaptics")] [assembly: AssemblyVersion("1.0.0.0")] namespace RepoEventsHaptics { [BepInPlugin("com.dylan.repoevents", "REPO bHaptics", "1.0.0")] public class RepoEventsHaptics : BaseUnityPlugin { private static bool isHolding = false; internal static bool FloaterSmashJustHappened = false; internal static bool PlayerJustDied = false; private static string appId = "692b843fe3348ff1af12474b"; private static string sdkKey = "iqYVDIQZUv1ZUA6eq3RS"; private void Awake() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown ((BaseUnityPlugin)this).Logger.LogInfo((object)"RepoEventsHaptics plugin loaded (grab + collision + gun logging + item upgrades)."); Harmony val = new Harmony("com.dylan.repoevents"); val.PatchAll(); try { bool flag = BhapticsSDK2Wrapper.registryAndInit(sdkKey, appId, ""); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"bHaptics SDK v2 registryAndInit success={flag}"); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to authenticate bHaptics SDK v2 wrapper: " + ex.Message)); } PlayerCollision val2 = Object.FindObjectOfType<PlayerCollision>(); if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).gameObject.GetComponent<PlayerCollisionRelay>() == (Object)null) { ((Component)val2).gameObject.AddComponent<PlayerCollisionRelay>(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"PlayerCollisionRelay attached to player."); } } internal static int Play(string eventId) { try { return BhapticsSDK2Wrapper.play(eventId); } catch (Exception ex) { Logger.CreateLogSource("RepoEventsHaptics").LogError((object)("Play failed for " + eventId + ": " + ex.Message)); return -1; } } internal static void Stop(string eventId) { try { BhapticsSDK2Wrapper.stopByEventId(eventId); } catch (Exception ex) { Logger.CreateLogSource("RepoEventsHaptics").LogError((object)("Stop failed for " + eventId + ": " + ex.Message)); } } internal static void OnGrabStarted() { if (!isHolding) { Play("grabfeedback"); isHolding = true; } } internal static void OnGrabEnded() { if (isHolding) { Stop("grabfeedback"); isHolding = false; } } internal static void OnCollisionStarted(Collision collision, PlayerCollision player) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) Play("collisionfeedback"); ContactPoint[] contacts = collision.contacts; for (int i = 0; i < contacts.Length; i++) { ContactPoint val = contacts[i]; Vector3 val2 = ((Component)player).transform.InverseTransformPoint(((ContactPoint)(ref val)).point); Logger.CreateLogSource("RepoEventsHaptics").LogInfo((object)$"Collision START at local {val2} with {((Object)collision.gameObject).name}"); } } internal static void OnCollisionEnded(Collision collision, PlayerCollision player) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) Stop("collisionfeedback"); ContactPoint[] contacts = collision.contacts; for (int i = 0; i < contacts.Length; i++) { ContactPoint val = contacts[i]; Vector3 val2 = ((Component)player).transform.InverseTransformPoint(((ContactPoint)(ref val)).point); Logger.CreateLogSource("RepoEventsHaptics").LogInfo((object)$"Collision END at local {val2} with {((Object)collision.gameObject).name}"); } } internal static void OnGunFired(ItemGun gun) { PhotonView component = ((Component)gun).GetComponent<PhotonView>(); if (!((Object)(object)component == (Object)null) && component.IsMine) { string name = ((Object)gun).name; string eventId = (name.Contains("Shotgun") ? "playershootsshotgun" : (name.Contains("Shockwave") ? "playershootsshockwave" : (name.Contains("Handgun") ? "playershootspistol" : (name.Contains("Stun") ? "playershootsstun" : ((!name.Contains("Laser")) ? "playershootsgeneric" : "playershootslaser"))))); Play(eventId); } } } [HarmonyPatch(typeof(ItemGun), "Shoot")] internal class ItemGunShootPatch { private static void Postfix(ItemGun __instance) { RepoEventsHaptics.OnGunFired(__instance); } } [HarmonyPatch(typeof(PhysGrabObject), "GrabStarted")] internal class GrabStartedPatch { private static void Postfix(PhysGrabObject __instance) { FieldInfo fieldInfo = AccessTools.Field(typeof(PhysGrabObject), "heldByLocalPlayer"); if (fieldInfo != null && (bool)fieldInfo.GetValue(__instance)) { RepoEventsHaptics.OnGrabStarted(); } } } [HarmonyPatch(typeof(PhysGrabObject), "GrabEnded")] internal class GrabEndedPatch { private static void Postfix(PhysGrabObject __instance) { FieldInfo fieldInfo = AccessTools.Field(typeof(PhysGrabObject), "heldByLocalPlayer"); if (fieldInfo != null && (bool)fieldInfo.GetValue(__instance)) { RepoEventsHaptics.OnGrabEnded(); } } } public class PlayerCollisionRelay : MonoBehaviour { private PlayerCollision player; private void Awake() { player = ((Component)this).GetComponent<PlayerCollision>(); } private void OnCollisionEnter(Collision other) { if ((Object)(object)player != (Object)null) { RepoEventsHaptics.OnCollisionStarted(other, player); } } private void OnCollisionExit(Collision other) { if ((Object)(object)player != (Object)null) { RepoEventsHaptics.OnCollisionEnded(other, player); } } } [HarmonyPatch(typeof(ItemUpgrade), "PlayerUpgrade")] internal class ItemUpgradePatch { private static FieldInfo playerIdField; private static void Postfix(ItemUpgrade __instance) { try { ItemToggle component = ((Component)__instance).GetComponent<ItemToggle>(); if ((Object)(object)component == (Object)null) { return; } if (playerIdField == null) { playerIdField = typeof(ItemToggle).GetField("playerTogglePhotonID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? typeof(ItemToggle).GetField("field_Private_Int32_0", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeof(ItemToggle).GetField("field_Public_Int32_0", BindingFlags.Instance | BindingFlags.Public) ?? typeof(ItemToggle).GetField("<playerTogglePhotonID>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic); } if (playerIdField == null) { return; } int num = (int)playerIdField.GetValue(component); PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(num); if ((Object)(object)val == (Object)null) { return; } PhotonView component2 = ((Component)val).GetComponent<PhotonView>(); if (!((Object)(object)component2 == (Object)null) && component2.IsMine) { string name = ((Object)__instance).name; string eventId = "playerupgrade_generic"; if (name.Contains("Tumble Climb")) { eventId = "playerupgrade_tumbleclimb"; } else if (name.Contains("Map Player Count")) { eventId = "playerupgrade_mapcount"; } else if (name.Contains("Sprint Speed")) { eventId = "playerupgrade_sprintspeed"; } else if (name.Contains("Grab Range")) { eventId = "playerupgrade_grabrange"; } else if (name.Contains("Energy")) { eventId = "playerupgrade_energy"; } else if (name.Contains("Grab Strength")) { eventId = "playerupgrade_grabstrength"; } else if (name.Contains("Extra Jump")) { eventId = "playerupgrade_extrajump"; } else if (name.Contains("Health")) { eventId = "playerupgrade_health"; } else if (name.Contains("Tumble Wing")) { eventId = "playerupgrade_tumblewings"; } else if (name.Contains("Tumble Launch")) { eventId = "playerupgrade_tumblelaunch"; } else if (name.Contains("Death Head Battery")) { eventId = "playerupgrade_deadhead"; } else if (name.Contains("Crouch Rest")) { eventId = "playerupgrade_crouchrest"; } RepoEventsHaptics.Play(eventId); } } catch (Exception ex) { Logger.CreateLogSource("RepoEventsHaptics").LogError((object)("ItemUpgradePatch failed: " + ex.Message)); } } } [HarmonyPatch(typeof(PlayerDeathEffects), "Trigger")] internal class PlayerDeathEffectsTriggerPatch { private static void Postfix(PlayerDeathEffects __instance) { try { PlayerAvatar componentInParent = ((Component)__instance).GetComponentInParent<PlayerAvatar>(); if (!((Object)(object)componentInParent == (Object)null)) { PhotonView component = ((Component)componentInParent).GetComponent<PhotonView>(); if (!((Object)(object)component == (Object)null) && component.IsMine) { RepoEventsHaptics.PlayerJustDied = true; Logger.CreateLogSource("RepoEventsHaptics").LogInfo((object)"Local PlayerDeath triggered -> haptic playerdeath"); RepoEventsHaptics.Play("playerdeath"); } } } catch (Exception ex) { Logger.CreateLogSource("RepoEventsHaptics").LogError((object)("PlayerDeathEffectsTriggerPatch failed: " + ex.Message)); } } } [HarmonyPatch(typeof(FloaterAttackLogic), "StateLevitateFixed")] internal class FloaterLevitateLoopPatch { private static void Postfix(FloaterAttackLogic __instance) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Invalid comparison between Unknown and I4 FieldInfo field = typeof(FloaterAttackLogic).GetField("state", BindingFlags.Instance | BindingFlags.NonPublic); FloaterAttackState val = (FloaterAttackState)field.GetValue(__instance); if ((int)val != 1) { return; } FieldInfo field2 = typeof(FloaterAttackLogic).GetField("capturedPlayerAvatars", BindingFlags.Instance | BindingFlags.NonPublic); if (!(field2.GetValue(__instance) is List<PlayerAvatar> list)) { return; } foreach (PlayerAvatar item in list) { if (!((Object)(object)item == (Object)null)) { PhotonView component = ((Component)item).GetComponent<PhotonView>(); if (((Object)(object)component != (Object)null && component.IsMine) || ((Object)(object)PlayerAvatar.instance != (Object)null && (Object)(object)item == (Object)(object)PlayerAvatar.instance)) { RepoEventsHaptics.Play("floater_levitate_loop"); break; } } } } } [HarmonyPatch(typeof(PlayerTumble), "ImpactHurtSet")] internal class FloaterImpactHurtPatch { private static void Postfix(PlayerTumble __instance, object[] __args) { try { RepoEventsHaptics.FloaterSmashJustHappened = true; RepoEventsHaptics.Play("hurt_floater_smash"); } catch { } } } [HarmonyPatch(typeof(EnemyHeartHugger), "StateLure")] internal class HeartHuggerDistanceScaledPullPatch { private static void Postfix(EnemyHeartHugger __instance) { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) object? obj = typeof(EnemyHeartHugger).GetField("currentTarget", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance); PlayerAvatar val = (PlayerAvatar)((obj is PlayerAvatar) ? obj : null); if (!((Object)(object)val == (Object)null)) { PhotonView component = ((Component)val).GetComponent<PhotonView>(); if (((Object)(object)component != (Object)null && component.IsMine) || ((Object)(object)PlayerAvatar.instance != (Object)null && (Object)(object)val == (Object)(object)PlayerAvatar.instance)) { float num = Vector3.Distance(((Component)val).transform.position, ((Component)__instance).transform.position); RepoEventsHaptics.Play("heart_hugger_pull"); } } } } [HarmonyPatch(typeof(PlayerHealth))] public static class GenericHurtHapticPatch { [HarmonyPostfix] [HarmonyPatch("Hurt", new Type[] { typeof(int), typeof(bool), typeof(int) })] public static void Postfix_GenericHurt(PlayerHealth __instance, int damage, bool savingGrace, int enemyIndex) { try { if (damage <= 0) { return; } PhotonView componentInParent = ((Component)__instance).GetComponentInParent<PhotonView>(); if (!((Object)(object)componentInParent == (Object)null) && componentInParent.IsMine) { if (RepoEventsHaptics.FloaterSmashJustHappened) { RepoEventsHaptics.FloaterSmashJustHappened = false; } else if (RepoEventsHaptics.PlayerJustDied) { RepoEventsHaptics.PlayerJustDied = false; } else if (damage < 33) { RepoEventsHaptics.Play("player_hurt_low"); } else if (damage < 67) { RepoEventsHaptics.Play("player_hurt_medium"); } else { RepoEventsHaptics.Play("player_hurt_high"); } } } catch (Exception arg) { Logger.CreateLogSource("RepoEventsHaptics").LogError((object)$"[GenericHurt] Error in Hurt postfix: {arg}"); } } } } namespace tact_csharp2 { public class BhapticsSDK2Wrapper { private const string ModuleName = "bhaptics_library"; [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool registryAndInit(string sdkAPIKey, string workspaceId, string initData); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool registryAndInitHost(string sdkAPIKey, string workspaceId, string initData, string url); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool wsIsConnected(); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern void wsClose(); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool reInitMessage(string sdkAPIKey, string workspaceId, string initData); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern int play(string eventId); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern int playParam(string eventId, int requestId, float intensity, float duration, float angleX, float offsetY); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern void playWithStartTime(string eventId, int requestId, int startMillis, float intensity, float duration, float angleX, float offsetY); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern int playLoop(string eventId, int requestId, float intensity, float duration, float angleX, float offsetY, int interval, int maxCount); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern int pause(string eventId); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool resume(string eventId); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool stop(int requestId); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool stopByEventId(string eventId); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool stopAll(); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool isPlaying(); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool isPlayingByRequestId(int requestId); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool isPlayingByEventId(string eventId); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern int playDot(int requestId, int position, int durationMillis, int[] motors, int size); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern int playWaveform(int requestId, int position, int[] motorValues, int[] playTimeValues, int[] shapeValues, int motorLen); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern int playPath(int requestId, int position, float[] xValues, float[] yValues, int[] intensityValues, int Len); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool isbHapticsConnected(int position); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool ping(string address); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool pingAll(); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool swapPosition(string address); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool setDeviceVsm(string address, int vsm); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr getDeviceInfoJson(); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool isPlayerInstalled(); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool isPlayerRunning(); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool launchPlayer(bool tryLaunch); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern int getEventTime(string eventId); [DllImport("bhaptics_library", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr getHapticMappingsJson(); } }