mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Rename GameResourceManagement, add some output
This commit is contained in:
parent
041485cad4
commit
940f1fbb3d
11 changed files with 65 additions and 34 deletions
|
|
@ -2,11 +2,12 @@ using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Dalamud.Logging;
|
using Dalamud.Logging;
|
||||||
using Penumbra.Structs;
|
using Penumbra.Structs;
|
||||||
|
using Penumbra.Util;
|
||||||
using ResourceHandle = FFXIVClientStructs.FFXIV.Client.System.Resource.Handle.ResourceHandle;
|
using ResourceHandle = FFXIVClientStructs.FFXIV.Client.System.Resource.Handle.ResourceHandle;
|
||||||
|
|
||||||
namespace Penumbra.Interop
|
namespace Penumbra.Interop
|
||||||
{
|
{
|
||||||
public class GameResourceManagement
|
public class ResidentResources
|
||||||
{
|
{
|
||||||
private const int NumResources = 85;
|
private const int NumResources = 85;
|
||||||
|
|
||||||
|
|
@ -17,7 +18,7 @@ namespace Penumbra.Interop
|
||||||
public unsafe delegate void* UnloadPlayerResourcesPrototype( IntPtr pResourceManager );
|
public unsafe delegate void* UnloadPlayerResourcesPrototype( IntPtr pResourceManager );
|
||||||
|
|
||||||
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
|
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
|
||||||
public unsafe delegate void* LoadCharacterResourcesPrototype( CharacterResourceManager* pCharacterResourceManager );
|
public unsafe delegate void* LoadCharacterResourcesPrototype( CharacterUtility* pCharacterResourceManager );
|
||||||
|
|
||||||
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
|
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
|
||||||
public unsafe delegate void* UnloadCharacterResourcePrototype( IntPtr resource );
|
public unsafe delegate void* UnloadCharacterResourcePrototype( IntPtr resource );
|
||||||
|
|
@ -25,37 +26,50 @@ namespace Penumbra.Interop
|
||||||
|
|
||||||
public LoadPlayerResourcesPrototype LoadPlayerResources { get; }
|
public LoadPlayerResourcesPrototype LoadPlayerResources { get; }
|
||||||
public UnloadPlayerResourcesPrototype UnloadPlayerResources { get; }
|
public UnloadPlayerResourcesPrototype UnloadPlayerResources { get; }
|
||||||
public LoadCharacterResourcesPrototype LoadCharacterResources { get; }
|
public LoadCharacterResourcesPrototype LoadDataFiles { get; }
|
||||||
public UnloadCharacterResourcePrototype UnloadCharacterResource { get; }
|
public UnloadCharacterResourcePrototype UnloadCharacterResource { get; }
|
||||||
|
|
||||||
// Object addresses
|
// Object addresses
|
||||||
private readonly IntPtr _playerResourceManagerAddress;
|
private readonly IntPtr _residentResourceManagerAddress;
|
||||||
|
|
||||||
public IntPtr PlayerResourceManagerPtr
|
public IntPtr ResidentResourceManager
|
||||||
=> Marshal.ReadIntPtr( _playerResourceManagerAddress );
|
=> Marshal.ReadIntPtr( _residentResourceManagerAddress );
|
||||||
|
|
||||||
private readonly IntPtr _characterResourceManagerAddress;
|
private readonly IntPtr _characterUtilityAddress;
|
||||||
|
|
||||||
public unsafe CharacterResourceManager* CharacterResourceManagerPtr
|
public unsafe CharacterUtility* CharacterUtility
|
||||||
=> ( CharacterResourceManager* )Marshal.ReadIntPtr( _characterResourceManagerAddress ).ToPointer();
|
=> ( CharacterUtility* )Marshal.ReadIntPtr( _characterUtilityAddress ).ToPointer();
|
||||||
|
|
||||||
public GameResourceManagement( )
|
public ResidentResources()
|
||||||
{
|
{
|
||||||
|
var module = Dalamud.SigScanner.Module.BaseAddress.ToInt64();
|
||||||
var loadPlayerResourcesAddress =
|
var loadPlayerResourcesAddress =
|
||||||
Dalamud.SigScanner.ScanText(
|
Dalamud.SigScanner.ScanText(
|
||||||
"E8 ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? BA ?? ?? ?? ?? 41 B8 ?? ?? ?? ?? 48 8B 48 30 48 8B 01 FF 50 10 48 85 C0 74 0A " );
|
"E8 ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? BA ?? ?? ?? ?? 41 B8 ?? ?? ?? ?? 48 8B 48 30 48 8B 01 FF 50 10 48 85 C0 74 0A " );
|
||||||
var unloadPlayerResourcesAddress =
|
GeneralUtil.PrintDebugAddress( "LoadPlayerResources", loadPlayerResourcesAddress );
|
||||||
Dalamud.SigScanner.ScanText( "41 55 48 81 EC ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 84 24 ?? ?? ?? ?? 4C 8B E9 48 83 C1 08" );
|
|
||||||
var loadCharacterResourcesAddress = Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? 00 48 8D 8E ?? ?? 00 00 E8 ?? ?? ?? 00 33 D2" );
|
|
||||||
var unloadCharacterResourceAddress = Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? FF 4C 89 37 48 83 C7 08 48 83 ED 01 75 ?? 48 8B CB" );
|
|
||||||
|
|
||||||
_playerResourceManagerAddress = Dalamud.SigScanner.GetStaticAddressFromSig( "0F 44 FE 48 8B 0D ?? ?? ?? ?? 48 85 C9 74 05" );
|
var unloadPlayerResourcesAddress =
|
||||||
_characterResourceManagerAddress =
|
Dalamud.SigScanner.ScanText(
|
||||||
|
"41 55 48 81 EC ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 84 24 ?? ?? ?? ?? 4C 8B E9 48 83 C1 08" );
|
||||||
|
GeneralUtil.PrintDebugAddress( "UnloadPlayerResources", unloadPlayerResourcesAddress );
|
||||||
|
|
||||||
|
var loadDataFilesAddress = Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? 00 48 8D 8E ?? ?? 00 00 E8 ?? ?? ?? 00 33 D2" );
|
||||||
|
GeneralUtil.PrintDebugAddress( "LoadDataFiles", loadDataFilesAddress );
|
||||||
|
|
||||||
|
var unloadCharacterResourceAddress =
|
||||||
|
Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? FF 4C 89 37 48 83 C7 08 48 83 ED 01 75 ?? 48 8B CB" );
|
||||||
|
GeneralUtil.PrintDebugAddress( "UnloadCharacterResource", unloadCharacterResourceAddress );
|
||||||
|
|
||||||
|
_residentResourceManagerAddress = Dalamud.SigScanner.GetStaticAddressFromSig( "0F 44 FE 48 8B 0D ?? ?? ?? ?? 48 85 C9 74 05" );
|
||||||
|
GeneralUtil.PrintDebugAddress( "ResidentResourceManager", _residentResourceManagerAddress );
|
||||||
|
|
||||||
|
_characterUtilityAddress =
|
||||||
Dalamud.SigScanner.GetStaticAddressFromSig( "48 8B 0D ?? ?? ?? ?? E8 ?? ?? ?? 00 48 8D 8E ?? ?? 00 00 E8 ?? ?? ?? 00 33 D2" );
|
Dalamud.SigScanner.GetStaticAddressFromSig( "48 8B 0D ?? ?? ?? ?? E8 ?? ?? ?? 00 48 8D 8E ?? ?? 00 00 E8 ?? ?? ?? 00 33 D2" );
|
||||||
|
GeneralUtil.PrintDebugAddress( "CharacterUtility", _characterUtilityAddress );
|
||||||
|
|
||||||
LoadPlayerResources = Marshal.GetDelegateForFunctionPointer< LoadPlayerResourcesPrototype >( loadPlayerResourcesAddress );
|
LoadPlayerResources = Marshal.GetDelegateForFunctionPointer< LoadPlayerResourcesPrototype >( loadPlayerResourcesAddress );
|
||||||
UnloadPlayerResources = Marshal.GetDelegateForFunctionPointer< UnloadPlayerResourcesPrototype >( unloadPlayerResourcesAddress );
|
UnloadPlayerResources = Marshal.GetDelegateForFunctionPointer< UnloadPlayerResourcesPrototype >( unloadPlayerResourcesAddress );
|
||||||
LoadCharacterResources = Marshal.GetDelegateForFunctionPointer< LoadCharacterResourcesPrototype >( loadCharacterResourcesAddress );
|
LoadDataFiles = Marshal.GetDelegateForFunctionPointer< LoadCharacterResourcesPrototype >( loadDataFilesAddress );
|
||||||
UnloadCharacterResource =
|
UnloadCharacterResource =
|
||||||
Marshal.GetDelegateForFunctionPointer< UnloadCharacterResourcePrototype >( unloadCharacterResourceAddress );
|
Marshal.GetDelegateForFunctionPointer< UnloadCharacterResourcePrototype >( unloadCharacterResourceAddress );
|
||||||
}
|
}
|
||||||
|
|
@ -65,8 +79,8 @@ namespace Penumbra.Interop
|
||||||
{
|
{
|
||||||
ReloadCharacterResources();
|
ReloadCharacterResources();
|
||||||
|
|
||||||
UnloadPlayerResources( PlayerResourceManagerPtr );
|
UnloadPlayerResources( ResidentResourceManager );
|
||||||
LoadPlayerResources( PlayerResourceManagerPtr );
|
LoadPlayerResources( ResidentResourceManager );
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe string ResourceToPath( byte* resource )
|
public unsafe string ResourceToPath( byte* resource )
|
||||||
|
|
@ -75,12 +89,12 @@ namespace Penumbra.Interop
|
||||||
private unsafe void ReloadCharacterResources()
|
private unsafe void ReloadCharacterResources()
|
||||||
{
|
{
|
||||||
var oldResources = new IntPtr[NumResources];
|
var oldResources = new IntPtr[NumResources];
|
||||||
var resources = new IntPtr( &CharacterResourceManagerPtr->Resources );
|
var resources = new IntPtr( &CharacterUtility->Resources );
|
||||||
var pResources = ( void** )resources.ToPointer();
|
var pResources = ( void** )resources.ToPointer();
|
||||||
|
|
||||||
Marshal.Copy( resources, oldResources, 0, NumResources );
|
Marshal.Copy( resources, oldResources, 0, NumResources );
|
||||||
|
|
||||||
LoadCharacterResources( CharacterResourceManagerPtr );
|
LoadDataFiles( CharacterUtility );
|
||||||
|
|
||||||
for( var i = 0; i < NumResources; i++ )
|
for( var i = 0; i < NumResources; i++ )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -53,22 +53,26 @@ namespace Penumbra.Interop
|
||||||
public ResourceLoader( Penumbra penumbra )
|
public ResourceLoader( Penumbra penumbra )
|
||||||
{
|
{
|
||||||
Penumbra = penumbra;
|
Penumbra = penumbra;
|
||||||
Crc32 = new Crc32();
|
Crc32 = new Crc32();
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe void Init()
|
public unsafe void Init()
|
||||||
{
|
{
|
||||||
var readFileAddress =
|
var readFileAddress =
|
||||||
Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? ?? 84 C0 0F 84 ?? 00 00 00 4C 8B C3 BA 05" );
|
Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? ?? 84 C0 0F 84 ?? 00 00 00 4C 8B C3 BA 05" );
|
||||||
|
GeneralUtil.PrintDebugAddress( "ReadFile", readFileAddress );
|
||||||
|
|
||||||
var readSqpackAddress =
|
var readSqpackAddress =
|
||||||
Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? ?? EB 05 E8 ?? ?? ?? ?? 84 C0 0F 84 ?? 00 00 00 4C 8B C3" );
|
Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? ?? EB 05 E8 ?? ?? ?? ?? 84 C0 0F 84 ?? 00 00 00 4C 8B C3" );
|
||||||
|
GeneralUtil.PrintDebugAddress( "ReadSqPack", readSqpackAddress );
|
||||||
|
|
||||||
var getResourceSyncAddress =
|
var getResourceSyncAddress =
|
||||||
Dalamud.SigScanner.ScanText( "E8 ?? ?? 00 00 48 8D 8F ?? ?? 00 00 48 89 87 ?? ?? 00 00" );
|
Dalamud.SigScanner.ScanText( "E8 ?? ?? 00 00 48 8D 8F ?? ?? 00 00 48 89 87 ?? ?? 00 00" );
|
||||||
|
GeneralUtil.PrintDebugAddress( "GetResourceSync", getResourceSyncAddress );
|
||||||
|
|
||||||
var getResourceAsyncAddress =
|
var getResourceAsyncAddress =
|
||||||
Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? 00 48 8B D8 EB ?? F0 FF 83 ?? ?? 00 00" );
|
Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? 00 48 8B D8 EB ?? F0 FF 83 ?? ?? 00 00" );
|
||||||
|
GeneralUtil.PrintDebugAddress( "GetResourceAsync", getResourceAsyncAddress );
|
||||||
|
|
||||||
|
|
||||||
ReadSqpackHook = new Hook< ReadSqpackPrototype >( readSqpackAddress, ReadSqpackHandler );
|
ReadSqpackHook = new Hook< ReadSqpackPrototype >( readSqpackAddress, ReadSqpackHandler );
|
||||||
|
|
@ -193,6 +197,7 @@ namespace Penumbra.Interop
|
||||||
{
|
{
|
||||||
if( ReadFile == null || pFileDesc == null || pFileDesc->ResourceHandle == null )
|
if( ReadFile == null || pFileDesc == null || pFileDesc->ResourceHandle == null )
|
||||||
{
|
{
|
||||||
|
PluginLog.Error( "THIS SHOULD NOT HAPPEN" );
|
||||||
return ReadSqpackHook?.Original( pFileHandler, pFileDesc, priority, isSync ) ?? 0;
|
return ReadSqpackHook?.Original( pFileHandler, pFileDesc, priority, isSync ) ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ namespace Penumbra.Meta
|
||||||
|
|
||||||
private readonly MetaDefaults _default;
|
private readonly MetaDefaults _default;
|
||||||
private readonly DirectoryInfo _dir;
|
private readonly DirectoryInfo _dir;
|
||||||
private readonly GameResourceManagement _resourceManagement;
|
private readonly ResidentResources _resourceManagement;
|
||||||
private readonly Dictionary< GamePath, FileInfo > _resolvedFiles;
|
private readonly Dictionary< GamePath, FileInfo > _resolvedFiles;
|
||||||
|
|
||||||
private readonly Dictionary< MetaManipulation, Mod.Mod > _currentManipulations = new();
|
private readonly Dictionary< MetaManipulation, Mod.Mod > _currentManipulations = new();
|
||||||
|
|
@ -120,7 +120,7 @@ namespace Penumbra.Meta
|
||||||
{
|
{
|
||||||
_resolvedFiles = resolvedFiles;
|
_resolvedFiles = resolvedFiles;
|
||||||
_default = Service< MetaDefaults >.Get();
|
_default = Service< MetaDefaults >.Get();
|
||||||
_resourceManagement = Service< GameResourceManagement >.Get();
|
_resourceManagement = Service< ResidentResources >.Get();
|
||||||
_dir = new DirectoryInfo( Path.Combine( tempDir.FullName, name.ReplaceBadXivSymbols() ) );
|
_dir = new DirectoryInfo( Path.Combine( tempDir.FullName, name.ReplaceBadXivSymbols() ) );
|
||||||
ClearDirectory();
|
ClearDirectory();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ namespace Penumbra.Mods
|
||||||
|
|
||||||
if( reloadMeta && ActiveCollection.Settings.TryGetValue( mod.BasePath.Name, out var config ) && config.Enabled )
|
if( reloadMeta && ActiveCollection.Settings.TryGetValue( mod.BasePath.Name, out var config ) && config.Enabled )
|
||||||
{
|
{
|
||||||
Service< GameResourceManagement >.Get().ReloadPlayerResources();
|
Service< ResidentResources >.Get().ReloadPlayerResources();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -186,7 +186,7 @@ namespace Penumbra.Mods
|
||||||
if( ActiveCollection == DefaultCollection )
|
if( ActiveCollection == DefaultCollection )
|
||||||
{
|
{
|
||||||
ActiveCollection = c;
|
ActiveCollection = c;
|
||||||
var resourceManager = Service< GameResourceManagement >.Get();
|
var resourceManager = Service< ResidentResources >.Get();
|
||||||
resourceManager.ReloadPlayerResources();
|
resourceManager.ReloadPlayerResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,7 +208,7 @@ namespace Penumbra.Mods
|
||||||
&& ActiveCollection == collection )
|
&& ActiveCollection == collection )
|
||||||
{
|
{
|
||||||
ActiveCollection = c;
|
ActiveCollection = c;
|
||||||
var resourceManager = Service< GameResourceManagement >.Get();
|
var resourceManager = Service< ResidentResources >.Get();
|
||||||
resourceManager.ReloadPlayerResources();
|
resourceManager.ReloadPlayerResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ namespace Penumbra.Mods
|
||||||
Cache.UpdateMetaManipulations();
|
Cache.UpdateMetaManipulations();
|
||||||
if( activeCollection )
|
if( activeCollection )
|
||||||
{
|
{
|
||||||
Service< GameResourceManagement >.Get().ReloadPlayerResources();
|
Service< ResidentResources >.Get().ReloadPlayerResources();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Penumbra
|
||||||
MusicManager = new MusicManager();
|
MusicManager = new MusicManager();
|
||||||
MusicManager.DisableStreaming();
|
MusicManager.DisableStreaming();
|
||||||
|
|
||||||
var gameUtils = Service< GameResourceManagement >.Set();
|
var gameUtils = Service< ResidentResources >.Set();
|
||||||
PlayerWatcher = PlayerWatchFactory.Create( Dalamud.Framework, Dalamud.ClientState, Dalamud.Objects );
|
PlayerWatcher = PlayerWatchFactory.Create( Dalamud.Framework, Dalamud.ClientState, Dalamud.Objects );
|
||||||
Service< MetaDefaults >.Set();
|
Service< MetaDefaults >.Set();
|
||||||
var modManager = Service< ModManager >.Set();
|
var modManager = Service< ModManager >.Set();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
|
||||||
namespace Penumbra.Structs
|
namespace Penumbra.Structs
|
||||||
{
|
{
|
||||||
[StructLayout( LayoutKind.Sequential )]
|
[StructLayout( LayoutKind.Sequential )]
|
||||||
public unsafe struct CharacterResourceManager
|
public unsafe struct CharacterUtility
|
||||||
{
|
{
|
||||||
public void* VTable;
|
public void* VTable;
|
||||||
|
|
||||||
|
|
@ -6,7 +6,6 @@ using System.Numerics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Dalamud.Game.ClientState.Objects.Types;
|
using Dalamud.Game.ClientState.Objects.Types;
|
||||||
using Dalamud.Plugin;
|
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using Penumbra.Api;
|
using Penumbra.Api;
|
||||||
using Penumbra.GameData.Enums;
|
using Penumbra.GameData.Enums;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using FFXIVClientStructs.FFXIV.Client.System.Resource;
|
using FFXIVClientStructs.FFXIV.Client.System.Resource;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle;
|
||||||
using FFXIVClientStructs.STD;
|
using FFXIVClientStructs.STD;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using ResourceHandle = FFXIVClientStructs.FFXIV.Client.System.Resource.Handle.ResourceHandle;
|
|
||||||
using ResourceManager = FFXIVClientStructs.FFXIV.Client.System.Resource.ResourceManager;
|
|
||||||
|
|
||||||
namespace Penumbra.UI
|
namespace Penumbra.UI
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -248,7 +248,7 @@ namespace Penumbra.UI
|
||||||
{
|
{
|
||||||
if( ImGui.Button( LabelReloadResource ) )
|
if( ImGui.Button( LabelReloadResource ) )
|
||||||
{
|
{
|
||||||
Service< GameResourceManagement >.Get().ReloadPlayerResources();
|
Service< ResidentResources >.Get().ReloadPlayerResources();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
14
Penumbra/Util/GeneralUtil.cs
Normal file
14
Penumbra/Util/GeneralUtil.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using Dalamud.Logging;
|
||||||
|
|
||||||
|
namespace Penumbra.Util
|
||||||
|
{
|
||||||
|
public static class GeneralUtil
|
||||||
|
{
|
||||||
|
public static void PrintDebugAddress( string name, IntPtr address )
|
||||||
|
{
|
||||||
|
var module = Dalamud.SigScanner.Module.BaseAddress.ToInt64();
|
||||||
|
PluginLog.Debug( "{Name} found at 0x{Address:X16}, +0x{Offset}", name, address.ToInt64(), address.ToInt64() - module );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue