mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-15 13:14:17 +01:00
add Penumbra.ObjectIsRedrawn and Penumbra.ReverseResolvePath to API
This commit is contained in:
parent
086f90171e
commit
45d8d58ce2
6 changed files with 194 additions and 127 deletions
|
|
@ -51,6 +51,7 @@ public interface IPenumbraApi : IPenumbraApiBase
|
||||||
|
|
||||||
// Triggered when the user clicks a listed changed object in a mod tab.
|
// Triggered when the user clicks a listed changed object in a mod tab.
|
||||||
public event ChangedItemClick? ChangedItemClicked;
|
public event ChangedItemClick? ChangedItemClicked;
|
||||||
|
event EventHandler? ObjectIsRedrawn;
|
||||||
|
|
||||||
// Queue redrawing of all actors of the given name with the given RedrawType.
|
// Queue redrawing of all actors of the given name with the given RedrawType.
|
||||||
public void RedrawObject( string name, RedrawType setting );
|
public void RedrawObject( string name, RedrawType setting );
|
||||||
|
|
@ -72,6 +73,9 @@ public interface IPenumbraApi : IPenumbraApiBase
|
||||||
// Returns the given gamePath if penumbra would not manipulate it.
|
// Returns the given gamePath if penumbra would not manipulate it.
|
||||||
public string ResolvePath( string gamePath, string characterName );
|
public string ResolvePath( string gamePath, string characterName );
|
||||||
|
|
||||||
|
// Reverse resolves a given modded local path into its replacement in form of all applicable game path for given character
|
||||||
|
public string[] ReverseResolvePath( string moddedPath, string characterName );
|
||||||
|
|
||||||
// Try to load a given gamePath with the resolved path from Penumbra.
|
// Try to load a given gamePath with the resolved path from Penumbra.
|
||||||
public T? GetFile< T >( string gamePath ) where T : FileResource;
|
public T? GetFile< T >( string gamePath ) where T : FileResource;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
||||||
public int ApiVersion { get; } = 4;
|
public int ApiVersion { get; } = 4;
|
||||||
private Penumbra? _penumbra;
|
private Penumbra? _penumbra;
|
||||||
private Lumina.GameData? _lumina;
|
private Lumina.GameData? _lumina;
|
||||||
|
public event EventHandler? ObjectIsRedrawn;
|
||||||
|
|
||||||
public bool Valid
|
public bool Valid
|
||||||
=> _penumbra != null;
|
=> _penumbra != null;
|
||||||
|
|
@ -30,10 +31,17 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
||||||
_lumina = ( Lumina.GameData? )Dalamud.GameData.GetType()
|
_lumina = ( Lumina.GameData? )Dalamud.GameData.GetType()
|
||||||
.GetField( "gameData", BindingFlags.Instance | BindingFlags.NonPublic )
|
.GetField( "gameData", BindingFlags.Instance | BindingFlags.NonPublic )
|
||||||
?.GetValue( Dalamud.GameData );
|
?.GetValue( Dalamud.GameData );
|
||||||
|
_penumbra.ObjectReloader.ObjectIsRedrawn += ObjectReloader_ObjectIsRedrawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ObjectReloader_ObjectIsRedrawn( object? sender, EventArgs e )
|
||||||
|
{
|
||||||
|
ObjectIsRedrawn?.Invoke( sender, e );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
_penumbra!.ObjectReloader.ObjectIsRedrawn -= ObjectReloader_ObjectIsRedrawn;
|
||||||
_penumbra = null;
|
_penumbra = null;
|
||||||
_lumina = null;
|
_lumina = null;
|
||||||
}
|
}
|
||||||
|
|
@ -121,6 +129,20 @@ public class PenumbraApi : IDisposable, IPenumbraApi
|
||||||
Penumbra.CollectionManager.Character( characterName ) );
|
Penumbra.CollectionManager.Character( characterName ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string[] ReverseResolvePath( string path, string characterName )
|
||||||
|
{
|
||||||
|
CheckInitialized();
|
||||||
|
if( !Penumbra.Config.EnableMods )
|
||||||
|
{
|
||||||
|
return new[] { path };
|
||||||
|
}
|
||||||
|
|
||||||
|
var gamePath = Utf8GamePath.FromString( path, out var p, true ) ? p : Utf8GamePath.Empty;
|
||||||
|
var ret = Penumbra.CollectionManager.Character( characterName ).ResolveReversePath( new FullPath( path ) ) ?? new List<Utf8GamePath>();
|
||||||
|
if( ret.Count == 0 ) ret.Add( gamePath );
|
||||||
|
return ret.Select( r => r.ToString() ).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
private T? GetFileIntern<T>( string resolvedPath ) where T : FileResource
|
private T? GetFileIntern<T>( string resolvedPath ) where T : FileResource
|
||||||
{
|
{
|
||||||
CheckInitialized();
|
CheckInitialized();
|
||||||
|
|
|
||||||
|
|
@ -115,11 +115,13 @@ public partial class PenumbraIpc
|
||||||
public const string LabelProviderRedrawIndex = "Penumbra.RedrawObjectByIndex";
|
public const string LabelProviderRedrawIndex = "Penumbra.RedrawObjectByIndex";
|
||||||
public const string LabelProviderRedrawObject = "Penumbra.RedrawObject";
|
public const string LabelProviderRedrawObject = "Penumbra.RedrawObject";
|
||||||
public const string LabelProviderRedrawAll = "Penumbra.RedrawAll";
|
public const string LabelProviderRedrawAll = "Penumbra.RedrawAll";
|
||||||
|
public const string LabelProviderObjectIsRedrawn = "Penumbra.ObjectIsRedrawn";
|
||||||
|
|
||||||
internal ICallGateProvider<string, int, object>? ProviderRedrawName;
|
internal ICallGateProvider<string, int, object>? ProviderRedrawName;
|
||||||
internal ICallGateProvider<int, int, object>? ProviderRedrawIndex;
|
internal ICallGateProvider<int, int, object>? ProviderRedrawIndex;
|
||||||
internal ICallGateProvider<GameObject, int, object>? ProviderRedrawObject;
|
internal ICallGateProvider<GameObject, int, object>? ProviderRedrawObject;
|
||||||
internal ICallGateProvider<int, object>? ProviderRedrawAll;
|
internal ICallGateProvider<int, object>? ProviderRedrawAll;
|
||||||
|
internal ICallGateProvider<string, string> ProviderObjectIsRedrawn;
|
||||||
|
|
||||||
private static RedrawType CheckRedrawType( int value )
|
private static RedrawType CheckRedrawType( int value )
|
||||||
{
|
{
|
||||||
|
|
@ -173,6 +175,21 @@ public partial class PenumbraIpc
|
||||||
{
|
{
|
||||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderRedrawAll}:\n{e}" );
|
PluginLog.Error( $"Error registering IPC provider for {LabelProviderRedrawAll}:\n{e}" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProviderObjectIsRedrawn = pi.GetIpcProvider<string, string>( LabelProviderObjectIsRedrawn );
|
||||||
|
Api.ObjectIsRedrawn += Api_ObjectIsRedrawn;
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
PluginLog.Error( $"Error registering IPC provider for {LabelProviderObjectIsRedrawn}:\n{e}" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Api_ObjectIsRedrawn( object? sender, EventArgs e )
|
||||||
|
{
|
||||||
|
ProviderObjectIsRedrawn.SendMessage( ( ( GameObject? )sender )?.Name.ToString() ?? "" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DisposeRedrawProviders()
|
private void DisposeRedrawProviders()
|
||||||
|
|
@ -181,6 +198,7 @@ public partial class PenumbraIpc
|
||||||
ProviderRedrawIndex?.UnregisterAction();
|
ProviderRedrawIndex?.UnregisterAction();
|
||||||
ProviderRedrawObject?.UnregisterAction();
|
ProviderRedrawObject?.UnregisterAction();
|
||||||
ProviderRedrawAll?.UnregisterAction();
|
ProviderRedrawAll?.UnregisterAction();
|
||||||
|
Api.ObjectIsRedrawn -= Api_ObjectIsRedrawn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,10 +207,12 @@ public partial class PenumbraIpc
|
||||||
public const string LabelProviderResolveDefault = "Penumbra.ResolveDefaultPath";
|
public const string LabelProviderResolveDefault = "Penumbra.ResolveDefaultPath";
|
||||||
public const string LabelProviderResolveCharacter = "Penumbra.ResolveCharacterPath";
|
public const string LabelProviderResolveCharacter = "Penumbra.ResolveCharacterPath";
|
||||||
public const string LabelProviderGetDrawObjectInfo = "Penumbra.GetDrawObjectInfo";
|
public const string LabelProviderGetDrawObjectInfo = "Penumbra.GetDrawObjectInfo";
|
||||||
|
public const string LabelProviderReverseResolvePath = "Penumbra.ReverseResolvePath";
|
||||||
|
|
||||||
internal ICallGateProvider<string, string>? ProviderResolveDefault;
|
internal ICallGateProvider<string, string>? ProviderResolveDefault;
|
||||||
internal ICallGateProvider<string, string, string>? ProviderResolveCharacter;
|
internal ICallGateProvider<string, string, string>? ProviderResolveCharacter;
|
||||||
internal ICallGateProvider<IntPtr, (IntPtr, string)>? ProviderGetDrawObjectInfo;
|
internal ICallGateProvider<IntPtr, (IntPtr, string)>? ProviderGetDrawObjectInfo;
|
||||||
|
internal ICallGateProvider<string, string, string[]>? ProviderReverseResolvePath;
|
||||||
|
|
||||||
private void InitializeResolveProviders( DalamudPluginInterface pi )
|
private void InitializeResolveProviders( DalamudPluginInterface pi )
|
||||||
{
|
{
|
||||||
|
|
@ -225,6 +245,16 @@ public partial class PenumbraIpc
|
||||||
{
|
{
|
||||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderGetDrawObjectInfo}:\n{e}" );
|
PluginLog.Error( $"Error registering IPC provider for {LabelProviderGetDrawObjectInfo}:\n{e}" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProviderReverseResolvePath = pi.GetIpcProvider<string, string, string[]>( LabelProviderReverseResolvePath );
|
||||||
|
ProviderReverseResolvePath.RegisterFunc( Api.ReverseResolvePath );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
PluginLog.Error( $"Error registering IPC provider for {LabelProviderGetDrawObjectInfo}:\n{e}" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DisposeResolveProviders()
|
private void DisposeResolveProviders()
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ public partial class ModCollection
|
||||||
PluginLog.Verbose( "Cleared cache of collection {Name:l}.", Name );
|
PluginLog.Verbose( "Cleared cache of collection {Name:l}.", Name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Utf8GamePath>? ResolveReversePath( FullPath path ) => _cache?.ReverseResolvePath( path );
|
||||||
|
|
||||||
public FullPath? ResolvePath( Utf8GamePath path )
|
public FullPath? ResolvePath( Utf8GamePath path )
|
||||||
=> _cache?.ResolvePath( path );
|
=> _cache?.ResolvePath( path );
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,13 @@ public partial class ModCollection
|
||||||
return candidate.Path;
|
return candidate.Path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Utf8GamePath> ReverseResolvePath( FullPath localFilePath )
|
||||||
|
{
|
||||||
|
string strToSearchFor = localFilePath.FullName.Replace( '/', '\\' ).ToLower();
|
||||||
|
return ResolvedFiles.Where( f => f.Value.Path.FullName.ToLower() == strToSearchFor )
|
||||||
|
.Select( kvp => kvp.Key ).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnModSettingChange( ModSettingChange type, int modIdx, int oldValue, int groupIdx, bool _ )
|
private void OnModSettingChange( ModSettingChange type, int modIdx, int oldValue, int groupIdx, bool _ )
|
||||||
{
|
{
|
||||||
switch( type )
|
switch( type )
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ public unsafe partial class ObjectReloader
|
||||||
private static void EnableDraw( GameObject actor )
|
private static void EnableDraw( GameObject actor )
|
||||||
=> ( ( delegate* unmanaged< IntPtr, void >** )actor.Address )[ 0 ][ 16 ]( actor.Address );
|
=> ( ( delegate* unmanaged< IntPtr, void >** )actor.Address )[ 0 ][ 16 ]( actor.Address );
|
||||||
|
|
||||||
|
public event EventHandler? ObjectIsRedrawn;
|
||||||
|
|
||||||
// Check whether we currently are in GPose.
|
// Check whether we currently are in GPose.
|
||||||
// Also clear the name list.
|
// Also clear the name list.
|
||||||
|
|
@ -281,6 +282,8 @@ public sealed unsafe partial class ObjectReloader : IDisposable
|
||||||
break;
|
break;
|
||||||
default: throw new ArgumentOutOfRangeException( nameof( settings ), settings, null );
|
default: throw new ArgumentOutOfRangeException( nameof( settings ), settings, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObjectIsRedrawn?.Invoke( actor, new EventArgs() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GameObject? GetLocalPlayer()
|
private static GameObject? GetLocalPlayer()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue