From 808d7ab017f26fe0de1711572be508495558a40b Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Tue, 19 Sep 2023 20:18:53 +0200 Subject: [PATCH] Add CalculateHeight Hook --- Penumbra.GameData | 2 +- Penumbra/Interop/PathResolving/MetaState.cs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Penumbra.GameData b/Penumbra.GameData index f004e069..7c483764 160000 --- a/Penumbra.GameData +++ b/Penumbra.GameData @@ -1 +1 @@ -Subproject commit f004e069824a1588244e06080b32bab170f78077 +Subproject commit 7c483764678c6edb5efd55f056aeaecae144d5fe diff --git a/Penumbra/Interop/PathResolving/MetaState.cs b/Penumbra/Interop/PathResolving/MetaState.cs index 40984c6a..a68e376b 100644 --- a/Penumbra/Interop/PathResolving/MetaState.cs +++ b/Penumbra/Interop/PathResolving/MetaState.cs @@ -1,5 +1,7 @@ using Dalamud.Hooking; using Dalamud.Utility.Signatures; +using FFXIVClientStructs.FFXIV.Client.Game.Character; +using FFXIVClientStructs.FFXIV.Client.Game.Object; using FFXIVClientStructs.FFXIV.Client.Graphics.Scene; using OtterGui.Classes; using Penumbra.Collections; @@ -36,7 +38,7 @@ namespace Penumbra.Interop.PathResolving; // RSP tail entries seem to be obtained by "E8 ?? ?? ?? ?? 0F 28 F0 48 8B 05" // RSP bust size entries seem to be obtained by "E8 ?? ?? ?? ?? F2 0F 10 44 24 ?? 8B 44 24 ?? F2 0F 11 45 ?? 89 45 ?? 83 FF" // they all are called by many functions, but the most relevant seem to be Human.SetupFromCharacterData, which is only called by CharacterBase.Create, -// ChangeCustomize and RspSetupCharacter, which is hooked here. +// ChangeCustomize and RspSetupCharacter, which is hooked here, as well as Character.CalculateHeight. // GMP Entries seem to be only used by "48 8B ?? 53 55 57 48 83 ?? ?? 48 8B", which has a DrawObject as its first parameter. public unsafe class MetaState : IDisposable @@ -74,6 +76,7 @@ public unsafe class MetaState : IDisposable _setupVisorHook.Enable(); _rspSetupCharacterHook.Enable(); _changeCustomize.Enable(); + _calculateHeightHook.Enable(); _gameEventManager.CreatingCharacterBase += OnCreatingCharacterBase; _gameEventManager.CharacterBaseCreated += OnCharacterBaseCreated; } @@ -118,6 +121,7 @@ public unsafe class MetaState : IDisposable _setupVisorHook.Dispose(); _rspSetupCharacterHook.Dispose(); _changeCustomize.Dispose(); + _calculateHeightHook.Dispose(); _gameEventManager.CreatingCharacterBase -= OnCreatingCharacterBase; _gameEventManager.CharacterBaseCreated -= OnCharacterBaseCreated; } @@ -242,6 +246,19 @@ public unsafe class MetaState : IDisposable } } + private delegate ulong CalculateHeightDelegate(Character* character); + + // TODO: use client structs + [Signature(Sigs.CalculateHeight, DetourName = nameof(CalculateHeightDetour))] + private readonly Hook _calculateHeightHook = null!; + + private ulong CalculateHeightDetour(Character* character) + { + var resolveData = _collectionResolver.IdentifyCollection((GameObject*)character, true); + using var cmp = resolveData.ModCollection.TemporarilySetCmpFile(_characterUtility); + return _calculateHeightHook.Original(character); + } + private delegate bool ChangeCustomizeDelegate(nint human, nint data, byte skipEquipment); [Signature(Sigs.ChangeCustomize, DetourName = nameof(ChangeCustomizeDetour))]