$AppData = [Environment]::GetFolderPath('ApplicationData')
$Display = Get-PrimaryDisplay
$VirtualStore = "registry::\HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\SOFTWARE"
New-Item "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts" -Force
New-Item "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts\The Battle for Middle-earth II" -Force
New-Item "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts\The Battle for Middle-earth II\ergc" -Force
New-Item "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Force
New-Item "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II\1.0" -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts\The Battle for Middle-earth II" -Name "Language" -Value "english" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts\The Battle for Middle-earth II" -Name "InstallPath" -Value "$InstallDirectory" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts\The Battle for Middle-earth II" -Name "Version" -Value 65542 -PropertyType DWord -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts\The Battle for Middle-earth II" -Name "MapPackVersion" -Value 65536 -PropertyType DWord -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts\The Battle for Middle-earth II" -Name "UseLocalUserMaps" -Value 0 -PropertyType DWord -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts\The Battle for Middle-earth II" -Name "UserDataLeafName" -Value "My Battle for Middle-earth(tm) II Files" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts\The Battle for Middle-earth II\ergc" -Name "(default)" -Value "" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "DisplayName" -Value "The Battle for Middle-earth (tm) II" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "Installed From" -Value "H:\" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "Registration" -Value "SOFTWARE\Electronic Arts\Electronic Arts\The Battle for Middle-earth II\ergc" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "CacheSize" -Value "5499066368" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "SwapSize" -Value "0" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "Language" -Value "English UK" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "Locale" -Value "en_uk" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "CD Drive" -Value "H:\" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "Install Dir" -Value "$InstallDirectory" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "Product GUID" -Value "{2A9F95AB-65A3-432c-8631-B8BC5BF7477A}" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "Region" -Value "NorthAmerica" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "Folder" -Value "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Electronic Arts\The Battle for Middle-earth (tm) II\" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "Patch URL" -Value "http://transtest.ea.com/Electronic Arts/The Battle for Middle-earth 2/NorthAmerica" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Name "Suppression Exe" -Value "rtsi.exe" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II\1.0" -Name "Language" -Value 19 -PropertyType DWord -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II\1.0" -Name "DisplayName" -Value "The Battle for Middle-earth (tm) II" -PropertyType String -Force
New-ItemProperty -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II\1.0" -Name "LanguageName" -Value "English UK" -PropertyType String -Force
New-Item -Path "registry::\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\lotrbfme2.exe"
New-ItemProperty -Path "registry::\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\lotrbfme2.exe" -Name "Game Registry" -Value "SOFTWARE\Electronic Arts\The Battle for Middle-earth II" -Force
New-ItemProperty -Path "registry::\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\lotrbfme2.exe" -Name "Restart" -Value 0 -Force
New-ItemProperty -Path "registry::\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\lotrbfme2.exe" -Name "DirectX Installed" -Value 0 -Force
New-ItemProperty -Path "registry::\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\lotrbfme2.exe" -Name "Installed" -Value 1 -Force
New-ItemProperty -Path "registry::\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\lotrbfme2.exe" -Name "@" -Value "$InstallDirectory\lotrbfme2.exe" -Force
New-ItemProperty -Path "registry::\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\lotrbfme2.exe" -Name "Path" -Value "$InstallDirectory" -Force
Copy-Item -Path "$InstallDirectory\ProfileTemplate" -Destination "$AppData\My Battle for Middle-earth(tm) II Files" -Recurse -Force
Write-ReplaceContentInFile -Pattern '^Resolution = (.+)' -Substitution "Resolution = $($Display.Bounds.Width) $($Display.Bounds.Height)" -FilePath "$AppData\My Battle for Middle-earth(tm) II Files\Options.ini"
# Skip Intros
Remove-Item -Path "$InstallDirectory\data\movies\CS01.vp6"
Remove-Item -Path "$InstallDirectory\data\movies\TE_LOGO.vp6"
Remove-Item -Path "$InstallDirectory\data\movies\NewLineLogo.vp6"
Remove-Item -Path "$InstallDirectory\data\movies\NLC_LOGO.vp6"
Remove-Item -Path "$InstallDirectory\data\movies\EALogo.vp6"
$VirtualStore = "registry::\HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\SOFTWARE"
Remove-Item -Path "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts" -Force -Recurse
Remove-Item -Path "$VirtualStore\WOW6432Node\Electronic Arts\The Battle for Middle-earth II" -Force -Recurse
Remove-Item -Path "registry::\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\lotrbfme2.exe" -Force -Recurse
Remove-Item -Path "%appdata%\My Battle for Middle-earth(tm) II Files" -Force -Recurse
if ($NewPlayerAlias.Length -gt 10) {
$NewPlayerAlias = $NewPlayerAlias.Substring(0, 10);
}
$NetworkPrefsFormattedName = ""
foreach ($character in $NewPlayerAlias.ToCharArray()) {
$NetworkPrefsFormattedName = $NetworkPrefsFormattedName + $character + "_00"
}
$NetworkPrefsIni = @"
Rts:Color = 6
Rts:PrimarySort = 4
Rts:Rules = 1 0 1 100 1000 -1 -1 -1 -1 -1
Rts:SecondarySort = 8
Rts:StatusColumn = 0
Strat:Color = 0
Strat:PrimarySort = 4
Strat:SecondarySort = 8
Strat:StrategicScenario = 1
UserName = $NetworkPrefsFormattedName
"@
New-Item -ItemType Directory -Force -Path "$($env:APPDATA)\My Battle for Middle-earth(tm) II Files"
Set-Content "$($env:APPDATA)\My Battle for Middle-earth(tm) II Files\NetworkPref.ini" $NetworkPrefsIni
$VirtualStore = "registry::\HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\SOFTWARE"
$BaseRegistryPath = "$VirtualStore\WOW6432Node\Electronic Arts\Electronic Arts\The Battle for Middle-earth II\ergc"
New-Item -Path $BaseRegistryPath
Set-ItemProperty -Path "$BaseRegistryPath" -Name "(Default)" -Value $AllocatedKey -Force