Add cutscene identification and IPC, reorder PathResolver stuff.

This commit is contained in:
Ottermandias 2022-08-09 22:12:15 +02:00
parent dc61f362fd
commit 8fdd173388
21 changed files with 1326 additions and 1323 deletions

View file

@ -124,6 +124,9 @@ public interface IPenumbraApi : IPenumbraApiBase
// Obtain the game object associated with a given draw object and the name of the collection associated with this game object.
public (IntPtr, string) GetDrawObjectInfo( IntPtr drawObject );
// Obtain the parent game object index for an unnamed cutscene actor by its index.
public int GetCutsceneParentIndex( int actor );
// Obtain a list of all installed mods. The first string is their directory name, the second string is their mod name.
public IList< (string, string) > GetModList();

View file

@ -201,6 +201,7 @@ public class IpcTester : IDisposable
private string _currentDrawObjectString = string.Empty;
private string _currentReversePath = string.Empty;
private IntPtr _currentDrawObject = IntPtr.Zero;
private int _currentCutsceneActor = 0;
private string _lastCreatedGameObjectName = string.Empty;
private DateTimeOffset _lastCreatedGameObjectTime = DateTimeOffset.MaxValue;
@ -231,6 +232,8 @@ public class IpcTester : IDisposable
: IntPtr.Zero;
}
ImGui.InputInt( "Cutscene Actor", ref _currentCutsceneActor, 0 );
using var table = ImRaii.Table( string.Empty, 3, ImGuiTableFlags.SizingFixedFit );
if( !table )
{
@ -263,6 +266,10 @@ public class IpcTester : IDisposable
ImGui.TextUnformatted( ptr == IntPtr.Zero ? $"No Actor Associated, {collection}" : $"{ptr:X}, {collection}" );
}
DrawIntro( PenumbraIpc.LabelProviderGetDrawObjectInfo, "Cutscene Parent" );
ImGui.TextUnformatted( _pi.GetIpcSubscriber< int, int >( PenumbraIpc.LabelProviderGetCutsceneParentIndex )
.InvokeFunc( _currentCutsceneActor ).ToString() );
DrawIntro( PenumbraIpc.LabelProviderReverseResolvePath, "Reversed Game Paths" );
if( _currentReversePath.Length > 0 )
{

View file

@ -6,7 +6,6 @@ using System.Linq;
using System.Reflection;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Logging;
using FFXIVClientStructs.FFXIV.Common.Configuration;
using Lumina.Data;
using Newtonsoft.Json;
using OtterGui;
@ -16,14 +15,13 @@ using Penumbra.GameData.Enums;
using Penumbra.Interop.Resolver;
using Penumbra.Meta.Manipulations;
using Penumbra.Mods;
using Penumbra.Util;
namespace Penumbra.Api;
public class PenumbraApi : IDisposable, IPenumbraApi
{
public (int, int) ApiVersion
=> ( 4, 11 );
=> ( 4, 12 );
private Penumbra? _penumbra;
private Lumina.GameData? _lumina;
@ -43,8 +41,8 @@ public class PenumbraApi : IDisposable, IPenumbraApi
public event CreatingCharacterBaseDelegate? CreatingCharacterBase
{
add => _penumbra!.PathResolver.CreatingCharacterBase += value;
remove => _penumbra!.PathResolver.CreatingCharacterBase -= value;
add => PathResolver.DrawObjectState.CreatingCharacterBase += value;
remove => PathResolver.DrawObjectState.CreatingCharacterBase -= value;
}
public bool Valid
@ -54,8 +52,8 @@ public class PenumbraApi : IDisposable, IPenumbraApi
{
_penumbra = penumbra;
_lumina = ( Lumina.GameData? )Dalamud.GameData.GetType()
.GetField( "gameData", BindingFlags.Instance | BindingFlags.NonPublic )
?.GetValue( Dalamud.GameData );
.GetField( "gameData", BindingFlags.Instance | BindingFlags.NonPublic )
?.GetValue( Dalamud.GameData );
foreach( var collection in Penumbra.CollectionManager )
{
SubscribeToCollection( collection );
@ -221,10 +219,16 @@ public class PenumbraApi : IDisposable, IPenumbraApi
public (IntPtr, string) GetDrawObjectInfo( IntPtr drawObject )
{
CheckInitialized();
var (obj, collection) = _penumbra!.PathResolver.IdentifyDrawObject( drawObject );
var (obj, collection) = PathResolver.IdentifyDrawObject( drawObject );
return ( obj, collection.Name );
}
public int GetCutsceneParentIndex( int actor )
{
CheckInitialized();
return _penumbra!.PathResolver.CutsceneActor( actor );
}
public IList< (string, string) > GetModList()
{
CheckInitialized();
@ -429,7 +433,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
}
if( !forceOverwriteCharacter && Penumbra.CollectionManager.Characters.ContainsKey( character )
|| Penumbra.TempMods.Collections.ContainsKey( character ) )
|| Penumbra.TempMods.Collections.ContainsKey( character ) )
{
return ( PenumbraApiEc.CharacterCollectionExists, string.Empty );
}
@ -475,7 +479,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
{
CheckInitialized();
if( !Penumbra.TempMods.CollectionByName( collectionName, out var collection )
&& !Penumbra.CollectionManager.ByName( collectionName, out collection ) )
&& !Penumbra.CollectionManager.ByName( collectionName, out collection ) )
{
return PenumbraApiEc.CollectionMissing;
}
@ -512,7 +516,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi
{
CheckInitialized();
if( !Penumbra.TempMods.CollectionByName( collectionName, out var collection )
&& !Penumbra.CollectionManager.ByName( collectionName, out collection ) )
&& !Penumbra.CollectionManager.ByName( collectionName, out collection ) )
{
return PenumbraApiEc.CollectionMissing;
}

View file

@ -261,6 +261,7 @@ public partial class PenumbraIpc
public const string LabelProviderResolveCharacter = "Penumbra.ResolveCharacterPath";
public const string LabelProviderResolvePlayer = "Penumbra.ResolvePlayerPath";
public const string LabelProviderGetDrawObjectInfo = "Penumbra.GetDrawObjectInfo";
public const string LabelProviderGetCutsceneParentIndex = "Penumbra.GetCutsceneParentIndex";
public const string LabelProviderReverseResolvePath = "Penumbra.ReverseResolvePath";
public const string LabelProviderReverseResolvePlayerPath = "Penumbra.ReverseResolvePlayerPath";
public const string LabelProviderCreatingCharacterBase = "Penumbra.CreatingCharacterBase";
@ -269,6 +270,7 @@ public partial class PenumbraIpc
internal ICallGateProvider< string, string, string >? ProviderResolveCharacter;
internal ICallGateProvider< string, string >? ProviderResolvePlayer;
internal ICallGateProvider< IntPtr, (IntPtr, string) >? ProviderGetDrawObjectInfo;
internal ICallGateProvider< int, int >? ProviderGetCutsceneParentIndex;
internal ICallGateProvider< string, string, string[] >? ProviderReverseResolvePath;
internal ICallGateProvider< string, string[] >? ProviderReverseResolvePathPlayer;
internal ICallGateProvider< IntPtr, string, IntPtr, IntPtr, IntPtr, object? >? ProviderCreatingCharacterBase;
@ -315,6 +317,16 @@ public partial class PenumbraIpc
PluginLog.Error( $"Error registering IPC provider for {LabelProviderGetDrawObjectInfo}:\n{e}" );
}
try
{
ProviderGetCutsceneParentIndex = pi.GetIpcProvider<int, int>( LabelProviderGetCutsceneParentIndex );
ProviderGetCutsceneParentIndex.RegisterFunc( Api.GetCutsceneParentIndex );
}
catch( Exception e )
{
PluginLog.Error( $"Error registering IPC provider for {LabelProviderGetCutsceneParentIndex}:\n{e}" );
}
try
{
ProviderReverseResolvePath = pi.GetIpcProvider< string, string, string[] >( LabelProviderReverseResolvePath );
@ -350,6 +362,7 @@ public partial class PenumbraIpc
private void DisposeResolveProviders()
{
ProviderGetDrawObjectInfo?.UnregisterFunc();
ProviderGetCutsceneParentIndex?.UnregisterFunc();
ProviderResolveDefault?.UnregisterFunc();
ProviderResolveCharacter?.UnregisterFunc();
ProviderReverseResolvePath?.UnregisterFunc();