diff --git a/src/Ryujinx.Graphics.RenderDocApi/RenderDoc.cs b/src/Ryujinx.Graphics.RenderDocApi/RenderDoc.cs index 600e43f43..0782b4a90 100644 --- a/src/Ryujinx.Graphics.RenderDocApi/RenderDoc.cs +++ b/src/Ryujinx.Graphics.RenderDocApi/RenderDoc.cs @@ -75,7 +75,7 @@ namespace Ryujinx.Graphics.RenderDocApi } set { - fixed (byte* ptr = Encoding.UTF8.GetBytes(value + '\0')) + fixed (byte* ptr = value.ToNullTerminatedByteArray()) { Api->SetCaptureFilePathTemplate(ptr); } @@ -254,7 +254,7 @@ namespace Ryujinx.Graphics.RenderDocApi fixed (byte* ptr = bytes) Api->GetCapture(index, ptr, &length, ×tamp); - string fileName = Encoding.UTF8.GetString(bytes.Slice(length)); + string fileName = Encoding.UTF8.GetString(bytes[length..]); return new Capture(index, fileName, DateTimeOffset.FromUnixTimeSeconds(timestamp).DateTime); } @@ -272,7 +272,7 @@ namespace Ryujinx.Graphics.RenderDocApi return Api->LaunchReplayUI(connectTargetControl ? 1 : 0, null) != 0; } - fixed (byte* ptr = Encoding.UTF8.GetBytes(commandLine + '\0')) + fixed (byte* ptr = commandLine.ToNullTerminatedByteArray()) { return Api->LaunchReplayUI(connectTargetControl ? 1 : 0, ptr) != 0; } @@ -339,7 +339,7 @@ namespace Ryujinx.Graphics.RenderDocApi { AssertAtLeast(1, 2); - byte[] commentBytes = Encoding.UTF8.GetBytes(comments + '\0'); + byte[] commentBytes = comments.ToNullTerminatedByteArray(); fixed (byte* pcomment = commentBytes) { @@ -349,7 +349,7 @@ namespace Ryujinx.Graphics.RenderDocApi } else { - byte[] fileBytes = Encoding.UTF8.GetBytes(fileName + '\0'); + byte[] fileBytes = fileName.ToNullTerminatedByteArray(); fixed (byte* pfile = fileBytes) { @@ -407,7 +407,7 @@ namespace Ryujinx.Graphics.RenderDocApi public static void SetCaptureTitle(string title) { AssertAtLeast(1, 6); - fixed (byte* ptr = Encoding.UTF8.GetBytes(title + '\0')) + fixed (byte* ptr = title.ToNullTerminatedByteArray()) Api->SetCaptureTitle(ptr); } @@ -511,6 +511,13 @@ namespace Ryujinx.Graphics.RenderDocApi private static RenderDocVersion SystemVersionToRenderdocVersion(Version version) => (RenderDocVersion)(version.Major * 10000 + version.Minor * 100 + version.Build); + private static byte[] ToNullTerminatedByteArray(this string str, Encoding? encoding = null) + { + encoding ??= Encoding.UTF8; + + return encoding.GetBytes(str + '\0'); + } + #endregion } }