Skip to content

Instantly share code, notes, and snippets.

@biosmanager
Created August 8, 2020 13:58
Show Gist options
  • Save biosmanager/56df733a9ff2801c50e072c4903089d6 to your computer and use it in GitHub Desktop.
Save biosmanager/56df733a9ff2801c50e072c4903089d6 to your computer and use it in GitHub Desktop.
Launches The Legend of Zelda: Breath of the Wild in CEMU with a given resolution and framerate, changing the corresponding graphics pack. Afterwards it restores the previous display settings.
##########################################################################################################
# Launches The Legend of Zelda: Breath of the Wild in CEMU with a given resolution and restores the #
# previous resolution after exit. #
# Also changes the graphics pack resolution. #
# Uses my other tool DisplaySettingsChanger (https://github.com/biosmanager/DisplaySettingsChanger). #
# Make sure you have that tool in the same path as this script or in PATH. #
# #
# I use this script to easily switch the resolution when playing on different monitors. #
##########################################################################################################
## Parameters
param (
[string]$width = $(throw "-width is required."),
[string]$height = $(throw "-height is required."),
[string]$refreshRate = $(throw "-refreshRate is required.")
)
# Configuration
$cemuDirectoryPath = "D:\Games\CEMU\Emulator"
$botwRpxPath = "D:\Games\CEMU\Games\BOTW\Game\The Legend of Zelda Breath of the Wild [ALZE01]\code\U-King.rpx"
# Temporary file to store current display settings in
$tempFile = New-TemporaryFile
# Backup current primary display settings
DisplaySettingsChanger.exe get -j -f $tempFile.FullName
# Change display settings
DisplaySettingsChanger.exe set -w $width -h $height -r $refreshRate
# Backup existing CEMU settings
Copy-Item (Join-Path $cemuDirectoryPath -ChildPath "settings.xml") -Destination (Join-Path $cemuDirectoryPath -ChildPath "settings.xml.bak")
# Find if that resolution is a valid graphics pack setting
$graphicsPackResolution = Select-String (Join-Path $cemuDirectoryPath -ChildPath "graphicPacks\downloadedGraphicPacks\BreathOfTheWild_Resolution\rules.txt") -Pattern "$($width)x$($height)"
if ($graphicsPackResolution.Matches.Count -gt 0)
{
# Edit resolution in CEMU settings
$resolutionEntry = Select-XML (Join-Path $cemuDirectoryPath -ChildPath "settings.xml") -XPath "//Entry[@filename='graphicPacks\downloadedGraphicPacks\BreathOfTheWild_Resolution\rules.txt']"
$resolutionEntry.Node.Preset.preset = $graphicsPackResolution.Matches[0].Value
$resolutionEntry.Node.OwnerDocument.Save($resolutionEntry.Path)
}
else
{
Write-Error "The resolution $($width)x$($height) is not a preset for the BotW resolution graphics pack!"
}
# Find if refresh rate is a valid graphics pack setting
$graphicsPackFps = Select-String (Join-Path $cemuDirectoryPath -ChildPath "graphicPacks\downloadedGraphicPacks\BreathOfTheWild_FPS++\Limit FPS\rules.txt") -Pattern $refreshRate
if ($graphicsPackFps.Matches.Count -gt 0)
{
# Edit resolution in CEMU settings
$fpsEntry = Select-XML (Join-Path $cemuDirectoryPath -ChildPath "settings.xml") -XPath "//Entry[@filename='graphicPacks\downloadedGraphicPacks\BreathOfTheWild_FPS++\Limit FPS\rules.txt']"
$fpsEntry.Node.Preset.preset = $graphicsPackFps.Matches[0].Value
$fpsEntry.Node.OwnerDocument.Save($fpsEntry.Path)
}
else
{
Write-Error "$($refreshRate) FPS is not a preset for the BotW resolution graphics pack!"
}
# Launch game
Write-Output "Game running..."
Start-Process -FilePath (Join-Path $cemuDirectoryPath -ChildPath "CEMU.exe") -ArgumentList "-f -g `"$botwRpxPath`"" -Wait
# Restore previously saved display settings
DisplaySettingsChanger.exe set -j -f $tempFile.FullName
# Clean-up temporary file
Remove-Item $tempFile.FullName -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment