From b1c45ef3d70c56a42f1709805132192789ad0846 Mon Sep 17 00:00:00 2001 From: aianlinb Date: Wed, 24 Jun 2020 12:55:00 +0800 Subject: [PATCH] Fix end of file exception 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 --- LibDat/Types/TypeFactory.cs | 4 ++++ LibDat/Types/TypeFactory64.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/LibDat/Types/TypeFactory.cs b/LibDat/Types/TypeFactory.cs index 5350a29..4f4af73 100644 --- a/LibDat/Types/TypeFactory.cs +++ b/LibDat/Types/TypeFactory.cs @@ -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); } @@ -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); diff --git a/LibDat/Types/TypeFactory64.cs b/LibDat/Types/TypeFactory64.cs index 79906e2..e4c98bf 100644 --- a/LibDat/Types/TypeFactory64.cs +++ b/LibDat/Types/TypeFactory64.cs @@ -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); } @@ -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);