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 HiroSuits v1.0.0
BepInEx/plugins/HiroSuits/HiroSuits.dll
Decompiled 39 minutes agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using ModelReplacement; using ModelReplacement.AvatarBodyUpdater; using UnityEngine; using UnityEngine.LowLevel; using UnityEngine.PlayerLoop; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] namespace HiroSuits; [HarmonyPatch(typeof(AvatarUpdater), "Update")] internal static class AvatarUpdaterUpdatePatch { private static void Postfix() { FootLift.TickAll(); } } public class FootLift : MonoBehaviour { public BodyReplacementBase Body; private const BindingFlags AnyInstance = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; private static readonly List<FootLift> Instances = new List<FootLift>(); private static bool loopInstalled; private static bool loopFailed; private static UpdateFunction tickAll; private static FieldInfo replacementModelField; private static FieldInfo controllerField; private static PropertyInfo controllerProperty; private static FieldInfo playerModelField; private static PropertyInfo playerModelProperty; private Animator animator; private Transform spine; private Transform modelFoot; private Transform[] playerBones; private bool usePlayerFoot; private bool active; private bool gaveUp; private int attempts; private bool logged; private bool diagLogged; public static float LastLift; private static bool firstTickLogged; private void Awake() { animator = ((Component)this).GetComponentInChildren<Animator>(true); if (!Instances.Contains(this)) { Instances.Add(this); } InstallLoop(); } private void OnDestroy() { Instances.Remove(this); } private static void InstallLoop() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: 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_003b: 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_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) if (loopInstalled || loopFailed) { return; } try { PlayerLoopSystem system = PlayerLoop.GetCurrentPlayerLoop(); PlayerLoopSystem child = new PlayerLoopSystem { type = typeof(FootLift), updateDelegate = GetTickDelegate() }; if (Insert(ref system, typeof(PostLateUpdate), child)) { PlayerLoop.SetPlayerLoop(system); loopInstalled = true; if (Plugin.Log != null) { Plugin.Log.LogInfo((object)"[FootLift] injected into PostLateUpdate"); } } else { loopFailed = true; if (Plugin.Log != null) { Plugin.Log.LogWarning((object)"[FootLift] PostLateUpdate not found, falling back to LateUpdate"); } } } catch (Exception ex) { loopFailed = true; if (Plugin.Log != null) { Plugin.Log.LogWarning((object)("[FootLift] player loop injection failed: " + ex.Message)); } } } private static UpdateFunction GetTickDelegate() { //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_0019: Expected O, but got Unknown //IL_001a: Expected O, but got Unknown if (tickAll == null) { UpdateFunction val = TickAll; tickAll = val; return val; } return tickAll; } private static bool Insert(ref PlayerLoopSystem system, Type parentType, PlayerLoopSystem child) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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_004d: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) if (system.subSystemList == null) { return false; } if (system.type == parentType) { List<PlayerLoopSystem> list = new List<PlayerLoopSystem>(system.subSystemList); list.Add(child); system.subSystemList = list.ToArray(); return true; } for (int i = 0; i < system.subSystemList.Length; i++) { PlayerLoopSystem system2 = system.subSystemList[i]; if (Insert(ref system2, parentType, child)) { system.subSystemList[i] = system2; return true; } } return false; } public static void TickAll() { for (int i = 0; i < Instances.Count; i++) { FootLift footLift = Instances[i]; if ((Object)(object)footLift == (Object)null) { continue; } try { footLift.Tick(); } catch (Exception ex) { if (Plugin.Log != null) { Plugin.Log.LogError((object)("[FootLift] tick failed: " + ex)); } footLift.gaveUp = true; } } } private void Tick() { //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0188: 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_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_020e: 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_024f: Unknown result type (might be due to invalid IL or missing references) if (!firstTickLogged) { firstTickLogged = true; if (Plugin.Log != null) { Plugin.Log.LogInfo((object)("[FootLift] first tick on " + ((Object)this).name + " body=" + ((Object)(object)Body != (Object)null) + " active=" + active + " gaveUp=" + gaveUp + " animator=" + ((Object)(object)animator != (Object)null) + " spine=" + ((Object)(object)spine != (Object)null) + " foot=" + ((Object)(object)modelFoot != (Object)null))); } } if ((!active && !TryActivate()) || (Object)(object)spine == (Object)null || (Object)(object)modelFoot == (Object)null || playerBones == null) { return; } Transform val = FindPlayerFoot(); if ((Object)(object)val == (Object)null) { return; } float num = val.position.y - modelFoot.position.y; if (float.IsNaN(num) || Mathf.Abs(num) > 3f) { return; } LastLift = num; if (Mathf.Abs(num) <= 0.0005f) { return; } Transform transform = ((Component)this).transform; transform.position += Vector3.up * num; if (!logged) { logged = true; if (Plugin.Log != null) { Plugin.Log.LogInfo((object)("[FootLift] " + ((Object)this).name + " lifted model by " + num.ToString("F3") + " (player " + ((Object)val).name + " y=" + val.position.y.ToString("F3") + ", model " + ((Object)modelFoot).name + " y=" + modelFoot.position.y.ToString("F3") + ")")); } } } private bool TryActivate() { if (gaveUp) { return false; } if ((Object)(object)Body == (Object)null) { gaveUp = true; return false; } if (++attempts > 400) { gaveUp = true; Diag("gave up"); return false; } if (replacementModelField == null) { replacementModelField = typeof(BodyReplacementBase).GetField("replacementModel", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } GameObject val = (GameObject)((replacementModelField != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val == (Object)null) { Diag("replacementModel null"); return false; } if ((Object)(object)val != (Object)(object)((Component)this).gameObject && !((Component)this).gameObject.transform.IsChildOf(val.transform) && !val.transform.IsChildOf(((Component)this).gameObject.transform)) { gaveUp = true; ((Behaviour)this).enabled = false; Diag("not the main model"); return false; } object controller = GetController(); if (controller == null) { Diag("controller null"); return false; } SkinnedMeshRenderer playerModel = GetPlayerModel(controller); if ((Object)(object)playerModel == (Object)null) { Diag("thisPlayerModel null"); return false; } if (playerModel.bones == null || playerModel.bones.Length == 0) { Diag("player model has no bones"); return false; } playerBones = playerModel.bones; if ((Object)(object)animator == (Object)null) { animator = ((Component)this).GetComponentInChildren<Animator>(true); } if ((Object)(object)animator == (Object)null) { Diag("animator null"); gaveUp = true; return false; } if ((Object)(object)animator.avatar == (Object)null) { Diag("avatar null"); gaveUp = true; return false; } if (!animator.avatar.isHuman) { Diag("avatar not humanoid"); gaveUp = true; return false; } spine = animator.GetBoneTransform((HumanBodyBones)7); if ((Object)(object)spine == (Object)null) { spine = animator.GetBoneTransform((HumanBodyBones)0); } modelFoot = animator.GetBoneTransform((HumanBodyBones)19); if ((Object)(object)modelFoot == (Object)null) { modelFoot = animator.GetBoneTransform((HumanBodyBones)20); } if ((Object)(object)modelFoot == (Object)null) { modelFoot = animator.GetBoneTransform((HumanBodyBones)5); if ((Object)(object)modelFoot == (Object)null) { modelFoot = animator.GetBoneTransform((HumanBodyBones)6); } usePlayerFoot = true; } if ((Object)(object)spine == (Object)null || (Object)(object)modelFoot == (Object)null) { Diag("spine/foot missing"); gaveUp = true; return false; } active = true; if (Plugin.Log != null) { Plugin.Log.LogInfo((object)("[FootLift] active on " + ((Object)this).name + " after " + attempts + " attempts (spine=" + ((Object)spine).name + " foot=" + ((Object)modelFoot).name + " playerToe=" + (usePlayerFoot ? "foot" : "toe") + ")")); } return true; } private static object GetController(BodyReplacementBase body) { if (controllerField == null && controllerProperty == null) { Type typeFromHandle = typeof(BodyReplacementBase); controllerField = typeFromHandle.GetField("controller", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (controllerField == null) { controllerProperty = typeFromHandle.GetProperty("controller", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } } if (controllerField != null) { return controllerField.GetValue(body); } if (controllerProperty != null) { return controllerProperty.GetValue(body); } return null; } private object GetController() { return GetController(Body); } private static SkinnedMeshRenderer GetPlayerModel(object controller) { if (playerModelField == null && playerModelProperty == null) { Type type = controller.GetType(); playerModelField = type.GetField("thisPlayerModel", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (playerModelField == null) { playerModelProperty = type.GetProperty("thisPlayerModel", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } } object obj = null; if (playerModelField != null) { obj = playerModelField.GetValue(controller); } else if (playerModelProperty != null) { obj = playerModelProperty.GetValue(controller); } return (SkinnedMeshRenderer)((obj is SkinnedMeshRenderer) ? obj : null); } private void Diag(string why) { if (!diagLogged) { diagLogged = true; if (Plugin.Log != null) { Plugin.Log.LogWarning((object)("[FootLift] " + ((Object)this).name + ": " + why + " (attempt " + attempts + ", body=" + ((Object)(object)Body != (Object)null) + ", controllerField=" + (controllerField != null) + ", controllerProp=" + (controllerProperty != null) + ", playerModelField=" + (playerModelField != null) + ", playerModelProp=" + (playerModelProperty != null) + ")")); } } } private Transform FindPlayerFoot() { string text = (usePlayerFoot ? "foot.l" : "toe.l"); string text2 = (usePlayerFoot ? "foot.r" : "toe.r"); Transform val = null; for (int i = 0; i < playerBones.Length; i++) { Transform val2 = playerBones[i]; if (!((Object)(object)val2 == (Object)null)) { string text3 = ((Object)val2).name.ToLowerInvariant(); if (text3 == text || text3.EndsWith("." + text) || text3.EndsWith("_" + text)) { return val2; } if ((Object)(object)val == (Object)null && (text3 == text2 || text3.EndsWith("." + text2) || text3.EndsWith("_" + text2))) { val = val2; } } } return val; } } public class Hiro2Replacement : BodyReplacementBase { protected unsafe override GameObject LoadAssetsAndReturnModel() { //IL_00bb: 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) GameObject val = SuitAssets.Model("Hiro2"); if ((Object)(object)val == (Object)null) { if (Plugin.Log != null) { Plugin.Log.LogError((object)"[Hiro2] prefab not found in bundle"); } return null; } Animator componentInChildren = val.GetComponentInChildren<Animator>(true); if ((Object)(object)componentInChildren == (Object)null) { if (Plugin.Log != null) { Plugin.Log.LogError((object)"[Hiro2] no Animator in prefab"); } return val; } OffsetBuilder component = ((Component)componentInChildren).gameObject.GetComponent<OffsetBuilder>(); if ((Object)(object)component == (Object)null) { if (Plugin.Log != null) { Plugin.Log.LogError((object)"[Hiro2] no OffsetBuilder on animator object"); } return val; } component.GenerateViewModel = Plugin.EnableViewModel.Value; component.RemoveHelmet = false; if (Plugin.Log != null) { ManualLogSource log = Plugin.Log; string text = component.GenerateViewModel.ToString(); Vector3 rootScale = component.rootScale; log.LogInfo((object)("[Hiro2] viewmodel=" + text + " rootScale=" + ((object)(*(Vector3*)(&rootScale))/*cast due to .constrained prefix*/).ToString())); } FootLift footLift = val.GetComponent<FootLift>(); if ((Object)(object)footLift == (Object)null) { footLift = val.AddComponent<FootLift>(); } footLift.Body = (BodyReplacementBase)(object)this; PerfTweak perfTweak = val.GetComponent<PerfTweak>(); if ((Object)(object)perfTweak == (Object)null) { perfTweak = val.AddComponent<PerfTweak>(); } perfTweak.Body = (BodyReplacementBase)(object)this; SanitizeMaterials.Fix(val, Plugin.Log); TwistFollow twistFollow = val.GetComponent<TwistFollow>(); if ((Object)(object)twistFollow == (Object)null) { twistFollow = val.AddComponent<TwistFollow>(); } twistFollow.Setup(val); return val; } } public class HiroKimonoReplacement : BodyReplacementBase { protected unsafe override GameObject LoadAssetsAndReturnModel() { //IL_00bb: 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) GameObject val = SuitAssets.Model("HiroKimono"); if ((Object)(object)val == (Object)null) { if (Plugin.Log != null) { Plugin.Log.LogError((object)"[HiroKimono] prefab not found in bundle"); } return null; } Animator componentInChildren = val.GetComponentInChildren<Animator>(true); if ((Object)(object)componentInChildren == (Object)null) { if (Plugin.Log != null) { Plugin.Log.LogError((object)"[HiroKimono] no Animator in prefab"); } return val; } OffsetBuilder component = ((Component)componentInChildren).gameObject.GetComponent<OffsetBuilder>(); if ((Object)(object)component == (Object)null) { if (Plugin.Log != null) { Plugin.Log.LogError((object)"[HiroKimono] no OffsetBuilder on animator object"); } return val; } component.GenerateViewModel = Plugin.EnableViewModel.Value; component.RemoveHelmet = false; if (Plugin.Log != null) { ManualLogSource log = Plugin.Log; string text = component.GenerateViewModel.ToString(); Vector3 rootScale = component.rootScale; log.LogInfo((object)("[HiroKimono] viewmodel=" + text + " rootScale=" + ((object)(*(Vector3*)(&rootScale))/*cast due to .constrained prefix*/).ToString())); } FootLift footLift = val.GetComponent<FootLift>(); if ((Object)(object)footLift == (Object)null) { footLift = val.AddComponent<FootLift>(); } footLift.Body = (BodyReplacementBase)(object)this; PerfTweak perfTweak = val.GetComponent<PerfTweak>(); if ((Object)(object)perfTweak == (Object)null) { perfTweak = val.AddComponent<PerfTweak>(); } perfTweak.Body = (BodyReplacementBase)(object)this; SanitizeMaterials.Fix(val, Plugin.Log); TwistFollow twistFollow = val.GetComponent<TwistFollow>(); if ((Object)(object)twistFollow == (Object)null) { twistFollow = val.AddComponent<TwistFollow>(); } twistFollow.Setup(val); return val; } } public class HiroReplacement : BodyReplacementBase { protected unsafe override GameObject LoadAssetsAndReturnModel() { //IL_00bb: 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) GameObject val = SuitAssets.Model("Hiro"); if ((Object)(object)val == (Object)null) { if (Plugin.Log != null) { Plugin.Log.LogError((object)"[Hiro] prefab not found in bundle"); } return null; } Animator componentInChildren = val.GetComponentInChildren<Animator>(true); if ((Object)(object)componentInChildren == (Object)null) { if (Plugin.Log != null) { Plugin.Log.LogError((object)"[Hiro] no Animator in prefab"); } return val; } OffsetBuilder component = ((Component)componentInChildren).gameObject.GetComponent<OffsetBuilder>(); if ((Object)(object)component == (Object)null) { if (Plugin.Log != null) { Plugin.Log.LogError((object)"[Hiro] no OffsetBuilder on animator object"); } return val; } component.GenerateViewModel = Plugin.EnableViewModel.Value; component.RemoveHelmet = false; if (Plugin.Log != null) { ManualLogSource log = Plugin.Log; string text = component.GenerateViewModel.ToString(); Vector3 rootScale = component.rootScale; log.LogInfo((object)("[Hiro] viewmodel=" + text + " rootScale=" + ((object)(*(Vector3*)(&rootScale))/*cast due to .constrained prefix*/).ToString())); } FootLift footLift = val.GetComponent<FootLift>(); if ((Object)(object)footLift == (Object)null) { footLift = val.AddComponent<FootLift>(); } footLift.Body = (BodyReplacementBase)(object)this; PerfTweak perfTweak = val.GetComponent<PerfTweak>(); if ((Object)(object)perfTweak == (Object)null) { perfTweak = val.AddComponent<PerfTweak>(); } perfTweak.Body = (BodyReplacementBase)(object)this; SanitizeMaterials.Fix(val, Plugin.Log); TwistFollow twistFollow = val.GetComponent<TwistFollow>(); if ((Object)(object)twistFollow == (Object)null) { twistFollow = val.AddComponent<TwistFollow>(); } twistFollow.Setup(val); return val; } } public class PerfTweak : MonoBehaviour { public BodyReplacementBase Body; private static FieldInfo _shadowField; private static bool _typeLogged; private int _applied; private float _nextScan; private void Start() { Apply(); _nextScan = Time.time + 0.5f; } private void Update() { if (Plugin.PerfTweaks.Value && !(Time.time < _nextScan)) { _nextScan = Time.time + 1f; Apply(); } } private void Apply() { if (!Plugin.PerfTweaks.Value || (Object)(object)Body == (Object)null || (Object)(object)Body.replacementModel != (Object)(object)((Component)this).gameObject) { return; } if (_applied == 0) { int num = 0; int num2 = 0; Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true); foreach (Renderer obj in componentsInChildren) { obj.shadowCastingMode = (ShadowCastingMode)0; obj.receiveShadows = false; SkinnedMeshRenderer val = (SkinnedMeshRenderer)(object)((obj is SkinnedMeshRenderer) ? obj : null); if ((Object)(object)val != (Object)null) { val.skinnedMotionVectors = false; if ((Object)(object)val.sharedMesh != (Object)null) { num2 += val.sharedMesh.blendShapeCount; if (val.sharedMesh.blendShapeCount > 0) { val.sharedMesh.ClearBlendShapes(); } } } num++; } if (Plugin.Log != null) { Plugin.Log.LogInfo((object)("[Perf] " + ((Object)this).name + " renderers=" + num + " blendshapesCleared=" + num2)); } } _applied++; if (_shadowField == null) { _shadowField = ((object)Body).GetType().GetField("replacementModelShadow", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!_typeLogged && Plugin.Log != null) { _typeLogged = true; Plugin.Log.LogInfo((object)("[Perf] shadow field=" + (_shadowField != null))); } } GameObject val2 = (GameObject)((_shadowField != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val2 != (Object)null && val2.activeSelf) { val2.SetActive(false); } } } [BepInPlugin("meow.HiroSuits", "Hiro Suits", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string Guid = "meow.HiroSuits"; public static Plugin Instance; public static ManualLogSource Log; public static ConfigEntry<bool> EnableForAllSuits; public static ConfigEntry<bool> EnableAsDefault; public static ConfigEntry<string> SuitNames; public static ConfigEntry<bool> EnableViewModel; public static ConfigEntry<bool> PerfTweaks; private void Awake() { //IL_01ae: Unknown result type (might be due to invalid IL or missing references) Instance = this; Log = ((BaseUnityPlugin)this).Logger; EnableForAllSuits = ((BaseUnityPlugin)this).Config.Bind<bool>("Suits to Replace", "Enable Model for all Suits", false, "Replace every player model with these models"); EnableAsDefault = ((BaseUnityPlugin)this).Config.Bind<bool>("Suits to Replace", "Enable Model as default", false, "Only replace suits nobody else registered"); SuitNames = ((BaseUnityPlugin)this).Config.Bind<string>("Suits to Replace", "Extra suit names to use the model", "", "Comma separated suit names (default suits: Hiro, Hiro2, HiroKimono)"); EnableViewModel = ((BaseUnityPlugin)this).Config.Bind<bool>("Viewmodel", "Show model arms in first person", true, "Generate a first person viewmodel from the model's arms"); PerfTweaks = ((BaseUnityPlugin)this).Config.Bind<bool>("Perf", "Enable performance tweaks", true, "Disable model shadow casting, the extra shadow-only model clone, motion vectors and blendshape buffers (recommended)"); SuitAssets.Populate("hirosuits"); if ((Object)(object)SuitAssets.Bundle == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"[HiroSuits] asset bundle failed to load, model will not appear"); } Type typeFromHandle = typeof(HiroReplacement); if (EnableForAllSuits.Value) { ModelReplacementAPI.RegisterModelReplacementOverride(typeFromHandle); } if (EnableAsDefault.Value) { ModelReplacementAPI.RegisterModelReplacementDefault(typeFromHandle); } string[] array = SuitNames.Value.Split(','); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length > 0) { ModelReplacementAPI.RegisterSuitModelReplacement(text, typeFromHandle); } } if ((Object)(object)SuitAssets.Bundle != (Object)null) { ModelReplacementAPI.RegisterSuitModelReplacement("Hiro", typeof(HiroReplacement)); } if ((Object)(object)SuitAssets.Bundle != (Object)null) { ModelReplacementAPI.RegisterSuitModelReplacement("Hiro2", typeof(Hiro2Replacement)); } if ((Object)(object)SuitAssets.Bundle != (Object)null) { ModelReplacementAPI.RegisterSuitModelReplacement("HiroKimono", typeof(HiroKimonoReplacement)); } try { new Harmony("meow.HiroSuits").PatchAll(typeof(Plugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[FootLift] harmony patches applied"); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("[FootLift] harmony patch failed: " + ex)); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"[HiroSuits] registered replacements: Hiro, Hiro2, HiroKimono"); } } public static class SanitizeMaterials { public static void Fix(GameObject root, ManualLogSource log) { if ((Object)(object)root == (Object)null) { return; } Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true); Material val = null; Renderer[] array = componentsInChildren; for (int i = 0; i < array.Length; i++) { Material[] sharedMaterials = array[i].sharedMaterials; foreach (Material val2 in sharedMaterials) { if ((Object)(object)val2 != (Object)null && (Object)(object)val2.shader != (Object)null && ((Object)val2.shader).name.StartsWith("HDRP/")) { val = val2; break; } } if ((Object)(object)val != (Object)null) { break; } } if ((Object)(object)val == (Object)null) { if (log != null) { log.LogError((object)"[SanitizeMaterials] no HDRP material found on model, cannot fill null slots"); } return; } int num = 0; array = componentsInChildren; foreach (Renderer val3 in array) { Material[] sharedMaterials2 = val3.sharedMaterials; bool flag = false; for (int k = 0; k < sharedMaterials2.Length; k++) { if ((Object)(object)sharedMaterials2[k] == (Object)null) { sharedMaterials2[k] = val; num++; flag = true; } } if (flag) { val3.sharedMaterials = sharedMaterials2; } } if (log != null) { log.LogInfo((object)("[SanitizeMaterials] fallback=" + ((Object)val).name + " nulls=" + num)); } } } public static class SuitAssets { public static AssetBundle Bundle; public static void Populate(string bundleName) { if ((Object)(object)Bundle != (Object)null) { return; } string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), bundleName); if (!File.Exists(text)) { if (Plugin.Log != null) { Plugin.Log.LogError((object)("[Suit] missing bundle: " + text)); } } else { Bundle = AssetBundle.LoadFromFile(text); } } public static GameObject Model(string prefabName) { if ((Object)(object)Bundle == (Object)null) { return null; } return Bundle.LoadAsset<GameObject>(prefabName); } } public class TwistFollow : MonoBehaviour { private struct Pair { public Transform twist; public Transform source; public Quaternion invSrcRest; public Quaternion dstRest; } private readonly List<Pair> pairs = new List<Pair>(); public void Setup(GameObject root) { //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) pairs.Clear(); Transform[] componentsInChildren = root.GetComponentsInChildren<Transform>(true); Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>(); Transform[] array = componentsInChildren; foreach (Transform val in array) { if (!dictionary.ContainsKey(((Object)val).name)) { dictionary[((Object)val).name] = val; } } array = componentsInChildren; foreach (Transform val2 in array) { string name = ((Object)val2).name; if (name.Length >= 2 && name.EndsWith("W") && dictionary.TryGetValue(name.Substring(0, name.Length - 1), out var value) && !((Object)(object)value == (Object)(object)val2)) { pairs.Add(new Pair { twist = val2, source = value, invSrcRest = Quaternion.Inverse(value.rotation), dstRest = val2.rotation }); if (Plugin.Log != null) { Plugin.Log.LogInfo((object)("[TwistFollow] pair " + ((Object)val2).name + " <- " + ((Object)value).name)); } } } if (Plugin.Log != null) { Plugin.Log.LogInfo((object)("[TwistFollow] pairs=" + pairs.Count)); } } private void LateUpdate() { //IL_0039: 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_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < pairs.Count; i++) { Pair pair = pairs[i]; if (!((Object)(object)pair.twist == (Object)null) && !((Object)(object)pair.source == (Object)null)) { pair.twist.rotation = pair.source.rotation * (pair.invSrcRest * pair.dstRest); } } } }