Make meta hooks respect Enable Mod setting and fix EQP composition.

This commit is contained in:
Ottermandias 2024-06-19 22:34:59 +02:00
parent a90e253c73
commit 29f8c91306
12 changed files with 121 additions and 33 deletions

View file

@ -6,7 +6,7 @@ using Penumbra.Interop.PathResolving;
namespace Penumbra.Interop.Hooks.Meta;
public unsafe class EqdpAccessoryHook : FastHook<EqdpAccessoryHook.Delegate>
public unsafe class EqdpAccessoryHook : FastHook<EqdpAccessoryHook.Delegate>, IDisposable
{
public delegate void Delegate(CharacterUtility* utility, EqdpEntry* entry, uint id, uint raceCode);
@ -15,7 +15,8 @@ public unsafe class EqdpAccessoryHook : FastHook<EqdpAccessoryHook.Delegate>
public EqdpAccessoryHook(HookManager hooks, MetaState metaState)
{
_metaState = metaState;
Task = hooks.CreateHook<Delegate>("GetEqdpAccessoryEntry", "E8 ?? ?? ?? ?? 41 BF ?? ?? ?? ?? 83 FB", Detour, true);
Task = hooks.CreateHook<Delegate>("GetEqdpAccessoryEntry", "E8 ?? ?? ?? ?? 41 BF ?? ?? ?? ?? 83 FB", Detour, metaState.Config.EnableMods);
_metaState.Config.ModsEnabled += Toggle;
}
private void Detour(CharacterUtility* utility, EqdpEntry* entry, uint setId, uint raceCode)
@ -27,4 +28,7 @@ public unsafe class EqdpAccessoryHook : FastHook<EqdpAccessoryHook.Delegate>
Penumbra.Log.Excessive(
$"[GetEqdpAccessoryEntry] Invoked on 0x{(ulong)utility:X} with {setId}, {(GenderRace)raceCode}, returned {(ushort)*entry:B10}.");
}
public void Dispose()
=> _metaState.Config.ModsEnabled -= Toggle;
}

View file

@ -6,7 +6,7 @@ using Penumbra.Interop.PathResolving;
namespace Penumbra.Interop.Hooks.Meta;
public unsafe class EqdpEquipHook : FastHook<EqdpEquipHook.Delegate>
public unsafe class EqdpEquipHook : FastHook<EqdpEquipHook.Delegate>, IDisposable
{
public delegate void Delegate(CharacterUtility* utility, EqdpEntry* entry, uint id, uint raceCode);
@ -15,7 +15,8 @@ public unsafe class EqdpEquipHook : FastHook<EqdpEquipHook.Delegate>
public EqdpEquipHook(HookManager hooks, MetaState metaState)
{
_metaState = metaState;
Task = hooks.CreateHook<Delegate>("GetEqdpEquipEntry", "E8 ?? ?? ?? ?? 85 DB 75 ?? F6 45", Detour, true);
Task = hooks.CreateHook<Delegate>("GetEqdpEquipEntry", "E8 ?? ?? ?? ?? 85 DB 75 ?? F6 45", Detour, metaState.Config.EnableMods);
_metaState.Config.ModsEnabled += Toggle;
}
private void Detour(CharacterUtility* utility, EqdpEntry* entry, uint setId, uint raceCode)
@ -27,4 +28,7 @@ public unsafe class EqdpEquipHook : FastHook<EqdpEquipHook.Delegate>
Penumbra.Log.Excessive(
$"[GetEqdpEquipEntry] Invoked on 0x{(ulong)utility:X} with {setId}, {(GenderRace)raceCode}, returned {(ushort)*entry:B10}.");
}
public void Dispose()
=> _metaState.Config.ModsEnabled -= Toggle;
}

View file

