mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-23 08:17:59 +01:00
Added an event when a newly created draw object finishes CharacterBase.Create.
This commit is contained in:
parent
5b5a1e2fd8
commit
80edfe7804
6 changed files with 54 additions and 153 deletions
|
|
@ -26,6 +26,8 @@ public delegate void ModSettingChanged( ModSettingChange type, string collection
|
|||
public delegate void CreatingCharacterBaseDelegate( IntPtr gameObject, ModCollection collection, IntPtr modelId, IntPtr customize,
|
||||
IntPtr equipData );
|
||||
|
||||
public delegate void CreatedCharacterBaseDelegate( IntPtr gameObject, ModCollection collection, IntPtr drawObject );
|
||||
|
||||
public enum PenumbraApiEc
|
||||
{
|
||||
Success = 0,
|
||||
|
|
@ -73,6 +75,10 @@ public interface IPenumbraApi : IPenumbraApiBase
|
|||
// before the Draw Object is actually created, so customize and equipdata can be manipulated beforehand.
|
||||
public event CreatingCharacterBaseDelegate? CreatingCharacterBase;
|
||||
|
||||
// Triggered after a character base was created if a corresponding gameObject could be found,
|
||||
// so you can apply flag changes after finishing.
|
||||
public event CreatedCharacterBaseDelegate? CreatedCharacterBase;
|
||||
|
||||
// Queue redrawing of all actors of the given name with the given RedrawType.
|
||||
public void RedrawObject( string name, RedrawType setting );
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ public class IpcTester : IDisposable
|
|||
private readonly ICallGateSubscriber< string, bool, object? > _modDirectoryChanged;
|
||||
private readonly ICallGateSubscriber< IntPtr, int, object? > _redrawn;
|
||||
private readonly ICallGateSubscriber< ModSettingChange, string, string, bool, object? > _settingChanged;
|
||||
private readonly ICallGateSubscriber< IntPtr, string, IntPtr, IntPtr, IntPtr, object? > _characterBaseCreated;
|
||||
private readonly ICallGateSubscriber< IntPtr, string, IntPtr, IntPtr, IntPtr, object? > _characterBaseCreating;
|
||||
private readonly ICallGateSubscriber< IntPtr, string, IntPtr, object? > _characterBaseCreated;
|
||||
|
||||
private readonly List< DateTimeOffset > _initializedList = new();
|
||||
private readonly List< DateTimeOffset > _disposedList = new();
|
||||
|
|
@ -47,15 +48,17 @@ public class IpcTester : IDisposable
|
|||
_postSettingsDraw = _pi.GetIpcSubscriber< string, object? >( PenumbraIpc.LabelProviderPostSettingsDraw );
|
||||
_settingChanged = _pi.GetIpcSubscriber< ModSettingChange, string, string, bool, object? >( PenumbraIpc.LabelProviderModSettingChanged );
|
||||
_modDirectoryChanged = _pi.GetIpcSubscriber< string, bool, object? >( PenumbraIpc.LabelProviderModDirectoryChanged );
|
||||
_characterBaseCreated =
|
||||
_characterBaseCreating =
|
||||
_pi.GetIpcSubscriber< IntPtr, string, IntPtr, IntPtr, IntPtr, object? >( PenumbraIpc.LabelProviderCreatingCharacterBase );
|
||||
_characterBaseCreated = _pi.GetIpcSubscriber< IntPtr, string, IntPtr, object? >( PenumbraIpc.LabelProviderCreatedCharacterBase );
|
||||
_initialized.Subscribe( AddInitialized );
|
||||
_disposed.Subscribe( AddDisposed );
|
||||
_redrawn.Subscribe( SetLastRedrawn );
|
||||
_preSettingsDraw.Subscribe( UpdateLastDrawnMod );
|
||||
_postSettingsDraw.Subscribe( UpdateLastDrawnMod );
|
||||
_settingChanged.Subscribe( UpdateLastModSetting );
|
||||
_characterBaseCreated.Subscribe( UpdateLastCreated );
|
||||
_characterBaseCreating.Subscribe( UpdateLastCreated );
|
||||
_characterBaseCreated.Subscribe( UpdateLastCreated2 );
|
||||
_modDirectoryChanged.Subscribe( UpdateModDirectoryChanged );
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +72,8 @@ public class IpcTester : IDisposable
|
|||
_preSettingsDraw.Unsubscribe( UpdateLastDrawnMod );
|
||||
_postSettingsDraw.Unsubscribe( UpdateLastDrawnMod );
|
||||
_settingChanged.Unsubscribe( UpdateLastModSetting );
|
||||
_characterBaseCreated.Unsubscribe( UpdateLastCreated );
|
||||
_characterBaseCreating.Unsubscribe( UpdateLastCreated );
|
||||
_characterBaseCreated.Unsubscribe( UpdateLastCreated2 );
|
||||
_modDirectoryChanged.Unsubscribe( UpdateModDirectoryChanged );
|
||||
}
|
||||
|
||||
|
|
@ -218,6 +222,7 @@ public class IpcTester : IDisposable
|
|||
private IntPtr _currentDrawObject = IntPtr.Zero;
|
||||
private int _currentCutsceneActor = 0;
|
||||
private string _lastCreatedGameObjectName = string.Empty;
|
||||
private IntPtr _lastCreatedDrawObject = IntPtr.Zero;
|
||||
private DateTimeOffset _lastCreatedGameObjectTime = DateTimeOffset.MaxValue;
|
||||
|
||||
private unsafe void UpdateLastCreated( IntPtr gameObject, string _, IntPtr _2, IntPtr _3, IntPtr _4 )
|
||||
|
|
@ -225,6 +230,15 @@ public class IpcTester : IDisposable
|
|||
var obj = ( FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* )gameObject;
|
||||
_lastCreatedGameObjectName = new Utf8String( obj->GetName() ).ToString();
|
||||
_lastCreatedGameObjectTime = DateTimeOffset.Now;
|
||||
_lastCreatedDrawObject = IntPtr.Zero;
|
||||
}
|
||||
|
||||
private unsafe void UpdateLastCreated2( IntPtr gameObject, string _, IntPtr drawObject )
|
||||
{
|
||||
var obj = ( FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* )gameObject;
|
||||
_lastCreatedGameObjectName = new Utf8String( obj->GetName() ).ToString();
|
||||
_lastCreatedGameObjectTime = DateTimeOffset.Now;
|
||||
_lastCreatedDrawObject = drawObject;
|
||||
}
|
||||
|
||||
private void DrawResolve()
|
||||
|
|
@ -318,7 +332,9 @@ public class IpcTester : IDisposable
|
|||
DrawIntro( PenumbraIpc.LabelProviderCreatingCharacterBase, "Last Drawobject created" );
|
||||
if( _lastCreatedGameObjectTime < DateTimeOffset.Now )
|
||||
{
|
||||
ImGui.TextUnformatted( $"for <{_lastCreatedGameObjectName}> at {_lastCreatedGameObjectTime}" );
|
||||
ImGui.TextUnformatted( _lastCreatedDrawObject != IntPtr.Zero
|
||||
? $"0x{_lastCreatedDrawObject:X} for <{_lastCreatedGameObjectName}> at {_lastCreatedGameObjectTime}"
|
||||
: $"NULL for <{_lastCreatedGameObjectName}> at {_lastCreatedGameObjectTime}" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,12 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
|||
remove => PathResolver.DrawObjectState.CreatingCharacterBase -= value;
|
||||
}
|
||||
|
||||
public event CreatedCharacterBaseDelegate? CreatedCharacterBase
|
||||
{
|
||||
add => PathResolver.DrawObjectState.CreatedCharacterBase += value;
|
||||
remove => PathResolver.DrawObjectState.CreatedCharacterBase -= value;
|
||||
}
|
||||
|
||||
public bool Valid
|
||||
=> _penumbra != null;
|
||||
|
||||
|
|
|
|||
|
|
@ -282,6 +282,7 @@ public partial class PenumbraIpc
|
|||
public const string LabelProviderReverseResolvePath = "Penumbra.ReverseResolvePath";
|
||||
public const string LabelProviderReverseResolvePlayerPath = "Penumbra.ReverseResolvePlayerPath";
|
||||
public const string LabelProviderCreatingCharacterBase = "Penumbra.CreatingCharacterBase";
|
||||
public const string LabelProviderCreatedCharacterBase = "Penumbra.CreatedCharacterBase";
|
||||
|
||||
internal ICallGateProvider< string, string >? ProviderResolveDefault;
|
||||
internal ICallGateProvider< string, string, string >? ProviderResolveCharacter;
|
||||
|
|
@ -291,6 +292,7 @@ public partial class PenumbraIpc
|
|||
internal ICallGateProvider< string, string, string[] >? ProviderReverseResolvePath;
|
||||
internal ICallGateProvider< string, string[] >? ProviderReverseResolvePathPlayer;
|
||||
internal ICallGateProvider< IntPtr, string, IntPtr, IntPtr, IntPtr, object? >? ProviderCreatingCharacterBase;
|
||||
internal ICallGateProvider< IntPtr, string, IntPtr, object? >? ProviderCreatedCharacterBase;
|
||||
|
||||
private void InitializeResolveProviders( DalamudPluginInterface pi )
|
||||
{
|
||||
|
|
@ -374,6 +376,17 @@ public partial class PenumbraIpc
|
|||
{
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderCreatingCharacterBase}:\n{e}" );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ProviderCreatedCharacterBase =
|
||||
pi.GetIpcProvider< IntPtr, string, IntPtr, object? >( LabelProviderCreatedCharacterBase );
|
||||
Api.CreatedCharacterBase += CreatedCharacterBaseEvent;
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderCreatedCharacterBase}:\n{e}" );
|
||||
}
|
||||
}
|
||||
|
||||
private void DisposeResolveProviders()
|
||||
|
|
@ -385,12 +398,18 @@ public partial class PenumbraIpc
|
|||
ProviderReverseResolvePath?.UnregisterFunc();
|
||||
ProviderReverseResolvePathPlayer?.UnregisterFunc();
|
||||
Api.CreatingCharacterBase -= CreatingCharacterBaseEvent;
|
||||
Api.CreatedCharacterBase -= CreatedCharacterBaseEvent;
|
||||
}
|
||||
|
||||
private void CreatingCharacterBaseEvent( IntPtr gameObject, ModCollection collection, IntPtr modelId, IntPtr customize, IntPtr equipData )
|
||||
{
|
||||
ProviderCreatingCharacterBase?.SendMessage( gameObject, collection.Name, modelId, customize, equipData );
|
||||
}
|
||||
|
||||
private void CreatedCharacterBaseEvent( IntPtr gameObject, ModCollection collection, IntPtr drawObject )
|
||||
{
|
||||
ProviderCreatedCharacterBase?.SendMessage( gameObject, collection.Name, drawObject );
|
||||
}
|
||||
}
|
||||
|
||||
public partial class PenumbraIpc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue