Skip to content

UI: the crusader trail's mission intro screen at 100% - #455

Open
kotijekriv wants to merge 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round42-100
Open

kotijekriv wants to merge 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round42-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

One function at 100%, written from the original's listing with gynt's draft beside it. No header changes. One behaviour fix against his best-scoring draft, one he also made on a later branch (below).

Function Address Before reccmp raw Normalised
MenuViews::CrusadeMissionIntro::MenuView_CrusadeMissionIntro_DoEveryFrame 0x004DD7B0 gynt's best 53.5% 100.0% 100.0%

gynt's best, 53.54%, is b4fa695 ("Style pass", 2026-10-25) on his fork's archive/UI-MenuViews-merged-full, from after he closed #253 (reimpl/UI-MenuViews), which has the function at 35.8% (2dd4786). Two days later he found the missing returns himself: 1958ae8 ("Early returns", 42.04%) on his reimpl/UI-MenuViews-development, which has the function at 45.0% (466d2ea). His 08c492b on reimpl/UI-MenuItems-development (38.6%) writes the id test as <= 0; the original compares with 1 (0x004DE193), so it stays id < 1 here.

Measured

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie. The struct resolvers and the function resolvers are enabled locally (not committed). In the full build 0x004314E0 (the MapEditorLandscaping_GeneralButtons handler) is left out and its resolver stays off, as in main's baseline.
  • Narrow build: this file as committed, alone. 100.0 raw and normalised, with no diff line. gynt's b4fa695 in the same build: 53.5 / 47.0.
  • Full build: an all-on build of the previous cut of this branch on main 02fab42 (the same code: the last cut only changes comments, writes one test inline and renames four locals, which compiles to the same listing): 0 failed of 2,424 compile steps, 99.58 over 2,440 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files under tools/, cmake: optional wrapper units built from function-visibility.txt #399's 02fab42 the optional function-visibility units, off by default, and cmake: function-visibility.txt, which callers must see which callees' bodies #398 one line to the optional units' list). The new function reads 100.0 raw and normalised there too. Unrounded, the average is 99.5802 against 99.5759 (normalised 99.5535 / 99.5492; 2,324 at 100.0 raw against 2,322). One main function moves, up: Global::Init::Constructor_MenuView_CrusadeMissionIntro (0x0059A9A0) goes from 90.0 to 100.0 raw and normalised, because the only difference on main, the callback it pushes (a trampoline to 0x004DD7B0 against the original's bare address), now pairs with this function. main already records it as 100% with Reimplement 176 static initializers and GetStringBasedOnHardcodedMaps #405's remark ("counted: only the pushed callback address is unnamed in the original"). All 174 of Reimplement 176 static initializers and GetStringBasedOnHardcodedMaps #405's static constructors carry that remark, and 137 of them already read 100.0 raw in main's own all-on build and keep it, so the status line is left as it is. No other function changes.
  • Instructions: the original's 822 (826 with its four alignment fillers: lea ecx, [ecx], nop, two lea esp, [esp]), in its order; reccmp's diff for the function is empty. The function has no switch table.
  • Checks: our local style checker gives 0 ERROR and 9 CHECK (below); our local fixer finds nothing to change.
  • Not run in game.

The behaviour fix

The function draws the mission intro screen of a crusader trail: the map's preview with the keeps, the lords' starting gold, the mission's number and name, and the opponents sorted by team.

  • When the current trail is complete the original draws only its message (after RenderGfxHelperUnk, which both paths call). With 20 extreme missions, 30 war chest missions or 50 first-edition missions done, it draws "Crusader Trail Completed!" and returns (three copies, 0x004DD7F7 to 0x004DD8E2). gynt's b4fa695 draws the message and then the whole screen as well; his later 1958ae8 ("Early returns") adds the three returns, as this file has them.

In play, the draft's screen for a finished trail went on past the message: it loaded the campaign data for the mission after the trail's last (when the game is not suspended), drew the boxes over the message, and titled them with the next name in the list: "51. First Step" (the war chest's first mission) after the first edition, "81. Look Out" (the extreme trail's first) after the war chest, and "21. MP-Divided" (a multiplayer map) after the extreme trail.

Read block by block against the listing, b4fa695 does everything else the way the original does.

What got it to 100%

  • The title written out per trail and per font: the number, "." and name six times over, as the original has them (its six arms end in two shared tails, one per font). With one copy and the font in a local, the function came out at 588 instructions to the original's 822.
  • Positions and text indexes in locals right before the calls that nest getText: the position (y, then x) of the completed-trail message, of the lords' texts and of the mission's name, and the name's index for the width test and for the name itself. Written inline, the compiler merges the three message copies the original keeps, hands the scratch registers out in another order from the lords' texts on, and the six title arms (three trails, two fonts) do not share their tails as the original's do.
  • The opponents' list in the original's two paths: the team stored in each arm of the game-suspended test, and the arm for a player without a lord counting and continuing on its own. With one count after the test, the compiler walks the entries with one pointer where the original walks one per field.
  • The time tests compare the map time first, as the original's cmp [time], reg; jle does.
  • avatarX copied from listX after rowY: copied straight after listX, the border height is read only once (the original reads it twice).
  • The rows' previous team in its own variable, set with the draw buffer before the two positions: with the sort's variable reused for it, listX, avatarY and the previous team take other stack slots (the frame's slots are ordered by reference count, and the three tie).

Things in the file that look odd and are the original's

  • Three copies of the completed-trail message, each with its own return: see above.
  • The mission's title is written out six times (three trails, two fonts): see above.
  • The trail type and the progress are read again from the lords' gold on, after the four locals at the top: the original reloads them there as well (0x004DDB22, 0x004DDC6E, and every title arm).
  • The war chest's missions are numbered from 51 (progress + 51, its names' index), where the other two trails show progress + 1: the original does the same in both of its arms (0x004DDDE2, 0x004DDE54).
  • The opponents' teams are stored by count and read by player id - 1 (teams[id - 1] in the rows), while the no-lord flags are stored and read by player id. Kept as the original has it (the two agree while every player from 1 up to that id takes part).
  • The sorted ids start at index 1: the sort writes sorted[k + 1] and the rows read sorted[n] from 1.
  • The sort's lowest team has no initial value; the first pick sets it (= 0 puts a xor where the original loads the slot, so a comment says so). main's style-lint bot will post one finding for it.
  • The no-lord test (no lord, and the map time more than 200 ticks past section1127) is written twice, before and after the avatar, as the original tests it twice.
  • The entries' second and third fields are only cleared, never read here.

