Skip to content

Commit

Permalink
fix RemoveIllegalComponents method getting changed in newer vrc sdk. fix
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rkc0d3r committed Oct 13, 2022
1 parent cf8c6d5 commit 5981f43
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
31 changes: 30 additions & 1 deletion src/d4rkAvatarOptimizerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Type> 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<Type>;
RemoveIllegalComponents.Invoke(null, new object[] { target, whitelist, true, false, true });
return;
}

Debug.LogWarning("Could not find RemoveIllegalComponents method");
}

public override void OnInspectorGUI()
{
Expand Down Expand Up @@ -2913,7 +2942,7 @@ public override void OnInspectorGUI()
copy.name = settings.gameObject.name + "(BrokenCopy)";
DestroyImmediate(copy.GetComponent<d4rkAvatarOptimizer>());
if (copy.GetComponent<VRCAvatarDescriptor>() != null)
VRC.SDK3.Validation.AvatarValidation.RemoveIllegalComponents(copy);
RemoveIllegalComponents(copy);
Optimize(copy);
copy.name = settings.gameObject.name + "(OptimizedCopy)";
copy.SetActive(true);
Expand Down

0 comments on commit 5981f43

Please sign in to comment.