diff --git a/Penumbra/Interop/GameResourceManagement.cs b/Penumbra/Interop/GameResourceManagement.cs index 1b88e0c1..a36f09ab 100644 --- a/Penumbra/Interop/GameResourceManagement.cs +++ b/Penumbra/Interop/GameResourceManagement.cs @@ -2,11 +2,12 @@ using System; using System.Runtime.InteropServices; using Dalamud.Logging; using Penumbra.Structs; +using Penumbra.Util; using ResourceHandle = FFXIVClientStructs.FFXIV.Client.System.Resource.Handle.ResourceHandle; namespace Penumbra.Interop { - public class GameResourceManagement + public class ResidentResources { private const int NumResources = 85; @@ -17,7 +18,7 @@ namespace Penumbra.Interop public unsafe delegate void* UnloadPlayerResourcesPrototype( IntPtr pResourceManager ); [UnmanagedFunctionPointer( CallingConvention.ThisCall )] - public unsafe delegate void* LoadCharacterResourcesPrototype( CharacterResourceManager* pCharacterResourceManager ); + public unsafe delegate void* LoadCharacterResourcesPrototype( CharacterUtility* pCharacterResourceManager ); [UnmanagedFunctionPointer( CallingConvention.ThisCall )] public unsafe delegate void* UnloadCharacterResourcePrototype( IntPtr resource ); @@ -25,37 +26,50 @@ namespace Penumbra.Interop public LoadPlayerResourcesPrototype LoadPlayerResources { get; } public UnloadPlayerResourcesPrototype UnloadPlayerResources { get; } - public LoadCharacterResourcesPrototype LoadCharacterResources { get; } + public LoadCharacterResourcesPrototype LoadDataFiles { get; } public UnloadCharacterResourcePrototype UnloadCharacterResource { get; } // Object addresses - private readonly IntPtr _playerResourceManagerAddress; + private readonly IntPtr _residentResourceManagerAddress; - public IntPtr PlayerResourceManagerPtr - => Marshal.ReadIntPtr( _playerResourceManagerAddress ); + public IntPtr ResidentResourceManager + => Marshal.ReadIntPtr( _residentResourceManagerAddress ); - private readonly IntPtr _characterResourceManagerAddress; + private readonly IntPtr _characterUtilityAddress; - public unsafe CharacterResourceManager* CharacterResourceManagerPtr - => ( CharacterResourceManager* )Marshal.ReadIntPtr( _characterResourceManagerAddress ).ToPointer(); + public unsafe CharacterUtility* CharacterUtility + => ( CharacterUtility* )Marshal.ReadIntPtr( _characterUtilityAddress ).ToPointer(); - public GameResourceManagement( ) + public ResidentResources() { + var module = Dalamud.SigScanner.Module.BaseAddress.ToInt64(); var loadPlayerResourcesAddress = 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 " ); - var unloadPlayerResourcesAddress = - 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" ); + GeneralUtil.PrintDebugAddress( "LoadPlayerResources", loadPlayerResourcesAddress ); - _playerResourceManagerAddress = Dalamud.SigScanner.GetStaticAddressFromSig( "0F 44 FE 48 8B 0D ?? ?? ?? ?? 48 85 C9 74 05" ); - _characterResourceManagerAddress = + var unloadPlayerResourcesAddress = + 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" ); + GeneralUtil.PrintDebugAddress( "CharacterUtility", _characterUtilityAddress ); LoadPlayerResources = Marshal.GetDelegateForFunctionPointer< LoadPlayerResourcesPrototype >( loadPlayerResourcesAddress ); UnloadPlayerResources = Marshal.GetDelegateForFunctionPointer< UnloadPlayerResourcesPrototype >( unloadPlayerResourcesAddress ); - LoadCharacterResources = Marshal.GetDelegateForFunctionPointer< LoadCharacterResourcesPrototype >( loadCharacterResourcesAddress ); + LoadDataFiles = Marshal.GetDelegateForFunctionPointer< LoadCharacterResourcesPrototype >( loadDataFilesAddress ); UnloadCharacterResource = Marshal.GetDelegateForFunctionPointer< UnloadCharacterResourcePrototype >( unloadCharacterResourceAddress ); } @@ -65,8 +79,8 @@ namespace Penumbra.Interop { ReloadCharacterResources(); - UnloadPlayerResources( PlayerResourceManagerPtr ); - LoadPlayerResources( PlayerResourceManagerPtr ); + UnloadPlayerResources( ResidentResourceManager ); + LoadPlayerResources( ResidentResourceManager ); } public unsafe string ResourceToPath( byte* resource ) @@ -75,12 +89,12 @@ namespace Penumbra.Interop private unsafe void ReloadCharacterResources() { var oldResources = new IntPtr[NumResources]; - var resources = new IntPtr( &CharacterResourceManagerPtr->Resources ); + var resources = new IntPtr( &CharacterUtility->Resources ); var pResources = ( void** )resources.ToPointer(); Marshal.Copy( resources, oldResources, 0, NumResources ); - LoadCharacterResources( CharacterResourceManagerPtr ); + LoadDataFiles( CharacterUtility ); for( var i = 0; i < NumResources; i++ ) { diff --git a/Penumbra/Interop/ResourceLoader.cs b/Penumbra/Interop/ResourceLoader.cs index e6034a85..8d4c5937 100644 --- a/Penumbra/Interop/ResourceLoader.cs +++ b/Penumbra/Interop/ResourceLoader.cs @@ -53,22 +53,26 @@ namespace Penumbra.Interop public ResourceLoader( Penumbra penumbra ) { Penumbra = penumbra; - Crc32 = new Crc32(); + Crc32 = new Crc32(); } public unsafe void Init() { var readFileAddress = Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? ?? 84 C0 0F 84 ?? 00 00 00 4C 8B C3 BA 05" ); + GeneralUtil.PrintDebugAddress( "ReadFile", readFileAddress ); var readSqpackAddress = Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? ?? EB 05 E8 ?? ?? ?? ?? 84 C0 0F 84 ?? 00 00 00 4C 8B C3" ); + GeneralUtil.PrintDebugAddress( "ReadSqPack", readSqpackAddress ); var getResourceSyncAddress = Dalamud.SigScanner.ScanText( "E8 ?? ?? 00 00 48 8D 8F ?? ?? 00 00 48 89 87 ?? ?? 00 00" ); + GeneralUtil.PrintDebugAddress( "GetResourceSync", getResourceSyncAddress ); var getResourceAsyncAddress = Dalamud.SigScanner.ScanText( "E8 ?? ?? ?? 00 48 8B D8 EB ?? F0 FF 83 ?? ?? 00 00" ); + GeneralUtil.PrintDebugAddress( "GetResourceAsync", getResourceAsyncAddress ); ReadSqpackHook = new Hook< ReadSqpackPrototype >( readSqpackAddress, ReadSqpackHandler ); @@ -193,6 +197,7 @@ namespace Penumbra.Interop { if( ReadFile == null || pFileDesc == null || pFileDesc->ResourceHandle == null ) { + PluginLog.Error( "THIS SHOULD NOT HAPPEN" ); return ReadSqpackHook?.Original( pFileHandler, pFileDesc, priority, isSync ) ?? 0; } diff --git a/Penumbra/Meta/MetaManager.cs b/Penumbra/Meta/MetaManager.cs index 4fc8d3f3..995fcd97 100644 --- a/Penumbra/Meta/MetaManager.cs +++ b/Penumbra/Meta/MetaManager.cs @@ -44,7 +44,7 @@ namespace Penumbra.Meta private readonly MetaDefaults _default; private readonly DirectoryInfo _dir; - private readonly GameResourceManagement _resourceManagement; + private readonly ResidentResources _resourceManagement; private readonly Dictionary< GamePath, FileInfo > _resolvedFiles; private readonly Dictionary< MetaManipulation, Mod.Mod > _currentManipulations = new(); @@ -120,7 +120,7 @@ namespace Penumbra.Meta { _resolvedFiles = resolvedFiles; _default = Service< MetaDefaults >.Get(); - _resourceManagement = Service< GameResourceManagement >.Get(); + _resourceManagement = Service< ResidentResources >.Get(); _dir = new DirectoryInfo( Path.Combine( tempDir.FullName, name.ReplaceBadXivSymbols() ) ); ClearDirectory(); } diff --git a/Penumbra/Mods/CollectionManager.cs b/Penumbra/Mods/CollectionManager.cs index 30ff82e4..1a2ca986 100644 --- a/Penumbra/Mods/CollectionManager.cs +++ b/Penumbra/Mods/CollectionManager.cs @@ -78,7 +78,7 @@ namespace Penumbra.Mods 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 ) { ActiveCollection = c; - var resourceManager = Service< GameResourceManagement >.Get(); + var resourceManager = Service< ResidentResources >.Get(); resourceManager.ReloadPlayerResources(); } @@ -208,7 +208,7 @@ namespace Penumbra.Mods && ActiveCollection == collection ) { ActiveCollection = c; - var resourceManager = Service< GameResourceManagement >.Get(); + var resourceManager = Service< ResidentResources >.Get(); resourceManager.ReloadPlayerResources(); } diff --git a/Penumbra/Mods/ModCollection.cs b/Penumbra/Mods/ModCollection.cs index d8805749..5646601e 100644 --- a/Penumbra/Mods/ModCollection.cs +++ b/Penumbra/Mods/ModCollection.cs @@ -140,7 +140,7 @@ namespace Penumbra.Mods Cache.UpdateMetaManipulations(); if( activeCollection ) { - Service< GameResourceManagement >.Get().ReloadPlayerResources(); + Service< ResidentResources >.Get().ReloadPlayerResources(); } } } diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index f565bfd8..ac367c48 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -46,7 +46,7 @@ namespace Penumbra MusicManager = new MusicManager(); MusicManager.DisableStreaming(); - var gameUtils = Service< GameResourceManagement >.Set(); + var gameUtils = Service< ResidentResources >.Set(); PlayerWatcher = PlayerWatchFactory.Create( Dalamud.Framework, Dalamud.ClientState, Dalamud.Objects ); Service< MetaDefaults >.Set(); var modManager = Service< ModManager >.Set(); diff --git a/Penumbra/Structs/CharacterResourceManager.cs b/Penumbra/Structs/CharacterUtility.cs similarity index 81% rename from Penumbra/Structs/CharacterResourceManager.cs rename to Penumbra/Structs/CharacterUtility.cs index d21f04dc..2459e2d6 100644 --- a/Penumbra/Structs/CharacterResourceManager.cs +++ b/Penumbra/Structs/CharacterUtility.cs @@ -4,7 +4,7 @@ using System.Runtime.InteropServices; namespace Penumbra.Structs { [StructLayout( LayoutKind.Sequential )] - public unsafe struct CharacterResourceManager + public unsafe struct CharacterUtility { public void* VTable; diff --git a/Penumbra/UI/MenuTabs/TabDebug.cs b/Penumbra/UI/MenuTabs/TabDebug.cs index 6e0c4aae..18dac78b 100644 --- a/Penumbra/UI/MenuTabs/TabDebug.cs +++ b/Penumbra/UI/MenuTabs/TabDebug.cs @@ -6,7 +6,6 @@ using System.Numerics; using System.Reflection; using System.Runtime.InteropServices; using Dalamud.Game.ClientState.Objects.Types; -using Dalamud.Plugin; using ImGuiNET; using Penumbra.Api; using Penumbra.GameData.Enums; diff --git a/Penumbra/UI/MenuTabs/TabResourceManager.cs b/Penumbra/UI/MenuTabs/TabResourceManager.cs index 3443516b..a480c566 100644 --- a/Penumbra/UI/MenuTabs/TabResourceManager.cs +++ b/Penumbra/UI/MenuTabs/TabResourceManager.cs @@ -1,9 +1,8 @@ using System.Numerics; using FFXIVClientStructs.FFXIV.Client.System.Resource; +using FFXIVClientStructs.FFXIV.Client.System.Resource.Handle; using FFXIVClientStructs.STD; using ImGuiNET; -using ResourceHandle = FFXIVClientStructs.FFXIV.Client.System.Resource.Handle.ResourceHandle; -using ResourceManager = FFXIVClientStructs.FFXIV.Client.System.Resource.ResourceManager; namespace Penumbra.UI { diff --git a/Penumbra/UI/MenuTabs/TabSettings.cs b/Penumbra/UI/MenuTabs/TabSettings.cs index 530ac42f..47a33a8d 100644 --- a/Penumbra/UI/MenuTabs/TabSettings.cs +++ b/Penumbra/UI/MenuTabs/TabSettings.cs @@ -248,7 +248,7 @@ namespace Penumbra.UI { if( ImGui.Button( LabelReloadResource ) ) { - Service< GameResourceManagement >.Get().ReloadPlayerResources(); + Service< ResidentResources >.Get().ReloadPlayerResources(); } } diff --git a/Penumbra/Util/GeneralUtil.cs b/Penumbra/Util/GeneralUtil.cs new file mode 100644 index 00000000..f0a2e83a --- /dev/null +++ b/Penumbra/Util/GeneralUtil.cs @@ -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 ); + } + } +} \ No newline at end of file