-
Notifications
You must be signed in to change notification settings - Fork 8
/
variant.go
106 lines (85 loc) · 1.77 KB
/
variant.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package wz
import (
"encoding/hex"
"fmt"
)
type WZVariant struct {
*WZImageObject
Type uint8
Value interface{}
}
func NewWZVariant(name string, parent *WZSimpleNode) *WZVariant {
node := new(WZVariant)
node.WZImageObject = NewWZImageObject(name, parent)
return node
}
func (m *WZVariant) Parse(file *WZFileBlob, offset int64) {
if file.Debug {
m.debug(file, "> WZVariant::Parse")
defer func() { m.debug(file, "< WZVariant::Parse") }()
}
m.Type = file.readByte()
if file.Debug {
m.debug(file, "Type: ", m.Type)
}
switch m.Type {
// no data
case 0:
m.Value = nil
break // Nothing
// int16
case 2, 11:
m.Value = file.readInt16()
break
// int32
case 3, 19:
m.Value = int32(file.readWZInt())
break
// int64
case 20:
m.Value = file.readWZLong()
break
// float32
case 4:
if file.readByte() == 0x80 {
m.Value = file.readFloat32()
} else {
m.Value = float32(0.0)
}
break
// float64
case 5:
m.Value = file.readFloat64()
break
// String
case 8:
m.Value = file.readWZObjectUOL(m.GetPath(), offset)
break
// Sub object
case 9:
size := int64(file.readInt32())
x := file.pos()
if file.Debug {
m.debug(file, "Size: ", size, " - x: ", x)
m.debug(file, "Offset: ", offset)
}
typename := file.readWZObjectUOL(m.GetPath(), offset)
if file.Debug {
m.debug(file, "typename: ", typename)
}
m.Value = ParseObject(m.Name, typename, m.WZSimpleNode, file, offset)
if x+size != file.pos() {
x += size
x -= file.pos()
m.debug(file, "NOT ENOUGH PARSED: ", x, " bytes left???")
if x > 0 {
m.debug(file, "Bytes: \n", hex.Dump(file.readBytes(int32(x))))
} else {
file.skip(x)
}
}
break
default:
panic(fmt.Sprint("Unknown wz prop type ", m.Type, " at ", m.GetPath(), " AT ", file.pos()))
}
}