-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUpdateHogwarts.ps1
473 lines (394 loc) · 17.5 KB
/
UpdateHogwarts.ps1
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# The 2 functions for INI files below is 1:1 copied from http://lipkau.net/PsIni/ version 3.0.1
Function Out-IniFile {
<#
.Synopsis
Write hash content to INI file
.Description
Write hash content to INI file
.Notes
Author : Oliver Lipkau <[email protected]>
Blog : http://oliver.lipkau.net/blog/
Source : https://github.com/lipkau/PsIni
http://gallery.technet.microsoft.com/scriptcenter/ea40c1ef-c856-434b-b8fb-ebd7a76e8d91
#Requires -Version 2.0
.Inputs
System.String
System.Collections.IDictionary
.Outputs
System.IO.FileSystemInfo
.Example
Out-IniFile $IniVar "C:\myinifile.ini"
-----------
Description
Saves the content of the $IniVar Hashtable to the INI File c:\myinifile.ini
.Example
$IniVar | Out-IniFile "C:\myinifile.ini" -Force
-----------
Description
Saves the content of the $IniVar Hashtable to the INI File c:\myinifile.ini and overwrites the file if it is already present
.Example
$file = Out-IniFile $IniVar "C:\myinifile.ini" -PassThru
-----------
Description
Saves the content of the $IniVar Hashtable to the INI File c:\myinifile.ini and saves the file into $file
.Example
$Category1 = @{“Key1”=”Value1”;”Key2”=”Value2”}
$Category2 = @{“Key1”=”Value1”;”Key2”=”Value2”}
$NewINIContent = @{“Category1”=$Category1;”Category2”=$Category2}
Out-IniFile -InputObject $NewINIContent -FilePath "C:\MyNewFile.ini"
-----------
Description
Creating a custom Hashtable and saving it to C:\MyNewFile.ini
.Link
Get-IniContent
#>
[CmdletBinding()]
[OutputType(
[System.IO.FileSystemInfo]
)]
Param(
# Adds the output to the end of an existing file, instead of replacing the file contents.
[switch]
$Append,
# Specifies the file encoding. The default is UTF8.
#
# Valid values are:
# -- ASCII: Uses the encoding for the ASCII (7-bit) character set.
# -- BigEndianUnicode: Encodes in UTF-16 format using the big-endian byte order.
# -- Byte: Encodes a set of characters into a sequence of bytes.
# -- String: Uses the encoding type for a string.
# -- Unicode: Encodes in UTF-16 format using the little-endian byte order.
# -- UTF7: Encodes in UTF-7 format.
# -- UTF8: Encodes in UTF-8 format.
[ValidateSet("Unicode", "UTF7", "UTF8", "ASCII", "BigEndianUnicode", "Byte", "String")]
[Parameter()]
[String]
$Encoding = "UTF8",
# Specifies the path to the output file.
[ValidateNotNullOrEmpty()]
[ValidateScript( {Test-Path $_ -IsValid} )]
[Parameter( Position = 0, Mandatory = $true )]
[String]
$FilePath,
# Allows the cmdlet to overwrite an existing read-only file. Even using the Force parameter, the cmdlet cannot override security restrictions.
[Switch]
$Force,
# Specifies the Hashtable to be written to the file. Enter a variable that contains the objects or type a command or expression that gets the objects.
[Parameter( Mandatory = $true, ValueFromPipeline = $true )]
[System.Collections.IDictionary]
$InputObject,
# Passes an object representing the location to the pipeline. By default, this cmdlet does not generate any output.
[Switch]
$Passthru,
# Adds spaces around the equal sign when writing the key = value
[Switch]
$Loose,
# Writes the file as "pretty" as possible
#
# Adds an extra linebreak between Sections
[Switch]
$Pretty
)
Begin {
Write-Debug "PsBoundParameters:"
$PSBoundParameters.GetEnumerator() | ForEach-Object { Write-Debug $_ }
if ($PSBoundParameters['Debug']) {
$DebugPreference = 'Continue'
}
Write-Debug "DebugPreference: $DebugPreference"
Write-Verbose "$($MyInvocation.MyCommand.Name):: Function started"
function Out-Keys {
param(
[ValidateNotNullOrEmpty()]
[Parameter( Mandatory, ValueFromPipeline )]
[System.Collections.IDictionary]
$InputObject,
[ValidateSet("Unicode", "UTF7", "UTF8", "ASCII", "BigEndianUnicode", "Byte", "String")]
[Parameter( Mandatory )]
[string]
$Encoding = "UTF8",
[ValidateNotNullOrEmpty()]
[ValidateScript( {Test-Path $_ -IsValid})]
[Parameter( Mandatory, ValueFromPipelineByPropertyName )]
[Alias("Path")]
[string]
$FilePath,
[Parameter( Mandatory )]
$Delimiter,
[Parameter( Mandatory )]
$MyInvocation
)
Process {
if (!($InputObject.get_keys())) {
Write-Warning ("No data found in '{0}'." -f $FilePath)
}
Foreach ($key in $InputObject.get_keys()) {
if ($key -match "^Comment\d+") {
Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing comment: $key"
"$($InputObject[$key])" | Out-File -Encoding $Encoding -FilePath $FilePath -Append
}
else {
Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing key: $key"
$InputObject[$key] |
ForEach-Object { "$key$delimiter$_" } |
Out-File -Encoding $Encoding -FilePath $FilePath -Append
}
}
}
}
$delimiter = '='
if ($Loose) {
$delimiter = ' = '
}
# Splatting Parameters
$parameters = @{
Encoding = $Encoding;
FilePath = $FilePath
}
}
Process {
$extraLF = ""
if ($Append) {
Write-Debug ("Appending to '{0}'." -f $FilePath)
$outfile = Get-Item $FilePath
}
else {
Write-Debug ("Creating new file '{0}'." -f $FilePath)
$outFile = New-Item -ItemType file -Path $Filepath -Force:$Force
}
if (!(Test-Path $outFile.FullName)) {Throw "Could not create File"}
Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing to file: $Filepath"
foreach ($i in $InputObject.get_keys()) {
if (!($InputObject[$i].GetType().GetInterface('IDictionary'))) {
#Key value pair
Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing key: $i"
"$i$delimiter$($InputObject[$i])" | Out-File -Append @parameters
}
elseif ($i -eq $script:NoSection) {
#Key value pair of NoSection
Out-Keys $InputObject[$i] `
@parameters `
-Delimiter $delimiter `
-MyInvocation $MyInvocation
}
else {
#Sections
Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing Section: [$i]"
# Only write section, if it is not a dummy ($script:NoSection)
if ($i -ne $script:NoSection) { "$extraLF[$i]" | Out-File -Append @parameters }
if ($Pretty) {
$extraLF = "`r`n"
}
if ( $InputObject[$i].Count) {
Out-Keys $InputObject[$i] `
@parameters `
-Delimiter $delimiter `
-MyInvocation $MyInvocation
}
}
}
Write-Verbose "$($MyInvocation.MyCommand.Name):: Finished Writing to file: $FilePath"
}
End {
if ($PassThru) {
Write-Debug ("Returning file due to PassThru argument.")
Write-Output (Get-Item $outFile)
}
Write-Verbose "$($MyInvocation.MyCommand.Name):: Function ended"
}
}
Function Get-IniContent {
<#
.Synopsis
Gets the content of an INI file
.Description
Gets the content of an INI file and returns it as a hashtable
.Notes
Author : Oliver Lipkau <[email protected]>
Source : https://github.com/lipkau/PsIni
http://gallery.technet.microsoft.com/scriptcenter/ea40c1ef-c856-434b-b8fb-ebd7a76e8d91
Version : 1.0.0 - 2010/03/12 - OL - Initial release
1.0.1 - 2014/12/11 - OL - Typo (Thx SLDR)
Typo (Thx Dave Stiff)
1.0.2 - 2015/06/06 - OL - Improvment to switch (Thx Tallandtree)
1.0.3 - 2015/06/18 - OL - Migrate to semantic versioning (GitHub issue#4)
1.0.4 - 2015/06/18 - OL - Remove check for .ini extension (GitHub Issue#6)
1.1.0 - 2015/07/14 - CB - Improve round-tripping and be a bit more liberal (GitHub Pull #7)
OL - Small Improvments and cleanup
1.1.1 - 2015/07/14 - CB - changed .outputs section to be OrderedDictionary
1.1.2 - 2016/08/18 - SS - Add some more verbose outputs as the ini is parsed,
allow non-existent paths for new ini handling,
test for variable existence using local scope,
added additional debug output.
#Requires -Version 2.0
.Inputs
System.String
.Outputs
System.Collections.Specialized.OrderedDictionary
.Example
$FileContent = Get-IniContent "C:\myinifile.ini"
-----------
Description
Saves the content of the c:\myinifile.ini in a hashtable called $FileContent
.Example
$inifilepath | $FileContent = Get-IniContent
-----------
Description
Gets the content of the ini file passed through the pipe into a hashtable called $FileContent
.Example
C:\PS>$FileContent = Get-IniContent "c:\settings.ini"
C:\PS>$FileContent["Section"]["Key"]
-----------
Description
Returns the key "Key" of the section "Section" from the C:\settings.ini file
.Link
Out-IniFile
#>
[CmdletBinding()]
[OutputType(
[System.Collections.Specialized.OrderedDictionary]
)]
Param(
# Specifies the path to the input file.
[ValidateNotNullOrEmpty()]
[Parameter( Mandatory = $true, ValueFromPipeline = $true )]
[String]
$FilePath,
# Specify what characters should be describe a comment.
# Lines starting with the characters provided will be rendered as comments.
# Default: ";"
[Char[]]
$CommentChar = @(";"),
# Remove lines determined to be comments from the resulting dictionary.
[Switch]
$IgnoreComments
)
Begin {
Write-Debug "PsBoundParameters:"
$PSBoundParameters.GetEnumerator() | ForEach-Object { Write-Debug $_ }
if ($PSBoundParameters['Debug']) {
$DebugPreference = 'Continue'
}
Write-Debug "DebugPreference: $DebugPreference"
Write-Verbose "$($MyInvocation.MyCommand.Name):: Function started"
$commentRegex = "^\s*([$($CommentChar -join '')].*)$"
$sectionRegex = "^\s*\[(.+)\]\s*$"
$keyRegex = "^\s*(.+?)\s*=\s*(['`"]?)(.*)\2\s*$"
Write-Debug ("commentRegex is {0}." -f $commentRegex)
}
Process {
Write-Verbose "$($MyInvocation.MyCommand.Name):: Processing file: $Filepath"
$ini = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase)
#$ini = @{}
if (!(Test-Path $Filepath)) {
Write-Verbose ("Warning: `"{0}`" was not found." -f $Filepath)
Write-Output $ini
}
$commentCount = 0
switch -regex -file $FilePath {
$sectionRegex {
# Section
$section = $matches[1]
Write-Verbose "$($MyInvocation.MyCommand.Name):: Adding section : $section"
$ini[$section] = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase)
$CommentCount = 0
continue
}
$commentRegex {
# Comment
if (!$IgnoreComments) {
if (!(test-path "variable:local:section")) {
$section = $script:NoSection
$ini[$section] = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase)
}
$value = $matches[1]
$CommentCount++
Write-Debug ("Incremented CommentCount is now {0}." -f $CommentCount)
$name = "Comment" + $CommentCount
Write-Verbose "$($MyInvocation.MyCommand.Name):: Adding $name with value: $value"
$ini[$section][$name] = $value
}
else {
Write-Debug ("Ignoring comment {0}." -f $matches[1])
}
continue
}
$keyRegex {
# Key
if (!(test-path "variable:local:section")) {
$section = $script:NoSection
$ini[$section] = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase)
}
$name, $value = $matches[1, 3]
Write-Verbose "$($MyInvocation.MyCommand.Name):: Adding key $name with value: $value"
if (-not $ini[$section][$name]) {
$ini[$section][$name] = $value
}
else {
if ($ini[$section][$name] -is [string]) {
$ini[$section][$name] = [System.Collections.ArrayList]::new()
$ini[$section][$name].Add($ini[$section][$name]) | Out-Null
$ini[$section][$name].Add($value) | Out-Null
}
else {
$ini[$section][$name].Add($value) | Out-Null
}
}
continue
}
}
Write-Verbose "$($MyInvocation.MyCommand.Name):: Finished Processing file: $FilePath"
Write-Output $ini
}
End {
Write-Verbose "$($MyInvocation.MyCommand.Name):: Function ended"
}
}
function Main() {
$configFile = "$env:LOCALAPPDATA\Hogwarts Legacy\Saved\Config\WindowsNoEditor\Engine.ini"
# These are a list of variables it will check exist in the file
$expectedVariables = @("r.TextureStreaming", "1"),
@("PoolSizeVRAMPercentage", "100"),
@("r.Streaming.LimitPoolSizeToVRAM", "1"),
@("r.bForceCPUAccessToGPUSkinVerts", "True"),
@("r.GTSyncType", "1"),
@("r.OneFrameThreadLag", "1"),
@("r.FinishCurrentFrame", "0")
if (!(Test-Path $configFile)) {
throw "Error: The file $configFile does not exist."
}
# Get the users VRAM avaliable in kilobytes
$vram = (Get-ItemProperty -Path "HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0*" -Name HardwareInformation.qwMemorySize -ErrorAction SilentlyContinue)."HardwareInformation.qwMemorySize" | Measure-Object -Maximum
# Calculate the amount of VRAM they can use
$poolSize = [math]::Round($vram.Maximum / 1MB / 2)
# Check if $poolSize is less than 0 or not defined, just incase the above returns null
if ($poolSize -lt 0 -or !$poolSize) {
$poolSize = 2048
}
# More than 6GB for a texture pool is too much even on a 4090
if ($poolSize -gt 6144) {
$poolSize = 6144
}
# Add the value for r.Streaming.PoolSize to the expectedVariables list
$expectedVariables += , @("r.Streaming.PoolSize", "$poolSize")
# Load the ini
$ini = Get-IniContent $configFile
$systemSection = "SystemSettings"
if (!$ini[$systemSection]) {
$ini[$systemSection] = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase)
}
for ($i=0; $i -lt $expectedVariables.length; $i++) {
$name = $expectedVariables[$i][0]
$value = $expectedVariables[$i][1]
Write-Output "key $name and value $value setting to $($ini[$systemSection][$name])"
$ini[$systemSection][$name] = $value
}
# Backup original config and delete the original
Copy-Item $configFile -Destination "$configFile.bak"
Write-Output "Copied original config to the file $configFile.bak"
Remove-Item $configFile
# Write the updated ini file
$ini | Out-IniFile -FilePath $configFile
Write-Output "Succesfully updated the file $configFile"
}
Main