mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
spoiler alert: its still fucking broken
This commit is contained in:
parent
2c42c15e4e
commit
fbb39a8626
3 changed files with 73 additions and 39 deletions
4
.idea/.idea.Penumbra/.idea/riderModule.iml
generated
4
.idea/.idea.Penumbra/.idea/riderModule.iml
generated
|
|
@ -1,6 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module version="4">
|
<module version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$USER_HOME$/.nuget/packages/reloaded.assembler/1.0.9/build/FASM-LICENSE.TXT" />
|
||||||
|
<content url="file://$USER_HOME$/.nuget/packages/reloaded.assembler/1.0.9/build/FASM.DLL" />
|
||||||
|
<content url="file://$USER_HOME$/.nuget/packages/reloaded.assembler/1.0.9/build/FASMX64.DLL" />
|
||||||
|
<content url="file://$USER_HOME$/.nuget/packages/reloaded.assembler/1.0.9/build/Reloaded.Assembler.targets" />
|
||||||
<content url="file://$MODULE_DIR$/../.." />
|
<content url="file://$MODULE_DIR$/../.." />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
||||||
|
|
@ -51,5 +51,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DotNetZip" Version="1.13.8" />
|
<PackageReference Include="DotNetZip" Version="1.13.8" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
|
<PackageReference Include="Reloaded.Hooks" Version="2.4.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -2,12 +2,13 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Dalamud.Hooking;
|
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Penumbra.Structs;
|
using Penumbra.Structs;
|
||||||
using Penumbra.Util;
|
using Penumbra.Util;
|
||||||
using FileMode = Penumbra.Structs.FileMode;
|
using FileMode = Penumbra.Structs.FileMode;
|
||||||
using Penumbra.Extensions;
|
using Reloaded.Hooks;
|
||||||
|
using Reloaded.Hooks.Definitions;
|
||||||
|
using Reloaded.Hooks.Definitions.X64;
|
||||||
|
|
||||||
namespace Penumbra
|
namespace Penumbra
|
||||||
{
|
{
|
||||||
|
|
@ -21,25 +22,31 @@ namespace Penumbra
|
||||||
|
|
||||||
|
|
||||||
// Delegate prototypes
|
// Delegate prototypes
|
||||||
|
[Function( CallingConventions.Microsoft )]
|
||||||
public unsafe delegate byte ReadFilePrototype( IntPtr pFileHandler, SeFileDescriptor* pFileDesc, int priority, bool isSync );
|
public unsafe delegate byte ReadFilePrototype( IntPtr pFileHandler, SeFileDescriptor* pFileDesc, int priority, bool isSync );
|
||||||
|
|
||||||
|
[Function( CallingConventions.Microsoft )]
|
||||||
public unsafe delegate byte ReadSqpackPrototype( IntPtr pFileHandler, SeFileDescriptor* pFileDesc, int priority, bool isSync );
|
public unsafe delegate byte ReadSqpackPrototype( IntPtr pFileHandler, SeFileDescriptor* pFileDesc, int priority, bool isSync );
|
||||||
|
|
||||||
|
[Function( CallingConventions.Microsoft )]
|
||||||
public unsafe delegate void* GetResourceSyncPrototype( IntPtr pFileManager, uint* pCategoryId, char* pResourceType,
|
public unsafe delegate void* GetResourceSyncPrototype( IntPtr pFileManager, uint* pCategoryId, char* pResourceType,
|
||||||
uint* pResourceHash, char* pPath, void* pUnknown );
|
uint* pResourceHash, char* pPath, void* pUnknown );
|
||||||
|
|
||||||
|
[Function( CallingConventions.Microsoft )]
|
||||||
public unsafe delegate void* GetResourceAsyncPrototype( IntPtr pFileManager, uint* pCategoryId, char* pResourceType,
|
public unsafe delegate void* GetResourceAsyncPrototype( IntPtr pFileManager, uint* pCategoryId, char* pResourceType,
|
||||||
uint* pResourceHash, char* pPath, void* pUnknown, bool isUnknown );
|
uint* pResourceHash, char* pPath, void* pUnknown, bool isUnknown );
|
||||||
|
|
||||||
|
[Function( CallingConventions.Microsoft )]
|
||||||
public unsafe delegate void* LoadPlayerResourcesPrototype( IntPtr pResourceManager );
|
public unsafe delegate void* LoadPlayerResourcesPrototype( IntPtr pResourceManager );
|
||||||
|
|
||||||
|
[Function( CallingConventions.Microsoft )]
|
||||||
public unsafe delegate void* UnloadPlayerResourcesPrototype( IntPtr pResourceManager );
|
public unsafe delegate void* UnloadPlayerResourcesPrototype( IntPtr pResourceManager );
|
||||||
|
|
||||||
|
|
||||||
// Hooks
|
// Hooks
|
||||||
public Hook< GetResourceSyncPrototype > GetResourceSyncHook { get; private set; }
|
public IHook< GetResourceSyncPrototype > GetResourceSyncHook { get; private set; }
|
||||||
public Hook< GetResourceAsyncPrototype > GetResourceAsyncHook { get; private set; }
|
public IHook< GetResourceAsyncPrototype > GetResourceAsyncHook { get; private set; }
|
||||||
public Hook< ReadSqpackPrototype > ReadSqpackHook { get; private set; }
|
public IHook< ReadSqpackPrototype > ReadSqpackHook { get; private set; }
|
||||||
|
|
||||||
// Unmanaged functions
|
// Unmanaged functions
|
||||||
public ReadFilePrototype ReadFile { get; private set; }
|
public ReadFilePrototype ReadFile { get; private set; }
|
||||||
|
|
@ -79,9 +86,9 @@ namespace Penumbra
|
||||||
scanner.ScanText( "E8 ?? ?? ?? 00 48 8B D8 EB ?? F0 FF 83 ?? ?? 00 00" );
|
scanner.ScanText( "E8 ?? ?? ?? 00 48 8B D8 EB ?? F0 FF 83 ?? ?? 00 00" );
|
||||||
|
|
||||||
|
|
||||||
ReadSqpackHook = new Hook< ReadSqpackPrototype >( readSqpackAddress, new ReadSqpackPrototype( ReadSqpackHandler ) );
|
ReadSqpackHook = new Hook< ReadSqpackPrototype >( ReadSqpackHandler, ( long )readSqpackAddress );
|
||||||
GetResourceSyncHook = new Hook< GetResourceSyncPrototype >( getResourceSyncAddress, new GetResourceSyncPrototype( GetResourceSyncHandler ) );
|
GetResourceSyncHook = new Hook< GetResourceSyncPrototype >( GetResourceSyncHandler, ( long )getResourceSyncAddress );
|
||||||
GetResourceAsyncHook = new Hook< GetResourceAsyncPrototype >( getResourceAsyncAddress, new GetResourceAsyncPrototype( GetResourceAsyncHandler ) );
|
GetResourceAsyncHook = new Hook< GetResourceAsyncPrototype >( GetResourceAsyncHandler, ( long )getResourceAsyncAddress );
|
||||||
|
|
||||||
ReadFile = Marshal.GetDelegateForFunctionPointer< ReadFilePrototype >( readFileAddress );
|
ReadFile = Marshal.GetDelegateForFunctionPointer< ReadFilePrototype >( readFileAddress );
|
||||||
|
|
||||||
|
|
@ -101,28 +108,54 @@ namespace Penumbra
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public unsafe void* GetResourceSyncHandler( IntPtr pFileManager, uint* pCategoryId,
|
private unsafe void* GetResourceSyncHandler(
|
||||||
char* pResourceType, uint* pResourceHash, char* pPath, void* pUnknown )
|
IntPtr pFileManager,
|
||||||
{
|
uint* pCategoryId,
|
||||||
return GetResourceHandler( true, pFileManager, pCategoryId, pResourceType,
|
char* pResourceType,
|
||||||
pResourceHash, pPath, pUnknown, false );
|
uint* pResourceHash,
|
||||||
}
|
char* pPath,
|
||||||
|
void* pUnknown
|
||||||
|
) => GetResourceHandler( true, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, false );
|
||||||
|
|
||||||
public unsafe void* GetResourceAsyncHandler( IntPtr pFileManager, uint* pCategoryId,
|
private unsafe void* GetResourceAsyncHandler(
|
||||||
char* pResourceType, uint* pResourceHash, char* pPath, void* pUnknown, bool isUnknown )
|
IntPtr pFileManager,
|
||||||
{
|
uint* pCategoryId,
|
||||||
return GetResourceHandler( false, pFileManager, pCategoryId, pResourceType,
|
char* pResourceType,
|
||||||
pResourceHash, pPath, pUnknown, isUnknown );
|
uint* pResourceHash,
|
||||||
}
|
char* pPath,
|
||||||
|
void* pUnknown,
|
||||||
|
bool isUnknown
|
||||||
|
) => GetResourceHandler( false, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
|
||||||
|
|
||||||
private unsafe void* GetResourceHandler( bool isSync, IntPtr pFileManager, uint* pCategoryId,
|
private unsafe void* CallOriginalHandler(
|
||||||
char* pResourceType, uint* pResourceHash, char* pPath, void* pUnknown, bool isUnknown )
|
bool isSync,
|
||||||
|
IntPtr pFileManager,
|
||||||
|
uint* pCategoryId,
|
||||||
|
char* pResourceType,
|
||||||
|
uint* pResourceHash,
|
||||||
|
char* pPath,
|
||||||
|
void* pUnknown,
|
||||||
|
bool isUnknown
|
||||||
|
) => isSync
|
||||||
|
? GetResourceSyncHook.OriginalFunction( pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown )
|
||||||
|
: GetResourceAsyncHook.OriginalFunction( pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
|
||||||
|
|
||||||
|
private unsafe void* GetResourceHandler(
|
||||||
|
bool isSync,
|
||||||
|
IntPtr pFileManager,
|
||||||
|
uint* pCategoryId,
|
||||||
|
char* pResourceType,
|
||||||
|
uint* pResourceHash,
|
||||||
|
char* pPath,
|
||||||
|
void* pUnknown,
|
||||||
|
bool isUnknown
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var gameFsPath = Marshal.PtrToStringAnsi( new IntPtr( pPath ) );
|
var gameFsPath = Marshal.PtrToStringAnsi( new IntPtr( pPath ) );
|
||||||
|
|
||||||
if( LogAllFiles )
|
if( LogAllFiles )
|
||||||
{
|
{
|
||||||
PluginLog.Log( "[ReadSqPack] {0}", gameFsPath );
|
PluginLog.Log( "[GetResourceHandler] {0}", gameFsPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
var candidate = Plugin.ModManager.GetCandidateForGameFile( gameFsPath );
|
var candidate = Plugin.ModManager.GetCandidateForGameFile( gameFsPath );
|
||||||
|
|
@ -130,11 +163,7 @@ namespace Penumbra
|
||||||
// path must be < 260 because statically defined array length :(
|
// path must be < 260 because statically defined array length :(
|
||||||
if( candidate == null || candidate.FullName.Length >= 260 || !candidate.Exists )
|
if( candidate == null || candidate.FullName.Length >= 260 || !candidate.Exists )
|
||||||
{
|
{
|
||||||
return isSync
|
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
|
||||||
? GetResourceSyncHook.Original( pFileManager, pCategoryId, pResourceType,
|
|
||||||
pResourceHash, pPath, pUnknown )
|
|
||||||
: GetResourceAsyncHook.Original( pFileManager, pCategoryId, pResourceType,
|
|
||||||
pResourceHash, pPath, pUnknown, isUnknown );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var cleanPath = candidate.FullName.Replace( '\\', '/' );
|
var cleanPath = candidate.FullName.Replace( '\\', '/' );
|
||||||
|
|
@ -148,15 +177,11 @@ namespace Penumbra
|
||||||
Crc32.Update( asciiPath );
|
Crc32.Update( asciiPath );
|
||||||
*pResourceHash = Crc32.Checksum;
|
*pResourceHash = Crc32.Checksum;
|
||||||
|
|
||||||
return isSync
|
return CallOriginalHandler( isSync, pFileManager, pCategoryId, pResourceType, pResourceHash, pPath, pUnknown, isUnknown );
|
||||||
? GetResourceSyncHook.Original( pFileManager, pCategoryId, pResourceType,
|
|
||||||
pResourceHash, pPath, pUnknown )
|
|
||||||
: GetResourceAsyncHook.Original( pFileManager, pCategoryId, pResourceType,
|
|
||||||
pResourceHash, pPath, pUnknown, isUnknown );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public unsafe byte ReadSqpackHandler( IntPtr pFileHandler, SeFileDescriptor* pFileDesc, int priority, bool isSync )
|
private unsafe byte ReadSqpackHandler( IntPtr pFileHandler, SeFileDescriptor* pFileDesc, int priority, bool isSync )
|
||||||
{
|
{
|
||||||
var gameFsPath = Marshal.PtrToStringAnsi( new IntPtr( pFileDesc->ResourceHandle->FileName ) );
|
var gameFsPath = Marshal.PtrToStringAnsi( new IntPtr( pFileDesc->ResourceHandle->FileName ) );
|
||||||
|
|
||||||
|
|
@ -164,7 +189,7 @@ namespace Penumbra
|
||||||
|
|
||||||
if( gameFsPath == null || gameFsPath.Length >= 260 || !isRooted )
|
if( gameFsPath == null || gameFsPath.Length >= 260 || !isRooted )
|
||||||
{
|
{
|
||||||
return ReadSqpackHook.Original( pFileHandler, pFileDesc, priority, isSync );
|
return ReadSqpackHook.OriginalFunction( pFileHandler, pFileDesc, priority, isSync );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|
@ -197,6 +222,10 @@ namespace Penumbra
|
||||||
if( IsEnabled )
|
if( IsEnabled )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ReadSqpackHook.Activate();
|
||||||
|
GetResourceSyncHook.Activate();
|
||||||
|
GetResourceAsyncHook.Activate();
|
||||||
|
|
||||||
ReadSqpackHook.Enable();
|
ReadSqpackHook.Enable();
|
||||||
GetResourceSyncHook.Enable();
|
GetResourceSyncHook.Enable();
|
||||||
GetResourceAsyncHook.Enable();
|
GetResourceAsyncHook.Enable();
|
||||||
|
|
@ -221,9 +250,9 @@ namespace Penumbra
|
||||||
if( IsEnabled )
|
if( IsEnabled )
|
||||||
Disable();
|
Disable();
|
||||||
|
|
||||||
ReadSqpackHook.Dispose();
|
// ReadSqpackHook.Disable();
|
||||||
GetResourceSyncHook.Dispose();
|
// GetResourceSyncHook.Disable();
|
||||||
GetResourceAsyncHook.Dispose();
|
// GetResourceAsyncHook.Disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue