2020-01-26 00:39:13 -05:00
|
|
|
package d2dcc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DCC struct {
|
|
|
|
Signature int
|
|
|
|
Version int
|
|
|
|
NumberOfDirections int
|
|
|
|
FramesPerDirection int
|
2020-06-24 10:13:11 -04:00
|
|
|
Directions []*DCCDirection
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadDCC(fileData []byte) (*DCC, error) {
|
|
|
|
result := &DCC{}
|
|
|
|
var bm = d2common.CreateBitMuncher(fileData, 0)
|
|
|
|
result.Signature = int(bm.GetByte())
|
|
|
|
if result.Signature != 0x74 {
|
2020-02-01 21:51:49 -05:00
|
|
|
return nil, errors.New("signature expected to be 0x74 but it is not")
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
|
|
|
result.Version = int(bm.GetByte())
|
|
|
|
result.NumberOfDirections = int(bm.GetByte())
|
|
|
|
result.FramesPerDirection = int(bm.GetInt32())
|
|
|
|
if bm.GetInt32() != 1 {
|
2020-02-01 21:51:49 -05:00
|
|
|
return nil, errors.New("this value isn't 1. It has to be 1")
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
|
|
|
bm.GetInt32() // TotalSizeCoded
|
|
|
|
directionOffsets := make([]int, result.NumberOfDirections)
|
|
|
|
for i := 0; i < result.NumberOfDirections; i++ {
|
|
|
|
directionOffsets[i] = int(bm.GetInt32())
|
|
|
|
}
|
2020-06-24 10:13:11 -04:00
|
|
|
result.Directions = make([]*DCCDirection, result.NumberOfDirections)
|
2020-01-26 00:39:13 -05:00
|
|
|
for i := 0; i < result.NumberOfDirections; i++ {
|
|
|
|
result.Directions[i] = CreateDCCDirection(d2common.CreateBitMuncher(fileData, directionOffsets[i]*8), *result)
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|