From 6a9e0cc31c3340073142778653b6522dfae51ba2 Mon Sep 17 00:00:00 2001 From: Infi Date: Thu, 19 Feb 2026 20:15:58 +0100 Subject: [PATCH] - Add Utf8String extesions (copy of CStringExtension) - Remove debug notes in Nodetree --- .../UiDebug/Browsing/NodeTree.Component.cs | 17 +++--- Dalamud/Utility/Utf8StringExtensions.cs | 60 +++++++++++++++++++ 2 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 Dalamud/Utility/Utf8StringExtensions.cs diff --git a/Dalamud/Interface/Internal/UiDebug/Browsing/NodeTree.Component.cs b/Dalamud/Interface/Internal/UiDebug/Browsing/NodeTree.Component.cs index fb4444be1..b7bb16c46 100644 --- a/Dalamud/Interface/Internal/UiDebug/Browsing/NodeTree.Component.cs +++ b/Dalamud/Interface/Internal/UiDebug/Browsing/NodeTree.Component.cs @@ -1,11 +1,10 @@ using System.Runtime.InteropServices; using Dalamud.Bindings.ImGui; +using Dalamud.Utility; using FFXIVClientStructs.FFXIV.Component.GUI; -using Lumina.Text.ReadOnly; - using static Dalamud.Interface.Internal.UiDebug.Utility.Gui; using static Dalamud.Utility.Util; using static FFXIVClientStructs.FFXIV.Component.GUI.ComponentType; @@ -92,14 +91,14 @@ internal unsafe class ComponentNodeTree : ResNodeTree { case TextInput: var textInputComponent = (AtkComponentTextInput*)this.Component; - ImGui.Text($"InputBase Text1 (Lumina): {new ReadOnlySeStringSpan(textInputComponent->AtkComponentInputBase.EvaluatedString.AsSpan()).ToMacroString()}"); - ImGui.Text($"InputBase Text2 (Lumina): {new ReadOnlySeStringSpan(textInputComponent->AtkComponentInputBase.RawString.AsSpan()).ToMacroString()}"); + ImGui.Text($"InputBase Text1: {textInputComponent->AtkComponentInputBase.EvaluatedString.AsReadOnlySeStringSpan().ToMacroString()}"); + ImGui.Text($"InputBase Text2: {textInputComponent->AtkComponentInputBase.RawString.AsReadOnlySeStringSpan().ToMacroString()}"); // TODO: Reenable when unknowns have been unprivated / named - // ImGui.Text($"Text1: {new ReadOnlySeStringSpan(textInputComponent->UnkText01.AsSpan()).ToMacroString()}"); - // ImGui.Text($"Text2: {new ReadOnlySeStringSpan(textInputComponent->UnkText02.AsSpan()).ToMacroString()}"); - ImGui.Text($"AvailableLines: {new ReadOnlySeStringSpan(textInputComponent->AvailableLines.AsSpan()).ToMacroString()}"); - ImGui.Text($"HighlightedAutoTranslateOptionColorPrefix: {new ReadOnlySeStringSpan(textInputComponent->HighlightedAutoTranslateOptionColorPrefix.AsSpan()).ToMacroString()}"); - ImGui.Text($"HighlightedAutoTranslateOptionColorSuffix: {new ReadOnlySeStringSpan(textInputComponent->HighlightedAutoTranslateOptionColorSuffix.AsSpan()).ToMacroString()}"); + // ImGui.Text($"Text1: {textInputComponent->UnkText01.AsReadOnlySeStringSpan().ToMacroString()}"); + // ImGui.Text($"Text2: {textInputComponent->UnkText02.AsReadOnlySeStringSpan().ToMacroString()}"); + ImGui.Text($"AvailableLines: {textInputComponent->AvailableLines.AsReadOnlySeStringSpan().ToMacroString()}"); + ImGui.Text($"HighlightedAutoTranslateOptionColorPrefix: {textInputComponent->HighlightedAutoTranslateOptionColorPrefix.AsReadOnlySeStringSpan().ToMacroString()}"); + ImGui.Text($"HighlightedAutoTranslateOptionColorSuffix: {textInputComponent->HighlightedAutoTranslateOptionColorSuffix.AsReadOnlySeStringSpan().ToMacroString()}"); break; case List: case TreeList: diff --git a/Dalamud/Utility/Utf8StringExtensions.cs b/Dalamud/Utility/Utf8StringExtensions.cs new file mode 100644 index 000000000..644e0b39f --- /dev/null +++ b/Dalamud/Utility/Utf8StringExtensions.cs @@ -0,0 +1,60 @@ +using Dalamud.Game.Text.SeStringHandling; + +using FFXIVClientStructs.FFXIV.Client.System.String; + +using Lumina.Text.ReadOnly; + +namespace Dalamud.Utility; + +/// +/// A set of helpful utilities for working with s from ClientStructs. +/// +/// +/// WARNING: Will break if a custom ClientStructs is used. These are here for CONVENIENCE ONLY!. +/// +public static class Utf8StringExtensions +{ + /// + /// Convert a Utf8String to a ReadOnlySeStringSpan. + /// + /// The Utf8String to convert. + /// A span. + public static ReadOnlySeStringSpan AsReadOnlySeStringSpan(this Utf8String str) + { + return str.AsSpan(); + } + + /// + /// Convert a Utf8String to a Dalamud SeString. + /// + /// The Utf8String to convert. + /// A Dalamud-flavored SeString. + public static SeString AsDalamudSeString(this Utf8String str) + { + return str.AsReadOnlySeStringSpan().ToDalamudString(); + } + + /// + /// Get a new ReadOnlySeString that's a copy of the text in this Utf8String. + /// + /// + /// This should be functionally identical to , but exists + /// for convenience in places that already expect ReadOnlySeString as a type (and where a copy is desired). + /// + /// The Utf8String to copy. + /// A new Lumina ReadOnlySeString. + public static ReadOnlySeString AsReadOnlySeString(this Utf8String str) + { + return new ReadOnlySeString(str.AsSpan().ToArray()); + } + + /// + /// Extract text from this Utf8String following 's rules. + /// + /// The Utf8String to process. + /// Extracted text. + public static string ExtractText(this Utf8String str) + { + return str.AsReadOnlySeStringSpan().ExtractText(); + } +}