using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using ModelReplacement; using ModelReplacement.AvatarBodyUpdater; using ModelReplacement.Monobehaviors; using UnityEngine; using UnityEngine.Rendering; [assembly: AssemblyTitle("Mobi Suit")] [assembly: AssemblyFileVersion("1.1.3.0")] [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("1.1.3.0")] namespace MobiSuitMod; internal static class BakedModel { private const string SourceHash = "083f76547201c3a30c8270a0d44c069c2201444408df3727e4ff9f60e11c6ad6"; internal static GameObject Load(string path, Material gameMaterial, List resources) { //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_038a: Unknown result type (might be due to invalid IL or missing references) //IL_0391: Expected O, but got Unknown //IL_03c9: Unknown result type (might be due to invalid IL or missing references) //IL_03d7: Unknown result type (might be due to invalid IL or missing references) //IL_0481: Unknown result type (might be due to invalid IL or missing references) //IL_0486: Unknown result type (might be due to invalid IL or missing references) //IL_0489: Unknown result type (might be due to invalid IL or missing references) //IL_048e: Unknown result type (might be due to invalid IL or missing references) //IL_0499: Unknown result type (might be due to invalid IL or missing references) //IL_04a0: Expected O, but got Unknown //IL_04d5: Unknown result type (might be due to invalid IL or missing references) //IL_04e3: Unknown result type (might be due to invalid IL or missing references) //IL_04f1: Unknown result type (might be due to invalid IL or missing references) //IL_054c: Unknown result type (might be due to invalid IL or missing references) //IL_0b15: Unknown result type (might be due to invalid IL or missing references) //IL_071d: Unknown result type (might be due to invalid IL or missing references) //IL_074c: Unknown result type (might be due to invalid IL or missing references) //IL_074e: Unknown result type (might be due to invalid IL or missing references) //IL_0770: Unknown result type (might be due to invalid IL or missing references) //IL_0775: Unknown result type (might be due to invalid IL or missing references) //IL_085d: Unknown result type (might be due to invalid IL or missing references) //IL_0864: Expected O, but got Unknown //IL_0b8f: Unknown result type (might be due to invalid IL or missing references) //IL_0ba7: Unknown result type (might be due to invalid IL or missing references) //IL_0bbf: Unknown result type (might be due to invalid IL or missing references) //IL_0bef: Unknown result type (might be due to invalid IL or missing references) //IL_0c0e: Unknown result type (might be due to invalid IL or missing references) //IL_0c60: Unknown result type (might be due to invalid IL or missing references) //IL_0c6c: Unknown result type (might be due to invalid IL or missing references) //IL_0c71: Unknown result type (might be due to invalid IL or missing references) //IL_0c76: Unknown result type (might be due to invalid IL or missing references) //IL_0c92: Unknown result type (might be due to invalid IL or missing references) //IL_0c97: Unknown result type (might be due to invalid IL or missing references) //IL_0c9c: Unknown result type (might be due to invalid IL or missing references) //IL_0cb8: Unknown result type (might be due to invalid IL or missing references) //IL_0cbd: Unknown result type (might be due to invalid IL or missing references) //IL_0cc3: Unknown result type (might be due to invalid IL or missing references) //IL_0cc5: Unknown result type (might be due to invalid IL or missing references) //IL_0cdf: Unknown result type (might be due to invalid IL or missing references) GameObject val = null; List list = new List(); try { using (FileStream fileStream = File.OpenRead(path)) { using BinaryReader binaryReader = new BinaryReader(fileStream, Encoding.UTF8); if (Encoding.ASCII.GetString(Bytes(binaryReader, 8)) != "MOBISUIT" || binaryReader.ReadInt32() != 1) { throw new InvalidDataException("Unsupported Mobi model data."); } string text = BitConverter.ToString(Bytes(binaryReader, 32)).Replace("-", "").ToLowerInvariant(); if (text != "083f76547201c3a30c8270a0d44c069c2201444408df3727e4ff9f60e11c6ad6") { throw new InvalidDataException("This model data belongs to a different source model."); } val = new GameObject("Mobi Suit cached template"); int num = Count(binaryReader, 126, 126); Transform[] array = (Transform[])(object)new Transform[num]; int[] array2 = new int[num]; HashSet hashSet = new HashSet(StringComparer.Ordinal); hashSet.Add(((Object)val).name); HashSet hashSet2 = hashSet; for (int i = 0; i < num; i++) { string text2 = Text(binaryReader); if (!hashSet2.Add(text2)) { throw new InvalidDataException("Duplicate model node name."); } array[i] = new GameObject(text2).transform; array[i].SetParent(val.transform, false); array2[i] = binaryReader.ReadInt32(); if (array2[i] < -1 || array2[i] >= i) { throw new InvalidDataException("Model nodes must be ordered before their children."); } array[i].SetParent((array2[i] < 0) ? val.transform : array[array2[i]], false); array[i].localPosition = Vector3Value(binaryReader); array[i].localRotation = new Quaternion(Float(binaryReader), Float(binaryReader), Float(binaryReader), Float(binaryReader)); array[i].localScale = Vector3Value(binaryReader); } Dictionary dictionary = ((IEnumerable)HumanTrait.BoneName).ToDictionary((Func)((string text5) => (HumanBodyBones)Enum.Parse(typeof(HumanBodyBones), text5.Replace(" ", ""))), (Func)((string result) => result)); int num2 = Count(binaryReader, 51, 51); HumanBone[] array3 = (HumanBone[])(object)new HumanBone[num2]; Dictionary dictionary2 = new Dictionary(); for (int num3 = 0; num3 < num2; num3++) { Transform val2 = array[Index(binaryReader, array.Length)]; HumanBodyBones key = (HumanBodyBones)Enum.Parse(typeof(HumanBodyBones), Text(binaryReader)); dictionary2.Add(key, val2); ref HumanBone reference = ref array3[num3]; HumanBone val3 = default(HumanBone); ((HumanBone)(ref val3)).boneName = ((Object)val2).name; ((HumanBone)(ref val3)).humanName = dictionary[key]; HumanLimit limit = default(HumanLimit); ((HumanLimit)(ref limit)).useDefaultValues = true; val3.limit = limit; reference = val3; } HumanDescription val4 = new HumanDescription { human = array3 }; ((HumanDescription)(ref val4)).upperArmTwist = Float(binaryReader); ((HumanDescription)(ref val4)).lowerArmTwist = Float(binaryReader); ((HumanDescription)(ref val4)).upperLegTwist = Float(binaryReader); ((HumanDescription)(ref val4)).lowerLegTwist = Float(binaryReader); ((HumanDescription)(ref val4)).armStretch = Float(binaryReader); ((HumanDescription)(ref val4)).legStretch = Float(binaryReader); ((HumanDescription)(ref val4)).feetSpacing = Float(binaryReader); ((HumanDescription)(ref val4)).hasTranslationDoF = binaryReader.ReadBoolean(); HumanDescription val5 = val4; Texture2D[] array4 = (Texture2D[])(object)new Texture2D[Count(binaryReader, 2, 2)]; for (int num4 = 0; num4 < array4.Length; num4++) { string text3 = Text(binaryReader); int mode = binaryReader.ReadInt32(); int mode2 = binaryReader.ReadInt32(); int num5 = binaryReader.ReadInt32(); int num6 = binaryReader.ReadInt32(); byte[] array5 = Bytes(binaryReader, Count(binaryReader, 1, 67108864)); Texture2D val6 = new Texture2D(2, 2, (TextureFormat)4, true, false); list.Add((Object)(object)val6); ((Object)val6).name = text3; if (!ImageConversion.LoadImage(val6, array5, false)) { throw new InvalidDataException("Could not decode Mobi's texture " + text3 + "."); } ((Texture)val6).wrapModeU = Wrap(mode); ((Texture)val6).wrapModeV = Wrap(mode2); ((Texture)val6).filterMode = (FilterMode)((num5 == 9987) ? 2 : ((num6 != 9728 || num5 != 9728) ? 1 : 0)); array4[num4] = val6; } Material[] array6 = (Material[])(object)new Material[Count(binaryReader, 3, 3)]; Color val7 = default(Color); for (int num7 = 0; num7 < array6.Length; num7++) { string name = Text(binaryReader); ((Color)(ref val7))..ctor(Float(binaryReader), Float(binaryReader), Float(binaryReader), Float(binaryReader)); int num8 = binaryReader.ReadInt32(); if (num8 < -1 || num8 >= array4.Length) { throw new InvalidDataException("Invalid material texture."); } Vector2 val8 = Vector2Value(binaryReader); Vector2 val9 = Vector2Value(binaryReader); bool flag = binaryReader.ReadBoolean(); Material val10 = new Material(gameMaterial); list.Add((Object)(object)val10); ((Object)val10).name = name; val10.SetTexture("_BaseColorMap", (Texture)(object)((num8 < 0) ? Texture2D.whiteTexture : array4[num8])); val10.SetTextureScale("_BaseColorMap", val8); val10.SetTextureOffset("_BaseColorMap", val9); val10.SetColor("_BaseColor", val7); val10.SetFloat("_Smoothness", 0f); val10.SetFloat("_Metallic", 0f); val10.SetFloat("_NormalScale", 0f); val10.SetTexture("_NormalMap", (Texture)null); val10.SetTexture("_MaskMap", (Texture)null); val10.SetColor("_EmissiveColor", Color.black); val10.SetFloat("_AlphaCutoffEnable", 0f); val10.DisableKeyword("_ALPHATEST_ON"); if (flag && val10.HasProperty("_DoubleSidedEnable")) { val10.SetFloat("_DoubleSidedEnable", 1f); val10.EnableKeyword("_DOUBLESIDED_ON"); } array6[num7] = val10; } int num9 = Count(binaryReader, 2, 2); for (int num10 = 0; num10 < num9; num10++) { Transform val11 = array[Index(binaryReader, array.Length)]; string name2 = Text(binaryReader); int num11 = Count(binaryReader, 1, 100000); Vector3[] vertices = Vector3Array(binaryReader, num11); Vector3[] normals = Vector3Array(binaryReader, num11); Vector2[] uv = Vector2Array(binaryReader, num11); Vector2[] uv2 = Vector2Array(binaryReader, num11); BoneWeight[] array7 = (BoneWeight[])(object)new BoneWeight[num11]; for (int num12 = 0; num12 < num11; num12++) { ((BoneWeight)(ref array7[num12])).boneIndex0 = binaryReader.ReadInt32(); ((BoneWeight)(ref array7[num12])).boneIndex1 = binaryReader.ReadInt32(); ((BoneWeight)(ref array7[num12])).boneIndex2 = binaryReader.ReadInt32(); ((BoneWeight)(ref array7[num12])).boneIndex3 = binaryReader.ReadInt32(); } for (int num13 = 0; num13 < num11; num13++) { ((BoneWeight)(ref array7[num13])).weight0 = Float(binaryReader); ((BoneWeight)(ref array7[num13])).weight1 = Float(binaryReader); ((BoneWeight)(ref array7[num13])).weight2 = Float(binaryReader); ((BoneWeight)(ref array7[num13])).weight3 = Float(binaryReader); } int num14 = Count(binaryReader, 1, 256); Transform[] array8 = (Transform[])(object)new Transform[num14]; Matrix4x4[] array9 = (Matrix4x4[])(object)new Matrix4x4[num14]; for (int num15 = 0; num15 < num14; num15++) { array8[num15] = array[Index(binaryReader, array.Length)]; Matrix4x4 val12 = default(Matrix4x4); for (int num16 = 0; num16 < 16; num16++) { ((Matrix4x4)(ref val12))[num16] = Float(binaryReader); } array9[num15] = val12; } for (int num17 = 0; num17 < num11; num17++) { BoneWeight val13 = array7[num17]; if (((BoneWeight)(ref val13)).boneIndex0 < 0 || ((BoneWeight)(ref val13)).boneIndex0 >= num14 || ((BoneWeight)(ref val13)).boneIndex1 < 0 || ((BoneWeight)(ref val13)).boneIndex1 >= num14 || ((BoneWeight)(ref val13)).boneIndex2 < 0 || ((BoneWeight)(ref val13)).boneIndex2 >= num14 || ((BoneWeight)(ref val13)).boneIndex3 < 0 || ((BoneWeight)(ref val13)).boneIndex3 >= num14 || ((BoneWeight)(ref val13)).weight0 < 0f || ((BoneWeight)(ref val13)).weight1 < 0f || ((BoneWeight)(ref val13)).weight2 < 0f || ((BoneWeight)(ref val13)).weight3 < 0f || Math.Abs(((BoneWeight)(ref val13)).weight0 + ((BoneWeight)(ref val13)).weight1 + ((BoneWeight)(ref val13)).weight2 + ((BoneWeight)(ref val13)).weight3 - 1f) > 0.001f) { throw new InvalidDataException("Invalid skin weights."); } } Mesh val14 = new Mesh(); list.Add((Object)(object)val14); ((Object)val14).name = name2; val14.indexFormat = (IndexFormat)(num11 > 65535); val14.vertices = vertices; val14.normals = normals; val14.uv = uv; val14.uv2 = uv2; val14.boneWeights = array7; val14.bindposes = array9; int num18 = (val14.subMeshCount = Count(binaryReader, 1, 16)); Material[] array10 = (Material[])(object)new Material[num18]; for (int num20 = 0; num20 < num18; num20++) { array10[num20] = array6[Index(binaryReader, array6.Length)]; int num21 = Count(binaryReader, 3, 1000000); if (num21 % 3 != 0) { throw new InvalidDataException("Invalid triangle count."); } int[] array11 = new int[num21]; for (int num22 = 0; num22 < num21; num22++) { array11[num22] = Index(binaryReader, num11); } val14.SetTriangles(array11, num20, false); } int num23 = Count(binaryReader, 0, 256); float[] array12 = new float[num23]; for (int num24 = 0; num24 < num23; num24++) { string text4 = Text(binaryReader); array12[num24] = Float(binaryReader) * 100f; Vector3[] array13 = Vector3Array(binaryReader, num11); Vector3[] array14 = Vector3Array(binaryReader, num11); val14.AddBlendShapeFrame(text4, 100f, array13, array14, (Vector3[])null); } val14.RecalculateBounds(); val14.RecalculateTangents(); SkinnedMeshRenderer val15 = ((Component)val11).gameObject.AddComponent(); ((Renderer)val15).enabled = false; val15.bones = array8; val15.sharedMesh = val14; val15.rootBone = array8[0]; ((Renderer)val15).sharedMaterials = array10; val15.quality = (SkinQuality)4; val15.updateWhenOffscreen = true; for (int num25 = 0; num25 < num23; num25++) { val15.SetBlendShapeWeight(num25, array12[num25]); } } if (fileStream.Position != fileStream.Length) { throw new InvalidDataException("Unexpected trailing model data."); } Transform[] componentsInChildren = val.GetComponentsInChildren(true); Vector3[] array15 = componentsInChildren.Select((Transform t) => t.localPosition).ToArray(); Quaternion[] array16 = componentsInChildren.Select((Transform t) => t.localRotation).ToArray(); Vector3[] array17 = componentsInChildren.Select((Transform t) => t.localScale).ToArray(); val5.skeleton = ((IEnumerable)componentsInChildren).Select((Func)((Transform t) => new SkeletonBone { name = ((Object)t).name, position = t.localPosition, rotation = t.localRotation, scale = t.localScale })).ToArray(); Avatar val16 = AvatarBuilder.BuildHumanAvatar(val, val5); if ((Object)(object)val16 != (Object)null) { list.Add((Object)(object)val16); } if ((Object)(object)val16 == (Object)null || !val16.isValid || !val16.isHuman) { throw new InvalidDataException("Mobi's baked rig did not produce a valid humanoid Avatar."); } ((Object)val16).name = "Mobi humanoid"; Animator val17 = val.AddComponent(); ((Behaviour)val17).enabled = false; val17.avatar = val16; for (int num26 = 0; num26 < componentsInChildren.Length; num26++) { componentsInChildren[num26].localPosition = array15[num26]; componentsInChildren[num26].localRotation = array16[num26]; componentsInChildren[num26].localScale = array17[num26]; } foreach (KeyValuePair item in dictionary2) { if ((Object)(object)val17.GetBoneTransform(item.Key) != (Object)(object)item.Value) { throw new InvalidDataException(string.Concat("Humanoid bone mapping failed for ", item.Key, ".")); } } SkinnedMeshRenderer[] componentsInChildren2 = val.GetComponentsInChildren(true); Bounds localBounds = default(Bounds); foreach (SkinnedMeshRenderer val18 in componentsInChildren2) { Matrix4x4 val19 = val18.rootBone.worldToLocalMatrix * ((Component)val18).transform.localToWorldMatrix; Vector3[] vertices2 = val18.sharedMesh.vertices; ((Bounds)(ref localBounds))..ctor(((Matrix4x4)(ref val19)).MultiplyPoint3x4(vertices2[0]), Vector3.zero); Vector3[] array18 = vertices2; foreach (Vector3 val20 in array18) { ((Bounds)(ref localBounds)).Encapsulate(((Matrix4x4)(ref val19)).MultiplyPoint3x4(val20)); } ((Renderer)val18).localBounds = localBounds; } } resources.AddRange(list); return val; } catch { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } foreach (Object item2 in list) { if (item2 != (Object)null) { Object.Destroy(item2); } } throw; } } private static TextureWrapMode Wrap(int mode) { return (TextureWrapMode)(mode switch { 10497 => 0, 33071 => 1, 33648 => 2, _ => throw new InvalidDataException("Unsupported texture wrap mode."), }); } private static int Count(BinaryReader reader, int min, int max) { int num = reader.ReadInt32(); if (num < min || num > max) { throw new InvalidDataException("Invalid model count."); } return num; } private static int Index(BinaryReader reader, int length) { return Count(reader, 0, length - 1); } private static byte[] Bytes(BinaryReader reader, int count) { byte[] array = reader.ReadBytes(count); if (array.Length != count) { throw new EndOfStreamException(); } return array; } private static string Text(BinaryReader reader) { return new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true).GetString(Bytes(reader, Count(reader, 1, 4096))); } private static float Float(BinaryReader reader) { float num = reader.ReadSingle(); if (float.IsNaN(num) || float.IsInfinity(num)) { throw new InvalidDataException("Non-finite model value."); } return num; } private static Vector3 Vector3Value(BinaryReader reader) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) return new Vector3(Float(reader), Float(reader), Float(reader)); } private static Vector2 Vector2Value(BinaryReader reader) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) return new Vector2(Float(reader), Float(reader)); } private static Vector3[] Vector3Array(BinaryReader reader, int count) { //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) Vector3[] array = (Vector3[])(object)new Vector3[count]; for (int i = 0; i < count; i++) { ref Vector3 reference = ref array[i]; reference = Vector3Value(reader); } return array; } private static Vector2[] Vector2Array(BinaryReader reader, int count) { //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) Vector2[] array = (Vector2[])(object)new Vector2[count]; for (int i = 0; i < count; i++) { ref Vector2 reference = ref array[i]; reference = Vector2Value(reader); } return array; } } [BepInDependency("meow.ModelReplacementAPI", "2.4.20")] [BepInPlugin("MadJack.MobiSuit", "Mobi Suit", "1.1.3")] [BepInIncompatibility("MadJack.MobiSuit.MadJackTest")] public sealed class MobiSuitPlugin : BaseUnityPlugin { internal static MobiSuitPlugin Instance; internal GameObject Template; internal ConfigEntry GenerateArms; internal ConfigEntry RemoveHelmet; internal ConfigEntry ModelScale; private ConfigEntry steamId; private bool loading; private bool loadFailed; private bool assignmentFailed; private readonly List ownedResources = new List(); private readonly Dictionary playerStates = new Dictionary(); private string scanState; private bool hookObserved; private float nextScan; private string modelPath; private void Awake() { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown Instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); modelPath = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Mobi.model"); steamId = ((BaseUnityPlugin)this).Config.Bind("Assignment", "SteamID64", "76561198392031972", "Only this Steam account receives Mobi. Use a 17-digit Steam64 ID. Restart after editing."); GenerateArms = ((BaseUnityPlugin)this).Config.Bind("Appearance", "GenerateFirstPersonArms", false, "Generate Mobi first-person arms using ModelReplacementAPI. Optional and disabled by default."); RemoveHelmet = ((BaseUnityPlugin)this).Config.Bind("Appearance", "RemoveHelmet", false, "Hide the helmet for Mobi's local player."); ModelScale = ((BaseUnityPlugin)this).Config.Bind("Appearance", "Scale", 1f, new ConfigDescription("Scale multiplier after the API's normal player-height adjustment.", (AcceptableValueBase)(object)new AcceptableValueRange(0.25f, 2f), new object[0])); if (!Assignment.TryParse(steamId.Value, out var id)) { ((BaseUnityPlugin)this).Logger.LogError((object)"Invalid SteamID64. Mobi is disabled until the configuration is corrected and the game restarted."); ((Behaviour)this).enabled = false; return; } try { V80Compatibility.Apply(((BaseUnityPlugin)this).Logger); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Mobi could not initialize the V80 inventory compatibility fix. " + ex)); ((Behaviour)this).enabled = false; return; } ModelReplacementAPI.RegisterModelReplacementException(typeof(MobiBodyReplacement)); try { MobiPlayerDetection.Install(); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Mobi Suit ready for Steam64 " + id + ". PlayerControllerB.LateUpdate hook installed (1.1.3).")); } catch (Exception ex2) { assignmentFailed = true; ((BaseUnityPlugin)this).Logger.LogError((object)("Mobi could not install its player update hook. " + ex2)); } } internal void OnPlayerLateUpdate() { if (!hookObserved) { hookObserved = true; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Mobi player update hook reached (1.1.3). Starting player scans."); } if (!loadFailed && !assignmentFailed && !(Time.unscaledTime < nextScan)) { nextScan = Time.unscaledTime + 0.25f; ScanPlayers(); } } internal void ScanPlayers() { if (loadFailed || assignmentFailed || !Assignment.TryParse(steamId.Value, out var id)) { return; } PlayerControllerB[] array = Object.FindObjectsOfType(true); int num = 0; PlayerControllerB[] array2 = array; BodyReplacementBase val2 = default(BodyReplacementBase); foreach (PlayerControllerB val in array2) { if ((Object)(object)val == (Object)null) { continue; } MobiBodyReplacement component = ((Component)val).GetComponent(); if ((Object)(object)component != (Object)null && (val.disconnectedMidGame || !Assignment.Matches(id, val.playerSteamId))) { ModelReplacementAPI.RemovePlayerModelReplacement(val); } else { if (!Assignment.Matches(id, val.playerSteamId)) { continue; } num++; if (!((Component)val).gameObject.activeInHierarchy || val.disconnectedMidGame || !val.isPlayerControlled) { PlayerState(val, "Waiting: target object active=" + ((Component)val).gameObject.activeInHierarchy + ", disconnected=" + val.disconnectedMidGame + ", controlled=" + val.isPlayerControlled + "."); continue; } StartOfRound instance = StartOfRound.Instance; if ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null || (Object)(object)instance == (Object)null || (Object)(object)instance.unlockablesList == (Object)null || instance.unlockablesList.unlockables == null || val.currentSuitID < 0 || val.currentSuitID >= instance.unlockablesList.unlockables.Count || instance.unlockablesList.unlockables[val.currentSuitID] == null) { PlayerState(val, "Waiting: lobby and suit data are not ready for ModelReplacementAPI."); continue; } if (ModelReplacementAPI.GetPlayerModelReplacement(val, ref val2)) { PlayerState(val, (val2 is MobiBodyReplacement) ? "Mobi is already assigned." : ("Assignment blocked by existing replacement: " + ((object)val2).GetType().FullName + ".")); continue; } if ((Object)(object)val.thisPlayerModel == (Object)null || (Object)(object)((Renderer)val.thisPlayerModel).sharedMaterial == (Object)null || (Object)(object)((Renderer)val.thisPlayerModel).sharedMaterial.shader == (Object)null) { PlayerState(val, "Waiting: ModelReplacementAPI's primary player renderer/material is not ready."); continue; } Material val3 = FindGameMaterial(val); if ((Object)(object)val3 == (Object)null) { PlayerState(val, "Waiting: no compatible player material is available yet."); continue; } bool flag = false; if ((Object)(object)((Component)val).GetComponent() == (Object)null) { ((Component)val).gameObject.AddComponent(); flag = true; } if ((Object)(object)((Component)val).GetComponent() == (Object)null) { ((Component)val).gameObject.AddComponent(); flag = true; } if (flag) { PlayerState(val, "Restored missing ModelReplacementAPI player components; waiting for their Start methods."); continue; } if ((Object)(object)Template == (Object)null) { PlayerState(val, "Target matched. Loading Mobi with material " + ((Object)val3).name + "."); if (!loading) { LoadTemplate(val3); } return; } try { ModelReplacementAPI.SetPlayerModelReplacement(val, typeof(MobiBodyReplacement)); if (ModelReplacementAPI.GetPlayerModelReplacement(val, ref val2) && val2 is MobiBodyReplacement) { if ((Object)(object)val2.replacementModel == (Object)null || val2.avatar == null) { assignmentFailed = true; ModelReplacementAPI.RemovePlayerModelReplacement(val); ((BaseUnityPlugin)this).Logger.LogError((object)"Mobi did not finish initialization. Check the earlier API error and restart after fixing it."); return; } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Applied Mobi to " + val.playerUsername + " (" + val.playerSteamId + ").")); PlayerState(val, "Mobi is already assigned."); } else { PlayerState(val, "ModelReplacementAPI did not create the replacement; waiting to retry."); } } catch (Exception ex) { assignmentFailed = true; ((BaseUnityPlugin)this).Logger.LogError((object)("Mobi assignment failed; further attempts stopped. Restart after fixing the cause. " + ex)); } } } string text = ((num > 0) ? "Target player detected." : ("Waiting for Steam64 " + id + "; player objects=" + array.Length + "; observed IDs=" + string.Join(",", (from p in array where (Object)(object)p != (Object)null select p.playerSteamId.ToString()).Distinct().ToArray()))); if (scanState != text) { scanState = text; ((BaseUnityPlugin)this).Logger.LogInfo((object)text); } } internal void ReportDetectorError(Exception error) { if (!assignmentFailed) { assignmentFailed = true; ((BaseUnityPlugin)this).Logger.LogError((object)("Mobi player detection failed; further attempts stopped. " + error)); } } private void PlayerState(PlayerControllerB player, string state) { int instanceID = ((Object)player).GetInstanceID(); if (!playerStates.TryGetValue(instanceID, out var value) || !(value == state)) { playerStates[instanceID] = state; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Player " + player.playerUsername + " (" + player.playerSteamId + "): " + state)); } } private static Material FindGameMaterial(PlayerControllerB player) { if ((Object)(object)player.thisPlayerModel != (Object)null) { Material[] sharedMaterials = ((Renderer)player.thisPlayerModel).sharedMaterials; foreach (Material val in sharedMaterials) { if ((Object)(object)val != (Object)null && (Object)(object)val.shader != (Object)null && val.HasProperty("_BaseColorMap")) { return val; } } } SkinnedMeshRenderer[] componentsInChildren = ((Component)player).GetComponentsInChildren(true); foreach (SkinnedMeshRenderer val2 in componentsInChildren) { Material[] sharedMaterials2 = ((Renderer)val2).sharedMaterials; foreach (Material val3 in sharedMaterials2) { if ((Object)(object)val3 != (Object)null && (Object)(object)val3.shader != (Object)null && val3.HasProperty("_BaseColorMap")) { return val3; } } } return null; } private void LoadTemplate(Material gameMaterial) { //IL_006c: 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_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: 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_0103: Unknown result type (might be due to invalid IL or missing references) loading = true; GameObject val = null; try { if (!File.Exists(modelPath)) { throw new FileNotFoundException("Keep Mobi.model beside MobiSuit.dll.", modelPath); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading Mobi's converted mesh and humanoid rig."); GameObject val2 = BakedModel.Load(modelPath, gameMaterial, ownedResources); val = val2; Object.DontDestroyOnLoad((Object)(object)val2); Animator component = val2.GetComponent(); MobiRig.Apply(component); OffsetBuilder val3 = ((Component)component).gameObject.AddComponent(); val3.rootScale = Vector3.one * ModelScale.Value; val3.GenerateViewModel = GenerateArms.Value; val3.RemoveHelmet = RemoveHelmet.Value; val3.UseNoPostProcessing = false; SkinnedMeshRenderer[] componentsInChildren = val2.GetComponentsInChildren(true); Bounds bounds = ((Renderer)componentsInChildren[0]).bounds; SkinnedMeshRenderer[] array = componentsInChildren; foreach (SkinnedMeshRenderer val4 in array) { ((Bounds)(ref bounds)).Encapsulate(((Renderer)val4).bounds); } val3.rootPositionOffset = ReferencePose.CalculateRootOffset(component, bounds, ModelScale.Value); Renderer[] componentsInChildren2 = val2.GetComponentsInChildren(true); foreach (Renderer val5 in componentsInChildren2) { val5.enabled = false; val5.receiveShadows = true; val5.shadowCastingMode = (ShadowCastingMode)2; } Template = val2; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Mobi humanoid template loaded. Player assignment will now use ModelReplacementAPI."); } catch (Exception ex) { loadFailed = true; if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } ((BaseUnityPlugin)this).Logger.LogError((object)("Mobi model loading failed; further attempts stopped. " + ex)); } finally { loading = false; } } } internal static class MobiPlayerDetection { internal static void Install() { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(PlayerControllerB), "LateUpdate", Type.EmptyTypes, (Type[])null); MethodInfo methodInfo2 = AccessTools.DeclaredMethod(typeof(MobiPlayerDetection), "AfterPlayerLateUpdate", Type.EmptyTypes, (Type[])null); if (methodInfo == null || methodInfo2 == null) { throw new MissingMethodException("Mobi player update hook could not find its methods."); } new Harmony("MadJack.MobiSuit.PlayerDetection").Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static void AfterPlayerLateUpdate() { MobiSuitPlugin instance = MobiSuitPlugin.Instance; if (object.ReferenceEquals(instance, null)) { return; } try { instance.OnPlayerLateUpdate(); } catch (Exception error) { instance.ReportDetectorError(error); } } } public static class Assignment { public static bool TryParse(string value, out ulong id) { id = 0uL; if (value != null && value.Length == 17 && value.StartsWith("7656119", StringComparison.Ordinal) && ulong.TryParse(value, out id)) { return id > 76561197960265728L; } return false; } public static bool Matches(ulong configured, ulong actual) { if (configured != 0 && actual != 0) { return configured == actual; } return false; } } public sealed class MobiBodyReplacement : BodyReplacementBase { protected override void AddModelScripts() { Renderer[] componentsInChildren = base.replacementModel.GetComponentsInChildren(true); foreach (Renderer val in componentsInChildren) { val.enabled = true; } } protected override GameObject LoadAssetsAndReturnModel() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) MobiSuitPlugin instance = MobiSuitPlugin.Instance; if (object.ReferenceEquals(instance, null) || (Object)(object)instance.Template == (Object)null) { throw new InvalidOperationException("Mobi template is not ready."); } instance.Template.transform.localScale = Vector3.one; instance.Template.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); return instance.Template; } } internal sealed class MobiRig : AvatarUpdater { internal static void Apply(Animator animator) { //IL_0013: 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_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_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) Transform[] componentsInChildren = ((Component)animator).gameObject.GetComponentsInChildren(true); SkeletonBone[] skeleton = animator.avatar.humanDescription.skeleton; foreach (SkeletonBone bone in skeleton) { Func predicate = (Transform val3) => ((Object)val3).name == bone.name; Transform val = componentsInChildren.FirstOrDefault(predicate); if ((Object)(object)val != (Object)null) { val.localRotation = bone.rotation; } } Dictionary rotations = ReferencePose.GetRotations(); Dictionary dictionary = new Dictionary(AvatarUpdater.modelToAvatarBone); bool flag = (Object)(object)animator.GetBoneTransform((HumanBodyBones)54) != (Object)null; if (flag) { dictionary["spine.002"] = (HumanBodyBones)8; } dictionary["spine.003"] = (HumanBodyBones)(flag ? 54 : 8); foreach (KeyValuePair item in dictionary) { Transform boneTransform = animator.GetBoneTransform(item.Value); if (!((Object)(object)boneTransform == (Object)null) && rotations.TryGetValue(item.Key, out var value)) { RotationOffset val2 = ((Component)boneTransform).gameObject.AddComponent(); val2.offset = Quaternion.Inverse(value) * boneTransform.rotation; } } } } internal static class ReferencePose { internal static readonly Vector3 HipsPosition = new Vector3(0f, 1.2622944f, -0.09272201f); internal static readonly Vector3 SpinePosition = new Vector3(3.0441368E-14f, 1.4085414f, -0.05483783f); internal static readonly Vector3 LeftToesPosition = new Vector3(-0.1584645f, -0.010062802f, 0.068162985f); internal static readonly Vector3 RightToesPosition = new Vector3(0.1657071f, -0.010440803f, 0.057560906f); internal static readonly Vector3 LeftFootPosition = new Vector3(-0.1553287f, 0.077057555f, -0.04766048f); internal static readonly Vector3 RightFootPosition = new Vector3(0.16240005f, 0.077721484f, -0.05746692f); private static readonly Vector3 HipInverseUp = new Vector3(-1.0660793E-07f, 0.86307454f, -0.22357298f); internal static Vector3 CalculateRootOffset(Animator animator, Bounds modelBounds, float modelScale) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: 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_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0126: 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_0195: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)animator == (Object)null) { throw new ArgumentNullException("animator"); } float y = ((Bounds)(ref modelBounds)).extents.y; if (y <= 0f || float.IsNaN(y) || float.IsInfinity(y)) { throw new ArgumentException("The model must have finite, nonzero skinned bounds."); } if (modelScale <= 0f || float.IsNaN(modelScale) || float.IsInfinity(modelScale)) { throw new ArgumentOutOfRangeException("modelScale"); } Transform boneTransform = animator.GetBoneTransform((HumanBodyBones)0); if ((Object)(object)boneTransform == (Object)null) { throw new ArgumentException("The humanoid avatar must contain hips."); } Transform boneTransform2 = animator.GetBoneTransform((HumanBodyBones)19); Transform boneTransform3 = animator.GetBoneTransform((HumanBodyBones)20); Vector3 val = LeftToesPosition; Vector3 val2 = RightToesPosition; if ((Object)(object)boneTransform2 == (Object)null && (Object)(object)boneTransform3 == (Object)null) { boneTransform2 = animator.GetBoneTransform((HumanBodyBones)5); boneTransform3 = animator.GetBoneTransform((HumanBodyBones)6); val = LeftFootPosition; val2 = RightFootPosition; } if ((Object)(object)boneTransform2 == (Object)null && (Object)(object)boneTransform3 == (Object)null) { throw new ArgumentException("The humanoid avatar must contain feet or toes."); } float num = (((Object)(object)boneTransform2 != (Object)null && (Object)(object)boneTransform3 != (Object)null) ? ((boneTransform2.position.y + boneTransform3.position.y) * 0.5f) : (((Object)(object)boneTransform2 != (Object)null) ? boneTransform2.position.y : boneTransform3.position.y)); float num2 = (((Object)(object)boneTransform2 != (Object)null && (Object)(object)boneTransform3 != (Object)null) ? ((val.y + val2.y) * 0.5f) : (((Object)(object)boneTransform2 != (Object)null) ? val.y : val2.y)); float num3 = 1.465f / y * modelScale; float num4 = num2 - HipsPosition.y - (num - boneTransform.position.y) * num3; return HipInverseUp * num4; } internal static Dictionary GetRotations() { //IL_0025: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_018d: 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_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_021d: 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_0265: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_0319: Unknown result type (might be due to invalid IL or missing references) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_0361: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) //IL_03f1: Unknown result type (might be due to invalid IL or missing references) //IL_0415: Unknown result type (might be due to invalid IL or missing references) //IL_0439: Unknown result type (might be due to invalid IL or missing references) //IL_045d: Unknown result type (might be due to invalid IL or missing references) //IL_0481: Unknown result type (might be due to invalid IL or missing references) //IL_04a5: Unknown result type (might be due to invalid IL or missing references) //IL_04c9: Unknown result type (might be due to invalid IL or missing references) //IL_04ed: Unknown result type (might be due to invalid IL or missing references) //IL_0511: Unknown result type (might be due to invalid IL or missing references) //IL_0535: Unknown result type (might be due to invalid IL or missing references) //IL_0559: Unknown result type (might be due to invalid IL or missing references) //IL_057d: Unknown result type (might be due to invalid IL or missing references) //IL_05a1: Unknown result type (might be due to invalid IL or missing references) //IL_05c5: Unknown result type (might be due to invalid IL or missing references) Dictionary dictionary = new Dictionary(StringComparer.Ordinal); dictionary.Add("spine", new Quaternion(0.12639649f, -2.3650632E-07f, -3.0135297E-08f, 0.9919798f)); dictionary.Add("spine.001", new Quaternion(0.095710926f, -1.18662E-07f, -1.1409663E-08f, 0.9954092f)); dictionary.Add("spine.002", new Quaternion(0.017602552f, -1.19209034E-07f, 2.452893E-10f, 0.9998451f)); dictionary.Add("spine.003", new Quaternion(-0.035710074f, -1.1927635E-07f, 6.596345E-09f, 0.9993622f)); dictionary.Add("shoulder.L", new Quaternion(-0.48973152f, 0.50033516f, 0.49966472f, 0.5100617f)); dictionary.Add("arm.L_upper", new Quaternion(-0.7339971f, 0.67302173f, -0.040365193f, -0.081612684f)); dictionary.Add("arm.L_lower", new Quaternion(-0.7362502f, 0.67066705f, -0.040314563f, -0.08072178f)); dictionary.Add("hand.L", new Quaternion(-0.5140182f, 0.47665706f, 0.4704767f, 0.53594315f)); dictionary.Add("finger5.L", new Quaternion(0.013960492f, -0.122404836f, 0.66726166f, 0.7345638f)); dictionary.Add("finger5.L.001", new Quaternion(-0.17880636f, -0.13006642f, 0.80150926f, 0.55560225f)); dictionary.Add("finger4.L", new Quaternion(-0.0648905f, -0.07896751f, 0.6732184f, 0.73234576f)); dictionary.Add("finger4.L.001", new Quaternion(-0.027446099f, -0.059287686f, 0.8398368f, 0.53889316f)); dictionary.Add("finger3.L", new Quaternion(-0.017874219f, -0.02438416f, 0.71825045f, 0.6951274f)); dictionary.Add("finger3.L.001", new Quaternion(0.010554342f, -0.04593746f, 0.8380089f, 0.54361707f)); dictionary.Add("finger2.L", new Quaternion(0.00082967826f, -0.011169321f, 0.6973147f, 0.7166776f)); dictionary.Add("finger2.L.001", new Quaternion(0.032191917f, -0.025644023f, 0.8749317f, 0.48249415f)); dictionary.Add("finger1.L", new Quaternion(0.18517825f, 0.16860205f, 0.6767169f, 0.6923413f)); dictionary.Add("finger1.L.001", new Quaternion(0.03330569f, 0.017522547f, 0.714852f, 0.6982624f)); dictionary.Add("shoulder.R", new Quaternion(-0.49077132f, -0.49931467f, -0.50068444f, 0.50906134f)); dictionary.Add("arm.R_upper", new Quaternion(-0.5300529f, -0.50260735f, -0.503137f, 0.46182567f)); dictionary.Add("arm.R_lower", new Quaternion(-0.7283316f, -0.6667459f, 0.11033738f, -0.11317505f)); dictionary.Add("hand.R", new Quaternion(-0.51996106f, -0.51033854f, -0.45818207f, 0.50918f)); dictionary.Add("finger5.R", new Quaternion(-0.054162618f, 0.016203085f, -0.6140409f, 0.7872469f)); dictionary.Add("finger5.R.001", new Quaternion(-0.15208758f, 0.063779615f, -0.80226886f, 0.57373005f)); dictionary.Add("finger4.R", new Quaternion(-0.04556026f, 0.0023397137f, -0.67061794f, 0.74039876f)); dictionary.Add("finger4.R.001", new Quaternion(-0.10774975f, 0.032901496f, -0.8134386f, 0.57063574f)); dictionary.Add("finger3.R", new Quaternion(-0.0074658752f, -0.03550613f, -0.6911992f, 0.7217529f)); dictionary.Add("finger3.R.001", new Quaternion(-0.0463604f, -0.0069759325f, -0.82483906f, 0.5634205f)); dictionary.Add("finger2.R", new Quaternion(0.041853994f, -0.078056596f, -0.71481794f, 0.69367915f)); dictionary.Add("finger2.R.001", new Quaternion(-0.0120287845f, -0.030357908f, -0.8355307f, 0.5484726f)); dictionary.Add("finger1.R", new Quaternion(0.18769486f, -0.22029f, -0.6545502f, 0.6984318f)); dictionary.Add("finger1.R.001", new Quaternion(0.031098688f, -0.06868927f, -0.71509755f, 0.6949461f)); dictionary.Add("spine.004", new Quaternion(0.022720095f, -1.1918473E-07f, -3.6471004E-10f, 0.99974185f)); dictionary.Add("thigh.L", new Quaternion(0.99917924f, -0.008936019f, 0.03230247f, 0.022749925f)); dictionary.Add("shin.L", new Quaternion(0.99945444f, 0.0007038034f, 0.030207673f, -0.013335306f)); dictionary.Add("foot.L", new Quaternion(0.8938854f, 0.0069676177f, 0.038162712f, 0.4466139f)); dictionary.Add("toe.L", new Quaternion(-0.03860532f, 0.67573607f, 0.73612213f, 0.0038228573f)); dictionary.Add("thigh.R", new Quaternion(0.9992668f, 0.011121959f, -0.031773318f, 0.018236643f)); dictionary.Add("shin.R", new Quaternion(0.9993965f, 0.0014982255f, -0.029757904f, -0.017856808f)); dictionary.Add("foot.R", new Quaternion(0.8959387f, -0.0055838292f, -0.03707501f, 0.44259244f)); dictionary.Add("toe.R", new Quaternion(0.037177056f, 0.67243624f, 0.7392049f, -0.004853835f)); return dictionary; } } internal static class V80Compatibility { private const string HarmonyId = "MadJack.MobiSuit.V80ItemSlots"; private static readonly object Sync = new object(); private static bool applied; internal static void Apply(ManualLogSource logger) { //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Expected O, but got Unknown //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Expected O, but got Unknown if (logger == null) { throw new ArgumentNullException("logger"); } lock (Sync) { if (applied) { return; } Assembly assembly = typeof(BodyReplacementBase).Assembly; if (assembly.GetType("ModelReplacement.V80ItemSlotCompatibility", throwOnError: false) != null) { logger.LogInfo((object)"ModelReplacementAPI already includes the V80 item-slot fix."); return; } if (assembly.GetName().Version != new Version(2, 4, 20, 0)) { throw new NotSupportedException(string.Concat("Mobi's V80 item-slot fix supports ModelReplacementAPI 2.4.20.0 or the existing patched API. Found ", assembly.GetName().Version, ".")); } Type type = assembly.GetType("ModelReplacement.Patches.LocateHeldObjectsOnModelReplacementPatch", throwOnError: true); MethodInfo[] array = new MethodInfo[2] { RequireMethod(typeof(BodyReplacementBase), "UpdateItemTransform"), RequireMethod(type, "LateUpdatePatch") }; MethodInfo method = typeof(V80Compatibility).GetMethod("ReplaceItemSlotRead", BindingFlags.Static | BindingFlags.NonPublic); Harmony val = new Harmony("MadJack.MobiSuit.V80ItemSlots"); try { MethodInfo[] array2 = array; foreach (MethodInfo methodInfo in array2) { val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(method), (HarmonyMethod)null, (HarmonyMethod)null); } applied = true; logger.LogInfo((object)"Enabled the V80 utility-slot fix for both ModelReplacementAPI item updates."); } catch { val.UnpatchSelf(); throw; } } } private static MethodInfo RequireMethod(Type type, string name) { MethodInfo methodInfo = null; MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo2 in methods) { if (!(methodInfo2.Name != name)) { if (methodInfo != null) { throw new AmbiguousMatchException(type.FullName + "." + name); } methodInfo = methodInfo2; } } if (methodInfo == null) { throw new MissingMethodException(type.FullName, name); } return methodInfo; } private static IEnumerable ReplaceItemSlotRead(IEnumerable instructions, MethodBase __originalMethod) { List list = new List(instructions); FieldInfo field = typeof(PlayerControllerB).GetField("ItemSlots"); FieldInfo field2 = typeof(PlayerControllerB).GetField("currentItemSlot"); FieldInfo field3 = typeof(GrabbableObject).GetField("playerHeldBy"); int num = -1; for (int i = 0; i < list.Count; i++) { if (!(list[i].opcode != OpCodes.Ldfld) && object.Equals(list[i].operand, field)) { if (num != -1) { throw LayoutError(__originalMethod); } num = i; } } if (field == null || field2 == null || field3 == null || num < 0) { throw LayoutError(__originalMethod); } int num2; if (__originalMethod.DeclaringType == typeof(BodyReplacementBase) && __originalMethod.Name == "UpdateItemTransform") { num2 = num + 4; if (num2 >= list.Count || list[num + 1].opcode != OpCodes.Ldarg_0 || list[num + 2].opcode != OpCodes.Call || !IsControllerGetter(list[num + 2].operand) || list[num + 3].opcode != OpCodes.Ldfld || !object.Equals(list[num + 3].operand, field2) || list[num2].opcode != OpCodes.Ldelem_Ref) { throw LayoutError(__originalMethod); } } else { if (!(__originalMethod.DeclaringType.FullName == "ModelReplacement.Patches.LocateHeldObjectsOnModelReplacementPatch") || !(__originalMethod.Name == "LateUpdatePatch")) { throw LayoutError(__originalMethod); } num2 = num + 5; if (num2 >= list.Count || list[num + 1].opcode != OpCodes.Ldarg_0 || list[num + 2].opcode != OpCodes.Ldind_Ref || list[num + 3].opcode != OpCodes.Ldfld || !object.Equals(list[num + 3].operand, field3) || list[num + 4].opcode != OpCodes.Ldfld || !object.Equals(list[num + 4].operand, field2) || list[num2].opcode != OpCodes.Ldelem_Ref) { throw LayoutError(__originalMethod); } } list[num].opcode = OpCodes.Call; list[num].operand = typeof(V80Compatibility).GetMethod("GetSelectedItem", BindingFlags.Static | BindingFlags.NonPublic); for (int j = num + 1; j <= num2; j++) { list[j].opcode = OpCodes.Nop; list[j].operand = null; } return list; } private static bool IsControllerGetter(object operand) { MethodInfo methodInfo = operand as MethodInfo; if (methodInfo != null && methodInfo.DeclaringType == typeof(BodyReplacementBase) && methodInfo.Name == "get_controller" && methodInfo.ReturnType == typeof(PlayerControllerB)) { return methodInfo.GetParameters().Length == 0; } return false; } private static InvalidOperationException LayoutError(MethodBase method) { return new InvalidOperationException("Mobi could not safely patch the item-slot read in " + method.DeclaringType.FullName + "." + method.Name + ". Expected exactly one original ModelReplacementAPI 2.4.20 read."); } private static GrabbableObject GetSelectedItem(PlayerControllerB player) { if ((Object)(object)player == (Object)null) { return null; } if (player.ItemSlots != null && player.currentItemSlot >= 0 && player.currentItemSlot < player.ItemSlots.Length) { return player.ItemSlots[player.currentItemSlot]; } return player.ItemOnlySlot; } }