diff --git a/IKTweaks/FullBodyHandling.cs b/IKTweaks/FullBodyHandling.cs index 40aa71e..88ef4d6 100644 --- a/IKTweaks/FullBodyHandling.cs +++ b/IKTweaks/FullBodyHandling.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; using Harmony; @@ -13,8 +14,30 @@ namespace IKTweaks { - public class FullBodyHandling + public static class FullBodyHandling { + private static T MinBy(this IEnumerable src, Func selector) + { + var seenElement = false; + var minValue = int.MaxValue; + T best = default; + foreach (var x in src) + { + seenElement = true; + var current = selector(x); + if (current < minValue) + { + minValue = current; + best = x; + } + } + + if (!seenElement) + throw new ArgumentException("Sequence is empty"); + + return best; + } + internal static VRCFbbIkController LastInitializedController; internal static VRIK_New LastInitializedVRIK; @@ -440,9 +463,9 @@ internal static void HookFullBodyController(HarmonyInstance harmony) new HarmonyMethod(typeof(FullBodyHandling), nameof(IsCalibratedForAvatarPrefix))); var userOfHfts = typeof(VRCFbbIkController) - .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Single(it => + .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(it => XrefScanner.XrefScan(it).Any(jt => jt.Type == XrefType.Global && jt.ReadAsObject()?.ToString() == - "Hip+Feet Tracking: 3 trackers found, tracking enabled.")); + "Hip+Feet Tracking: 3 trackers found, tracking enabled.")).MinBy(it => XrefScanner.XrefScan(it).Count()); var hipAndFeetTrackingSupportedCandidates = XrefScanner.XrefScan(userOfHfts).Where(it => { if (it.Type != XrefType.Method) return false; diff --git a/IKTweaks/IKTweaks.csproj b/IKTweaks/IKTweaks.csproj index ee65877..2401cea 100644 --- a/IKTweaks/IKTweaks.csproj +++ b/IKTweaks/IKTweaks.csproj @@ -4,7 +4,7 @@ true latest true - 1.0.8 + 1.0.9 diff --git a/IKTweaks/IKTweaksMod.cs b/IKTweaks/IKTweaksMod.cs index 9438b3a..09aca3b 100644 --- a/IKTweaks/IKTweaksMod.cs +++ b/IKTweaks/IKTweaksMod.cs @@ -15,7 +15,7 @@ using Delegate = Il2CppSystem.Delegate; using Object = UnityEngine.Object; -[assembly:MelonInfo(typeof(IKTweaksMod), "IKTweaks", "1.0.8", "knah", "https://github.com/knah/VRCMods")] +[assembly:MelonInfo(typeof(IKTweaksMod), "IKTweaks", "1.0.9", "knah", "https://github.com/knah/VRCMods")] [assembly:MelonGame("VRChat", "VRChat")] [assembly:MelonOptionalDependencies("UIExpansionKit")]