Created
November 17, 2023 16:05
-
-
Save refracta/4445006e37cae9c86fde3b751d4cf98c to your computer and use it in GitHub Desktop.
발더스게이트 3 한글 패치 자동 설치기 (일반 배포용)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
if exist "patcher.ps1" ( | |
del "patcher.ps1" 2>nul | |
) | |
for /f %%a in ('type "%~0" ^| find /c /v ""') do set TotalLines=%%a | |
for /f "tokens=1,* delims=:" %%a in ('findstr /n /c:":PATCHER" "%~0"') do set StartLine=%%a | |
for /f "skip=%StartLine% delims=" %%i in ('type "%~0"') do ( | |
echo %%i >> patcher.ps1 | |
) | |
echo This automatic patcher may fail depending on your system environment. | |
echo If an error occurs, please manually paste the patch file into the game directory. | |
echo: | |
powershell.exe -ExecutionPolicy Bypass -File patcher.ps1 | |
pause | |
goto :eof | |
:PATCHER | |
Add-Type -AssemblyName System.Windows.Forms | |
function getLibraryFoldersVDFPath { | |
$drives = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Root -like "[A-Z]:\" } | |
foreach ($drive in $drives) { | |
$targetPath = Join-Path $drive.Root "Program Files (x86)\Steam\config\libraryfolders.vdf" | |
if (Test-Path $targetPath) { | |
return $targetPath | |
} | |
} | |
return $null | |
} | |
function getSteamLibraryPaths { | |
$vdfPath = getLibraryFoldersVDFPath | |
if (-not $vdfPath) { | |
Write-Error "Failed to retrieve the Steam library info file (libraryfolders.vdf)." | |
return @() | |
} | |
$content = Get-Content $vdfPath -Raw | |
$matches = [regex]::Matches($content, """\d+""\s+{\s+""path""\s+""([^""]+)""") | |
return $matches | ForEach-Object { | |
$_.Groups[1].Value -replace '\\\\', '\' | |
} | |
} | |
function getUserBG3Path { | |
$folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog | |
$folderBrowser.Description = "Select the Baldurs Gate 3 folder." | |
$folderBrowser.RootFolder = [System.Environment+SpecialFolder]::MyComputer | |
if ($folderBrowser.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { | |
return $folderBrowser.SelectedPath | |
} | |
return $null | |
} | |
function getSteamBG3Path { | |
$libraries = getSteamLibraryPaths | |
foreach ($library in $libraries) { | |
$bg3Path = Join-Path $library "steamapps\common\Baldurs Gate 3" | |
if (Test-Path $bg3Path) { | |
return $bg3Path | |
} | |
} | |
return $null | |
} | |
function Backup-File { | |
param ( | |
[string]$path | |
) | |
$backupPath = "$path.1.bak" | |
$counter = 1 | |
while (Test-Path $backupPath) { | |
$counter++ | |
$backupPath = "$path.$counter.bak" | |
} | |
Move-Item -Path $path -Destination $backupPath -ErrorAction SilentlyContinue | |
} | |
function Copy-WithBackup { | |
param ( | |
[string]$source, | |
[string]$destination | |
) | |
if ($destination -like "*\Localization\*") { | |
if (Test-Path $destination) { | |
Backup-File -Path $destination | |
} | |
} | |
Copy-Item -Path $source -Destination $destination -Force | |
$trimmedSource = $source -replace "^.+\\Data", "Data" | |
Write-Output "$trimmedSource >>> $destination" | |
} | |
function cleanExit { | |
Remove-Item -Path patcher.ps1 | |
exit | |
} | |
$bg3Path = getSteamBG3Path | |
if ($bg3Path) { | |
Write-Output "Baldurs Gate 3 Path (Steam): $bg3Path" | |
} else { | |
Write-Output "Please select the folder where Baldurs Gate 3 is installed." | |
$bg3Path = getUserBG3Path | |
if($bg3Path) { | |
Write-Output "Baldurs Gate 3 Path (User): $bg3Path" | |
} else { | |
Write-Output "Patch cancelled." | |
cleanExit | |
} | |
} | |
if ($bg3Path) { | |
$sourceData = Join-Path $PSScriptRoot "Data" | |
$destinationData = Join-Path $bg3Path "Data" | |
if($sourceData -eq $destinationData) { | |
Write-Host "Patch is already complete (Running patcher in game path)" -ForegroundColor Red | |
cleanExit | |
} | |
$pakFiles = Get-ChildItem -Filter *.pak | |
$keys = [char[]](97..122) # a-z | |
$pakMenu = @{} | |
Write-Host "`nSelect your translation pak file: " | |
for ($i = 0; $i -lt $pakFiles.Count; $i++) { | |
$key = $keys[$i] | |
$file = $pakFiles[$i] | |
$pakMenu[$key] = $file | |
Write-Host "`t($key) $file" | |
} | |
Write-Host "`t" -NoNewLine | |
$selectedPak = $null | |
while ($null -eq $selectedPak) { | |
$input = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | |
if ($pakMenu.ContainsKey($input.Character)) { | |
$selectedPak = $pakMenu[$input.Character] | |
} | |
} | |
Write-Host "`n`tSelected pak: $($selectedPak.Name)" -ForegroundColor Blue | |
$dirs = Get-ChildItem -Recurse -Directory | |
$fontDirs = @() | |
$fontFullDirs = @() | |
foreach ($dir in $dirs) { | |
$dataFolder = Join-Path $dir.FullName "Data" | |
if (Test-Path $dataFolder) { | |
$fontDirs += $dir | |
$fontFullDirs += $dir.FullName | |
} | |
} | |
$fontMenu = @{} | |
Write-Host "`nSelect your font: " | |
for ($i = 0; $i -lt $fontDirs.Count; $i++) { | |
$key = $keys[$i] | |
$dir = $fontDirs[$i] | |
$fullDir = $fontFullDirs[$i] | |
$fontMenu[$key] = $dir, $fullDir | |
Write-Host "`t($key) $dir" | |
} | |
Write-Host "`t" -NoNewLine | |
$selectedFont = $null | |
while ($null -eq $selectedFont) { | |
$input = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | |
if ($fontMenu.ContainsKey($input.Character)) { | |
$selectedFont = $fontMenu[$input.Character] | |
} | |
} | |
Write-Host "`n`tSelected font: $($selectedFont[0].Name)" -ForegroundColor Blue | |
Remove-Item -Path Data -Recurse -Force -ErrorAction SilentlyContinue | |
Copy-Item -Path "$($selectedFont[1])\Data" -Destination . -Recurse -Force | |
New-Item -Path Data\Localization -ItemType Directory | Out-Null | |
Copy-Item -Path $selectedPak -Destination Data\Localization\English.pak -Force | |
Write-Host | |
if (Test-Path $sourceData) { | |
Get-ChildItem -Path $sourceData -Recurse | ForEach-Object { | |
$relativePath = $_.FullName.Substring($sourceData.Length) | |
$destinationPath = Join-Path $destinationData $relativePath | |
if ($_ -is [System.IO.DirectoryInfo]) { | |
if (-not (Test-Path $destinationPath)) { | |
New-Item -ItemType Directory -Path $destinationPath | Out-Null | |
} | |
} else { | |
Copy-WithBackup -Source $_.FullName -Destination $destinationPath | |
} | |
} | |
Remove-Item -Path Data -Recurse -Force -ErrorAction SilentlyContinue | |
Write-Host "Korean patch done! Balkkiyathou~!!!" -ForegroundColor Green | |
} else { | |
Write-Error "Cannot find patch file. Please uncompress file first." | |
} | |
} | |
cleanExit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment