fix unif loading of mapper names with junk in field beyond end of null termination. also made it utf-8 while i'm in there.
This commit is contained in:
parent
a7bf968554
commit
b41c223464
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
@ -27,14 +28,22 @@ namespace BizHawk.Common.IOExtensions
|
|||
public static string ReadStringFixedAscii(this BinaryReader r, int bytes)
|
||||
{
|
||||
var read = new byte[bytes];
|
||||
for (var b = 0; b < bytes; b++)
|
||||
{
|
||||
read[b] = r.ReadByte();
|
||||
}
|
||||
|
||||
r.Read(read, 0, bytes);
|
||||
return Encoding.UTF8.GetString(read);
|
||||
}
|
||||
|
||||
public static string ReadStringUtf8NullTerminated(this BinaryReader br)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
for (; ; )
|
||||
{
|
||||
var b = br.ReadByte();
|
||||
if (b == 0)
|
||||
return System.Text.Encoding.UTF8.GetString(ms.ToArray());
|
||||
ms.WriteByte(b);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyTo(this Stream src, Stream dest)
|
||||
{
|
||||
int size = (src.CanSeek) ? Math.Min((int)(src.Length - src.Position), 0x2000) : 0x2000;
|
||||
|
|
|
@ -5,6 +5,8 @@ using System.Text;
|
|||
using System.IO;
|
||||
|
||||
using BizHawk.Common.BufferExtensions;
|
||||
using BizHawk.Common.IOExtensions;
|
||||
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.NES
|
||||
{
|
||||
|
@ -81,7 +83,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
|
|||
|
||||
if (chunks.TryGetValue("MAPR", out tmp))
|
||||
{
|
||||
ci.board_type = Encoding.ASCII.GetString(tmp);
|
||||
ci.board_type = new BinaryReader(new MemoryStream(tmp)).ReadStringUtf8NullTerminated();
|
||||
}
|
||||
|
||||
ci.board_type = ci.board_type.TrimEnd('\0');
|
||||
|
|
Loading…
Reference in New Issue