mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-03 07:07:25 -05:00
data encoder: COF remade Cof encoder to use stream writter
This commit is contained in:
parent
c5eb602de0
commit
0f32ad5d62
@ -26,6 +26,13 @@ func (v *StreamWriter) PushByte(val byte) {
|
|||||||
v.data.WriteByte(val)
|
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
|
// PushInt16 writes a int16 word to the stream
|
||||||
func (v *StreamWriter) PushInt16(val int16) {
|
func (v *StreamWriter) PushInt16(val int16) {
|
||||||
v.PushUint16(uint16(val))
|
v.PushUint16(uint16(val))
|
||||||
|
@ -142,47 +142,47 @@ func Load(fileData []byte) (*COF, error) {
|
|||||||
|
|
||||||
// Marshals encodes COF back into byte slince
|
// Marshals encodes COF back into byte slince
|
||||||
func (c *COF) Marshal() []byte {
|
func (c *COF) Marshal() []byte {
|
||||||
var result []byte
|
sw := d2datautils.CreateStreamWriter()
|
||||||
|
|
||||||
result = append(result, byte(c.NumberOfLayers))
|
sw.PushByte(byte(c.NumberOfLayers))
|
||||||
result = append(result, byte(c.FramesPerDirection))
|
sw.PushByte(byte(c.FramesPerDirection))
|
||||||
result = append(result, byte(c.NumberOfDirections))
|
sw.PushByte(byte(c.NumberOfDirections))
|
||||||
result = append(result, c.unknownHeaderBytes...)
|
sw.PushBytes(c.unknownHeaderBytes)
|
||||||
result = append(result, byte(c.Speed))
|
sw.PushByte(byte(c.Speed))
|
||||||
result = append(result, c.unknown1...)
|
sw.PushBytes(c.unknown1)
|
||||||
|
|
||||||
for i := range c.CofLayers {
|
for i := range c.CofLayers {
|
||||||
result = append(result, byte(c.CofLayers[i].Type.Int()))
|
sw.PushByte(byte(c.CofLayers[i].Type.Int()))
|
||||||
result = append(result, c.CofLayers[i].Shadow)
|
sw.PushByte(c.CofLayers[i].Shadow)
|
||||||
|
|
||||||
if c.CofLayers[i].Selectable {
|
if c.CofLayers[i].Selectable {
|
||||||
result = append(result, byte(1))
|
sw.PushByte(byte(1))
|
||||||
} else {
|
} else {
|
||||||
result = append(result, byte(0))
|
sw.PushByte(byte(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.CofLayers[i].Transparent {
|
if c.CofLayers[i].Transparent {
|
||||||
result = append(result, byte(1))
|
sw.PushByte(byte(1))
|
||||||
} else {
|
} 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 {
|
for _, i := range c.AnimationFrames {
|
||||||
result = append(result, byte(i))
|
sw.PushByte(byte(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
for direction := 0; direction < c.NumberOfDirections; direction++ {
|
for direction := 0; direction < c.NumberOfDirections; direction++ {
|
||||||
for frame := 0; frame < c.FramesPerDirection; frame++ {
|
for frame := 0; frame < c.FramesPerDirection; frame++ {
|
||||||
for i := 0; i < c.NumberOfLayers; i++ {
|
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()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user