using System;
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 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;
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)
{
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")))));
int num = Play(eventId);
}
}
[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(ItemGun), "Shoot")]
internal class ItemGunShootPatch
{
private static void Postfix(ItemGun __instance)
{
RepoEventsHaptics.OnGunFired(__instance);
}
}
[HarmonyPatch(typeof(ItemUpgrade), "PlayerUpgrade")]
internal class ItemUpgradePatch
{
private static void Postfix(ItemUpgrade __instance)
{
try
{
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";
}
else
{
Logger.CreateLogSource("RepoEventsHaptics").LogInfo((object)("[NEW UPGRADE DETECTED] ItemUpgrade activated: " + name));
}
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
{
Logger.CreateLogSource("RepoEventsHaptics").LogInfo((object)"PlayerDeath triggered -> haptic playerdeath");
RepoEventsHaptics.Play("playerdeath");
}
catch (Exception ex)
{
Logger.CreateLogSource("RepoEventsHaptics").LogError((object)("PlayerDeathEffectsTriggerPatch failed: " + ex.Message));
}
}
}
}
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();
}
}