Docs

These docs follow the dev branch and can describe changes newer than v0.9.4. The release notes list what the download contains.

Game flow#

Most of what the game does between screens is not in code: it is in about fifty XML state graphs in media/gamemodes.zip. Starting the game, free roam, every kind of race, the pause menu, the map, photo shoots and the multiplayer lobby are each a StateGroup of State elements. A state runs behaviours, can call into a state of another group, and leaves through named exits to the next state.

The executable supplies the pieces. Every behaviour id in the scripts is the name of a C++ class in the States namespace, which the executable registers by name. So the scripts can recombine existing behaviours freely, but anything new needs code.

FLOW FILE (STATEGROUP)State ABehaviour id=CSetTimeOfDayNode state=global.xState BBehaviour id=CPrepareCutsceneExit target=CExitState CEntry, Transition,Attribute elementsGROUP GLOBALState xshared by 40 callersEXECUTABLEStates::CSetTimeOfDaycreated by name throughCConstructor0 / 2runs a state of another groupcreates the C++ behaviour
How a flow file reaches the code. A state's behaviours are created by class name; a Node runs a state of another group (most often the shared global group) and comes back through its exits.

The shape of a flow file, with invented ids (the element and attribute names are the game's):

<StateGroup id="example_event">
  <State id="intro">
    <Behaviour id="CSetTimeOfDay">            <!-- a States:: class, created by name -->
      <Attribute id="..." value="..."/>       <!-- parameters the class reads -->
    </Behaviour>
    <Node id="take_control" state="global.some_state">
      <Exit id="success" target="race"/>     <!-- where to go when the called state exits -->
      <Exit id="failure" target="leave"/>
    </Node>
  </State>
  <State id="race"> ... </State>
  <State id="leave"> ... </State>
</StateGroup>

Behaviours may also hold Transition elements, and a state may hold Entry and StateSubstitute elements; their exact semantics are not traced yet. gamemodes.zip also holds documents that are not state graphs: the activity list, cutscene cameras, leaderboards and radio DJ requests (see the records below).

Graphing a flow is the quickest way to read one. This prints a Graphviz graph of an extracted flow file, with calls into other groups dashed:

import sys
import xml.etree.ElementTree as ET


def flow_to_dot(path):
    """A Graphviz graph of one extracted StateGroup file."""
    group = ET.parse(path).getroot()
    lines = [f'digraph "{group.get("id")}" {{', "  node [shape=box, fontname=monospace];"]
    for state in group.findall("State"):
        sid = state.get("id")
        behaviours = [b.get("id") for b in state.findall("Behaviour")]
        label = "\\n".join([sid, *behaviours])
        lines.append(f'  "{sid}" [label="{label}"];')
        for node in state.findall("Node"):  # runs a state of another group
            lines.append(f'  "{sid}" -> "{node.get("state")}" [style=dashed];')
        for leave in state.iter("Exit"):
            if leave.get("target"):
                lines.append(f'  "{sid}" -> "{leave.get("target")}" [label="{leave.get("id")}"];')
    return "\n".join(lines + ["}"])


print(flow_to_dot(sys.argv[1]))
python flow_to_dot.py extracted/gamemodes/<file>.xml | dot -Tsvg -o flow.svg

Extract the archive first (Methods and tools); the files are plain XML once out.

Flow scripts#

AddressFindingConfidence
media/gamemodes.zipflow scripts are XML state graphs The game's top-level flow (start, free roam, every race type, pause, map, photo shoots, multiplayer and the rest) is data: 50 StateGroup XML files in media/gamemodes.zip, 44 distinct group ids. A group holds State elements; a state holds Behaviour, Node, Entry, Exit and StateSubstitute elements, a behaviour holds its Attribute (id, value) and Transition elements, and a node holds its own Entry and Exit elements. Exit and Entry name a target, and a Node with state="group.state" runs a state of another group (147 cross-group references; global, Audio, UIShowScreens and InGameUI are the most used). The free-roam flow has 908 elements; the race states file 461.

Established by Extracted gamemodes.zip with pinyon_shift_fh1_archive_extract; counted element and attribute names and the state references.

Confirmed
—behaviours are States:: classes Every Behaviour id in the flow scripts names a C++ class in the States namespace: all 439 distinct ids match an RTTI name (for example CSetRadioPlaylist, CPrepareCutscene, CSetTimeOfDay). The executable registers them through CConstructor0/CConstructor2 templates, so a flow creates behaviours by class name. 50 States classes are never named by a base-game flow. New flow logic can therefore be written in XML only from existing behaviours; a new behaviour needs code.

Established by Matched the extracted flow files against the RTTI census.

Confirmed
media/gamemodes.zipother gamemodes.zip documents Besides the 50 flow files, gamemodes.zip holds 134 CutsceneManager documents (camera cuts per track, hub and festival), 99 ActivityManager documents (speed traps, zones, stunts, barn finds, shops, per track), five LeaderboardManager and two LeaderboardEntries documents and one ActivityCoordinator. Folders per world (Colorado, TestBed and the UI scenes UIAutoshow, UIPaintshop, UIWorkshop, UIThumbnail, UIThumBig, UIAuctionHouse) hold that world's copies. 254 of 292 members are XMem compressed, 38 stored.

Established by Root element census of the extracted archive.

Confirmed
Colorado/activities.xmlgeneric activities and career activation Generic activity portals belong in Colorado/activities.xml and can load an event directly. An unknown event, or a generic portal placed in the career activation file, does not start the event. A generic portal suppresses a nearby existing trigger (the Gauntlet's).

Established by Experiment with copied base game-flow data.
Detail docs/DLC_BACKLOG.md Base-disc solo stage probe

Confirmed Negative
media/gamemodes.zip; behaviour registered in sub_829944C0loading waits in the flow graphs Loads are gated by state, not by timers. global.wait_for_streaming (CWaitForStreaming) appears four times in the free-roam flow, twice in festival races and once in fast travel; free roam and the festival also wait in LoadAndWaitForLOD0Cars, and enable_streaming/disable_streaming bracket loads. The only fixed waits are wait_half_sec after the nemesis sequence, one wait_2_sec, one wait_3_sec and three wait_one_frame. CCompressDatabase states (decompress_database_wait, compress_database_*) are defined but used by no flow file read so far.

Established by Element and attribute census of the extracted flow XML.
Detail docs/CONSOLE_ERA_RESEARCH.md CE-13

ConfirmedThe time spent inside CWaitForStreaming is not measured (CE-0.1, CE-13); its update method is not traced.

Script actions#

Scripts also call actions: small functors registered under a name, separate from the state behaviours. Each one's factory has a create method in its vtable, which leads from the name to the code.

AddressFindingConfidence
sub_825AD820script actions are registered by name Script actions are functors registered by name through factories whose create method builds the action, so following a factory's vtable leads from a name to its code. Found this way: the camera and wristband actions below, CWristbandManager, CStartRewindReplayFunctor, CFinishRewindFunctor, CGivePlayerMoney (sub_825AD820), CStoreRestorePlayerCarPosition, CWaitForEndCondition and CDisableAIPlayerCarControls.

Established by Registration calls and factory vtables in the generated code.
Detail docs/NATIVE_PORT_BACKLOG.md NP-8.4; src/pinyon_shift_runtime_hooks.cpp PinyonShiftApplyCredits

Confirmed
sub_8291DD80
sub_8291DF68
0x832E6364v4sub_829D0D90
sub_829D0F78
0x833D3F34
career event and free-roam loaders CLoadIntoCareerRace loads a career event, also from a results branch, and keeps the player-car restoration and loading preparation; CPlaceCar places the car. The career event loader sub_8291DD80 holds the event name as an inline std::string at +128 (length +144, capacity +148), read synchronously; native event menus leave it empty and select through the application's +896. sub_8291DF68 is the free-roam loader, which returns to Colorado. The global 0x832E6364 points to the LoadGame loader, whose first word is its state; it accepts a load request only in its idle state, 22.

Established by Patched game-flow graphs on the base build; replacing each loader through the dispatcher (the base-disc Rally adapter chained stages with CLoadIntoCareerRace("RALLY_NEXT")); traces of the selected event while launching Rally events; the loader state read as a gate before entering activities from a host menu.
Detail src/pinyon_shift_runtime_hooks.cpp RallySeriesLoader; docs/DLC_BACKLOG.md Base-disc Rally investigation; docs/TITLE_UPDATE_V4_BACKLOG.md Review of the base-disc Rally adapter; src/pinyon_shift_runtime_hooks.cpp Rally comments, QueueRallyRaceTrace

ConfirmedThe LoadGame idle state is probable.
sub_825558A0
sub_82554598v4sub_825D4500
sub_825D3548
ordinary free-roam parameter construction The ordinary free-roam loader calls a parameter constructor (base sub_825558A0, v4 sub_825D4500) that selects track 317. Its setup call receives the parameter object in r3, track ID in r4 and 1 in r5 (base sub_82554598, v4 sub_825D3548). This is separate from v4's Rally menu-hub loader.

Established by Read-only generated-code call-site and argument inspection, starting at the already identified free-roam loader in both builds.
Detail docs/RALLY_FREEROAM.md Owned data contract

ConfirmedThe meaning of r5 and safety of reinitializing live parameters are not established; no runtime wrapper is implemented.
sub_82983A90v4sub_82A37858CStoreRestorePlayerCarPosition Stores the player's free-roam return position, when the byte at +32 of its object is set, and restores it after an event. Called again between consecutive races, it overwrites the stored point with the last race's finish, so base post-race cleanup can leave the player at a race finish.

Established by Function replacement in the base-disc Rally adapter; native traces of the return position and the restore flag.
Detail src/pinyon_shift_runtime_hooks.cpp RallyStoreRestorePosition; docs/DLC_BACKLOG.md Base-disc stage transition probe; Private four-stage director and resume

Confirmed
sub_828F2DB0
sub_828F7180
sub_82486C40
sub_82486C70
sub_82858638v4sub_824B68E0
sub_824B6910
sub_82908AC0
CChangeToFreeCamera The script action CChangeToFreeCamera (sub_828F2DB0, its factory registered by sub_828F7180) sets each of the world's camera controllers (count sub_82486C40, controller sub_82486C70) to mode 6, the free camera, with sub_82858638. The free camera then flies with the left stick.

Established by Followed the registered functor's vtable; calling the same functions from a host guest task showed the free camera above the car (fh1-free-camera).
Detail docs/NATIVE_PORT_BACKLOG.md NP-8.4, NP-8.5; src/pinyon_shift_runtime_hooks.cpp PinyonShiftApplyFreeCamera

Confirmed
sub_82937158
sub_82486B40
sub_825A86F8v4sub_824B6758
sub_826207B0
CResetCameraToPlayer The script action CResetCameraToPlayer (sub_82937158) returns each player camera (sub_82486B40(world, index)) to the player with sub_825A86F8.

Established by Functor vtable; used to switch the free camera back, after which the chase camera returns.
Detail docs/NATIVE_PORT_BACKLOG.md NP-8.4; src/pinyon_shift_runtime_hooks.cpp PinyonShiftApplyFreeCamera

Confirmed
sub_82987978
sub_82989D10
0x8208C858
sub_824CD660
sub_82407B20
CTriggerWristbandUpgrade The wristband ceremony is the script action CTriggerWristbandUpgrade (registered by sub_82987978, factory vtable 0x8208C858, execute sub_82989D10, this unused). It accepts game modes 17, 18 and 3, passes the player's current wristband to sub_824CD660 to upgrade it, then assigns the WristbandGet.wmv video path to the UI flow's movie string through the string assign sub_82407B20. Calling the execute from a host task in free roam changes nothing visible.

Established by Followed the factory's create method to the action; host-task call experiment.
Detail docs/NATIVE_PORT_BACKLOG.md NP-2.9, NP-8.4

Confirmed

Rally behaviours (v4)#

Title update 4 adds the Rally expansion's flow: new state groups in its media.zip and 335 new States classes (Title update v4).

AddressFindingConfidence
—v4CLoadIntoRallyFreeRoam
CShowUIScreen_RallyHub
Rally entry and hub behaviours v4 adds Rally entry and hub behaviours: CLoadIntoRallyFreeRoam, CShowUIScreen_RallyHub, CShowRallyOutpostScreen, CShowMultiStageEventSelectionScreen, CRemovePlayerCarWhilePaused, CShowBackgroundMovie, CHasSeenInitialRallyTicket and CSetRestrictionsForFirstRallyAutoshow. It also adds Rally attributes to base behaviours: onRally on the pause screen and Race Central, rallyFreeRoam, and applyRallyFilterByDefault on car registration.

Established by String comparison of the base and v4 images; v4 Rally flow files.
Detail docs/TITLE_UPDATE_V4_BACKLOG.md What v4 adds

Confirmed
—v4CLoadIntoRallyRace
CRallyStageIntro
Rally race, scoring and progression behaviours Race and scoring: CLoadIntoRallyRace, CRallyStageIntro, CRallyAIState, CRallyDriverState, CShowNextMultiStageLoadingScreen, CShowRallyStageScoreboard, CShowRallyRollupScoreboard, CHudStatusSplitTime and COMPONENT_CO_DRIVER. Progression: CInitialiseEventUnlocksRally, CTriggerRallyEventUnlocks, CCollectRallyUnlocks, CIsRallyXPEvent, CShowPostRaceRallyPointsScreen, CHasCompletedRallyInitialFlow, end-sequence and post-championship map behaviours, and ACHIEVEMENT_RALLYCHAMPION.

Established by String comparison of the base and v4 images; v4 Rally flow files.
Detail docs/TITLE_UPDATE_V4_BACKLOG.md What v4 adds

Confirmed
—v4Rally free roamRally free roam is a menu hub In v4, Rally free roam is a menu hub, not a drivable area: world presentation is off, the player car is removed and a background movie plays. The seven Rally activation coordinates look like map pins for the unlock flow, not places to drive to, so a physical Rally entry point is the wrong thing to look for.

Established by Reading v4's Rally flow behaviours; native Rally entry runs from the pause menu.
Detail docs/TITLE_UPDATE_V4_BACKLOG.md Review of the base-disc Rally adapter

Probable NegativeThe map-pin reading of the coordinates is a guess.