Skip to content

About

Windows background watcher that imports, builds, pushes and deploys Railroader mod source zips

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

Mod Build Watcher

A Windows background script for authors of C# game mods who get new versions of their mod's source as zip files (for example from an AI chat). It is set up for Railroader out of the box, and works for other games built with dotnet build through the Game setting. Drop <Mod>-<version>-source.zip into a watched folder and it:

  1. checks the zip,
  2. imports it into the mod's git repo as a commit,
  3. builds it against your game install,
  4. pushes it to GitHub and copies the built mod into the game.

If the build fails and Claude Code is installed, a headless Claude Code session is allowed to try a minimal compile fix, which the script then checks for itself. Everything else runs without AI and costs nothing.

Requirements

  • Windows 10 or 11 with Windows PowerShell 5.1 (built in).
  • Git for Windows and the .NET SDK.
  • For Railroader: version 0.6.0 or newer (the game's built-in mod loader).
  • Optional: GitHub CLI (gh), signed in, to open an issue when a build can't be fixed.
  • Optional: Claude Code, signed in, for automatic compile fixes.

Your mod's repo

Each mod lives in <ProjectsDir>\<Mod>. It must be:

  • a git repo on branch main, with its first version committed by hand;
  • built by <Mod>.csproj, with a version file next to it: for Railroader, an Info.json that has a "version" field (the game's mod format), otherwise whatever Game.VersionFile and Game.VersionField name;
  • optionally pushed to an origin remote. Without one, commits stay local.

The watcher builds with:

dotnet build -c Release -nologo /p:RailroaderDir=<GameDir> /p:ModsDir=<ModsDir> [/p:DeployToGame=false]

(for another game, RailroaderDir is Game.DirProperty, GameDir by default), so the csproj should reference the game's DLLs through that property and copy the built mod and its version file into $(ModsDir)\<Mod> after the build unless DeployToGame is false. The watcher checks the deploy by reading the version file there. For Railroader:

<PropertyGroup>
  <RailroaderDir Condition="'$(RailroaderDir)' == ''">C:\Program Files (x86)\Steam\steamapps\common\Railroader</RailroaderDir>
  <ManagedDir>$(RailroaderDir)\Railroader_Data\Managed</ManagedDir>
  <ModsDir Condition="'$(ModsDir)' == ''">$([System.Environment]::GetFolderPath(SpecialFolder.MyDocuments))\Railroader\Mods</ModsDir>
</PropertyGroup>
<ItemGroup>
  <Reference Include="$(ManagedDir)\Railroader.dll" Private="false" />
  <Reference Include="$(ManagedDir)\Railroader.Modding.dll" Private="false" />
  <Reference Include="$(ManagedDir)\UnityEngine.CoreModule.dll" Private="false" />
</ItemGroup>
<Target Name="DeployToGame" AfterTargets="Build" Condition="'$(DeployToGame)' != 'false'">
  <Copy SourceFiles="$(OutDir)MyMod.dll;Info.json" DestinationFolder="$(ModsDir)\MyMod" />
</Target>

Setup

  1. Clone or download this repo anywhere.
  2. Copy config.example.json to config.json and edit it (see below).
  3. Run powershell -ExecutionPolicy Bypass -File Install-Task.ps1.

Install-Task.ps1 registers a scheduled task, Mod Build Watcher, that starts the watcher at logon with no window and starts it again every 5 minutes if it was stopped. A running watcher makes the extra starts exit at once. It replaces the Railroader Build Watcher task that older versions registered. It also puts a shortcut in your Startup folder that starts the status window in the tray at logon. After you change config.json or update the script, restart it (see Commands).

Status window

Watcher-Gui.ps1 shows what the watcher is doing, in a window and a tray icon. Make a desktop shortcut for it once:

powershell -ExecutionPolicy Bypass -File Watcher-Gui.ps1 -Shortcut

The window shows whether the watcher is running, the end of watcher.log, and for each mod:

  • Version: the version in its repo.
  • Status: what last happened to it: Importing, Fixing (Claude), Committed, Waiting for game (built, deploys when the game closes), Deployed, or a problem: Build failed, Rejected, Needs review, Repo not clean or No repo.
  • Last import and Last release: the newest version imported ((fixed) if Claude fixed it) and the newest GitHub release (off for mods not in Releases).
  • When and Details: the time and text of its latest log entry. Double-click a mod to open its repo. The buttons start, stop and restart the scheduled task, open config.json in Notepad and open the watcher's folder.

The tray icon is green while the watcher runs, red when it is stopped and orange when the task is not installed. Click it to open the window; right-click it for the same commands. Closing the window keeps the tray icon; Exit in its menu ends it. Starting the GUI again brings up the window that is already open. With -Tray it starts in the tray only, and with -Dir <folder> it shows the watcher in another folder. -Startup makes it start in the tray at logon (Install-Task.ps1 does this for you), and -NoStartup stops that.

The GUI only reads config.json, state.json and watcher.log, so opening or closing it does not affect the watcher.

config.json

Every setting is optional except Mods. Paths may use environment variables such as %USERPROFILE%. In JSON, backslashes must be doubled: "C:\\Games\\Railroader".

Key Default Meaning
Mods none Names of the mods to watch. Each one is a folder in ProjectsDir, a <Mod>.csproj and a zip prefix.
ProjectsDir Desktop\Projects Folder that holds the mod repos.
WatchDirs Desktop\Projects, Downloads Folders searched for zips.
Game Railroader The game the mods are for. See Another game.
GameDir Game.Dir The game install that the mod is compiled against.
ModsDir Game.ModsDir Where the built mod is deployed, into <ModsDir>\<Mod>. See below.
ClaudeModel sonnet Model for the automatic compile fix.
Releases none Mods that get a published GitHub release after each import. See GitHub releases.
Resets none "<Mod>=<version>" entries. The next zip with exactly that version is imported even though it is lower than the repo's version (for example "MyMod=1.0.0" for a 1.0.0 release after 2.9.x). Zips of the old line of versions are then recycled, and the release notes start from the new version's changelog section. Remove the entry after the import.
Renames none "<OldName>=<NewName>" entries for a renamed mod. List the mod under its new name in Mods and Releases. When the first <NewName>-<ver>-source.zip arrives and there is no <NewName> repo yet, the <OldName> repo folder is renamed (once it is clean and on main, and nothing has it open), its .csproj is renamed in a commit, and the import continues from there. After the new mod is deployed, <ModsDir><OldName> is removed so the game does not load both. Remove the entry after the import. The GitHub repository is not renamed; do that on GitHub (the old URL redirects).

The same names, except Game, work as command-line parameters of Watch-Builds.ps1 and override config.json. GameDir and ModsDir also override Game.Dir and Game.ModsDir.

Where mods are deployed. Railroader loads installed mods from <home>\Mods, where home is Documents\Railroader, or the folder given with -homedir in the game's Steam launch options (Installing Mods, Command Line Arguments). By default the watcher works this out the same way: it reads -homedir from Steam's launch options for Railroader if there is one, and otherwise uses Documents\Railroader. To deploy into the game's development folder (<home>\ModDev) instead, or anywhere else, set ModsDir, for example "ModsDir": "%USERPROFILE%\\Documents\\Railroader\\ModDev".

GitHub releases

For a mod listed in Releases, each version that builds (cleanly or after an automatic fix) and is pushed also gets a published GitHub release, created with gh once the push is done:

  • tag v<ver> on the commit just pushed, titled with the name from the version file (or the mod's folder name);
  • <Mod>-<ver>.zip attached: the mod built into an empty folder the same way it is deployed, so everything sits in <Mod>/;
  • the ## <ver> section of CHANGELOG.md as the notes. If the import includes skipped versions, their sections are listed too, each under its own heading.

This lets a workflow in the mod's repo, triggered by release: published, take over from there, for example to upload the zip to Nexus Mods. A publish starts that workflow, so every imported version goes out. If the release can't be created (no gh, or the tag already exists), the import stands and a notification says so. Workflow files under .github/ are never taken from zips. Commit them by hand. Imports leave them alone, since only top-level files are ever removed.

For the Nexus upload, save your Nexus Mods API key once:

.\Watch-Builds.ps1 -SetNexusKey

It asks for the key and stores it in nexus-key.dat, encrypted so that only your Windows account on this machine can read it. Before each release, the watcher writes it to the mod repo's NEXUSMODS_API_KEY Actions secret, so every mod in Releases gets it, including ones added later. To change the key, run the command again; each mod picks up the new key on its next release. Entering an empty key removes it, and the watcher then leaves the secrets alone.

Another game

Game describes the game. Without it, or with "Name": "Railroader", the Railroader settings apply, and any key you set overrides one of them. With any other name, every key starts from the generic default, and Dir and ModsDir must be set. For example, for a game whose mods have a Thunderstore-style manifest.json:

{
    "Mods": [ "MyMod" ],
    "Game": {
        "Name": "Some Game",
        "Dir": "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Some Game",
        "Process": "SomeGame",
        "RequiredFiles": [ "SomeGame_Data\\Managed\\Assembly-CSharp.dll" ],
        "ModsDir": "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Some Game\\BepInEx\\plugins",
        "VersionFile": "manifest.json",
        "VersionField": "version_number"
    }
}
Key Railroader Generic default Meaning
Name Railroader Shown in notifications.
Dir Steam's default Railroader folder none The game install.
DirProperty RailroaderDir GameDir MSBuild property the game folder is passed in.
Process Railroader none Process name. While it runs, deploys wait (the game locks the DLL). None: never wait.
RequiredFiles Railroader.dll, Railroader.Modding.dll in Railroader_Data\Managed none Files, relative to Dir, without which nothing compiles. While one is missing, builds wait.
ModsDir <Railroader home>\Mods none Where mods are deployed.
VersionFile Info.json Info.json JSON file in the mod's folder that holds its version.
VersionField Version Version Field in that file with the version (x.y.z). Not case-sensitive.

What it does with a new zip

Every 5 seconds it looks, for each mod, for <Mod>-<x.y.z>-source.zip in the watched folders with a version newer than the one committed in the mod's repo. It then:

  1. Waits until the download has finished, then checks the zip.
    • The files may sit either inside a <Mod>/ folder or at the top level of the zip, but not both, and no deeper.
    • Only .cs, .md, the version file (Info.json), <Mod>.csproj and .gitignore are allowed, up to 5 MB in total.
    • The version file and <Mod>.csproj must be present, and the version file must match the version in the zip's name.
  2. Refuses to build if the .csproj changed beyond the version number, and tells you to review it. The csproj decides what the build runs, so it is never taken from a zip unseen.
  3. Imports the zip as a commit (Import v<ver> source) and builds it. Files the zip leaves out are deleted from the repo, except .gitignore and CLAUDE.md. If CHANGELOG.md has ## x.y.z headings for skipped versions, the commit message lists them.
  4. If it builds cleanly: pushes to GitHub, publishes a GitHub release if the mod is listed in Releases, and deploys to the game.
  5. If it fails to build: starts Claude Code headless. That session may only read files, edit .cs files and run dotnet build. Afterwards the script checks that only existing .cs files changed, and builds again itself.
    • Fixed: the fix is pushed as its own commit (Fix compile errors in v<ver> (automatic)), then it deploys.
    • Not fixed (or Claude Code not installed): main stays on the previous version, the import goes to the incoming/v<ver> branch, and a GitHub issue lists the errors and Claude's explanation.

It waits instead of acting when:

  • the game is running (Game.Process; this only delays the deploy, since the game locks the DLL);
  • the repo has uncommitted changes or is not on main;
  • one of the game's Game.RequiredFiles is missing, for Railroader Railroader.dll or Railroader.Modding.dll (for example during a Steam update).

Every step shows a Windows notification.

Old zips: after each successful import, and once per mod when the watcher starts, source zips older than the repo's version are moved to the Recycle Bin, but only if some commit on main has that version in its version file. The current version's zip, any zip that was rejected or failed to build, and zips of versions that were never committed (from before the repo existed, or folded into a later import) are kept.

Files

  • Watch-Builds.ps1: the watcher.
  • Install-Task.ps1: registers the scheduled task and starts the status window at logon. Install-Task.ps1 -Remove removes both.
  • Watcher-Gui.ps1: the status window and tray icon.
  • config.example.json: a starting point for config.json.
  • Created when it runs, and ignored by git:
    • config.json: your settings.
    • watcher.log: what it did, including build errors and Claude's reports.
    • state.json: zips already handled (by hash), so a failed zip is not retried (delete its entry to retry it), notifications already shown, and mods waiting to be deployed.
    • work\: zips being checked.
    • nexus-key.dat: the Nexus Mods API key from -SetNexusKey, encrypted for your Windows account.
    • BuildWatcher.ico: the desktop shortcut's icon, from Watcher-Gui.ps1 -Shortcut.

Commands

The status window has buttons for starting, stopping and restarting. From PowerShell:

  • Stop it: Stop-ScheduledTask 'Mod Build Watcher', then end the powershell.exe running Watch-Builds.ps1 in Task Manager if it is still there.
  • Start it: Start-ScheduledTask 'Mod Build Watcher'
  • Try a change for a few polls next to the running watcher, without deploying, opening issues or releasing: powershell -File Watch-Builds.ps1 -StateDir <empty folder> -Ticks 3 -NoDeploy -NoIssue -NoRelease. It still imports, commits and pushes any new zip it finds, so point -ProjectsDir and -WatchDirs at test copies if that matters.

License

MIT. See LICENSE.

About

Windows background watcher that imports, builds, pushes and deploys Railroader mod source zips

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages