Skip to content

Reimplement 9 UI functions from gynt's drafts (100%) - #385

Merged
gynt merged 16 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round7-100
Nov 10, 2026
Merged

gynt merged 16 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round7-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Nine more UI functions at 100%. Each one was written from the original's instructions, with gynt's draft (below 100%) used for the reads. Each commit cites the drafts it builds on and credits him as co-author. This is part of the rest of UI gynt OK'd on 2026-11-09.

Function Address gynt's best draft
MenuItemRenderFunction_AlliesOrder_Main 0x004AD480 61.11%
MenuItemActionHandler_InGameMenu_ViewToKeeps 0x004335A0 44.28%
MenuItemActionHandler_NewMapMapsize_Buttons 0x0042F940 72.62%
MenuItemRenderFunction_EditScenario_StartDate 0x004BAC90 79.73%
MenuItemActionHandler_SoundOptions_VolumeSlider 0x00492890 78.72%
MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons 0x004BA980 54.45%
MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops 0x00439160 47.7%
MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton 0x00466320 52.48%
HoveredState::calculateHoveredTile 0x005119D0 66.5%

Measured on main (9528350 for the first six, b6d9688 for the last three; the only change between the two is the style guide). The setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), resolvers enabled locally (not committed), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.

  • reccmp: a full build reads all nine at 100.0%.
  • Last commit: it holds only names, comments and shapes that compile the same. quick_diff output is identical for all nine files.
  • Checks: openshc-pr-check gives no errors, and status_regression.py finds no score below a known one.
  • None of it has been run in game.

Behaviour fixed compared with the drafts

  • AlliesOrder render: for a human player the original returns after drawing the name (0x004AD708-0x004AD73B), where the draft went on to draw the AI name text as well.
  • UnusedCreateMessageEvent_Buttons: off the "Characters" page the original returns after face 1012, as after 1009 to 1011 (0x004BA9D1). The draft fell through, which either cleared DAT_ButtonUnknownZero again (pages 0 to 3) or drew the button (pages past 4).

Header changes (each in a commit of its own)

Main's Ghidra sync (6c1e0bd) brought these header lines, and main (d5d965d) is merged in, with our code following main's spellings (TAIT_UNKNOWN for text index 4, INT_00b9840c), so the declaration check passes now.

  • DAT_00b9840c is an int (3a26fe6, and dbb3e8c for its data.asm symbol, which the new type needs to link). ViewToKeeps uses it as a signed count of wheel steps within a second: down counts 1, 2 (test ebx, ebx; jge at 0x4335EE, cmp ebx, 2 at 0x4335F7), up counts -1, -2 (test ebx, ebx; jle at 0x433711, cmp ebx, -2 at 0x43371A). No file on main uses it.
    • When main retyped 0x00B95954 (e32319b), the generator also renamed it INT_00b95954 and updated the precomp address list. We left the name and the precomp line for gynt's next sync rather than guess the generator's output.
  • GameCore::viewedKeepIndex is an int (6ca034f). ViewToKeeps wraps it back to 0 once it passes the number of keeps, with a signed compare (add edi, 1; cmp edi, esi; jl at 0x4336EF-0x4336FC). No file on main uses it.
  • MapPropertiesState's message-library fields are ints (9eae62a): field_0x13590, plus the 8 bytes after it, which were one padding_0x13594[8], as field_0x13594 and field_0x13598.
    • The Buttons render reads field_0x13590 as a signed page number (jge at 0x4BAB00 after cmp eax, 3 at 0x4BAA15, and cmp eax, 4; jge at 0x4BAB0B).
    • It reads the other two as dwords, each compared with a button's offset (0x4BA9FD, 0x4BAA2A, 0x4BAA08). They are int, like the values they are compared with.
    • The struct's size is unchanged, and no file on main uses these fields.

Kept as they are, measured with quick_diff

