From 8e0877659f009253c830e32391dc403dc0c4c664 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Wed, 4 Oct 2023 16:17:03 +0200 Subject: [PATCH] Update LoadCharacterSound. --- .../PathResolving/AnimationHookService.cs | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Penumbra/Interop/PathResolving/AnimationHookService.cs b/Penumbra/Interop/PathResolving/AnimationHookService.cs index 7f69ceef..9b089658 100644 --- a/Penumbra/Interop/PathResolving/AnimationHookService.cs +++ b/Penumbra/Interop/PathResolving/AnimationHookService.cs @@ -21,7 +21,7 @@ public unsafe class AnimationHookService : IDisposable private readonly CollectionResolver _collectionResolver; private readonly DrawObjectState _drawObjectState; private readonly CollectionResolver _resolver; - private readonly ICondition _conditions; + private readonly ICondition _conditions; private readonly ThreadLocal _animationLoadData = new(() => ResolveData.Invalid, true); private readonly ThreadLocal _characterSoundData = new(() => ResolveData.Invalid, true); @@ -111,17 +111,19 @@ public unsafe class AnimationHookService : IDisposable } /// 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); + private delegate nint LoadCharacterSound(nint character, int unk1, int unk2, nint unk3, ulong unk4, int unk5, int unk6, ulong unk7); + // TODO: Use ClientStructs [Signature(Sigs.LoadCharacterSound, DetourName = nameof(LoadCharacterSoundDetour))] private readonly Hook _loadCharacterSoundHook = null!; - private IntPtr LoadCharacterSoundDetour(IntPtr character, int unk1, int unk2, IntPtr unk3, ulong unk4, int unk5, int unk6, ulong unk7) + private nint LoadCharacterSoundDetour(nint container, int unk1, int unk2, nint unk3, ulong unk4, int unk5, int unk6, ulong unk7) { using var performance = _performance.Measure(PerformanceType.LoadSound); var last = _characterSoundData.Value; - _characterSoundData.Value = _collectionResolver.IdentifyCollection((GameObject*)character, true); - var ret = _loadCharacterSoundHook.Original(character, unk1, unk2, unk3, unk4, unk5, unk6, unk7); + var character = *(GameObject**)(container + 8); + _characterSoundData.Value = _collectionResolver.IdentifyCollection(character, true); + var ret = _loadCharacterSoundHook.Original(container, unk1, unk2, unk3, unk4, unk5, unk6, unk7); _characterSoundData.Value = last; return ret; } @@ -130,12 +132,12 @@ public unsafe class AnimationHookService : IDisposable /// The timeline object loads the requested .tmb and .pap files. The .tmb files load the respective .avfx files. /// We can obtain the associated game object from the timelines 28'th vfunc and use that to apply the correct collection. /// - private delegate ulong LoadTimelineResourcesDelegate(IntPtr timeline); + private delegate ulong LoadTimelineResourcesDelegate(nint timeline); [Signature(Sigs.LoadTimelineResources, DetourName = nameof(LoadTimelineResourcesDetour))] private readonly Hook _loadTimelineResourcesHook = null!; - private ulong LoadTimelineResourcesDetour(IntPtr timeline) + private ulong LoadTimelineResourcesDetour(nint timeline) { using var performance = _performance.Measure(PerformanceType.TimelineResources); // Do not check timeline loading in cutscenes. @@ -153,12 +155,12 @@ public unsafe class AnimationHookService : IDisposable /// Probably used when the base idle animation gets loaded. /// Make it aware of the correct collection to load the correct pap files. /// - private delegate void CharacterBaseNoArgumentDelegate(IntPtr drawBase); + private delegate void CharacterBaseNoArgumentDelegate(nint drawBase); [Signature(Sigs.CharacterBaseLoadAnimation, DetourName = nameof(CharacterBaseLoadAnimationDetour))] private readonly Hook _characterBaseLoadAnimationHook = null!; - private void CharacterBaseLoadAnimationDetour(IntPtr drawObject) + private void CharacterBaseLoadAnimationDetour(nint drawObject) { using var performance = _performance.Measure(PerformanceType.LoadCharacterBaseAnimation); var last = _animationLoadData.Value; @@ -171,17 +173,17 @@ public unsafe class AnimationHookService : IDisposable } /// Unknown what exactly this is but it seems to load a bunch of paps. - private delegate void LoadSomePap(IntPtr a1, int a2, IntPtr a3, int a4); + private delegate void LoadSomePap(nint a1, int a2, nint a3, int a4); [Signature(Sigs.LoadSomePap, DetourName = nameof(LoadSomePapDetour))] private readonly Hook _loadSomePapHook = null!; - private void LoadSomePapDetour(IntPtr a1, int a2, IntPtr a3, int a4) + private void LoadSomePapDetour(nint a1, int a2, nint a3, int a4) { using var performance = _performance.Measure(PerformanceType.LoadPap); var timelinePtr = a1 + Offsets.TimeLinePtr; var last = _animationLoadData.Value; - if (timelinePtr != IntPtr.Zero) + if (timelinePtr != nint.Zero) { var actorIdx = (int)(*(*(ulong**)timelinePtr + 1) >> 3); if (actorIdx >= 0 && actorIdx < _objects.Length) @@ -206,12 +208,12 @@ public unsafe class AnimationHookService : IDisposable } /// Load a VFX specifically for a character. - private delegate IntPtr LoadCharacterVfxDelegate(byte* vfxPath, VfxParams* vfxParams, byte unk1, byte unk2, float unk3, int unk4); + private delegate nint LoadCharacterVfxDelegate(byte* vfxPath, VfxParams* vfxParams, byte unk1, byte unk2, float unk3, int unk4); [Signature(Sigs.LoadCharacterVfx, DetourName = nameof(LoadCharacterVfxDetour))] private readonly Hook _loadCharacterVfxHook = null!; - private IntPtr LoadCharacterVfxDetour(byte* vfxPath, VfxParams* vfxParams, byte unk1, byte unk2, float unk3, int unk4) + private nint LoadCharacterVfxDetour(byte* vfxPath, VfxParams* vfxParams, byte unk1, byte unk2, float unk3, int unk4) { using var performance = _performance.Measure(PerformanceType.LoadCharacterVfx); var last = _animationLoadData.Value; @@ -296,7 +298,7 @@ public unsafe class AnimationHookService : IDisposable { try { - if (timeline != IntPtr.Zero) + if (timeline != nint.Zero) { var getGameObjectIdx = ((delegate* unmanaged**)timeline)[0][Offsets.GetGameObjectIdxVfunc]; var idx = getGameObjectIdx(timeline);