diff --git a/CHANGELOG.md b/CHANGELOG.md index 2222680..bbf024b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.7 +### Bug Fixes +* Fix optimizer not working with VRCSDK3-AVATAR-2022.10.12.21.07 SDK onwards. [(more)](https://github.com/d4rkc0d3r/d4rkAvatarOptimizer/issues/12) + ## v1.6 ### Features * Optimizer now shows a progress bar dialog when optimizing an avatar. diff --git a/src/d4rkAvatarOptimizerEditor.cs b/src/d4rkAvatarOptimizerEditor.cs index 4473a27..4e6e853 100644 --- a/src/d4rkAvatarOptimizerEditor.cs +++ b/src/d4rkAvatarOptimizerEditor.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using System.Threading; using System.Globalization; +using System.Reflection; using UnityEngine; using UnityEngine.Animations; using UnityEngine.SceneManagement; @@ -2839,6 +2840,34 @@ private void PerfRankChangeLabel(string label, int oldValue, int newValue, Avata EditorGUILayout.LabelField(label); EditorGUILayout.EndHorizontal(); } + + private void RemoveIllegalComponents(GameObject target) + { + // call VRC.SDK3.Validation.AvatarValidation.RemoveIllegalComponents(target, true) with reflection if it exists + var RemoveIllegalComponents = Type.GetType("VRC.SDK3.Validation.AvatarValidation, Assembly-CSharp") + ?.GetMethod("RemoveIllegalComponents", BindingFlags.Static | BindingFlags.Public); + if (RemoveIllegalComponents != null) + { + RemoveIllegalComponents.Invoke(null, new object[] { target, true }); + return; + } + + // if not found use newer sdk method with reflection + // VRC.SDK3.Validation.AvatarValidation.GetComponentWhitelist() + // VRC.SDKBase.Validation.ValidationUtils.RemoveIllegalComponents(GameObject target, HashSet whitelist, bool retry, bool onlySceneObjects, bool logStripping) + var GetComponentWhitelist = Type.GetType("VRC.SDK3.Validation.AvatarValidation, Assembly-CSharp") + ?.GetMethod("GetComponentWhitelist", BindingFlags.Static | BindingFlags.NonPublic); + RemoveIllegalComponents = Type.GetType("VRC.SDKBase.Validation.ValidationUtils, Assembly-CSharp") + ?.GetMethod("RemoveIllegalComponents", BindingFlags.Static | BindingFlags.Public); + if (GetComponentWhitelist != null && RemoveIllegalComponents != null) + { + var whitelist = GetComponentWhitelist.Invoke(null, null) as HashSet; + RemoveIllegalComponents.Invoke(null, new object[] { target, whitelist, true, false, true }); + return; + } + + Debug.LogWarning("Could not find RemoveIllegalComponents method"); + } public override void OnInspectorGUI() { @@ -2913,7 +2942,7 @@ public override void OnInspectorGUI() copy.name = settings.gameObject.name + "(BrokenCopy)"; DestroyImmediate(copy.GetComponent()); if (copy.GetComponent() != null) - VRC.SDK3.Validation.AvatarValidation.RemoveIllegalComponents(copy); + RemoveIllegalComponents(copy); Optimize(copy); copy.name = settings.gameObject.name + "(OptimizedCopy)"; copy.SetActive(true);