From d5e2fc3b057c2ea40fe564df8f3249bb7d0d77b2 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Thu, 22 Dec 2022 16:45:23 +0100 Subject: [PATCH] Try to associate battle voices to characters. --- .../Resolver/PathResolver.AnimationState.cs | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/Penumbra/Interop/Resolver/PathResolver.AnimationState.cs b/Penumbra/Interop/Resolver/PathResolver.AnimationState.cs index 3c842250..e862b82b 100644 --- a/Penumbra/Interop/Resolver/PathResolver.AnimationState.cs +++ b/Penumbra/Interop/Resolver/PathResolver.AnimationState.cs @@ -14,8 +14,9 @@ public unsafe partial class PathResolver { private readonly DrawObjectState _drawObjectState; - private ResolveData _animationLoadData = ResolveData.Invalid; - private ResolveData _lastAvfxData = ResolveData.Invalid; + private ResolveData _animationLoadData = ResolveData.Invalid; + private ResolveData _lastAvfxData = ResolveData.Invalid; + private ResolveData _characterSoundData = ResolveData.Invalid; public AnimationState( DrawObjectState drawObjectState ) { @@ -27,9 +28,22 @@ public unsafe partial class PathResolver { switch( type ) { + case ResourceType.Scd: + if( _characterSoundData.Valid ) + { + resolveData = _characterSoundData; + return true; + } + + if( _animationLoadData.Valid ) + { + resolveData = _animationLoadData; + return true; + } + + break; case ResourceType.Tmb: case ResourceType.Pap: - case ResourceType.Scd: if( _animationLoadData.Valid ) { resolveData = _animationLoadData; @@ -76,6 +90,7 @@ public unsafe partial class PathResolver _loadSomePapHook.Enable(); _someActionLoadHook.Enable(); _someOtherAvfxHook.Enable(); + _loadCharacterSoundHook.Enable(); } public void Disable() @@ -86,6 +101,7 @@ public unsafe partial class PathResolver _loadSomePapHook.Disable(); _someActionLoadHook.Disable(); _someOtherAvfxHook.Disable(); + _loadCharacterSoundHook.Disable(); } public void Dispose() @@ -96,6 +112,22 @@ public unsafe partial class PathResolver _loadSomePapHook.Dispose(); _someActionLoadHook.Dispose(); _someOtherAvfxHook.Dispose(); + _loadCharacterSoundHook.Dispose(); + } + + // Characters load some of their voice lines or whatever with this function. + private delegate IntPtr LoadCharacterSound( IntPtr character, int unk1, int unk2, IntPtr unk3, ulong unk4, int unk5, int unk6, ulong unk7 ); + + [Signature( "4C 89 4C 24 ?? 55 57 41 56", DetourName = nameof( LoadCharacterSoundDetour ) )] + private readonly Hook< LoadCharacterSound > _loadCharacterSoundHook = null!; + + private IntPtr LoadCharacterSoundDetour( IntPtr character, int unk1, int unk2, IntPtr unk3, ulong unk4, int unk5, int unk6, ulong unk7 ) + { + var last = _characterSoundData; + _characterSoundData = IdentifyCollection( ( GameObject* )character, true ); + var ret = _loadCharacterSoundHook.Original( character, unk1, unk2, unk3, unk4, unk5, unk6, unk7 ); + _characterSoundData = last; + return ret; } // The timeline object loads the requested .tmb and .pap files. The .tmb files load the respective .avfx files.