Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0ceal0t committed Jul 5, 2024
1 parent 16ae60f commit fba68bc
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 55 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
9 changes: 7 additions & 2 deletions VFXEditor/Formats/MtrlFormat/MtrlManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ public MtrlManager() : base( "Mtrl Editor", "Mtrl" ) {

// Tiling textures
// TODO
// TileDiffuseFile = Dalamud.DataManager.GetFile<TextureDataFile>( "chara/common/texture/tile_orb_array.tex" );
// TileNormalFile = Dalamud.DataManager.GetFile<TextureDataFile>( "chara/common/texture/tile_norm_array.tex" );
try {
TileDiffuseFile = Dalamud.DataManager.GetFile<TextureDataFile>( "chara/common/texture/tile_orb_array.tex" );
TileNormalFile = Dalamud.DataManager.GetFile<TextureDataFile>( "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
Expand Down
10 changes: 2 additions & 8 deletions VFXEditor/Interop/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions VFXEditor/Interop/Penumbra/PenumbraIpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions VFXEditor/Interop/ResourceLoader.Replace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
14 changes: 14 additions & 0 deletions VFXEditor/Interop/ResourceLoader.Utils.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Dalamud.Hooking;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using Penumbra.String;
using System;
Expand Down Expand Up @@ -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<RequestFilePrototype> 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;
Expand Down
3 changes: 3 additions & 0 deletions VFXEditor/Interop/ResourceLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public ResourceLoader() {
GetFileManager2 = Marshal.GetDelegateForFunctionPointer<GetFileManagerDelegate>( Dalamud.SigScanner.ScanText( Constants.GetFileManager2Sig ) );
DecRef = Marshal.GetDelegateForFunctionPointer<DecRefDelegate>( Dalamud.SigScanner.ScanText( Constants.DecRefSig ) );
RequestFile = Marshal.GetDelegateForFunctionPointer<RequestFileDelegate>( Dalamud.SigScanner.ScanText( Constants.RequestFileSig ) );
RequestFileHook = Dalamud.Hooks.HookFromSignature<RequestFilePrototype>( Constants.RequestFileSig, RequestFileDetour );

CheckFileStateHook = Dalamud.Hooks.HookFromSignature<CheckFileStateDelegate>( Constants.CheckFileStateSig, CheckFileStateDetour );
LoadTexFileLocal = Marshal.GetDelegateForFunctionPointer<LoadTexFileLocalDelegate>( Dalamud.SigScanner.ScanText( Constants.LoadTexFileLocalSig ) );
Expand Down Expand Up @@ -79,6 +80,7 @@ public ResourceLoader() {
PlayActionHook.Enable();
VfxUseTriggerHook.Enable();
InitSoundHook.Enable();
RequestFileHook.Enable();
PathResolved += AddCrc;
}

Expand All @@ -97,6 +99,7 @@ public void Dispose() {
LoadMdlFileExternHook.Dispose();
PlayActionHook.Dispose();
VfxUseTriggerHook.Dispose();
RequestFileHook.Dispose();
InitSoundHook.Dispose();
}
}
Expand Down
31 changes: 0 additions & 31 deletions VFXEditor/Interop/Structs/ResourceHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
7 changes: 3 additions & 4 deletions VFXEditor/Interop/Structs/SeFileDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle;
using System.Runtime.InteropServices;

namespace VfxEditor.Structs {
Expand All @@ -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;
}
}

0 comments on commit fba68bc

Please sign in to comment.