diff --git a/d2common/d2data/animation_data.go b/d2common/d2data/animation_data.go index 1cbc640d..3a159dfe 100644 --- a/d2common/d2data/animation_data.go +++ b/d2common/d2data/animation_data.go @@ -7,6 +7,11 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2common" ) +const ( + numCofNameBytes = 8 + numFlagBytes = 144 +) + // AnimationDataRecord represents a single entry in the animation data dictionary file type AnimationDataRecord struct { // COFName is the name of the COF file used for this animation @@ -30,13 +35,13 @@ func LoadAnimationData(rawData []byte) { for !streamReader.EOF() { dataCount := int(streamReader.GetInt32()) for i := 0; i < dataCount; i++ { - cofNameBytes := streamReader.ReadBytes(8) + cofNameBytes := streamReader.ReadBytes(numCofNameBytes) data := &AnimationDataRecord{ COFName: strings.ReplaceAll(string(cofNameBytes), string(0), ""), FramesPerDirection: int(streamReader.GetInt32()), AnimationSpeed: int(streamReader.GetInt32()), } - data.Flags = streamReader.ReadBytes(144) + data.Flags = streamReader.ReadBytes(numFlagBytes) cofIndex := strings.ToLower(data.COFName) if _, found := AnimationData[cofIndex]; !found { diff --git a/d2common/d2data/d2compression/huffman.go b/d2common/d2data/d2compression/huffman.go index aaa4e006..07a7ef96 100644 --- a/d2common/d2data/d2compression/huffman.go +++ b/d2common/d2data/d2compression/huffman.go @@ -256,7 +256,8 @@ func insertNode(tail *linkedNode, decomp int) *linkedNode { adjustTree(newnode) - // TODO: For compression type 0, AdjustTree should be called once for every value written and only once here + // ISSUE #680: For compression type 0, adjustTree should be + // called once for every value written and only once here adjustTree(newnode) return result diff --git a/d2common/d2data/d2datadict/d2datadict.go b/d2common/d2data/d2datadict/d2datadict.go index 7a3f895e..d94823b7 100644 --- a/d2common/d2data/d2datadict/d2datadict.go +++ b/d2common/d2data/d2datadict/d2datadict.go @@ -1,7 +1,6 @@ -// Package d2datadict parses txt files as data dictionaries and exports records arrays -// For the Diablo II MPQ's, data dictionaries are the tab-separated value txt files found in `data/global/excel` package d2datadict +// these show up in a lot of txt files where blizzard added LoD expansion stuff const ( expansion = "Expansion" expansionCode = 100 diff --git a/d2common/d2data/d2datadict/doc.go b/d2common/d2data/d2datadict/doc.go new file mode 100644 index 00000000..e3f953a9 --- /dev/null +++ b/d2common/d2data/d2datadict/doc.go @@ -0,0 +1,4 @@ +// Package d2datadict parses txt files as data dictionaries and exports records arrays +// For the Diablo II MPQ's, data dictionaries are the tab-separated value txt files +// found in `data/global/excel` +package d2datadict diff --git a/d2common/d2data/d2video/binkdecoder.go b/d2common/d2data/d2video/binkdecoder.go index 9994ef76..b145ede4 100644 --- a/d2common/d2data/d2video/binkdecoder.go +++ b/d2common/d2data/d2video/binkdecoder.go @@ -11,22 +11,22 @@ type BinkVideoMode uint32 const ( // BinkVideoModeNormal is a normal video - BinkVideoModeNormal BinkVideoMode = 0 + BinkVideoModeNormal BinkVideoMode = iota // BinkVideoModeHeightDoubled is a height-doubled video - BinkVideoModeHeightDoubled BinkVideoMode = 1 + BinkVideoModeHeightDoubled // BinkVideoModeHeightInterlaced is a height-interlaced video - BinkVideoModeHeightInterlaced BinkVideoMode = 2 + BinkVideoModeHeightInterlaced // BinkVideoModeWidthDoubled is a width-doubled video - BinkVideoModeWidthDoubled BinkVideoMode = 3 + BinkVideoModeWidthDoubled // BinkVideoModeWidthAndHeightDoubled is a width and height-doubled video - BinkVideoModeWidthAndHeightDoubled BinkVideoMode = 4 + BinkVideoModeWidthAndHeightDoubled // BinkVideoModeWidthAndHeightInterlaced is a width and height interlaced video - BinkVideoModeWidthAndHeightInterlaced BinkVideoMode = 5 + BinkVideoModeWidthAndHeightInterlaced ) // BinkAudioAlgorithm represents the type of bink audio algorithm @@ -34,10 +34,10 @@ type BinkAudioAlgorithm uint32 const ( // BinkAudioAlgorithmFFT is the FTT audio algorithm - BinkAudioAlgorithmFFT BinkAudioAlgorithm = 0 + BinkAudioAlgorithmFFT BinkAudioAlgorithm = iota // BinkAudioAlgorithmDCT is the DCT audio algorithm - BinkAudioAlgorithmDCT BinkAudioAlgorithm = 1 + BinkAudioAlgorithmDCT ) // BinkAudioTrack represents an audio track @@ -84,8 +84,7 @@ func CreateBinkDecoder(source []byte) *BinkDecoder { // GetNextFrame gets the next frame func (v *BinkDecoder) GetNextFrame() { - //nolint:gocritic // v.streamReader.SetPosition(uint64(v.FrameIndexTable[i] & 0xFFFFFFFE)) - + //nolint:gocritic // v.streamReader.SetPosition(uint64(v.FrameIndexTable[i] & 0xFFFFFFFE)) lengthOfAudioPackets := v.streamReader.GetUInt32() - 4 //nolint:gomnd // decode magic samplesInPacket := v.streamReader.GetUInt32() diff --git a/d2common/d2data/d2video/doc.go b/d2common/d2data/d2video/doc.go new file mode 100644 index 00000000..729b8b5f --- /dev/null +++ b/d2common/d2data/d2video/doc.go @@ -0,0 +1,2 @@ +// Package d2video provides a bink video decoder +package d2video diff --git a/d2common/d2data/doc.go b/d2common/d2data/doc.go new file mode 100644 index 00000000..72692b0e --- /dev/null +++ b/d2common/d2data/doc.go @@ -0,0 +1,3 @@ +// Package d2data provides file compression utilities, video decoders, and file loaders +// for the txt files inside of diablo's mpq files +package d2data diff --git a/d2common/d2fileformats/d2ds1/ds1.go b/d2common/d2fileformats/d2ds1/ds1.go index 4c686e14..093ab08a 100644 --- a/d2common/d2fileformats/d2ds1/ds1.go +++ b/d2common/d2fileformats/d2ds1/ds1.go @@ -2,7 +2,6 @@ package d2ds1 import ( "github.com/OpenDiablo2/OpenDiablo2/d2common" - "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector" @@ -13,7 +12,7 @@ const maxActNumber = 5 // DS1 represents the "stamp" data that is used to build up maps. type DS1 struct { Files []string // FilePtr table of file string pointers - Objects []d2data.Object // Objects + Objects []Object // Objects Tiles [][]TileRecord // The tile data for the DS1 SubstitutionGroups []SubstitutionGroup // Substitution groups for the DS1 Version int32 // The version of the DS1 @@ -111,10 +110,10 @@ func LoadDS1(fileData []byte) (*DS1, error) { func (ds1 *DS1) loadObjects(br *d2common.StreamReader) { if ds1.Version >= 2 { //nolint:gomnd // Version number numberOfObjects := br.GetInt32() - ds1.Objects = make([]d2data.Object, numberOfObjects) + ds1.Objects = make([]Object, numberOfObjects) for objIdx := 0; objIdx < int(numberOfObjects); objIdx++ { - newObject := d2data.Object{} + newObject := Object{} newObject.Type = int(br.GetInt32()) newObject.ID = int(br.GetInt32()) newObject.X = int(br.GetInt32()) @@ -124,7 +123,7 @@ func (ds1 *DS1) loadObjects(br *d2common.StreamReader) { ds1.Objects[objIdx] = newObject } } else { - ds1.Objects = make([]d2data.Object, 0) + ds1.Objects = make([]Object, 0) } } diff --git a/d2common/d2data/object.go b/d2common/d2fileformats/d2ds1/object.go similarity index 92% rename from d2common/d2data/object.go rename to d2common/d2fileformats/d2ds1/object.go index c2abade2..dcc315c5 100644 --- a/d2common/d2data/object.go +++ b/d2common/d2fileformats/d2ds1/object.go @@ -1,4 +1,4 @@ -package d2data +package d2ds1 import ( "github.com/OpenDiablo2/OpenDiablo2/d2common"