Function Kept The cleaner form
CurrentlySelectedTroops every troop type its own case (7 and 25 repeat 2, 24 repeats 20) shared labels and fall-throughs: 0.9457 → 0.7640
RepairBuildingButton the disabled flag tested twice one if/else holding the texts: 0.9481 → 0.6994; a colour variable: 0.7368
RepairBuildingButton the text position read in each of the three arms once before them: 0.6623; in the calls: 0.8395
UnusedCreateMessageEvent_Buttons the plain text as an if/else on the hover state an early return: 0.9718 → 0.8870
SoundOptions_VolumeSlider the read-back written out in events 1 and 4 one read-back after the switch: 0.9222 → 0.7797; slider 2 before 1: 0.8136
EditScenario_StartDate the labels' position read y first; the other buttons in the switch's default x first: 0.9306 → 0.8750; no break or early returns: 0.8784
NewMapMapsize_Buttons both arms of the U2_mapType_singleOrMulti == 1 test, which the original still compares one call: 0.9704 → 0.7636
NewMapMapsize_Buttons mapSize set before the early returns after them: 0.9704 → 0.9586
ViewToKeeps one plain loop over the ten keep slots (MSVC unrolls it five wide, as the original is) an outer loop in fives: 0.5844
calculateHoveredTile the flag's picture and offsets kept across the loop declared at their first use: 0.9690 → 0.6590
  • calculateHoveredTile passes the element's type to setConstructionGFXLayerBasedOnPlacementChecks as (MappersEnum)(ushort). The original loads it as a word (movzx at 0x511BFB), and the callee reads a word (mov bx, word ptr [esp+0x28] at 0x504F14), but the header's parameter is a MappersEnum. MappersEnumShort would give a movsx, so it is no drop-in.

  • AlliesOrder casts DAT_00df5200 to eTextSections because the global is undefined4. The three globals at 0xDF51F8/FC/5200 are only used here: the tooltip's player, its text number and its text group. They could become int/eTextSections in a header commit.

  • Numbers left as numbers:

    • the orientation case labels in calculateHoveredTile (main compares mapOrientation as a number too);
    • StartDate's button IDs;
    • the scroll events and sliders in VolumeSlider;
    • ViewToKeeps' wheel events 7 and 8 (main writes them as numbers; 7 is the wheel turned down).

    None of these has an enum on main.

  • The '\0' in NewMapMapsize stores a char array's terminator (rule 26).

