mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Add testing to IPC Meta.
This commit is contained in:
parent
c8ad4bc106
commit
242c0ee38f
4 changed files with 29 additions and 13 deletions
|
|
@ -146,11 +146,12 @@ public class MetaApi(IFramework framework, CollectionResolver collectionResolver
|
||||||
/// The empty string is treated as an empty set.
|
/// The empty string is treated as an empty set.
|
||||||
/// Only returns true if all conversions are successful and distinct.
|
/// Only returns true if all conversions are successful and distinct.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static bool ConvertManips(string manipString, [NotNullWhen(true)] out MetaDictionary? manips)
|
internal static bool ConvertManips(string manipString, [NotNullWhen(true)] out MetaDictionary? manips, out byte version)
|
||||||
{
|
{
|
||||||
if (manipString.Length == 0)
|
if (manipString.Length == 0)
|
||||||
{
|
{
|
||||||
manips = new MetaDictionary();
|
manips = new MetaDictionary();
|
||||||
|
version = byte.MaxValue;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,9 +164,9 @@ public class MetaApi(IFramework framework, CollectionResolver collectionResolver
|
||||||
zipStream.CopyTo(resultStream);
|
zipStream.CopyTo(resultStream);
|
||||||
resultStream.Flush();
|
resultStream.Flush();
|
||||||
resultStream.Position = 0;
|
resultStream.Position = 0;
|
||||||
var data = resultStream.GetBuffer().AsSpan(0, (int)resultStream.Length);
|
var data = resultStream.GetBuffer().AsSpan(0, (int)resultStream.Length);
|
||||||
var version = data[0];
|
version = data[0];
|
||||||
data = data[1..];
|
data = data[1..];
|
||||||
switch (version)
|
switch (version)
|
||||||
{
|
{
|
||||||
case 0: return ConvertManipsV0(data, out manips);
|
case 0: return ConvertManipsV0(data, out manips);
|
||||||
|
|
@ -179,7 +180,8 @@ public class MetaApi(IFramework framework, CollectionResolver collectionResolver
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Penumbra.Log.Debug($"Error decompressing manipulations:\n{ex}");
|
Penumbra.Log.Debug($"Error decompressing manipulations:\n{ex}");
|
||||||
manips = null;
|
manips = null;
|
||||||
|
version = byte.MaxValue;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -274,7 +276,7 @@ public class MetaApi(IFramework framework, CollectionResolver collectionResolver
|
||||||
var json = Encoding.UTF8.GetString(data);
|
var json = Encoding.UTF8.GetString(data);
|
||||||
manips = JsonConvert.DeserializeObject<MetaDictionary>(json);
|
manips = JsonConvert.DeserializeObject<MetaDictionary>(json);
|
||||||
return manips != null;
|
return manips != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void TestMetaManipulations()
|
internal void TestMetaManipulations()
|
||||||
{
|
{
|
||||||
|
|
@ -291,11 +293,11 @@ public class MetaApi(IFramework framework, CollectionResolver collectionResolver
|
||||||
var v1Time = watch.ElapsedMilliseconds;
|
var v1Time = watch.ElapsedMilliseconds;
|
||||||
|
|
||||||
watch.Restart();
|
watch.Restart();
|
||||||
var v1Success = ConvertManips(v1, out var v1Roundtrip);
|
var v1Success = ConvertManips(v1, out var v1Roundtrip, out _);
|
||||||
var v1RoundtripTime = watch.ElapsedMilliseconds;
|
var v1RoundtripTime = watch.ElapsedMilliseconds;
|
||||||
|
|
||||||
watch.Restart();
|
watch.Restart();
|
||||||
var v0Success = ConvertManips(v0, out var v0Roundtrip);
|
var v0Success = ConvertManips(v0, out var v0Roundtrip, out _);
|
||||||
var v0RoundtripTime = watch.ElapsedMilliseconds;
|
var v0RoundtripTime = watch.ElapsedMilliseconds;
|
||||||
|
|
||||||
Penumbra.Log.Information($"Version | Count | Time | Length | Success | ReCount | ReTime | Equal");
|
Penumbra.Log.Information($"Version | Count | Time | Length | Success | ReCount | ReTime | Equal");
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ public class TemporaryApi(
|
||||||
if (!ConvertPaths(paths, out var p))
|
if (!ConvertPaths(paths, out var p))
|
||||||
return ApiHelpers.Return(PenumbraApiEc.InvalidGamePath, args);
|
return ApiHelpers.Return(PenumbraApiEc.InvalidGamePath, args);
|
||||||
|
|
||||||
if (!MetaApi.ConvertManips(manipString, out var m))
|
if (!MetaApi.ConvertManips(manipString, out var m, out _))
|
||||||
return ApiHelpers.Return(PenumbraApiEc.InvalidManipulation, args);
|
return ApiHelpers.Return(PenumbraApiEc.InvalidManipulation, args);
|
||||||
|
|
||||||
var ret = tempMods.Register(tag, null, p, m, new ModPriority(priority)) switch
|
var ret = tempMods.Register(tag, null, p, m, new ModPriority(priority)) switch
|
||||||
|
|
@ -86,7 +86,7 @@ public class TemporaryApi(
|
||||||
if (!ConvertPaths(paths, out var p))
|
if (!ConvertPaths(paths, out var p))
|
||||||
return ApiHelpers.Return(PenumbraApiEc.InvalidGamePath, args);
|
return ApiHelpers.Return(PenumbraApiEc.InvalidGamePath, args);
|
||||||
|
|
||||||
if (!MetaApi.ConvertManips(manipString, out var m))
|
if (!MetaApi.ConvertManips(manipString, out var m, out _))
|
||||||
return ApiHelpers.Return(PenumbraApiEc.InvalidManipulation, args);
|
return ApiHelpers.Return(PenumbraApiEc.InvalidManipulation, args);
|
||||||
|
|
||||||
var ret = tempMods.Register(tag, collection, p, m, new ModPriority(priority)) switch
|
var ret = tempMods.Register(tag, collection, p, m, new ModPriority(priority)) switch
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,19 @@ using Dalamud.Plugin;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using OtterGui.Raii;
|
using OtterGui.Raii;
|
||||||
using OtterGui.Services;
|
using OtterGui.Services;
|
||||||
|
using OtterGui.Text;
|
||||||
|
using Penumbra.Api.Api;
|
||||||
using Penumbra.Api.IpcSubscribers;
|
using Penumbra.Api.IpcSubscribers;
|
||||||
|
using Penumbra.Meta.Manipulations;
|
||||||
|
|
||||||
namespace Penumbra.Api.IpcTester;
|
namespace Penumbra.Api.IpcTester;
|
||||||
|
|
||||||
public class MetaIpcTester(IDalamudPluginInterface pi) : IUiService
|
public class MetaIpcTester(IDalamudPluginInterface pi) : IUiService
|
||||||
{
|
{
|
||||||
private int _gameObjectIndex;
|
private int _gameObjectIndex;
|
||||||
|
private string _metaBase64 = string.Empty;
|
||||||
|
private MetaDictionary _metaDict = new();
|
||||||
|
private byte _parsedVersion = byte.MaxValue;
|
||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
|
|
@ -17,6 +23,11 @@ public class MetaIpcTester(IDalamudPluginInterface pi) : IUiService
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ImGui.InputInt("##metaIdx", ref _gameObjectIndex, 0, 0);
|
ImGui.InputInt("##metaIdx", ref _gameObjectIndex, 0, 0);
|
||||||
|
if (ImUtf8.InputText("##metaText"u8, ref _metaBase64, "Base64 Metadata..."u8))
|
||||||
|
if (!MetaApi.ConvertManips(_metaBase64, out _metaDict, out _parsedVersion))
|
||||||
|
_metaDict ??= new MetaDictionary();
|
||||||
|
|
||||||
|
|
||||||
using var table = ImRaii.Table(string.Empty, 3, ImGuiTableFlags.SizingFixedFit);
|
using var table = ImRaii.Table(string.Empty, 3, ImGuiTableFlags.SizingFixedFit);
|
||||||
if (!table)
|
if (!table)
|
||||||
return;
|
return;
|
||||||
|
|
@ -34,5 +45,8 @@ public class MetaIpcTester(IDalamudPluginInterface pi) : IUiService
|
||||||
var base64 = new GetMetaManipulations(pi).Invoke(_gameObjectIndex);
|
var base64 = new GetMetaManipulations(pi).Invoke(_gameObjectIndex);
|
||||||
ImGui.SetClipboardText(base64);
|
ImGui.SetClipboardText(base64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IpcTester.DrawIntro(string.Empty, "Parsed Data");
|
||||||
|
ImUtf8.Text($"Version: {_parsedVersion}, Count: {_metaDict.Count}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ public abstract class MetaDrawer<TIdentifier, TEntry>(ModMetaEditor editor, Meta
|
||||||
if (!ImUtf8.IconButton(FontAwesomeIcon.Clipboard, tooltip))
|
if (!ImUtf8.IconButton(FontAwesomeIcon.Clipboard, tooltip))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var text = Functions.ToCompressedBase64(manipulations.Value, MetaApi.CurrentVersion);
|
var text = Functions.ToCompressedBase64(manipulations.Value, 0);
|
||||||
if (text.Length > 0)
|
if (text.Length > 0)
|
||||||
ImGui.SetClipboardText(text);
|
ImGui.SetClipboardText(text);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue