Merge branch 'master' into api4-b

# Conflicts:
#	Penumbra/Interop/GameResourceManagement.cs
#	Penumbra/Penumbra.cs
#	Penumbra/Penumbra.csproj
This commit is contained in:
Ottermandias 2021-09-01 21:40:02 +02:00
commit 34b21c2fde
8 changed files with 164 additions and 16 deletions

Binary file not shown.

Binary file not shown.

BIN
FFXIVClientStructs.dll Normal file

Binary file not shown.

View file

@ -4,6 +4,8 @@ using System.Runtime.InteropServices;
using Dalamud.Logging;
using Dalamud.Plugin;
using Penumbra.Structs;
using Reloaded.Hooks.Definitions.X64;
using ResourceHandle = FFXIVClientStructs.FFXIV.Client.System.Resource.Handle.ResourceHandle;
namespace Penumbra.Interop
{
@ -85,9 +87,11 @@ namespace Penumbra.Interop
for( var i = 0; i < NumResources; i++ )
{
var handle = ( ResourceHandle* )oldResources[ i ];
if( oldResources[ i ].ToPointer() == pResources[ i ] )
{
PluginLog.Debug( $"Unchanged resource: {ResourceToPath( ( byte* )oldResources[ i ].ToPointer() )}" );
( ( ResourceHandle* )oldResources[ i ] )->DecRef();
continue;
}
@ -96,7 +100,14 @@ namespace Penumbra.Interop
+ $"{ResourceToPath( ( byte* )pResources[ i ] )}" );
UnloadCharacterResource( oldResources[ i ] );
// Temporary fix against crashes?
if( handle->RefCount <= 0 )
{
handle->RefCount = 1;
handle->IncRef();
handle->RefCount = 1;
}
}
}
}
}
}

View file

@ -38,6 +38,7 @@ namespace Penumbra
public Penumbra( DalamudPluginInterface pluginInterface )
{
FFXIVClientStructs.Resolver.Initialize();
Dalamud.Initialize( pluginInterface );
GameData.GameData.GetIdentifier( Dalamud.GameData, Dalamud.ClientState.ClientLanguage );
Config = Configuration.Load();
@ -186,4 +187,4 @@ namespace Penumbra
SettingsInterface.FlipVisibility();
}
}
}
}

View file

@ -29,38 +29,48 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ILRepack" Version="2.0.18" GeneratePathProperty="true" />
<Reference Include="Dalamud">
<HintPath>$(DALAMUD_ROOT)\Dalamud.dll</HintPath>
<HintPath>..\libs\Dalamud.dll</HintPath>
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Dalamud.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGui.NET">
<HintPath>$(DALAMUD_ROOT)\ImGui.NET.dll</HintPath>
<HintPath>..\libs\ImGui.NET.dll</HintPath>
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\ImGui.NET.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ImGuiScene">
<HintPath>$(DALAMUD_ROOT)\ImGuiScene.dll</HintPath>
<HintPath>..\libs\ImGuiScene.dll</HintPath>
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\ImGuiScene.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina">
<HintPath>$(DALAMUD_ROOT)\Lumina.dll</HintPath>
<HintPath>..\libs\Lumina.dll</HintPath>
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Lumina.Excel">
<HintPath>$(DALAMUD_ROOT)\Lumina.Excel.dll</HintPath>
<HintPath>..\libs\Lumina.Excel.dll</HintPath>
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.Excel.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="FFXIVClientStructs">
<HintPath>..\FFXIVClientStructs.dll</HintPath>
<Private>true</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Net.Http" />
</ItemGroup>
<Target Name="ILRepack" AfterTargets="Build">
<ItemGroup>
<InputAssemblies Include="$(TargetPath)"/>
<InputAssemblies Include="$(TargetDir)Penumbra.dll $(TargetDir)FFXIVClientStructs.dll" Exclude="$(TargetPath)"/>
</ItemGroup>
<Exec Command="$(ILRepack) /lib:$(TargetDir) /lib:$(AppData)\XIVLauncher\addon\Hooks\dev /out:$(TargetDir)$(TargetFileName) @(InputAssemblies, ' ')"/>
</Target>
<ItemGroup>
<PackageReference Include="EmbedIO" Version="3.4.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
@ -68,8 +78,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Penumbra.GameData\Penumbra.GameData.csproj" />
<ProjectReference Include="..\Penumbra.PlayerWatch\Penumbra.PlayerWatch.csproj" />
<ProjectReference Include="..\Penumbra.GameData\Penumbra.GameData.csproj" />
<ProjectReference Include="..\Penumbra.PlayerWatch\Penumbra.PlayerWatch.csproj" />
</ItemGroup>
<ItemGroup>
@ -77,4 +87,4 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
</Project>

View file

