using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using BepisResoniteWrapper;
using Elements.Core;
using FrooxEngine;
using HarmonyLib;
using Renderite.Shared;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v10.0", FrameworkDisplayName = ".NET 10.0")]
[assembly: AssemblyCompany("nullobsi")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6342072216248b7763f6f040925d008d8dbd4268")]
[assembly: AssemblyProduct("FixHandPose (for FrooxEngine)")]
[assembly: AssemblyTitle("FixHandPose.FrooxEngine")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/nullobsi/FixHandPose")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace FixHandPose.Shared
{
[HarmonyPatch(typeof(VR_ControllerState))]
internal class VR_ControllerState_Patch
{
private static readonly FieldInfo IsTrackingField = AccessTools.Field(typeof(VR_ControllerState), "isTracking") ?? throw new MissingFieldException(typeof(VR_ControllerState).FullName, "isTracking");
private static readonly FieldInfo HasBoundHandField = AccessTools.Field(typeof(VR_ControllerState), "hasBoundHand") ?? throw new MissingFieldException(typeof(VR_ControllerState).FullName, "hasBoundHand");
[HarmonyTranspiler]
[HarmonyPatch("Pack")]
private static global::System.Collections.Generic.IEnumerable<CodeInstruction> Pack_Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> instructions)
{
return RemoveBranches(instructions);
}
[HarmonyTranspiler]
[HarmonyPatch("Unpack")]
private static global::System.Collections.Generic.IEnumerable<CodeInstruction> Unpack_Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> instructions)
{
return RemoveBranches(instructions);
}
private static global::System.Collections.Generic.IEnumerable<CodeInstruction> RemoveBranches(global::System.Collections.Generic.IEnumerable<CodeInstruction> instructions)
{
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: 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_0097: 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_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)
List<CodeInstruction> val = Enumerable.ToList<CodeInstruction>(instructions);
HashSet<FieldInfo> obj = new HashSet<FieldInfo>();
obj.Add(IsTrackingField);
obj.Add(HasBoundHandField);
HashSet<FieldInfo> val2 = obj;
for (int i = 0; i < val.Count - 1; i++)
{
object operand = val[i].operand;
FieldInfo val3 = (FieldInfo)((operand is FieldInfo) ? operand : null);
if (val3 != null && val2.Contains(val3) && CodeInstructionExtensions.LoadsField(val[i], val3, false) && (!(val[i + 1].opcode != OpCodes.Brfalse) || !(val[i + 1].opcode != OpCodes.Brfalse_S)))
{
val[i + 1].opcode = OpCodes.Pop;
val[i + 1].operand = null;
val2.Remove(val3);
}
}
if (val2.Count != 0)
{
throw new InvalidOperationException("Could not remove VR_ControllerState guards for: " + string.Join(", ", Enumerable.Select<FieldInfo, string>((global::System.Collections.Generic.IEnumerable<FieldInfo>)val2, (Func<FieldInfo, string>)((FieldInfo field) => ((MemberInfo)field).Name))) + ".");
}
return (global::System.Collections.Generic.IEnumerable<CodeInstruction>)val;
}
}
}
namespace FixHandPose.FrooxEngine
{
[ResonitePlugin("dog.unix.FixHandPose.FrooxEngine", "FixHandPose (for FrooxEngine)", "1.0.0", "nullobsi", "https://github.com/nullobsi/FixHandPose")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
[HarmonyPatch(typeof(OffsetableTrackedObject), "Initialize")]
private class OffsetableTrackedObject_Initialize_Patch
{
private static void Postfix(OffsetableTrackedObject __instance, string uniqueIdentifier, float3 defaultPositionOffset, floatQ defaultRotationOffset)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//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_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Fixing hand pose for ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(uniqueIdentifier);
}
log.LogInfo(val);
__instance.UpdateOffset(defaultPositionOffset, defaultRotationOffset);
((TrackedObject)__instance).BodyNodePositionOffset = defaultPositionOffset;
((TrackedObject)__instance).BodyNodeRotationOffset = defaultRotationOffset;
}
}
internal static ManualLogSource Log;
public override void Load()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
ResoniteHooks.OnEngineReady += new Action(OnEngineReady);
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("dog.unix.FixHandPose.FrooxEngine");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
}
log.LogInfo(val);
}
private void OnEngineReady()
{
//IL_0005: 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_0031: Expected O, but got Unknown
try
{
new Harmony("dog.unix.FixHandPose.FrooxEngine").PatchAll();
Log.LogInfo((object)"FixHandPose: FrooxEngine patches applied");
}
catch (global::System.Exception ex)
{
ManualLogSource log = Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(42, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("FixHandPose: FrooxEngine failed to patch: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<global::System.Exception>(ex);
}
log.LogError(val);
}
}
}
public static class PluginMetadata
{
public const string GUID = "dog.unix.FixHandPose.FrooxEngine";
public const string NAME = "FixHandPose (for FrooxEngine)";
public const string VERSION = "1.0.0";
public const string AUTHORS = "nullobsi";
public const string REPOSITORY_URL = "https://github.com/nullobsi/FixHandPose";
}
}