#
Public domain.
Like any other piece of software (and information generally), this script
comes with NO WARRANTY.
This is version 20220716 of Enhance-SilentHill2.ps1.
This script has been replaced by the Enhanced Edition installer:
http://www.enhanced.townofsilenthill.com/SH2/files/SH2EEsetup.exe
Details about this installer can be found inthis video:
https://www.youtube.com/watch?v=LylafxQta9w
This script requires you to already own a copy of Silent Hill 2 for PC.
This script is not for use with the Silent Hill HD Collection.
Example usage:
C:\Path\to\Enhance-SilentHill2.ps1 -Verbose
If your local copy of the game is not in
'C:\Users\yourname\Desktop\Silent Hill 2' as recommended, you can set
the path to the game files explicitly. If the game is in 'C:\SH2', run:
C:\Path\to\Enhance-SilentHill2.ps1 -Verbose -GamePath 'C:\SH2'
#>
<#
.SYNOPSIS
Download and install Silent Hill 2: Enhanced Edition packages
.DESCRIPTION
Silent Hill 2: Enhanced Edition is a set of updates and mods to improve the Silent Hill 2 PC gaming experience, fix bugs, and allow the game to run on newer machines. This setup script is not affiliated in any way with the Silent Hill 2: Enhanced Edition project and is not endorsed by the Silent Hill 2: Enhanced Edition development team.
.PARAMETER GamePath
The folder containing your installed Silent Hill 2 game data
.PARAMETER EnhancementPath
The folder containing this setup script
.PARAMETER TempPath
The folder where the enhancement packages will be extracted
.PARAMETER InstallVC
Set to $True to install VC++ and DirectX redistributable packages
.LINK
http://www.enhanced.townofsilenthill.com/SH2/
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$False)] [String] $GamePath = [System.IO.Path]::Combine(${Env:UserProfile}, 'Desktop', 'Silent Hill 2'),
[Parameter(Mandatory=$False)] [String] $EnhancementPath = $PSScriptRoot,
[Parameter(Mandatory=$False)] [String] $TempPath = [System.IO.Path]::GetTempPath(),
[Parameter(Mandatory=$False)] [Switch] $InstallVC = $False
)
$ErrorActionPreference = 'Continue'
Set-StrictMode -Version 1
$enhancement_urls = @{
'exe' = @{
'en_US' = 'http://www.enhanced.townofsilenthill.com/SH2/files/SH2PC_Enhanced_EXE_NA_v1.0.zip';
'multilang' = 'http://www.enhanced.townofsilenthill.com/SH2/files/SH2PC_Enhanced_EXE_Multilanguage_DC.zip';
};
'd3d8' = 'https://github.com/elishacloud/Silent-Hill-2-Enhancements/releases/download/v1.5.1750.0/d3d8.zip';
'essentials' = 'http://enhanced.townofsilenthill.com/SH2/files/Enhanced_Edition_Essential_Files_1.1.1.zip';
'fmv_pack' = 'http://enhanced.townofsilenthill.com/SH2/files/SH2PC_Enhanced_FMV_Pack_1.5.0.zip';
'indirectsnd' = 'http://www.enhanced.townofsilenthill.com/SH2/files/IndirectSound_0.20.zip';
'audio_pack' = 'http://www.enhanced.townofsilenthill.com/SH2/files/SH2PC_Audio_Enhancement_Pack_2.0.1.zip';
'reshade' = 'http://www.enhanced.townofsilenthill.com/SH2/files/SH2PC_ReShade_4.5.3_DirectX9.zip';
'vc_redist' = 'https://download.microsoft.com/download/5/B/C/5BC5DBB3-652D-4DCE-B14A-475AB85EEF6E/vcredist_x86.exe';
'dx_redist' = 'https://download.microsoft.com/download/8/4/A/84A35BF1-DAFE-4AE8-82AF-AD2AE20B6B14/directx_Jun2010_redist.exe';
# Camera editor tools:
#
#
#
}
Add-Type -Assembly 'System.IO.Compression.Filesystem'
Function IsAdmin {
Return ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')
}
Function Elevate-Admin {
if (-not (IsAdmin)) {
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" $PSCommandArgs -Verbose -InstallVC -EnhancementPath `"$EnhancementPath`" -TempPath $TempPath " -WorkingDirectory $pwd -Verb RunAs
Exit
}
}
Function Download-File {
Param([String] $Url)
$uri = New-Object -TypeName System.Uri($Url)
$file_name = $uri.Segments[-1]
$dst = [System.IO.Path]::Combine($EnhancementPath, $file_name)
$tmp = [System.IO.Path]::Combine($EnhancementPath, ("{0}.tmp" -f ($file_name)))
$wc = New-Object -TypeName System.Net.WebClient
if (Test-Path -Path $dst) { Return $dst }
if (Test-Path -Path $tmp) {
Remove-Item -Force $tmp
}
Write-Host ("Fetching {0}..." -f ($Url))
$duration = Measure-Command -Expression {
$wc.DownloadFile($Url, $tmp)
}
if (-not ([String]::IsNullOrEmpty($wc.ResponseHeaders['Last-Modified']))) {
$mtime = Get-Date -Date $wc.ResponseHeaders['Last-Modified']
Set-ItemProperty -Path $tmp -Name LastWriteTimeUtc -Value $mtime
}
Move-Item -Force -Path $tmp -Destination $dst
$len = (Get-Item -Path $dst).Length
$tp = $len / [Math]::Pow(2,20) / $duration.TotalSeconds
$unit = 'bytes'
$out_len = 0
if (1 -gt $out_len) { $out_len = $len / [Math]::Pow(2,30); $unit = 'GiB' }
if (1 -gt $out_len) { $out_len = $len / [Math]::Pow(2,20); $unit = 'MiB' }
if (1 -gt $out_len) { $out_len = $len / [Math]::Pow(2,10); $unit = 'KiB' }
$duration_str = ''
if (0 -lt $duration.Days) { $duration_str += "{0:0} days " -f ($duration.Days) }
if (0 -lt $duration.Hours) { $duration_str += "{0:0} hr " -f ($duration.Hours) }
if (0 -lt $duration.Minutes) { $duration_str += "{0:0} min " -f ($duration.Minutes) }
$duration_str += "{0:0}" -f ($duration.Seconds)
$duration_str += ".{0:000} sec" -f ($duration.Milliseconds)
Write-Host ("Fetched {0:0.0} {1} in {2} ({3:0.00} MiB/s)" -f ($out_len, $unit, $duration_str, $tp))
Return $dst
}
Function Split-Arguments {
Param([Array] $a)
if (1 -lt $a.Length) {
Return @($a[0], $enhancement_urls[$a[0]][$a[1]])
}
else {
Return @($a[0], $enhancement_urls[$a[0]])
}
}
Function Unzip-File {
Param(
[Parameter(Mandatory=$True)] [String] $Path,
[Parameter(Mandatory=$True)] [String] $Destination
)
if (Test-Path -Path $Destination) {
Remove-Item -Force -Recurse -Path $Destination
}
Write-Verbose ("Begin unzip of {0}" -f ($Path))
[IO.Compression.ZipFile]::ExtractToDirectory($Path, $Destination)
Write-Verbose 'End unzip'
Return
}
Function Install-Patch {
Param($File)
$unzip_dir = [System.IO.Path]::Combine($TempPath, 'sh2e')
$file_subdir = [System.IO.Path]::Combine($unzip_dir, 'Silent Hill 2', 'sh2e')
Unzip-File -Path $File -Destination $unzip_dir
Write-Verbose 'Begin copy'
Copy-Item -Force -Recurse -Path $file_subdir -Destination $GamePath
Write-Verbose 'End copy'
Remove-Item -Force -Recurse -Path $unzip_dir
Return
}
Function exe {
Param($File)
Write-Verbose 'Begin Step - Enhanced sh2pc.exe'
if (-not (Test-Path -Path $File)) {
Write-Error ("file {0} not found" -f ($File))
Return
}
$unzip_dir = [System.IO.Path]::Combine($TempPath, 'sh2e-enhancedexe')
$file_new = [System.IO.Path]::Combine($unzip_dir, 'Silent Hill 2', 'sh2pc.exe')
$file_orig = [System.IO.Path]::Combine($GamePath, 'sh2pc.exe')
$file_backup = [System.IO.Path]::Combine($GamePath, 'sh2pc.exe.backup')
Unzip-File -Path $File -Destination $unzip_dir
if (-not (Test-Path -Path $file_backup)) {
if (Test-Path -Path $file_orig) {
Write-Verbose 'Begin copy'
Copy-Item -Path $file_orig -Destination $file_backup
Write-Verbose 'End copy'
}
}
Copy-Item -Force -Path $file_new -Destination $file_orig
Remove-Item -Force -Recurse -Path $unzip_dir
Write-Verbose 'End Step'
Return
}
Function d3d8 {
Param($File)
Write-Verbose 'Begin Step - d3d8 Enhancements'
$unzip_dir = [System.IO.Path]::Combine($TempPath, 'sh2e-d3d8')
Unzip-File -Path $File -Destination $unzip_dir
Write-Verbose 'Begin move'
Get-ChildItem -Path $unzip_dir | Move-Item -Force -Destination $GamePath
Write-Verbose 'End move'
Remove-Item -Force -Recurse -Path $unzip_dir
Write-Verbose 'End Step'
Return
}
Function essentials {
Param($File)
Write-Verbose 'Begin Step - Enhanced Edition Essential Files'
Install-Patch $File
Write-Verbose 'End Step'
Return
}
Function fmv_pack {
Param($File)
Write-Verbose 'Begin Step - FMV Enhancement Pack'
Install-Patch $File
Write-Verbose 'End Step'
Return
}
Function indirectsnd {
Param($File)
Write-Verbose 'Begin Step - IndirectSound'
$unzip_dir = [System.IO.Path]::Combine($TempPath, 'sh2e-indirectsound')
Unzip-File -Path $File -Destination $unzip_dir
Write-Verbose 'Begin copy'
@('dll', 'ini') | foreach {
$file = [System.IO.Path]::Combine($unzip_dir, 'SILENT HILL 2', "dsound.{0}" -f ($_))
Copy-Item -Force -Path $file -Destination $GamePath
}
Write-Verbose 'End copy'
Remove-Item -Force -Recurse -Path $unzip_dir
Write-Verbose 'End Step'
Return
}
Function audio_pack {
Param($File)
Write-Verbose 'Begin Step - Audio Enhancement Pack'
Install-Patch $File
Write-Verbose 'End Step'
Return
}
Function reshade {
Param($File)
Write-Verbose 'Begin Step - ReShade Filter'
$unzip_dir = [System.IO.Path]::Combine($TempPath, 'sh2e')
$file_subdir = [System.IO.Path]::Combine($unzip_dir, 'Silent Hill 2')
Unzip-File -Path $File -Destination $unzip_dir
Write-Verbose 'Begin copy'
Get-ChildItem -Path $file_subdir | foreach {
Copy-Item -Recurse -Force -Path $_.FullName -Destination $GamePath
}
Write-Verbose 'End copy'
Remove-Item -Force -Recurse -Path $unzip_dir
Write-Verbose 'End Step'
Return
}
Function customini {
Param($File)
Write-Verbose 'Begin Step - Install Custom d3d8.ini'
$ini = [System.IO.Path]::Combine($EnhancementPath, 'd3d8.ini')
if (Test-Path -Path $ini) {
Write-Verbose 'Begin copy'
Copy-Item -Path $ini -Destination $GamePath
Write-Verbose 'End copy'
}
Write-Verbose 'End Step'
Return
}
Function vc_redist {
Param($File)
Write-Verbose 'Begin Step - Microsoft Visual C++ 2010 Redistributable Package (x86)'
if (-not (IsAdmin)) {
Write-Verbose 'not in elevated mode'
Write-Verbose 'End Step'
Return $True
}
$uri = New-Object -TypeName System.Uri($enhancement_urls['vc_redist'])
$File = Join-Path $EnhancementPath $uri.Segments[-1]
Write-Verbose 'Install Microsoft Visual C++ 2010 Redistributable Package (x86)'
Start-Process -Wait -NoNewWindow -FilePath $File -ArgumentList '/q'
Write-Verbose 'End Step'
Return
}
Function dx_redist {
Param($File)
Write-Verbose 'Begin Step - DirectX June 2010'
if (-not (IsAdmin)) {
Write-Verbose 'not in elevated mode'
Write-Verbose 'End Step'
Return $True
}
if ($null -eq $File) {
$uri = New-Object -TypeName System.Uri($enhancement_urls['dx_redist'])
$File = [System.IO.Path]::Combine($EnhancementPath, $uri.Segments[-1])
}
$tmp_path = [System.IO.Path]::Combine($TempPath, 'directx')
$dx_setup_bin = [System.IO.Path]::Combine($tmp_path, 'dxsetup.exe')
Write-Verbose 'DirectX June 2010 Redistributable Package'
Start-Process -Wait -NoNewWindow -FilePath $File -ArgumentList @('/q', ("/t:`"{0}`"" -f ($tmp_path)))
Start-Process -Wait -NoNewWindow -FilePath $dx_setup_bin
Write-Verbose 'End Step'
Return
}
Function Main {
$files = @()
$functions = @()
$need_elevation = @()
$steps_install = @('vc_redist') # Microsoft Visual C++ 2010 Redistributable Package (x86)
$steps_install += 'dx_redist' # DirectX June 2010 Redistributable Package
$steps_download = @(
@('exe', 'en_US'), # enhanced EXE
'essentials' # enhanced edition essential files
)
$steps_download += 'd3d8' # enhancements
$steps_download += 'fmv_pack' # FMV enhancement pack
$steps_download += 'indirectsnd' # IndirectSound
$steps_download += 'audio_pack' # audio enhancement pack
$steps_download += 'reshade' # ReShade
$steps_download += 'vc_redist' # Microsoft Visual C++ 2010 Redistributable Package (x86)
$steps_download += 'dx_redist' # DirectX June 2010 Redistributable Package
if ($InstallVC) {
foreach ($step in $steps_install) {
Invoke-Expression $step
}
Return
}
foreach ($step in $steps_download) {
$pieces = Split-Arguments $step
$file = Download-File -Url $pieces[1]
$functions += (@($pieces[0], $file) -join ' ')
}
foreach ($f in $functions) {
$result = Invoke-Expression $f
if ($null -ne $result) {
$need_elevation += $result
}
}
Invoke-Expression 'customini' # install custom d3d8.ini if present
if (0 -lt $need_elevation.Length) { Elevate-Admin }
Return
}
. Main
Exit