Skip to content

Reimplement 5 UI functions from gynt's drafts and #327/#328, with three header commits (100%) - #406

Merged
gynt merged 9 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round11-100
Nov 14, 2026
Merged

gynt merged 9 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round11-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

Five more UI functions at 100%, with three small header commits they need. Three of the functions are rewrites of gynt's drafts, with his draft used for the reads. The other two come from our drafts #327 and #328, which started from his versions too. Each commit cites the drafts it builds on and credits him as co-author. All five are part of the rest of UI that gynt OK'd on 2026-11-09.

Function Address Before After
MapEditorProperties::MenuView_MapEditorProperties_DoEveryFrame 0x0042E0D0 gynt's draft 76.56% (86f6e30) 100.0%
MapEditorProperties::MenuItemRenderFunction_MapEditorProperties_MapDescriptionBox 0x0042EBC0 gynt's draft 56.9% (8725ec5; 47.9% at ea6f9bb) 100.0% (see below)
MissionFinishedTransition::MenuView_MissionFinishedTransition_DoEveryFrame 0x004DC500 gynt's draft 56.76% (638ed4e) 100.0%
General::MenuItemRenderFunction_General_CreateEventCallbackFunction 0x004BBA60 our draft #327, 96.8% (4967da7); gynt's 95.35% (4e09857) 100.0%
VideoOptions::MenuItemRenderFunction_VideoOptions_Main 0x00492170 our draft #328, 80.4% (6325fb7); gynt's 79.95% (a457575) 100.0%

MapDescriptionBox read 100.0% in the full build described below. Built with only this round's files, it reads 99.4% raw and 100.0% normalised: the one difference is the target of its first tail call, which goes through the resolver of setScreenMenuSurfaceHeightRangeToResolution (0x0044CD30, not reimplemented yet). So it is 100% either way by the call-target rule.

Measured on main ea63a49.

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), resolvers enabled locally (not committed), and sourcehold's reccmp (6f980a441) with --resolve-wrapped-calls --ignore-security-cookie.
  • reccmp on main ea63a49: a build of this round's five files plus OptionsMenu's SubOptionsButtons handler reads all five at 100.0% normalised (MapDescriptionBox 99.4% raw, as above) and SubOptionsButtons at 100.0%.
  • Full build, before the rebase: on main c67521e with Fix main's build after the Ghidra sync: changeMapOrientation takes a MapOrientation #397's two commits (now on main as 5ec4011), a full build (all 2,171 source files) read all five at 100.0%, raw and normalised. The same full build without this branch was the baseline: every one of the 2,184 measured functions read exactly the same with this branch, header commits included. None was lower and none was higher. Since then the branch has changed in three small ways: the scroll-speed case names, two more typed fields in the MenuTextInputState header commit, and + x in MapDescriptionBox. Every function they touch reads the same before and after.
  • Checks: openshc-pr-check gives no errors, and status_regression.py finds no score below a known one.
  • Not run in game.

What got them to 100%

  • MapEditorProperties DoEveryFrame: written without the draft's gotos. The texts' positions are read into locals before each branch, y first. The minimap starts at the centre and each map size steps back to its corner (left -= 50; top -= 50). The size label's dimmed box takes the text width as a nested call, so its other arguments are pushed first.
  • MapDescriptionBox: early returns, and the button's position is read only after the three opening tests. The button's x is read once into x, which the first dimmed box and right both use (the same code as reading the global again).
  • MissionFinishedTransition DoEveryFrame: written without gotos too. The draft's gotos were MSVC's jump threading over plain if/else chains. The wait before leaving is a flag that MSVC threads away. The record-time update and the progress step are two separate tests on the trail type, and each trail's step is nested. The builder branch is a switch on the map type.
  • CreateEventCallbackFunction: the bandits text reads its position into y-then-x locals inside each of its two colour paths. MSVC still merges the two calls into the original's one, and the registers then land where the original has them.
  • VideoOptions: the button rows (not pressed, pressed) each make their own text call with their own position, y then x. The resolution cases are written in the original's block order (800x600, 1024x600, 1024x768, 1280x1024, 1600x1200, ...). Their blocks differ only in the string, so quick_diff read 1.0000 while reccmp read 81.9% until the order matched. The switch's default: return is the original's jump-table default, and the first test is button <= -10, as the original's cmp -10; jg. The cursor tests and the scroll-speed cases use the enum names (CT_ANI_CURSOR, CT_WINDOWS_LIKE_CURSOR, SS_SLOW, SS_FAST, SS_NORMAL).

