-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
159 lines (127 loc) · 3.37 KB
/
cli.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
const (
cmdInvalid = 0
cmdExtractLauncher = 1
cmdDecryptTitles = 2
)
type cliParams struct {
cmdType int
rglPath string
outPath string
titlesPath string
}
const (
helpCommand = "`.\\RGLExtractor.exe --rgl \"C:\\Program Files\\Rockstar Games\\Launcher\" --out \"C:\\Launcher_rpf\"`" +
"\nor\n`.\\RGLExtractor.exe --titles \"C:\\Launcher_rpf\" --out \"C:\\titles_rgl\"`"
)
func parseParams() *cliParams {
rglPath := flag.String("rgl", "", "Path to root folder of RGL installation")
outPath := flag.String("out", "", "Path to output folder for extraction")
titlesPath := flag.String("titles", "", "Path to folder with title.rgl files to decrypt")
flag.Parse()
cmdType := cmdInvalid
if *titlesPath != "" {
cmdType = cmdDecryptTitles
pathStat, err := os.Stat(*titlesPath)
if err == os.ErrNotExist || !pathStat.IsDir() {
fmt.Printf("Invalid titles path: \"%s\"\n", *rglPath)
return nil
}
} else if *rglPath != "" {
cmdType = cmdExtractLauncher
pathStat, err := os.Stat(*rglPath)
if err == os.ErrNotExist || !pathStat.IsDir() {
fmt.Printf("Invalid launcher path: \"%s\"\n", *rglPath)
return nil
}
} else {
fmt.Printf("You need to specify more arguments. Example:\n%s\n", helpCommand)
return nil
}
if *outPath == "" {
fmt.Printf("You need to specify output path. Example:\n%s\n", helpCommand)
return nil
}
outPathStat, err := os.Stat(*outPath)
if err == os.ErrNotExist {
err = os.MkdirAll(*outPath, 0755)
if err != nil {
fmt.Printf("Failed to create output path at: \"%s\"\n", *outPath)
fmt.Println("Try a different place or launch extractor with the administrative rights")
return nil
}
} else if err == nil && !outPathStat.IsDir() {
fmt.Printf("Invalid output path: \"%s\"\n", *outPath)
return nil
}
return &cliParams{
cmdType: cmdType,
rglPath: *rglPath,
outPath: *outPath,
titlesPath: *titlesPath,
}
}
func extractLauncher(params *cliParams) error {
rgl, err := LoadLauncher(params.rglPath)
if err != nil {
return err
}
logFunc := func(log string) {
fmt.Println(log)
}
for _, packFile := range rgl.Files {
err = packFile.extractPackFile(params.outPath, logFunc)
if err != nil {
return err
}
}
fmt.Printf("Done! Extracted into %s\n", params.outPath)
return nil
}
func decryptTitles(params *cliParams) error {
decryptFile := func(filePath string) error {
title, err := ReadTitleFromFile(filePath)
if err != nil {
return err
}
fileName := title.Name
if fileName == "" {
_, fileName = filepath.Split(filePath)
}
outPath := filepath.Join(params.outPath, fileName+".rgl.json")
directory := filepath.Dir(outPath)
if _, err := os.Stat(directory); os.IsNotExist(err) {
err := os.MkdirAll(directory, 0755)
if err != nil {
return err
}
}
file, err := os.OpenFile(outPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
return err
}
defer file.Close()
content := title.decrypt()
if _, err = file.Write([]byte(content)); err != nil {
return err
}
return nil
}
err := filepath.Walk(params.titlesPath, func(path string, info os.FileInfo, err error) error {
if err == nil && filepath.Ext(info.Name()) == ".rgl" {
decryptFile(path)
}
return nil
})
if err != nil {
panic(err)
}
fmt.Printf("Done! Decrypted into %s\n", params.outPath)
return nil
}