/
parser_common.go
145 lines (119 loc) · 3.08 KB
/
parser_common.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package parser
import (
"context"
"math"
"strings"
)
func (parser *PakParser) ReadFGenerationInfo() *FGenerationInfo {
return &FGenerationInfo{
ExportCount: parser.ReadInt32(),
NameCount: parser.ReadInt32(),
}
}
func (parser *PakParser) ReadFEngineVersion() *FEngineVersion {
return &FEngineVersion{
Major: parser.ReadUint16(),
Minor: parser.ReadUint16(),
Patch: parser.ReadUint16(),
ChangeList: parser.ReadUint32(),
Branch: parser.ReadString(),
}
}
func (parser *PakParser) ReadFCompressedChunk() *FCompressedChunk {
return &FCompressedChunk{
UncompressedOffset: parser.ReadInt32(),
UncompressedSize: parser.ReadInt32(),
CompressedOffset: parser.ReadInt32(),
CompressedSize: parser.ReadInt32(),
}
}
func (parser *PakParser) ReadFName(names []*FNameEntrySerialized) string {
index := parser.ReadUint32()
// Instance ID
parser.Read(4)
return names[index].Name
}
func (parser *PakParser) ReadFPackageIndex(imports []*FObjectImport, exports []*FObjectExport) *FPackageIndex {
return parser.ReadFPackageIndexInt(parser.ReadInt32(), imports, exports)
}
func (parser *PakParser) ReadFPackageIndexInt(index int32, imports []*FObjectImport, exports []*FObjectExport) *FPackageIndex {
if index == 0 {
// TODO Values of 0 indicate that this resource represents a top-level UPackage object (the linker's LinkerRoot). Serialized
return &FPackageIndex{
Index: index,
Reference: nil,
}
}
if index < 0 {
correctedIndex := index*-1 - 1
if correctedIndex >= 0 && correctedIndex < int32(len(imports)) {
return &FPackageIndex{
Index: index,
Reference: imports[index*-1-1],
}
}
return &FPackageIndex{
Index: index,
Reference: nil,
}
}
if index-1 < int32(len(exports)) {
return &FPackageIndex{
Index: index - 1,
Reference: exports[index-1],
}
}
return nil
}
func (parser *PakParser) ReadFText() *FText {
flags := parser.ReadUint32()
historyType := int8(parser.Read(1)[0])
text := FText{
Flags: flags,
HistoryType: historyType,
}
if flags == 2 && historyType == -1 {
// TODO Unknown
if parser.ReadInt32() == 0 {
return &text
}
text.SourceString = parser.ReadString()
return &text
}
if flags == 0 && historyType == 11 {
// TODO Unknown
parser.Read(8)
text.SourceString = parser.ReadString()
return &text
}
if historyType != 0 {
return &text
}
text.Namespace = parser.ReadString()
text.Key = parser.ReadString()
text.SourceString = parser.ReadString()
return &text
}
func (parser *PakParser) ReadFPropertyTagLoop(ctx context.Context, uAsset *FPackageFileSummary) []*FPropertyTag {
properties := make([]*FPropertyTag, 0)
for {
property := parser.ReadFPropertyTag(ctx, uAsset, true, 0)
if property == nil {
break
}
properties = append(properties, property)
}
return properties
}
func d(n int) string {
return strings.Repeat(" ", n)
}
func assertFloat32IsFinite(n float32) {
value := float64(n)
if math.IsNaN(value) {
panic("Expected a float32, but received NaN")
}
if math.IsInf(value, 0) {
panic("Expected a float32, but received inf")
}
}