Skip to content

Reimplement 2 UI::MenuItems functions (draft, below 100%) - #327

Draft
kotijekriv wants to merge 74 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-MenuItems-3-development
Draft

kotijekriv wants to merge 74 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-MenuItems-3-development

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Two UI::MenuItems functions below 100%, so others can continue from them (gynt's rule: ready functions in their own PR, the rest in a draft). Each status line says what is left.

Class Function Address Status line Measured raw Normalised Notes
InGameMenu MenuItemActionHandler_InGameMenu_UnitSelectionAndControlsUnk 0x004348D0 50.2% 50.2% 42.1% 18 returns and the range tests fixed; block layout and register allocation. gynt's draft (43.3% on his branch)
NewEventAction MenuItemActionHandler_NewEventAction_Main 0x004B9C00 97.4% 97.1% 91.1% inner switch in the original's order, no goto; scheduling. Rewritten from gynt's draft (93.4%)

Moved out of this draft at 100%:

This draft now has 3 files: the two functions and the status list. It has no header changes.

Measured.

  • Setup: built on main e086ba7 with the bundled MSVC1400-SP1, natively on Windows, against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a). The struct resolvers and these functions' own resolvers were enabled locally (not committed), and the comparison used sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • Narrow build: it ran on 942d855. The head, 2ab3c7d, only removes the text editor's file and its status line from that commit. UnitSelectionAndControlsUnk reads what its status line says. NewEventAction_Main reads 97.1%, 0.3 below its status line's 97.4%.
  • Not run in game.
  • Still to tidy: MenuItemActionHandler_InGameMenu_UnitSelectionAndControlsUnk still has decompiler names and gotos. NewEventAction_Main has no gotos, but still uses param_1.

Behaviour fixed compared with the drafts

Each one is read from the original's asm, and the commit body gives the address.

  • InGameMenu_UnitSelectionAndControlsUnk:
    • 18 returns the draft dropped are back: eleven empty ifs, the sync-status pair and the ends of five blocks.
    • Its six range tests are distance > limit, as the original compares them (0x00434E9E-0x00434EAA).
    • The draft's always-true test also wrote stray values into two flags it reads later.

Proposed, not changed here

  • setSliderParameters' destination is an int*.

The original's oddities, kept

  • InGameMenu_UnitSelectionAndControlsUnk calls getBuildingHasHealthProperty twice (0x00435B48, 0x00435B5A), and its engineer test uses US_JESTER_ROAM_TO (109).

🤖 Generated with Claude Code

kotijekriv and others added 30 commits November 5, 2026 01:32
…ests fixed; block layout and register allocation

