summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-10-10 22:14:41 +0200
committerHimbeer <himbeer@disroot.org>2024-10-10 22:14:41 +0200
commit2129da31d7280ed336c826d4fa5c652af93065f3 (patch)
tree474cd6d73248671280968dccaa4c23fca9772096
parentdf181fce5c1548f1db6ce5d7e74274fe638a767c (diff)
Fix WearBarParams (de)serialization crash due to unsatisfied interface
While image/color.NRGBA has a (de)serialization override, it does not satisfy the (de)serializer interface. This causes a crash when certain item definitions are sent or received. This commit fixes the issue by manually copying the (de)serialization override of image/color.NRGBA to the WearBarParams override implementation instead of calling the (de)serialize function that requires the input to satisfy (de)serializer.
-rw-r--r--deserialize.fmt11
-rw-r--r--serialize.fmt7
-rw-r--r--serialize.go18
3 files changed, 26 insertions, 10 deletions
diff --git a/deserialize.fmt b/deserialize.fmt
index 1923db6..94aea4c 100644
--- a/deserialize.fmt
+++ b/deserialize.fmt
@@ -131,8 +131,13 @@ map[float32]image/color.NRGBA { // For WearBarParams.ColorStops.
*p = make(map[float32]color.NRGBA, n)
for ; n > 0; n-- {
wear := float32(read32(r))
- var colorStop color.NRGBA
- chk(deserialize(r, &colorStop))
- (*p)[wear] = colorStop
+ // Same as image/color.NRGBA, but it doesn't implement
+ // deserializer.
+ (*p)[wear] = color.NRGBA{
+ A: read8(r),
+ R: read8(r),
+ G: read8(r),
+ B: read8(r),
+ }
}
}
diff --git a/serialize.fmt b/serialize.fmt
index d79f7db..91d98bc 100644
--- a/serialize.fmt
+++ b/serialize.fmt
@@ -175,8 +175,11 @@ map[float32]image/color.NRGBA { // For WearBarParams.ColorStops.
chk(ErrTooLong)
}
write16(w, uint16(len(x)))
- for wear, colorStop := range x {
+ for wear, c := range x {
write32(w, uint32(wear))
- chk(serialize(w, colorStop))
+ // Same as image/color.NRGBA, but it doesn't implement
+ // serializer.
+ _, err := w.Write([]byte{c.A, c.R, c.G, c.B})
+ chk(err)
}
}
diff --git a/serialize.go b/serialize.go
index 6db8997..4a52f8e 100644
--- a/serialize.go
+++ b/serialize.go
@@ -43278,9 +43278,12 @@ func (obj *WearBarParams) serialize(w io.Writer) {
chk(ErrTooLong)
}
write16(w, uint16(len(x)))
- for wear, colorStop := range x {
+ for wear, c := range x {
write32(w, uint32(wear))
- chk(serialize(w, colorStop))
+ // Same as image/color.NRGBA, but it doesn't implement
+ // serializer.
+ _, err := w.Write([]byte{c.A, c.R, c.G, c.B})
+ chk(err)
}
}
}
@@ -43321,9 +43324,14 @@ func (obj *WearBarParams) deserialize(r io.Reader) {
*p = make(map[float32]color.NRGBA, n)
for ; n > 0; n-- {
wear := float32(read32(r))
- var colorStop color.NRGBA
- chk(deserialize(r, &colorStop))
- (*p)[wear] = colorStop
+ // Same as image/color.NRGBA, but it doesn't implement
+ // deserializer.
+ (*p)[wear] = color.NRGBA{
+ A: read8(r),
+ R: read8(r),
+ G: read8(r),
+ B: read8(r),
+ }
}
}
}