1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-10-01 15:46:17 -04:00

data encoder: COF remade Cof encoder to use stream writter

This commit is contained in:
M. Sz 2021-01-31 18:57:57 +01:00
parent c5eb602de0
commit 0f32ad5d62
2 changed files with 25 additions and 18 deletions

View File

@ -26,6 +26,13 @@ func (v *StreamWriter) PushByte(val byte) {
v.data.WriteByte(val)
}
// PushBytes writes a byte slince to the stream
func (v *StreamWriter) PushBytes(b []byte) {
for _, i := range b {
v.PushByte(i)
}
}
// PushInt16 writes a int16 word to the stream
func (v *StreamWriter) PushInt16(val int16) {
v.PushUint16(uint16(val))

View File

@ -142,47 +142,47 @@ func Load(fileData []byte) (*COF, error) {
// Marshals encodes COF back into byte slince
func (c *COF) Marshal() []byte {
var result []byte
sw := d2datautils.CreateStreamWriter()
result = append(result, byte(c.NumberOfLayers))
result = append(result, byte(c.FramesPerDirection))
result = append(result, byte(c.NumberOfDirections))
result = append(result, c.unknownHeaderBytes...)
result = append(result, byte(c.Speed))
result = append(result, c.unknown1...)
sw.PushByte(byte(c.NumberOfLayers))
sw.PushByte(byte(c.FramesPerDirection))
sw.PushByte(byte(c.NumberOfDirections))
sw.PushBytes(c.unknownHeaderBytes)
sw.PushByte(byte(c.Speed))
sw.PushBytes(c.unknown1)
for i := range c.CofLayers {
result = append(result, byte(c.CofLayers[i].Type.Int()))
result = append(result, c.CofLayers[i].Shadow)
sw.PushByte(byte(c.CofLayers[i].Type.Int()))
sw.PushByte(c.CofLayers[i].Shadow)
if c.CofLayers[i].Selectable {
result = append(result, byte(1))
sw.PushByte(byte(1))
} else {
result = append(result, byte(0))
sw.PushByte(byte(0))
}
if c.CofLayers[i].Transparent {
result = append(result, byte(1))
sw.PushByte(byte(1))
} else {
result = append(result, byte(0))
sw.PushByte(byte(0))
}
result = append(result, byte(c.CofLayers[i].DrawEffect))
sw.PushByte(byte(c.CofLayers[i].DrawEffect))
result = append(result, c.CofLayers[i].weaponClassByte...)
sw.PushBytes(c.CofLayers[i].weaponClassByte)
}
for _, i := range c.AnimationFrames {
result = append(result, byte(i))
sw.PushByte(byte(i))
}
for direction := 0; direction < c.NumberOfDirections; direction++ {
for frame := 0; frame < c.FramesPerDirection; frame++ {
for i := 0; i < c.NumberOfLayers; i++ {
result = append(result, byte(c.Priority[direction][frame][i]))
sw.PushByte(byte(c.Priority[direction][frame][i]))
}
}
}
return result
return sw.GetBytes()
}