using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Rendering;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("SeamlessGrip")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0a8d627fdcf0b223f82f19edc66e11596c735a95")]
[assembly: AssemblyProduct("SeamlessGrip")]
[assembly: AssemblyTitle("SeamlessGrip")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SeamlessGrip;
internal static class AimState
{
private delegate int Query(FVRFireArm firearm);
private static Query s_query;
private static bool s_warnedUnavailable;
private static readonly Dictionary<FVRFireArm, float> s_lastAligned = new Dictionary<FVRFireArm, float>();
private const float Grace = 0.35f;
internal static void Bind()
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int i = 0; i < assemblies.Length; i++)
{
Type type = assemblies[i].GetType("ActionCam.SharedAimState", throwOnError: false);
if ((object)type == null)
{
continue;
}
try
{
MethodInfo method = type.GetMethod("GetState", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(FVRFireArm) }, null);
if ((object)method == null || (object)method.ReturnType != typeof(int))
{
continue;
}
s_query = (Query)Delegate.CreateDelegate(typeof(Query), method);
Plugin.Log.LogInfo((object)"Seamless Grip: using ActionCam's sight alignment (catch held while aiming, eases back after).");
return;
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Seamless Grip: ActionCam's sight alignment could not be read; every catch eases back as before. " + ex.Message));
return;
}
}
Plugin.Log.LogInfo((object)"Seamless Grip: ActionCam not installed; every catch eases back as your hands move (no aim detection).");
}
internal static int Read(FVRFireArm firearm)
{
if ((Object)(object)firearm == (Object)null || s_query == null)
{
return -1;
}
int num;
try
{
num = s_query(firearm);
}
catch (Exception ex)
{
s_query = null;
Plugin.Log.LogWarning((object)("Seamless Grip: ActionCam's sight alignment failed; every catch eases back as before. " + ex.Message));
return -1;
}
if (num < 0)
{
if (!s_warnedUnavailable && Plugin.DebugLog.Value)
{
Plugin.Log.LogInfo((object)"Seamless Grip: ActionCam reports no aim data (aim view off or no player yet); catches ease back as before.");
}
s_warnedUnavailable = true;
return -1;
}
if (num == 1)
{
if (s_lastAligned.Count > 16)
{
s_lastAligned.Clear();
}
s_lastAligned[firearm] = Time.time;
return 1;
}
if (!s_lastAligned.TryGetValue(firearm, out var value) || !(Time.time - value < 0.35f))
{
return 0;
}
return 1;
}
}
internal sealed class GripDebug : MonoBehaviour
{
private FVRPhysicalObject m_gun;
private Grip.State m_state;
private Material m_material;
private readonly List<LineRenderer> m_lines = new List<LineRenderer>();
private readonly List<TextMesh> m_labels = new List<TextMesh>();
private Vector3 m_previousPosition;
private Quaternion m_previousRotation;
private int m_line;
private int m_label;
private const float Gain = 8f;
internal void Setup(FVRPhysicalObject gun, Grip.State state)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Expected O, but got Unknown
m_gun = gun;
m_state = state;
m_previousPosition = ((Component)gun).transform.position;
m_previousRotation = ((Component)gun).transform.rotation;
Shader val = Shader.Find("Sprites/Default");
if ((Object)(object)val == (Object)null)
{
val = Shader.Find("Unlit/Color");
}
if ((Object)(object)val == (Object)null)
{
Plugin.Log.LogWarning((object)"Seamless Grip: motion visualization shader unavailable.");
Object.Destroy((Object)(object)((Component)this).gameObject);
}
else
{
m_material = new Material(val);
}
}
private LineRenderer Line(Color color, int count)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
LineRenderer val;
if (m_line < m_lines.Count)
{
val = m_lines[m_line];
}
else
{
GameObject val2 = new GameObject("MotionLine");
val2.transform.SetParent(((Component)this).transform, false);
val = val2.AddComponent<LineRenderer>();
((Renderer)val).sharedMaterial = m_material;
val.useWorldSpace = true;
val.startWidth = 0.0015f;
val.endWidth = 0.0015f;
((Renderer)val).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)val).receiveShadows = false;
m_lines.Add(val);
}
m_line++;
((Renderer)val).enabled = true;
val.startColor = color;
val.endColor = color;
val.positionCount = count;
return val;
}
private void Segment(Vector3 a, Vector3 b, Color color)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
LineRenderer obj = Line(color, 2);
obj.SetPosition(0, a);
obj.SetPosition(1, b);
}
private void Arrow(Vector3 origin, Vector3 vector, Color color)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
if (!(((Vector3)(ref vector)).sqrMagnitude < 1E-08f))
{
vector = Vector3.ClampMagnitude(vector, 0.2f);
Vector3 val = origin + vector;
Vector3 normalized = ((Vector3)(ref vector)).normalized;
Vector3 val2 = Vector3.Cross(normalized, Vector3.up);
if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
{
val2 = Vector3.Cross(normalized, Vector3.right);
}
((Vector3)(ref val2)).Normalize();
float num = Mathf.Min(0.012f, ((Vector3)(ref vector)).magnitude * 0.25f);
Segment(origin, val, color);
Segment(val, val - normalized * num + val2 * num * 0.5f, color);
Segment(val, val - normalized * num - val2 * num * 0.5f, color);
}
}
private void Axes(Vector3 origin, Quaternion rotation, string name)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: 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_0029: 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_0038: 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)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
Arrow(origin, rotation * Vector3.right * 0.045f, Color.red);
Arrow(origin, rotation * Vector3.up * 0.045f, Color.green);
Arrow(origin, rotation * Vector3.forward * 0.045f, Color.blue);
Label(origin + Vector3.up * 0.055f, name, Color.white);
}
private void Arc(Vector3 center, Vector3 degrees, Color color, float radius)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: 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_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: 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)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
float num = Mathf.Min(160f, ((Vector3)(ref degrees)).magnitude * 8f);
if (!(num < 0.02f))
{
Vector3 normalized = ((Vector3)(ref degrees)).normalized;
Vector3 val = Vector3.Cross(normalized, Vector3.up);
if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
{
val = Vector3.Cross(normalized, Vector3.right);
}
val = ((Vector3)(ref val)).normalized * radius;
LineRenderer val2 = Line(color, 17);
for (int i = 0; i <= 16; i++)
{
val2.SetPosition(i, center + Quaternion.AngleAxis(num * (float)i / 16f, normalized) * val);
}
Vector3 val3 = Quaternion.AngleAxis(num, normalized) * val;
Vector3 origin = center + val3;
Vector3 val4 = Vector3.Cross(normalized, val3);
Arrow(origin, ((Vector3)(ref val4)).normalized * 0.009f, color);
Segment(center, center + normalized * radius * 0.5f, color);
}
}
private void Label(Vector3 position, string text, Color color)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
TextMesh val;
if (m_label < m_labels.Count)
{
val = m_labels[m_label];
}
else
{
GameObject val2 = new GameObject("MotionLabel");
val2.transform.SetParent(((Component)this).transform, false);
val = val2.AddComponent<TextMesh>();
val.fontSize = 32;
val.characterSize = 0.0015f;
val.anchor = (TextAnchor)4;
val.alignment = (TextAlignment)1;
m_labels.Add(val);
}
m_label++;
((Component)val).gameObject.SetActive(true);
val.text = text;
val.color = color;
((Component)val).transform.position = position;
if ((Object)(object)GM.CurrentPlayerBody != (Object)null && (Object)(object)GM.CurrentPlayerBody.Head != (Object)null)
{
((Component)val).transform.rotation = Quaternion.LookRotation(position - GM.CurrentPlayerBody.Head.position, Vector3.up);
}
}
private void LateUpdate()
{
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_0220: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_023a: Unknown result type (might be due to invalid IL or missing references)
//IL_023c: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Unknown result type (might be due to invalid IL or missing references)
//IL_026b: Unknown result type (might be due to invalid IL or missing references)
//IL_0270: Unknown result type (might be due to invalid IL or missing references)
//IL_0275: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_028a: Unknown result type (might be due to invalid IL or missing references)
//IL_0294: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: Unknown result type (might be due to invalid IL or missing references)
//IL_030c: Unknown result type (might be due to invalid IL or missing references)
//IL_0316: Unknown result type (might be due to invalid IL or missing references)
//IL_031b: Unknown result type (might be due to invalid IL or missing references)
//IL_035f: Unknown result type (might be due to invalid IL or missing references)
//IL_036a: Unknown result type (might be due to invalid IL or missing references)
//IL_0390: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)m_gun == (Object)null || (Object)(object)((FVRInteractiveObject)m_gun).m_hand == (Object)null || !Plugin.DebugVisuals.Value)
{
Object.Destroy((Object)(object)((Component)this).gameObject);
}
else if (!((Object)(object)m_material == (Object)null) && !((Object)(object)((FVRInteractiveObject)m_gun).PoseOverride == (Object)null))
{
m_line = 0;
m_label = 0;
Transform poseOverride = ((FVRInteractiveObject)m_gun).PoseOverride;
Vector3 val = Vector3.up * 0.24f;
Vector3 val2 = poseOverride.position + val;
Quaternion rotation = ((Component)m_gun).transform.rotation;
Vector3 val3 = ((Component)m_gun).transform.position - m_previousPosition;
Vector3 degrees = Grip.RotationVector(rotation * Quaternion.Inverse(m_previousRotation));
m_previousPosition = ((Component)m_gun).transform.position;
m_previousRotation = rotation;
Axes(val2, poseOverride.rotation, "GRIP");
Axes(((FVRInteractiveObject)m_gun).m_handPos + val, ((FVRInteractiveObject)m_gun).m_handRot, "HAND");
Quaternion val4 = m_state.RawRotation * rotation * Quaternion.Inverse(m_state.Turn) * Quaternion.Inverse(rotation);
Axes(val2 + rotation * m_state.Offset, val4 * poseOverride.rotation, "RETAINED TARGET");
Segment(poseOverride.position, val2, new Color(0.6f, 0.6f, 0.6f));
Vector3 val5 = val2 + Vector3.up * 0.13f;
Arrow(val5, ((FVRInteractiveObject)m_gun).m_hand.Input.VelLinearWorld * Time.deltaTime * 8f, Color.cyan);
Arrow(val5, val3 * 8f, Color.white);
Arrow(val5, m_state.CorrectionStep * 8f, Color.magenta);
Label(val5 + Vector3.up * 0.04f, "MOVE x8: hand / gun / correction", Color.white);
Vector3 val6 = val5 + Vector3.up * 0.13f;
Arc(val6, ((FVRInteractiveObject)m_gun).m_hand.Input.VelAngularWorld * Time.deltaTime * 57.29578f, Color.cyan, 0.05f);
Arc(val6, degrees, Color.white, 0.06f);
Arc(val6, m_state.CorrectionTurn, Color.magenta, 0.07f);
Label(val6 + Vector3.up * 0.09f, "TURN x8: cyan hand | white gun | magenta correction", Color.white);
Label(val6 + Vector3.up * 0.12f, "Retained " + (((Vector3)(ref m_state.Offset)).magnitude * 100f).ToString("0.0") + " cm / " + Quaternion.Angle(Quaternion.identity, m_state.Turn).ToString("0.0") + " deg", Color.white);
for (int i = m_line; i < m_lines.Count; i++)
{
((Renderer)m_lines[i]).enabled = false;
}
for (int j = m_label; j < m_labels.Count; j++)
{
((Component)m_labels[j]).gameObject.SetActive(false);
}
}
}
private void OnDestroy()
{
if ((Object)(object)m_material != (Object)null)
{
Object.Destroy((Object)(object)m_material);
}
}
}
[BepInPlugin("invent60.h3vr.seamlessgrip", "Seamless Grip", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public enum Guns
{
BoltActions,
BoltAndLeverActions,
AllLongGuns,
AllGuns
}
internal static ManualLogSource Log;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<Guns> AppliesTo;
internal static ConfigEntry<float> Share;
internal static ConfigEntry<float> TurnShare;
internal static ConfigEntry<float> MinSpeed;
internal static ConfigEntry<bool> DebugLog;
internal static ConfigEntry<bool> DebugVisuals;
private void Awake()
{
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Expected O, but got Unknown
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Expected O, but got Unknown
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Re-grabbing the grip while you aim through a sight (ActionCam's own aim detection) does not move the gun, and it stays put while\nyou keep aiming; once you stop aiming it eases back onto your hand as you move. Not aiming: the game's grab. Without ActionCam\n(or with its aim view off) every catch is kept and eases back as you move. false = the game's snap.\nExample: Enabled = false");
AppliesTo = ((BaseUnityPlugin)this).Config.Bind<Guns>("General", "Applies to", Guns.AllGuns, "Which guns. BoltActions = bolt-action rifles. BoltAndLeverActions = also lever actions. AllLongGuns = every gun that is not a\nhandgun. AllGuns = every gun.\nExample: Applies to = BoltAndLeverActions");
Share = ((BaseUnityPlugin)this).Config.Bind<float>("Drift", "Share of hand speed", 0.3f, new ConfigDescription("While the gun is still off your hand and your hand moves, this share of the hand's movement goes to bringing\nthe gun back onto it (along that same direction only). 0.3 = the gun moves 70 % as far as your hand until it sits right.\nExample: Share of hand speed = 0.15 (slower, harder to notice)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
TurnShare = ((BaseUnityPlugin)this).Config.Bind<float>("Drift", "Share of hand turn", 0.3f, new ConfigDescription("The same for turning: this share of your hand's turn (about the axis it turns about) goes to turning the gun\nback to how it sits in a hand.\nExample: Share of hand turn = 0.15", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
MinSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Drift", "Ignore hand speed under (m/s)", 0.03f, "Hand shake slower than this moves nothing (aiming stays still). Turning uses ten times this in radians a second.\nExample: Ignore hand speed under (m/s) = 0.05");
ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Spec 332 migrated", false, "Set by the mod once it moved Applies to to AllGuns. Example: true");
if (!val.Value)
{
if (AppliesTo.Value == Guns.BoltActions)
{
AppliesTo.Value = Guns.AllGuns;
}
val.Value = true;
}
DebugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Log", false, "Writes a line on each seamless re-grab (gun, offset) and when the gun sits on the hand again.\nExample: Log = true");
DebugVisuals = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Visualize grip motion", false, "Draw grip/hand/retained XYZ axes above the gun, plus cyan hand motion, white actual gun motion and magenta correction.\nTranslation arrows and rotation arcs are magnified 8 times. Example: Visualize grip motion = true");
Harmony val2 = new Harmony("invent60.h3vr.seamlessgrip");
AimState.Bind();
val2.PatchAll(typeof(Grip));
if (DebugLog.Value)
{
Log.LogInfo((object)"Seamless Grip ready (main-grip catch from a fixed handguard; kept while aiming via ActionCam; virtual stock preserved).");
}
}
}
[HarmonyPatch]
internal static class Grip
{
internal sealed class State
{
public Vector3 Offset;
public Quaternion Turn = Quaternion.identity;
public bool PositionCaptured;
public bool RotationCaptured;
public float Since;
public Vector3 RawTranslation;
public Quaternion RawRotation = Quaternion.identity;
public Vector3 CorrectionStep;
public Vector3 CorrectionTurn;
public GripDebug Visual;
public Vector3 CatchPosition;
public Quaternion CatchRotation;
public FVRViveHand Support;
public Vector3 SupportPosition;
public Quaternion SupportRotation;
public bool FilterSupportPosition;
public bool FilterSupportRotation;
public bool Holding;
}
private sealed class MotionTarget
{
public Vector3 Translation;
public Quaternion Rotation;
public bool HasPosition;
public bool HasRotation;
public float At;
}
private static readonly Dictionary<FVRPhysicalObject, State> s_active = new Dictionary<FVRPhysicalObject, State>();
private static readonly Dictionary<FVRPhysicalObject, MotionTarget> s_previous = new Dictionary<FVRPhysicalObject, MotionTarget>();
private static readonly FieldInfo s_savedGrip = AccessTools.Field(typeof(FVRPhysicalObject), "savedGrip");
private static readonly FieldInfo s_positionInterpolation = AccessTools.Field(typeof(FVRInteractiveObject), "m_pos_interp_tick");
private static readonly FieldInfo s_rotationInterpolation = AccessTools.Field(typeof(FVRInteractiveObject), "m_rot_interp_tick");
private static bool s_targetHookReady;
internal static bool Applies(FVRPhysicalObject o)
{
FVRFireArm val = (FVRFireArm)(object)((o is FVRFireArm) ? o : null);
if ((Object)(object)val == (Object)null || !s_targetHookReady || !Plugin.Enabled.Value || (Object)(object)((FVRInteractiveObject)val).PoseOverride == (Object)null)
{
return false;
}
if (((FVRPhysicalObject)val).IsPivotLocked || ((Object)(object)((FVRPhysicalObject)val).Bipod != (Object)null && ((FVRPhysicalObject)val).Bipod.IsBipodActive))
{
return false;
}
switch (Plugin.AppliesTo.Value)
{
case Plugin.Guns.BoltActions:
return val is BoltActionRifle;
case Plugin.Guns.BoltAndLeverActions:
if (!(val is BoltActionRifle))
{
return val is LeverActionFirearm;
}
return true;
case Plugin.Guns.AllLongGuns:
return !(val is Handgun);
default:
return true;
}
}
private static bool FixedGrip(FVRAlternateGrip alt)
{
if ((Object)(object)alt != (Object)null && !(alt is TubeFedShotgunHandle) && !(alt is ClosedBoltForeHandle))
{
return alt.FunctionalityEnabled;
}
return false;
}
private static bool HasHandguard(FVRPhysicalObject o)
{
FVRAlternateGrip altGrip = o.AltGrip;
if (FixedGrip(altGrip) && ((FVRInteractiveObject)altGrip).IsHeld && (Object)(object)((FVRInteractiveObject)altGrip).m_hand != (Object)null && ((FVRInteractiveObject)altGrip).m_hand != ((FVRInteractiveObject)o).m_hand)
{
return (object)((FVRInteractiveObject)altGrip).m_hand.CurrentInteractable == altGrip;
}
return false;
}
private static bool CatchingFromHandguard(FVRPhysicalObject o, FVRViveHand incoming)
{
if ((Object)(object)incoming == (Object)null)
{
return false;
}
if (!o.IsAltHeld)
{
if (HasHandguard(o))
{
return ((FVRInteractiveObject)o.AltGrip).m_hand != incoming;
}
return false;
}
if (FixedGrip((FVRAlternateGrip)(((object)s_savedGrip == null) ? null : /*isinst with value type is only supported in some contexts*/)) && ((FVRInteractiveObject)o).IsHeld && (Object)(object)((FVRInteractiveObject)o).m_hand != (Object)null && ((FVRInteractiveObject)o).m_hand != incoming)
{
return (object)((FVRInteractiveObject)o).m_hand.CurrentInteractable == o;
}
return false;
}
private static MotionTarget Observe(FVRPhysicalObject o)
{
if (!Applies(o) || !o.IsAltHeld || !((FVRInteractiveObject)o).IsHeld || (Object)(object)((FVRInteractiveObject)o).m_hand == (Object)null || !CatchingFromHandguard(o, ((FVRInteractiveObject)o).m_hand.OtherHand))
{
return null;
}
if (!s_previous.TryGetValue(o, out var value))
{
value = new MotionTarget();
s_previous.Add(o, value);
}
return value;
}
[HarmonyPatch(typeof(FVRPhysicalObject), "FU")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> FinalTargets(IEnumerable<CodeInstruction> instructions)
{
//IL_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Expected O, but got Unknown
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Expected O, but got Unknown
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0269: Expected O, but got Unknown
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Expected O, but got Unknown
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_02ad: Expected O, but got Unknown
//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
//IL_02c0: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
int num = -1;
int num2 = -1;
int num3 = 0;
int num4 = 0;
for (int i = 3; i < list.Count; i++)
{
FieldInfo fieldInfo = list[i].operand as FieldInfo;
if (list[i].opcode == OpCodes.Ldfld && (object)fieldInfo != null && fieldInfo.Name == "AttachedPositionMultiplier" && list[i - 1].opcode == OpCodes.Ldarg_0 && CodeInstructionExtensions.IsLdloc(list[i - 2], (LocalBuilder)null))
{
num = i - 2;
num3++;
}
MethodInfo methodInfo = list[i].operand as MethodInfo;
if ((list[i].opcode == OpCodes.Call || list[i].opcode == OpCodes.Callvirt) && (object)methodInfo != null && methodInfo.Name == "ToAngleAxis" && (object)methodInfo.DeclaringType == typeof(Quaternion) && (list[i - 3].opcode == OpCodes.Ldloca || list[i - 3].opcode == OpCodes.Ldloca_S) && list[i - 3].operand is LocalBuilder)
{
num2 = i - 3;
num4++;
}
}
s_targetHookReady = num3 == 1 && num4 == 1;
if (!s_targetHookReady)
{
Plugin.Log.LogError((object)("Seamless capture disabled: unexpected final motion targets " + num3 + "/" + num4));
return list;
}
List<CodeInstruction> list2 = new List<CodeInstruction>();
MethodInfo methodInfo2 = AccessTools.Method(typeof(Grip), "AdjustPosition", (Type[])null, (Type[])null);
MethodInfo methodInfo3 = AccessTools.Method(typeof(Grip), "AdjustRotation", (Type[])null, (Type[])null);
for (int j = 0; j < list.Count; j++)
{
if (j == num2)
{
CodeInstruction val = new CodeInstruction(OpCodes.Ldloc, list[j].operand);
val.labels.AddRange(list[j].labels);
list[j].labels.Clear();
list2.Add(val);
list2.Add(new CodeInstruction(OpCodes.Ldarg_0, (object)null));
list2.Add(new CodeInstruction(OpCodes.Call, (object)methodInfo3));
list2.Add(new CodeInstruction(OpCodes.Stloc, list[j].operand));
}
list2.Add(list[j]);
if (j == num)
{
list2.Add(new CodeInstruction(OpCodes.Ldarg_0, (object)null));
list2.Add(new CodeInstruction(OpCodes.Call, (object)methodInfo2));
}
}
if (Plugin.DebugLog != null && Plugin.DebugLog.Value)
{
Plugin.Log.LogInfo((object)"Seamless Grip: final motion target hooks ready; virtual stock branches unchanged.");
}
return list2;
}
[HarmonyPatch(typeof(FVRPhysicalObject), "BeginInteraction")]
[HarmonyPrefix]
private static void BeginPre(FVRPhysicalObject __instance, FVRViveHand hand, out State __state)
{
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
__state = null;
if (Applies(__instance) && !__instance.m_isSpawnLock && !((Object)(object)__instance.QuickbeltSlot != (Object)null) && CatchingFromHandguard(__instance, hand))
{
int num = AimState.Read((FVRFireArm)(object)((__instance is FVRFireArm) ? __instance : null));
if (num != 0)
{
MotionTarget value;
bool flag = s_previous.TryGetValue(__instance, out value) && value.HasPosition && value.HasRotation && Time.fixedTime - value.At <= Mathf.Max(0.1f, Time.fixedDeltaTime * 2f);
FVRViveHand support = (__instance.IsAltHeld ? ((FVRInteractiveObject)__instance).m_hand : ((FVRInteractiveObject)__instance.AltGrip).m_hand);
__state = new State
{
Since = Time.time,
Holding = (num == 1),
CatchPosition = ((Component)__instance).transform.position + (flag ? value.Translation : Vector3.zero),
CatchRotation = (flag ? value.Rotation : Quaternion.identity) * ((Component)__instance).transform.rotation,
Support = support,
FilterSupportPosition = (((FVRInteractiveObject)__instance).UseFilteredHandTransform || ((FVRInteractiveObject)__instance).UseFilteredHandPosition),
FilterSupportRotation = (((FVRInteractiveObject)__instance).UseFilteredHandTransform || ((FVRInteractiveObject)__instance).UseFilteredHandRotation),
SupportPosition = ((FVRInteractiveObject)__instance).m_handPos,
SupportRotation = ((FVRInteractiveObject)__instance).m_handRot
};
}
}
}
[HarmonyPatch(typeof(FVRPhysicalObject), "BeginInteraction")]
[HarmonyPostfix]
private static void BeginPost(FVRPhysicalObject __instance, FVRViveHand hand, State __state)
{
Drop(__instance);
s_previous.Remove(__instance);
if (__state != null && !((Object)(object)hand == (Object)null) && !__instance.IsAltHeld && ((FVRInteractiveObject)__instance).m_hand == hand && HasHandguard(__instance))
{
if ((object)s_positionInterpolation != null)
{
s_positionInterpolation.SetValue(__instance, 1f);
}
if ((object)s_rotationInterpolation != null)
{
s_rotationInterpolation.SetValue(__instance, 1f);
}
s_active[__instance] = __state;
if (Plugin.DebugLog.Value)
{
Plugin.Log.LogInfo((object)("Seamless Grip: " + ((Object)__instance).name + " main grip caught " + (__state.Holding ? "while aiming (held until you stop aiming)" : "(no aim data: eases back as you move)") + "; preserving pre-catch motion target on next physics update."));
}
}
}
[HarmonyPatch(typeof(FVRPhysicalObject), "EndInteraction")]
[HarmonyPostfix]
private static void EndPost(FVRPhysicalObject __instance)
{
Drop(__instance);
s_previous.Remove(__instance);
}
[HarmonyPatch(typeof(FVRInteractiveObject), "OnDestroy")]
[HarmonyPrefix]
private static void DestroyPre(FVRInteractiveObject __instance)
{
FVRPhysicalObject val = (FVRPhysicalObject)(object)((__instance is FVRPhysicalObject) ? __instance : null);
if (!((Object)(object)val == (Object)null))
{
Drop(val);
s_previous.Remove(val);
}
}
private static void Drop(FVRPhysicalObject o)
{
if (s_active.TryGetValue(o, out var value))
{
if ((Object)(object)value.Visual != (Object)null)
{
Object.Destroy((Object)(object)((Component)value.Visual).gameObject);
}
s_active.Remove(o);
}
}
private static State Active(FVRPhysicalObject o)
{
if (!s_active.TryGetValue(o, out var value))
{
return null;
}
if ((Object)(object)o == (Object)null || !Applies(o) || !HasHandguard(o) || !((FVRInteractiveObject)o).IsHeld || o.IsAltHeld || (Object)(object)((FVRInteractiveObject)o).m_hand == (Object)null)
{
Drop(o);
return null;
}
return value;
}
[HarmonyPatch(typeof(FVRPhysicalObject), "GetGrabPos")]
[HarmonyPostfix]
private static void GrabPos(FVRPhysicalObject __instance, ref Vector3 __result)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
if (Active(__instance) != null)
{
__result = ((FVRInteractiveObject)__instance).PoseOverride.position;
}
}
[HarmonyPatch(typeof(FVRPhysicalObject), "GetGrabRot")]
[HarmonyPostfix]
private static void GrabRot(FVRPhysicalObject __instance, ref Quaternion __result)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
if (Active(__instance) != null)
{
__result = ((FVRInteractiveObject)__instance).PoseOverride.rotation;
}
}
private static Vector3 AdjustPosition(Vector3 target, FVRPhysicalObject o)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: 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)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
MotionTarget motionTarget = Observe(o);
if (motionTarget != null)
{
motionTarget.Translation = target;
motionTarget.HasPosition = true;
motionTarget.At = Time.fixedTime;
}
State state = Active(o);
if (state == null)
{
return target;
}
Quaternion rotation = ((Component)o).transform.rotation;
if (!state.PositionCaptured)
{
Vector3 val = (state.FilterSupportPosition ? ((HandInput)(ref state.Support.Input)).OneEuroPosition : ((HandInput)(ref state.Support.Input)).Pos);
Vector3 val2 = state.CatchPosition - ((Component)o).transform.position + val - state.SupportPosition;
state.Offset = Quaternion.Inverse(rotation) * (target - val2);
state.PositionCaptured = true;
if (Plugin.DebugLog.Value)
{
Plugin.Log.LogInfo((object)("Seamless Grip: " + ((Object)o).name + " retained " + (((Vector3)(ref state.Offset)).magnitude * 100f).ToString("0.0") + " cm; pre-catch servo error preserved including stock."));
}
}
state.RawTranslation = target;
return target - rotation * state.Offset;
}
private static Quaternion AdjustRotation(Quaternion target, FVRPhysicalObject o)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: 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)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
MotionTarget motionTarget = Observe(o);
if (motionTarget != null)
{
motionTarget.Rotation = target;
motionTarget.HasRotation = true;
motionTarget.At = Time.fixedTime;
}
State state = Active(o);
if (state == null)
{
return target;
}
Quaternion rotation = ((Component)o).transform.rotation;
if (!state.RotationCaptured)
{
Quaternion val = (state.FilterSupportRotation ? state.Support.Input.OneEuroRotation : ((HandInput)(ref state.Support.Input)).Rot) * Quaternion.Inverse(state.SupportRotation) * state.CatchRotation * Quaternion.Inverse(rotation);
state.Turn = Quaternion.Inverse(rotation) * Quaternion.Inverse(val) * target * rotation;
state.RotationCaptured = true;
}
state.RawRotation = target;
return target * rotation * Quaternion.Inverse(state.Turn) * Quaternion.Inverse(rotation);
}
internal static Vector3 RotationVector(Quaternion rotation)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
float num = default(float);
Vector3 val = default(Vector3);
((Quaternion)(ref rotation)).ToAngleAxis(ref num, ref val);
if (num > 180f)
{
num -= 360f;
}
if (!(Mathf.Abs(num) < 0.001f) && !float.IsNaN(val.x))
{
return val * num;
}
return Vector3.zero;
}
[HarmonyPatch(typeof(FVRPhysicalObject), "FVRUpdate")]
[HarmonyPostfix]
private static void Ease(FVRPhysicalObject __instance)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
//IL_0243: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_0258: Unknown result type (might be due to invalid IL or missing references)
//IL_025d: Unknown result type (might be due to invalid IL or missing references)
//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
//IL_02be: Unknown result type (might be due to invalid IL or missing references)
//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Unknown result type (might be due to invalid IL or missing references)
//IL_026f: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Unknown result type (might be due to invalid IL or missing references)
//IL_0290: Unknown result type (might be due to invalid IL or missing references)
//IL_0295: Unknown result type (might be due to invalid IL or missing references)
//IL_029a: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_039c: Unknown result type (might be due to invalid IL or missing references)
//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0301: Unknown result type (might be due to invalid IL or missing references)
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
//IL_033a: Unknown result type (might be due to invalid IL or missing references)
//IL_033f: Unknown result type (might be due to invalid IL or missing references)
//IL_0341: Unknown result type (might be due to invalid IL or missing references)
//IL_0346: Unknown result type (might be due to invalid IL or missing references)
//IL_0348: Unknown result type (might be due to invalid IL or missing references)
//IL_034d: Unknown result type (might be due to invalid IL or missing references)
//IL_035e: Unknown result type (might be due to invalid IL or missing references)
//IL_035f: Unknown result type (might be due to invalid IL or missing references)
//IL_0364: Unknown result type (might be due to invalid IL or missing references)
//IL_0366: Unknown result type (might be due to invalid IL or missing references)
//IL_036b: Unknown result type (might be due to invalid IL or missing references)
//IL_036c: Unknown result type (might be due to invalid IL or missing references)
//IL_0371: Unknown result type (might be due to invalid IL or missing references)
//IL_0377: Unknown result type (might be due to invalid IL or missing references)
//IL_0379: Unknown result type (might be due to invalid IL or missing references)
//IL_0380: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
State state = Active(__instance);
if (state == null)
{
return;
}
if (Plugin.DebugVisuals.Value && (Object)(object)state.Visual == (Object)null)
{
state.Visual = new GameObject("SeamlessGripDebug").AddComponent<GripDebug>();
state.Visual.Setup(__instance, state);
}
else if (!Plugin.DebugVisuals.Value && (Object)(object)state.Visual != (Object)null)
{
Object.Destroy((Object)(object)((Component)state.Visual).gameObject);
}
if (!state.PositionCaptured || !state.RotationCaptured)
{
return;
}
state.CorrectionStep = Vector3.zero;
state.CorrectionTurn = Vector3.zero;
bool flag = AimState.Read((FVRFireArm)(object)((__instance is FVRFireArm) ? __instance : null)) == 1;
if (flag != state.Holding)
{
state.Holding = flag;
if (Plugin.DebugLog.Value)
{
Plugin.Log.LogInfo((object)("Seamless Grip: " + ((Object)__instance).name + (flag ? " aiming again: kept pose held (" : " stopped aiming: kept pose now eases back as you move (") + (((Vector3)(ref state.Offset)).magnitude * 100f).ToString("0.0") + " cm, " + Quaternion.Angle(Quaternion.identity, state.Turn).ToString("0.0") + " deg)."));
}
}
if (flag)
{
return;
}
Quaternion rotation = ((Component)__instance).transform.rotation;
HandInput input = ((FVRInteractiveObject)__instance).m_hand.Input;
float deltaTime = Time.deltaTime;
Vector3 val = rotation * state.Offset;
Vector3 velLinearWorld = input.VelLinearWorld;
float magnitude = ((Vector3)(ref velLinearWorld)).magnitude;
if (magnitude > Plugin.MinSpeed.Value && ((Vector3)(ref val)).sqrMagnitude > 1E-08f)
{
Vector3 val2 = velLinearWorld / magnitude;
float num = Vector3.Dot(-val, val2);
if (num > 0f)
{
Vector3 val3 = val2 * Mathf.Min(num, Mathf.Clamp01(Plugin.Share.Value) * magnitude * deltaTime);
state.Offset += Quaternion.Inverse(rotation) * val3;
state.CorrectionStep = -val3;
}
}
Vector3 val4 = input.VelAngularWorld;
FVRViveHand hand = ((FVRInteractiveObject)__instance.AltGrip).m_hand;
Vector3 val5 = hand.PalmTransform.position - ((FVRInteractiveObject)__instance).m_hand.PalmTransform.position;
if (((Vector3)(ref val5)).sqrMagnitude > 0.0225f)
{
val4 += Vector3.Cross(val5, hand.Input.VelLinearWorld - velLinearWorld) / ((Vector3)(ref val5)).sqrMagnitude;
}
float magnitude2 = ((Vector3)(ref val4)).magnitude;
Quaternion val6 = rotation * state.Turn * Quaternion.Inverse(rotation);
Vector3 val7 = RotationVector(val6);
if (magnitude2 > Plugin.MinSpeed.Value * 10f && ((Vector3)(ref val7)).sqrMagnitude > 0.0001f)
{
Vector3 val8 = val4 / magnitude2;
float num2 = Vector3.Dot(-val7, val8);
if (num2 > 0f)
{
float num3 = Mathf.Min(num2, Mathf.Clamp01(Plugin.TurnShare.Value) * magnitude2 * 57.29578f * deltaTime);
Quaternion val9 = Quaternion.AngleAxis(num3, val8) * val6;
if (Quaternion.Angle(Quaternion.identity, val9) <= ((Vector3)(ref val7)).magnitude)
{
state.Turn = Quaternion.Inverse(rotation) * val9 * rotation;
state.CorrectionTurn = -val8 * num3;
}
}
}
if (((Vector3)(ref state.Offset)).sqrMagnitude < 2.5000003E-07f && Quaternion.Angle(Quaternion.identity, state.Turn) < 0.2f)
{
if (Plugin.DebugLog.Value)
{
Plugin.Log.LogInfo((object)("Seamless Grip: " + ((Object)__instance).name + " aligned after " + (Time.time - state.Since).ToString("0.0") + " s; vanilla grip resumed."));
}
Drop(__instance);
}
}
}