Skip to content

Commit

Permalink
fix: some more VRCF/external hook compatibility issues (#162)
Browse files Browse the repository at this point in the history
Closes: #158
  • Loading branch information
bdunderscore authored Feb 12, 2024
1 parent 2896716 commit 09858e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ave3mu's "Run Preprocess Avatar Hook" option was force-enabled even when apply on play was disabled (#160)

### Changed
- Changed the hook processing logic to closer match VRCSDK (improves compatibility with VRCF and other external hooks)
(#162)

### Removed

Expand Down
27 changes: 22 additions & 5 deletions Editor/ApplyOnPlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,32 @@ private static void MaybeProcessAvatar(ApplyOnPlayGlobalActivator.OnDemandSource
if (avatar == null) return;

if (HookDedup.HasAvatar(avatar.gameObject)) return;

var avatarPreprocessed = false;
#if NDMF_VRCSDK3_AVATARS
if (avatar.GetComponent<VRCAvatarDescriptor>())
{
// For VRC avatars, we respect VRC Public SDK API, to align with other VRC preprocessors.
// That means, our entrypoint is the responsible VRCSDK hook, which calls ndmf and other VRC preprocessors.
avatarPreprocessed = true;
VRCBuildPipelineCallbacks.OnPreprocessAvatar(avatar.gameObject);
// When the VRCSDK processes an avatar, the original avatar and a clone exist at the same time in
// the scene, with the clone having a `(Clone)` suffix. Some non-NDMF hooks (e.g. VRCFury) depend
// on this behavior, so replicate it here.

var avatarGameObject = avatar.gameObject;
var oldName = avatarGameObject.name;
avatarGameObject.name += "(Clone)";
var fakeOriginal = new GameObject(oldName);

try
{
// For VRC avatars, we respect VRC Public SDK API, to align with other VRC preprocessors.
// That means, our entrypoint is the responsible VRCSDK hook, which calls ndmf and other VRC preprocessors.
avatarPreprocessed = true;
VRCBuildPipelineCallbacks.OnPreprocessAvatar(avatarGameObject);
}
finally
{
UnityEngine.Object.DestroyImmediate(fakeOriginal);
avatar.gameObject.name = oldName;
}
}
#endif
if (!avatarPreprocessed)
Expand Down

0 comments on commit 09858e9

Please sign in to comment.