@ -5,7 +5,7 @@ using Penumbra.Interop.PathResolving;
namespace Penumbra.Interop.Hooks.Meta;
public unsafe class EqpHook : FastHook<EqpHook.Delegate>
public unsafe class EqpHook : FastHook<EqpHook.Delegate>, IDisposable
{
public delegate void Delegate(CharacterUtility* utility, EqpEntry* flags, CharacterArmor* armor);
@ -14,7 +14,8 @@ public unsafe class EqpHook : FastHook<EqpHook.Delegate>
public EqpHook(HookManager hooks, MetaState metaState)
{
_metaState = metaState;
Task = hooks.CreateHook<Delegate>("GetEqpFlags", "E8 ?? ?? ?? ?? 0F B6 44 24 ?? C0 E8", Detour, true);
Task = hooks.CreateHook<Delegate>("GetEqpFlags", "E8 ?? ?? ?? ?? 0F B6 44 24 ?? C0 E8", Detour, metaState.Config.EnableMods);
_metaState.Config.ModsEnabled += Toggle;
}
private void Detour(CharacterUtility* utility, EqpEntry* flags, CharacterArmor* armor)
@ -31,4 +32,7 @@ public unsafe class EqpHook : FastHook<EqpHook.Delegate>
Penumbra.Log.Excessive($"[GetEqpFlags] Invoked on 0x{(nint)utility:X} with 0x{(ulong)armor:X}, returned 0x{(ulong)*flags:X16}.");
}
public void Dispose()
=> _metaState.Config.ModsEnabled -= Toggle;
}

View file

@ -6,7 +6,7 @@ using Penumbra.Meta.Manipulations;
namespace Penumbra.Interop.Hooks.Meta;
public class EstHook : FastHook<EstHook.Delegate>
public class EstHook : FastHook<EstHook.Delegate>, IDisposable
{
public delegate EstEntry Delegate(uint id, int estType, uint genderRace);
@ -14,14 +14,16 @@ public class EstHook : FastHook<EstHook.Delegate>
public EstHook(HookManager hooks, MetaState metaState)
{
_metaState = metaState;
Task = hooks.CreateHook<Delegate>("GetEstEntry", "44 8B C9 83 EA ?? 74", Detour, true);
_metaState = metaState;
Task = hooks.CreateHook<Delegate>("GetEstEntry", "44 8B C9 83 EA ?? 74", Detour, metaState.Config.EnableMods);
_metaState.Config.ModsEnabled += Toggle;
}
private EstEntry Detour(uint genderRace, int estType, uint id)
{
EstEntry ret;
if (_metaState.EstCollection.TryPeek(out var collection) && collection is { Valid: true, ModCollection.MetaCache: { } cache }
if (_metaState.EstCollection.TryPeek(out var collection)
&& collection is { Valid: true, ModCollection.MetaCache: { } cache }
&& cache.Est.TryGetValue(Convert(genderRace, estType, id), out var entry))
ret = entry.Entry;
else
@ -46,4 +48,7 @@ public class EstHook : FastHook<EstHook.Delegate>
};
return new EstIdentifier(i, type, gr);
}
public void Dispose()
=> _metaState.Config.ModsEnabled -= Toggle;
}

View file