What some placeholders hold

  • DAT_00b9840c: the wheel-step counter above.
  • field_0x13590: the message library's open page (0 "Tutor" to 4 "Characters").
  • field_0x13594 and field_0x13598: the entries chosen on it.
  • field_0x55487c: main's name. NewMapMapsize sets it to 200.
  • pendingStreamVolume0/1/3: undefined4, compared with ints. They could be int.

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 14 commits November 9, 2026 22:07
DAT_00b9840c, at 0x00B9840C, was undefined4. MenuItemActionHandler_InGameMenu_ViewToKeeps (0x004335A0) uses it as a
signed count of mouse wheel steps within a second: down counts 1, 2 (test ebx, ebx; jge; ... cmp ebx, 2), up counts
-1, -2 (test ebx, ebx; jle; sub ebx, 1; cmp ebx, -2). The annotation names the int instance too. No file on main reads
it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
data.asm names the instance at 0x00B9840C with the int type (H instead of I) in its PUBLIC and EQU lines, as it does
for main's other int globals, to go with the header commit before it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
viewedKeepIndex was dword. MenuItemActionHandler_InGameMenu_ViewToKeeps (0x004335A0) views the next keep and wraps
the index back to 0 once it passes the number of keeps with a signed compare (add edi, 1; cmp edi, esi; jl). No file
on main reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_AlliesOrder_Main draws the allies dialog: the enemies' portraits with an AI's or a human lord's
icon or face (buttons 1 to 6, an empty box past the last enemy), the dialog's other buttons, and as item -1 the
tooltip the hovered button set, with the player's name for a portrait. Written from the original's instructions, with
gynt's drafts (3b1bcad on his fork's reimpl/UI-MenuItems-development, 58.50% there, earlier d545ddb at 58.00%;
411fb29 at 61.11% and f8e2826 at 60.61% on reimpl/UI-MenuItems) for the reads. Behaviour fix: for a human player the original returns after the name, where the draft went on to draw the
AI name text as well. The forms the original needs: button itself becomes the row and then the player, as the
original's one register does, and the tooltip's position read x first. Also: decimals for the picture numbers, COL_B8EEFB,
TEXT_ALLIES, no gotos or decompiler locals. quick_diff leaves only the colour immediates and ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_InGameMenu_ViewToKeeps handles the mouse wheel in game: two steps down within a second view
the next keep on the map, two steps up the own keep (scroll event 7 is the wheel turned down, as main's
updateMouseStateBasedOnCursorAndTime sets it for a negative delta). Written from the original's instructions, with gynt's draft
(209d8e3 on his fork's reimpl/UI-MenuItems-development, 44.28% there; earlier 9707d0c at 42.07%) for the reads.
Needs the header commits for DAT_00b9840c and GameCore::viewedKeepIndex. The ten keep slots are one plain loop,
which MSVC unrolls five wide as the original is (an outer loop in fives with an inner loop up to i + 5 stays a
loop: quick_diff 0.5844). Also: countof, BEIE_KEEP for the keep's building entry, decimals, no decompiler locals.
quick_diff leaves the timeGetTime import call's form and ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_NewMapMapsize_Buttons makes a new map in the editor: buttons 1 to 4 set the map size (160, 200,
300 or 400), reset the heights, borders, path linkage, wildlife and minimap for it and open the map properties; 7
goes back to the custom scenarios. From gynt's draft (64e69da on his fork's reimpl/UI-MenuItems-development, 72.62%
there; earlier a3f0f9c at 55.95%;
his fork's reimpl/UI-MenuItems-development measured it again in 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%")). The forms the original needs: button 7 tested and handled first (it lays the
1-4 path out after it), and the switch to the map properties written in both arms of a test of
U2_mapType_singleOrMulti == 1, which the original compares there with both arms the same (one call: quick_diff 0.7636
and no cmp). Also: main's field_0x55487c, the map sizes as MapConstants, button and mapSize for the decompiler's
names, decimals. quick_diff leaves ret / ret 0 and the jump over the loop's alignment padding, which its npad hides.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_EditScenario_StartDate draws the scenario editor's text buttons: -5 "Start Date" and -1
"Name" as centred labels, 0 nothing, and any other button its own scenario text, centred unless the button has no
width. From gynt's draft (00717e8 on his fork's reimpl/UI-MenuItems, 79.73% there; earlier 20d5849 at 34.23%;
his fork's reimpl/UI-MenuItems-development also has it in 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%")).
The forms the original needs: the labels' position read y first (x first: quick_diff 0.9306 -> 0.8750), and the
other buttons handled in the switch's default, which ends in a break: only then does MSVC share the two text calls'
tail as the original does (no break, or the calls after the switch with early returns: 0.8784). Also: a switch for
the nested ifs, COL_CCFAFF, TEXT_SCENARIO, decimals, and the texts named from cr.tex (the draft's comment called
text 32 "Start Date"). quick_diff leaves only the colour immediates and ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_SoundOptions_VolumeSlider handles the music, sound effects and speech sliders (0, 1, 2):
event 1 sets the range 0 to 100 and reads the stored volume, 2 and 3 hand a changed volume to the slider's sound
channels (0; 1, 2 and -1; 3 and 4) and store it, 4 reads the stored volume back. From gynt's draft (aca568d on his
fork's reimpl/UI-MenuItems, 78.72% there; earlier 385b087 at 58.06%;
his fork's reimpl/UI-MenuItems-development also has it in 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%")). The form the original needs: the read-back
written out in both event 1 and event 4, each switch in slider order 0, 1, 2; MSVC then shares their blocks between
the two events the way the original does (one read-back after the switch: quick_diff 0.7797; slider 2 before 1 in
event 4: 0.8136, as the two copies are then merged whole). Also: main's pendingStreamVolume names, slider and
scrollbarEvent for the decompiler's names, no casts. quick_diff leaves only ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
field_0x13590 was undefined4 and the 8 bytes after it one padding_0x13594[8].
MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons (0x004BA980) reads field_0x13590 as a signed page number
(jge at 0x4BAB00 on the cmp eax, 3 at 0x4BAA15, and cmp eax, 4; jge at 0x4BAB0B) and the padding as two dwords,
each compared with a button's offset: 0x13594 at 0x4BA9FD and 0x4BAA2A (cmp reg, dword ptr [0x1666dec]), 0x13598
at 0x4BAA08 (cmp eax, dword ptr [0x1666df0]). So the three are ints, like the page numbers and button offsets they are compared with: field_0x13590, field_0x13594 and
field_0x13598. The struct's size is unchanged. No file on main reads them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons draws the buttons of the unused message library: buttons 4
to 8 open its pages "Tutor" to "Characters" (field_0x13590 0 to 4), on "Adviser Prompts" buttons 9 and 10 show
"Civil" and "Military", and on "Characters" the faces 1009 to 1012 stand in for buttons 9 to 12, with the face above
the name. The open page's button and the entries chosen in field_0x13594 and field_0x13598 are drawn highlighted;
buttons a page does not have set DAT_ButtonUnknownZero or are skipped. Written from the original's instructions,
with gynt's draft (ef255f4 on his fork's reimpl/UI-MenuItems-development, 54.45% there; earlier 9c47863 at
30.39%) for the reads. Needs the header commit for the three MapPropertiesState fields. Behaviour fix: off the
"Characters" page the original returns after face 1012 as after 1009 to 1011, where the draft fell through, which
cleared DAT_ButtonUnknownZero again (pages 0 to 3) or drew the button (pages past 4). The forms the original needs:
the highlight test as one condition, from which MSVC lays out the page tests and both copies of the "Civil" /
"Military" remap and of the face as the original does, and the plain text as an if/else on the hover state, so
that its first arm holds the text call's shared tail (an early return instead: quick_diff 0.9718 -> 0.8870). Also:
no gotos or decompiler locals, decimals, COL_CCFAFF and COL_C2F0EB, the texts named from cr.tex. quick_diff leaves
only the colour immediates and ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops draws one portrait of the build menu's selected-troops bar:
nothing while no own unit is selected or the slot is empty (-1), otherwise the slot's troop portrait, nudged into
place per troop type, with the number of selected units of that type under the button. The Arabian troops (19 on)
take their portraits from a second set further along the button table. From gynt's draft (dd1a7c4 on his fork's
reimpl/UI-MenuItems-development, 47.7% there after his 8725ec5; earlier 343a1ac at 44.53% and 8135310 at
35.71%). The form the original needs: every troop type its own case, with cases 7 and 25 repeating case 2 and case 24 repeating
case 20 instead of sharing their labels and no case falling through into the next. MSVC then copies the >= 19 test into every
case, shares the identical tails afterwards and builds one dword jump table, as the original does (shared labels and
fall-throughs: quick_diff 0.7640, with a byte table in front of the jump table). Also: the cases in order and named
after their troops from RenderingDefinedData::SelectionSlotUnitTypes, TRUE and FALSE for DAT_ButtonUnknownZero.
quick_diff leaves only the colour immediate, the jump table's label and ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton draws the repair button of a building's menu: it
sets DAT_ButtonUnknownZero for another player's building, is drawn disabled (renderBasicButton's 8, a dimmed button, and a grey "Repair") when the
building has no damage to repair or an enemy is within 30 (15 in a multiplayer game), and otherwise drawn live with
the hover colour. From gynt's draft (ef06bee on his fork's reimpl/UI-MenuItems, 52.48% there; earlier de4fae5 at
50.35%; his reimpl/UI-MenuItems-development copy last measured in 8725ec5, then restyled in 5084980). The forms the original needs: the disabled test
kept in a flag that is tested twice, once for the button and once for the text, so that MSVC lays the disabled button
out first and folds the second test into both arms (one if/else holding the texts: quick_diff 0.6994; a colour
variable: 0.7368), and the text's position read in each of the three text arms (once before them: 0.6623; in the
calls: 0.8395). Also: main's sibling handler's names (notDamaged, requiredDistance), unused for the parameter, TRUE
and FALSE for DAT_ButtonUnknownZero, COL_7CAAAF, COL_C2F0EB and COL_CCFAFF, decimals. quick_diff leaves only the
colour immediates and ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HoveredState::calculateHoveredTile, from gynt's drafts (9dedc43, 65.8%, in his closed sourcehold#256; 63e2b09, 65.83%, on his fork's
archive/UI-MenuViews branches;
66.5% in 10280b1 on his fork's reimpl/UI-Core-development), rewritten from the binary as one for-loop over the
elements with a switch on the mapper type. The flag's picture and offsets are locals that keep their values from
one element to the next, as in the original; the cases are in the original's block order (mangonel, ballista,
brazier, flags, heads, siege tents, then building previews) and the orientation cases in the order 0, 4, 2, 6. The
draft stepped its element pointer by six elements. In the siege-tent case the tile is stepped (++x / --x) before
the picture's x offset is set, as the original's instruction order has it, which gives its register pair (x in ecx,
the offset in edx). reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ain's siblings

