Skip to content

Commit 0a18f1c

Browse files
authored
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.
1 parent 8ad741f commit 0a18f1c

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

Codecs/Binary.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
@@ -315,7 +315,7 @@ public Datamodel Decode(int encoding_version, string format, int format_version,
315315
foreach (int attr_index in Enumerable.Range(0, Reader.ReadInt32()))
316316
{
317317
var name = ReadString_Raw();
318-
var value = DecodeAttribute(dm);
318+
var value = DecodeAttribute(dm, true);
319319
if (prefix_elem == 0) // skip subsequent elements...are they considered "old versions"?
320320
dm.PrefixAttributes[name] = value;
321321
}
@@ -354,7 +354,7 @@ public Datamodel Decode(int encoding_version, string format, int format_version,
354354
}
355355
else
356356
{
357-
elem.Add(name, DecodeAttribute(dm));
357+
elem.Add(name, DecodeAttribute(dm, false));
358358
}
359359
}
360360
}
@@ -366,15 +366,15 @@ public Datamodel Decode(int encoding_version, string format, int format_version,
366366
public object DeferredDecodeAttribute(Datamodel dm, long offset)
367367
{
368368
Reader.BaseStream.Seek(offset, SeekOrigin.Begin);
369-
return DecodeAttribute(dm);
369+
return DecodeAttribute(dm, false);
370370
}
371371

372-
object DecodeAttribute(Datamodel dm)
372+
object DecodeAttribute(Datamodel dm, bool prefix)
373373
{
374374
var type = IdToType(Reader.ReadByte());
375375

376376
if (!Datamodel.IsDatamodelArrayType(type))
377-
return ReadValue(dm, type, EncodingVersion < 4);
377+
return ReadValue(dm, type, EncodingVersion < 4 || prefix);
378378
else
379379
{
380380
var count = Reader.ReadInt32();

0 commit comments

Comments
 (0)