aboutsummaryrefslogtreecommitdiff
path: root/pkg/messages/types/svcBspDecal.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/messages/types/svcBspDecal.go')
-rw-r--r--pkg/messages/types/svcBspDecal.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/pkg/messages/types/svcBspDecal.go b/pkg/messages/types/svcBspDecal.go
new file mode 100644
index 0000000..484497f
--- /dev/null
+++ b/pkg/messages/types/svcBspDecal.go
@@ -0,0 +1,61 @@
1package messages
2
3import (
4 "github.com/pektezol/bitreader"
5)
6
7type SvcBspDecal struct {
8 Pos []vectorCoord
9 DecalTextureIndex int16
10 EntityIndex int16
11 ModelIndex int16
12 LowPriority int8
13}
14
15type vectorCoord struct {
16 Value float32
17 Valid bool
18}
19
20func ParseSvcBspDecal(reader *bitreader.ReaderType) SvcBspDecal {
21 svcBspDecal := SvcBspDecal{
22 Pos: readVectorCoords(reader),
23 DecalTextureIndex: int16(reader.TryReadBits(9)),
24 }
25 if reader.TryReadBool() {
26 svcBspDecal.EntityIndex = int16(reader.TryReadBits(11))
27 svcBspDecal.ModelIndex = int16(reader.TryReadBits(11))
28 }
29 svcBspDecal.LowPriority = int8(reader.TryReadBits(1))
30 return svcBspDecal
31}
32
33func readVectorCoords(reader *bitreader.ReaderType) []vectorCoord {
34 const COORD_INTEGER_BITS uint8 = 14
35 const COORD_FRACTIONAL_BITS uint8 = 5
36 const COORD_DENOMINATOR uint8 = 1 << COORD_FRACTIONAL_BITS
37 const COORD_RESOLUTION float32 = 1.0 / float32(COORD_DENOMINATOR)
38 readVectorCoord := func() float32 {
39 value := float32(0)
40 integer := reader.TryReadBits(1)
41 fraction := reader.TryReadBits(1)
42 if integer != 0 || fraction != 0 {
43 sign := reader.TryReadBits(1)
44 if integer != 0 {
45 integer = reader.TryReadBits(int(COORD_INTEGER_BITS)) + 1
46 }
47 if fraction != 0 {
48 fraction = reader.TryReadBits(int(COORD_FRACTIONAL_BITS))
49 }
50 value = float32(integer) + float32(fraction)*COORD_RESOLUTION
51 if sign != 0 {
52 value = -value
53 }
54 }
55 return value
56 }
57 x := reader.TryReadBits(1)
58 y := reader.TryReadBits(1)
59 z := reader.TryReadBits(1)
60 return []vectorCoord{{Value: readVectorCoord(), Valid: x != 0}, {Value: readVectorCoord(), Valid: y != 0}, {Value: readVectorCoord(), Valid: z != 0}}
61}