Skip to content

Commit

Permalink
Fix accessory VFX change not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Oct 6, 2024
1 parent df0526e commit 740816f
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions Penumbra/Interop/Hooks/Resources/ResolvePathHooksBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using OtterGui.Services;
using Penumbra.Collections;
using Penumbra.GameData.Enums;
using Penumbra.GameData.Structs;
using Penumbra.Interop.PathResolving;

namespace Penumbra.Interop.Hooks.Resources;
Expand Down Expand Up @@ -212,25 +214,39 @@ private nint ResolveSkpHuman(nint drawObject, nint pathBuffer, nint pathBufferSi
return ret;
}

[StructLayout(LayoutKind.Explicit)]
private struct ChangedEquipData
{
[FieldOffset(0)]
public PrimaryId Model;

[FieldOffset(2)]
public Variant Variant;

[FieldOffset(20)]
public ushort VfxId;

[FieldOffset(22)]
public GenderRace GenderRace;
}

private nint ResolveVfxHuman(nint drawObject, nint pathBuffer, nint pathBufferSize, uint slotIndex, nint unkOutParam)
{
if (slotIndex is <= 4 or >= 10)
return ResolveVfx(drawObject, pathBuffer, pathBufferSize, slotIndex, unkOutParam);

var changedEquipData = ((Human*)drawObject)->ChangedEquipData;
var changedEquipData = (ChangedEquipData*)((Human*)drawObject)->ChangedEquipData;
// Enable vfxs for accessories
if (changedEquipData == null)
return ResolveVfx(drawObject, pathBuffer, pathBufferSize, slotIndex, unkOutParam);

var slot = (ushort*)(changedEquipData + 12 * (nint)slotIndex);
var model = slot[0];
var variant = slot[1];
var vfxId = slot[4];
ref var slot = ref changedEquipData[slotIndex];

if (model == 0 || variant == 0 || vfxId == 0)
if (slot.Model == 0 || slot.Variant == 0 || slot.VfxId == 0)
return ResolveVfx(drawObject, pathBuffer, pathBufferSize, slotIndex, unkOutParam);

if (!Utf8.TryWrite(new Span<byte>((void*)pathBuffer, (int)pathBufferSize), $"chara/accessory/a{model:D4}/vfx/eff/va{vfxId:D4}.avfx\0",
if (!Utf8.TryWrite(new Span<byte>((void*)pathBuffer, (int)pathBufferSize),
$"chara/accessory/a{slot.Model.Id:D4}/vfx/eff/va{slot.VfxId:D4}.avfx\0",
out _))
return ResolveVfx(drawObject, pathBuffer, pathBufferSize, slotIndex, unkOutParam);

Expand Down

0 comments on commit 740816f

Please sign in to comment.