OCTR unified mod support — test implementation
Author: tcosi

PLAYER WORKFLOW
Place mods in the mods folder beside the OCTR launcher executable. Open Mods,
use Add files/Add folder or press Reload, then enable the desired entries. New mods are disabled initially.
Fully restart the game after changing the selection. Remove moves the source to
recoverable mod-state/removed storage; original game files and saves are retained.

Accepted layouts:
  mods/MyPatch.xml                   (standalone shadPS4 executable patches)
  mods/update3.pak
  mods/Character/archives/update3.pak
  mods/Character/update3.pak
  mods/Character.zip                 (one PAK, archives/, or a wrapper folder)
  mods/Custom-HUD.zip           (mod.json + assets + executable XML)

The same Mods page controls all these forms, with built-in mods listed first.
See docs/mod-packaging.html for the complete creator companion to venvs’s handbook.
Loose XML is mirrored into the existing patches compiler; identical legacy copies
are shown once and filename collisions are rejected. Remove the mods XML source
and Reload to remove its managed copy. Legacy patches/ remains supported.
A ZIP is recommended for sharing,
even for one PAK, because it preserves filenames and keeps a multi-PAK mod under
one toggle. Asset-only ZIPs do not require a manifest. Loose files keep their
creator-supplied archive filenames; do not rename update3.pak to a display name.
Folders let two creators both distribute update3.pak without overwriting either
download, but overlapping enabled archives still require a compatibility merge.

NATIVE CONTENT AND THE CREATOR HANDBOOK
PAK remains the native IGA archive, and IGZ remains the game resource format.
Use the existing creator tools and handbook for models, textures, tracks,
skeletons, package references and character/skin/track registration. This loader
does not replace those tools or change their file formats. New game content
must still include compatible registry/package/dependency edits; adding a file
does not by itself create a selectable character or track. The native game's
archive search and update precedence still apply. Test the effective loaded
resource, not merely successful import into the launcher.

Replacement PAKs are read directly from extracted mod storage through engine
file redirection. The selected original game path never changes. Matching relative
paths override the source only while enabled; missing paths fall back to the source.
Individual archive-entry operations use sparse BBPAK001 read overlays containing
only changed index records and mod payloads. No game tree or original archive is
copied, linked, repacked or modified. This requires the matching updated engine.
Newly added archives become visible through the ordinary game filesystem; the
loader does not invent engine mount requests or register their contents. A PAK
whose name/resources are never requested needs creator registration changes.
An archive-only import is therefore not a claim that arbitrary content works.

PACKAGES WITH LOGIC
Use mod.json (schemaVersion2), octr-mod.required and the included package_mod.py
creator command for packages needing assets plus XML. The marker and file list
are generated by the packager. There is no downloaded installer or Python hook.

  python scripts/package_mod.py CREATOR_FOLDER --output MOD.zip
  python scripts/package_mod.py CREATOR_FOLDER --validate

Metadata follows the existing declarative format implementation: stable ID,
name, version, author, description, checksummed files, required capabilities,
game-data compatibility, dependencies/conflicts, operations and patches.
Engine versions and engine SHA256 allowlists are not required or enforced.
Legacy runtime_versions/runtime_sha256 fields are accepted for old packages.
Only compatibility.online is required. Legacy eboot_sha256 lists are accepted
but are not a launch allowlist. Every declarative executable write must carry a
Signature and/or ExpectedSHA256; unsigned writes fail before launch. ExpectedSHA256
hashes the original file-backed bytes at the write site for the full write length.
Declare code-signatures in requiresCapabilities for packages using this feature,
so older launchers reject them explicitly. Fixed-address injected code is not
automatically relocated or ported to other game revisions. Original asset hashes
remain checked; compatibility means the affected code/resources actually match.
The launcher queries engine features automatically rather than requiring every
mod to list each supported launcher release.
Supported operations include complete native PAK files, individual existing PAK
entry replacements or byte deltas, game asset files, private shader operations,
and permitted private settings. XML uses OCTR's existing executable compiler.
See scripts/mod_format.py for the authoritative field validation. CNK Boost Gauge
is a concrete example containing29asset replacements and5executable writes.

COMPOSITION AND DISABLING
Independent assets in one archive can compose when declared as entry operations.
A complete PAK conflicts with other mods changing that same archive. Replacing
the same IGZ registry is blocked, not automatically merged. Track registrations
need a creator-authored merged resource/compatibility mod.
Racer registrations are merged (scripts/racer_registry.py): each racer mod ships an
update archive (update4.pak, update5.pak...) holding the game's whole racer list
(characterlisting.igz, looseData/systemData.igz, systemData_<language>.lng), and
the game keeps only the last one it loads. With two or more such archives enabled,
the launcher builds one registration from the game's own files plus every added
racer, each taken from the mod that ships its driver<name>.pak (else from the last
registration that has it), and serves it as the highest-numbered archive. A copy
of another mod's racer inside a later archive therefore never hides that mod's
newer version. Built-in edits of those game files (item rules, online racer list)
are not in the merged file, as with a single racer mod. A racer whose records
cannot be copied stops the launch with the mods named.
Code write overlaps and skipped signatures block modded launch. The actual
OCTR render/theme/online patches participate in strict executable validation.
Requested widescreen layouts must remain valid for the selected asset set.

The loader freezes selected mod contents, read overlays and file-map metadata,
snapshots settings and XML selection, and holds a process lock for the session.
User settings are not overwritten. Asset/package sessions use a separate save profile,
seeded from this installation's user profile. Successful normal exits commit to
that separate profile; original saves are not overwritten by package sessions.
Standalone XML and built-in patches retain ordinary saves; back those up before
progression/unlock patches. Disable all mods to
return to the original game/configuration. Caches remain inert for reuse.

Multiple versions of one stable mod ID produce one card. The newest validated
version wins (numeric major.minor.patch).
Older inputs stay in mods for rollback; Details lists them. The checkbox keeps
its stable ID. Identical duplicate content is listed once. Different content
claiming the same selected version is a visible conflict, not an arbitrary winner.
An invalid newer package does not hide a valid older one.
Conflicts between different enabled mods remain errors; filename order does not
silently select a winner. Removing a selected version disables the stable ID;
reload may then offer an older retained version, still disabled.

Legacy full-game profiles under mod-state/extensions/profiles are never reused.
New state lives in extensions/overlays and contains mod data/metadata, not a game
copy. Separate user saves/shader caches remain, and are not original game content.

CURRENT VERIFICATION SCOPE
Windows official OCTR v0.6 engine, current official source frontend. PAK/ZIP/
folder imports, composition, conflict rejection, sparse overlays, hash validation,
disabled path, locks/removal and malformed inputs have automated coverage.
A separately packaged Reserves + CNK HUD was prepared against the actual USA 1.21
game and official v0.6 engine, including its seven executable writes and the stock
32:9 layout. The user confirmed offline launch. Full online/gameplay validation,
arbitrary character/track mods and all DPI/resolution combinations are not claimed.
The HUD package and proprietary game resources are not included in this change.
No arbitrary character/track mod is certified merely because it imports.
No multiplayer asset syncing, hot reload or registry merger beyond racers is included.
This implementation is for OCTR; no separate Nitro Launcher product is required.
Linux run.sh integration and equivalent EU package authoring are not yet claimed.
