mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-15 05:04:15 +01:00
Add IPC test, optimize tester a little, only call event when game object available.
This commit is contained in:
parent
d12a3dd152
commit
0f35dd69f9
5 changed files with 87 additions and 36 deletions
|
|
@ -80,7 +80,9 @@ public interface IPenumbraApi : IPenumbraApiBase
|
|||
// so you can apply flag changes after finishing.
|
||||
public event CreatedCharacterBaseDelegate? CreatedCharacterBase;
|
||||
|
||||
public event GameObjectResourceResolvedDelegate GameObjectResourceResolved;
|
||||
// Triggered whenever a resource is redirected by Penumbra for a specific, identified game object.
|
||||
// Does not trigger if the resource is not requested for a known game object.
|
||||
public event GameObjectResourceResolvedDelegate? GameObjectResourceResolved;
|
||||
|
||||
// Queue redrawing of all actors of the given name with the given RedrawType.
|
||||
public void RedrawObject( string name, RedrawType setting );
|
||||
|
|
|
|||
|
|
@ -33,9 +33,12 @@ public class IpcTester : IDisposable
|
|||
private readonly ICallGateSubscriber< ModSettingChange, string, string, bool, object? > _settingChanged;
|
||||
private readonly ICallGateSubscriber< IntPtr, string, IntPtr, IntPtr, IntPtr, object? > _characterBaseCreating;
|
||||
private readonly ICallGateSubscriber< IntPtr, string, IntPtr, object? > _characterBaseCreated;
|
||||
private readonly ICallGateSubscriber< IntPtr, string, string, object? > _gameObjectResourcePathResolved;
|
||||
|
||||
private readonly List< DateTimeOffset > _initializedList = new();
|
||||
private readonly List< DateTimeOffset > _disposedList = new();
|
||||
private bool _subscribed = false;
|
||||
|
||||
|
||||
public IpcTester( DalamudPluginInterface pi, PenumbraIpc ipc )
|
||||
{
|
||||
|
|
@ -51,6 +54,15 @@ public class IpcTester : IDisposable
|
|||
_characterBaseCreating =
|
||||
_pi.GetIpcSubscriber< IntPtr, string, IntPtr, IntPtr, IntPtr, object? >( PenumbraIpc.LabelProviderCreatingCharacterBase );
|
||||
_characterBaseCreated = _pi.GetIpcSubscriber< IntPtr, string, IntPtr, object? >( PenumbraIpc.LabelProviderCreatedCharacterBase );
|
||||
_gameObjectResourcePathResolved =
|
||||
_pi.GetIpcSubscriber< IntPtr, string, string, object? >( PenumbraIpc.LabelProviderGameObjectResourcePathResolved );
|
||||
}
|
||||
|
||||
private void SubscribeEvents()
|
||||
{
|
||||
if( !_subscribed )
|
||||
{
|
||||
|
||||
_initialized.Subscribe( AddInitialized );
|
||||
_disposed.Subscribe( AddDisposed );
|
||||
_redrawn.Subscribe( SetLastRedrawn );
|
||||
|
|
@ -60,9 +72,14 @@ public class IpcTester : IDisposable
|
|||
_characterBaseCreating.Subscribe( UpdateLastCreated );
|
||||
_characterBaseCreated.Subscribe( UpdateLastCreated2 );
|
||||
_modDirectoryChanged.Subscribe( UpdateModDirectoryChanged );
|
||||
_gameObjectResourcePathResolved.Subscribe( UpdateGameObjectResourcePath );
|
||||
_subscribed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void UnsubscribeEvents()
|
||||
{
|
||||
if( _subscribed )
|
||||
{
|
||||
_initialized.Unsubscribe( AddInitialized );
|
||||
_disposed.Unsubscribe( AddDisposed );
|
||||
|
|
@ -75,7 +92,13 @@ public class IpcTester : IDisposable
|
|||
_characterBaseCreating.Unsubscribe( UpdateLastCreated );
|
||||
_characterBaseCreated.Unsubscribe( UpdateLastCreated2 );
|
||||
_modDirectoryChanged.Unsubscribe( UpdateModDirectoryChanged );
|
||||
_gameObjectResourcePathResolved.Unsubscribe( UpdateGameObjectResourcePath );
|
||||
_subscribed = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
=> UnsubscribeEvents();
|
||||
|
||||
private void AddInitialized()
|
||||
=> _initializedList.Add( DateTimeOffset.UtcNow );
|
||||
|
|
@ -87,6 +110,7 @@ public class IpcTester : IDisposable
|
|||
{
|
||||
try
|
||||
{
|
||||
SubscribeEvents();
|
||||
DrawAvailable();
|
||||
DrawGeneral();
|
||||
DrawResolve();
|
||||
|
|
@ -224,6 +248,10 @@ public class IpcTester : IDisposable
|
|||
private string _lastCreatedGameObjectName = string.Empty;
|
||||
private IntPtr _lastCreatedDrawObject = IntPtr.Zero;
|
||||
private DateTimeOffset _lastCreatedGameObjectTime = DateTimeOffset.MaxValue;
|
||||
private string _lastResolvedGamePath = string.Empty;
|
||||
private string _lastResolvedFullPath = string.Empty;
|
||||
private string _lastResolvedObject = string.Empty;
|
||||
private DateTimeOffset _lastResolvedGamePathTime = DateTimeOffset.MaxValue;
|
||||
|
||||
private unsafe void UpdateLastCreated( IntPtr gameObject, string _, IntPtr _2, IntPtr _3, IntPtr _4 )
|
||||
{
|
||||
|
|
@ -241,6 +269,15 @@ public class IpcTester : IDisposable
|
|||
_lastCreatedDrawObject = drawObject;
|
||||
}
|
||||
|
||||
private unsafe void UpdateGameObjectResourcePath( IntPtr gameObject, string gamePath, string fullPath )
|
||||
{
|
||||
var obj = ( FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* )gameObject;
|
||||
_lastResolvedObject = obj != null ? new Utf8String( obj->GetName() ).ToString() : "Unknown";
|
||||
_lastResolvedGamePath = gamePath;
|
||||
_lastResolvedFullPath = fullPath;
|
||||
_lastResolvedGamePathTime = DateTimeOffset.Now;
|
||||
}
|
||||
|
||||
private void DrawResolve()
|
||||
{
|
||||
using var _ = ImRaii.TreeNode( "Resolve IPC" );
|
||||
|
|
@ -336,6 +373,13 @@ public class IpcTester : IDisposable
|
|||
? $"0x{_lastCreatedDrawObject:X} for <{_lastCreatedGameObjectName}> at {_lastCreatedGameObjectTime}"
|
||||
: $"NULL for <{_lastCreatedGameObjectName}> at {_lastCreatedGameObjectTime}" );
|
||||
}
|
||||
|
||||
DrawIntro( PenumbraIpc.LabelProviderGameObjectResourcePathResolved, "Last GamePath resolved" );
|
||||
if( _lastResolvedGamePathTime < DateTimeOffset.Now )
|
||||
{
|
||||
ImGui.TextUnformatted(
|
||||
$"{_lastResolvedGamePath} -> {_lastResolvedFullPath} for <{_lastResolvedObject}> at {_lastResolvedGamePathTime}" );
|
||||
}
|
||||
}
|
||||
|
||||
private string _redrawName = string.Empty;
|
||||
|
|
|
|||
|
|
@ -95,10 +95,13 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
|
||||
private unsafe void OnResourceLoaded( ResourceHandle* _, Utf8GamePath originalPath, FullPath? manipulatedPath,
|
||||
ResolveData resolveData )
|
||||
{
|
||||
if( resolveData.AssociatedGameObject != IntPtr.Zero )
|
||||
{
|
||||
GameObjectResourceResolved?.Invoke( resolveData.AssociatedGameObject, originalPath.ToString(),
|
||||
manipulatedPath?.ToString() ?? originalPath.ToString() );
|
||||
}
|
||||
}
|
||||
|
||||
public event Action< string, bool >? ModDirectoryChanged
|
||||
{
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ public partial class PenumbraIpc
|
|||
internal ICallGateProvider< string, string[] >? ProviderReverseResolvePathPlayer;
|
||||
internal ICallGateProvider< IntPtr, string, IntPtr, IntPtr, IntPtr, object? >? ProviderCreatingCharacterBase;
|
||||
internal ICallGateProvider< IntPtr, string, IntPtr, object? >? ProviderCreatedCharacterBase;
|
||||
internal ICallGateProvider<IntPtr, string, string, object?>? ProviderGameObjectResourcePathResolved;
|
||||
internal ICallGateProvider< IntPtr, string, string, object? >? ProviderGameObjectResourcePathResolved;
|
||||
|
||||
private void InitializeResolveProviders( DalamudPluginInterface pi )
|
||||
{
|
||||
|
|
@ -392,7 +392,8 @@ public partial class PenumbraIpc
|
|||
|
||||
try
|
||||
{
|
||||
ProviderGameObjectResourcePathResolved = pi.GetIpcProvider<IntPtr, string, string, object?>( LabelProviderGameObjectResourcePathResolved );
|
||||
ProviderGameObjectResourcePathResolved =
|
||||
pi.GetIpcProvider< IntPtr, string, string, object? >( LabelProviderGameObjectResourcePathResolved );
|
||||
Api.GameObjectResourceResolved += GameObjectResourceResolvdedEvent;
|
||||
}
|
||||
catch( Exception e )
|
||||
|
|
|
|||
|
|
@ -422,6 +422,7 @@ public partial class ConfigWindow
|
|||
{
|
||||
if( !ImGui.CollapsingHeader( "IPC" ) )
|
||||
{
|
||||
_window._penumbra.Ipc.Tester.UnsubscribeEvents();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue