2019-11-06 22:12:15 -05:00
|
|
|
package _map
|
2019-10-28 17:51:17 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2019-11-06 22:12:15 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/common"
|
2019-10-28 17:51:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// https://d2mods.info/forum/viewtopic.php?t=65163
|
|
|
|
|
|
|
|
type Block struct {
|
2019-10-31 13:39:05 -04:00
|
|
|
X int16
|
|
|
|
Y int16
|
|
|
|
GridX byte
|
|
|
|
GridY byte
|
|
|
|
Format BlockDataFormat
|
|
|
|
EncodedData []byte
|
|
|
|
Length int32
|
|
|
|
FileOffset int32
|
2019-10-28 17:51:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type Tile struct {
|
|
|
|
Direction int32
|
|
|
|
RoofHeight int16
|
|
|
|
SoundIndex byte
|
2019-11-01 14:12:23 -04:00
|
|
|
Animated bool
|
2019-10-28 17:51:17 -04:00
|
|
|
Height int32
|
|
|
|
Width int32
|
|
|
|
Orientation int32
|
|
|
|
MainIndex int32
|
|
|
|
SubIndex int32
|
|
|
|
RarityFrameIndex int32
|
|
|
|
SubTileFlags [25]byte
|
|
|
|
blockHeaderPointer int32
|
|
|
|
blockHeaderSize int32
|
2019-10-31 13:39:05 -04:00
|
|
|
Blocks []Block
|
2019-10-28 17:51:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type DT1 struct {
|
|
|
|
Tiles []Tile
|
|
|
|
}
|
|
|
|
|
2019-10-31 13:39:05 -04:00
|
|
|
type BlockDataFormat int16
|
|
|
|
|
|
|
|
const (
|
|
|
|
BlockFormatRLE BlockDataFormat = 0 // Not 1
|
|
|
|
BlockFormatIsometric BlockDataFormat = 1
|
|
|
|
)
|
|
|
|
|
2019-11-06 22:12:15 -05:00
|
|
|
func LoadDT1(path string, fileProvider common.FileProvider) *DT1 {
|
2019-10-28 17:51:17 -04:00
|
|
|
result := &DT1{}
|
|
|
|
fileData := fileProvider.LoadFile(path)
|
2019-11-06 22:12:15 -05:00
|
|
|
br := common.CreateStreamReader(fileData)
|
2019-10-28 17:51:17 -04:00
|
|
|
ver1 := br.GetInt32()
|
|
|
|
ver2 := br.GetInt32()
|
|
|
|
if ver1 != 7 || ver2 != 6 {
|
|
|
|
log.Panicf("Expected %s to have a version of 7.6, but got %d.%d instead", path, ver1, ver2)
|
|
|
|
}
|
|
|
|
br.SkipBytes(260)
|
|
|
|
numberOfTiles := br.GetInt32()
|
2019-11-01 14:12:23 -04:00
|
|
|
br.SetPosition(uint64(br.GetInt32()))
|
2019-10-28 17:51:17 -04:00
|
|
|
result.Tiles = make([]Tile, numberOfTiles)
|
|
|
|
for tileIdx := range result.Tiles {
|
|
|
|
newTile := Tile{}
|
|
|
|
newTile.Direction = br.GetInt32()
|
|
|
|
newTile.RoofHeight = br.GetInt16()
|
|
|
|
newTile.SoundIndex = br.GetByte()
|
2019-11-01 14:12:23 -04:00
|
|
|
newTile.Animated = br.GetByte() == 1
|
2019-10-28 17:51:17 -04:00
|
|
|
newTile.Height = br.GetInt32()
|
|
|
|
newTile.Width = br.GetInt32()
|
|
|
|
br.SkipBytes(4)
|
|
|
|
newTile.Orientation = br.GetInt32()
|
|
|
|
newTile.MainIndex = br.GetInt32()
|
|
|
|
newTile.SubIndex = br.GetInt32()
|
|
|
|
newTile.RarityFrameIndex = br.GetInt32()
|
|
|
|
br.SkipBytes(4)
|
|
|
|
for i := range newTile.SubTileFlags {
|
|
|
|
newTile.SubTileFlags[i] = br.GetByte()
|
|
|
|
}
|
|
|
|
br.SkipBytes(7)
|
|
|
|
newTile.blockHeaderPointer = br.GetInt32()
|
|
|
|
newTile.blockHeaderSize = br.GetInt32()
|
2019-10-31 13:39:05 -04:00
|
|
|
newTile.Blocks = make([]Block, br.GetInt32())
|
2019-10-28 17:51:17 -04:00
|
|
|
br.SkipBytes(12)
|
|
|
|
result.Tiles[tileIdx] = newTile
|
|
|
|
}
|
|
|
|
for tileIdx, tile := range result.Tiles {
|
|
|
|
br.SetPosition(uint64(tile.blockHeaderPointer))
|
2019-10-31 13:39:05 -04:00
|
|
|
for blockIdx := range tile.Blocks {
|
|
|
|
result.Tiles[tileIdx].Blocks[blockIdx].X = br.GetInt16()
|
|
|
|
result.Tiles[tileIdx].Blocks[blockIdx].Y = br.GetInt16()
|
2019-10-28 17:51:17 -04:00
|
|
|
br.SkipBytes(2)
|
2019-10-31 13:39:05 -04:00
|
|
|
result.Tiles[tileIdx].Blocks[blockIdx].GridX = br.GetByte()
|
|
|
|
result.Tiles[tileIdx].Blocks[blockIdx].GridY = br.GetByte()
|
2019-11-01 14:12:23 -04:00
|
|
|
formatValue := br.GetInt16()
|
|
|
|
if formatValue == 1 {
|
|
|
|
result.Tiles[tileIdx].Blocks[blockIdx].Format = BlockFormatIsometric
|
|
|
|
} else {
|
|
|
|
result.Tiles[tileIdx].Blocks[blockIdx].Format = BlockFormatRLE
|
|
|
|
}
|
2019-10-31 13:39:05 -04:00
|
|
|
result.Tiles[tileIdx].Blocks[blockIdx].Length = br.GetInt32()
|
2019-10-28 17:51:17 -04:00
|
|
|
br.SkipBytes(2)
|
2019-10-31 13:39:05 -04:00
|
|
|
result.Tiles[tileIdx].Blocks[blockIdx].FileOffset = br.GetInt32()
|
2019-10-28 17:51:17 -04:00
|
|
|
}
|
2019-10-31 13:39:05 -04:00
|
|
|
for blockIndex, block := range tile.Blocks {
|
|
|
|
br.SetPosition(uint64(tile.blockHeaderPointer + block.FileOffset))
|
|
|
|
encodedData, _ := br.ReadBytes(int(block.Length))
|
|
|
|
tile.Blocks[blockIndex].EncodedData = encodedData
|
|
|
|
}
|
|
|
|
|
2019-10-28 17:51:17 -04:00
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|