Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions code/HellMapManager/Services/API/Dll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,18 @@ public static unsafe string Input(IntPtr ptr, int encoding)
}
public static byte[] Raw(IntPtr ptr, int encoding)
{
if (ptr == IntPtr.Zero) return Array.Empty<byte>();
if (ptr == IntPtr.Zero) return [];
try
{
var str = Marshal.PtrToStringAnsi(ptr) ?? "";
var data = encoding switch
int length = 0;
while (Marshal.ReadByte(ptr, length) != 0)
{
1 => gb18030Encoding.GetBytes(str),
_ => Encoding.UTF8.GetBytes(str),
};
return data;
length++;
}

byte[] destination = new byte[length];
Marshal.Copy(ptr, destination, 0, length);
return destination;
}
catch (Exception)
{
Expand Down