2020-02-26 22:52:05 -05:00
|
|
|
package d2pl2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
|
|
|
|
"github.com/go-restruct/restruct"
|
|
|
|
)
|
|
|
|
|
2020-06-28 22:32:34 -04:00
|
|
|
// PL2 represents a palette file.
|
|
|
|
type PL2 struct {
|
2020-04-11 14:56:47 -04:00
|
|
|
BasePalette PL2Palette
|
|
|
|
|
|
|
|
LightLevelVariations [32]PL2PaletteTransform
|
|
|
|
InvColorVariations [16]PL2PaletteTransform
|
|
|
|
SelectedUintShift PL2PaletteTransform
|
|
|
|
AlphaBlend [3][256]PL2PaletteTransform
|
|
|
|
AdditiveBlend [256]PL2PaletteTransform
|
|
|
|
MultiplicativeBlend [256]PL2PaletteTransform
|
|
|
|
HueVariations [111]PL2PaletteTransform
|
|
|
|
RedTones PL2PaletteTransform
|
|
|
|
GreenTones PL2PaletteTransform
|
|
|
|
BlueTones PL2PaletteTransform
|
|
|
|
UnknownVariations [14]PL2PaletteTransform
|
|
|
|
MaxComponentBlend [256]PL2PaletteTransform
|
|
|
|
DarkendColorShift PL2PaletteTransform
|
|
|
|
|
|
|
|
TextColors [13]PL2Color24Bits
|
|
|
|
TextColorShifts [13]PL2PaletteTransform
|
2020-02-26 22:52:05 -05:00
|
|
|
}
|
|
|
|
|
2020-06-28 22:32:34 -04:00
|
|
|
// Load uses restruct to read the binary pl2 data into structs
|
|
|
|
func Load(data []byte) (*PL2, error) {
|
|
|
|
result := &PL2{}
|
2020-02-26 22:52:05 -05:00
|
|
|
|
|
|
|
restruct.EnableExprBeta()
|
|
|
|
|
|
|
|
err := restruct.Unpack(data, binary.LittleEndian, &result)
|
|
|
|
if err != nil {
|
2020-04-11 14:56:47 -04:00
|
|
|
return nil, err
|
2020-02-26 22:52:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|