mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2026-01-11 20:10:38 +00:00
use a helper for creating null-terminated byte arrays out of System.String instead of duplicating the logic
This commit is contained in:
parent
d17025a4ab
commit
3b82cc5ccd
1 changed files with 13 additions and 6 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue