diff --git a/README.md b/README.md index ba29d335..e9f8e50a 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,6 @@ _VFX, animation, sound, and physics editing plugin for Dalamud_ > Just want to hide certain VFXs? Use [EasyEyes](https://github.com/0ceal0t/EasyEyes) instead -### DT TODO -- [ ] Offsets -- [ ] Test Lua actor table -- [ ] Double-Check new files -- [ ] Update stain -- [ ] Update tile textures -- [ ] Timeline to action - ### Supported File Types | Extension | Description | diff --git a/VFXEditor/Formats/MtrlFormat/MtrlManager.cs b/VFXEditor/Formats/MtrlFormat/MtrlManager.cs index 075ef498..00eb99db 100644 --- a/VFXEditor/Formats/MtrlFormat/MtrlManager.cs +++ b/VFXEditor/Formats/MtrlFormat/MtrlManager.cs @@ -35,8 +35,13 @@ public MtrlManager() : base( "Mtrl Editor", "Mtrl" ) { // Tiling textures // TODO - // TileDiffuseFile = Dalamud.DataManager.GetFile( "chara/common/texture/tile_orb_array.tex" ); - // TileNormalFile = Dalamud.DataManager.GetFile( "chara/common/texture/tile_norm_array.tex" ); + try { + TileDiffuseFile = Dalamud.DataManager.GetFile( "chara/common/texture/tile_orb_array.tex" ); + TileNormalFile = Dalamud.DataManager.GetFile( "chara/common/texture/tile_norm_array.tex" ); + } + catch( Exception e ) { + Dalamud.Error( e, "Error loading files" ); + } // the G buffer shader only uses red and green from the normal map // but all 4 channels from the "orb" map diff --git a/VFXEditor/Interop/Constants.cs b/VFXEditor/Interop/Constants.cs index feac4dde..b6fb5d17 100644 --- a/VFXEditor/Interop/Constants.cs +++ b/VFXEditor/Interop/Constants.cs @@ -43,9 +43,9 @@ public static class Constants { public const int PrepPapOffset = 105; - public const byte PrepPapValue = 0xec; + public const byte PrepPapValue = 0xEC; - // https://github.com/xivdev/Penumbra/blob/master/Penumbra.GameData/Offsets.cs#L18 + // https://github.com/Ottermandias/Penumbra.GameData/blob/main/Offsets.cs public const int GetGameObjectIdxVfunc = 28; @@ -72,11 +72,5 @@ public static class Constants { public const string PlaySoundSig = "E8 ?? ?? ?? ?? E9 ?? ?? ?? ?? FE C2"; public const string InitSoundSig = "E8 ?? ?? ?? ?? 8B 5D 77"; - - // https://github.com/Ottermandias/Penumbra.GameData/blob/main/Offsets.cs - - public const int ResourceHandleGetDataVfunc = 23; - - public const int ResourceHandleGetLengthVfunc = 17; } } diff --git a/VFXEditor/Interop/Penumbra/PenumbraIpc.cs b/VFXEditor/Interop/Penumbra/PenumbraIpc.cs index 861e0ab2..66d33bee 100644 --- a/VFXEditor/Interop/Penumbra/PenumbraIpc.cs +++ b/VFXEditor/Interop/Penumbra/PenumbraIpc.cs @@ -98,8 +98,8 @@ private void DisablePenumbra() { } public void Dispose() { - InitializedSubscriber.Dispose(); - DisposedSubscriber.Dispose(); + InitializedSubscriber?.Dispose(); + DisposedSubscriber?.Dispose(); } // https://github.com/Ottermandias/OtterGui/blob/4673e93f5165108a7f5b91236406d527f16384a5/Functions.cs#L154 diff --git a/VFXEditor/Interop/ResourceLoader.Replace.cs b/VFXEditor/Interop/ResourceLoader.Replace.cs index d6dac88c..588c7967 100644 --- a/VFXEditor/Interop/ResourceLoader.Replace.cs +++ b/VFXEditor/Interop/ResourceLoader.Replace.cs @@ -111,6 +111,11 @@ bool isUnknown } private byte ReadSqpackDetour( IntPtr fileHandler, SeFileDescriptor* fileDesc, int priority, bool isSync ) { + if( fileDesc->ResourceHandle == null ) { + Dalamud.Error( $"Invalid File Descriptor {( nint )fileDesc:X4}" ); + return ReadSqpackHook.Original( fileHandler, fileDesc, priority, isSync ); + } + if( !fileDesc->ResourceHandle->GamePath( out var originalGamePath ) ) { return ReadSqpackHook.Original( fileHandler, fileDesc, priority, isSync ); } diff --git a/VFXEditor/Interop/ResourceLoader.Utils.cs b/VFXEditor/Interop/ResourceLoader.Utils.cs index 8bc1d8bf..6c775883 100644 --- a/VFXEditor/Interop/ResourceLoader.Utils.cs +++ b/VFXEditor/Interop/ResourceLoader.Utils.cs @@ -1,3 +1,4 @@ +using Dalamud.Hooking; using FFXIVClientStructs.FFXIV.Client.Game.Object; using Penumbra.String; using System; @@ -45,6 +46,19 @@ private enum RedrawState { private readonly RequestFileDelegate RequestFile; + // ======== FOR DEBUGGING ============= + + public delegate void* RequestFilePrototype( IntPtr a1, IntPtr a2, IntPtr a3, byte a4 ); + + public Hook RequestFileHook { get; private set; } + + private void* RequestFileDetour( IntPtr a1, IntPtr a2, IntPtr a3, byte a4 ) { + if( Plugin.Configuration?.LogDebug == true ) Dalamud.Log( $"[RequestFile] {a1:X4} {a2:X4} {a3:X4} {a4}" ); + return RequestFileHook.Original( a1, a2, a3, a4 ); + } + + // ====================== + public void ReRender() { if( CurrentRedrawState != RedrawState.None || Plugin.PlayerObject == null ) return; CurrentRedrawState = RedrawState.Start; diff --git a/VFXEditor/Interop/ResourceLoader.cs b/VFXEditor/Interop/ResourceLoader.cs index ec434000..714614de 100644 --- a/VFXEditor/Interop/ResourceLoader.cs +++ b/VFXEditor/Interop/ResourceLoader.cs @@ -30,6 +30,7 @@ public ResourceLoader() { GetFileManager2 = Marshal.GetDelegateForFunctionPointer( Dalamud.SigScanner.ScanText( Constants.GetFileManager2Sig ) ); DecRef = Marshal.GetDelegateForFunctionPointer( Dalamud.SigScanner.ScanText( Constants.DecRefSig ) ); RequestFile = Marshal.GetDelegateForFunctionPointer( Dalamud.SigScanner.ScanText( Constants.RequestFileSig ) ); + RequestFileHook = Dalamud.Hooks.HookFromSignature( Constants.RequestFileSig, RequestFileDetour ); CheckFileStateHook = Dalamud.Hooks.HookFromSignature( Constants.CheckFileStateSig, CheckFileStateDetour ); LoadTexFileLocal = Marshal.GetDelegateForFunctionPointer( Dalamud.SigScanner.ScanText( Constants.LoadTexFileLocalSig ) ); @@ -79,6 +80,7 @@ public ResourceLoader() { PlayActionHook.Enable(); VfxUseTriggerHook.Enable(); InitSoundHook.Enable(); + RequestFileHook.Enable(); PathResolved += AddCrc; } @@ -97,6 +99,7 @@ public void Dispose() { LoadMdlFileExternHook.Dispose(); PlayActionHook.Dispose(); VfxUseTriggerHook.Dispose(); + RequestFileHook.Dispose(); InitSoundHook.Dispose(); } } diff --git a/VFXEditor/Interop/Structs/ResourceHandle.cs b/VFXEditor/Interop/Structs/ResourceHandle.cs index 7a5a13b9..fc26ff90 100644 --- a/VFXEditor/Interop/Structs/ResourceHandle.cs +++ b/VFXEditor/Interop/Structs/ResourceHandle.cs @@ -80,36 +80,5 @@ public bool GamePath( out Utf8GamePath path ) [FieldOffset( 0xAC )] public uint RefCount; - - // May return null. - public static byte* GetData( ResourceHandle* handle ) - => ( ( delegate* unmanaged< ResourceHandle*, byte* > )handle->VTable[Constants.ResourceHandleGetDataVfunc] )( handle ); - - public static ulong GetLength( ResourceHandle* handle ) - => ( ( delegate* unmanaged< ResourceHandle*, ulong > )handle->VTable[Constants.ResourceHandleGetLengthVfunc] )( handle ); - - - // Only use these if you know what you are doing. - // Those are actually only sure to be accessible for DefaultResourceHandles. - [FieldOffset( 0xB0 )] - public DataIndirection* Data; - - [FieldOffset( 0xB8 )] - public uint DataLength; - - public (IntPtr Data, int Length) GetData() - => Data != null - ? (( IntPtr )Data->DataPtr, ( int )Data->DataLength) - : (IntPtr.Zero, 0); - - public bool SetData( IntPtr data, int length ) { - if( Data == null ) - return false; - - Data->DataPtr = length != 0 ? ( byte* )data : null; - Data->DataLength = ( ulong )length; - DataLength = ( uint )length; - return true; - } } } \ No newline at end of file diff --git a/VFXEditor/Interop/Structs/SeFileDescriptor.cs b/VFXEditor/Interop/Structs/SeFileDescriptor.cs index 9ccfa169..cfa9e013 100644 --- a/VFXEditor/Interop/Structs/SeFileDescriptor.cs +++ b/VFXEditor/Interop/Structs/SeFileDescriptor.cs @@ -1,4 +1,3 @@ -using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle; using System.Runtime.InteropServices; namespace VfxEditor.Structs { @@ -8,12 +7,12 @@ public unsafe struct SeFileDescriptor { public FileMode FileMode; [FieldOffset( 0x30 )] - public void* FileDescriptor; // + public void* FileDescriptor; [FieldOffset( 0x50 )] - public ResourceHandle* ResourceHandle; // + public ResourceHandle* ResourceHandle; [FieldOffset( 0x70 )] - public char Utf16FileName; // + public char Utf16FileName; } } \ No newline at end of file