Skip to content

Reimplement 5 UI menu-item engine functions from gynt's drafts (100%) - #383

Merged
gynt merged 11 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-A-round38-100
Nov 10, 2026
Merged

gynt merged 11 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-A-round38-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Five functions of the menu-item engine, the code that builds, steps through and draws a menu's items, all at 100%. Each was written from gynt's draft, which was below 100% (his closed #256, restyled later on his fork), and each commit cites the drafts it builds on and credits him as co-author. This is part of the rest of UI that gynt OK'd on 2026-11-09.

Function Address gynt's best Now
BottomLeftTextDisplayState::setBottomLeftTextDisplayText 0x004F4E00 35.9% 100.0%
MenuItem::prepareAndRenderMenuItems 0x004F49D0 59.8% 100.0%
Menu::handleMenuItems 0x004F6280 20.8% 100.0%
Menu::Constructor_Menu 0x004F4100 21.5% 100.0%
Menu::renderConstructionMenu 0x004F64A0 64.0% 100.0%

Measured on today's main (9528350).

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), resolvers enabled locally (not committed), sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • A full build reads all five at 100.0% raw.
  • openshc-pr-check gives no errors, and status_regression.py finds no score lower than before.
  • None of it has been run in game.

What changed from the drafts

  • setBottomLeftTextDisplayText:
    • a message type of 0 clears the text and returns, and a less important text returns early (the draft's check was empty);
    • the countdown restarts unless the same text is shown again;
    • a duration of -1 stores 0 and skips timeGetTime.
  • prepareAndRenderMenuItems:
    • while the build menu slides, an item outside the menu area, or any item between 45% and 55% of the slide, returns without being drawn (the draft only zeroed the blend strength there);
    • the slider branch reads secondItemTypeData.scrollbarOrSliderState (minValue, maxValue, currentValue, dragTiming) where the draft read the same four ints through buttonState.
  • handleMenuItems: one for over the items up to MIT_LAST_ENTRY, with an if/else chain on the item type. The draft's empty ifs are the returns the original has: on the current tab's stop item, on MIT_STOP_HANDLING, during a build-menu slide while handling input, while a modal dialog is open, and when an item's input callback asks to stop.
  • Constructor_Menu: written from the binary. The item before a run of alternatives is marked as the run's head.
  • renderConstructionMenu: written from the binary.
    • The message type is one switch: 0 returns; twelve types show the text bottom-left, each storing and returning on its own; every other type shows the tooltip once the mouse has rested on the item for 200 ms.
    • "Resume Game" is shown while the game is paused.

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.

  • SliderRenderFunction and ScrollbarRenderFunction: the last parameter bool → BOOLEnum (bffeb07).
    • The original keeps the flag in a stack slot (mov dword ptr [esp + 8], 1 at 0x004F4BB4) and pushes it as a dword. A bool parameter makes MSVC compare and setne first.
    • MenuItemRenderFunction_0x20, the same callback in Ghidra's other copy, already has BOOLEnum.
    • Main's slider render functions take BOOL isDragged (five) or BOOLEnum (NewInvasion_RepeatSlider), and every scrollbar render function takes BOOLEnum.
    • Only MenuItemRenderFunctionUnion uses the two typedefs, and no .cpp on main uses its .slider/.scrollbar members, so nothing else changes.
  • TextMessageBLLookupStructTypeEnum gets TMBLLSTE_UNKNOWN_0 and _7 to _13 (e94e6ea).
    • renderConstructionMenu switches on the lookup's message type with cases for 0 and for 7 to 13, besides the five named types.
    • Each of 7 to 13 passes its own number on as the message type.
    • They are named the way TheRedDaemon asked on Reimplement 33 Map::Version functions that are 100% #300. No .cpp on main uses the enum's names.
  • setBottomLeftTextDisplayText's param_4 is associatedTypeUnk (28ded95).
    • The parameter is compared with and stored as the lookup's associatedType.
    • Main's three callers (processMenuViewSwitch, DeleteAction, TriggerPlaceWallCommand) pass it by position, and the .func.hpp takes only the member pointer, so nothing depends on the name.

Kept as they are, measured with quick_diff (each has a one-line comment)

Function Kept The cleaner form
renderConstructionMenu the index masked again for the tooltip's two reads reusing index: 0.9559 → 0.8883
renderConstructionMenu hoverTextX stored in both branches one store before the test: 0.9559 → 0.9046
renderConstructionMenu each case stores and returns a break to one shared store: 0.9559 → 0.8475
renderConstructionMenu the ushort field loaded as a word 0.9559 → 0.9227
Constructor_Menu a while over the options (the pointer advances in the inner loop) a for: 0.8787 → 0.6025
prepareAndRenderMenuItems isDragged declared early at its first use: 0.9645 → 0.7980
prepareAndRenderMenuItems the range written out at each use in a local: 0.9645 → 0.8832
setBottomLeftTextDisplayText the lookup index declared before the message type in the for: 0.9884 → 0.9767
handleMenuItems the sign bit tested with & >= 0: 0.9191 → 0.9118

The style-lint bot's three findings:

  • Constructor_Menu's while is the measured row above.
  • 0xffff (renderConstructionMenu) and 0x7fffff (prepareAndRenderMenuItems) are masks used with &. gynt's rule (Reimplement 32 rendering and UI rendering functions at 100% #311) allows hex there. The second is MIT_MENU_ITEM_TYPE_ID_PARTUnk's 23-bit index mask, not a colour.

renderConstructionMenu reads the text index as *(int*)&item->textMessageLookupIndex & 0xffff, the whole dword masked, as the original does. gynt's handleMenuElementsCallbacks makes the same read and takes the high word as a sound ID, so the field looks like a union (see below).

Proposed, not changed here

  • MenuItemType names for the bits handleMenuItems and Constructor_Menu test, written as local constants for now:
    • MIT_OPTION_GROUPUnk and MIT_OPTIONUnk;
    • MIT_CLICK_HANDLERUnk = 7;
    • MIT_ALTERNATIVEUnk (1 << 26) and MIT_ALTERNATIVES_HEADUnk (1 << 27);
    • MIT_RENDER_SEPARATELYUnk = 0x800000, which matches MIHS_…_FOR_FLAG_0X800000;
    • the sign bit, which we call hiddenFlag (a guess).
  • MenuHandlerState::const017/const516 dword → int. prepareAndRenderMenuItems casts them, and setupBuildMenuState only stores them.
  • A minThumbLengthUnk member in MenuItemFirstItemTypeData: for a slider, itemsToSkip holds the minimum thumb length.
  • MenuItem::textMessageLookupIndex as a union: an int, plus the low word (the text index) and the high word (a sound ID).
  • Main's resetMenuItemStateUnk writes slider state through buttonState, the same mix-up the draft had here.

What some fields hold

  • Menu::zero: the tooltip state (0 none, 1 waiting, 2 shown).
  • someTimestampUnk: when the hover started.
  • someMenuItemPtr_0x3c: the tooltip's item.
  • As the original does: UNITS_AND_WEAPONS passes message type 6, the other named types pass their type − 1, and 7 to 13 pass their own number.

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 10 commits November 9, 2026 18:13
BottomLeftTextDisplayState::setBottomLeftTextDisplayText, from gynt's draft (4320604, 35.93%, and c7ba75f,
32.7%, in his closed sourcehold#256; restyled up to cf563c2 on his fork's archive/UI-MenuViews-development-second-pass and
in 10280b1 on reimpl/UI-Core-development), rewritten from the binary: a message type of 0 clears the text and
returns, a less important text returns early (the draft's check was empty), the countdown restarts unless the same
text is shown again, and a duration of -1 stores 0 and skips timeGetTime. The parameter stays main's int
param_4 (the draft used the union); it is compared with and stored as the union's buildingType. The lookup loop's
index is set before the message type (declared in the for it measures lower; the numbers are in the PR
text), and the sound is s_placement_warning1_wav_005ab8f4
rather than a string literal. reccmp 100.0%.

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

The original pushes it as a 4-byte value: prepareAndRenderMenuItems (0x004F49D0, next commit) keeps the flag in a
stack slot (mov dword ptr [esp + 8], 1 at 0x004F4BB4) and pushes it with mov ecx, dword ptr [esp + 8] / push ecx,
where a bool parameter makes MSVC compare and setne first. MenuItemRenderFunction_0x20, the same callback in
Ghidra's other copy, already has BOOLEnum there. SliderRenderFunction is only used by MenuItemRenderFunctionUnion's
slider member, so nothing else changes. With it prepareAndRenderMenuItems is at reccmp 100.0%. Main's six slider
render functions take BOOL isDragged (five of them) or BOOLEnum (NewInvasion_RepeatSlider). ScrollbarRenderFunction,
the union's scrollbar member, gets the same type: every scrollbar render function on main takes BOOLEnum isDragged.
The scrollbar items are drawn through the slider member, and no .cpp uses the scrollbar member.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItem::prepareAndRenderMenuItems, from gynt's draft (ab38baa, 59.83%, and 95757c6, 59.8%, in his closed
sourcehold#256; restyled up to 71eb42a on his fork's archive/UI-MenuViews-development-second-pass and in 10280b1 on
reimpl/UI-Core-development), with these changes from the binary. While the build menu slides, an item outside the
menu area, or any item between 45 and 55 percent of the slide, returns without being drawn (the draft only zeroed
the blend strength there). The slider's clamp is written on its fields, the flag it passes is a BOOLEnum that
starts FALSE next to the thumb position (the previous commit makes the callback take it), and the range is written out
at each use (a local measures lower; the numbers are in the PR text). The picture's first index is main's GMFirstPictureIndex (the draft's
GMTotalPicturesProcessed isn't on main), and the gmDataIndex mask is a named local. reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Menu::handleMenuItems, from gynt's draft (b7ae11d, 14.41%, the ActiveMenuTab compare, 7672ad2, 14.4%, and
2e7d6fd, 19.8%, the infinite loop fixed, in his closed sourcehold#256; 20.8% in 10280b1 on his fork's
reimpl/UI-Core-development), rewritten from the binary as one for-loop over the items up to MIT_LAST_ENTRY with an
if/else chain on the item type. The draft's empty ifs are the returns the original has: on the current tab's stop
item, on MIT_STOP_HANDLING, during a build-menu slide while handling input, while a modal dialog is open, and when
an item's input callback asks to stop. The build-menu shift toggles between 0 and buildMenuItemsLeftShift_0x28, and
the switch sends both render passes to prepareAndRenderMenuItems. The item types and flags MenuItemType doesn't
name are local constants written as the bits they set, and the sign bit is tested with & (>= 0 measures lower; the numbers are in the PR text).
reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Menu::Constructor_Menu, from gynt's draft (8a20e11, 21.49%, and b357877, 21.5%, in his closed sourcehold#256; restyled up
to 71eb42a on his fork's archive/UI-MenuViews-development-second-pass and in 10280b1 on
reimpl/UI-Core-development), rewritten from the binary as one for-loop over the items: each item gets its menu
pointer, its UC index (or -1) and a cleared unknownZero; a tab counts its items up to the next tab, the end or past
a stop item; an interaction group hands its callbacks to members that have none, then does the same for each option
that follows it and marks itself an option group; and the item before a run of alternatives is flagged as its head.
The draft walked the items through a pointer offset by the position field (+4), reached ucIndex_0x4 through a cast,
and counted the members with GmDataIndex values; the counts are ints in itemsToSkip here. The flags MenuItemType
doesn't name are local constants written as the bits they set, as in handleMenuItems (0x004F6280, previous commit).
reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Menu::renderConstructionMenu, from gynt's draft (65e9021, 63.31%, and 1791e0a, 62.7%, in his closed sourcehold#256; 64.0%
in 10280b1 on his fork's reimpl/UI-Core-development, names in 7069ca9), rewritten from the binary. The hovered
item's text index is looked up in TextMessageLookupTable, and the message type is one switch: 0 returns, twelve
types show the text bottom-left with setBottomLeftTextDisplayText (most of them only with bubble help on) and each
clears zero and returns on its own, as the original does (with a break to one shared store: quick_diff 0.9559 ->
0.8475, as 0 no longer gets a register), and every other type shows the tooltip once the mouse has rested on the
item for 200 ms. The index is the dword's low word, read whole and masked as handleMenuElementsCallbacks does on
gynt's branch (*(int*)&this->textMessageLookupIndex); the ushort field_0x0 loads a word (the numbers are in the PR text).
Tab, view and message types are main's enum names where it has them (types 7 to 13 have none), and the tooltip's
colour is COL_C2F0EB. reccmp 100.0%.

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

