- package wow
- import (
- "os"
- "bytes"
- "encoding/binary"
- )
- type DBC interface {
- FromBytes(int, []byte, []byte) os.Error
- }
- func DBCFromBytes(dbc DBC, b []byte) os.Error {
- /*fourcc*/_ = binary.LittleEndian.Uint32(b[0:4])
- /*nRecords*/_ = binary.LittleEndian.Uint32(b[4:8])
- /*nFields*/_ = binary.LittleEndian.Uint32(b[8:12])
- szRecord := int(binary.LittleEndian.Uint32(b[12:16]))
- szString := int(binary.LittleEndian.Uint32(b[16:20]))
- n := len(b)
- records := b[20:n-szString]
- strings := b[n-szString:n]
- return dbc.FromBytes(szRecord, records, strings)
- }
- func dbcString(o, s []byte) string {
- offset := int(binary.LittleEndian.Uint32(o))
- n := bytes.IndexByte(s[offset:], 0x00)
- return string(s[offset:offset+n])
- }
- //
- // Liquid Type
- //
- type DBC_LiquidType struct {
- ID []uint32
- Name []string
- Flags []uint32
- Type []uint32
- Sound []uint32
- Spell []uint32
- Material []uint32
- Texture [][8]string
- }
- func (dbc *DBC_LiquidType) FromBytes(size int, r, s []byte) os.Error {
- n := len(r)/size
- dbc.ID = make([]uint32, n)
- dbc.Name = make([]string, n)
- dbc.Flags = make([]uint32, n)
- dbc.Type = make([]uint32, n)
- dbc.Sound = make([]uint32, n)
- dbc.Spell = make([]uint32, n)
- dbc.Material = make([]uint32, n)
- dbc.Texture = make([][8]string, n)
- for i:=0 ; i < n ; i++ {
- dbc.ID[i] = binary.LittleEndian.Uint32(r[0:4])
- dbc.Name[i] = dbcString(r[4:8], s)
- dbc.Flags[i] = binary.LittleEndian.Uint32(r[8:12])
- dbc.Type[i] = binary.LittleEndian.Uint32(r[12:16])
- dbc.Sound[i] = binary.LittleEndian.Uint32(r[16:20])
- dbc.Spell[i] = binary.LittleEndian.Uint32(r[20:24])
- //[24:60] ???
- dbc.Material[i] = binary.LittleEndian.Uint32(r[60:64])
- dbc.Texture[i][0] = dbcString(r[64:68], s)
- dbc.Texture[i][1] = dbcString(r[68:72], s)
- dbc.Texture[i][2] = dbcString(r[72:76], s)
- dbc.Texture[i][3] = dbcString(r[76:80], s)
- dbc.Texture[i][4] = dbcString(r[80:84], s)
- dbc.Texture[i][5] = dbcString(r[84:88], s)
- dbc.Texture[i][6] = dbcString(r[88:92], s)
- dbc.Texture[i][7] = dbcString(r[92:96], s)
- //[96:184] ???
- r = r[size:]
- }
- return nil
- }
- //
- // Map
- //
- type DBC_Map struct {
- ID []uint32
- Name []string
- Area []uint32
- }
- func (dbc *DBC_Map) FromBytes(size int, r, s []byte) os.Error {
- n := len(r)/size
- dbc.ID = make([]uint32, n)
- dbc.Name = make([]string, n)
- dbc.Area = make([]uint32, n)
- for i:=0 ; i < n ; i++ {
- dbc.ID[i] = binary.LittleEndian.Uint32(r[0:4])
- dbc.Name[i] = dbcString(r[4:8], s)
- dbc.Area[i] = binary.LittleEndian.Uint32(r[8:12])
- // todo
- r = r[size:]
- }
- return nil
- }