Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 2.63 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package wow
  2.  
  3. import (
  4.         "os"
  5.         "bytes"
  6.         "encoding/binary"
  7. )
  8.  
  9. type DBC interface {
  10.         FromBytes(int, []byte, []byte) os.Error
  11. }
  12.  
  13. func DBCFromBytes(dbc DBC, b []byte) os.Error {
  14.         /*fourcc*/_ = binary.LittleEndian.Uint32(b[0:4])
  15.         /*nRecords*/_ = binary.LittleEndian.Uint32(b[4:8])
  16.         /*nFields*/_ = binary.LittleEndian.Uint32(b[8:12])
  17.         szRecord := int(binary.LittleEndian.Uint32(b[12:16]))
  18.         szString := int(binary.LittleEndian.Uint32(b[16:20]))
  19.  
  20.         n := len(b)
  21.         records := b[20:n-szString]
  22.         strings := b[n-szString:n]
  23.  
  24.         return dbc.FromBytes(szRecord, records, strings)
  25. }
  26.  
  27. func dbcString(o, s []byte) string {
  28.         offset := int(binary.LittleEndian.Uint32(o))
  29.         n := bytes.IndexByte(s[offset:], 0x00)
  30.         return string(s[offset:offset+n])
  31. }
  32.  
  33. //
  34. // Liquid Type
  35. //
  36.  
  37. type DBC_LiquidType struct {
  38.         ID       []uint32
  39.         Name     []string
  40.         Flags    []uint32
  41.         Type     []uint32
  42.         Sound    []uint32
  43.         Spell    []uint32
  44.         Material []uint32
  45.         Texture  [][8]string
  46. }
  47. func (dbc *DBC_LiquidType) FromBytes(size int, r, s []byte) os.Error {
  48.         n := len(r)/size
  49.         dbc.ID       = make([]uint32, n)
  50.         dbc.Name     = make([]string, n)
  51.         dbc.Flags    = make([]uint32, n)
  52.         dbc.Type     = make([]uint32, n)
  53.         dbc.Sound    = make([]uint32, n)
  54.         dbc.Spell    = make([]uint32, n)
  55.         dbc.Material = make([]uint32, n)
  56.         dbc.Texture  = make([][8]string, n)
  57.         for i:=0 ; i < n ; i++ {
  58.                 dbc.ID[i]    = binary.LittleEndian.Uint32(r[0:4])
  59.                 dbc.Name[i]  = dbcString(r[4:8], s)
  60.                 dbc.Flags[i] = binary.LittleEndian.Uint32(r[8:12])
  61.                 dbc.Type[i]  = binary.LittleEndian.Uint32(r[12:16])
  62.                 dbc.Sound[i] = binary.LittleEndian.Uint32(r[16:20])
  63.                 dbc.Spell[i] = binary.LittleEndian.Uint32(r[20:24])
  64.                 //[24:60] ???
  65.                 dbc.Material[i] = binary.LittleEndian.Uint32(r[60:64])
  66.                 dbc.Texture[i][0] = dbcString(r[64:68], s)
  67.                 dbc.Texture[i][1] = dbcString(r[68:72], s)
  68.                 dbc.Texture[i][2] = dbcString(r[72:76], s)
  69.                 dbc.Texture[i][3] = dbcString(r[76:80], s)
  70.                 dbc.Texture[i][4] = dbcString(r[80:84], s)
  71.                 dbc.Texture[i][5] = dbcString(r[84:88], s)
  72.                 dbc.Texture[i][6] = dbcString(r[88:92], s)
  73.                 dbc.Texture[i][7] = dbcString(r[92:96], s)
  74.                 //[96:184] ???
  75.  
  76.                 r = r[size:]
  77.         }
  78.         return nil
  79. }
  80.  
  81. //
  82. // Map
  83. //
  84.  
  85. type DBC_Map struct {
  86.         ID       []uint32
  87.         Name     []string
  88.         Area     []uint32
  89. }
  90. func (dbc *DBC_Map) FromBytes(size int, r, s []byte) os.Error {
  91.         n := len(r)/size
  92.         dbc.ID   = make([]uint32, n)
  93.         dbc.Name = make([]string, n)
  94.         dbc.Area = make([]uint32, n)
  95.         for i:=0 ; i < n ; i++ {
  96.                 dbc.ID[i]   = binary.LittleEndian.Uint32(r[0:4])
  97.                 dbc.Name[i] = dbcString(r[4:8], s)
  98.                 dbc.Area[i] = binary.LittleEndian.Uint32(r[8:12])
  99.                 // todo
  100.  
  101.                 r = r[size:]
  102.         }
  103.         return nil
  104. }