- CurrentlySelectedTroops render: the troop type is a UnitSelectionEnumInt with main's USE_* names as the case
  labels and the Arabian test, slotID as in the sibling handler, and the kept shape's comment gives its measurement.
- AlliesOrder render: the TEXT_ALLIES texts in comments ("Clear Orders", "Defend Me", "Attack") and the AI's name;
  the comment on the row and player is one line.
- ViewToKeeps: `unused` for the first parameter, the wheel directions the right way round (7 is the wheel turned
  down, as main's updateMouseStateBasedOnCursorAndTime sets it for a negative delta), and early returns for the
  last block.
- NewMapMapsize_Buttons: FALSE/TRUE for the two BOOLEnum fields, `row` as main's twin names the wildlife loop, and
  the two kept shapes say what they measure.
- calculateHoveredTile: names qualified instead of two `using namespace` lines, and one line each on the locals kept
  across the loop and the type passed as a word.
- RepairBuildingButton, UnusedCreateMessageEvent_Buttons, SoundOptions_VolumeSlider: the kept shapes give their
  measurements in main's one-line form; VolumeSlider loses a trailing return.
quick_diff output is identical for all nine files. Tried and lost: mapSize set after NewMapMapsize's early returns
(0.9704 -> 0.9586), calculateHoveredTile's locals at their first use (0.9690 -> 0.6590).

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 9, 2026
kotijekriv and others added 2 commits November 10, 2026 00:43
Main's Ghidra sync 6c1e0bd brought this branch's header changes; main's versions are kept.

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

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 9, 2026
@gynt
gynt added this pull request to the merge queue Nov 10, 2026
Merged via the queue into sourcehold:main with commit d97856d Nov 10, 2026
4 checks passed
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