Repository navigation
Expand file tree
/
Copy pathunreal.go
More file actions
65 lines (57 loc) · 1.74 KB
/
Copy pathunreal.go
File metadata and controls
65 lines (57 loc) · 1.74 KB
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
package dash
// Reference game pages used to verify this detector:
// https://almightybr0.itch.io/daylight
// UE4 WindowsNoEditor, pak version 11
import (
"bytes"
"encoding/binary"
"strings"
)
// unrealDetector annotates Unreal Engine builds: a root with Engine/ and
// <Project>/Content/Paks/*.pak, launchers at the root and under
// <Project>/Binaries/.
//
// Details: "paks" (count), "pakVersion" (from the first pak's footer).
// Version is the major ("4") when the pak format pins it down, else empty.
type unrealDetector struct{}
var unrealPakMagic = []byte{0xe1, 0x12, 0x6f, 0x5a}
func (unrealDetector) detect(s *scan) error {
seen := make(map[string]bool)
for index, lower := range s.lowerFiles {
if !strings.HasSuffix(lower, ".pak") {
continue
}
paksDir := parentDir(lower)
if !strings.HasSuffix(paksDir, "/content/paks") {
continue
}
project := parentDir(parentDir(paksDir))
root := parentDir(project)
if seen[root] || !s.hasDir(joinPath(root, "engine")) {
continue
}
seen[root] = true
info := &EngineInfo{Engine: EngineUnreal}
info.detail("paks", len(s.filesUnder(paksDir)))
if v, ok := unrealPakVersion(s.readTail(index, 256)); ok {
info.detail("pakVersion", v)
if v <= 10 {
info.Version = "4"
}
}
s.annotateNativesIn(root, info)
for _, c := range s.nativesUnder(joinPath(project, "binaries")) {
c.setEngine(cloneEngine(info))
}
}
return nil
}
// unrealPakVersion finds the footer magic, whose position depends on the
// pak version, and returns the version stored right after it.
func unrealPakVersion(tail []byte) (int, bool) {
i := bytes.LastIndex(tail, unrealPakMagic)
if i < 0 || i+8 > len(tail) {
return 0, false
}
return int(binary.LittleEndian.Uint32(tail[i+4 : i+8])), true
}