Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Fix end of file exception
Browse files Browse the repository at this point in the history
Fix EOFException caused by pointing to the end of the file to express an empty string (or something not yet added?) in some dats
For example: SkillSurgeEffects.dat
  • Loading branch information
aianlinb authored Jun 24, 2020
1 parent 7e58b21 commit b1c45ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions LibDat/Types/TypeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static class TypeFactory
{typeof (ulong), s => s.ReadUInt64()},
{typeof (string), s =>
{
if (s.BaseStream.Position == s.BaseStream.Length)
return "{null}"; //Fix EOFException caused by pointing to the end of the file to express an empty string (or something not yet added?) in some dats
var sb = new StringBuilder();
char ch;
while ((ch = s.ReadChar()) != 0) { sb.Append(ch); }
Expand All @@ -54,6 +56,8 @@ public static class TypeFactory
{typeof (ulong), (bw, o) => bw.Write((ulong)o)},
{typeof (string), (bw, o) =>
{
if (bw.BaseStream.Position == bw.BaseStream.Length)
return;
foreach (var ch in (string)o)
{
bw.Write(ch);
Expand Down
4 changes: 4 additions & 0 deletions LibDat/Types/TypeFactory64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public static class TypeFactory64
},
{typeof (string), s =>
{
if (s.BaseStream.Position == s.BaseStream.Length)
return "{null}"; ////Fix EOFException caused by pointing to the end of the file to express an empty string (or something not yet added?) in some dats
var sb = new StringBuilder();
char ch;
while ((ch = s.ReadChar()) != 0) { sb.Append(ch); }
Expand Down Expand Up @@ -77,6 +79,8 @@ public static class TypeFactory64
},
{typeof (string), (bw, o) =>
{
if (bw.BaseStream.Position == bw.BaseStream.Length)
return;
foreach (var ch in (string)o)
{
bw.Write(ch);
Expand Down

0 comments on commit b1c45ef

Please sign in to comment.