Some cleanup and add option to disable skin material attribute scanning.

This commit is contained in:
Ottermandias 2025-08-18 15:41:10 +02:00
parent 83a36ed4cb
commit 23257f94a4
4 changed files with 23 additions and 18 deletions

View file

@ -2,5 +2,6 @@ namespace Penumbra;
public class DebugConfiguration public class DebugConfiguration
{ {
public static bool WriteImcBytesToLog = false; public static bool WriteImcBytesToLog = false;
public static bool UseSkinMaterialProcessing = true;
} }

View file

@ -162,7 +162,7 @@ public sealed unsafe class ResolvePathHooksBase : IDisposable
private nint ResolveSkinMtrl(nint drawObject, nint pathBuffer, nint pathBufferSize, uint slotIndex) private nint ResolveSkinMtrl(nint drawObject, nint pathBuffer, nint pathBufferSize, uint slotIndex)
{ {
var finalPathBuffer = _resolveSkinMtrlPathHook.Original(drawObject, pathBuffer, pathBufferSize, slotIndex); var finalPathBuffer = _resolveSkinMtrlPathHook.Original(drawObject, pathBuffer, pathBufferSize, slotIndex);
if (finalPathBuffer != 0 && finalPathBuffer == pathBuffer) if (DebugConfiguration.UseSkinMaterialProcessing && finalPathBuffer != nint.Zero && finalPathBuffer == pathBuffer)
SkinMtrlPathEarlyProcessing.Process(new Span<byte>((void*)pathBuffer, (int)pathBufferSize), (CharacterBase*)drawObject, slotIndex); SkinMtrlPathEarlyProcessing.Process(new Span<byte>((void*)pathBuffer, (int)pathBufferSize), (CharacterBase*)drawObject, slotIndex);
return ResolvePath(drawObject, finalPathBuffer); return ResolvePath(drawObject, finalPathBuffer);

View file

@ -7,7 +7,7 @@ public static unsafe class SkinMtrlPathEarlyProcessing
{ {
public static void Process(Span<byte> path, CharacterBase* character, uint slotIndex) public static void Process(Span<byte> path, CharacterBase* character, uint slotIndex)
{ {
var end = path.IndexOf(".mtrl\0"u8); var end = path.IndexOf(MaterialExtension());
if (end < 0) if (end < 0)
return; return;
@ -23,16 +23,22 @@ public static unsafe class SkinMtrlPathEarlyProcessing
if (skinSuffix.IsEmpty || skinSuffix.Length > path.Length - suffixPos - 7) if (skinSuffix.IsEmpty || skinSuffix.Length > path.Length - suffixPos - 7)
return; return;
skinSuffix.CopyTo(path[(suffixPos + 1)..]); ++suffixPos;
".mtrl\0"u8.CopyTo(path[(suffixPos + 1 + skinSuffix.Length)..]); skinSuffix.CopyTo(path[suffixPos..]);
suffixPos += skinSuffix.Length;
MaterialExtension().CopyTo(path[suffixPos..]);
return;
static ReadOnlySpan<byte> MaterialExtension()
=> ".mtrl\0"u8;
} }
private static ModelResourceHandle* GetModelResourceHandle(CharacterBase* character, uint slotIndex) private static ModelResourceHandle* GetModelResourceHandle(CharacterBase* character, uint slotIndex)
{ {
if (character == null) if (character is null)
return null; return null;
if (character->TempSlotData != null) if (character->TempSlotData is not null)
{ {
// TODO ClientStructs-ify // TODO ClientStructs-ify
var handle = *(ModelResourceHandle**)((nint)character->TempSlotData + 0xE0 * slotIndex + 0x8); var handle = *(ModelResourceHandle**)((nint)character->TempSlotData + 0xE0 * slotIndex + 0x8);
@ -41,10 +47,7 @@ public static unsafe class SkinMtrlPathEarlyProcessing
} }
var model = character->Models[slotIndex]; var model = character->Models[slotIndex];
if (model == null) return model is null ? null : model->ModelResourceHandle;
return null;
return model->ModelResourceHandle;
} }
private static ReadOnlySpan<byte> GetSkinSuffix(ModelResourceHandle* handle) private static ReadOnlySpan<byte> GetSkinSuffix(ModelResourceHandle* handle)

View file

@ -6,10 +6,11 @@ public static class DebugConfigurationDrawer
{ {
public static void Draw() public static void Draw()
{ {
using var id = ImUtf8.CollapsingHeaderId("Debug Logging Options"u8); using var id = ImUtf8.CollapsingHeaderId("Debugging Options"u8);
if (!id) if (!id)
return; return;
ImUtf8.Checkbox("Log IMC File Replacements"u8, ref DebugConfiguration.WriteImcBytesToLog); ImUtf8.Checkbox("Log IMC File Replacements"u8, ref DebugConfiguration.WriteImcBytesToLog);
ImUtf8.Checkbox("Scan for Skin Material Attributes"u8, ref DebugConfiguration.UseSkinMaterialProcessing);
} }
} }