Menu::renderConstructionMenu (0x004F64A0) switches on TextMessageLookupTable[index].messageType with cases for 0
(it returns at once) and for 7 to 13 besides the five named types, and matches at reccmp 100.0 with them; each of
the cases for 7 to 13 passes its own number on to setBottomLeftTextDisplayText as its message type. The enum has no names for
them, so they get <PREFIX>_UNKNOWN_<n> (TheRedDaemon's ask on sourcehold#300); setBottomLeftTextDisplayText starts its lookup
type at 0. Used in the next commits; code generation is the same.

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

BottomLeftTextDisplayState::setBottomLeftTextDisplayText (0x004F4E00) compares its fourth parameter with
TextMessageLookupTable[i].associatedType.buildingType and stores it in currentlyDisplayedUnktextExtraObject, so it
is the associated type of the text (a building, button or unit type, after TextMessageBLLookupStruct's union);
param_4 becomes associatedTypeUnk, as the definition calls it from the next commit on. Only the name changes.

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

- prepareAndRenderMenuItems' slider branch reads secondItemTypeData.scrollbarOrSliderState (minValue, maxValue,
  currentValue, dragTiming), main's names for the same four ints, where it read them through buttonState; the GM
  image line stays on buttonState. isDragged/thumbPos/thumbLength after main's render-function parameters, the
  set-up call's 1 commented, no (BOOLEnum) cast on clicked | hovering.
- renderConstructionMenu: TMBLLSTE_UNKNOWN_0 and 7 to 13 (previous commits) for the case labels, the union's
  buttonText and unitsAndWeaponsType for those two cases, TEXT_BUBBLE_HELP_TEXT and TEXT_GAME_OPTIONS for 8 and 74,
  and one line above the switch on why each case stores and returns.
- handleMenuItems: the sign bit as hiddenFlag, `continue` for hidden items and for items that aren't handled now
  (one level of nesting instead of three), parentheses around each && pair, no cast on the click handler, and
  `alternative` for the loop over alternatives.
- Constructor_Menu: the item before a run of alternatives is marked as its head (the old comment had it the other
  way round), and the unused UserControlID include goes.
- setBottomLeftTextDisplayText: associatedTypeUnk (previous commit), TEXT_PANEL_FEEDBACK and
  BFRE_NOT_ENOUGH_WORKERS for 77 and 1, TMBLLSTE_UNKNOWN_0, and MappersEnum's include and using go (they come with
  TextMessageBLLookupStructUnion.hpp).
- The comments keep only the reasons; the quick_diff numbers go to the PR text.
Kept, measured (quick_diff): renderConstructionMenu's second masking of the index and its two hoverTextX stores
(reusing index and one store: 0.9559 -> 0.8393 together; each alone in the next commit), Constructor_Menu's while over the options (a for:
0.8787 -> 0.6025), prepareAndRenderMenuItems' isDragged declared early (at its use: 0.9645 -> 0.7980), each with a
line in the code. Everything else is quick_diff-identical, and all five functions are reccmp 100.0 in a full build.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
renderConstructionMenu's second masking of the index and its two hoverTextX stores, and Constructor_Menu's while
over the options, say what the cleaner form measures, each alone, in main's one-line form: reusing index 0.9559 ->
0.8883, one hoverTextX store 0.9559 -> 0.9046, a for 0.8787 -> 0.6025. handleMenuItems no longer includes
MenuItemHandleState.hpp twice (Menu.func.hpp brings it); quick_diff identical.

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
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Style guide reading (advisory, posted once)

3 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 3 of the 5 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
9 Prefer for over while/do 1
18 Use the name, not the number 2
Where

Rule 9 — Prefer for over while/do

  • src/OpenSHC/UI/Menu/Constructor_Menu.cpp:65 — while-loop; the guide asks for a for

Rule 18 — Use the name, not the number

  • src/OpenSHC/UI/Menu/renderConstructionMenu.cpp:33 — hex constant 0xFFFF; use a name, or decimal
  • src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp:46 — hex constant 0x7FFFFF; use a name, or decimal

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>
@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 e5ddf37 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