diff --git a/d2common/d2fileformats/d2cof/cof.go b/d2common/d2fileformats/d2cof/cof.go index 3b47c4a3..fa9b1002 100644 --- a/d2common/d2fileformats/d2cof/cof.go +++ b/d2common/d2fileformats/d2cof/cof.go @@ -30,6 +30,10 @@ const ( layerWeaponClass ) +const ( + layerWeaponClassLength = 4 +) + const ( badCharacter = string(byte(0)) ) @@ -192,11 +196,11 @@ func (c *COF) Marshal() []byte { sw.PushBytes(byte(c.CofLayers[i].DrawEffect)) - s := c.CofLayers[i].WeaponClass.String() + weaponClassString := c.CofLayers[i].WeaponClass.String() - for j := 0; j < 4; j++ { - if j < len(s) { - sw.PushBytes(s[j]) + for letter := 0; letter < layerWeaponClassLength; letter++ { + if letter < len(weaponClassString) { + sw.PushBytes(weaponClassString[letter]) } else { sw.PushBytes(0) }