Skip to content

Front-end scenes of a custom level

A campaign mission is four scenes: the pre-mission briefing, the level, the debriefing and the newspaper. A custom level built from a recipe (recipe-format.md) gets all four with its own content. This page explains how the game finds them, how the builder makes them, and what is still the base mission's.

How the game names a mission's scenes

ZLevelLinking (src/hitman3/levelcontrol/levellinking.cpp) keeps a table of 13 rows, one per campaign slot, s_asLevelname[13][8]. Column 0 is the level's name (M01), the others mark what scenes the slot has. GetNextSceneName walks nextSceneNameType through INTERVIEW → BRIEFING → LOAD → NAME → MISSION_DEBRIEFING → NEWSPAPERSTATS and builds:

Step Scene M01
INTERVIEW column 2 itself M01/M01_Premission (briefing, target pages, loadout)
NAME %s/%s_MAIN from column 0 M01/M01_MAIN
MISSION_DEBRIEFING %s/%s_postmission from the last completed level's column 0 M01/M01_postmission
NEWSPAPERSTATS %s/%s_News likewise M01/M01_News

ZHM3LevelControl::MissionCompleted2 calls CompleteCurrentLevel (which sets the step to NAME, so the next one is the debriefing) and loads GetNextSceneName(). Everything the menus print about the mission is keyed by the same name: /<name>/MissionObjectives/…, <name>/MissionBriefing/<name>_MB_01D (ZHM3BriefingControl, briefingmenu.cpp), AllLevels/Interface/LevelNames/<name>, <name>/Map/…, and money.xml's <Level name="<name>"> rewards. The newspaper uses the slot's number instead (NewsPaper/Articles_M{CurrentLevel}, NewsPaper/Statistics/MissionData/<field>/{CurrentLevel}).

The level table change: a row of the level's own

The disc overlay (cdreadsdl.cpp) serves a mod's raw/ file only where the disc has no file, so a mod cannot replace M01_POST.ZIP, and that stays so. Instead a custom level gets names the disc does not have. mod.json's level entry gives a scene_code (GC1) and a mission_slot (M01). When the launcher starts that level (port/hitman3/hitman3/_sdl/launchersdl.cpp, SetCustomLevelRow):

  • the slot's row keeps its number (loadout, statistics, the profile), but column 0 becomes the code and column 2 <code>/<code>_Premission. The old pointers are kept and put back when another mission starts;
  • the quick start opens the briefing scene (column 2) instead of the main scene, and LauncherApplyQuickStart sets nextSceneNameType to BRIEFING, so the briefing's start button asks GetNextSceneName for <code>/<code>_MAIN;
  • from there the game runs as for a campaign mission: GC1/GC1_postmission, GC1/GC1_News, then saveandcontinue. "Restart" on the debriefing (LoadNextScene("PreviousScene")) builds GC1/GC1_main from the same row.

The port turns each name into a disc path with 8.3 parts (DiscFileName): SCENES\GC1\GC1_MAIN.ZIP, GC1_PREM.ZIP, GC1_POST.ZIP, GC1_NEWS.ZIP, which is why a code has at most 5 characters. ModManagerLevelGet's SModLevelDef gained szSceneCode, and mission_slot sets lMissionIndex (without it, the slot comes from base_scene as before). A level without a scene_code behaves exactly as before. No src/ file changed: the table's pointers are not const, and the port changes them at run time.

Side effects, all harmless for a custom level: ZHM3LevelControlM01::Init calls SetCurrentLevel("M01"), which now finds no such row and returns -1 without changing anything; code that compares the level name with M00, M04, M06, M12 or M13 sees the code; hm3cameraconsole.cpp's per-level camera angles have no entry for it.

What the builder does with each scene

