NvapiUnicodeString.cs
1 using System.Runtime.InteropServices; 2 using System.Text; 3 4 namespace Ryujinx.Common.GraphicsDriver.NVAPI 5 { 6 [StructLayout(LayoutKind.Sequential, Pack = 4)] 7 public unsafe struct NvapiUnicodeString 8 { 9 private fixed byte _data[4096]; 10 11 public NvapiUnicodeString(string text) 12 { 13 Set(text); 14 } 15 16 public readonly string Get() 17 { 18 fixed (byte* data = _data) 19 { 20 string text = Encoding.Unicode.GetString(data, 4096); 21 22 int index = text.IndexOf('\0'); 23 if (index > -1) 24 { 25 text = text.Remove(index); 26 } 27 28 return text; 29 } 30 } 31 32 public readonly void Set(string text) 33 { 34 text += '\0'; 35 fixed (char* textPtr = text) 36 fixed (byte* data = _data) 37 { 38 int written = Encoding.Unicode.GetBytes(textPtr, text.Length, data, 4096); 39 } 40 } 41 } 42 }