@ -5,7 +5,7 @@ using Penumbra.Meta.Manipulations;
namespace Penumbra.Interop.Hooks.Meta;
public unsafe class GmpHook : FastHook<GmpHook.Delegate>
public unsafe class GmpHook : FastHook<GmpHook.Delegate>, IDisposable
{
public delegate nint Delegate(nint gmpResource, uint dividedHeadId);
@ -16,7 +16,8 @@ public unsafe class GmpHook : FastHook<GmpHook.Delegate>
public GmpHook(HookManager hooks, MetaState metaState)
{
_metaState = metaState;
Task = hooks.CreateHook<Delegate>("GetGmpEntry", "E8 ?? ?? ?? ?? 48 85 C0 74 ?? 43 8D 0C", Detour, true);
Task = hooks.CreateHook<Delegate>("GetGmpEntry", "E8 ?? ?? ?? ?? 48 85 C0 74 ?? 43 8D 0C", Detour, metaState.Config.EnableMods);
_metaState.Config.ModsEnabled += Toggle;
}
/// <remarks>
@ -27,7 +28,8 @@ public unsafe class GmpHook : FastHook<GmpHook.Delegate>
private nint Detour(nint gmpResource, uint dividedHeadId)
{
nint ret;
if (_metaState.GmpCollection.TryPeek(out var collection) && collection.Collection is { Valid: true, ModCollection.MetaCache: { } cache }
if (_metaState.GmpCollection.TryPeek(out var collection)
&& collection.Collection is { Valid: true, ModCollection.MetaCache: { } cache }
&& cache.Gmp.TryGetValue(new GmpIdentifier(collection.Id), out var entry))
{
if (entry.Entry.Enabled)
@ -61,4 +63,7 @@ public unsafe class GmpHook : FastHook<GmpHook.Delegate>
Marshal.FreeHGlobal((nint)Pointer);
}
}
public void Dispose()
=> _metaState.Config.ModsEnabled -= Toggle;
}

View file

@ -7,7 +7,7 @@ using Penumbra.Meta.Manipulations;
namespace Penumbra.Interop.Hooks.Meta;
public unsafe class RspBustHook : FastHook<RspBustHook.Delegate>
public unsafe class RspBustHook : FastHook<RspBustHook.Delegate>, IDisposable
{
public delegate float* Delegate(nint cmpResource, float* storage, Race race, byte gender, byte isSecondSubRace, byte bodyType,
byte bustSize);
@ -19,7 +19,8 @@ public unsafe class RspBustHook : FastHook<RspBustHook.Delegate>
{
_metaState = metaState;
_metaFileManager = metaFileManager;
Task = hooks.CreateHook<Delegate>("GetRspBust", "E8 ?? ?? ?? ?? F2 0F 10 44 24 ?? 8B 44 24", Detour, true);
Task = hooks.CreateHook<Delegate>("GetRspBust", "E8 ?? ?? ?? ?? F2 0F 10 44 24 ?? 8B 44 24", Detour, metaState.Config.EnableMods);
_metaState.Config.ModsEnabled += Toggle;
}
private float* Detour(nint cmpResource, float* storage, Race race, byte gender, byte isSecondSubRace, byte bodyType, byte bustSize)
@ -63,4 +64,7 @@ public unsafe class RspBustHook : FastHook<RspBustHook.Delegate>
$"[GetRspBust] Invoked on 0x{cmpResource:X} with {race}, {(Gender)(gender + 1)}, {isSecondSubRace == 1}, {bodyType}, {bustSize}, returned {storage[0]}, {storage[1]}, {storage[2]}.");
return ret;
}
public void Dispose()
=> _metaState.Config.ModsEnabled -= Toggle;
}

View file

@ -1,4 +1,3 @@
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using OtterGui.Services;
using Penumbra.GameData.Enums;
using Penumbra.Interop.PathResolving;
@ -8,7 +7,7 @@ using Penumbra.Meta.Manipulations;
namespace Penumbra.Interop.Hooks.Meta;
public class RspHeightHook : FastHook<RspHeightHook.Delegate>
public class RspHeightHook : FastHook<RspHeightHook.Delegate>, IDisposable
{
public delegate float Delegate(nint cmpResource, Race clan, byte gender, byte isSecondSubRace, byte bodyType, byte height);
@ -17,15 +16,18 @@ public class RspHeightHook : FastHook<RspHeightHook.Delegate>
public RspHeightHook(HookManager hooks, MetaState metaState, MetaFileManager metaFileManager)
{
_metaState = metaState;
_metaState = metaState;
_metaFileManager = metaFileManager;
Task = hooks.CreateHook<Delegate>("GetRspHeight", "E8 ?? ?? ?? ?? 48 8B 8E ?? ?? ?? ?? 44 8B CF", Detour, true);
Task = hooks.CreateHook<Delegate>("GetRspHeight", "E8 ?? ?? ?? ?? 48 8B 8E ?? ?? ?? ?? 44 8B CF", Detour, metaState.Config.EnableMods);
_metaState.Config.ModsEnabled += Toggle;
}
private unsafe float Detour(nint cmpResource, Race race, byte gender, byte isSecondSubRace, byte bodyType, byte height)
{
float scale;
if (bodyType < 2 && _metaState.RspCollection.TryPeek(out var collection) && collection is { Valid: true, ModCollection.MetaCache: { } cache })
if (bodyType < 2
&& _metaState.RspCollection.TryPeek(out var collection)
&& collection is { Valid: true, ModCollection.MetaCache: { } cache })
{
var clan = (SubRace)(((int)race - 1) * 2 + 1 + isSecondSubRace);
var (minIdent, maxIdent) = gender == 0
@ -66,4 +68,7 @@ public class RspHeightHook : FastHook<RspHeightHook.Delegate>
$"[GetRspHeight] Invoked on 0x{cmpResource:X} with {race}, {(Gender)(gender + 1)}, {isSecondSubRace == 1}, {bodyType}, {height}, returned {scale}.");
return scale;
}
public void Dispose()
=> _metaState.Config.ModsEnabled -= Toggle;
}

View file

@ -7,7 +7,7 @@ using Penumbra.Meta.Manipulations;
namespace Penumbra.Interop.Hooks.Meta;
public class RspTailHook : FastHook<RspTailHook.Delegate>
public class RspTailHook : FastHook<RspTailHook.Delegate>, IDisposable
{
public delegate float Delegate(nint cmpResource, Race clan, byte gender, byte isSecondSubRace, byte bodyType, byte height);
@ -18,7 +18,8 @@ public class RspTailHook : FastHook<RspTailHook.Delegate>
{
_metaState = metaState;
_metaFileManager = metaFileManager;
Task = hooks.CreateHook<Delegate>("GetRspTail", "E8 ?? ?? ?? ?? 0F 28 F0 48 8B 05", Detour, true);
Task = hooks.CreateHook<Delegate>("GetRspTail", "E8 ?? ?? ?? ?? 0F 28 F0 48 8B 05", Detour, metaState.Config.EnableMods);
_metaState.Config.ModsEnabled += Toggle;
}
private unsafe float Detour(nint cmpResource, Race race, byte gender, byte isSecondSubRace, byte bodyType, byte tailLength)
@ -65,4 +66,7 @@ public class RspTailHook : FastHook<RspTailHook.Delegate>
$"[GetRspTail] Invoked on 0x{cmpResource:X} with {race}, {(Gender)(gender + 1)}, {isSecondSubRace == 1}, {bodyType}, {tailLength}, returned {scale}.");
return scale;
}
public void Dispose()
=> _metaState.Config.ModsEnabled -= Toggle;
}

View file

@ -37,7 +37,7 @@ namespace Penumbra.Interop.PathResolving;
// GMP Entries seem to be only used by "48 8B ?? 53 55 57 48 83 ?? ?? 48 8B", which is SetupVisor.
public sealed unsafe class MetaState : IDisposable, IService
{
private readonly Configuration _config;
public readonly Configuration Config;
private readonly CommunicatorService _communicator;
private readonly CollectionResolver _collectionResolver;
private readonly ResourceLoader _resources;
@ -64,7 +64,7 @@ public sealed unsafe class MetaState : IDisposable, IService
_resources = resources;
_createCharacterBase = createCharacterBase;
_characterUtility = characterUtility;
_config = config;
Config = config;
_createCharacterBase.Subscribe(OnCreatingCharacterBase, CreateCharacterBase.Priority.MetaState);
_createCharacterBase.Subscribe(OnCharacterBaseCreated, CreateCharacterBase.PostEvent.Priority.MetaState);
}
@ -84,7 +84,7 @@ public sealed unsafe class MetaState : IDisposable, IService
}
public DecalReverter ResolveDecal(ResolveData resolve, bool which)
=> new(_config, _characterUtility, _resources, resolve, which);
=> new(Config, _characterUtility, _resources, resolve, which);
public void Dispose()
{
@ -99,7 +99,7 @@ public sealed unsafe class MetaState : IDisposable, IService
_communicator.CreatingCharacterBase.Invoke(_lastCreatedCollection.AssociatedGameObject,
_lastCreatedCollection.ModCollection.Id, (nint)modelCharaId, (nint)customize, (nint)equipData);
var decal = new DecalReverter(_config, _characterUtility, _resources, _lastCreatedCollection,
var decal = new DecalReverter(Config, _characterUtility, _resources, _lastCreatedCollection,
UsesDecal(*(uint*)modelCharaId, (nint)customize));
RspCollection.Push(_lastCreatedCollection);
_characterBaseCreateMetaChanges.Dispose(); // Should always be empty.