-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvallc.ps1
More file actions
293 lines (251 loc) · 11 KB
/
vallc.ps1
File metadata and controls
293 lines (251 loc) · 11 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
$savePath = "$($env:LOCALAPPDATA)/ValorantLangChanger/"
$configPath = -join($savePath, 'config.csv')
$savePakPath = 'ShooterGame/Content/Paks/'
$manifestDownloaderUrl = 'https://github.com/Morilli/ManifestDownloader/releases/download/v1.8.2/ManifestDownloader.exe'
function Get-Hash([string]$textToHash) {
$hasher = new-object System.Security.Cryptography.MD5CryptoServiceProvider
$toHash = [System.Text.Encoding]::UTF8.GetBytes($textToHash)
$hashByteArray = $hasher.ComputeHash($toHash)
foreach($byte in $hashByteArray) {
$result += "{0:X2}" -f $byte
}
return $result;
}
$manifestDownloaderFile = -join((Get-Hash $manifestDownloaderUrl), '.exe')
Write-Host '~ Valorant Language Changer ~' -ForegroundColor Cyan
Write-Host '~ by EaZyCode ~' -ForegroundColor DarkGray
Write-Host ''
if ($args.count -eq 0) {
Write-Host 'Hey! Thanks for using this tool!' -ForegroundColor Cyan
Write-Host 'I will guide you through the setup now!' -ForegroundColor Cyan
Write-Host ''
}
if (!(Test-Path $savePath)) {
$_ = New-Item -Path $savePath -ItemType Directory
}
try {
Write-Host 'Fetching VALORANT config from Riot Games...' -ForegroundColor Green
$patchConfigs = (ConvertFrom-Json (Invoke-WebRequest -UseBasicParsing -Uri 'https://clientconfig.rpg.riotgames.com/api/v1/config/public?namespace=keystone.products.valorant.patchlines').Content).'keystone.products.valorant.patchlines.live'.platforms.win.configurations
} catch {
Write-Host 'Error contacting Riot Games servers' -ForegroundColor Red
Write-Host $_
Read-Host
Exit
}
$valid = @{}
$valid.regions = $patchConfigs | ForEach-Object {$_.id}
# Load config or guide the user to create a new one
$config = @{}
if (Test-Path $configPath) {
try {
Import-Csv (-join($savePath, 'config.csv')) | foreach -Process {$config.Add($_.Key, $_.Value)}
} catch {
# ignore
}
}
$outer = @{}
function Ensure-Config {
$outer.modified = 0
$tried = 0
while (!$valid.regions.Contains($config.region)) {
$outer.modified = 1
if ($tried -eq 1) {
Write-Host 'That is not a valid region!' -ForegroundColor Red
}
Write-Host 'Please enter your general region:' -ForegroundColor Yellow
Write-Host (-join('(', [string]::Join(', ', $valid.regions), ')')) -ForegroundColor DarkGray
$config.region = Read-Host
$tried = 1
}
$outer.regionConfig = $patchConfigs | Where-Object 'id' -eq $config.region
$valid.langs = $outer.regionConfig | ForEach-Object {$_.locale_data.available_locales}
$tried = 0
while (!$valid.langs.Contains($config.voiceLang)) {
$outer.modified = 1
if ($tried -eq 1) {
Write-Host 'That is not a valid language!' -ForegroundColor Red
}
Write-Host 'Please enter your voice language:' -ForegroundColor Yellow
Write-Host (-join('(', [string]::Join(', ', $valid.langs), ')')) -ForegroundColor DarkGray
$config.voiceLang = Read-Host
$tried = 1
}
$tried = 0
while (!$valid.langs.Contains($config.textLang)) {
$outer.modified = 1
if ($tried -eq 1) {
Write-Host 'That is not a valid language!' -ForegroundColor Red
}
Write-Host 'Please enter your text language:' -ForegroundColor Yellow
Write-Host (-join('(', [string]::Join(', ', $valid.langs), ')')) -ForegroundColor DarkGray
$config.textLang = Read-Host
$tried = 1
}
$tried = 0
:out while (($null -eq $config.pakPath) -or (!$config.pakPath.EndsWith($savePakPath)) -or !(Test-Path $config.pakPath)) {
$outer.modified = 1
if ($tried -eq 1) {
Write-Host 'That is not the correct folder!' -ForegroundColor Red
} else {
Write-Host 'Trying to find VALORANT...' -ForegroundColor Green
$drives = Get-PSDrive -PSProvider FileSystem | ForEach-Object {$_.Root}
foreach ($drive in $drives) {
$jsonPath = -join($drive, 'ProgramData\Riot Games\RiotClientInstalls.json')
if (!(Test-Path $jsonPath)) {
continue
}
$installs = Get-Content ($jsonPath) | ConvertFrom-Json
$installPaths = $installs.associated_client.PSObject.Properties.Name
foreach ($path in $installPaths) {
$path = $path.Replace('\', '/')
if ($path.EndsWith('VALORANT/live/')) {
$config.pakPath = -join($path, $savePakPath)
if (Test-Path $config.pakPath) {
Write-Host 'Found it!' -ForegroundColor Green
break out
}
}
}
}
if (($null -eq $config.pakPath) -or !(Test-Path $config.pakPath)) {
Write-Host 'Sorry, can''t find VALORANT.' -ForegroundColor Red
}
}
if (!$FileBrowser) {
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
}
Write-Host 'A window to select a folder will now open.' -ForegroundColor Yellow
Write-Host 'Please go to your VALORANT installation folder.' -ForegroundColor Yellow
Write-Host (-join('In that folder, please find "', $savePakPath, '" and press Open.')) -ForegroundColor Yellow
$status = $FileBrowser.ShowDialog()
if ($status -eq 'OK') {
$config.pakPath = $FileBrowser.SelectedPath.Replace('\', '/')
if (!$config.pakPath.EndsWith('/')) {
$config.pakPath = -join($config.pakPath, '/')
}
}
$tried = 1
}
# save the config
if ($outer.modified -eq 1) {
$config.GetEnumerator() | Select Key, Value | Export-Csv (-join($savePath, 'config.csv'))
}
}
Ensure-Config
# continue setup
if ($args.count -eq 0) {
if ($outer.modified -eq 0) {
$tried = 0
while ($true) {
if ($tried -eq 1) {
Write-Host 'That is not a valid choice!' -ForegroundColor Red
}
Write-Host 'What do you want to do? (Please type the number of your choice)' -ForegroundColor Yellow
Write-Host '1. Create a shortcut' -ForegroundColor Yellow
Write-Host '2. Run setup from the start (change region, language, ...)' -ForegroundColor Yellow
$choice = Read-Host
if ($choice -eq "1") {
break
} elseif ($choice -eq "2") {
$config = @{}
Ensure-Config
Write-Host 'Saved new config!' -ForegroundColor Green
Write-Host 'Press enter to exit.' -ForegroundColor DarkGray
Read-Host
Exit
}
$tried = 1
}
}
$shell = New-Object -COM WScript.Shell
$tried = 0
while (($null -eq $shortcutPath) -or !(Test-Path $shortcutPath)) {
if ($tried -eq 1) {
Write-Host 'That is not a valid path to a shortcut!' -ForegroundColor Red
}
Write-Host 'Please drag your VALORANT shortcut into this window and press enter.' -ForegroundColor Yellow
Write-Host '(The file which you double-click to start Valorant usually.)' -ForegroundColor DarkGray
Write-Host '(The path to the shortcut should appear.)' -ForegroundColor DarkGray
$shortcutPath = (Read-Host).Replace('"', '')
$tried = 1
}
Write-Host 'Creating a new shortcut for you...' -ForegroundColor Green
$newShortcutPath = (-join([Environment]::GetFolderPath("Desktop"), '/VALORANT Custom Language.lnk'))
Copy-Item $shortcutPath $newShortcutPath
$shortcut = $shell.CreateShortcut($newShortcutPath)
$shortcut.Arguments = -join('-ExecutionPolicy Bypass -File "%localappdata%\ValorantLangChanger\vallc.ps1" "', $shortcut.TargetPath, '" ', $shortcut.Arguments)
$shortcut.TargetPath = 'powershell.exe'
$shortcut.Save()
Write-Host 'Setting up all the files...' -ForegroundColor Green
$psPath = $MyInvocation.MyCommand.Path
Copy-Item $psPath (-join($savePath, 'vallc.ps1'))
Invoke-WebRequest -UseBasicParsing -Uri $manifestDownloaderUrl -OutFile (-join($savePath, $manifestDownloaderFile))
Write-Host 'Done! You can now close this window and start VALORANT from the new icon on your desktop!' -ForegroundColor Green
Write-Host 'You could delete this file now.' -ForegroundColor Green
Write-Host 'If you want to change anything (like your language), just (download and) run this script again.' -ForegroundColor Green
Read-Host
Exit
}
$checkBefore = Get-WmiObject -Class 'win32_process' -Filter 'name = "VALORANT.exe"'
if ($checkBefore) {
Write-Host 'Valorant is already running. Please close VALORANT first.' -ForegroundColor Red
Write-Host 'Press enter to exit.' -ForegroundColor Red
Read-Host
Exit
}
# download/update lang files
Write-Host 'Checking for new language files...' -ForegroundColor DarkGray
try {
$lastPatchUrl = ''
# check if both lang files exist, if not download
if ((Test-Path (-join($savePath, 'url.txt'))) -and (!(Test-Path (-join($savePath, $savePakPath, $config.textLang, '_Text-WindowsClient.pak'))) -or !(Test-Path (-join($savePath, $savePakPath, $config.voiceLang, '_Text-WindowsClient.pak'))))) {
Remove-Item (-join($savePath, 'url.txt'))
}
if (Test-Path (-join($savePath, 'url.txt'))) {
$lastPatchUrl = Get-Content -Path (-join($savePath, 'url.txt'))
}
$patchUrl = $outer.regionConfig.patch_url
if ($patchUrl -ne $lastPatchUrl) {
Write-Host 'Downloading new language files...' -ForegroundColor Green
$downloaderProcess = Start-Process -PassThru -Wait -NoNewWindow -FilePath (-join($savePath, $manifestDownloaderFile)) -ArgumentList ($patchUrl,'-b','https://valorant.secure.dyn.riotcdn.net/channels/public/bundles','-l',$config.textLang,$config.voiceLang,'-o',$savePath,'-f','.+Text-WindowsClient.+')
if ($downloaderProcess.ExitCode -eq 0) {
$patchUrl | Out-File -FilePath (-join($savePath, 'url.txt'))
Write-Host 'Downloaded new language files!' -ForegroundColor Green
} else {
Write-Host 'Error trying to download new language files!' -ForegroundColor Red
Read-Host
Exit
}
} else {
Write-Host 'Up to date!' -ForegroundColor Green
}
} catch {
Write-Host 'Can not check for new language files' -ForegroundColor Red
Write-Host $_
Read-Host
Exit
}
if (!(Test-Path (-join($config.pakPath, $config.voiceLang, '_Text-WindowsClient.pak')))) {
Write-Host (-join('Please change your language *ingame* to ', $config.voiceLang, '!')) -ForegroundColor Red
Write-Host 'Press enter to continue, after you changed your language, please restart Valorant.' -ForegroundColor Red
Read-Host
}
Write-Host 'Starting Valorant...' -ForegroundColor Green
# copy 'voice' text lang files to valorant (to fool the launcher)
Copy-Item (-join($savePath, $savePakPath, $config.voiceLang, '_Text-WindowsClient.pak')) (-join($config.pakPath, $config.voiceLang, '_Text-WindowsClient.pak'))
Copy-Item (-join($savePath, $savePakPath, $config.voiceLang, '_Text-WindowsClient.sig')) (-join($config.pakPath, $config.voiceLang, '_Text-WindowsClient.sig'))
Start-Process -FilePath $args[0] -ArgumentList $args[1..($args.count)]
Write-Host 'Waiting for Valorant to start...' -ForegroundColor DarkGray
while (1) {
$proc = Get-WmiObject -Class 'win32_process' -Filter 'name = "VALORANT.exe"'
if ($proc) {
break;
}
Start-Sleep -Milliseconds 100
}
Write-Host 'Changing text language files...' -ForegroundColor Green
# copy text lang files to valorant
Copy-Item (-join($savePath, $savePakPath, $config.textLang, '_Text-WindowsClient.pak')) (-join($config.pakPath, $config.voiceLang, '_Text-WindowsClient.pak'))
Copy-Item (-join($savePath, $savePakPath, $config.textLang, '_Text-WindowsClient.sig')) (-join($config.pakPath, $config.voiceLang, '_Text-WindowsClient.sig'))
Write-Host 'Have fun!' -ForegroundColor Green