Behaviour fixed compared with the drafts

  • MapDescriptionBox: when the description isn't from the string table, the original draws it, resets the surface's height range and returns. The draft went on to draw the string-table text as well, and reset the range twice.
  • VideoOptions: with a resolution the switch doesn't know, button -1 returns, as the original's jump-table default does (the same return as a button that isn't -1, at 0x0049261E). The draft fell into the zoom switch and drew the zoom text.
  • CreateEventCallbackFunction (kept from Reimplement 7 UI::MenuItems functions (draft, below 100%) #327): a crusader or arabian button that isn't the current choice falls back to the default button render. gynt's draft fell through into the bandits case.

Header changes (each in a commit of its own)

  • MC_MAP_SIZE_100 (56222fc). MapConstants names the map sizes 160, 200, 300 and 400, but not the 100 the editor also offers. The map-size switch in MapEditorProperties DoEveryFrame (0x0042E0D0) has a 100 case beside 160, 200 and 300 (400 is its default), and uses the new name. A new enum value changes no code.

  • Three MenuTextInputState fields get the types main already has (555f12c), instead of undefined4. OptionsMenu's SubOptionsButtons handler (0x00493BD0) fills all three when it opens the video options, and the VideoOptions render tests each one against its type's values:

    • menuCursorType (0x50) is a CursorTypeInt. It is copied from MouseState's cursor type, and compared with CT_ANI_CURSOR and CT_WINDOWS_LIKE_CURSOR to pick each cursor button's highlighted icon.
    • menuCurrentlySelectedResolution (0x28) is a ScreenResolutionEnumInt. It is copied from WindowAndDirectDraw::currentGameResolution, which is a ScreenResolutionEnumInt on main, and switched on with the SRE_ values to pick the resolution text.
    • menuScrollSpeedSetting (0x34) is a ScrollSpeedInt. It is copied from ScrollingHandler::scrollSpeedSetting_0x38, which is a ScrollSpeedInt on main, and switched on with SS_SLOW, SS_FAST and SS_NORMAL to pick the scroll-speed text.

    These two functions are the only reimplemented users of the three fields, and both read 100.0% before and after.

  • GameCore::skirmishTrailStartDateMonths, warchestTrailStartDateMonths, extremeTrailStartDateMonths and historicCampaignNumber are ints (e2ede57), not dwords. The original compares them signed: MissionFinishedTransition DoEveryFrame tests months - <trail>StartDateMonths < monthsTaken with jl (0x004DC6E9, 0x004DC70E, 0x004DC732), and missionNumber1to20 > historicCampaignNumber * 5 with jle (0x004DC918). With unsigned fields that takes (int) casts. Main's other users read the same before and after the change, both in a build of the fields' users and in the full build: playUnitSpeechEffect, incrementMissionProgress, switchToMenuView, readMapOrSavFile, HistoricCampaignSelect's handler, and HistoricCampaignIntro's and HistoricCampaignOutro's Prepare. Main ea63a49 has no new users of these fields.

The declaration check will fail and label this PR until main has these lines. Then I'll merge main in.

Two functions leave the drafts

Each draft gets one commit that removes the .cpp and puts its status line back to main's (fba4a22 on #327, 1849424 on #328). Both drafts still compile without them.

Kept as they are, measured with quick_diff

Function Kept The cleaner form
MapEditorProperties DoEveryFrame the header texts' position in locals before the single/multiplayer branch, y first inline: 0.7363
MapEditorProperties DoEveryFrame the map name's position in locals in both of its branches inline: 0.8768 and 0.8659
MapEditorProperties DoEveryFrame the clicked-button texts' position in locals, y first inline: 0.9746
MapEditorProperties DoEveryFrame the separators and map-type names write x + 140 and y + 35 at each call reading the textX / textY locals there: 0.7615
MapEditorProperties DoEveryFrame the minimap's centre copied after the map-size switch's default copied straight after top: 0.9909
MapDescriptionBox top worked out before right right first: 0.9704
MapDescriptionBox the lines work from top, with no local for the button's y a y local: 0.8798
MapDescriptionBox x - 1 written at each use in a local: 0.9436
MissionFinishedTransition DoEveryFrame each trail's step nested, the progress incremented in both branches three separate ifs: 0.6224; alive in a local: 0.8892
MissionFinishedTransition DoEveryFrame the builder branch as a switch on the map type an if/else: 0.9905
MissionFinishedTransition DoEveryFrame isSkirmishTrail == TRUE a truth test; the original compares the field with 1
VideoOptions the button rows' own text calls one shared final call with the text set on every path: 0.9845
VideoOptions each cursor button's icon starts at 0, becomes 2 for the chosen cursor, and then gets its base (182 or 183) added int icon = 182; if (..) icon += 2;: 0.9871
CreateEventCallbackFunction the bandits text's position in locals inside each colour path inside the calls: 96.8% in reccmp

The kept forms that a reader might tidy away each have a one-line comment.

Numbers left as numbers:

  • CreateEventCallbackFunction's text numbers (91 to 99, 146, 148, 157 to 162, 221, 222): textNumInGroup is a number in the TEXT_SCENARIO group, with no enum on main.
  • VideoOptions' zoom flag (0, 1): MenuTextInputState::unknownZoomRelatedFlag01 is an undefined4 with no enum.

What some placeholders hold

  • DAT_00b960f4: the map description's scroll offset in pixels. Main's MapDescriptionScrollbar handler moves it in steps of 14 and clamps it, and SingleplayerMapChoice_MapTable resets it to 0. The render subtracts it from the text's y.
  • INT_00b960e4: whether the map has a name. While it is 0, MapEditorProperties shows TEXT_MAPEDIT text 24 ("Untitled") in the name row, otherwise the user's text 2. Main's UnusedCreateSiege_SiegeThat handler sets it to TRUE.
  • INT_00b95f68: main's MapDescriptionBox action handler sets it to TRUE when the box is clicked. MapEditorProperties DoEveryFrame clears it, together with MenuTextInputState::field_0xa4, while that field is set.

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 8 commits November 14, 2026 00:10
MapConstants names the map sizes 160, 200, 300 and 400 but not 100, which the editor also offers: the map-size switch
in MenuView_MapEditorProperties_DoEveryFrame (0x0042E0D0) has cases for 100, 160, 200 and 300, with 400 as its
default, and now uses MC_MAP_SIZE_100 there. A new enum value changes no code; the functions that read the map
constants measure the same before and after (reccmp, one build with every user on the build list).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d are typed

Three undefined4 fields of MenuTextInputState hold values whose type main already has. OptionsMenu's
SubOptionsButtons handler (0x00493BD0) fills each of them when it opens the video options, and the VideoOptions
render (0x00492170) tests them against that type's values:
- menuCursorType (0x50) is a CursorTypeInt: copied from MouseState's cursorType, and compared with CT_ANI_CURSOR and
  CT_WINDOWS_LIKE_CURSOR to pick each cursor button's highlighted icon.
- menuCurrentlySelectedResolution (0x28) is a ScreenResolutionEnumInt: copied from WindowAndDirectDraw's
  currentGameResolution (a ScreenResolutionEnumInt on main), and switched on with the SRE_ values to pick the
  resolution text.
- menuScrollSpeedSetting (0x34) is a ScrollSpeedInt: copied from ScrollingHandler's scrollSpeedSetting_0x38 (a
  ScrollSpeedInt on main), and switched on with SS_SLOW, SS_FAST and SS_NORMAL to pick the scroll-speed text.
These two are the only reimplemented functions that use the three fields, and both measure the same before and
after (reccmp 100.0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ints

skirmishTrailStartDateMonths, warchestTrailStartDateMonths, extremeTrailStartDateMonths and historicCampaignNumber
were dword. The original compares them signed: MissionFinishedTransition's DoEveryFrame (0x004DC500) tests
`months - <trail>StartDateMonths < monthsTaken` with jl (0x004DC6E9, 0x004DC70E, 0x004DC732) and
`missionNumber1to20 > historicCampaignNumber * 5` with jle (0x004DC918), which an unsigned field could only give
through (int) casts. Every other user on main measures the same after the change (reccmp, one build):
playUnitSpeechEffect, incrementMissionProgress, switchToMenuView (98.7 before and after, its call target),
readMapOrSavFile, HistoricCampaignSelect's handler, and HistoricCampaignIntro's and HistoricCampaignOutro's Prepare.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft 86f6e30 (76.56%, "Map-size dispatch is a switch"), without its gotos and decompiler
locals; the behaviour is the same. The forms the original was compiled from, each measured (quick_diff 0.9964,
against 0.6978 for the draft built on main; reccmp 100.0):
- the header texts' position is read into locals before the single/multiplayer branch, y first, and so are the map
  name's position in each of its two branches and the clicked-button texts' (inline: 0.7363, 0.8768, 0.8659, 0.9746);
- the separators and map-type names write x + 140 / y + 35 at each call: reading the textX / textY locals there
  measured 0.7615, so a comment says the original reads the position again;
- the minimap starts at the centre and each size steps back to its corner (left -= 50, top -= 50), with the centre
  copied after the map-size default (copied straight after top: 0.9909);
- the size label's dimmed box takes the text width as a nested call, so its other arguments are pushed first.

The 100 map size is MC_MAP_SIZE_100 (the MapConstants header commit). COL_BLACK's short value is passed uncast,
needsRedraw takes TRUE, and the string comments stand above their calls, the TEXT_MAPEDIT entries included
("Multi-Player", "Untitled", "Flag this map as Balanced" / "Un-Balanced", "Invasion", "Economic"). The draft's
field44_0xa4 is main's field_0xa4.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (ea6f9bb at 47.9%; his last reimplement commit on the file is 8725ec5 and his last
style pass dd1a7c4; 0.5519 in quick_diff for the draft built on main), with early returns. reccmp 99.4, normalised
100.0: the only difference is the first tail call's target, which goes through the resolver for
setScreenMenuSurfaceHeightRangeToResolution (0x0044CD30), not reimplemented yet.

Behaviour fix: when the description is not from the string table, the original draws it, resets the surface height
range and returns; the draft went on to draw the string-table text as well and reset twice.

Forms the original was compiled from, measured (quick_diff 0.9882): the button position is read only after the three
conditions; top is computed before right (right first: 0.9704); the lines work from top rather than a local for the
button's y (a y local: 0.8798); x - 1 is written at each use (in a local: 0.9436). The first dimmed box and right
take the x local (the same code). The parameter is never read, so it is named unused; the colour's short value is
passed uncast.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten without gotos from gynt's draft (638ed4e at 56.76%; 0.6469 in quick_diff for the draft built on main).
reccmp 100.0.

The decompiler's gotos are MSVC's jump threading over plain if/else chains, so the source is written as those:
the wait before leaving uses a flag that MSVC threads away; every exit after it shares the final
skipStoreSKMasters = 0 (the early return does not reach it, as in the original); the record-time update and the
progress step are two separate dispatches on the trail type; and each trail's step is nested, the progress
incremented in both branches (as three separate ifs: quick_diff 0.6224; alive read into a local: 0.8892). The
builder branch is a switch on the map type (an if/else: 0.9905).

The progress steps are ++; the loop-flag stores before the two endSoundStream calls are indexed by SND_STR_SPEECH_2
and SND_STR_SPEECH_1, being endSpeechStreamsAndResetLoopFlags (0x00424700) written out inline; the trail start dates
and historicCampaignNumber need no casts after the GameCore header commit; the Bink handle is compared with NULL and
the wait flag is a BOOLEnum.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_General_CreateEventCallbackFunction, from the draft sourcehold#327 (reimpl/UI-MenuItems-3-development,
4967da7, 96.8%; the file's newest commit on the draft is 446f9fa), itself rewritten from gynt's 4e09857
(95.35%). The bandits text now reads its position into `int const textY` then `textX` inside each of the two colour
paths: MSVC still merges the two calls into the original's one, and the first push 0 and the " - " text's registers
now land where the original has them. With the position written inside the calls it measured 96.8%. reccmp 100.0,
normalised 100.0, quick_diff 157/157 at 1.0000.

The parameter is textNumInGroup, as main names it in RenderScenarioButtonWithText, which gets the same value.
Case 93 sets option = 2 rather than the draft's iconOffset, which holds 2 there (the same code), and a comment marks
case 148's fall-through into 146.
Behaviour fix kept from sourcehold#327: a crusader or arabian button that is not the current choice falls back to the default
button render; gynt's draft fell through into the bandits case.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_VideoOptions_Main, from the draft sourcehold#328 (reimpl/UI-MenuItems-3-development-2, 6325fb7, 80.4%;
the file's newest commit on the draft is a552e96), itself gynt's draft (newest gynt reimplement commit on the
function: a457575). Three changes:
- The button rows (not pressed, pressed) each make their own text call with their own position, y then x, and the
  zoom and scroll-speed rows share one call after their switches. MSVC merges the button calls into the original's
  and puts the push 0s where the original has them; the draft's single shared call with an iVar1/yParam/color set on
  every path measured 0.9845 in quick_diff.
- The resolution cases are written in the original's block order (800x600, 1024x600, 1024x768, 1280x1024, 1600x1200,
  ...): their blocks differ only in the string, so quick_diff read 1.0000 while reccmp read 81.9 until the order
  matched.
- The first test is `button <= -10`, as the original's `cmp -10; jg`.

Behaviour fix: with an unknown resolution, button -1 returns, as the original's jump-table default does (the same
`return` as a button that is not -1, 0x0049261E); the draft fell into the zoom switch and drew the zoom text. reccmp
100.0, normalised 100.0, quick_diff 388/388 at 1.0000.

The cursor tests use CT_WINDOWS_LIKE_CURSOR and CT_ANI_CURSOR and the scroll-speed cases SS_SLOW, SS_FAST and
SS_NORMAL (the fields are typed in the MenuTextInputState header commit). `int icon = 182; if (..) icon += 2;`
measured 0.9871, so the icon still starts at 0 and a comment says so. The resolution strings are string-literals.hpp
pointers with their comments above the calls, the no-op (int) casts on the int button globals are gone, the parameter
is button and the icon and text indices have names.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 13, 2026
gynt added a commit that referenced this pull request Nov 14, 2026
Main's Ghidra sync 3fe22dd has this PR's header changes, so the PR no
longer changes a header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 14, 2026
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.

2 participants