Skip to content

Commit

Permalink
Fix issue #10: rollback obfuscation of animators which are not refere…
Browse files Browse the repository at this point in the history
…nced in the VRC avatar descriptor, show an unsupported message instead
  • Loading branch information
Esska committed Jun 19, 2023
1 parent 709d1f0 commit 8bc377c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 42 deletions.
37 changes: 20 additions & 17 deletions Editor/AV3ObfuscatorEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,26 @@ public override void OnInspectorGUI() {
descriptor = obfus.GetComponent<VRCAvatarDescriptor>();

if (descriptor == null) {
EditorGUILayout.HelpBox("No avatar descriptor found", MessageType.Warning, true);
EditorGUILayout.HelpBox("VRCAvatarDescriptor component is missing", MessageType.Error, true);
return;
}

Animator animator = descriptor.GetComponent<Animator>();

if (animator == null) {
EditorGUILayout.HelpBox("Animator component is missing", MessageType.Error, true);
return;
}

if (animator.avatar == null) {
EditorGUILayout.HelpBox("Animator has no avatar", MessageType.Error, true);
return;
}

Animator[] animators = descriptor.GetComponentsInChildren<Animator>(true);

if (animators.Length > 1) {
EditorGUILayout.HelpBox("More than one animator found. Obfuscation of additional animators below the hierarchy is not supported.", MessageType.Error, true);
return;
}

Expand Down Expand Up @@ -65,22 +84,6 @@ public override void OnInspectorGUI() {
}
}

Animator[] animators = descriptor.GetComponentsInChildren<Animator>(true);

foreach (var item in animators) {

if (item.runtimeAnimatorController == null)
continue;

AnimatorController controller = (AnimatorController)item.runtimeAnimatorController;

foreach (var parameter in controller.parameters) {

if (!allParameters.Contains(parameter.name))
allParameters.Add(parameter.name);
}
}

for (int i = obfus.config.obfuscatedParameters.Count - 1; i >= 0; i--) {

if (!allParameters.Contains(obfus.config.obfuscatedParameters[i]))
Expand Down
34 changes: 10 additions & 24 deletions Editor/Obfuscator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class Obfuscator : ScriptableObject {
Dictionary<AvatarMask, AvatarMask> obfuscatedAvatarMasks;
Dictionary<string, string> obfuscatedBlendShapeNames;
Dictionary<BlendTree, BlendTree> obfuscatedBlendTrees;
Dictionary<AnimatorController, AnimatorController> obfuscatedControllers;
Dictionary<VRCExpressionsMenu, VRCExpressionsMenu> obfuscatedExpressionMenus;
Dictionary<Material, Material> obfuscatedMaterials;
Dictionary<Mesh, Mesh> obfuscatedMeshes;
Expand Down Expand Up @@ -118,6 +117,14 @@ public void Obfuscate(GameObject gameObject, ObfuscationConfiguration config) {
if (animator == null)
throw new System.Exception("Animator component is missing");

if (animator.avatar == null)
throw new System.Exception("Animator has no avatar");

Animator[] animators = descriptor.GetComponentsInChildren<Animator>(true);

if (animators.Length > 1)
throw new System.Exception("More than one animator found. Obfuscation of additional animators below the hierarchy is not supported.");

Init();

EditorUtility.DisplayProgressBar(TITLE, "Obfuscate Transforms", 0.1f);
Expand Down Expand Up @@ -182,7 +189,6 @@ void Init() {
obfuscatedAvatarMasks = new Dictionary<AvatarMask, AvatarMask>();
obfuscatedBlendShapeNames = new Dictionary<string, string>();
obfuscatedBlendTrees = new Dictionary<BlendTree, BlendTree>();
obfuscatedControllers = new Dictionary<AnimatorController, AnimatorController>();
obfuscatedExpressionMenus = new Dictionary<VRCExpressionsMenu, VRCExpressionsMenu>();
obfuscatedMaterials = new Dictionary<Material, Material>();
obfuscatedMeshes = new Dictionary<Mesh, Mesh>();
Expand Down Expand Up @@ -227,9 +233,6 @@ void CollectTransforms(Transform rootTransform, Transform transform) {
transformNames.Add(child.name);
transformPaths.Add(AnimationUtility.CalculateTransformPath(child, rootTransform));
CollectTransforms(rootTransform, child);

if (child.GetComponent<Animator>() != null)
CollectTransforms(child, child);
}
}

Expand All @@ -245,9 +248,6 @@ void CollectObfuscatedTransforms(Transform rootTransform, Transform transform) {
obfuscatedTransformNames.Add(child.name);
obfuscatedTransformPaths.Add(AnimationUtility.CalculateTransformPath(child, rootTransform));
CollectObfuscatedTransforms(rootTransform, child);

if (child.GetComponent<Animator>() != null)
CollectObfuscatedTransforms(child, child);
}
}

Expand Down Expand Up @@ -555,28 +555,14 @@ void ObfuscateControllers(VRCAvatarDescriptor descriptor, Animator animator) {

Animator[] animators = descriptor.GetComponentsInChildren<Animator>(true);

foreach (var item in animators) {

if (item == animator || item.runtimeAnimatorController == null)
continue;

AnimatorController obfuscatedController = ObfuscateController((AnimatorController)item.runtimeAnimatorController);

if (obfuscatedController != null)
item.runtimeAnimatorController = obfuscatedController;
}

if (animator.runtimeAnimatorController != null && !runtimeAnimatorValid)
Debug.LogError("Controller in Animator component cannot be obfuscated. You should set an controller, which is part of your playable layers (e.g. FX controller).", animator);
}

AnimatorController ObfuscateController(AnimatorController controller) {
string newPath = GetObfuscatedPath<AnimatorController>();

if (obfuscatedControllers.ContainsKey(controller)) {
return obfuscatedControllers[controller];
}
else if (AssetDatabase.CopyAsset(AssetDatabase.GetAssetPath(controller), newPath)) {
if (AssetDatabase.CopyAsset(AssetDatabase.GetAssetPath(controller), newPath)) {
AnimatorController obfuscatedController = AssetDatabase.LoadAssetAtPath<AnimatorController>(newPath);

// Parameters
Expand Down Expand Up @@ -1091,7 +1077,7 @@ Texture ObfuscateTexture(Texture texture) {
return texture;
}
else if (path.Contains("unity_builtin")) {
Debug.LogError("Unity built-in Texture '{texture.name}' cannot be obfuscated. It will be ignored.");
Debug.LogError($"Unity built-in Texture '{texture.name}' cannot be obfuscated. It will be ignored.");
return texture;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.esska.av3obfuscator",
"displayName": "Esska AV3 Obfuscator",
"version": "2.0.7",
"version": "2.0.8",
"unity": "2019.4",
"description": "Esska AV3Obfuscator allows you to obfuscate your VRChat avatar.",
"author": {
Expand Down

0 comments on commit 8bc377c

Please sign in to comment.