From b9ae34852925f45d3e7d4a1c07cd159c41ce8655 Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Sun, 10 Jul 2022 14:53:22 +0200 Subject: [PATCH] add GetPlayerMetaManipulations --- Penumbra/Api/IPenumbraApi.cs | 4 ++++ Penumbra/Api/PenumbraApi.cs | 20 ++++++++++++++------ Penumbra/Api/PenumbraIpc.cs | 36 ++++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Penumbra/Api/IPenumbraApi.cs b/Penumbra/Api/IPenumbraApi.cs index 0ba87fca..292d822c 100644 --- a/Penumbra/Api/IPenumbraApi.cs +++ b/Penumbra/Api/IPenumbraApi.cs @@ -137,6 +137,10 @@ public interface IPenumbraApi : IPenumbraApiBase // Note that success does only imply a successful call, not a successful mod load. public PenumbraApiEc AddMod( string modDirectory ); + // Obtain a base64 encoded, zipped json-string with a prepended version-byte of the current manipulations + // for the collection currently associated with the player. + public string GetPlayerMetaManipulations(); + // Obtain a base64 encoded, zipped json-string with a prepended version-byte of the current manipulations // for the given collection associated with the character name, or the default collection. public string GetMetaManipulations( string characterName ); diff --git a/Penumbra/Api/PenumbraApi.cs b/Penumbra/Api/PenumbraApi.cs index 9ce0395f..a620ff54 100644 --- a/Penumbra/Api/PenumbraApi.cs +++ b/Penumbra/Api/PenumbraApi.cs @@ -23,7 +23,7 @@ namespace Penumbra.Api; public class PenumbraApi : IDisposable, IPenumbraApi { public (int, int) ApiVersion - => ( 4, 10 ); + => ( 4, 11 ); private Penumbra? _penumbra; private Lumina.GameData? _lumina; @@ -54,8 +54,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 ); @@ -429,7 +429,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 +475,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi { CheckInitialized(); if( !Penumbra.TempMods.Collections.Values.FindFirst( c => c.Name == collectionName, out var collection ) - && !Penumbra.CollectionManager.ByName( collectionName, out collection ) ) + && !Penumbra.CollectionManager.ByName( collectionName, out collection ) ) { return PenumbraApiEc.CollectionMissing; } @@ -512,7 +512,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi { CheckInitialized(); if( !Penumbra.TempMods.Collections.Values.FindFirst( c => c.Name == collectionName, out var collection ) - && !Penumbra.CollectionManager.ByName( collectionName, out collection ) ) + && !Penumbra.CollectionManager.ByName( collectionName, out collection ) ) { return PenumbraApiEc.CollectionMissing; } @@ -525,6 +525,14 @@ public class PenumbraApi : IDisposable, IPenumbraApi }; } + public string GetPlayerMetaManipulations() + { + CheckInitialized(); + var collection = PathResolver.PlayerCollection(); + var set = collection.MetaCache?.Manipulations.ToArray() ?? Array.Empty< MetaManipulation >(); + return Functions.ToCompressedBase64( set, MetaManipulation.CurrentVersion ); + } + public string GetMetaManipulations( string characterName ) { CheckInitialized(); diff --git a/Penumbra/Api/PenumbraIpc.cs b/Penumbra/Api/PenumbraIpc.cs index fa3f677e..de179d66 100644 --- a/Penumbra/Api/PenumbraIpc.cs +++ b/Penumbra/Api/PenumbraIpc.cs @@ -428,18 +428,20 @@ public partial class PenumbraIpc public partial class PenumbraIpc { - public const string LabelProviderGetMods = "Penumbra.GetMods"; - public const string LabelProviderGetCollections = "Penumbra.GetCollections"; - public const string LabelProviderCurrentCollectionName = "Penumbra.GetCurrentCollectionName"; - public const string LabelProviderDefaultCollectionName = "Penumbra.GetDefaultCollectionName"; - public const string LabelProviderCharacterCollectionName = "Penumbra.GetCharacterCollectionName"; - public const string LabelProviderGetMetaManipulations = "Penumbra.GetMetaManipulations"; + public const string LabelProviderGetMods = "Penumbra.GetMods"; + public const string LabelProviderGetCollections = "Penumbra.GetCollections"; + public const string LabelProviderCurrentCollectionName = "Penumbra.GetCurrentCollectionName"; + public const string LabelProviderDefaultCollectionName = "Penumbra.GetDefaultCollectionName"; + public const string LabelProviderCharacterCollectionName = "Penumbra.GetCharacterCollectionName"; + public const string LabelProviderGetPlayerMetaManipulations = "Penumbra.GetPlayerMetaManipulations"; + public const string LabelProviderGetMetaManipulations = "Penumbra.GetMetaManipulations"; internal ICallGateProvider< IList< (string, string) > >? ProviderGetMods; internal ICallGateProvider< IList< string > >? ProviderGetCollections; internal ICallGateProvider< string >? ProviderCurrentCollectionName; internal ICallGateProvider< string >? ProviderDefaultCollectionName; internal ICallGateProvider< string, (string, bool) >? ProviderCharacterCollectionName; + internal ICallGateProvider< string >? ProviderGetPlayerMetaManipulations; internal ICallGateProvider< string, string >? ProviderGetMetaManipulations; private void InitializeDataProviders( DalamudPluginInterface pi ) @@ -451,7 +453,7 @@ public partial class PenumbraIpc } catch( Exception e ) { - PluginLog.Error( $"Error registering IPC provider for {LabelProviderChangedItemClick}:\n{e}" ); + PluginLog.Error( $"Error registering IPC provider for {LabelProviderGetMods}:\n{e}" ); } try @@ -461,7 +463,7 @@ public partial class PenumbraIpc } catch( Exception e ) { - PluginLog.Error( $"Error registering IPC provider for {LabelProviderChangedItemClick}:\n{e}" ); + PluginLog.Error( $"Error registering IPC provider for {LabelProviderGetCollections}:\n{e}" ); } try @@ -471,7 +473,7 @@ public partial class PenumbraIpc } catch( Exception e ) { - PluginLog.Error( $"Error registering IPC provider for {LabelProviderChangedItemClick}:\n{e}" ); + PluginLog.Error( $"Error registering IPC provider for {LabelProviderCurrentCollectionName}:\n{e}" ); } try @@ -481,7 +483,7 @@ public partial class PenumbraIpc } catch( Exception e ) { - PluginLog.Error( $"Error registering IPC provider for {LabelProviderChangedItemClick}:\n{e}" ); + PluginLog.Error( $"Error registering IPC provider for {LabelProviderDefaultCollectionName}:\n{e}" ); } try @@ -491,7 +493,17 @@ public partial class PenumbraIpc } catch( Exception e ) { - PluginLog.Error( $"Error registering IPC provider for {LabelProviderChangedItemClick}:\n{e}" ); + PluginLog.Error( $"Error registering IPC provider for {LabelProviderCharacterCollectionName}:\n{e}" ); + } + + try + { + ProviderGetPlayerMetaManipulations = pi.GetIpcProvider< string >( LabelProviderGetPlayerMetaManipulations ); + ProviderGetPlayerMetaManipulations.RegisterFunc( Api.GetPlayerMetaManipulations ); + } + catch( Exception e ) + { + PluginLog.Error( $"Error registering IPC provider for {LabelProviderGetPlayerMetaManipulations}:\n{e}" ); } try @@ -501,7 +513,7 @@ public partial class PenumbraIpc } catch( Exception e ) { - PluginLog.Error( $"Error registering IPC provider for {LabelProviderChangedItemClick}:\n{e}" ); + PluginLog.Error( $"Error registering IPC provider for {LabelProviderGetMetaManipulations}:\n{e}" ); } }