diff --git a/Dalamud/Game/Libc/LibcFunction.cs b/Dalamud/Game/Libc/LibcFunction.cs index 4c58376f2..7dfc26b3b 100644 --- a/Dalamud/Game/Libc/LibcFunction.cs +++ b/Dalamud/Game/Libc/LibcFunction.cs @@ -4,6 +4,7 @@ using System.Text; using Dalamud.IoC; using Dalamud.IoC.Internal; +using Dalamud.Plugin.Services; namespace Dalamud.Game.Libc; @@ -13,7 +14,10 @@ namespace Dalamud.Game.Libc; [PluginInterface] [InterfaceVersion("1.0")] [ServiceManager.BlockingEarlyLoadedService] -public sealed class LibcFunction : IServiceType +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning restore SA1015 +public sealed class LibcFunction : IServiceType, ILibcFunction { private readonly LibcFunctionAddressResolver address; private readonly StdStringFromCStringDelegate stdStringCtorCString; @@ -37,11 +41,7 @@ public sealed class LibcFunction : IServiceType [UnmanagedFunctionPointer(CallingConvention.ThisCall)] private delegate IntPtr StdStringDeallocateDelegate(IntPtr address); - /// - /// Create a new string from the given bytes. - /// - /// The bytes to convert. - /// An owned std string object. + /// public OwnedStdString NewString(byte[] content) { // While 0x70 bytes in the memory should be enough in DX11 version, @@ -56,14 +56,9 @@ public sealed class LibcFunction : IServiceType return new OwnedStdString(pReallocString, this.DeallocateStdString); } - - /// - /// Create a new string form the given bytes. - /// - /// The bytes to convert. - /// A non-default encoding. - /// An owned std string object. - public OwnedStdString NewString(string content, Encoding encoding = null) + + /// + public OwnedStdString NewString(string content, Encoding? encoding = null) { encoding ??= Encoding.UTF8; diff --git a/Dalamud/Plugin/Services/ILibcFunction.cs b/Dalamud/Plugin/Services/ILibcFunction.cs new file mode 100644 index 000000000..bebd62936 --- /dev/null +++ b/Dalamud/Plugin/Services/ILibcFunction.cs @@ -0,0 +1,26 @@ +using System.Text; + +using Dalamud.Game.Libc; + +namespace Dalamud.Plugin.Services; + +/// +/// This class handles creating cstrings utilizing native game methods. +/// +public interface ILibcFunction +{ + /// + /// Create a new string from the given bytes. + /// + /// The bytes to convert. + /// An owned std string object. + public OwnedStdString NewString(byte[] content); + + /// + /// Create a new string form the given bytes. + /// + /// The bytes to convert. + /// A non-default encoding. + /// An owned std string object. + public OwnedStdString NewString(string content, Encoding? encoding = null); +}