Skip to content

Commit

Permalink
Add CalculateHeight Hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Sep 19, 2023
1 parent 69012e5 commit 808d7ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Penumbra.GameData
19 changes: 18 additions & 1 deletion Penumbra/Interop/PathResolving/MetaState.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -74,6 +76,7 @@ public MetaState(PerformanceTracker performance, CommunicatorService communicato
_setupVisorHook.Enable();
_rspSetupCharacterHook.Enable();
_changeCustomize.Enable();
_calculateHeightHook.Enable();
_gameEventManager.CreatingCharacterBase += OnCreatingCharacterBase;
_gameEventManager.CharacterBaseCreated += OnCharacterBaseCreated;
}
Expand Down Expand Up @@ -118,6 +121,7 @@ public void Dispose()
_setupVisorHook.Dispose();
_rspSetupCharacterHook.Dispose();
_changeCustomize.Dispose();
_calculateHeightHook.Dispose();
_gameEventManager.CreatingCharacterBase -= OnCreatingCharacterBase;
_gameEventManager.CharacterBaseCreated -= OnCharacterBaseCreated;
}
Expand Down Expand Up @@ -242,6 +246,19 @@ private void RspSetupCharacterDetour(nint drawObject, nint unk2, float unk3, nin
}
}

private delegate ulong CalculateHeightDelegate(Character* character);

// TODO: use client structs
[Signature(Sigs.CalculateHeight, DetourName = nameof(CalculateHeightDetour))]
private readonly Hook<CalculateHeightDelegate> _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))]
Expand Down

0 comments on commit 808d7ab

Please sign in to comment.