Skip to content

Instantly share code, notes, and snippets.

@childsish
Last active July 8, 2018 05:46
Show Gist options
  • Save childsish/ab22851093ef00396f41cb3db026a2f3 to your computer and use it in GitHub Desktop.
Save childsish/ab22851093ef00396f41cb3db026a2f3 to your computer and use it in GitHub Desktop.
A simple Powershell save game backup script to cheese Mordheim: City of the Damned
$Process = @(Get-CimInstance Win32_Process -Filter "Name='powershell.exe' AND CommandLine LIKE '%mordheim.ps1%'")
if ($Process.Count -gt 1) {
exit
}
Add-Type -Name Window -Namespace Console -MemberDefinition '
[DllImport("Kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
'
$SteamRegistryPath = "hkcu:\Software\Valve\Steam"
$SteamPath = Get-ItemProperty -Path $SteamRegistryPath -Name SteamPath
$MordheimSavesPath = $SteamPath.SteamPath + "/userdata/81398979/276810"
$MordheimBackupsPath = [Environment]::GetFolderPath("MyDocuments") + "\Mordheim copied saves\276810"
Function Hide-Console {
$ConsolePtr = [Console.Window]::GetConsoleWindow()
[Console.Window]::ShowWindow($ConsolePtr, 0)
}
Function SaveClick([System.Windows.Forms.TextBox]$TextBox) {
if (Test-Path $MordheimSavesPath) {
if (Test-Path $MordheimBackupsPath) {
Rename-Item -Path $MordheimBackupsPath -NewName ($MordheimBackupsPath + ".bak")
}
try {
Copy-Item -Path $MordheimSavesPath -Destination $MordheimBackupsPath -Recurse
$TextBox.Text = "Mordheim saves backed up."
}
catch {
if (Test-Path $MordheimBackupsPath) {
Remove-Item $MordheimBackupsPath -Recurse
}
Rename-Item -Path ($MordheimBackupsPath + ".bak") -NewName $MordheimBackupsPath
$TextBox.Text = "Unable to backup Mordheim saves.";
}
if (Test-Path ($MordheimBackupsPath + ".bak")) {
Remove-Item -Path ($MordheimBackupsPath + ".bak") -Recurse
}
}
else {
$TextBox.Text = "Unable to find Mordheim saves."
#$TextBox.Text = $MordheimSavesPath
}
}
Function LoadClick([System.Windows.Forms.TextBox]$TextBox) {
if (Test-Path $MordheimBackupsPath) {
if (Test-Path $MordheimSavesPath) {
Remove-Item -Path $MordheimSavesPath -Recurse
}
Copy-Item -Path $MordheimBackupsPath -Destination $MordheimSavesPath -Recurse
$TextBox.Text = "Mordheim backups restored."
}
else {
$TextBox.Text = "Unable to find Mordheim backups."
}
}
Function Minimise([System.Windows.Forms.Form]$Form) {
$Form.WindowState = [System.Windows.Forms.FormWindowState]::Minimized
}
Function Generate-Form {
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "Mordheim Backups"
$Form.Size = New-Object System.Drawing.Size(200, 200)
$Form.StartPosition = "CenterScreen"
$Form.Topmost = $True
$Form.MaximizeBox = $false
$Form.MinimizeBox = $false
$Form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$TextBox = New-Object System.Windows.Forms.TextBox
$TextBox.Location = New-Object System.Drawing.Size(5, 105)
$TextBox.Size = New-Object System.Drawing.Size(175, 23)
$TextBox.Enabled = $false
$SaveButton = New-Object System.Windows.Forms.Button
$SaveButton.Location = New-Object System.Drawing.Size(35, 35)
$SaveButton.Size = New-Object System.Drawing.Size(120, 23)
$SaveButton.Text = "Save"
$SaveButton.Add_Click({ (SaveClick $TextBox) })
$LoadButton = New-Object System.Windows.Forms.Button
$LoadButton.Location = New-Object System.Drawing.Size(35, 70)
$LoadButton.Size = New-Object System.Drawing.Size(120, 23)
$LoadButton.Text = "Load"
$LoadButton.Add_Click({ (LoadClick $TextBox ) })
$Form.Controls.Add($SaveButton)
$Form.Controls.Add($LoadButton)
$Form.Controls.Add($TextBox)
$Form.Add_Deactivate({ (Minimise $Form) })
$form.ShowDialog()| Out-Null
}
Hide-Console
Generate-Form
@childsish
Copy link
Author

childsish commented Jan 1, 2018

I just didn't have the time to play Mordheim properly so I created a script that could backup and restore the save files. Just download it and run it (try the context menu - right click on the script). The GUI automatically minimises when focus is lost. Saving can be performed when Mordheim is running, but loading probably needs to be done when Mordheim is not. No guarantees that it works and make sure you know you're doing something safe before downloading and running a strange script off the internet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment