d2tbl.LoadTextDictionary now returns an error

This commit is contained in:
gravestench 2021-01-11 01:12:46 -08:00
parent 5a8ba5dee7
commit 2c0f3d9cd9
2 changed files with 11 additions and 7 deletions

View File

@ -1,7 +1,7 @@
package d2tbl
import (
"log"
"errors"
"strconv"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils"
@ -24,7 +24,7 @@ const (
)
// LoadTextDictionary loads the text dictionary from the given data
func LoadTextDictionary(dictionaryData []byte) TextDictionary {
func LoadTextDictionary(dictionaryData []byte) (TextDictionary, error) {
lookupTable := make(TextDictionary)
br := d2datautils.CreateStreamReader(dictionaryData)
@ -37,7 +37,7 @@ func LoadTextDictionary(dictionaryData []byte) TextDictionary {
// Version (always 0)
if _, err := br.ReadByte(); err != nil {
log.Fatal("Error reading Version record")
return nil, errors.New("error reading Version record")
}
br.GetUInt32() // StringOffset
@ -62,6 +62,10 @@ func LoadTextDictionary(dictionaryData []byte) TextDictionary {
}
for idx, hashEntry := range hashEntries {
if br.EOF() {
return nil, errors.New("unexpected end of text dictionary file")
}
if !hashEntry.IsActive {
continue
}
@ -93,5 +97,5 @@ func LoadTextDictionary(dictionaryData []byte) TextDictionary {
}
}
return lookupTable
return lookupTable, nil
}

View File

@ -274,9 +274,9 @@ func (am *AssetManager) LoadStringTable(tablePath string) (d2tbl.TextDictionary,
return nil, err
}
table := d2tbl.LoadTextDictionary(data)
if table == nil {
return nil, fmt.Errorf("table not found: %s", tablePath)
table, err := d2tbl.LoadTextDictionary(data)
if err != nil {
return table, err
}
am.Debugf(fmtLoadStringTable, tablePath)