tools/port/scene/build_level.py builds the main scene with RecipeBuilder (gltf_level's builder) and the three front-end scenes with frontend.SceneFile: the base mission's archive from the player's disc, edited in place. No geom is added or removed in a front-end scene, so their run-time references, collision trees, light lists and room trees stay the disc's (the main-scene builder clears light lists, which a lit menu scene would miss).

Text (every scene). frontend.level_text copies the base level's LOC folder (M01/) to <code>/ (its voice-line subtitles and actor sounds keep working), drops the copy's interview, briefing and map names, and sets AllLevels/Interface/LevelNames/<code>. Then mission.apply_text writes the objectives, target pages, briefing paragraphs and hints under <code>/ (main scene and briefing). money.xml gets a <Level name="<code>"> copy of the base level's rewards.

Target photos (main scene and briefing). The target pages ask the menu's resource manager for a graphic <n>Picture (ZHM3BriefingDetail::Setup). It is a ZWINGROUP holding a ZWINPIC, whose PicResourcePrim is a PRM block: a sprite count, the sprites (SSpriteArrayElementUV: centre, u and v ranges, size), a count of sprite arrays, one sprite-array prim per array (SPrimSpritesArray, its lTextureId at byte 4) and the array records. M01's 79 × 85 photos are three strips (256 × 64, 256 × 16, 256 × 8 textures, 16 colours). frontend.paint_picture maps every texel a sprite shows to its point on the picture and takes our image's colour there, keeping the texel's alpha, then re-encodes the texture in place (tex.replace_texels: same size, format and blocks). render_picture is the inverse, used to check the result.

A third target needs a 3Picture that M01 does not have. Adding a geom would shift the run-time references of the briefing scene (and its light lists, which the builder does not remap), so frontend.add_picture_slot renames an unused graphic of the same shape instead: the sixth objective's BriefingNotCompletedArrow#05 (a level with up to five objectives leaves it unused) becomes 3Picture, with a copy of 1Picture's objects, a new PicResourcePrim and three new textures. Renaming adds the string to the BUF and updates its name offset in the GMS.

The M01 preset gives the third and fourth targets spare graphics. The fourth uses BriefingCompletedArrow#05. A fifth target has no picture slot.

Pause map (main scene). M01's map rooms (M01/M01_MAP.zip) are removed. The builder adds one map room, <code>__MAP_Level: a ZROOM with a quad over the level's footprint textured with map.png (north up), and one MapGroup controller per world room (m_szName <code>/Map/Level, m_rWorldGroup the room), copied from M01's. A map room has an OCT block like any room but no room-tree box (build_scene.py skips rooms marked map), so 47 is never "in" it. CMapGroup::Init2 registers it with the in-game map and hides it.

Newspaper. The page behind the text (ZoomGroup\BackgroundPictures, 80 tiles of 128 × 256 for 1280 × 1850), the headline photo (TargetPic), the side story's picture (StoryPic_M01) and the fillers' pictures are painted from the recipe's images. The headline story is the game's own template (NewsPaper/Texts/NewsPaperTextStats_Murder), fed from NewsPaper/Statistics/MissionData/<field>/<slot number> (city, date, location, target names and titles, police, the paragraphs about target 1 Target1Background/<n>A…F) and NumberOfTargets. The photos' captions are read by keys fixed in the scene (Target1PictureText/1, Articles_M1/Story/Story_PicText, the pictures' Picturetext m_szStringId), so captions are written under the base level's number as well. The side articles (Articles_M<slot>/Story, FillerLongA, FillerLongB, FillerShortA) are replaced line for line; their layout code prints a fixed number of lines.

Debriefing. Its LOC gets the level title and the newspaper data (the debriefing's rating texts come from the same tree). The statistics are the mission's own. Its backdrop is M01's wine cellar, a lit 3D room; the builder repaints the cellar's materials with the recipe's (debriefing.backdrop: wall, stone, floor, wood, barrel and plaster images; the base preset names which disc textures each role covers, by part of their names). The shapes stay the cellar's: vaults, barrels and a desk, now in the level's brick, concrete, marble, planks and crates.

What is still the base mission's

  • The debriefing backdrop's shapes: the vaulted wine cellar of M01_postmission (its materials are the level's). Replacing the geometry means building that scene with ours (gltf_level on the postmission base, the camera moved into our level) and remapping its light lists; not done.
  • The loading screen (M01/Loader_Sequence) does not show for a quick start.
  • The music. ZHM3LevelControlM01 drives the music controller with M01's cues (MusicInit, CompleteObjective), and the tracks stream from PS2_Eng.str, which no scene archive holds and the overlay cannot add to. Our own music would need either a new stream file and the port's streaming code taught to read it, or a mission that plays its music as sound-bank effects (as the hum and alarm do), which loops but does not follow the music controller's states.
  • The briefing's 3D and voice: the briefing has no voice for our paragraphs (the LOC entries carry no sound), and its weapon-selection models are the game's.

Failures and fixes

# Symptom Cause Fix
F1 The newspaper printed M00's story (Joseph Clarence in Baltimore) and its side articles. ZStatisticsTest::GenerateText sets {CurrentLevel} to atoi of the level name after its first letter: GC1 gives atoi("C1") = 0. frontend.news_number(code) computes the same number; news_text copies the base level's mission data and article layouts (Articles_M1, whose pictures the scene holds) to that number before writing ours.
F2 A band of the disc's photo showed through our headline photo, at the seam of its two rows of tiles. The second row of tiles uses only v 0 to 0.84 of its textures, and the painter measured v from the bottom. v counts from the texture's top row (_texel_region); render_picture of the disc's photo is seamless with it.
F3 Avoided: repainting a texture shared by two records. M01's two photos share their bottom strip, which is fully transparent. tex.replace_texels refuses shared blocks; paint_picture skips textures with nothing visible.
F4 Avoided: the quick start into the briefing would have led back to the briefing. SetCurrentLevel resets the step to LLNONE, and the next step is INTERVIEW, the briefing itself. LauncherApplyQuickStart sets the step to BRIEFING for a level with a scene code.
F5 A scripted playthrough (no walking) could not use the exit. The showcase's start is in the hall; the exit is in the storeroom, through a doorway. The recipe starts 47 by the loading door (start_from view_LoadingDoor, an empty the generator adds): he comes in where he leaves.