Files
pokemon/scripts/launch-pc-hack.ps1
T
ginnoir 2ebc2cb276 feat: add PC fan-game migration tooling for RomM windows platform
Place RPG-Maker/Essentials hacks into RomM's windows library with dry-run migration, Playnite Game.exe launcher, and Ludusavi save-path manifest.
2026-06-23 00:09:44 -05:00

67 lines
2.7 KiB
PowerShell

<#
.SYNOPSIS
Launch a RomM-served Pokémon PC hack (RPG Maker XP / Essentials) from Playnite.
.DESCRIPTION
The RomM Playnite plugin downloads each `windows`-platform hack and extracts the
zip into a folder. These are RPG Maker XP / Pokémon Essentials games whose
launcher is `Game.exe` at the extracted folder root, and RGSS REQUIRES the
working directory to be that folder (relative paths to Data/, Audio/, Graphics/).
This script takes whatever path Playnite hands it (the extracted folder, a file
inside it, or the zip's sibling folder), locates the correct Game.exe (shallowest
match, ignoring dev tools like animmaker.exe / RPGXP.exe), sets CWD, and runs it.
Register it in Playnite as a Custom emulator (see scripts/README or the vault
ROM Library note) so every `windows` hack imported from RomM uses it.
.PARAMETER Target
Path Playnite passes — typically {ImagePath} or {StartupDir}. May be a file or
a directory; the script resolves the game folder from either.
.EXAMPLE
powershell -ExecutionPolicy Bypass -File launch-pc-hack.ps1 "{ImagePath}"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$Target
)
$ErrorActionPreference = 'Stop'
# dev/editor exes that ship alongside the game but are NOT the launcher
$ignore = @('animmaker.exe', 'rpgxp.exe', 'rgss', 'editor.exe', 'unins', 'setup.exe')
function Find-GameExe([string]$root) {
# Prefer Game.exe; fall back to the shallowest non-ignored .exe.
$candidates = Get-ChildItem -LiteralPath $root -Recurse -File -Filter '*.exe' -ErrorAction SilentlyContinue |
Where-Object { $n = $_.Name.ToLower(); -not ($ignore | Where-Object { $n -like "*$_*" }) } |
Sort-Object { ($_.FullName -split '[\\/]').Count } # shallowest first
$game = $candidates | Where-Object { $_.Name -ieq 'Game.exe' } | Select-Object -First 1
if (-not $game) { $game = $candidates | Select-Object -First 1 }
return $game
}
# Resolve the starting directory from whatever Playnite passed.
if (Test-Path -LiteralPath $Target -PathType Leaf) {
$start = Split-Path -LiteralPath $Target -Parent
} elseif (Test-Path -LiteralPath $Target -PathType Container) {
$start = $Target
} else {
throw "launch-pc-hack: path not found: $Target"
}
$exe = Find-GameExe $start
if (-not $exe) {
# The extracted game may sit one level up (Playnite handed us a sibling file).
$exe = Find-GameExe (Split-Path -LiteralPath $start -Parent)
}
if (-not $exe) { throw "launch-pc-hack: no Game.exe found under $start" }
$dir = Split-Path -LiteralPath $exe.FullName -Parent
Write-Host "Launching $($exe.Name) in $dir"
# RGSS needs CWD = game folder. Start and wait so Playnite tracks play session.
Start-Process -FilePath $exe.FullName -WorkingDirectory $dir -Wait