改了一亿个东西,修了一亿个 BUG
This commit is contained in:
40
ReplayFile/ReplayExtensions.cs
Normal file
40
ReplayFile/ReplayExtensions.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace AnotherReplayReader.ReplayFile
|
||||
{
|
||||
internal static class ReplayExtensions
|
||||
{
|
||||
public static string ReadUTF16String(this BinaryReader reader)
|
||||
{
|
||||
var currentBytes = new List<byte>();
|
||||
var lastTwoBytes = Array.Empty<byte>();
|
||||
while (true)
|
||||
{
|
||||
lastTwoBytes = reader.ReadBytes(2);
|
||||
if (lastTwoBytes.Length != 2)
|
||||
{
|
||||
throw new InvalidDataException();
|
||||
}
|
||||
if (lastTwoBytes.All(x => x == 0))
|
||||
{
|
||||
break;
|
||||
}
|
||||
currentBytes.AddRange(lastTwoBytes);
|
||||
}
|
||||
|
||||
return Encoding.Unicode.GetString(currentBytes.ToArray());
|
||||
}
|
||||
|
||||
public static void Write(this BinaryWriter writer, ReplayChunk chunk) => chunk.WriteTo(writer);
|
||||
|
||||
public static void Write(this BinaryWriter writer, ReplayFooter footer) => footer.WriteTo(writer);
|
||||
|
||||
public static void Write(this BinaryWriter writer, Replay replay) => replay.WriteTo(writer);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user