mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-09 01:56:47 -05:00
d2tbl.LoadTextDictionary now returns an error
This commit is contained in:
parent
5a8ba5dee7
commit
2c0f3d9cd9
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user