feat(sagepatch): casual QoL patch for macOS + Linux (Phase 1)#110
feat(sagepatch): casual QoL patch for macOS + Linux (Phase 1)#110ebellumat wants to merge 9 commits intofbraz3:mainfrom
Conversation
Introduces an optional patch (Patches/SagePatch/) that adds quality-of-life
features for casual play without modifying the game source. Gated by the
new RTS_BUILD_OPTION_SAGE_PATCH cmake flag (default OFF, ON in macos-vulkan
preset).
Architecture: a separate dylib loaded via DYLD_INSERT_LIBRARIES that
replaces SDL_PollEvent at the dyld level (__DATA,__interpose) to capture
hot-keys, plus an engine-side INI override picked up automatically from
Data/INI/Default/GameData/SagePatch.ini. No D3D8 proxy, no Vulkan layer,
no engine source changes.
Features in this initial drop:
F11 PNG screenshot via /usr/sbin/screencapture (window-only)
Scroll Lock cursor lock toggle (SDL_SetWindowMouseGrab)
Ctrl+PgUp/Dn display gamma adjustment, range -128..+128
Override.ini MaxCameraHeight=800, MinCameraHeight=60, ScrollSpeed=1.0,
EnforceMaxCameraHeight=No
Anti-cheat features (MDS, Game File Validator, ergc, version validation)
and competitive/networking features (Money Display, Player Table, Random
Balance, replay tools, CNC Online, ticker, Upload Mode, Auto Updater) are
intentionally excluded — focus is casual QoL only.
Smoke test: dylib loads cleanly via DYLD_INSERT_LIBRARIES, engine reads
the INI override, GameMain returns code 0.
…s + FPS
GeneralsX is a multi-platform project; the Phase-1 SagePatch was macOS-only,
which broke the rule. Restructured src/ tree and added Linux backend.
Source tree:
src/common/ SDL3-only code that works everywhere — Init, KeyHandler,
CursorLock, WindowPosition.
src/macos/ __DATA,__interpose hook, screencapture, CoreGraphics gamma.
src/linux/ LD_PRELOAD + dlsym(RTLD_NEXT), ImageMagick `import` /
gnome-screenshot, XF86VidMode (lazy dlopen, X11 only —
no-op under Wayland).
src/windows/ stubs only (Phase 2 — would need a proxy DLL).
New features in this iteration:
* Window snap presets — Ctrl+1..5 (center / TL / TR / BL / BR), via
SDL_SetWindowPosition. Cross-platform.
* FPS counter — both macOS and Linux deploy scripts default DXVK_HUD=fps
when SagePatch is active, so casual users get a frame counter without
extra config. Override with DXVK_HUD=0 or any custom value.
* Camera pitch override added to resources/Override.ini.
Linux deploy script (scripts/build/linux/deploy-linux-zh.sh) now copies
libsage_patch.so + Override.ini, and the generated run.sh sets LD_PRELOAD
when the library is present. SAGE_PATCH_DISABLED=1 still skips the preload.
Phase 1 complete. Phase 2 items intentionally deferred:
- Engine bug fixes (scud / tunnel / building / multiplayer crash) require
edits inside Generals*/Code, defeating SagePatch's "no source change"
contract.
- Windows preload is structurally different — needs a d3d8.dll proxy.
- In-game overlay text (clock, match timer, in-game menu) needs a
graphics hook (D3D8 proxy or Vulkan layer).
… fixes Two important clarifications after a code-base inventory: 1. Engine already supports GenTool-style CLI flags natively. Document -nologo, -noShellAnim, -noshellmap, -quickstart, -xres/-yres, -forcefullviewport, -noaudio/-nomusic/-novideo so users do not assume they need SagePatch to get those. They have always been part of the engine's CommandLine.cpp; no patch required. 2. Engine bug fixes (scud / tunnel / building / multiplayer movement crash) are handled by the upstream TheSuperHackers/GeneralsGameCode project which is maintained by the same author who wrote GenTool (xezon). The codebase already carries 170+ @BugFix annotations including the Tunnel System fixes by xezon himself. SagePatch does not duplicate them — that would create merge conflicts on the next upstream sync. This explicitly scopes SagePatch to QoL features that live outside the engine source tree.
Local deploy already shipped SagePatch on the previous commit. This wires
the same artifacts (libsage_patch.{dylib,so} + Override.ini) into every
release bundle so users actually get the QoL features when they download
the official zip / tar / flatpak — not just when they build from source.
Touches:
- scripts/build/macos/bundle-macos-zh.sh
- scripts/build/macos/bundle-macos-generals.sh
- scripts/build/linux/bundle-linux-zh.sh
- scripts/build/linux/bundle-linux.sh
- flatpak/com.fbraz3.GeneralsXZH.yml
- flatpak/com.fbraz3.GeneralsX.yml
Each one now:
1. Copies libsage_patch.{dylib,so} into the bundle's lib path (guarded by
`-f` so the build still succeeds when SAGE_PATCH=OFF).
2. Ships resources/Override.ini into the bundle's data path
(Resources/Data/... on macOS, /app/share/... in flatpak,
Data/... in the standalone Linux tar).
3. Generated wrapper scripts now set DYLD_INSERT_LIBRARIES / LD_PRELOAD
when the lib is present, with a `:` guard so empty existing values do
not break dyld.
4. Wrapper seeds the INI override into `${CNC_GENERALS_*_PATH}/Data/INI/Default/GameData/SagePatch.ini`
on first launch (engine reads INIs from cwd, not from inside the bundle).
5. DXVK_HUD defaults to "fps" when SagePatch is active (was: "0").
Flatpak manifests also pick up `-DRTS_BUILD_OPTION_SAGE_PATCH=ON` and run
the `sage_patch` build target after `z_generals` / `g_generals`.
Verified on macOS by running bundle-macos-zh.sh end-to-end:
GeneralsXZH.app/Contents/Resources/lib/libsage_patch.dylib (55 KB, arm64)
GeneralsXZH.app/Contents/Resources/Data/INI/Default/GameData/SagePatch.ini
…awIndex The wrapper scripts shipped DXVK_HUD=fps when SagePatch was active. On macOS 26 (MoltenVK 1.4.1, current SDK), DXVK's HUD pipeline shader uses gl_DrawID, which lowers to SPIR-V DrawIndex. SPIRV-Cross to MSL has no equivalent for that decoration and aborts conversion: [mvk-error] SPIR-V to MSL conversion error: DrawIndex is not supported in MSL. err: Failed to create swap chain blit pipeline: VK_ERROR_INITIALIZATION_FAILED The blit pipeline failure means DXVK can never present a frame; the game hangs at the EA Games logo (last thing the engine drew before DXVK started needing the blit pipeline). Revert the default to DXVK_HUD=0 on the three macOS wrapper scripts. Users who want the FPS overlay can still opt in with DXVK_HUD=fps. Linux and Flatpak wrappers are unchanged: native Vulkan drivers handle DrawIndex correctly there.
The engine resolves Local FS lookups (Data/INI/Default/<subdir>/*.ini overrides, loose Data/ assets, etc.) relative to the binary's cwd, never the binary's location. Without an explicit cd, launching the wrapper via absolute path, Finder, gtimeout, or any other invocation that does not happen to start in the asset dir caused the engine to miss every loose INI on disk — including SagePatch.ini — while still loading the BIG-archived defaults via the archive file system. Symptom: the game runs but the override apparently does nothing. Wrapper now cds to the script's own directory (which deploy puts the binary, the dylibs, the override INI, and the .big assets into) and execs the binary relative to that. Matches the bundle-script wrappers which already did this.
|
Hey @ebellumat, thanks for your contribution! I see there are several commits in this PR. Please let me know when it's ready for review. Regarding the |
The engine ships a native FPS overlay at the top-left via W3DDisplay::drawFPSStats(), gated by #ifdef RTS_DEBUG plus the runtime -benchmark <seconds> CLI flag. The previous SagePatch revision defaulted DXVK_HUD=fps in the run wrapper as a release-build alternative, but that default was already reverted in 55f06b7 because MoltenVK on macOS 26 cannot compile DXVK's HUD pipeline shader (DrawIndex has no MSL equivalent) and the resulting blit-pipeline failure hangs the game at the EA logo. Removing the FPS row from the feature table and replacing it with a small 'About FPS counters' section that explains the native option and why our DXVK_HUD shortcut is parked.
|
You're right, didn't realize the native one existed. The DXVK_HUD trick I had in the wrapper is broken on macOS anyway (MoltenVK can't compile the HUD shader, hangs the game at the EA logo), so I just dropped the FPS claim from the docs in 535c8a1. Keeping it as draft for now, want to do another pass on macOS at 1440p with assets and get a Linux smoke test before flipping. Will ping when ready. |
The engine subsystem init for TheWritableGlobalData scans two parent dirs: path1 = Data/INI/Default/GameData (loaded first) path2 = Data/INI/GameData (loaded second) Each parsed GameData block overwrites prior values in TheWritableGlobalData (INI_LOAD_OVERWRITE semantics). The vanilla camera defaults (MaxCameraHeight = 310, MinCameraHeight = 120, CameraPitch = 37.5) live in the BIG-archived Data/INI/GameData.ini and are parsed in the SECOND pass, so an override placed under Data/INI/Default/GameData/ — which is parsed in the FIRST pass — is silently undone right after. Verified via temporary instrumentation in parseGameDataDefinition: pass 1: file=Data/INI/Default/GameData.ini max=300/min=100 (debug-only block) pass 2: file=Data/INI/GameData.ini line=464 max=310/min=120 (vanilla, was last-write) pass 3: file=Data/INI/GameData/SagePatch.ini max=800/min=60 (now winning) Deploy scripts on both platforms now write to Data/INI/GameData/SagePatch.ini (path2 subdir, parsed last) instead of Data/INI/Default/GameData/SagePatch.ini, and clean up any prior misplaced copy. SAGEPATCH.md gains a short section explaining the load order so future contributors do not repeat the mistake.
MaxCameraHeight=800 was too aggressive — on small maps it pushed the orthographic frustum past the playable border, exposing void/cull at the screen edges. Drop to 500 (~1.6x vanilla 310) so the extra range is useful without breaking small skirmish maps. Also raise MinCameraHeight back to 80 (slightly closer than vanilla 120 but not as tight as the previous 60), and remove the CameraPitch override entirely — letting the engine keep its vanilla ~37.5 pitch instead of forcing 50, which was an arbitrary choice and not a published GenTool default. Scroll factor stays at 1.0 (2x vanilla). Reaffirms that no published GenTool tuning numbers are public; these are conservative casual-friendly bumps.
Cool! This kind of zoom remember me the older C&C games like RA2. |
|
note: I pushed a bugfix for full screen mode on |

Summary
Introduces SagePatch — an optional, drop-in patch for GeneralsX that adds quality-of-life features for casual play, gated by the new CMake flag
RTS_BUILD_OPTION_SAGE_PATCH(defaultOFF,ONin themacos-vulkanpreset).Inspired by the casual subset of the original GenTool, but independently implemented from the public GenTool changelog and SDL3/CoreGraphics/X11 documentation. No code reverse-engineered from the original closed-source
d3d8.dll(which is VMProtect-protected anyway). No anti-cheat, no networking, no replay tools, no engine bug fixes — see the doc for the explicit non-goals.The whole thing is outside the game source tree in
Patches/SagePatch/. The only files touched incoreare CMakeLists.txt, CMakePresets.json, andcmake/config-build.cmaketo wire the option.What's in
F11screencapture -l <id>import(ImageMagick) /gnome-screenshotScroll LockCtrl + PageUp/Ctrl + PageDownCtrl + 1..5DXVK_HUD=fpsdefault inrun.shArchitecture
No D3D8 proxy, no Vulkan layer, no engine source modifications. Phase 1 patch source is ~600 lines C++ across
common/,macos/,linux/,windows/(stubs).Layout
What's intentionally not in scope
TheSuperHackers/GeneralsGameCode, which is the parent of GeneralsX and is maintained by the same author who wrote GenTool. The codebase already carries 170+@bugfixannotations including Tunnel System fixes by xezon. Duplicating them here would create merge conflicts on the next upstream sync.DXVK_HUDprovides a basic FPS counter as a substitute.LD_PRELOAD/__interposeequivalent; needs a proxyd3d8.dlllike the original GenTool. Stubs are in place so the build still succeeds withRTS_BUILD_OPTION_SAGE_PATCH=ONon Windows, but the runtime is no-op until the proxy is implemented.Already in the engine, no patch needed
These GenTool-era options are first-class engine flags in
Common/CommandLine.cpp. Documented in the SAGEPATCH.md so users know they can call them directly viarun.sh:-nologo-noShellAnim-noshellmap-quickstart-xres N -yres N(resolution unlock — engine no longer locks the list)-forcefullviewport-noaudio,-nomusic,-novideoTest plan
macos-vulkanpreset,RTS_BUILD_OPTION_SAGE_PATCH=ON)libsage_patch.dylibproduced — 55 KB, arm64 native, dynamic SDL3 lookupOverride.iniinto the game runtime dirrun.shwrapper setsDYLD_INSERT_LIBRARIEScorrectly (no trailing:)Data/INI/Default/GameData/SagePatch.iniSAGE_PATCH_DISABLED=1 ./run.shskips the preload as expectedNotes on naming
SagePatchis a placeholder picked at scaffolding time (the SAGE engine being what Generals runs on). Trivial to rename via:Commits
d42ef875c— initial Phase 1 (macOS-only, mistake)3efaac65c— cross-platform refactor (macOS + Linux + Windows stubs), window snaps, FPS HUD default3a87fa2cd— docs scope clarifications