@@ -303,6 +303,10 @@ func parseStringTable(
303303 flags int32 ,
304304 variantBitCount bool ) (items []* stringTableItem ) {
305305 items = make ([]* stringTableItem , 0 )
306+ // Some tables have no data
307+ if len (buf ) == 0 {
308+ return items
309+ }
306310
307311 // Create a reader for the buffer
308312 r := bit .NewSmallBitReader (bytes .NewReader (buf ))
@@ -312,14 +316,9 @@ func parseStringTable(
312316 index := int32 (- 1 )
313317 keys := make ([]string , 0 , stringtableKeyHistorySize + 1 )
314318
315- // Some tables have no data
316- if len (buf ) == 0 {
317- return items
318- }
319-
320319 // Loop through entries in the data structure
321320 //
322- // Each entry is a tuple consisting of {index, key, value}
321+ // Each entry is a tuple consisting of {index, missing m_iItemDefinitionIndex property key, value}
323322 //
324323 // Index can either be incremented from the previous position or
325324 // overwritten with a given entry.
@@ -373,46 +372,49 @@ func parseStringTable(
373372 if len (keys ) > stringtableKeyHistorySize {
374373 keys = keys [1 :]
375374 }
376- }
377375
378- // Some entries have a value.
379- hasValue := r .ReadBit ()
380- if hasValue {
381- bitSize := uint (0 )
382- isCompressed := false
383- if userDataFixed {
384- bitSize = uint (userDataSize )
385- } else {
386- if (flags & 0x1 ) != 0 {
387- isCompressed = r .ReadBit ()
388- }
376+ // Some entries have a value.
377+ hasValue := r .ReadBit ()
378+ if hasValue {
379+ bitSize := uint (0 )
380+ isCompressed := false
389381
390- if variantBitCount {
391- bitSize = r . ReadUBitInt () * 8
382+ if userDataFixed {
383+ bitSize = uint ( userDataSize )
392384 } else {
393- bitSize = r .ReadInt (17 ) * 8
385+ if (flags & 0x1 ) != 0 {
386+ isCompressed = r .ReadBit ()
387+ }
388+
389+ if variantBitCount {
390+ bitSize = r .ReadUBitInt () * 8
391+ } else {
392+ bitSize = r .ReadInt (17 ) * 8
393+ }
394394 }
395- }
396- value = r .ReadBits (int (bitSize ))
397395
398- if isCompressed {
399- tmp , err := snappy .Decode (nil , value )
400- if err != nil {
401- panic (fmt .Sprintf ("unable to decode snappy compressed stringtable item (%s, %d, %s): %s" , name , index , key , err ))
396+ value = r .ReadBits (int (bitSize ))
397+
398+ if isCompressed {
399+ tmp , err := snappy .Decode (nil , value )
400+ if err != nil {
401+ panic (fmt .Sprintf ("unable to decode snappy compressed stringtable item (%s, %d, %s): %s" , name , index , key , err ))
402+ }
403+
404+ value = tmp
402405 }
403- value = tmp
404406 }
405- }
406407
407- items = append (items , & stringTableItem {index , key , value })
408+ items = append (items , & stringTableItem {index , key , value })
409+ }
408410 }
409411
410412 return items
411413}
412414
413415var instanceBaselineKeyRegex = regexp .MustCompile (`^\d+:\d+$` )
414416
415- func (p * parser ) processStringTableS2 (tab createStringTable , br * bit. BitReader ) {
417+ func (p * parser ) processStringTableS2 (tab createStringTable ) {
416418 items := parseStringTable (tab .StringData , tab .GetNumEntries (), tab .GetName (), tab .GetUserDataFixedSize (), tab .GetUserDataSize (), tab .GetFlags (), tab .GetUsingVarintBitcounts ())
417419
418420 for _ , item := range items {
@@ -452,23 +454,23 @@ func (p *parser) processStringTable(tab createStringTable) {
452454 tab .StringData = b
453455 }
454456
455- br := bit .NewSmallBitReader (bytes .NewReader (tab .StringData ))
456-
457457 if tab .isS2 {
458- p .processStringTableS2 (tab , br )
458+ p .processStringTableS2 (tab )
459459 } else {
460+ br := bit .NewSmallBitReader (bytes .NewReader (tab .StringData ))
461+
460462 if br .ReadBit () {
461463 panic ("unknown stringtable format" )
462464 }
463465
464466 p .processStringTableS1 (tab , br )
467+
468+ p .poolBitReader (br )
465469 }
466470
467471 if tab .GetName () == stNameModelPreCache {
468472 p .processModelPreCacheUpdate ()
469473 }
470-
471- p .poolBitReader (br )
472474}
473475
474476func parsePlayerInfo (reader io.Reader ) common.PlayerInfo {
0 commit comments