@ -0,0 +1,125 @@
using System.Numerics;
using FFXIVClientStructs.FFXIV.Client.System.Resource;
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
{
public partial class SettingsInterface
{
private static string GetNodeLabel( string label, uint type, ulong count )
{
var byte1 = type >> 24;
var byte2 = ( type >> 16 ) & 0xFF;
var byte3 = ( type >> 8 ) & 0xFF;
var byte4 = type & 0xFF;
return byte1 == 0
? $"{( char )byte2}{( char )byte3}{( char )byte4} - {count}###{label}{type}Debug"
: $"{( char )byte1}{( char )byte2}{( char )byte3}{( char )byte4} - {count}###{label}{type}Debug";
}
private unsafe void DrawResourceMap( string label, StdMap< uint, Pointer< ResourceHandle > >* typeMap )
{
if( typeMap == null || !ImGui.TreeNodeEx( label ) )
{
return;
}
if( typeMap->Count == 0 || !ImGui.BeginTable( $"##{label}_table", 4, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.RowBg ) )
{
ImGui.TreePop();
return;
}
ImGui.TableSetupColumn( "Hash", ImGuiTableColumnFlags.WidthFixed, 100 );
ImGui.TableSetupColumn( "Ptr", ImGuiTableColumnFlags.WidthFixed, 100 );
ImGui.TableSetupColumn( "Path", ImGuiTableColumnFlags.WidthFixed, ImGui.GetWindowContentRegionWidth() - 300 );
ImGui.TableSetupColumn( "Refs", ImGuiTableColumnFlags.WidthFixed, 30 );
ImGui.TableHeadersRow();
var node = typeMap->SmallestValue;
while( !node->IsNil )
{
ImGui.TableNextRow();
ImGui.TableNextColumn();
ImGui.Text( node->KeyValuePair.Item1.ToString() );
ImGui.TableNextColumn();
var address = $"0x{( ulong )node->KeyValuePair.Item2.Value:X}";
ImGui.Text( address );
if( ImGui.IsItemClicked() )
{
ImGui.SetClipboardText( address );
}
ImGui.TableNextColumn();
ImGui.Text( node->KeyValuePair.Item2.Value->FileName.ToString() );
ImGui.TableNextColumn();
ImGui.Text( node->KeyValuePair.Item2.Value->RefCount.ToString() );
node = node->Next();
}
ImGui.EndTable();
ImGui.TreePop();
}
private unsafe void DrawCategoryContainer( string label, ResourceGraph.CategoryContainer container )
{
var map = container.MainMap;
if( map == null || !ImGui.TreeNodeEx( $"{label} - {map->Count}###{label}Debug" ) )
{
return;
}
var node = map->SmallestValue;
while( !node->IsNil )
{
DrawResourceMap( GetNodeLabel( label, node->KeyValuePair.Item1, node->KeyValuePair.Item2.Value->Count ),
node->KeyValuePair.Item2.Value );
node = node->Next();
}
ImGui.TreePop();
}
private unsafe void DrawResourceManagerTab()
{
if( !ImGui.BeginTabItem( "Resource Manager Tab" ) )
{
return;
}
var resourceHandler = *( ResourceManager** )( _plugin.PluginInterface.TargetModuleScanner.Module.BaseAddress + 0x1D93AC0 );
if( resourceHandler == null )
{
return;
}
if( ImGui.BeginChild( "##ResourceManagerChild", -Vector2.One, true ) )
{
DrawCategoryContainer( "Common", resourceHandler->ResourceGraph->CommonContainer );
DrawCategoryContainer( "BgCommon", resourceHandler->ResourceGraph->BgCommonContainer );
DrawCategoryContainer( "Bg", resourceHandler->ResourceGraph->BgContainer );
DrawCategoryContainer( "Cut", resourceHandler->ResourceGraph->CutContainer );
DrawCategoryContainer( "Chara", resourceHandler->ResourceGraph->CharaContainer );
DrawCategoryContainer( "Shader", resourceHandler->ResourceGraph->ShaderContainer );
DrawCategoryContainer( "Ui", resourceHandler->ResourceGraph->UiContainer );
DrawCategoryContainer( "Sound", resourceHandler->ResourceGraph->SoundContainer );
DrawCategoryContainer( "Vfx", resourceHandler->ResourceGraph->VfxContainer );
DrawCategoryContainer( "UiScript", resourceHandler->ResourceGraph->UiScriptContainer );
DrawCategoryContainer( "Exd", resourceHandler->ResourceGraph->ExdContainer );
DrawCategoryContainer( "GameScript", resourceHandler->ResourceGraph->GameScriptContainer );
DrawCategoryContainer( "Music", resourceHandler->ResourceGraph->MusicContainer );
DrawCategoryContainer( "SqpackTest", resourceHandler->ResourceGraph->SqpackTestContainer );
DrawCategoryContainer( "Debug", resourceHandler->ResourceGraph->DebugContainer );
}
ImGui.EndChild();
ImGui.EndTabItem();
}
}
}

View file

@ -80,6 +80,7 @@ namespace Penumbra.UI
if( DebugTabVisible )
{
_base.DrawDebugTab();
_base.DrawResourceManagerTab();
}
ImGui.EndTabBar();
@ -87,4 +88,4 @@ namespace Penumbra.UI
}
}
}
}
}