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.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Renderite.Shared; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("nullobsi")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+6342072216248b7763f6f040925d008d8dbd4268")] [assembly: AssemblyProduct("FixHandPose (for Unity)")] [assembly: AssemblyTitle("FixHandPose.Unity")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/nullobsi/FixHandPose")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace 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 IEnumerable Pack_Transpiler(IEnumerable instructions) { return RemoveBranches(instructions); } [HarmonyTranspiler] [HarmonyPatch("Unpack")] private static IEnumerable Unpack_Transpiler(IEnumerable instructions) { return RemoveBranches(instructions); } private static IEnumerable RemoveBranches(IEnumerable instructions) { List list = instructions.ToList(); HashSet hashSet = new HashSet { IsTrackingField, HasBoundHandField }; for (int i = 0; i < list.Count - 1; i++) { if (list[i].operand is FieldInfo fieldInfo && hashSet.Contains(fieldInfo) && CodeInstructionExtensions.LoadsField(list[i], fieldInfo, false) && (!(list[i + 1].opcode != OpCodes.Brfalse) || !(list[i + 1].opcode != OpCodes.Brfalse_S))) { list[i + 1].opcode = OpCodes.Pop; list[i + 1].operand = null; hashSet.Remove(fieldInfo); } } if (hashSet.Count != 0) { throw new InvalidOperationException("Could not remove VR_ControllerState guards for: " + string.Join(", ", hashSet.Select((FieldInfo field) => field.Name)) + "."); } return list; } } } namespace FixHandPose.Unity { [BepInPlugin("FixHandPose.Unity", "FixHandPose (for Unity)", "1.0.0")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Logger; private void Awake() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) Logger = ((BaseUnityPlugin)this).Logger; Logger.LogInfo((object)"Plugin FixHandPose.Unity is loaded!"); try { new Harmony("dog.unix.FixHandPose.Unity").PatchAll(); Logger.LogInfo((object)"FixHandPose: Unity patches applied"); } catch (Exception arg) { Logger.LogError((object)$"FixHandPose: Unity failed to patch: {arg}"); } } } }