gynt's draft (43.3% on his branch) with two fixes for the a521bf7 headers: setBottomLeftTextDisplayText takes an int as its 4th argument (the zeroed union local is gone), and Building's field at 0xC2 is field70_0xc2. The rest is the mechanical pass (decimal numbers, // comments, compound assignments, unused usings); quick_diff output identical. What is left is mostly block layout: 54 diff regions cover about 2000 of 2829 instructions. Behaviour fixes against the original's asm, which the draft still had: 18 dropped returns (the empty `if (...) {}` and five blocks that end in the original's epilogues or tail calls, e.g. 0x00434908, 0x0043492E, 0x00434C93, 0x00434CF8, 0x00436949); the six tactical-power range tests, where Ghidra's SBORROW had become an always-true compare (so a power was refused at every distance except exactly 2500 or 12544, and bVar15 / bVar16 got stray writes the function reads later), are `distance > limit` as the original's cmp / jle (0x00434E9E-0x00434EAA); and `extraout_ECX == 2` read an uninitialised local where the original's ecx still holds shiftRelated0or3 (0x004376E6). Mechanical: local_18 is an int, `+ TRUE` and the unitControlsRelated TRUEs are 1, `<= 200` / `<= 2401`, `--x == 0`, the shift as `shift ? 3 : 0`, and the decompiler's comments are gone. The `(-x & mask) + 2916` lines stay as they are: as a conditional they lose the match (0.5517 -> 0.4777 in quick_diff).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LobbyscreenStartButtonClick queues command 103 with the selected map's index as its parameter (button 105).
The draft wrote it as GCT_SHARE_GAME_STATE_PARTIAL_HASHES | GCT_MULTIPLAYER_ANNOUNCE_HOST (100 | 3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Used by the drafts in the companion development PRs: LobbyscreenStartButtonClick and CrusadeMap_Main play
sound 253 when they switch to the rankings screen. The LobbyscreenStartButtonClick draft wrote it as
SEID_UNIT_DAMAGE3 | SEID_ARROW_SHOOT (248 | 5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lobby's keep-position drag keeps the dragged player's position in DAT_00b95960 (-1 for none, compared
signed: cmp/jl at 0x00442A29) and its slot index in DAT_00b95f64 (an array index). DAT_00b95b74 is the map
description's height, used signed in the scroll limit.

General_MenuMiniMap reads DAT_00b95960 here; the other users are drafts in the companion PRs
(LobbyscreenStartButtonClick, MapEditorProperties_MainButtons, SingleplayerMapChoice_ButtonsAndHands). On main,
DisplayMapDescriptionAndAllocatePlayersToSlots stores to DAT_00b95b74 and compiles to the same instructions
with the int.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It is compared signed against 0 and 15 (cmp/jge at 0x00442683, jle at 0x0044269E). addChatMessageToDisplayList
and clearChatEvents, its users on main, compile to the same code with the int (quick_diff identical).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xes; block layout

Rewritten from gynt's draft (83.0%) as one switch: the original dispatches 105 and 413 with the table cases (cmp 0x69; jg; je; then the -201..4 jump table), so they are cases, not ifs before the switch, and the ~190 empty case labels are gone. Three behaviour fixes the original's asm shows:
- load game (1) and start game (4) return as soon as an occupied slot is not ready (je to the epilogue at 0x004426CA / 0x0044282B); the draft only left the loop and carried on;
- dropping a keep position (-201) ends with DAT_00b95960 = -1 on every path, and stops when no position is under the mouse; the draft's loop never ended in that case and skipped the reset after a swap.
Command 103 and sound 253 have names (header commits), DAT_00b95960 / DAT_00b95f64 / DAT_00b95b74 and chatScrollOffset are ints, which removes the casts. The swap's temporary is an int, as the original's movsx shows. quick_diff 0.7976 -> 0.9274. Left: block layout - the original places the shared epilogue right after case -1 and falls into it there; ours puts it elsewhere, which shifts most jump displacements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The TextEditor buttons render the label "Pic" (0x005A55E0, between "Link" and "ScrSize"), which had no entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… order, 3 behaviour fixes; scheduling

gynt's draft (77.3% here) with the switches rebuilt from the original's tables: the outer cases in the original's layout order (-1, -2, -4, -5, the 1..15/20 buttons, 31..36), the button labels as a switch on the button number itself (it was param_1 + 5), and the first field52 switch with case 10 after case 3. Three behaviour fixes: button -5 drew its label twice when not pressed (the original returns after the first text call, 0x0045DF3B). Case -4 is an if/else with one call per arm. The 1..15/20 arm keeps the original's test of -4, which never matches there; one comment line says so. The "Pic" label has a string entry now (its own commit). Left: case -5's and the colour copy's scheduling. Pressed buttons 32 and 34 (arms 2, 3, 10 and 12) no longer return after setting the colours: the original goes on into the field52 switch (0x0045E5F8 -> 0x0045E617) and draws the box and "NEXT" (0x0045EAFA -> 0x0045EB0D). The no-op casts on DAT_Button* and textColor are gone, 255 is COL_0000FF, the alignment codes are plain numbers, and the "Back", "Exit" and "Pic" texts are commented (identical code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
InGameMenu_MainButtons plays sound 257 when it opens the pause menu, and 123, 124, 125, 126, 127 and 128 when
it opens the build menu's tabs 10, 20, 30, 40, 25 and 28. The draft wrote most of them as ORs of unrelated
sounds (SEID_SIEGE_EQUIPMENT_DESTROYED | SEID_INN is 124).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From gynt's draft (86.3% here). reccmp's raw 99.8% differs only in the target of the tail call to confirmAndQueueDestructionCommand; normalized 100.0%.

The chain tests -1/-6 last (if (button != -1 && button != -6) ... else ...), as the original lays it out. Four behaviour fixes the original's asm shows:
- pause button in siege-editor mode: the original returns after switching to the siege view (0x0044513E); the draft fell through and also opened the pause menu;
- skirmish/scenario end (-5): the scenario-description path also switches the view and closes the three modal dialogs (the draft returned early);
- buttons 71..79 in the editor or siege-editor mode clear DAT_StopHandlingMenuItems and return (0x00444ECC to 0x00444D60); the draft carried on into the menu switch;
- closing the building help with those buttons carries on into the menu switch (call at 0x00444EE9, no return); the draft returned.
Sounds 123-128 and 257 have names (header commit), the editor slot index is one local, the nine player-ID clears are a loop, and the keep-and-granary test calls its checks inline instead of through temporaries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er and store order; register allocation

gynt's draft (83.3% here) with the -1 and -2 arms as the original lays them out: the repeat clamp in case 4 falls through into the minimum check (no early return), the minimum clamp stores the value first, both arms write case 7 out (the original shares one block between them, so the goto into -2's case 7 is gone) and -2's case 7 comes before case 4. The minimum, maximum and current values are stored in the original's order in -2's cases 1-3 and in the action arm's case 1 (stores through the three pointers keep source order). quick_diff 0.7797 -> 0.8373. Left: register choice in the -2 arm, one byte longer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SelectCrusade_Main clears the menu tab to switch to with 0 (no tab), and MissionEndscreen_Main stores 0 into
the active tab. The ChooseNetworkServiceProvider_Buttons draft in the companion development PR uses it too.

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

The map editor compares the active brush and the affect type signed (jle at 0x00431563 and 0x004315E3, jge
at 0x004317D3) and halves the brush with sar. switchToMenuView on main and InGameMenu_MainButtons here compile
to the same code (quick_diff identical); the other users are drafts in the companion development PRs
(MapEditorLandscaping_GeneralButtons, MapEditorLandscaping_QueueCommandCallback).

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

gynt's draft (81.1% here) as one switch without gotos: AREA_BACK is a case of it (the original dispatches it next to the table, cmp 0x14b; je), AREA and AREA_BACK each write their brush step in full, and every big-rock case writes its odd-brush adjustment itself; MSVC merges the rock cases' identical tails again, as the original does. The brush, its half-size and the affect type are ints (header commit), so the compares are signed as in the original. quick_diff 0.7430 -> 0.8145. Left: the original shares one brush store between AREA's and AREA_BACK's adjustments (cross-jumps between the two cases); written out per branch, ours stores in each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sound 146 is the menu buttons' hover sound: NewMapMapsize_Buttons and NewMapMaptype_Buttons play it when the
cursor moves onto another button, and so does the HistoricCampaignSelect draft in the companion development
PR. 251 has no user in these PRs: the main menu render function, which is not in them, plays it when the
cursor first moves onto button 5. The drafts wrote them as SEID_CHILDREN_PLAY_MAYPOLE | SEID_WOOD_CHOP
(144 | 2) and SEID_UNIT_DAMAGE3 | SEID_WOOD_SAW (248 | 3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (94.0%). The original returns as soon as a modal dialog is open (call, test, jne to the epilogue before any register is saved) and reads the button position afterwards; the draft read the position first and wrapped the body in an if. The position loop is a for loop instead of do-while, the locals are named (keepX, drawX, player, playerIndex) and the casts are gone: the fields are already char and int. Raw 98.5%: only the type name in the symbol of DAT_00b95960 differs (int here, unsigned int on the original side), the address is the same; normalized 100%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (89.1%). One behaviour fix the original's asm shows: in case 5 the original opens the quit dialog only when INT_00b95f68 is set, and otherwise only switches to the custom scenarios menu; the draft opened the quit dialog on both paths. The player slot is read once into a const local, as the original keeps it in a register for every playerDataArray store, startResources is indexed by RT_GOLD / RT_STONE, and the map name is STR_Mission22Map from string-literals.hpp. Left: the original loads ecx for importTradingCosts after the three playerDataArray stores, ours before them; reordering the stores around it made it worse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DAT_TutorialCurrentStep and DAT_00df5554 are compared signed everywhere the original reads them (jl / jle in
the tutorial box handler), so they are int, like DAT_00df5558, DAT_00df555c and DAT_00df556c, which main's
header sync 7c6bb9e already has as int; that removes the casts in the tutorial box handler. Their other
users compile to the same instructions (only the resolver symbols' type changes): GetCurrentTutorialStep on
main and the tutorial box render function here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (88.0%, the same code). Named locals (traderIndex, resource, icon, imhIndex), GM_INTERFACE_ICONS2 for the GM index, early returns, no casts. The draft's comment on the second text said "On"; the game's text table has 173 as "Off". Left: register allocation in the text position sums; the compiler normalises the operand order, so no spelling moves it.

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

Rewritten from gynt's draft (95.6%). One behaviour fix the original's asm shows: a crusader or arabian button that is not the current choice falls back to the default button render (jne to the RenderScenarioButtonWithText call); the draft fell through into the bandits case and drew it as a bandits button. The highlighted text is chosen by if/else around one call each, which MSVC merges into the original's single call with a branch on the colour push; a ternary compiles branch-free instead. The " - " string is s___005a2304 from string-literals.hpp, COL_CCFAFF names the highlight colour. Left: register allocation around the name width.

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

Rewritten from gynt's draft (96.8%). Two behaviour fixes the original's asm shows: the month button (-1) returns after drawing its text once, in the plain or the highlight colour; the draft drew the plain text and then the highlighted one over it. An invader button whose choice matches returns after drawing; the draft also fell into the default button render. The draft's comment "Crusader. Arabian. (...)" is replaced by the list of invaders the buttons stand for (cr.tex: rat, snake, pig, wolf, other, crusader, arabian). Left: one register choice in the invader text call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…al's order, no goto; scheduling

Rewritten from gynt's draft (93.4%). The inner switch has its arms in the original's order (50, 100, then 10 falling into the slider set-up) and returns from default instead of jumping to a label. The second column's buttons adjust param_1 itself and a copy drives the inner switch, which is how the original keeps them (edx and esi); the slider value and destination are read in place rather than through a local pointer; the popup delay is stored first, as in the original. The pointer to the event type stays: without it the match halves. Left: one store scheduled differently and an lea / add choice.

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

Rewritten from gynt's draft (96.9%). The draft computed the speech file name as a raw address (counter * 0x60 + 0xb3d810); it is MissionAestheticsDefinedData::field112_0x41e4[counter], a char[3][32] per entry. Taking a pointer to the name before the counter is incremented matches better than indexing in the call. The hand-written security cookie is gone (the compiler adds it for the char buffer), the tutorial counters are ints (header commit), early returns, and the player slot is read inside the step-14 test, as the original does. Left: the order of two loads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The old title menu's exit button renders the label "Exit" (0x005A22D0, between "FireFly's" and "Continue"), which had no entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The AI lord select handler queues command 112 with the slot it filled as its parameter, after a lobby AI is added
(111 is GCT_SKIRMISH_ADD_AI_PLAYER). The draft wrote it as GCT_SEND_RESYNC_TILEMAPDATA2 | GCT_LOAD_MAP_HEADER (64 | 48).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (95.3%). One behaviour fix the original's asm shows: when no slot is free the original closes the dialog and returns (0x004AE82B); the draft's while loop reset the dialog but kept going past slot 8. The free-slot search is a for loop with a break, and the occupied-slot count a for loop that MSVC unrolls into the original's eight tests (writing them out by hand gives the same code). Command 112 has a name (header commit) instead of GCT_SEND_RESYNC_TILEMAPDATA2 | GCT_LOAD_MAP_HEADER.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (98.0%). One behaviour fix the original's asm shows: the larger font is for French, Italian and Spanish only (an unsigned range test, cmp 2 / ja); the draft's signed `gameLanguage - GL_FRENCH < 3` also took English, American and German. Written as GL_FRENCH <= language <= GL_SPANISH, which MSVC compiles to the same test. Sound 146 is SEID_UNKNOWN_0x92 (header commit), the text comments come from cr.tex, early returns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt's draft (97.3%) passed the literal "Exit", so reccmp saw our own copy of the string; with the string's entry at 0x005A22D0 (string commit) it is s_Exit_005a22d0 and the function matches. Also COL_0000FF for the text colour and no casts; the button width passed as the alignment stays, with a comment, because the original does that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (98.7%, the same code): early returns, the branches in the original's order, sound 146 as SEID_UNKNOWN_0x92, the campaign names from cr.tex. Left: the original loads ecx for getTextStringInGroupAtOffset between its two pushes; ours after them. No spelling of the text index or the position moves it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (98.4%, the same code). The draft read SEC_MercRecruitable[param_1 - 7], a negative index; the address is barracksRecruitability.array.barracksRecruitability[param_1], as the handler for the same screen reads it. Early returns, `param_1 >= 0 && param_1 <= 7` instead of the unsigned cast, COL_CCFAFF, no casts. Left: one push 0 that the original schedules before the sar of the text position.

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

With the bandits text's position read into y-then-x locals inside each colour path, the function reaches 100.0%
(96.8% here), so it moves to the round 11 PR (reimpl/UI-B-round11-100, 69a3ba2). This draft drops it, and its
status line goes back to main's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HistoricCampaignSelect's render (0x004255D0) goes from 98.7% here to 100.0% in the round 13 PR
(reimpl/UI-B-round13-100, b607ec8): the campaign name is drawn by two identical calls, one per hover state, which
gives the original's load order for the text call. This draft drops its .cpp file, and its status line goes back to
main's. Main doesn't have the function, and this draft changes no header, so nothing else goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv and others added 4 commits November 17, 2026 05:06
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…etMarker

Main's Ghidra sync (1b36c0a) named Building's field at 0xC2 targetMarker, a BuildingTargetMarkerShort. The draft
stored 2 into field_0xc2, which is BTM_ENGINEER_TARGET; it now says so. quick_diff 0.5332 on main e086ba7 (the
draft did not compile there before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 33 TextEditor keyword and button strings are the s_ pointers from string-literals.hpp instead of the S_
macros, cast to char* for renderText's parameter as elsewhere on main. quick_diff gives the same instructions as
before (0.9743).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_General_EventSlider (0x004B9E50) reaches 100% (two comparisons with their operands the other
way round, and case 7 before case 4 in the repeat slider's switch). It goes out with the ready PR built from
reimpl/worker-C-ui-100, together with the header commit it uses (IngameInvasionEventItemContent has an int at
0xA4). Its file leaves this draft and its status line goes back to main's.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
MenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClick (0x00442640) reaches 100% (1d1afa8 on
reimpl/UI-B-round17-100: one draw-buffer store after the launch, the keep position's x read with no local, and the
map index of case 105 through a local declared before the switch). It goes out in the ready PR of round 17. Its file
leaves this draft and its status line goes back to main's.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@kotijekriv kotijekriv changed the title Reimplement 7 UI::MenuItems functions (draft, below 100%) Reimplement 3 UI::MenuItems functions (draft, below 100%) Nov 19, 2026
MenuItemRenderFunction_TextEditor_Buttons (0x0045DE40) reaches 100% (aeff76c on reimpl/UI-B-round18-100, after
be046d5, which makes ColorUnion 2 bytes: case -5 as an if/else with one return, case 32's help text nested in the
render call, cases 35 and 36 as one-case switches, and case 32's colour stores in the original's order). It goes out
in the ready PR of round 18. Its file leaves this draft and its status line goes back to main's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kotijekriv kotijekriv changed the title Reimplement 3 UI::MenuItems functions (draft, below 100%) Reimplement 2 UI::MenuItems functions (draft, below 100%) Nov 19, 2026

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