mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-10 10:36:42 -05:00
d2tbl.LoadTextDictionary now returns an error
This commit is contained in:
parent
5a8ba5dee7
commit
2c0f3d9cd9
@ -1,7 +1,7 @@
|
|||||||
package d2tbl
|
package d2tbl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils"
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2datautils"
|
||||||
@ -24,7 +24,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// LoadTextDictionary loads the text dictionary from the given data
|
// LoadTextDictionary loads the text dictionary from the given data
|
||||||
func LoadTextDictionary(dictionaryData []byte) TextDictionary {
|
func LoadTextDictionary(dictionaryData []byte) (TextDictionary, error) {
|
||||||
lookupTable := make(TextDictionary)
|
lookupTable := make(TextDictionary)
|
||||||
|
|
||||||
br := d2datautils.CreateStreamReader(dictionaryData)
|
br := d2datautils.CreateStreamReader(dictionaryData)
|
||||||
@ -37,7 +37,7 @@ func LoadTextDictionary(dictionaryData []byte) TextDictionary {
|
|||||||
|
|
||||||
// Version (always 0)
|
// Version (always 0)
|
||||||
if _, err := br.ReadByte(); err != nil {
|
if _, err := br.ReadByte(); err != nil {
|
||||||
log.Fatal("Error reading Version record")
|
return nil, errors.New("error reading Version record")
|
||||||
}
|
}
|
||||||
|
|
||||||
br.GetUInt32() // StringOffset
|
br.GetUInt32() // StringOffset
|
||||||
@ -62,6 +62,10 @@ func LoadTextDictionary(dictionaryData []byte) TextDictionary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for idx, hashEntry := range hashEntries {
|
for idx, hashEntry := range hashEntries {
|
||||||
|
if br.EOF() {
|
||||||
|
return nil, errors.New("unexpected end of text dictionary file")
|
||||||
|
}
|
||||||
|
|
||||||
if !hashEntry.IsActive {
|
if !hashEntry.IsActive {
|
||||||
continue
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
table := d2tbl.LoadTextDictionary(data)
|
table, err := d2tbl.LoadTextDictionary(data)
|
||||||
if table == nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("table not found: %s", tablePath)
|
return table, err
|
||||||
}
|
}
|
||||||
|
|
||||||
am.Debugf(fmtLoadStringTable, tablePath)
|
am.Debugf(fmtLoadStringTable, tablePath)
|
||||||
|
Loading…
Reference in New Issue
Block a user