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 MechamaruJJK VoidFiend v1.0.0
MechamaruJJK_VoidFiend.dll
Decompiled a day agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using EntityStates; using EntityStates.VoidSurvivor; using MonoMod.RuntimeDetour; using MonoMod.RuntimeDetour.HookGen; using MwSkinAdditions; using RoR2; using RuneFoxMods.DynamicSkins; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace MechamaruJJK_VoidFiend { [BepInPlugin("com.KrononConpsirator.MechamaruJJK_VoidFiend", "MechamaruJJK_VoidFiend", "1.0.0")] public class MechamaruJJK_VoidFiendPlugin : BaseUnityPlugin { public class DynamicSkinExtension { private Modification MechamaruJJKVoidFiendSkinDefHeadaddonModification; private Modification MechamaruJJKVoidFiendSkinDefElbowaddon_LModification; private Modification MechamaruJJKVoidFiendSkinDefElbowaddon_RModification; internal void BeforeStart() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) _DynamicSkinManager.InstanceLogger = ((BaseUnityPlugin)Instance).Logger; new Hook((MethodBase)typeof(SkinDef).GetMethod("ApplyAsync"), (Delegate)new Func<Func<SkinDef, GameObject, List<AssetReferenceT<Material>>, List<AssetReferenceT<Mesh>>, int, IEnumerator>, SkinDef, GameObject, List<AssetReferenceT<Material>>, List<AssetReferenceT<Mesh>>, int, IEnumerator>(_DynamicSkinManager.SkinDefApply)).Apply(); } internal void AfterStart() { InitializeModifications(); InitializeDynamicBones(); AddModificationsToList(); } internal void BeforeBodyCatalogInit() { VoidSurvivorBodyMechamaruJJKVoidFiendSkinDefSkinAddedEvent += onSkinAdded; } internal void AfterBodyCatalogInit() { } private void InitializeModifications() { MechamaruJJKVoidFiendSkinDefHeadaddonModification = new Modification("Headaddon.prefab", "Neck", "VoidSurvivorBody", "KRONONCONPSIRATOR_SKIN_MECHAMARUJJKVOIDFIENDSKINDEF_NAME", 10, AffectsBaseModel: true, assetBundle); MechamaruJJKVoidFiendSkinDefElbowaddon_LModification = new Modification("Elbowaddon_L.prefab", "Forearm.l", "VoidSurvivorBody", "KRONONCONPSIRATOR_SKIN_MECHAMARUJJKVOIDFIENDSKINDEF_NAME", 49, AffectsBaseModel: true, assetBundle); MechamaruJJKVoidFiendSkinDefElbowaddon_RModification = new Modification("Elbowaddon_R.prefab", "Forearm.r", "VoidSurvivorBody", "KRONONCONPSIRATOR_SKIN_MECHAMARUJJKVOIDFIENDSKINDEF_NAME", 58, AffectsBaseModel: true, assetBundle); } private void InitializeDynamicBones() { //IL_003d: 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_0065: 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_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) MechamaruJJKVoidFiendSkinDefHeadaddonModification.dynamicBoneData = new DynamicBoneData("Headaddon", 0f, null, 0f, null, 1f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0); MechamaruJJKVoidFiendSkinDefElbowaddon_LModification.dynamicBoneData = new DynamicBoneData("Elbowaddon_L", 0f, null, 0f, null, 1f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0); MechamaruJJKVoidFiendSkinDefElbowaddon_RModification.dynamicBoneData = new DynamicBoneData("Elbowaddon_R", 0f, null, 0f, null, 1f, null, 0f, null, 0f, null, 0f, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new List<DynamicBoneColliderData>(), new List<string>(), (FreezeAxis)0); } private void AddModificationsToList() { _DynamicSkinManager.AddModification("KRONONCONPSIRATOR_SKIN_MECHAMARUJJKVOIDFIENDSKINDEF_NAME", 10, MechamaruJJKVoidFiendSkinDefHeadaddonModification); _DynamicSkinManager.AddModification("KRONONCONPSIRATOR_SKIN_MECHAMARUJJKVOIDFIENDSKINDEF_NAME", 49, MechamaruJJKVoidFiendSkinDefElbowaddon_LModification); _DynamicSkinManager.AddModification("KRONONCONPSIRATOR_SKIN_MECHAMARUJJKVOIDFIENDSKINDEF_NAME", 58, MechamaruJJKVoidFiendSkinDefElbowaddon_RModification); } private static void onSkinAdded(object sender, SkinAddedArgs e) { _DynamicSkinManager.AddSkinDef(e.skinDef); } } public delegate void VoidDelegate(); public class SkinAddedArgs : EventArgs { public SkinDef skinDef { get; } public GameObject bodyPrefab { get; } public SkinAddedArgs(SkinDef newSkinDef, GameObject newGameObject) { skinDef = newSkinDef; bodyPrefab = newGameObject; } } public class MeshActivationExtension { internal void BeforeStart() { } internal void AfterStart() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown _meshActivationApplyHook = new Hook((MethodBase)typeof(SkinDef).GetMethod("ApplyAsync"), (Delegate)new Func<Func<SkinDef, GameObject, List<AssetReferenceT<Material>>, List<AssetReferenceT<Mesh>>, int, IEnumerator>, SkinDef, GameObject, List<AssetReferenceT<Material>>, List<AssetReferenceT<Mesh>>, int, IEnumerator>(MeshActivation_OnSkinDefApplyAsync)); _meshActivationApplyHook.Apply(); } internal void BeforeBodyCatalogInit() { } internal void AfterBodyCatalogInit() { //IL_0119: 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_01e7: Unknown result type (might be due to invalid IL or missing references) GameObject val = BodyCatalog.FindBodyPrefab("VoidSurvivorBody"); if (!Object.op_Implicit((Object)(object)val)) { ManualLogSource instanceLogger = InstanceLogger; if (instanceLogger != null) { instanceLogger.LogWarning((object)"MeshActivation: could not find body prefab \"VoidSurvivorBody\""); } return; } ModelLocator component = val.GetComponent<ModelLocator>(); GameObject val2 = (Object.op_Implicit((Object)(object)component) ? ((Component)component.modelTransform).gameObject : null); ModelSkinController val3 = (Object.op_Implicit((Object)(object)val2) ? val2.GetComponent<ModelSkinController>() : null); SkinDef val4 = (Object.op_Implicit((Object)(object)val3) ? ((IEnumerable<SkinDef>)val3.skins).FirstOrDefault((Func<SkinDef, bool>)((SkinDef s) => ((Object)s).name == "MechamaruJJKVoidFiendSkinDef")) : null); if (!Object.op_Implicit((Object)(object)val4)) { ManualLogSource instanceLogger2 = InstanceLogger; if (instanceLogger2 != null) { instanceLogger2.LogWarning((object)"MeshActivation: could not find skin \"MechamaruJJKVoidFiendSkinDef\" on \"VoidSurvivorBody\""); } return; } MeshActivation_SkinConfig meshActivation_SkinConfig = new MeshActivation_SkinConfig { armaturePath = "VoidSurvivorArmature", autoDetectAll = false }; meshActivation_SkinConfig.manualEntries.Add(new MeshActivation_Entry { prefabName = "Mechamaru_Add_Arm", initialActiveState = true, overrides = new List<MeshActivation_RendererOverride> { new MeshActivation_RendererOverride { rendererName = "Mechamaru_Add_Arm", material = assetBundle.LoadAsset<Material>("Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mat/MechamaruJJK_Body2_Mat.mat"), ignoreOverlays = true, shadowCastingMode = (ShadowCastingMode)1 } } }); meshActivation_SkinConfig.manualEntries.Add(new MeshActivation_Entry { prefabName = "Mechamaru_Add_Hand_ClawEnd", initialActiveState = false, overrides = new List<MeshActivation_RendererOverride> { new MeshActivation_RendererOverride { rendererName = "Mechamaru_Add_Hand_ClawEnd", material = assetBundle.LoadAsset<Material>("Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mat/MechamaruJJK_Body2_Mat.mat"), ignoreOverlays = true, shadowCastingMode = (ShadowCastingMode)1 } } }); meshActivation_SkinConfig.manualEntries.Add(new MeshActivation_Entry { prefabName = "Mechamaru_Add_Hand_FingerEnd", initialActiveState = true, overrides = new List<MeshActivation_RendererOverride> { new MeshActivation_RendererOverride { rendererName = "Mechamaru_Add_Hand_FingerEnd", material = assetBundle.LoadAsset<Material>("Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mat/MechamaruJJK_Body2_Mat.mat"), ignoreOverlays = true, shadowCastingMode = (ShadowCastingMode)1 } } }); _meshActivationConfigs[val4] = meshActivation_SkinConfig; } } public class MwSkinAdditionsExtension { internal void BeforeStart() { } internal void AfterStart() { } internal void BeforeBodyCatalogInit() { VoidSurvivorBodyMechamaruJJKVoidFiendSkinDefSkinAddedEvent += delegate(object sender, SkinAddedArgs args) { MechamaruJJKVoidFiendSkinDefSkin = args.skinDef; }; } internal void AfterBodyCatalogInit() { InitializeSkinAdditions(); } private void InitializeSkinAdditions() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_0036: 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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_006d: 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_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Expected O, but got Unknown //IL_0094: Unknown result type (might be due to invalid IL or missing references) SkinDef mechamaruJJKVoidFiendSkinDefSkin = MechamaruJJKVoidFiendSkinDefSkin; EventSubOptions val = new EventSubOptions(); val.transformInCSS = true; val.useAnimations = false; val.boneTransformations = (BoneTransformation[])(object)new BoneTransformation[2] { new BoneTransformation("VoidSurvivorArmature/ROOT/base/Stomach/Chest/Shoulder.r/Upperarm.r", new Vector3(1f, 1f, 1f), new Vector3(0f, 0f, 0f), true, (string)null), new BoneTransformation("VoidSurvivorArmature/ROOT/base/Stomach/Chest/Shoulder.r/Upperarm.r/Forearm.r", new Vector3(1f, 1f, 1f), new Vector3(0f, 0f, 0f), true, (string)null) }; new EventSub(mechamaruJJKVoidFiendSkinDefSkin, val).Init(); } } private class FieldException : Exception { public FieldException(string message, Exception innerException) : base(message, innerException) { } } private class ElementException : Exception { public int Index { get; } public ElementException(int index, string message) : base(message) { Index = index; } } public class CorruptionAddon { internal void AfterStart() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown corruptionOnEnterHook = new Hook((MethodBase)typeof(CorruptionTransitionBase).GetMethod("OnEnter"), (Delegate)new Action<Action<CorruptionTransitionBase>, CorruptionTransitionBase>(OnVoidStateChange)); corruptionOnEnterHook.Apply(); } private static GameObject GetChildGameObject(GameObject fromGameObject, string withName, bool checkInactive) { Transform val = ((IEnumerable<Transform>)fromGameObject.GetComponentsInChildren<Transform>(checkInactive)).FirstOrDefault((Func<Transform, bool>)((Transform k) => ((Object)((Component)k).gameObject).name == withName)); if ((Object)(object)val == (Object)null) { return null; } return ((Component)val).gameObject; } private static void OnVoidStateChange(Action<CorruptionTransitionBase> orig, CorruptionTransitionBase self) { orig(self); ModelLocator component = ((EntityState)self).gameObject.GetComponent<ModelLocator>(); object obj; if (component == null) { obj = null; } else { Transform modelTransform = component.modelTransform; obj = ((modelTransform != null) ? ((Component)modelTransform).gameObject : null); } GameObject val = (GameObject)obj; if ((Object)(object)val == (Object)null) { return; } GameObject childGameObject = GetChildGameObject(val, "Mechamaru_Add_Hand_ClawEnd(Clone)", checkInactive: true); GameObject childGameObject2 = GetChildGameObject(val, "Mechamaru_Add_Hand_FingerEnd(Clone)", checkInactive: true); GameObject childGameObject3 = GetChildGameObject(val, "Headaddon", checkInactive: false); GameObject childGameObject4 = GetChildGameObject(val, "Elbowaddon_R", checkInactive: false); GameObject childGameObject5 = GetChildGameObject(val, "Elbowaddon_L", checkInactive: false); if (self.voidSurvivorController.corruption <= self.voidSurvivorController.minimumCorruption) { if (childGameObject != null) { childGameObject.SetActive(false); } if (childGameObject2 != null) { childGameObject2.SetActive(true); } if ((Object)(object)childGameObject3 != (Object)null) { Animator component2 = childGameObject3.gameObject.GetComponent<Animator>(); if (component2 != null) { component2.SetBool("Corrupt", false); } } if ((Object)(object)childGameObject4 != (Object)null) { Animator component3 = childGameObject4.gameObject.GetComponent<Animator>(); if (component3 != null) { component3.SetBool("Corrupt", false); } } if ((Object)(object)childGameObject5 != (Object)null) { Animator component4 = childGameObject5.gameObject.GetComponent<Animator>(); if (component4 != null) { component4.SetBool("Corrupt", false); } } } else { if (!(self.voidSurvivorController.corruption >= self.voidSurvivorController.maxCorruption)) { return; } if (childGameObject != null) { childGameObject.SetActive(true); } if (childGameObject2 != null) { childGameObject2.SetActive(false); } if ((Object)(object)childGameObject3 != (Object)null) { Animator component5 = childGameObject3.gameObject.GetComponent<Animator>(); if (component5 != null) { component5.SetBool("Corrupt", true); } } if ((Object)(object)childGameObject4 != (Object)null) { Animator component6 = childGameObject4.gameObject.GetComponent<Animator>(); if (component6 != null) { component6.SetBool("Corrupt", true); } } if ((Object)(object)childGameObject5 != (Object)null) { Animator component7 = childGameObject5.gameObject.GetComponent<Animator>(); if (component7 != null) { component7.SetBool("Corrupt", true); } } } } } private static DynamicSkinExtension _DynamicSkinExtension = new DynamicSkinExtension(); private static DynamicSkinManager _DynamicSkinManager = new DynamicSkinManager(); private static VoidDelegate BeforeStartDelegate; private static VoidDelegate AfterStartDelegate; private static VoidDelegate BeforeBodyCatalogDelegate; private static VoidDelegate AfterBodyCatalogDelegate; private static MeshActivationExtension _MeshActivationExtension = new MeshActivationExtension(); private static readonly Dictionary<SkinDef, MeshActivation_SkinConfig> _meshActivationConfigs = new Dictionary<SkinDef, MeshActivation_SkinConfig>(); private static Hook _meshActivationApplyHook; private static MwSkinAdditionsExtension _MwSkinAdditionsExtension = new MwSkinAdditionsExtension(); public static SkinDef MechamaruJJKVoidFiendSkinDefSkin; private static AssetBundle assetBundle; private static readonly List<Material> materialsWithRoRShader = new List<Material>(); private static CorruptionAddon _CorruptionAddon = new CorruptionAddon(); private static Hook corruptionOnEnterHook; internal static MechamaruJJK_VoidFiendPlugin Instance { get; private set; } internal static ManualLogSource InstanceLogger { get { MechamaruJJK_VoidFiendPlugin instance = Instance; if (instance == null) { return null; } return ((BaseUnityPlugin)instance).Logger; } } private static event EventHandler<SkinAddedArgs> VoidSurvivorBodyMechamaruJJKVoidFiendSkinDefSkinAddedEvent; private static IEnumerator MeshActivation_OnSkinDefApplyAsync(Func<SkinDef, GameObject, List<AssetReferenceT<Material>>, List<AssetReferenceT<Mesh>>, int, IEnumerator> orig, SkinDef self, GameObject modelObject, List<AssetReferenceT<Material>> loadedMaterials, List<AssetReferenceT<Mesh>> loadedMeshes, int unloadType) { if (!_meshActivationConfigs.TryGetValue(self, out var config)) { IEnumerator passthrough = orig(self, modelObject, loadedMaterials, loadedMeshes, unloadType); while (passthrough.MoveNext()) { yield return passthrough.Current; } yield break; } Transform armature = modelObject.transform.Find(config.armaturePath); HashSet<Transform> before = null; if (config.autoDetectAll && (Object)(object)armature != (Object)null) { before = new HashSet<Transform>(((Component)armature).GetComponentsInChildren<Transform>(true)); } IEnumerator origEnumerator = orig(self, modelObject, loadedMaterials, loadedMeshes, unloadType); while (origEnumerator.MoveNext()) { yield return origEnumerator.Current; } if ((Object)(object)armature == (Object)null) { ManualLogSource instanceLogger = InstanceLogger; if (instanceLogger != null) { instanceLogger.LogWarning((object)("MeshActivation: could not find \"" + config.armaturePath + "\" on the spawned model")); } yield break; } CharacterModel component = modelObject.GetComponent<CharacterModel>(); if ((Object)(object)component == (Object)null) { yield break; } if (config.autoDetectAll) { foreach (Transform item in from t in ((Component)armature).GetComponentsInChildren<Transform>(true) where (Object)(object)t != (Object)(object)armature && !before.Contains(t) && ((Object)(object)t.parent == (Object)(object)armature || before.Contains(t.parent)) select t) { MeshActivation_RegisterObject(((Component)item).gameObject, component, null, initialActiveState: true); } yield break; } foreach (MeshActivation_Entry entry in config.manualEntries) { Transform val = ((IEnumerable<Transform>)((Component)armature).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => (Object)(object)t != (Object)(object)armature && MeshActivation_StripClone(((Object)t).name) == entry.prefabName)); if ((Object)(object)val == (Object)null) { ManualLogSource instanceLogger2 = InstanceLogger; if (instanceLogger2 != null) { instanceLogger2.LogWarning((object)("MeshActivation: could not find spawned prefab named \"" + entry.prefabName + "\" under \"" + config.armaturePath + "\"")); } } else { MeshActivation_RegisterObject(((Component)val).gameObject, component, entry.overrides, entry.initialActiveState); } } } private static void MeshActivation_RegisterObject(GameObject spawned, CharacterModel characterModel, List<MeshActivation_RendererOverride> overrides, bool initialActiveState) { //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) MeshActivation_RegisterMesh(spawned, characterModel); SkinnedMeshRenderer[] componentsInChildren = spawned.GetComponentsInChildren<SkinnedMeshRenderer>(true); int num = characterModel.baseRendererInfos.Length; Array.Resize(ref characterModel.baseRendererInfos, num + componentsInChildren.Length); for (int i = 0; i < componentsInChildren.Length; i++) { SkinnedMeshRenderer renderer = componentsInChildren[i]; MeshActivation_RendererOverride meshActivation_RendererOverride = overrides?.FirstOrDefault((MeshActivation_RendererOverride o) => MeshActivation_StripClone(((Object)renderer).name) == MeshActivation_StripClone(o.rendererName)) ?? overrides?.FirstOrDefault((MeshActivation_RendererOverride o) => string.IsNullOrEmpty(o.rendererName)); characterModel.baseRendererInfos[num + i] = new RendererInfo { renderer = (Renderer)(object)renderer, defaultMaterial = (((Object)(object)meshActivation_RendererOverride?.material != (Object)null) ? meshActivation_RendererOverride.material : ((Renderer)renderer).sharedMaterial), ignoreOverlays = (meshActivation_RendererOverride?.ignoreOverlays ?? false), defaultShadowCastingMode = (ShadowCastingMode)((meshActivation_RendererOverride == null) ? 1 : ((int)meshActivation_RendererOverride.shadowCastingMode)) }; } spawned.SetActive(initialActiveState); characterModel.UpdateMaterials(); } private static void MeshActivation_RegisterMesh(GameObject spawned, CharacterModel characterModel) { SkinnedMeshRenderer componentInChildren = ((Component)characterModel).GetComponentInChildren<SkinnedMeshRenderer>(); if (Object.op_Implicit((Object)(object)componentInChildren)) { SkinnedMeshRenderer[] componentsInChildren = spawned.GetComponentsInChildren<SkinnedMeshRenderer>(true); foreach (SkinnedMeshRenderer obj in componentsInChildren) { obj.rootBone = componentInChildren.rootBone; obj.bones = componentInChildren.bones; } } } private static string MeshActivation_StripClone(string name) { if (!name.EndsWith("(Clone)")) { return name; } return name.Substring(0, name.Length - "(Clone)".Length).TrimEnd(); } private void Start() { Instance = this; BeforeStart(); using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MechamaruJJK_VoidFiend.krononconpsiratormechamarujjk_voidfiend")) { assetBundle = AssetBundle.LoadFromStream(stream); } ((ResourceAvailability)(ref BodyCatalog.availability)).CallWhenAvailable((Action)BodyCatalogInit); HookEndpointManager.Add((MethodBase)typeof(Language).GetMethod("LoadStrings"), (Delegate)new Action<Action<Language>, Language>(LanguageLoadStrings)); ReplaceShaders(); AfterStart(); } private void BeforeStart() { BeforeStartDelegate = (VoidDelegate)Delegate.Combine(BeforeStartDelegate, new VoidDelegate(_MwSkinAdditionsExtension.BeforeStart)); BeforeStartDelegate = (VoidDelegate)Delegate.Combine(BeforeStartDelegate, new VoidDelegate(_DynamicSkinExtension.BeforeStart)); BeforeStartDelegate = (VoidDelegate)Delegate.Combine(BeforeStartDelegate, new VoidDelegate(_MeshActivationExtension.BeforeStart)); BeforeStartDelegate?.Invoke(); } private void AfterStart() { AfterStartDelegate = (VoidDelegate)Delegate.Combine(AfterStartDelegate, new VoidDelegate(_MwSkinAdditionsExtension.AfterStart)); AfterStartDelegate = (VoidDelegate)Delegate.Combine(AfterStartDelegate, new VoidDelegate(_DynamicSkinExtension.AfterStart)); AfterStartDelegate = (VoidDelegate)Delegate.Combine(AfterStartDelegate, new VoidDelegate(_MeshActivationExtension.AfterStart)); AfterStartDelegate = (VoidDelegate)Delegate.Combine(AfterStartDelegate, new VoidDelegate(_CorruptionAddon.AfterStart)); AfterStartDelegate?.Invoke(); } private static void BeforeBodyCatalogInit() { BeforeBodyCatalogDelegate = (VoidDelegate)Delegate.Combine(BeforeBodyCatalogDelegate, new VoidDelegate(_MwSkinAdditionsExtension.BeforeBodyCatalogInit)); BeforeBodyCatalogDelegate = (VoidDelegate)Delegate.Combine(BeforeBodyCatalogDelegate, new VoidDelegate(_DynamicSkinExtension.BeforeBodyCatalogInit)); BeforeBodyCatalogDelegate = (VoidDelegate)Delegate.Combine(BeforeBodyCatalogDelegate, new VoidDelegate(_MeshActivationExtension.BeforeBodyCatalogInit)); BeforeBodyCatalogDelegate?.Invoke(); } private static void AfterBodyCatalogInit() { AfterBodyCatalogDelegate = (VoidDelegate)Delegate.Combine(AfterBodyCatalogDelegate, new VoidDelegate(_MwSkinAdditionsExtension.AfterBodyCatalogInit)); AfterBodyCatalogDelegate = (VoidDelegate)Delegate.Combine(AfterBodyCatalogDelegate, new VoidDelegate(_DynamicSkinExtension.AfterBodyCatalogInit)); AfterBodyCatalogDelegate = (VoidDelegate)Delegate.Combine(AfterBodyCatalogDelegate, new VoidDelegate(_MeshActivationExtension.AfterBodyCatalogInit)); AfterBodyCatalogDelegate?.Invoke(); } private static void ReplaceShaders() { LoadMaterialsWithReplacedShader("RoR2/Base/Shaders/HGStandard.shader", "Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mat/MechamaruJJK_Body1_Mat.mat", "Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mat/MechamaruJJK_Eye_Mat.mat", "Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mat/MechamaruJJK_Body2_Mat.mat", "Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mat/MechamaruJJK_Face_Mat.mat"); } private static void LoadMaterialsWithReplacedShader(string shaderPath, params string[] materialPaths) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) Shader shader = Addressables.LoadAssetAsync<Shader>((object)shaderPath).WaitForCompletion(); foreach (string text in materialPaths) { Material val = assetBundle.LoadAsset<Material>(text); val.shader = shader; materialsWithRoRShader.Add(val); } } private static void LanguageLoadStrings(Action<Language> orig, Language self) { orig(self); self.SetStringByToken("KRONONCONPSIRATOR_SKIN_MECHAMARUJJKVOIDFIENDSKINDEF_NAME", "Heavenly Caged"); } private static void BodyCatalogInit() { BeforeBodyCatalogInit(); AddVoidSurvivorBodyMechamaruJJKVoidFiendSkinDefSkin(); AfterBodyCatalogInit(); } private static void VoidSurvivorBodyMechamaruJJKVoidFiendSkinDefSkinAdded(SkinDef skinDef, GameObject bodyPrefab) { MechamaruJJK_VoidFiendPlugin.VoidSurvivorBodyMechamaruJJKVoidFiendSkinDefSkinAddedEvent(Instance, new SkinAddedArgs(skinDef, bodyPrefab)); } private static void AddVoidSurvivorBodyMechamaruJJKVoidFiendSkinDefSkin() { string text = "VoidSurvivorBody"; string text2 = "MechamaruJJKVoidFiendSkinDef"; try { GameObject val = BodyCatalog.FindBodyPrefab(text); if (!Object.op_Implicit((Object)(object)val)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin because \"" + text + "\" doesn't exist")); return; } ModelLocator component = val.GetComponent<ModelLocator>(); if (!Object.op_Implicit((Object)(object)component)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\" because it doesn't have \"ModelLocator\" component")); return; } GameObject mdl = ((Component)component.modelTransform).gameObject; ModelSkinController skinController = (Object.op_Implicit((Object)(object)mdl) ? mdl.GetComponent<ModelSkinController>() : null); if (!Object.op_Implicit((Object)(object)skinController)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\" because it doesn't have \"ModelSkinController\" component")); return; } Renderer[] renderers = mdl.GetComponentsInChildren<Renderer>(true); mdl.GetComponentsInChildren<Light>(true); SkinDef skin = ScriptableObject.CreateInstance<SkinDef>(); SkinDefParams skinParams = ScriptableObject.CreateInstance<SkinDefParams>(); skin.skinDefParams = skinParams; TryCatchThrow("Icon", delegate { skin.icon = assetBundle.LoadAsset<Sprite>("Assets\\SkinMods\\MechamaruJJK_VoidFiend\\Icons\\MechamaruJJKVoidFiendSkinDefIcon.png"); }); ((Object)skin).name = text2; skin.nameToken = "KRONONCONPSIRATOR_SKIN_MECHAMARUJJKVOIDFIENDSKINDEF_NAME"; skin.rootObject = mdl; TryCatchThrow("Base Skins", delegate { skin.baseSkins = (SkinDef[])(object)new SkinDef[1] { ThrowIfOutOfBounds(0, "Index 0 is out of bounds of skins array", skinController.skins, 0) }; }); TryCatchThrow("Unlockable Name", delegate { skin.unlockableDef = null; }); TryCatchThrow("Game Object Activations", delegate { //IL_0010: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: 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_009e: 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_00ba: 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_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_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_016c: 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_0176: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_021f: 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) skinParams.gameObjectActivations = (GameObjectActivation[])(object)new GameObjectActivation[3] { new GameObjectActivation { gameObject = ((Component)ThrowIfNull<Transform>(0, "There is no renderer at path \"VoidSurvivorArmature/ROOT\"", mdl.transform.Find("VoidSurvivorArmature/ROOT"))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = true, localPosition = new Vector3(0f, 0f, 0f), localRotation = new Vector3(0f, 0f, 0f), localScale = new Vector3(0f, 0f, 0f), prefab = assetBundle.LoadAsset<GameObject>("Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mechamaru_Add_Arm.prefab") }, new GameObjectActivation { gameObject = ((Component)ThrowIfNull<Transform>(1, "There is no renderer at path \"VoidSurvivorArmature/ROOT/base\"", mdl.transform.Find("VoidSurvivorArmature/ROOT/base"))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = true, localPosition = new Vector3(0f, 0f, 0f), localRotation = new Vector3(0f, 0f, 0f), localScale = new Vector3(0f, 0f, 0f), prefab = assetBundle.LoadAsset<GameObject>("Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mechamaru_Add_Hand_ClawEnd.prefab") }, new GameObjectActivation { gameObject = ((Component)ThrowIfNull<Transform>(2, "There is no renderer at path \"VoidSurvivorArmature\"", mdl.transform.Find("VoidSurvivorArmature"))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = true, localPosition = new Vector3(0f, 0f, 0f), localRotation = new Vector3(0f, 0f, 0f), localScale = new Vector3(0f, 0f, 0f), prefab = assetBundle.LoadAsset<GameObject>("Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mechamaru_Add_Hand_FingerEnd.prefab") } }; }); TryCatchThrow("Renderer Infos", delegate { //IL_0010: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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_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_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0166: 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_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) skinParams.rendererInfos = (RendererInfo[])(object)new RendererInfo[4] { new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mat/MechamaruJJK_Body1_Mat.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = true, renderer = ThrowIfNull<Renderer>(0, "There is no renderer with the name \"mdlVoidSurvivorMetal\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "mdlVoidSurvivorMetal"))) }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mat/MechamaruJJK_Eye_Mat.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = false, renderer = ThrowIfNull<Renderer>(1, "There is no renderer with the name \"mdlVoidSurvivorBody\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "mdlVoidSurvivorBody"))) }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mat/MechamaruJJK_Body2_Mat.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = true, renderer = ThrowIfNull<Renderer>(2, "There is no renderer with the name \"mdlVoidSurvivorHead\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "mdlVoidSurvivorHead"))) }, new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/Skins/SkinAsset/Vanilla/VoidFiend/MechamaruJJK/Mat/MechamaruJJK_Face_Mat.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = true, renderer = ThrowIfNull<Renderer>(3, "There is no renderer with the name \"metalcollar.001\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "metalcollar.001"))) } }; }); TryCatchThrow("Mesh Replacements", delegate { //IL_0010: 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_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0136: 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_018f: Unknown result type (might be due to invalid IL or missing references) skinParams.meshReplacements = (MeshReplacement[])(object)new MeshReplacement[4] { new MeshReplacement { mesh = assetBundle.LoadAsset<Mesh>("Assets\\SkinMods\\MechamaruJJK_VoidFiend\\Meshes\\Mechamaru_Body.mesh"), renderer = ThrowIfNull<Renderer>(0, "There is no renderer with the name \"mdlVoidSurvivorMetal\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "mdlVoidSurvivorMetal"))) }, new MeshReplacement { mesh = assetBundle.LoadAsset<Mesh>("Assets\\SkinMods\\MechamaruJJK_VoidFiend\\Meshes\\Mechamaru_Eye.mesh"), renderer = ThrowIfNull<Renderer>(1, "There is no renderer with the name \"mdlVoidSurvivorBody\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "mdlVoidSurvivorBody"))) }, new MeshReplacement { mesh = assetBundle.LoadAsset<Mesh>("Assets\\SkinMods\\MechamaruJJK_VoidFiend\\Meshes\\Mechamaru_Hand.mesh"), renderer = ThrowIfNull<Renderer>(2, "There is no renderer with the name \"mdlVoidSurvivorHead\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "mdlVoidSurvivorHead"))) }, new MeshReplacement { mesh = assetBundle.LoadAsset<Mesh>("Assets\\SkinMods\\MechamaruJJK_VoidFiend\\Meshes\\Mechamaru_Head.mesh"), renderer = ThrowIfNull<Renderer>(3, "There is no renderer with the name \"metalcollar.001\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "metalcollar.001"))) } }; }); TryCatchThrow("Light Infos", delegate { skinParams.lightReplacements = (LightInfo[])(object)new LightInfo[0]; }); TryCatchThrow("Minion Skin Replacements", delegate { skinParams.minionSkinReplacements = Array.Empty<MinionSkinReplacement>(); }); TryCatchThrow("Projectile Ghost Replacements", delegate { skinParams.projectileGhostReplacements = Array.Empty<ProjectileGhostReplacement>(); }); Array.Resize(ref skinController.skins, skinController.skins.Length + 1); skinController.skins[skinController.skins.Length - 1] = skin; VoidSurvivorBodyMechamaruJJKVoidFiendSkinDefSkinAdded(skin, val); } catch (FieldException ex) { if (ex.InnerException is ElementException ex2) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\"")); InstanceLogger.LogWarning((object)$"Field causing issue: {ex.Message}, element: {ex2.Index}"); InstanceLogger.LogWarning((object)ex2.Message); InstanceLogger.LogError((object)ex.InnerException); } else { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\"")); InstanceLogger.LogWarning((object)("Field causing issue: " + ex.Message)); InstanceLogger.LogError((object)ex.InnerException); } } catch (Exception ex3) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\"")); InstanceLogger.LogError((object)ex3); } } private static T ThrowIfEquals<T>(int index, string message, T value, T expected) where T : Enum { if (value.Equals(expected)) { throw new ElementException(index, message); } return value; } private static T ThrowIfOutOfBounds<T>(int index, string message, T[] array, int elementIndex) where T : class { if (array == null || array.Length <= elementIndex) { throw new ElementException(index, message); } return array[elementIndex]; } private static T ThrowIfNull<T>(int index, string message, T value) where T : class { if (value == null) { throw new ElementException(index, message); } return value; } private static void TryCatchThrow(string message, Action action) { try { action?.Invoke(); } catch (Exception innerException) { throw new FieldException(message, innerException); } } private static void TryAddComponent<T>(GameObject obj) where T : Component { if (Object.op_Implicit((Object)(object)obj) && !Object.op_Implicit((Object)(object)obj.GetComponent<T>())) { obj.AddComponent<T>(); } } } internal class MeshActivation_SkinConfig { public string armaturePath; public bool autoDetectAll; public List<MeshActivation_Entry> manualEntries = new List<MeshActivation_Entry>(); } internal class MeshActivation_Entry { public string prefabName; public bool initialActiveState; public List<MeshActivation_RendererOverride> overrides = new List<MeshActivation_RendererOverride>(); } internal class MeshActivation_RendererOverride { public string rendererName; public Material material; public bool ignoreOverlays; public ShadowCastingMode shadowCastingMode; } } namespace RuneFoxMods { internal class Utils { public static void PrintBodyCatalog() { Debug.Log((object)"\nBodyCatalog"); foreach (GameObject allBodyPrefab in BodyCatalog.allBodyPrefabs) { Debug.Log((object)((Object)allBodyPrefab).name); } Debug.Log((object)"\n"); } public static void ReadChildren(GameObject parent, int tabs, bool includecomponents = true) { //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) string text = ""; for (int i = 0; i < tabs; i++) { text += " "; } for (int j = 0; j < parent.transform.childCount; j++) { Transform child = parent.transform.GetChild(j); if ((Object)(object)child == (Object)null) { break; } string text2 = ((Component)child).gameObject.activeInHierarchy.ToString(); Debug.Log((object)(text + ((Object)child).name + " " + text2 + " " + ((object)((Component)child).transform.position/*cast due to .constrained prefix*/).ToString())); if (includecomponents) { ReadComponents(((Component)child).gameObject, tabs + 1); Debug.Log((object)""); } ReadChildren(((Component)child).gameObject, tabs + 1, includecomponents); } } public static void readheiarchy(GameObject parent, bool includeComponents = true) { Debug.Log((object)((Object)parent).name); if (includeComponents) { ReadComponents(parent, 1); Debug.Log((object)""); } ReadChildren(parent, 1, includeComponents); } public static void ReadComponents(GameObject obj, int tabs) { string text = ""; for (int i = 0; i < tabs; i++) { text += " "; } Component[] components = obj.GetComponents(typeof(Component)); foreach (Component val in components) { string text2 = ""; Debug.Log((object)(text + "Comp: " + ((object)val).GetType().ToString() + " " + text2)); } } public static void PrintAllPaths(GameObject parent) { Debug.Log((object)((Object)parent).name); PrintAllPathsInner(parent, ((Object)parent).name); } private static void PrintAllPathsInner(GameObject parent, string parent_string) { int childCount = parent.transform.childCount; for (int i = 0; i < childCount; i++) { Transform child = parent.transform.GetChild(i); if (!((Object)child).name.EndsWith("_end")) { string text = parent_string + "/" + ((Object)child).name; Debug.Log((object)(" " + ((Object)child).name + "\t\t" + text)); PrintAllPathsInner(((Component)child).gameObject, text); continue; } break; } } public unsafe static void PrintDynamicBone(DynamicBone DB) { //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_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) Debug.Log((object)("Root: " + (object)DB.m_Root)); Debug.Log((object)("Damping: " + DB.m_Damping)); Debug.Log((object)("Damping Dist: " + (object)DB.m_DampingDistrib)); Debug.Log((object)("Elasticity: " + DB.m_Elasticity)); Debug.Log((object)("Elasticity Dist: " + (object)DB.m_ElasticityDistrib)); Debug.Log((object)("Stiffness: " + DB.m_Stiffness)); Debug.Log((object)("Stiffness Dist: " + (object)DB.m_StiffnessDistrib)); Debug.Log((object)("Inert: " + DB.m_Inert)); Debug.Log((object)("Inert Dist: " + (object)DB.m_InertDistrib)); Debug.Log((object)("Radius: " + DB.m_Radius)); Debug.Log((object)("Radius Dist: " + (object)DB.m_RadiusDistrib)); Debug.Log((object)("End Length: " + DB.m_EndLength)); Vector3 endOffset = DB.m_EndOffset; Debug.Log((object)("End Offset: " + ((object)(*(Vector3*)(&endOffset))/*cast due to .constrained prefix*/).ToString())); endOffset = DB.m_Gravity; Debug.Log((object)("Gravity: " + ((object)(*(Vector3*)(&endOffset))/*cast due to .constrained prefix*/).ToString())); endOffset = DB.m_Force; Debug.Log((object)("Force: " + ((object)(*(Vector3*)(&endOffset))/*cast due to .constrained prefix*/).ToString())); Debug.Log((object)("FreezeAxis: " + ((object)Unsafe.As<FreezeAxis, FreezeAxis>(ref DB.m_FreezeAxis)/*cast due to .constrained prefix*/).ToString())); Debug.Log((object)("Colliders: " + DB.m_Colliders.Count)); foreach (DynamicBoneCollider collider in DB.m_Colliders) { Debug.Log((object)("\t Parent: " + ((Object)((Component)collider).transform).name)); Debug.Log((object)("\t Direction: " + ((object)Unsafe.As<Direction, Direction>(ref collider.m_Direction)/*cast due to .constrained prefix*/).ToString())); endOffset = collider.m_Center; Debug.Log((object)("\t Center " + ((object)(*(Vector3*)(&endOffset))/*cast due to .constrained prefix*/).ToString())); Debug.Log((object)("\t Bound " + ((object)Unsafe.As<Bound, Bound>(ref collider.m_Bound)/*cast due to .constrained prefix*/).ToString())); Debug.Log((object)("\t Radius " + collider.m_Radius)); Debug.Log((object)("\t Height " + collider.m_Height)); } Debug.Log((object)("Exclusions: " + DB.m_Exclusions.Count)); foreach (Transform exclusion in DB.m_Exclusions) { Debug.Log((object)("\t Transform: " + ((Object)exclusion).name)); } } public static ChildLocator GetChildLocator(GameObject body) { ChildLocator val = null; Transform child = body.transform.GetChild(0); if (Object.op_Implicit((Object)(object)child)) { Transform child2 = child.GetChild(0); if (Object.op_Implicit((Object)(object)child2)) { val = ((Component)child2).GetComponent<ChildLocator>(); if (Object.op_Implicit((Object)(object)val)) { Debug.Log((object)"Locator Found"); } } } return val; } public static Transform FindChildInTree(Transform Root, string name) { Queue<Transform> queue = new Queue<Transform>(); queue.Enqueue(Root); while (queue.Count != 0) { Transform val = queue.Dequeue(); if (((Object)val).name == name) { return val; } for (int i = 0; i < val.childCount; i++) { Transform child = val.GetChild(i); queue.Enqueue(child); } } return null; } public static string RemoveCloneNaming(string str) { return str.Remove(str.Length - 7); } } } namespace RuneFoxMods.DynamicSkins { public static class DynamicSkinHelpers { public static SkinnedMeshRenderer[] GetBaseSkinRenderers(GameObject modelObject) { SkinnedMeshRenderer[] componentsInChildren = modelObject.GetComponentsInChildren<SkinnedMeshRenderer>(true); List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>(); SkinnedMeshRenderer[] array = componentsInChildren; foreach (SkinnedMeshRenderer val in array) { if ((Object)(object)((Component)val).transform.parent == (Object)(object)modelObject.transform) { list.Add(val); } } return list.ToArray(); } public static Transform[] BoneArrayBuilder(Transform NewBoneRoot) { List<Transform> list = new List<Transform>(); BoneArrayBuilderHelper(NewBoneRoot, list); return list.ToArray(); } public static void BoneArrayBuilderHelper(Transform parent, List<Transform> list) { if (!((Object)parent).name.EndsWith("_end")) { list.Add(parent); } for (int i = 0; i < parent.childCount; i++) { BoneArrayBuilderHelper(parent.GetChild(i), list); } } public static Transform GetArmature(GameObject obj) { return GetArmatureHelper(obj); } public static Transform GetArmatureHelper(GameObject obj) { if (((Object)obj).name.ToLower().Contains("armature")) { return obj.transform; } for (int i = 0; i < obj.transform.childCount; i++) { Transform armatureHelper = GetArmatureHelper(((Component)obj.transform.GetChild(i)).gameObject); if (Object.op_Implicit((Object)(object)armatureHelper)) { return armatureHelper; } } return null; } public static Transform GetTopParent(Transform obj) { Transform val = obj; while ((Object)(object)val.parent != (Object)null) { val = val.parent; } return val; } public static string GetPrevBoneInList(Transform targetBone, SkinnedMeshRenderer meshRenderer) { Transform[] bones = meshRenderer.bones; for (int i = 0; i <= bones.Length - 1; i++) { if (((Object)bones[i + 1]).name == ((Object)targetBone).name) { return ((Object)bones[i]).name; } } return null; } public static int GetBoneIndexInList(Transform targetBone, SkinnedMeshRenderer meshRenderer) { Transform[] bones = meshRenderer.bones; for (int i = 0; i <= bones.Length; i++) { if (((Object)bones[i]).name == ((Object)targetBone).name) { return i; } } return -1; } public static int GetPrevBoneIndexInList(Transform targetBone, SkinnedMeshRenderer meshRenderer) { Transform[] bones = meshRenderer.bones; for (int i = 0; i <= bones.Length - 1; i++) { if (((Object)bones[i + 1]).name == ((Object)targetBone).name) { return i; } } return -1; } } internal class DynamicSkinManager { internal Dictionary<string, SkinDef> SkinDefs = new Dictionary<string, SkinDef>(); private GameObject LastModelObject; internal Dictionary<string, SortedList<int, Modification>> ModificationList = new Dictionary<string, SortedList<int, Modification>>(); private Dictionary<GameObject, AppliedModifications> ModifiedObjects = new Dictionary<GameObject, AppliedModifications>(); internal ManualLogSource InstanceLogger; internal void AddModification(string skinNameToken, int boneIndex, Modification modification) { if (!ModificationList.TryGetValue(skinNameToken, out var value)) { value = new SortedList<int, Modification>(); ModificationList.Add(skinNameToken, value); } value.Add(boneIndex, modification); } internal void AddSkinDef(SkinDef skinDef) { SkinDefs.Add(skinDef.nameToken, skinDef); } internal IEnumerator SkinDefApply(Func<SkinDef, GameObject, List<AssetReferenceT<Material>>, List<AssetReferenceT<Mesh>>, int, IEnumerator> orig, SkinDef self, GameObject modelObject, List<AssetReferenceT<Material>> loadedMaterials, List<AssetReferenceT<Mesh>> loadedMeshes, int unloadType) { IEnumerator result = orig(self, modelObject, loadedMaterials, loadedMeshes, unloadType); RemoveInvalidModelObjects(); ModifiedObjects.TryGetValue(modelObject, out var value); try { if (!SkinDefs.TryGetValue(self.nameToken, out var _)) { if (value != null) { ClearSkinModifications(LastModelObject, value); } return result; } if (value == null) { AppliedModifications appliedModifications = new AppliedModifications(); ModifiedObjects.Add(modelObject, appliedModifications); ApplySkinModifications(self, modelObject, appliedModifications); } } catch (Exception ex) { InstanceLogger.LogWarning((object)"An error occured while adding accessories to a skin"); InstanceLogger.LogError((object)ex); } return result; } private void RemoveInvalidModelObjects() { foreach (GameObject item in ModifiedObjects.Keys.Where((GameObject el) => !Object.op_Implicit((Object)(object)el)).ToList()) { ModifiedObjects.Remove(item); } } private void ClearSkinModifications(GameObject modelObject, AppliedModifications modifications) { while (modifications.BaseModelModifications.Count != 0) { Modification modification = modifications.BaseModelModifications.Pop(); clearModification(modification, modelObject, modifications); } while (modifications.OtherModifications.Count != 0) { clearModification(modifications.OtherModifications[0], modelObject, modifications); } ModifiedObjects.Remove(modelObject); } private void ApplySkinModifications(SkinDef skindef, GameObject modelObject, AppliedModifications modifications) { CharacterModel component = modelObject.GetComponent<CharacterModel>(); LastModelObject = modelObject; if (!ModificationList.TryGetValue(skindef.nameToken, out var value)) { return; } foreach (KeyValuePair<int, Modification> item in value) { ApplyModification(modelObject, component, item.Value, modifications); } } private static void ApplyModification(GameObject modelObject, CharacterModel characterModel, Modification modification, AppliedModifications modifications) { _ = modification.bodyname; string parentname = modification.parentname; Transform val = Utils.FindChildInTree(modelObject.transform, parentname); GameObject val2; if (modification.affectsbasemodel) { val2 = Object.Instantiate<GameObject>(modification.prefab, val, false); ((Object)val2).name = Utils.RemoveCloneNaming(((Object)val2).name); modification.instance = val2; modification.inst_armature = val2; ModificationApplyBones(modelObject, modification, modifications); } else { val2 = Object.Instantiate<GameObject>(modification.prefab, modelObject.transform, false); ((Object)val2).name = Utils.RemoveCloneNaming(((Object)val2).name); modification.instance = val2; Transform armature = DynamicSkinHelpers.GetArmature(val2); ((Component)armature).transform.SetParent(val, false); modification.inst_armature = ((Component)armature).gameObject; } modification.instance = val2; if (modification.dynamicBoneData != null) { ModificationApplyDynamicBones(modelObject, modification); } ModificationAddRenderers(val2, characterModel); modifications.OtherModifications.Add(modification); } private static void ModificationApplyBones(GameObject modelObject, Modification modification, AppliedModifications modifications) { SkinnedMeshRenderer[] baseSkinRenderers = DynamicSkinHelpers.GetBaseSkinRenderers(modelObject); List<Transform> list = baseSkinRenderers[0].bones.ToList(); Transform[] array = DynamicSkinHelpers.BoneArrayBuilder(modification.instance.transform); list.InsertRange(modification.boneIndex, array); modification.boneCount = array.Length; SkinnedMeshRenderer[] array2 = baseSkinRenderers; for (int i = 0; i < array2.Length; i++) { array2[i].bones = list.ToArray(); } modifications.BaseModelModifications.Push(modification); } private static void ModificationApplyDynamicBones(GameObject modelObject, Modification modification) { //IL_0057: 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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: 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_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: 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_0253: Unknown result type (might be due to invalid IL or missing references) DynamicBone val = (modification.inst_dynamicBone = modification.instance.AddComponent<DynamicBone>()); List<DynamicBoneCollider> list = new List<DynamicBoneCollider>(); foreach (DynamicBoneColliderData collider in modification.dynamicBoneData.m_Colliders) { DynamicBoneCollider val2 = ((Component)Utils.FindChildInTree(modelObject.transform, collider.m_parent_name)).gameObject.AddComponent<DynamicBoneCollider>(); val2.m_Direction = collider.m_Direction; val2.m_Center = collider.m_Center; val2.m_Bound = collider.m_Bound; val2.m_Radius = collider.m_Radius; val2.m_Height = collider.m_Height; list.Add(val2); } modification.inst_DB_colliders = list; Transform root = (val.m_Root = Utils.FindChildInTree(modification.inst_armature.transform, modification.dynamicBoneData.m_Root)); val.m_Damping = modification.dynamicBoneData.m_Damping; val.m_DampingDistrib = modification.dynamicBoneData.m_DampingDistrib; val.m_Elasticity = modification.dynamicBoneData.m_Elasticity; val.m_ElasticityDistrib = modification.dynamicBoneData.m_ElasticityDistrib; val.m_Stiffness = modification.dynamicBoneData.m_Stiffness; val.m_StiffnessDistrib = modification.dynamicBoneData.m_StiffnessDistrib; val.m_Inert = modification.dynamicBoneData.m_Inert; val.m_InertDistrib = modification.dynamicBoneData.m_InertDistrib; val.m_Radius = modification.dynamicBoneData.m_Radius; val.m_RadiusDistrib = modification.dynamicBoneData.m_RadiusDistrib; val.m_EndLength = modification.dynamicBoneData.m_EndLength; val.m_EndOffset = modification.dynamicBoneData.m_EndOffset; val.m_Gravity = modification.dynamicBoneData.m_Gravity; val.m_Force = modification.dynamicBoneData.m_Force; val.m_Colliders = list; val.m_Exclusions = new List<Transform>(); foreach (string exclusion in modification.dynamicBoneData.m_Exclusions) { Transform val3 = Utils.FindChildInTree(root, exclusion); if ((Object)(object)val3 != (Object)null) { val.m_Exclusions.Add(val3); } else { Debug.LogWarning((object)"Tried to exclude a transform that could not be found"); } } val.m_FreezeAxis = modification.dynamicBoneData.m_FreezeAxis; } private static void ModificationAddRenderers(GameObject newPart, CharacterModel characterModel) { //IL_0044: 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_0076: 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) SkinnedMeshRenderer[] componentsInChildren = newPart.GetComponentsInChildren<SkinnedMeshRenderer>(true); Array.Resize(ref characterModel.baseRendererInfos, characterModel.baseRendererInfos.Length + componentsInChildren.Length); if (componentsInChildren.Length != 0) { int num = componentsInChildren.Length; SkinnedMeshRenderer[] array = componentsInChildren; foreach (SkinnedMeshRenderer val in array) { characterModel.baseRendererInfos[characterModel.baseRendererInfos.Length - num] = new RendererInfo { renderer = (Renderer)(object)componentsInChildren[^num], ignoreOverlays = false, defaultShadowCastingMode = (ShadowCastingMode)1, defaultMaterial = ((Renderer)val).sharedMaterial }; num--; } } } private void clearModification(Modification modification, GameObject modelObject, AppliedModifications modifications) { if (modification.inst_DB_colliders != null) { foreach (DynamicBoneCollider inst_DB_collider in modification.inst_DB_colliders) { Object.Destroy((Object)(object)inst_DB_collider); } } if (modification.affectsbasemodel) { SkinnedMeshRenderer[] baseSkinRenderers = DynamicSkinHelpers.GetBaseSkinRenderers(modelObject); List<Transform> list = baseSkinRenderers[0].bones.ToList(); list.RemoveRange(modification.boneIndex, modification.boneCount); SkinnedMeshRenderer[] array = baseSkinRenderers; for (int i = 0; i < array.Length; i++) { array[i].bones = list.ToArray(); } } Object.Destroy((Object)(object)modifications.OtherModifications[0].inst_dynamicBone); Object.Destroy((Object)(object)modifications.OtherModifications[0].inst_armature); Object.Destroy((Object)(object)modifications.OtherModifications[0].instance); if (!modifications.OtherModifications.Remove(modification)) { InstanceLogger.LogError((object)"Skin Modification was not removed"); } } } internal class Modification { public string prefabpath; public string bodyname; public string parentname; public GameObject prefab; public bool affectsbasemodel; public DynamicBoneData dynamicBoneData; public string parentSkinToken; public int boneIndex; public int boneCount; public GameObject instance; public GameObject inst_armature; public DynamicBone inst_dynamicBone; public List<DynamicBoneCollider> inst_DB_colliders = new List<DynamicBoneCollider>(); public Modification(string PrefabPath, string ParentName, string BodyName, string ParentSkinToken, int BoneIndex, bool AffectsBaseModel, AssetBundle assetBundle) { bodyname = BodyName; prefabpath = PrefabPath; parentname = ParentName; parentSkinToken = ParentSkinToken; affectsbasemodel = AffectsBaseModel; boneIndex = BoneIndex; prefab = assetBundle.LoadAsset<GameObject>(prefabpath); if ((Object)(object)prefab == (Object)null) { Debug.LogWarning((object)("Asset at " + PrefabPath + " was not loaded")); } } } internal class AppliedModifications { public Stack<Modification> BaseModelModifications = new Stack<Modification>(); public List<Modification> OtherModifications = new List<Modification>(); } internal class DynamicBoneData { public string m_Root; public float m_Damping; public AnimationCurve m_DampingDistrib; public float m_Elasticity; public AnimationCurve m_ElasticityDistrib; public float m_Stiffness; public AnimationCurve m_StiffnessDistrib; public float m_Inert; public AnimationCurve m_InertDistrib; public float m_Radius; public AnimationCurve m_RadiusDistrib; public float m_EndLength; public Vector3 m_EndOffset; public Vector3 m_Gravity; public Vector3 m_Force; public List<DynamicBoneColliderData> m_Colliders; public List<string> m_Exclusions; public FreezeAxis m_FreezeAxis; public DynamicBoneData(string root, float damping, AnimationCurve damping_dist, float elasticity, AnimationCurve elasticity_dist, float stiffness, AnimationCurve stiffness_dist, float inert, AnimationCurve inert_dist, float radius, AnimationCurve radius_dist, float end_length, Vector3 end_offset, Vector3 gravity, Vector3 force, List<DynamicBoneColliderData> colliders, List<string> exclusions, FreezeAxis freeze_axis) { //IL_0064: 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_006c: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) m_Root = root; m_Damping = damping; m_DampingDistrib = damping_dist; m_Elasticity = elasticity; m_ElasticityDistrib = elasticity_dist; m_Stiffness = stiffness; m_StiffnessDistrib = stiffness_dist; m_Inert = inert; m_InertDistrib = inert_dist; m_Radius = radius; m_RadiusDistrib = radius_dist; m_EndLength = end_length; m_EndOffset = end_offset; m_Gravity = gravity; m_Force = force; m_Colliders = colliders; m_Exclusions = exclusions; m_FreezeAxis = freeze_axis; } } internal class DynamicBoneColliderData { public string m_parent_name; public Direction m_Direction; public Vector3 m_Center; public Bound m_Bound; public float m_Radius; public float m_Height; public DynamicBoneColliderData(string parent_name, Direction direction, Vector3 Center, Bound bound, float radius, float heaight) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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) m_parent_name = parent_name; m_Direction = direction; m_Center = Center; m_Bound = bound; m_Radius = radius; m_Height = heaight; } } }