Decompiled source of FixHandPose v1.0.0

plugins/FixHandPose.FrooxEngine/FixHandPose.FrooxEngine.dll

Decompiled 12 hours ago
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";
	}
}

Renderer/BepInEx/plugins/FixHandPose.Unity/FixHandPose.Unity.dll

Decompiled 12 hours ago
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<CodeInstruction> Pack_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			return RemoveBranches(instructions);
		}

		[HarmonyTranspiler]
		[HarmonyPatch("Unpack")]
		private static IEnumerable<CodeInstruction> Unpack_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			return RemoveBranches(instructions);
		}

		private static IEnumerable<CodeInstruction> RemoveBranches(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			HashSet<FieldInfo> hashSet = new HashSet<FieldInfo> { 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}");
			}
		}
	}
}