Skip to content

Commit

Permalink
Fix #14
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed Apr 14, 2022
1 parent 69c3eaa commit 58dc7b1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions BundleUtilities/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,23 @@ public static bool EOF(this BinaryReader self)

public static string ReadCStr(this BinaryReader self)
{
StringBuilder sb = new StringBuilder();
List<byte> bytes = new List<byte>();

try
{
while (true)
{
char c = (char)self.ReadByte();
byte c = self.ReadByte();
if (c == '\0')
break;
sb.Append(c);
bytes.Add(c);
}
}
catch (EndOfStreamException)
{
// Ignore
}

return sb.ToString();
return Encoding.UTF8.GetString(bytes.ToArray());
}

public static byte[] Flip(this byte[] self)
Expand Down Expand Up @@ -136,12 +135,14 @@ public static string ReadCStringPtr(this BinaryReader self)

public static void WriteCStr(this BinaryWriter self, string value)
{
for (int i = 0; i < value.Length; i++)
byte[] bytes = Encoding.UTF8.GetBytes(value);
for (int i = 0; i < bytes.Length; i++)
{
self.Write((byte)value[i]);
self.Write(bytes[i]);
}
self.Write((byte) 0);
}

// Add padding: Has to be divisible by 16, else add padding
public static void WritePadding(this BinaryWriter self)
{
Expand Down

0 comments on commit 58dc7b1

Please sign in to comment.