Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of REEmotes v1.1.0
REEmotes.dll
Decompiled 7 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using RE4Company; using TooManyEmotes; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("REEmotes")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyInformationalVersion("1.1.0")] [assembly: AssemblyProduct("REEmotes")] [assembly: AssemblyTitle("REEmotes")] [assembly: AssemblyVersion("1.1.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [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 REEmotes { public struct RootState { public bool Valid; public Vector3 LocalPosition; public Quaternion LocalRotation; } internal static class BridgePatches { public static void ApplyPrefix(Re4Rig rig, out RootState __state) { //IL_0021: 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_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) __state = default(RootState); if (!((Object)(object)rig == (Object)null)) { Transform transform = ((Component)rig).transform; __state.Valid = true; __state.LocalPosition = transform.localPosition; __state.LocalRotation = transform.localRotation; } } public static void ApplyPostfix(PlayerControllerB p, Re4Rig rig, InteractionPolicy state, bool firstPerson, RootState __state) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) EmoteRetargeter.AfterBridge(p, rig, state, firstPerson, __state); } public static void ForgetPostfix(Re4Rig rig) { EmoteRetargeter.Forget(rig); } public static void ClearPostfix() { EmoteRetargeter.DisposeAll(); } public static void StopEmotePostfix(EmoteController __instance) { EmoteRetargeter.EmoteStopped(__instance); } } internal static class EmoteRetargeter { private sealed class Session { public float StartTime; public int LastFrame; public EmoteController Controller; } private static readonly Dictionary<Re4Rig, RigRetarget> rigs = new Dictionary<Re4Rig, RigRetarget>(); private static readonly Dictionary<Re4Rig, Session> sessions = new Dictionary<Re4Rig, Session>(); private static readonly Dictionary<Animator, SourceRig> sources = new Dictionary<Animator, SourceRig>(); private static readonly Dictionary<Transform, SourceRig> vanillaSources = new Dictionary<Transform, SourceRig>(); private static readonly Dictionary<EmoteController, Vector3> scaledProps = new Dictionary<EmoteController, Vector3>(); private static readonly HashSet<string> reported = new HashSet<string>(); private static int calls; public static void AfterBridge(PlayerControllerB p, Re4Rig rig, InteractionPolicy state, bool firstPerson, RootState root) { //IL_0033: 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_003a: Invalid comparison between Unknown and I4 //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.Enabled.Value || firstPerson || (Object)(object)p == (Object)null || (Object)(object)rig == (Object)null || (Object)(object)rig.SharedRig != (Object)null || (int)state.Kind != 4) { return; } try { if (++calls % 600 == 0) { Prune(); } EmoteController val = Controller(p); if ((Object)(object)val == (Object)null || (Object)(object)val.animator == (Object)null) { sessions.Remove(rig); return; } bool flag = val.isPerformingEmote && val.performingEmote != null; bool flag2 = !flag && p.performingEmote && Plugin.VanillaEmotes.Value && (Object)(object)val.metarig != (Object)null; if (!flag && !flag2) { sessions.Remove(rig); return; } SourceRig sourceRig = Source(val.animator); if (sourceRig == null) { return; } if (flag2) { sourceRig = Vanilla(val.metarig, sourceRig); if (sourceRig == null) { return; } } RigRetarget rigRetarget = Target(rig); if (rigRetarget != null && rigRetarget.Valid) { rigRetarget.Solve(sourceRig); if (root.Valid) { ((Component)rig).transform.localPosition = root.LocalPosition; ((Component)rig).transform.localRotation = root.LocalRotation; } if (!sessions.TryGetValue(rig, out var value) || (Object)(object)value.Controller != (Object)(object)val || Time.frameCount - value.LastFrame > 2) { value = new Session { StartTime = Time.time, Controller = val }; sessions[rig] = value; } value.LastFrame = Time.frameCount; float value2 = Plugin.BlendInSeconds.Value; float weight = ((value2 <= 0f) ? 1f : Mathf.Clamp01((Time.time - value.StartTime) / value2)); rigRetarget.Write(weight); if (flag && Plugin.ScaleProps.Value) { ScaleProps(val, rigRetarget); } } } catch (Exception ex) { Report("apply:" + ex.GetType().Name, $"Emote retarget failed for {p.playerUsername}: {ex}"); } } private static EmoteController Controller(PlayerControllerB p) { Dictionary<PlayerControllerB, EmoteControllerPlayer> allPlayerEmoteControllers = EmoteControllerPlayer.allPlayerEmoteControllers; if (allPlayerEmoteControllers == null) { return null; } if (!allPlayerEmoteControllers.TryGetValue(p, out var value) || !((Object)(object)value != (Object)null)) { return null; } return (EmoteController)(object)value; } private static SourceRig Source(Animator animator) { if (sources.TryGetValue(animator, out var value)) { if (!value.Valid) { return null; } return value; } value = SourceRig.Build(animator, Plugin.humanoidSkeletonPrefab); sources[animator] = value; if (!value.Valid) { Report("source:" + value.Problem, "Can't read TooManyEmotes' emote skeleton: " + value.Problem + ". RE4Gameplay's own emote handling stays in place."); } else if (Plugin.LogRig.Value) { Plugin.Log.LogInfo((object)$"TooManyEmotes skeleton: hips {value.HipsHeight:0.###} units above the feet, rest pose from the {value.RestSource}."); } if (!value.Valid) { return null; } return value; } private static SourceRig Vanilla(Transform metarig, SourceRig emoteSkeleton) { if (vanillaSources.TryGetValue(metarig, out var value) && (Object)(object)value.Root == (Object)(object)emoteSkeleton.Root) { if (!value.Valid) { return null; } return value; } value = emoteSkeleton.Remap(metarig, "on Lethal Company's skeleton"); vanillaSources[metarig] = value; if (!value.Valid) { Report("vanilla:" + value.Problem, "Can't retarget Lethal Company's own emotes: " + value.Problem + "."); } if (!value.Valid) { return null; } return value; } private static RigRetarget Target(Re4Rig rig) { if (rigs.TryGetValue(rig, out var value)) { return value; } value = RigRetarget.Build(rig); rigs[rig] = value; if (value.Valid) { if (Plugin.LogRig.Value) { Plugin.Log.LogInfo((object)value.Describe()); } else if (reported.Add("ok:" + ((Object)rig).name)) { Plugin.Log.LogInfo((object)("Retargeting emotes onto '" + ((Object)rig).name + "'.")); } } else { Report("rig:" + ((Object)rig).name + ":" + value.Problem, "Can't retarget emotes onto '" + ((Object)rig).name + "': " + value.Problem + ". RE4Gameplay's own emote handling stays in place for it."); } return value; } private static void ScaleProps(EmoteController ec, RigRetarget target) { //IL_0055: 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_00bb: 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_00a6: Unknown result type (might be due to invalid IL or missing references) Transform propsParent = ec.propsParent; if ((Object)(object)propsParent == (Object)null || (Object)(object)propsParent.parent != (Object)(object)ec.humanoidSkeleton || !sources.TryGetValue(ec.animator, out var value) || value == null || !value.Valid) { return; } float num = value.HipsHeight * Mathf.Abs(((Component)ec.animator).transform.lossyScale.y); float num2 = target.HipsHeightWorld(); if (!(num <= 0.0001f) && !(num2 <= 0.0001f)) { float num3 = Mathf.Clamp(num2 / num, 0.5f, 3f); if (!scaledProps.ContainsKey(ec)) { scaledProps[ec] = propsParent.localScale; } Vector3 val = scaledProps[ec]; propsParent.localScale = val * num3; } } public static void EmoteStopped(EmoteController ec) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)ec == (Object)null) && scaledProps.TryGetValue(ec, out var value)) { if ((Object)(object)ec.propsParent != (Object)null) { ec.propsParent.localScale = value; } scaledProps.Remove(ec); } } public static void Forget(Re4Rig rig) { if (!((Object)(object)rig == (Object)null)) { rigs.Remove(rig); sessions.Remove(rig); } } public static void DisposeAll() { //IL_006e: Unknown result type (might be due to invalid IL or missing references) rigs.Clear(); sessions.Clear(); sources.Clear(); vanillaSources.Clear(); foreach (KeyValuePair<EmoteController, Vector3> scaledProp in scaledProps) { if ((Object)(object)scaledProp.Key != (Object)null && (Object)(object)scaledProp.Key.propsParent != (Object)null) { scaledProp.Key.propsParent.localScale = scaledProp.Value; } } scaledProps.Clear(); } private static void Prune() { List<Re4Rig> list = new List<Re4Rig>(); foreach (KeyValuePair<Re4Rig, RigRetarget> rig in rigs) { if ((Object)(object)rig.Key == (Object)null) { list.Add(rig.Key); } } foreach (Re4Rig item in list) { rigs.Remove(item); sessions.Remove(item); } List<Animator> list2 = new List<Animator>(); foreach (KeyValuePair<Animator, SourceRig> source in sources) { if ((Object)(object)source.Key == (Object)null) { list2.Add(source.Key); } } foreach (Animator item2 in list2) { sources.Remove(item2); } List<Transform> list3 = new List<Transform>(); foreach (KeyValuePair<Transform, SourceRig> vanillaSource in vanillaSources) { if ((Object)(object)vanillaSource.Key == (Object)null) { list3.Add(vanillaSource.Key); } } foreach (Transform item3 in list3) { vanillaSources.Remove(item3); } List<EmoteController> list4 = new List<EmoteController>(); foreach (KeyValuePair<EmoteController, Vector3> scaledProp in scaledProps) { if ((Object)(object)scaledProp.Key == (Object)null) { list4.Add(scaledProp.Key); } } foreach (EmoteController item4 in list4) { scaledProps.Remove(item4); } } private static void Report(string key, string message) { if (reported.Add(key)) { Plugin.Log.LogWarning((object)message); } } } [BepInPlugin("link.reemotes", "REEmotes", "1.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "link.reemotes"; public const string Name = "REEmotes"; public const string Version = "1.1.0"; internal const string Re4GameplayGuid = "re4company.overhaul"; internal const string TooManyEmotesGuid = "FlipMods.TooManyEmotes"; internal static ManualLogSource Log; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<float> BlendInSeconds; internal static ConfigEntry<bool> ScaleProps; internal static ConfigEntry<bool> VanillaEmotes; internal static ConfigEntry<bool> LogRig; private Harmony harmony; private void Awake() { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Retarget TooManyEmotes emotes onto RE4Gameplay characters (Leon, Ada, HUNK, Krauser, RE5Gameplay's Chris and Sheva, and other add-on suits that use RE4Gameplay's skeleton). Turn off to fall back to RE4Gameplay's own emote handling."); BlendInSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "BlendInSeconds", 0.2f, new ConfigDescription("How long the character takes to blend into an emote.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); ScaleProps = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ScaleEmoteProps", true, "Resize and reposition emote props (instruments, signs and so on) to match the RE character's size, so they line up with the hands."); VanillaEmotes = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "VanillaEmotes", true, "Also retarget Lethal Company's own emotes (dance and point, keys 1 and 2)."); LogRig = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogRig", false, "Write the bone mapping for each RE character to the log the first time it emotes."); harmony = new Harmony("link.reemotes"); try { Patch(); Log.LogInfo((object)"REEmotes 1.1.0 ready: TooManyEmotes emotes will drive RE4Gameplay characters."); } catch (Exception ex) { Log.LogError((object)("REEmotes could not hook RE4Gameplay (" + ex.GetType().Name + ": " + ex.Message + "). Emotes will use RE4Gameplay's own handling.")); } } private void Patch() { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //IL_007e: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Expected O, but got Unknown //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Expected O, but got Unknown //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Expected O, but got Unknown Type? obj = typeof(Re4Rig).Assembly.GetType("RE4Company.NativePoseBridge") ?? throw new MissingMemberException("RE4Company.NativePoseBridge not found (RE4Gameplay version changed?)"); MethodInfo methodInfo = AccessTools.Method(obj, "Apply", (Type[])null, (Type[])null) ?? throw new MissingMemberException("NativePoseBridge.Apply not found"); harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(BridgePatches), "ApplyPrefix", (Type[])null), new HarmonyMethod(typeof(BridgePatches), "ApplyPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); MethodInfo methodInfo2 = AccessTools.Method(obj, "Forget", (Type[])null, (Type[])null); if (methodInfo2 != null) { harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(BridgePatches), "ForgetPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } MethodInfo methodInfo3 = AccessTools.Method(obj, "Clear", (Type[])null, (Type[])null); if (methodInfo3 != null) { harmony.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(BridgePatches), "ClearPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } MethodInfo methodInfo4 = AccessTools.Method(typeof(EmoteController), "StopPerformingEmote", (Type[])null, (Type[])null); if (methodInfo4 != null) { harmony.Patch((MethodBase)methodInfo4, (HarmonyMethod)null, new HarmonyMethod(typeof(BridgePatches), "StopEmotePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } MethodInfo methodInfo5 = AccessTools.Method(typeof(EmoteController), "ResetPerformingEmote", (Type[])null, (Type[])null); if (methodInfo5 != null) { harmony.Patch((MethodBase)methodInfo5, (HarmonyMethod)null, new HarmonyMethod(typeof(BridgePatches), "StopEmotePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } private void OnDestroy() { EmoteRetargeter.DisposeAll(); } } internal sealed class RigRetarget { private const int IdHips = 0; private const int IdSpine = 1; private const int IdChest = 2; private const int IdNeck = 3; private const int IdHead = 4; private const int IdRightUpperArm = 7; private const int IdRightLowerArm = 8; private const int IdRightHand = 10; private const int IdLeftUpperArm = 13; private const int IdLeftLowerArm = 14; private const int IdLeftHand = 16; private const int IdRightUpperLeg = 18; private const int IdRightLowerLeg = 19; private const int IdRightFoot = 20; private const int IdRightToes = 21; private const int IdLeftUpperLeg = 22; private const int IdLeftLowerLeg = 23; private const int IdLeftFoot = 24; private const int IdLeftToes = 25; private static readonly FieldInfo RestField = typeof(Re4Rig).GetField("rest", BindingFlags.Instance | BindingFlags.NonPublic); public readonly Re4Rig Rig; private Transform parent; private Transform[] rigBones; private int[] parentIndex; private Quaternion[] tposeRotation; private Vector3[] tposePosition; private Quaternion frameRotation; private Vector3 framePosition; private int hipsIndex; private float hipsHeight; private readonly List<HumanBodyBones> humanBone = new List<HumanBodyBones>(); private readonly List<int> humanIndex = new List<int>(); private Quaternion[] humanRest; private Quaternion[] worldRotation; private Vector3[] worldPosition; private Quaternion[] targetRotation; private Vector3[] targetPosition; private int cachedFrame = -1; private SourceRig cachedSource; public bool Valid { get; private set; } public string Problem { get; private set; } private RigRetarget(Re4Rig rig) { Rig = rig; } public static RigRetarget Build(Re4Rig rig) { RigRetarget rigRetarget = new RigRetarget(rig); string step = "starting"; try { rigRetarget.Construct(ref step); rigRetarget.Valid = true; } catch (Exception ex) { rigRetarget.Problem = ex.GetType().Name + " while " + step + ": " + ex.Message; if (!(ex is InvalidOperationException)) { Plugin.Log.LogWarning((object)("REEmotes setup error detail: " + ex)); } } return rigRetarget; } public float HipsHeightWorld() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)parent == (Object)null)) { return hipsHeight * Mathf.Abs(parent.lossyScale.y); } return 0f; } public void Solve(SourceRig source) { //IL_0018: 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_0036: 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) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_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_007a: 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_0093: 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_00ea: 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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_010f: 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_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0131: 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_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_013e: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0172: 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_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0180: 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_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01af: 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_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) if (cachedFrame == Time.frameCount && cachedSource == source) { return; } Vector3 val = source.HipsFromGround() * (hipsHeight / source.HipsHeight); Quaternion val2 = Quaternion.Inverse(source.Root.rotation); Quaternion?[] array = new Quaternion?[rigBones.Length]; for (int i = 0; i < humanIndex.Count; i++) { if (source.TryGet(humanBone[i], out var transform, out var val3)) { Quaternion val4 = val2 * transform.rotation * Quaternion.Inverse(val3); array[humanIndex[i]] = val4 * humanRest[i]; } } for (int j = 0; j < rigBones.Length; j++) { int num = parentIndex[j]; Quaternion val5 = ((num < 0) ? frameRotation : worldRotation[num]); Vector3 val6 = ((num < 0) ? framePosition : worldPosition[num]); Quaternion val7 = Quaternion.Inverse(val5); Vector3 val8 = tposePosition[j]; if (j == hipsIndex) { val8 = val7 * (val - val6); } Quaternion val9 = (array[j].HasValue ? (val7 * array[j].Value) : tposeRotation[j]); worldRotation[j] = val5 * val9; worldPosition[j] = val6 + val5 * val8; targetRotation[j] = val9; targetPosition[j] = val8; } cachedFrame = Time.frameCount; cachedSource = source; } public void Write(float weight) { //IL_004d: 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_005f: 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_0077: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) bool flag = weight >= 0.999f; for (int i = 0; i < rigBones.Length; i++) { Transform val = rigBones[i]; if (!((Object)(object)val == (Object)null)) { if (flag) { val.localRotation = targetRotation[i]; val.localPosition = targetPosition[i]; } else { val.localRotation = Quaternion.Slerp(val.localRotation, targetRotation[i], weight); val.localPosition = Vector3.Lerp(val.localPosition, targetPosition[i], weight); } } } } public string Describe() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append($"REEmotes rig '{((Object)Rig).name}': {rigBones.Length} bones, hips {hipsHeight:0.###} units above the feet. Humanoid map: "); for (int i = 0; i < humanIndex.Count; i++) { if (i > 0) { stringBuilder.Append(", "); } stringBuilder.Append(humanBone[i]).Append('=').Append(((Object)rigBones[humanIndex[i]]).name); } return stringBuilder.ToString(); } private void Construct(ref string step) { //IL_05a8: Unknown result type (might be due to invalid IL or missing references) //IL_05ad: Unknown result type (might be due to invalid IL or missing references) //IL_0670: Unknown result type (might be due to invalid IL or missing references) //IL_0679: Unknown result type (might be due to invalid IL or missing references) //IL_067e: Unknown result type (might be due to invalid IL or missing references) //IL_0683: Unknown result type (might be due to invalid IL or missing references) //IL_0689: Unknown result type (might be due to invalid IL or missing references) //IL_0692: Unknown result type (might be due to invalid IL or missing references) //IL_0697: Unknown result type (might be due to invalid IL or missing references) //IL_069c: Unknown result type (might be due to invalid IL or missing references) //IL_060e: Unknown result type (might be due to invalid IL or missing references) //IL_061c: Unknown result type (might be due to invalid IL or missing references) //IL_0621: Unknown result type (might be due to invalid IL or missing references) //IL_0623: Unknown result type (might be due to invalid IL or missing references) //IL_0628: Unknown result type (might be due to invalid IL or missing references) //IL_063f: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Unknown result type (might be due to invalid IL or missing references) //IL_05f5: Unknown result type (might be due to invalid IL or missing references) //IL_06cc: Unknown result type (might be due to invalid IL or missing references) //IL_06ce: Unknown result type (might be due to invalid IL or missing references) //IL_06d0: Unknown result type (might be due to invalid IL or missing references) //IL_06d5: Unknown result type (might be due to invalid IL or missing references) //IL_06d9: Unknown result type (might be due to invalid IL or missing references) //IL_06de: Unknown result type (might be due to invalid IL or missing references) //IL_06e0: Unknown result type (might be due to invalid IL or missing references) //IL_06e2: Unknown result type (might be due to invalid IL or missing references) //IL_06e4: Unknown result type (might be due to invalid IL or missing references) //IL_06e9: Unknown result type (might be due to invalid IL or missing references) //IL_06ed: Unknown result type (might be due to invalid IL or missing references) //IL_06f2: Unknown result type (might be due to invalid IL or missing references) //IL_06f4: Unknown result type (might be due to invalid IL or missing references) //IL_06f9: Unknown result type (might be due to invalid IL or missing references) //IL_06fe: Unknown result type (might be due to invalid IL or missing references) //IL_0704: Unknown result type (might be due to invalid IL or missing references) //IL_0709: Unknown result type (might be due to invalid IL or missing references) //IL_0714: Unknown result type (might be due to invalid IL or missing references) //IL_0719: Unknown result type (might be due to invalid IL or missing references) //IL_072b: Unknown result type (might be due to invalid IL or missing references) //IL_0730: Unknown result type (might be due to invalid IL or missing references) //IL_0736: Unknown result type (might be due to invalid IL or missing references) //IL_073b: Unknown result type (might be due to invalid IL or missing references) //IL_0745: Unknown result type (might be due to invalid IL or missing references) //IL_074a: Unknown result type (might be due to invalid IL or missing references) //IL_074f: Unknown result type (might be due to invalid IL or missing references) //IL_0752: Unknown result type (might be due to invalid IL or missing references) //IL_0754: Unknown result type (might be due to invalid IL or missing references) //IL_075a: Unknown result type (might be due to invalid IL or missing references) //IL_075c: Unknown result type (might be due to invalid IL or missing references) //IL_075e: Unknown result type (might be due to invalid IL or missing references) //IL_0763: Unknown result type (might be due to invalid IL or missing references) //IL_0768: Unknown result type (might be due to invalid IL or missing references) //IL_05cb: Unknown result type (might be due to invalid IL or missing references) //IL_05d0: Unknown result type (might be due to invalid IL or missing references) //IL_0926: Unknown result type (might be due to invalid IL or missing references) //IL_0943: Unknown result type (might be due to invalid IL or missing references) //IL_0960: Unknown result type (might be due to invalid IL or missing references) //IL_097d: Unknown result type (might be due to invalid IL or missing references) //IL_099a: Unknown result type (might be due to invalid IL or missing references) //IL_09b7: Unknown result type (might be due to invalid IL or missing references) //IL_09d4: Unknown result type (might be due to invalid IL or missing references) //IL_09f1: Unknown result type (might be due to invalid IL or missing references) //IL_0a3c: Unknown result type (might be due to invalid IL or missing references) //IL_0a41: Unknown result type (might be due to invalid IL or missing references) //IL_0a48: Unknown result type (might be due to invalid IL or missing references) //IL_0a4d: Unknown result type (might be due to invalid IL or missing references) //IL_0a52: Unknown result type (might be due to invalid IL or missing references) //IL_0890: Unknown result type (might be due to invalid IL or missing references) //IL_0895: Unknown result type (might be due to invalid IL or missing references) //IL_089f: Unknown result type (might be due to invalid IL or missing references) //IL_08a1: Unknown result type (might be due to invalid IL or missing references) //IL_08aa: Unknown result type (might be due to invalid IL or missing references) //IL_08b8: Unknown result type (might be due to invalid IL or missing references) //IL_08bd: Unknown result type (might be due to invalid IL or missing references) //IL_08c2: Unknown result type (might be due to invalid IL or missing references) //IL_08c7: Unknown result type (might be due to invalid IL or missing references) //IL_08d4: Unknown result type (might be due to invalid IL or missing references) //IL_08d6: Unknown result type (might be due to invalid IL or missing references) //IL_08df: Unknown result type (might be due to invalid IL or missing references) //IL_08e4: Unknown result type (might be due to invalid IL or missing references) //IL_08e9: Unknown result type (might be due to invalid IL or missing references) //IL_0865: Unknown result type (might be due to invalid IL or missing references) //IL_086a: Unknown result type (might be due to invalid IL or missing references) //IL_087b: Unknown result type (might be due to invalid IL or missing references) //IL_0880: Unknown result type (might be due to invalid IL or missing references) //IL_0bc1: Unknown result type (might be due to invalid IL or missing references) //IL_0bc6: Unknown result type (might be due to invalid IL or missing references) Transform[] bones = Rig.Bones; int[] ids = Rig.Ids; if (bones == null || ids == null || bones.Length == 0 || bones.Length != ids.Length) { throw new InvalidOperationException("the rig has no bone list"); } step = "reading the bone list"; Dictionary<int, Transform> dictionary = new Dictionary<int, Transform>(); Dictionary<Transform, int> dictionary2 = new Dictionary<Transform, int>(); for (int i = 0; i < bones.Length; i++) { if (!((Object)(object)bones[i] == (Object)null) && !dictionary2.ContainsKey(bones[i])) { dictionary2[bones[i]] = i; if (!dictionary.ContainsKey(ids[i])) { dictionary[ids[i]] = bones[i]; } } } step = "mapping humanoid bones"; Transform val = Need(Find(dictionary, 7), "right upper arm"); Transform val2 = Need(Find(dictionary, 8), "right forearm"); Transform val3 = Need(Find(dictionary, 10), "right hand"); Transform val4 = Need(Find(dictionary, 13), "left upper arm"); Transform val5 = Need(Find(dictionary, 14), "left forearm"); Transform val6 = Need(Find(dictionary, 16), "left hand"); Transform val7 = Need(Find(dictionary, 18), "right thigh"); Transform val8 = Need(Find(dictionary, 19), "right shin"); Transform val9 = Need(Find(dictionary, 20), "right foot"); Transform val10 = Need(Find(dictionary, 22), "left thigh"); Transform val11 = Need(Find(dictionary, 23), "left shin"); Transform val12 = Need(Find(dictionary, 24), "left foot"); Transform val13 = Need(Find(dictionary, 4), "head"); Transform val14 = Common(Common(val10, val7), val13); if ((Object)(object)val14 == (Object)null) { throw new InvalidOperationException("legs and head don't share a parent bone"); } Transform val15 = Find(dictionary, 1); if ((Object)(object)val15 == (Object)null || !IsStrictAncestor(val14, val15) || !IsStrictAncestor(val15, val13)) { val15 = ChildToward(val14, val13); } if ((Object)(object)val15 == (Object)null || (Object)(object)val15 == (Object)(object)val13) { throw new InvalidOperationException("no spine bone between hips and head"); } Transform val16 = Find(dictionary, 2); if ((Object)(object)val16 != (Object)null && (!IsStrictAncestor(val15, val16) || !IsStrictAncestor(val16, val13))) { val16 = null; } Transform val17 = Find(dictionary, 3); Transform ancestor = val16 ?? val15; if ((Object)(object)val17 != (Object)null && (!IsStrictAncestor(ancestor, val17) || !IsStrictAncestor(val17, val13))) { val17 = null; } Transform val18 = val16 ?? val15; if (!IsStrictAncestor(val18, val) || !IsStrictAncestor(val18, val4)) { if ((Object)(object)val16 != (Object)null && IsStrictAncestor(val15, val) && IsStrictAncestor(val15, val4)) { val16 = null; } val18 = val16 ?? val15; if (!IsStrictAncestor(val18, val) || !IsStrictAncestor(val18, val4)) { throw new InvalidOperationException("arms are not attached under the spine"); } if ((Object)(object)val17 != (Object)null && !IsStrictAncestor(val18, val17)) { val17 = null; } } Transform val19 = ChildToward(val18, val); if ((Object)(object)val19 == (Object)(object)val || ((Object)(object)val17 != (Object)null && IsAncestor(val19, val17))) { val19 = null; } Transform val20 = ChildToward(val18, val4); if ((Object)(object)val20 == (Object)(object)val4 || ((Object)(object)val17 != (Object)null && IsAncestor(val20, val17))) { val20 = null; } Chain(val, val2, "right arm"); Chain(val2, val3, "right arm"); Chain(val4, val5, "left arm"); Chain(val5, val6, "left arm"); Chain(val14, val7, "right leg"); Chain(val7, val8, "right leg"); Chain(val8, val9, "right leg"); Chain(val14, val10, "left leg"); Chain(val10, val11, "left leg"); Chain(val11, val12, "left leg"); Transform val21 = Find(dictionary, 21); if ((Object)(object)val21 != (Object)null && (Object)(object)val21.parent != (Object)(object)val9) { val21 = null; } Transform val22 = Find(dictionary, 25); if ((Object)(object)val22 != (Object)null && (Object)(object)val22.parent != (Object)(object)val12) { val22 = null; } step = "collecting bones"; Transform val23 = val14; while ((Object)(object)val23.parent != (Object)null && dictionary2.ContainsKey(val23.parent)) { val23 = val23.parent; } parent = val23.parent; if ((Object)(object)parent == (Object)null) { throw new InvalidOperationException("the skeleton has no parent object"); } List<Transform> list = new List<Transform>(); foreach (Transform key in dictionary2.Keys) { Transform val24 = key; while ((Object)(object)val24.parent != (Object)null && dictionary2.ContainsKey(val24.parent)) { val24 = val24.parent; } if ((Object)(object)val24.parent == (Object)(object)parent) { list.Add(key); } } list.Sort((Transform a, Transform b) => Depth(a).CompareTo(Depth(b))); step = "reading bind poses"; Dictionary<Transform, Vector3> dictionary3 = new Dictionary<Transform, Vector3>(); Dictionary<Transform, Quaternion> dictionary4 = new Dictionary<Transform, Quaternion>(); BindPoses(list, dictionary3, dictionary4); Vector3[] array = RestField?.GetValue(Rig) as Vector3[]; step = "filling missing rest poses"; foreach (Transform item in list) { if (!dictionary3.ContainsKey(item)) { Vector3 val25 = item.localPosition; if (array != null && dictionary2.TryGetValue(item, out var value) && value < array.Length) { val25 = array[value]; } if ((Object)(object)item.parent == (Object)(object)parent) { dictionary3[item] = val25; dictionary4[item] = Quaternion.identity; } else { dictionary3[item] = dictionary3[item.parent] + dictionary4[item.parent] * val25; dictionary4[item] = dictionary4[item.parent]; } } } step = "finding the character's facing"; Vector3 val26 = dictionary3[val13] - dictionary3[val14]; Vector3 val27 = dictionary3[val] - dictionary3[val4]; if (((Vector3)(ref val26)).sqrMagnitude < 1E-08f || ((Vector3)(ref val27)).sqrMagnitude < 1E-08f) { throw new InvalidOperationException("the rest pose is degenerate"); } ((Vector3)(ref val26)).Normalize(); Vector3 val28 = Vector3.ProjectOnPlane(val27, val26); val27 = ((Vector3)(ref val28)).normalized; val28 = Vector3.Cross(val27, val26); Quaternion val29 = Quaternion.Inverse(Quaternion.LookRotation(((Vector3)(ref val28)).normalized, val26)); float num = Mathf.Min(Vector3.Dot(dictionary3[val9], val26), Vector3.Dot(dictionary3[val12], val26)); Vector3 val30 = dictionary3[val14] - val26 * (Vector3.Dot(dictionary3[val14], val26) - num); frameRotation = val29; framePosition = val29 * -val30; step = "building the rest pose"; rigBones = list.ToArray(); int num2 = rigBones.Length; Dictionary<Transform, int> dictionary5 = new Dictionary<Transform, int>(); for (int num3 = 0; num3 < num2; num3++) { dictionary5[rigBones[num3]] = num3; } parentIndex = new int[num2]; tposeRotation = (Quaternion[])(object)new Quaternion[num2]; tposePosition = (Vector3[])(object)new Vector3[num2]; worldRotation = (Quaternion[])(object)new Quaternion[num2]; worldPosition = (Vector3[])(object)new Vector3[num2]; targetRotation = (Quaternion[])(object)new Quaternion[num2]; targetPosition = (Vector3[])(object)new Vector3[num2]; for (int num4 = 0; num4 < num2; num4++) { Transform val31 = rigBones[num4]; bool flag = (Object)(object)val31.parent == (Object)(object)parent; parentIndex[num4] = (flag ? (-1) : dictionary5[val31.parent]); if (flag) { tposePosition[num4] = dictionary3[val31]; tposeRotation[num4] = dictionary4[val31]; } else { Quaternion val32 = dictionary4[val31.parent]; tposePosition[num4] = Quaternion.Inverse(val32) * (dictionary3[val31] - dictionary3[val31.parent]); tposeRotation[num4] = Quaternion.Inverse(val32) * dictionary4[val31]; } } hipsIndex = dictionary5[val14]; step = "posing the T-pose"; Aim(dictionary5[val], dictionary5[val2], Vector3.right); Aim(dictionary5[val2], dictionary5[val3], Vector3.right); Aim(dictionary5[val4], dictionary5[val5], Vector3.left); Aim(dictionary5[val5], dictionary5[val6], Vector3.left); Aim(dictionary5[val7], dictionary5[val8], Vector3.down); Aim(dictionary5[val8], dictionary5[val9], Vector3.down); Aim(dictionary5[val10], dictionary5[val11], Vector3.down); Aim(dictionary5[val11], dictionary5[val12], Vector3.down); Pose(); float num5 = Mathf.Min(worldPosition[dictionary5[val9]].y, worldPosition[dictionary5[val12]].y); framePosition -= Vector3.up * num5; Pose(); hipsHeight = worldPosition[hipsIndex].y; if (hipsHeight <= 0.0001f) { throw new InvalidOperationException("the hips are not above the feet"); } step = "recording the humanoid map"; Add((HumanBodyBones)0, val14, dictionary5); Add((HumanBodyBones)7, val15, dictionary5); Add((HumanBodyBones)8, val16, dictionary5); Add((HumanBodyBones)9, val17, dictionary5); Add((HumanBodyBones)10, val13, dictionary5); Add((HumanBodyBones)12, val19, dictionary5); Add((HumanBodyBones)14, val, dictionary5); Add((HumanBodyBones)16, val2, dictionary5); Add((HumanBodyBones)18, val3, dictionary5); Add((HumanBodyBones)11, val20, dictionary5); Add((HumanBodyBones)13, val4, dictionary5); Add((HumanBodyBones)15, val5, dictionary5); Add((HumanBodyBones)17, val6, dictionary5); Add((HumanBodyBones)2, val7, dictionary5); Add((HumanBodyBones)4, val8, dictionary5); Add((HumanBodyBones)6, val9, dictionary5); Add((HumanBodyBones)20, val21, dictionary5); Add((HumanBodyBones)1, val10, dictionary5); Add((HumanBodyBones)3, val11, dictionary5); Add((HumanBodyBones)5, val12, dictionary5); Add((HumanBodyBones)19, val22, dictionary5); humanRest = (Quaternion[])(object)new Quaternion[humanIndex.Count]; for (int num6 = 0; num6 < humanIndex.Count; num6++) { humanRest[num6] = worldRotation[humanIndex[num6]]; } } private void Pose() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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_003c: 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_0041: 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_0051: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_0070: 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_007a: 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) for (int i = 0; i < rigBones.Length; i++) { int num = parentIndex[i]; Quaternion val = ((num < 0) ? frameRotation : worldRotation[num]); Vector3 val2 = ((num < 0) ? framePosition : worldPosition[num]); worldRotation[i] = val * tposeRotation[i]; worldPosition[i] = val2 + val * tposePosition[i]; } } private void Aim(int bone, int child, Vector3 direction) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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_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_003b: 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) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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_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_0081: 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) Pose(); Vector3 val = worldPosition[child] - worldPosition[bone]; if (!(((Vector3)(ref val)).sqrMagnitude < 1E-10f)) { Quaternion val2 = Quaternion.FromToRotation(((Vector3)(ref val)).normalized, direction) * worldRotation[bone]; int num = parentIndex[bone]; Quaternion val3 = ((num < 0) ? frameRotation : worldRotation[num]); tposeRotation[bone] = Quaternion.Inverse(val3) * val2; } } private void Add(HumanBodyBones bone, Transform rigBone, Dictionary<Transform, int> slot) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)rigBone == (Object)null) && slot.TryGetValue(rigBone, out var value)) { humanBone.Add(bone); humanIndex.Add(value); } } private static Transform Find(Dictionary<int, Transform> byId, int id) { if (!byId.TryGetValue(id, out var value)) { return null; } return value; } private void BindPoses(List<Transform> mirror, Dictionary<Transform, Vector3> restPos, Dictionary<Transform, Quaternion> restRot) { //IL_000d: 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_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: 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_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: 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_012a: Unknown result type (might be due to invalid IL or missing references) HashSet<Transform> hashSet = new HashSet<Transform>(mirror); Matrix4x4 worldToLocalMatrix = parent.worldToLocalMatrix; List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>(); list.AddRange(((Component)Rig).GetComponentsInChildren<SkinnedMeshRenderer>(true)); if ((Object)(object)parent != (Object)(object)((Component)Rig).transform) { list.AddRange(((Component)parent).GetComponentsInChildren<SkinnedMeshRenderer>(true)); } foreach (SkinnedMeshRenderer item in list) { if ((Object)(object)item == (Object)null || (Object)(object)item.sharedMesh == (Object)null) { continue; } Transform[] bones = item.bones; Matrix4x4[] bindposes = item.sharedMesh.bindposes; if (bones == null || bindposes == null || bindposes.Length != bones.Length) { continue; } Matrix4x4 val = worldToLocalMatrix * ((Component)item).transform.localToWorldMatrix; for (int i = 0; i < bones.Length; i++) { Transform val2 = bones[i]; if (!((Object)(object)val2 == (Object)null) && hashSet.Contains(val2) && !restPos.ContainsKey(val2)) { Matrix4x4 m = val * ((Matrix4x4)(ref bindposes[i])).inverse; restPos[val2] = Vector4.op_Implicit(((Matrix4x4)(ref m)).GetColumn(3)); restRot[val2] = Rotation(m); } } } } private static Quaternion Rotation(Matrix4x4 m) { //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_000d: 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) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Vector4.op_Implicit(((Matrix4x4)(ref m)).GetColumn(2)); Vector3 val2 = Vector4.op_Implicit(((Matrix4x4)(ref m)).GetColumn(1)); if (((Vector3)(ref val)).sqrMagnitude < 1E-12f || ((Vector3)(ref val2)).sqrMagnitude < 1E-12f) { return Quaternion.identity; } return Quaternion.LookRotation(val, val2); } private static Transform Need(Transform bone, string what) { if ((Object)(object)bone == (Object)null) { throw new InvalidOperationException("no " + what + " bone"); } return bone; } private static void Chain(Transform upper, Transform lower, string what) { if (!IsStrictAncestor(upper, lower)) { throw new InvalidOperationException(what + " bones are not chained"); } } private static int Depth(Transform t) { int num = 0; Transform val = t.parent; while ((Object)(object)val != (Object)null) { num++; val = val.parent; } return num; } private static bool IsAncestor(Transform ancestor, Transform t) { Transform val = t; while ((Object)(object)val != (Object)null) { if ((Object)(object)val == (Object)(object)ancestor) { return true; } val = val.parent; } return false; } private static bool IsStrictAncestor(Transform ancestor, Transform t) { if ((Object)(object)ancestor != (Object)null && (Object)(object)t != (Object)null && (Object)(object)ancestor != (Object)(object)t) { return IsAncestor(ancestor, t); } return false; } private static Transform Common(Transform a, Transform b) { Transform val = a; while ((Object)(object)val != (Object)null) { if (IsAncestor(val, b)) { return val; } val = val.parent; } return null; } private static Transform ChildToward(Transform from, Transform to) { Transform val = to; while ((Object)(object)val != (Object)null) { if ((Object)(object)val.parent == (Object)(object)from) { return val; } val = val.parent; } return null; } } internal sealed class SourceRig { public readonly Animator Animator; public readonly Transform Root; private Transform[] bones = (Transform[])(object)new Transform[55]; private readonly Quaternion[] rest = (Quaternion[])(object)new Quaternion[55]; private readonly bool[] hasRest = new bool[55]; private float ground; public bool Valid { get; private set; } public string Problem { get; private set; } public string RestSource { get; private set; } public float HipsHeight { get; private set; } private SourceRig(Animator animator) { Animator = animator; Root = ((Component)animator).transform; } public static SourceRig Build(Animator animator, GameObject prefab) { SourceRig sourceRig = new SourceRig(animator); try { sourceRig.Construct(prefab); sourceRig.Valid = true; } catch (Exception ex) { sourceRig.Problem = ex.Message; } return sourceRig; } public SourceRig Remap(Transform metarig, string label) { Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>(); Transform[] componentsInChildren = ((Component)metarig).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (!dictionary.ContainsKey(((Object)val).name)) { dictionary[((Object)val).name] = val; } } SourceRig sourceRig = (SourceRig)MemberwiseClone(); sourceRig.bones = (Transform[])(object)new Transform[bones.Length]; int num = 0; for (int j = 0; j < bones.Length; j++) { if ((Object)(object)bones[j] != (Object)null && dictionary.TryGetValue(((Object)bones[j]).name, out var value)) { sourceRig.bones[j] = value; num++; } } sourceRig.RestSource = RestSource + ", " + label; if ((Object)(object)sourceRig.bones[0] == (Object)null) { sourceRig.Valid = false; sourceRig.Problem = "Lethal Company's skeleton has no '" + ((Object)bones[0]).name + "' bone"; } return sourceRig; } public bool TryGet(HumanBodyBones bone, out Transform transform, out Quaternion tposeRotation) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Expected I4, but got Unknown //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) int num = (int)bone; transform = bones[num]; tposeRotation = rest[num]; if ((Object)(object)transform != (Object)null) { return hasRest[num]; } return false; } public Vector3 HipsFromGround() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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) Vector3 result = Root.InverseTransformPoint(bones[0].position); result.y -= ground; return result; } private void Construct(GameObject prefab) { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: 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_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: 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_00aa: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_021b: 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_0224: Unknown result type (might be due to invalid IL or missing references) //IL_0229: 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_0206: 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_020f: Unknown result type (might be due to invalid IL or missing references) //IL_022b: 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_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0241: 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) Avatar avatar = Animator.avatar; if ((Object)(object)avatar == (Object)null || !avatar.isHuman) { throw new InvalidOperationException("the emote skeleton has no humanoid avatar"); } for (int i = 0; i < bones.Length; i++) { bones[i] = Animator.GetBoneTransform((HumanBodyBones)i); } if ((Object)(object)bones[0] == (Object)null) { throw new InvalidOperationException("the emote skeleton has no hips"); } Dictionary<string, SkeletonBone> dictionary = new Dictionary<string, SkeletonBone>(); try { SkeletonBone[] skeleton = avatar.humanDescription.skeleton; if (skeleton != null) { SkeletonBone[] array = skeleton; foreach (SkeletonBone val in array) { if (!string.IsNullOrEmpty(val.name) && !dictionary.ContainsKey(val.name)) { dictionary[val.name] = val; } } } } catch (Exception) { } Dictionary<string, Transform> dictionary2 = new Dictionary<string, Transform>(); if ((Object)(object)prefab != (Object)null) { Transform[] componentsInChildren = prefab.GetComponentsInChildren<Transform>(true); foreach (Transform val2 in componentsInChildren) { if (!dictionary2.ContainsKey(((Object)val2).name)) { dictionary2[((Object)val2).name] = val2; } } } int num = 0; int num2 = 0; Vector3[] array2 = (Vector3[])(object)new Vector3[bones.Length]; for (int k = 0; k < bones.Length; k++) { if ((Object)(object)bones[k] == (Object)null) { continue; } List<Transform> list = new List<Transform>(); Transform val3 = bones[k]; while ((Object)(object)val3 != (Object)null && (Object)(object)val3 != (Object)(object)Root) { list.Add(val3); val3 = val3.parent; } list.Reverse(); Vector3 val4 = Vector3.zero; Quaternion val5 = Quaternion.identity; foreach (Transform item in list) { Vector3 val6; Quaternion val7; Transform value2; if (dictionary.TryGetValue(((Object)item).name, out var value)) { val6 = value.position; val7 = value.rotation; num++; } else if (dictionary2.TryGetValue(((Object)item).name, out value2)) { val6 = value2.localPosition; val7 = value2.localRotation; num2++; } else { val6 = item.localPosition; val7 = item.localRotation; } val4 += val5 * val6; val5 *= val7; } rest[k] = val5; array2[k] = val4; hasRest[k] = true; } RestSource = ((num >= num2) ? "avatar T-pose" : "skeleton prefab pose"); int num3 = 5; int num4 = 6; if ((Object)(object)bones[num3] == (Object)null || (Object)(object)bones[num4] == (Object)null) { throw new InvalidOperationException("the emote skeleton has no feet"); } ground = Mathf.Min(array2[num3].y, array2[num4].y); HipsHeight = array2[0].y - ground; if (HipsHeight <= 0.0001f) { throw new InvalidOperationException("the emote skeleton's hips are not above its feet"); } } } }