Checker CHECKs (not changed)

  • Placeholder names, with what this function suggests they are (leads, not checked elsewhere): MissionDefinedData::field_0xaf8, a byte; when it is 0 the screen draws nothing. RenderingDefinedData::field_0x53bb4, read as pairs by (balance + intensity * 5) and drawn as the human's and the computer lords' gold (times 3 on the extreme trail). INT_00eb9ae8, 0 until the map header is read; CHAR_ARRAY_00eb0ab0, the name passed to ReadMapHeaderFromFile.
  • lowestTeam, declared without a value: see "look odd" above. (The three arrays and the struct's array have no initialiser either; the loops below them zero them, as the original zeroes them store by store.)
  • The two (int) casts on GameCore fields: see below.

Header finding (nothing changed here)

  • GameCore::mapTimeInTicks is a uint and GameCore::section1127 a dword, but the original compares them signed (jle), so the code casts both to int. Retyping them would drop the casts; not done here, since every user would need measuring. section1127 is stored together with mapTimeInTicks (0x00441771, 0x004C63DB) and read elsewhere as mapTimeInTicks - section1127 (0x004AC570), so it looks like the map time at a starting point.

🤖 Generated with Claude Code

MenuViews::CrusadeMissionIntro::MenuView_CrusadeMissionIntro_DoEveryFrame, the crusader trail's mission
intro screen: the map preview with the keeps, the lords' gold, the mission's number and name, and the
opponents sorted by team. Written from the original's listing. gynt's best is b4fa695 on his fork's
archive/UI-MenuViews-merged-full (53.54%, "Style pass"; its status line reads 53.5%); his closed sourcehold#253 has
35.8%, and his later 1958ae8 ("Early returns", 42.04%, on reimpl/UI-MenuViews-development, now 45.0% at
466d2ea) has the three returns already. His 08c492b on reimpl/UI-MenuItems-development (38.6%)
writes the id test as `<= 0`, where the original compares with 1 (0x004DE193), so it stays `id < 1` here.

One behaviour fix against b4fa695: when the current trail is complete (extreme 20, war chest 30, first
edition 50 missions) the original draws "Crusader Trail Completed!" and returns (three copies, 0x004DD7F7
to 0x004DD8E2); b4fa695 draws the text and then the whole screen as well. Everything else it does the
way the original does.

What the match needed:

- The title written out per trail and per font: the number, "." and name six times over, as the original
  has them (its six arms end in two shared tails, one per font). With one copy and the font in a local,
  the function came out at 588 instructions to the original's 822.
- The position (y, then x) of the completed-trail message, of the lords' texts and of the mission's name
  in locals right before each call, and the name's index for the width test and for the name itself.
  Written inline, the compiler merges the three message copies the original keeps, hands the scratch
  registers out in another order from the lords' texts on, and the six title arms do not share their
  tails.
- The opponents' list in the original's two paths: the team stored in each arm of the game-suspended
  test, and the no-lord arm counting and continuing on its own. With one count after the test the entries
  are walked through one pointer where the original walks one per field.
- The time tests compare the map time first, as the original does.
- avatarX copied from listX after rowY: copied straight after listX, the border height is read only once
  (the original reads it twice).
- The rows' previous team in its own variable, set with the draw buffer before the two positions: with
  the sort's variable reused, listX, avatarY and the previous team take other stack slots.

Measured in a narrow build on main 3458fea of this file alone (main is now 812d149: sourcehold#399 and sourcehold#398 add
only the optional function-visibility units, off by default), struct resolvers and its resolver on:
100.0% raw and normalised, no diff entry. Not run in game.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Style guide reading (advisory, posted once)

1 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 1 of the 1 reimplemented .cpp file(s) in this PR.

The match comes first. Where the ugly form is what matched, it stays -- that is the guide's own overriding rule, and rule 21 asks for a one-line comment saying what was measured so the next reader does not retry it. This report is posted once, when the PR opens, and is not repeated on later pushes.

rule what it asks hits
24 Declare variables upon first use 1
Where

Rule 24 — Declare variables upon first use

  • src/OpenSHC/UI/MenuViews/CrusadeMissionIntro/MenuView_CrusadeMissionIntro_DoEveryFrame.cpp:395 — declare lowestTeam where it is first assigned

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant