|
| 1 | +$SCR_DIR = $(Split-Path $MyInvocation.MyCommand.Path -Parent) |
| 2 | +$SHOOK_DIR = "$SCR_DIR/../src/thirdparty/ScriptHook" |
| 3 | +$DOMAIN = "http://www.dev-c.com" |
| 4 | +$LINK = "/rdr2/scripthookrdr2/" |
| 5 | +$FILES = @( |
| 6 | + "inc/", "lib/", |
| 7 | + "inc/enums.h", "inc/main.h", "inc/nativeCaller.h", "inc/natives.h", |
| 8 | + "inc/types.h", "lib/ScriptHookRDR2.lib", "readme.txt" |
| 9 | +) |
| 10 | +$PATCHES = @{ |
| 11 | + "inc/main.h" = @( |
| 12 | + ,@( |
| 13 | + "VER_1_0_1207_69_RGS,`r`n`r`n`tVER_SIZE", |
| 14 | + ("`VER_1_0_1207_69_RGS,`r`n" + |
| 15 | + "`r`n`t//Added by patcher`r`n" + |
| 16 | + "`tVER_1_0_1207_73_RGS,`r`n" + |
| 17 | + "`tVER_1_0_1207_77_RGS,`r`n" + |
| 18 | + "`tVER_1_0_1207_80_RGS,`r`n" + |
| 19 | + "`tVER_1_0_1232_13_RGS,`r`n" + |
| 20 | + "`tVER_1_0_1232_17_RGS,`r`n" + |
| 21 | + "`tVER_1_0_1311_12_RGS,`r`n" + |
| 22 | + "`tVER_1_0_1436_25_RGS,`r`n" + |
| 23 | + "`tVER_1_0_1436_31_RGS,`r`n" + |
| 24 | + "`r`n`tVER_SIZE") |
| 25 | + ) |
| 26 | + ) |
| 27 | +} |
| 28 | + |
| 29 | +if(Test-Path -PathType Container $SHOOK_DIR) { |
| 30 | + $corrupted = $false |
| 31 | + |
| 32 | + Foreach($item in $FILES) { |
| 33 | + if(!(Test-Path "$SHOOK_DIR/$item")) { |
| 34 | + $corrupted = $true; |
| 35 | + break |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + if($corrupted) { |
| 40 | + $title = "Corrupted ScriptHookRDR2 installation" |
| 41 | + $text = "Looks like you have a broken ScriptHookRDR2, do you want to redownload it?" |
| 42 | + $choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription] |
| 43 | + $choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList "&Yes", "ScriptHookRDR2 will be redownloaded")) |
| 44 | + $choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList "&No", "This script will close")) |
| 45 | + switch($Host.UI.PromptForChoice($title, $text, $choices, 1)) { |
| 46 | + 0 { |
| 47 | + Remove-Item -Recurse -Force $SHOOK_DIR |
| 48 | + } |
| 49 | + 1 { |
| 50 | + Write-Host "Operation cancelled" |
| 51 | + Exit 0 |
| 52 | + } |
| 53 | + } |
| 54 | + } else { |
| 55 | + Exit 0 |
| 56 | + } |
| 57 | +} else { |
| 58 | + New-Item -ItemType Directory -Path $SHOOK_DIR |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +$HEADERS = @{ |
| 63 | + "Referer" = ($DOMAIN + $LINK); |
| 64 | + "User-Agent" = "RL/1.0" |
| 65 | +} |
| 66 | + |
| 67 | +Foreach($elem in (Invoke-WebRequest -URI ($DOMAIN + $LINK)).Links.Href) { |
| 68 | + if($elem.IndexOf("ScriptHookRDR2_SDK") -ige 0) { |
| 69 | + $outFile = "$SCR_DIR/temp.zip"; |
| 70 | + Invoke-WebRequest -Uri ($DOMAIN + $elem) -OutFile $outFile -Headers $HEADERS |
| 71 | + Add-Type -Assembly System.IO.Compression.FileSystem |
| 72 | + $zip = [IO.Compression.ZipFile]::OpenRead($outFile) |
| 73 | + Foreach($ent in $zip.Entries) { |
| 74 | + $fileName = $ent.FullName |
| 75 | + if($FILES.Contains($fileName)) { |
| 76 | + if($fileName.Substring($fileName.Length - 1) -eq '/') { |
| 77 | + New-Item -ItemType Directory -Path "$SHOOK_DIR\$filename" |
| 78 | + Continue |
| 79 | + } |
| 80 | + [IO.Compression.ZipFileExtensions]::ExtractToFile($ent, "$SHOOK_DIR\$fileName", $true) |
| 81 | + } |
| 82 | + } |
| 83 | + $zip.Dispose() |
| 84 | + Foreach($fpatches in $PATCHES.GetEnumerator()) { |
| 85 | + $fileName = "$SHOOK_DIR/$($fpatches.Name)" |
| 86 | + $content = (Get-Content $fileName -Raw) |
| 87 | + Foreach($patch in $fpatches.Value) { |
| 88 | + $content = $content -replace $patch[0], $patch[1] |
| 89 | + } |
| 90 | + $content | Set-Content $fileName -Force |
| 91 | + } |
| 92 | + Remove-Item -Path $outFile |
| 93 | + Exit 0 |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +Write-Error "SDK link not found" |
0 commit comments