From 0a18f1ceee8fa1823279b7ae6d6b51a48c1be41f Mon Sep 17 00:00:00 2001 From: Ian S Date: Tue, 15 Dec 2020 18:49:14 -0600 Subject: [PATCH] Read strings as raw when reading prefix Fix to binary format 9 reading that forces strings to be decoded as raw text rather than a StringDict reference (which throws a NullReferenceException). This seems to be an intentional decision on Valve's part to keep file reading linear, as the string dictionary comes after the prefix. --- Codecs/Binary.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Codecs/Binary.cs b/Codecs/Binary.cs index 699c33d..65691d8 100644 --- a/Codecs/Binary.cs +++ b/Codecs/Binary.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -315,7 +315,7 @@ public Datamodel Decode(int encoding_version, string format, int format_version, foreach (int attr_index in Enumerable.Range(0, Reader.ReadInt32())) { var name = ReadString_Raw(); - var value = DecodeAttribute(dm); + var value = DecodeAttribute(dm, true); if (prefix_elem == 0) // skip subsequent elements...are they considered "old versions"? dm.PrefixAttributes[name] = value; } @@ -354,7 +354,7 @@ public Datamodel Decode(int encoding_version, string format, int format_version, } else { - elem.Add(name, DecodeAttribute(dm)); + elem.Add(name, DecodeAttribute(dm, false)); } } } @@ -366,15 +366,15 @@ public Datamodel Decode(int encoding_version, string format, int format_version, public object DeferredDecodeAttribute(Datamodel dm, long offset) { Reader.BaseStream.Seek(offset, SeekOrigin.Begin); - return DecodeAttribute(dm); + return DecodeAttribute(dm, false); } - object DecodeAttribute(Datamodel dm) + object DecodeAttribute(Datamodel dm, bool prefix) { var type = IdToType(Reader.ReadByte()); if (!Datamodel.IsDatamodelArrayType(type)) - return ReadValue(dm, type, EncodingVersion < 4); + return ReadValue(dm, type, EncodingVersion < 4 || prefix); else { var count = Reader.ReadInt32();