Rename GameResourceManagement, add some output

This commit is contained in:
Ottermandias 2021-09-01 21:56:14 +02:00
parent 041485cad4
commit 940f1fbb3d
11 changed files with 65 additions and 34 deletions

View file

@ -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++ )
{

View file

@ -60,15 +60,19 @@ namespace Penumbra.Interop
{
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;
}

View file

@ -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();
}

View file

@ -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();
}

View file

@ -140,7 +140,7 @@ namespace Penumbra.Mods
Cache.UpdateMetaManipulations();
if( activeCollection )
{
Service< GameResourceManagement >.Get().ReloadPlayerResources();
Service< ResidentResources >.Get().ReloadPlayerResources();
}
}
}

View file

@ -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();

View file

@ -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;

View file

@ -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;

View file

@ -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
{

View file

@ -248,7 +248,7 @@ namespace Penumbra.UI
{
if( ImGui.Button( LabelReloadResource ) )
{
Service< GameResourceManagement >.Get().ReloadPlayerResources();
Service< ResidentResources >.Get().ReloadPlayerResources();
}
}

View 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 );
}
}
}