Repository navigation
Reimplement 2 UI::MenuItems functions (draft, below 100%) - #327
Draft
kotijekriv wants to merge 76 commits into
Draft
kotijekriv wants to merge 76 commits into
kotijekriv wants to merge 76 commits into
Conversation
…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>
This was referenced Nov 11, 2026
…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>
This was referenced Nov 13, 2026
Merged
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>
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>
This was referenced Nov 17, 2026
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>
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>
…ck layout left UnitSelectionAndControlsUnk, gynt's draft (fec9af4, 43.34% on his branch; as of f6c6b8b, his newest on reimpl/UI-MenuItems-development) as restructured on this branch (b4889c1, 50.2%), with more of it in the original's shape. The function's logic is his; this changes its shape, names and order. It reads 57.2 raw and 54.5 normalised (from 50.2 / 42.1). Each change was measured on its own in real builds and kept only where it gained; together they give the number above. 1. The tactical power's range test (shiftRelated0or3 == 4) is written the way the original runs it: - two block-local bools, out of range and checked, kept in bytes on the stack (0x00434E33, 0x00434E38); - each range test as two nested ifs, so the compiler shares the cmp's jle and the store of the flag (0x00434E9E..0x00434EAC); - the enemy keeps as a plain loop over players 1 to 8, which the compiler unrolls four times as the original does (0x00434FC9..0x0043531F), instead of the draft's hand-unrolled copies. - the tactical command when the left button goes down first, the floating number otherwise (0x00434F7B). 2. Tests the draft had the other way round, now in the original's order: - the attack-unit test, the engineer test after it, and the test inside that (0x004355F9, 0x00435866, 0x004358A6); - inside the attack-unit branch, the unmanned siege engine first (0x00435695), and the carrying engineer (0x00435802); - in the hit-box loop: the building part inline and the attack-unit branch as the else (0x00435E37), the carrying engineer's 50-tile box first with the sizes pushed directly (0x00435E05..0x00435E22); - shift-click on a selected unit first (0x00435423); - the left button held before the drag-stopped case (0x0043776F); the drag-box call at 0x004377DC has no second store of menuSwitchDelay, as the original. 3. The move-to loop (0x00436992..0x00436C74) has its own flags, as the original's slots show: second pass, can reach and can move. Can reach is set by an if (0x00436A3D), can move is cleared with it when the tower tile is full or no unit can move, and the mixed-assault target tile is computed before its test. After the loop the reach test comes first and the no-entry cursor last (0x00436B53..0x00436C31). 4. Smaller ones: the siege tab chosen with a plain if / else (0x00434C13..0x00434C2D); the siege engine's unit read inside its block (0x00434CA5); the animation time stored first (0x00434991); the final switch on the cursor state in case order -1 .. 4, each case ending in a break (0x0043782C..0x004378A3); the command switch reads the clicked building into a local where the original does (0x004370DB, 0x004374DC), with the pitch-ditch test the original's way round (0x00437504), and passes setRallying to every SetTribesPatrolButtonPressed call (0x00436FEB ..). 5. The command switch in the original's order: - with the shift key, the rally point first and the plain move command after it (0x004372AF), and inside the rally the patrol button pressed first (0x004372C8); - pending command 4 (exit the siege equipment) right after 3 (0x00437171); - pending command 11 sets unitControlsRelated itself and jumps past that store (0x00436FFD), as case 20 does (0x00437662); - in case 5 the building command for pending command 1 inline, the attack-land command after it (0x004374CF); - each command plays its speech with its own constant (0x00437130, 0x0043716A ..), the compiler sharing only the call (0x004376A4); - the outer cases in the original's layout order, 22 before 20 (0x004375E4, 0x0043765D). 6. The decompiler's names are gone: the locals (uVar1, BVar8, local_20 ..) and the labels (LAB_0043782c ..) have names that say what they hold or what follows them, and four locals nothing used any more are gone. The enemy-keep loop's bound is countof(playerDataArray). The gotos stay for now: they are the draft's way to share code the original shares, and the layout depends on them. 7. The file goes on /GL: the original compares ecx with 2 right after the call to SetTribesPatrolButtonPressed (0x004376E6). Only with /GL does the compiler know that call leaves ecx alone, and nothing else in the function changes. Tried and left out, each measured: the range switches' cases in the original's layout order (48.2), the ladder / siege tower / climb tests the other way round (50.1), setting lordMayAct by an if (-0.5), the building attack range moved into the attack-ground block (53.8), that block's building test first (52.9), unitControlsRelated == 5 tested first (raw down on the bases we tried, normalised up to 54.0), a volatile setRallying (55.2), the move-to loop's flags as the same variables as the unit part's, as the stack slots suggest (57.0), the game mode read once for the lord checks (-0.4). What is left: the register allocation of the constants. The original keeps the zero in ebx at the entry and 1, 61 and 107 in ebp, ebx and esi (0x004349D1; from 0x00436D90, 107 and 1 in ebx and ebp); ours chooses other registers, and the stack slots and the merging of the SetTribesPatrolButtonPressed calls follow from that (ours keeps setRallying in ebx, the original reads it from the stack at every call). And block layout around the goto labels the draft still has. Measured with real builds of our units stack's head (every header this file includes is the same there as on this branch's head 2ab3c7d, apart from Unit::disappearFadeAlphaCountdown's type, which the file does not use), the file in the build list on /GL, with SetTribesPatrolButtonPressed and SomeUnitAndViewportCheck in the list (both 100.0): 57.2 raw and 54.5 normalised. The draft read 50.2 / 42.1 in the same narrow build, off /GL as it was. Off /GL this text reads the same to one decimal, with the line at 0x004376E6 differing. Not run in game. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dAttackCommand4Params Main's Ghidra sync be552cd types the second parameter of UnitsState::queueDisbandAndAttackCommand4Params as UnitInstructionType (it was undefined4), so this handler's five calls, four with a plain number and one with the command type variable, no longer compile (C2664). They name the instructions now: 34 UIT_LIGHT_PITCH, 15 UIT_CONSTRUCT_SIEGE_EQUIPMENTOIL_DUTYENGINEERRELATED, 16 UIT_MAN_SIEGE_EQUIPMENT, 20 UIT_THROW_OIL, and the command type variable is cast to UnitInstructionType. The names compile against main's previous declaration too. No other change. Measured: quick_diff gives the same listing as the pushed head's text, with main 0e4a83b's headers and with be552cd's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Nov 24, 2026
…list's header and the mission rows (sourcehold#423) * reimplement: SHC_3BB0A8C1_0x00442640 100.0% Reimplemented LobbyMenu::MenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClick, from gynt's draft (c0a2f52 at 40.85% on his fork's development; c88d7a2 at 40.8% on upstream's reimpl/UI-MenuItems; f53ef94 to d81f02f, 54.93% to 69.03%, his fork's reimpl/UI-MenuItems; a4fb7c2 of 2026-10-28 on his fork's reimpl/Wilps-2026-10-18; 99cb905 at 80.53%, 35aef55 at 80.71% and dd1a7c4 of 2026-11-02, his newest commit on the file, on his fork's reimpl/UI-MenuItems-development) and our cb601a0 and 1918de9 in draft sourcehold#327 (90.7%). 90.3% -> 100.0% on main 3458fea: - case 4 sets the draw buffer back once, after the if / else that launches the game: the original pops three registers before that store in the skirmish arm (pop esi / pop ebp / pop ebx / mov / pop edi / ret); - the two keep-position loops read keepPositions[position].x where they use it, with no local, which gives lea ebp, [eax + edi + 572] with x as the base (a local gave [edi + eax + 572]); - the map index. Case 4 writes its two sums as DAT_MapSelectionScrollOffset + DAT_MapSelectionRelativeSelected, and case 105 takes its index through a local that is declared before the switch. That gives both cases the original's two loads and add (0x0044284E: edx, eax, add eax, edx; 0x00442AD8: ecx, edx, add edx, ecx). The three sums are coupled: of 32 combinations (each case's sum written out, as a block-scope local or as this local, in both operand orders) only this one and its twin with case 105's operands swapped match. A block-scope local in case 105 swaps case 4's loads, which is why the declaration stands before the switch, with one comment line. The local starts at 0, which nothing reads: declared without a value, style rule 24 asks for it in case 105, and the code is the same either way. quick_diff reads 0.9956: its two lines are a tail jump it prints as a label and the jmp over the first loop's alignment padding; it cannot see the load order, since it prints both fields as [G]. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00492DE0 100.0% Reimplemented SaveLoadMap::MenuItemActionHandler_SaveLoadMap_TableHeader, rewritten from the binary with gynt's draft for the names (f788afb at 17.2% on upstream's reimpl/UI-MenuItems; 54e57c4 and 21d4dcf at 47.81% and 49.40% on his fork's reimpl/UI-MenuItems; 8725ec5 at 49.4% on his reimpl/UI-MenuItems-development, his newest reimplement commit on the file). reccmp 100.0 (normalized 100.0) on main 3458fea with the data and its own function resolver on; the draft reads 47.8 there. The array index changed with the header. gynt's draft uses DAT_ArrayOfMapIndices[i - 1] and [i], which was right on his branch, where the array is declared at offset 0x884. Main's sync 12854bc (2026-11-04) moved the declared start to 0x880, so the original's 0x01126E28 and 0x01126E2C are [i] and [i + 1] here. - The order store is in each arm and previewedListIndex = -1 is written once after the if / else. MSVC copies that store into both arms, after the last pop, as the original has it; only the order store sits between the pops. Written in each arm, it keeps -1 in ebx and pushes ebx at the top, and the first sort's two loops lose their alignment padding. - The swap reads the moved element into a local inside the if. With both elements in locals before the test they land in each other's registers. - fileListEntryCount is read in the loop condition: the original reloads it after each swap's stores. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004269E0 100.0% Reimplemented HistoricMissionSelect::MenuItemRenderFunction_HistoricMissionSelect_MissionRows, rewritten from the binary with gynt's draft for the names (298b3af at 20.6% on upstream's reimpl/UI-MenuItems; 633d784 at 41.41% on his fork's reimpl/UI-MenuItems; 626fd68 at 44.53% on his reimpl/UI-MenuItems-development, his newest reimplement commit on the file). reccmp 100.0 (normalized 100.0) on main 3458fea with the data and its own function resolver on; the draft reads 45.3 there. Behaviour: a mission not reached yet is drawn as a greyed cell and the function returns (0x00426A53). The draft went on and drew the number and the name over it. - The number and the name are written in each of the three arms, and DAT_ButtonUnknownZero = FALSE once after them: MSVC hoists the arms' common pushes and shares the tail, as the original has it. - The number's position is written out in each arm; with locals for it the two loads come in the other order. - In the selected arm the name's position and index are read into locals before the nested call, Y, X, then the index, which gives the original's registers for that call. - The locked test compares (int)(DAT_00b96100 - row - 1): the global is an undefined4, and the original's jle is signed. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: DAT_00b96100, DAT_00b95b2c and the file list's sort order are ints, and a FileListSortOrder enum DAT_00b96100 is the first mission of the historic campaign the mission list shows (1, 6, 11 or 16), and DAT_00b95b2c is that campaign's index (0 to 3). MenuView_HistoricMissionSelect_Prepare (0x00426830) picks the campaign from missionNumber1to20 and stores the index and index * 5 + 1 (0x00426879 / 0x0042687E and the two other arms). The mission rows compare DAT_00b96100 - row - 1 with that campaign's progress signed (jle at 0x00426A22), so DAT_00b96100 is an int, and DAT_00b95b2c, an index from 0 to 3, is one with it. Their data.asm symbols follow in the next commit. MenuTextInputState::fileListSortOrder holds one of four orders of the load / save file list, and the three savedListSortOrder fields hold copies of it; all four are now int. The values get names in a new FileListSortOrder enum: 0 by name, A to Z, as discoverMapFiles sorts the list, 1 Z to A, 2 by file time newest first, 3 oldest first. The table header's four sorts end in those values (0x00492FA2, 0x00492F69, 0x00492F25, 0x00492EB5). Only the table header includes the enum: included by MenuTextInputState.hpp, which many files include, its declarations swap two registers in LobbyscreenStartButtonClick and LaunchSinglePlayerGameUnk. Header changes only. The users on main 48f7e94 and on this branch compile to the same code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * data: DAT_00b96100's and DAT_00b95b2c's symbols as ints data.asm names the instances at 0x00B96100 and 0x00B95B2C with the int type (H instead of I), as it does for main's other int globals, to go with the header commit before it. The Extern symbol's name carries the type, so a build with their struct resolvers off links only with both commits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MissionRows and SaveLoadMap's table header use the new types and names MissionRows tests DAT_00b96100, now an int, without a cast. The table header writes its sort orders as FileListSortOrder names, and its first switch's labels too: that switch is on -1 - button, the order the handler ends in. The listings are the same: narrow builds of this branch's files and of every user of the two globals and the four fields read 100.0 raw and normalised, with no diff line, before and after, and so do a full build of the branch merged with main 48f7e94 and narrow builds of these two files in their final form. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * HistoricMissionSelect uses the two globals' new names Main's header sync named DAT_00b95b2c and DAT_00b96100 INT_00b95b2c and INT_00b96100. The mission rows, and main's General handler and Prepare view, include the new headers and use the new names. Main's two files have not compiled since the sync without this. The code is otherwise the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Nov 24, 2026
…rcehold#426) * headers: ColorUnion is a short The 18 colour globals (COL_BLACK 0x00DF33D0, COL_WHITE 0x00DF338C and the rest, 0x00DF338C..0x00DF33F0) are only ever accessed 16 bits wide in the original: every instruction that names one of their addresses is a word mov, movzx, movsx or cmp, or a word store (COL_BLACK = 0 at 0x004678A3, COL_WHITE = 0x7FFF / 0xFFFF at 0x004678C9 and 0x0046792E), and none of the addresses is ever taken. The int member had no reader, and with it the union was 4 bytes, which lets MSVC widen a hoisted read of shortValue to a dword load: MenuItemRenderFunction_TextEditor_Buttons reads COL_BLACK with `mov ecx, dword ptr` where the original has `mov cx, word ptr [0xdf33d0]` (0x0045E5EF). ColorContainer, which holds one ColorUnion and is not used anywhere else, shrinks with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0045DE40 100.0% Reimplemented TextEditor::MenuItemRenderFunction_TextEditor_Buttons, from gynt's draft (d7366c2 at 62.8% on upstream's reimpl/UI-MenuItems; be19b2c at 74.93% on his fork's reimpl/UI-MenuItems; 140055c at 75.94% on his reimpl/UI-MenuItems-development, his newest reimplement commit on the file, with the string literals of his 0e551f6) by way of the sourcehold#327 draft (020b8de, 91.5% on main 3458fea). reccmp 100.0 (normalized 100.0) on main 3458fea plus the previous commit, with the data and its own function resolver on. The sourcehold#327 draft's work is kept: the switches are in the original's table order (-1, -2, -4, -5, the 1..15/20 buttons, 31..36), the button labels are a switch on the button number itself, and the first field_0x23970 switch has case 10 after case 3. Case -4 is an if/else with one call per arm, a change of shape only: gynt's draft renders once per path with the same arguments. So are its three behaviour fixes against gynt's draft: - button -5 drew its label twice when not pressed (the original returns after the first text call, 0x0045DF3B); - pressed button 32 returned from its pressed-colour arm before the field_0x23970 switch; the original goes on into it (0x0045E5F8 -> 0x0045E617); - pressed button 34 returned from the same arm inside its field_0x23970 cases 2, 3, 10 and 12; the original goes on and draws the box and "NEXT" (0x0045EAFA -> 0x0045EB0D). From 91.5 to 100: - Case -5 writes the two "Exit" calls as an if/else followed by one return. The original keeps a full copy of the call in each arm (0x0045DF3B and 0x0045DF6E, each with its own `pop esi; ret`); with a return inside the first arm MSVC merged the second arm into the first copy. - Case 32's arm 2 passes getHelpSectionText's result straight to renderTextToScreen. The original pushes the render call's other arguments first and calls getHelpSectionText last (0x0045E710, then 0x0045E71B); the locals the decompiler had for the text and the position are gone. - Cases 35 and 36 test field_0x23970 as a switch with the one case 1: the original has `sub eax, 1; jne` (0x0045EBA5 and 0x0045EC39), which is what a one-case switch compiles to, where `== 1` gives a cmp. - Case 32's colour block was the last two instructions. Each arm stores otherColorUnk_0x0 before textColor, which gives the original's copy into ax (`mov ax, cx` before the textColor store at 0x0045E60A, where we had `movzx eax, cx` after it). COL_BLACK's word load before the branch (`mov cx, word ptr`, 0x0045E5EF, where we had `mov ecx, dword ptr`) needed the previous commit: with a 4-byte ColorUnion MSVC loads it as a dword. Each change alone leaves the other instruction. Readability, with identical code: param_1 is `button`, as in 28 of the sibling handlers; the four textColor ternaries of cases 33 to 36 are if/else; the (ushort) and (uint)(ushort) casts on DAT_PointerToTemporaryTextMemory are gone (it is an LPWSTR, already unsigned 16-bit); the 15 (char*) casts on the s_ strings passed to renderTextToScreen are gone (it takes a char const*; the 18 for renderTextToScreen2, which takes a char*, stay); and the unpressed text colour of the 1..15/20 buttons is COL_000000. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Gynt <gynt@users.noreply.github.com>
6and8
pushed a commit
to 6and8/OpenSHC
that referenced
this pull request
Nov 24, 2026
…cehold#327/sourcehold#328, with one header commit (100%) (sourcehold#410) * headers: MenuModalComposition's slider minimum and maximum are ints sliderMinimum and sliderMaximum were dword. The original treats them as signed: the OverlaySlider handler (0x004AA600) tests `sliderMaximum - sliderMinimum > 200` with jle (0x4aa630, 0x4aa697, 0x4aa7a3) and divides by 5 signed (0x4aa635, 0x4aa6c4). With the fields as int the handler measures 100.0 instead of 57.1 (reccmp, main 1d819b7; the same again on 3416498). The only other users of the two fields, setSliderParameters and setSliderParameters2, only store to them, so they compile the same. sliderValue stays dword: the original only copies it, and the handler compiles to the same code either way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004AA600 100.0% Reimplemented MenuItemActionHandler_OverlaySlider_Slider, from our own drafts at 89.8% and 91.5% (local, never pushed), themselves rewritten from gynt's draft (593c4ef at 47.37% on his fork's reimpl/UI-MenuItems-development; his last style pass on the file is f6c6b8b). It needs the slider minimum and maximum as ints (the MenuModalComposition header commit before this one); with them reccmp reads 100.0, normalised 100.0. The fix: case 1 stores the current value once, after the large-range and small-range branches, rather than at the end of each. MSVC then gives the small-range branch the original's scratch registers, and case 2 and 3 follow (the store in each branch measured 91.5). Case 7 tests `*currentValue > *maxValue / 2` for the step of 1, which gives the original's setle. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004255D0 100.0% Reimplemented MenuItemRenderFunction_HistoricCampaignSelect_Main, from the draft sourcehold#327 (reimpl/UI-MenuItems-3-development, 90d1284 at 98.7%; the file's newest commit on the draft is 446f9fa), itself rewritten from gynt's draft (d07873b at 97.44%, after his 61351fe at 82.1% and 245178b at 94.87%; on his fork's reimpl/UI-MenuItems-development the function is 04f12f8 at 67.10%, his newest reimplement commit on the file is 8725ec5 and his last style pass 5084980). reccmp 100.0, quick_diff 78/78 at 1.0000. The last difference was the getTextStringInGroupAtOffset call loading ecx after both its pushes, where the original loads it between them. The campaign name is drawn by two calls that are the same, one per hover state, each with the position read into `int const textY` then `textX`: MSVC merges them completely and keeps the original's order. It is the same form as in MainMenu's render (0x00424F50), the sibling this function was copied from. The early returns, the branch order, the sound ID SEID_UNKNOWN_0x92 and the campaign names from cr.tex were already in the draft. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00492FD0 100.0% Reimplemented MenuItemRenderFunction_SaveLoadMap_TableHeader, from gynt's draft (78de101 at 97.44% on his fork's reimpl/UI-MenuItems, after his 0747a3c; on his reimpl/UI-MenuItems-development the file has 2002473, and his newest reimplement commit on it there is 8725ec5; quick_diff 0.9744 on main). reccmp 100.0, quick_diff 39/39 at 1.0000. The draft's only difference was the getTextStringInGroupAtOffset call loading ecx after both its pushes, where the original loads it between them. As in HistoricCampaignSelect's render (0x004255D0, earlier on this branch), the header text is written as two calls that are the same, one per hover state, each with `int const textY` then `textX`: MSVC merges them completely, leaving no branch, and keeps the original's order. Position locals alone measured the same as the draft. The column switch and its text numbers were already gynt's ("Name", "Date" and "Mission" in TEXT_GAME_OPTIONS); the colour is COL_CCFAFF, the font size 18, and the parameter is the column. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004D8EC0 100.0% Reimplemented MenuItemActionHandler_CrusadeMap_Main, rewritten from the binary. It starts from gynt's draft (00e21e3, 59034df and 98dc115 on his fork's reimpl/UI-MenuItems, 33.48% there; 3d6fb54 at 34.80% on his reimpl/UI-MenuItems-development, his newest reimplement commit on the file) and our mechanical pass of it in sourcehold#328 (2d468df, 35.2%). reccmp 100.0 (normalized 100.0), quick_diff 215/215 at 0.9907, the rest being the timeGetTime import call, which reccmp resolves. The buttons are Skip Current Mission (1000), the lord's face for the mission briefing (10), back to the choice of crusade (11), a click on the map (1) and the rankings (99), in the original's block order with early returns. What the match needed: - Skip Current Mission repeats the setStartDateUnk call and everything after it in each trail's branch. MSVC merges the three copies into the first one, as the original has them, and the constant 1 then goes to ebp; one call after the trail branches, or a switch on the trail type, measured 0.9395 and 0.8419. - The click test reads each position as `left = x - 10` and `top = y - 10`, compared with `left + 20` and `top + 20`, which is how the original computes both bounds (0.6075 with x - 10 and x + 10). Fixes against the draft: - The first edition and extreme trails tested the click's y the wrong way round (Ghidra's `y + -clickY >= 10`, that is clickY <= y - 10, where the original tests clickY >= y - 10), so a mission could only be picked by clicking above it. - The warchest and extreme searches went one mission too far (`> 30` and `20 <`), reading one position past the end of the warchest table; the original stops below 30 and 20. Cleanup: a click wrote all three trails' progress back, two of them unchanged; the original stores only the trail being played. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00444410 100.0% Reimplemented MenuItemActionHandler_General_ToolbarButtonPressed, from gynt's draft (d2993ae, 6e17808, 8a21939 and b984b98 on his fork's reimpl/UI-MenuItems, 65.02% there; a1c4156 at 67.59% and 9dc4216 at 67.74% on his reimpl/UI-MenuItems-development, 9dc4216 being his newest reimplement commit on the file) and our own draft in sourcehold#318 (c00f64a at 71.40% on reimpl/batch2-development), rearranged from the binary. The function leaves sourcehold#318 with this commit. reccmp 100.0 (normalized 100.0). quick_diff reads 0.8939 because it stops the original after the siege-engine case. On main the draft needed only renames to compile: buildingEntryInfos for the eight building references, unitIDSelectedCatapultOrTrebuchet and field_0x30. What the match needed: - The switch cases in the original's block order. The siege engines (with the Arab ballista) and the tunnel are plain cases that break to the code after the switch, and the three stances each make their own call (quick_diff 0.6693 -> 0.7085). - The eight building buttons each move the view to their building in their own copy of that code. MSVC merges the copies into the granary's, where the original has them, followed by the code after the switch (0.7085 -> 0.8915); one shared label puts the block after the last of them instead: reccmp 75.2 (normalized 61.3) against 100.0. - The tunnel button tests for no tunneler first. Fixes against the draft: - With one catapult or trebuchet selected and under 10 stone, the original only plays the lack-of-stone sound; the draft queued the command anyway. - After queueing the command for one engine or for the selection, the original returns; the draft went on to clear the patrol button and mark an engineer as selected. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Gynt <gynt@users.noreply.github.com>
gynt
added a commit
to gynt/OpenSHC
that referenced
this pull request
Nov 25, 2026
…#327 and sourcehold#328, with two header changes (sourcehold#417) * reimplement: SHC_3BB0A8C1_0x004708F0 100.0% Reimplemented, register allocation only (sourcehold#414) WindowAndDirectDraw::reinitWindow, moved out of our draft sourcehold#313 with one comment line added. The draft came from gynt's version on his fork's reimpl/UI-Rendering-development (3768087 at 56.90%, a8b64eb at 56.9%, and 63cc49f of 2026-10-25, his newest commit on the file) and reached 80.4% in 685b039. Register allocation only, per sourcehold#414: reccmp reads 80.4 (normalized 80.5), and the 56 instructions of both sides are the same instructions in the same order with the same memory operands. What differs is which of eax, ecx and edx holds each reload of windowHandle (and the address of the second corner) before it is pushed: eleven lines. if/else, nested and early-return shapes of the two branches all compile to the same code. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00493E20 100.0% Reimplemented VideoOptions::MenuItemActionHandler_VideoOptions_Main, rewritten from the listing on top of gynt's draft: aae2c08 (57.14%, his fork's development), cd76e7f (57.7%, upstream's reimpl/UI-MenuItems), 8725ec5 (61.5%, his fork's reimpl/UI-MenuItems-development) and 8ca7861 of 2026-10-27, his newest commit on the file (his fork's reimpl/Wilps-2026-10-18: the same code with newer field names). Our mechanical pass b2d7696 in draft sourcehold#328 read 61.5% as well. What the match needed: - case 11 keeps the resolution in a local through the loop and stores it once after it; the draft worked on the field, which stores it in every round; - case 18 reads the new resolution once and calls setExtraActiveModalDialog in every arm of the chain, in the original's order of arms. The draft set two position locals and called once, which shares the pushes. Two neighbouring arms with the same position joined by || read 0.8055 in quick_diff, so each resolution has its arm; - popModalDialog is called at the end of case 18 and in case 17: the compiler shares the one tail jump; - no goto and no position locals are left, and the loop is a for with its exit test in the header (a BOOLEnum that stands in for the original's do-while): the compiler puts the test at the end of the round, where the original has it. Names instead of numbers: CT_WINDOWS_LIKE_CURSOR, CT_ANI_CURSOR and SS_NORMAL. The parameter is button, as in most handlers on main; the buttons have no enum, so each case says what it does. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004C0CF0 100.0% Reimplemented SiegeAttackingForceAndStartGoods::MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main, rewritten from the listing on top of gynt's draft: ce671d7 and 37bf917 (40.1%, upstream's reimpl/UI-MenuItems), f0479fc, b83dff2 and d7600c8 (44.39% to 52.82%, his fork's reimpl/UI-MenuItems), then 25b481a (54.75%), 9743554 (52.49%) and 6aa5d32 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our mechanical pass 7b18743 and 53bea5f in draft sourcehold#328 read 53.8%. What the match needed: - one if / else-if chain with the draw buffer set back once, at the end. The draft returned from every arm, each with its own store; written once, the compiler copies the store into the arms as the original has it, and esi is pushed before the first branch; - renderGM for a unit's picture is written in both arms that draw one (rows 20 to 29 and 40 to 49). Shared after the chain it reads 0.7479 in quick_diff; - the row is -1 - button (or esi, -1 / sub esi, eax), not -button - 1; - every amount is drawn by a call in each arm of the colour test. One call with the colour as a ?: reads 0.9320 (neg / sbb / and / add for the colour), with a colour local 0.9608. Behaviour: none of the draft's forms differed in what they draw. Readability, all measured equal: rows 20 to 29 read SEC_SiegeInformation[index - 20] and rows 40 to 49 SEC_Section1067.siegeEngineCounts[index - 40] (the draft indexed SEC_StartingResources[index + 5] for both, which is the same address); the picture's height comes from DAT_GMImageHeaders as in TriggerInvasion_Main, not from a cast on PTR_ARRAY_Unknown_UnitGMHeights; index >= 40 && index < 50 for the unsigned range test. reccmp: 99.2% raw. The two lines that differ are the picture table's address 0x00B98782 (imh[first + picture - 1] .height), 14 bytes before DAT_GMImageHeaders: reccmp prints it as a number on the original's side and, on ours, as an offset from whichever variable of our DLL lies there (Instance<int,15544744>+2, DAT_ButtonX's instance). Only the name of the resolved address differs, which the project records as 100% (TriggerInvasion_Main in sourcehold#349 has the same two lines). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * headers: DAT_SentOrRequestedGoodsAmount is an int The amount the send / request goods dialog works with is compared as a signed value wherever it is read in MenuItemActionHandler_AlliesSendAndRequestGoods_Main (0x004B14C0): - 0x004B15E6: mov ecx, [0x00DF428C] / test ecx, ecx / jle: no amount chosen. An unsigned test would be je; - 0x004B16ED: mov ecx, [0x00DF428C] / cmp eax, ecx / jge against the room getResourceSpace returned; - 0x004B183A: cmp [the player's gold], esi / jge, and 0x004B1863 jl, 0x004B1870 cmp eax, esi / jge, with the amount in esi. As undefined4 (unsigned) each of these needs an (int) cast. Its only user on main, MenuItemActionHandler_Allies_Main (0x004B12D0), assigns to it and stays at 100.0% with the change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004B14C0 100.0% Reimplemented AlliesSendAndRequestGoods::MenuItemActionHandler_AlliesSendAndRequestGoods_Main, rewritten from the listing on top of gynt's draft: c7cfed8 and 8ee5623 (32.9%, upstream's reimpl/UI-MenuItems), cbc63a3, 17cbc68 and df54f4e (56.22% to 57.83%, his fork's reimpl/UI-MenuItems), 8725ec5 (58.2%) and 0e551f6 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our 1f29978 in draft sourcehold#328 read 60.5%. Behaviour, where the draft differed from the original: - buttons 21 and 50 to 53 return after their one store, and any other button but 100 returns after opening the allies dialog. The draft went on from each of them into button 100's path; - button 102 (cancel) queues its command only when the send dialog is open and DAT_00df4284 is set. The draft queued it always; - when a request fails for want of a building or of room, the original plays at most the one warning that fits the fail state and closes the dialog. The draft played the third warning in every case and, after a missing building, went on to the room test; - a request that is accepted queues the command and closes the dialog; the draft also played the "goods not sent" clip after it; - button 100 does nothing after the request path. The draft fell into the send path. What the match needed: - button 100 holds the whole confirm path and the other buttons' activateModalDialog comes last, which puts the return block where the original has it (with the test turned round it read 0.9305 in quick_diff); - the request path is one if / else-if chain that closes the dialog once at its end, with the five command stores and queueCommand written in both arms that send. The "not enough" arm comes first in the second (accepted first reads 0.9732); - good <= -1, as the original compares with -1 (good < 0 reads 0.9923); - the send path has one local for the resource, one for the type it is stored as, and one for the amount. Uses the header commit before this one (the amount is an int), so no cast on it is left. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * headers: IngameInvasionEventItemContent has an int at 0xA4 MenuItemActionHandler_General_EventSlider (0x004B9E50) reads the four bytes at 0xA4 as one int, the highest value of the invasion's slider: mov eax, dword ptr [0x01667EEC] at 0x004B9E86 (DAT_MapPropertiesState's invasionEventContent + 0xA4), which it then stores to *maxValue and clamps field_0xa8 with. The header had them as undefined1 padding_0xa4[4], which needs *(int*)&...padding_0xa4[0] to read. Named field_0xa4 like its neighbours field_0xa0 and field_0xa8; the struct's size and layout are unchanged, and nothing on main names the padding. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004B9E50 100.0% Reimplemented General::MenuItemActionHandler_General_EventSlider, from gynt's draft: cbdee60 and 7c31877 (45.3%, upstream's reimpl/UI-MenuItems), d0aa6c7 and 899dcd2 (55.93% and 69.21%, his fork's reimpl/UI-MenuItems), 514b907 (83.26%) and dd1a7c4 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our 2001534 and bddd6be in draft sourcehold#327 read 88.0%. What the match needed, on top of the draft: - the two range tests against the limit compare *currentValue > limit (cmp [ecx], eax / jle); the draft had limit < *currentValue, which swaps the operands; - in the repeat slider's switch, case 7 comes before case 4, as it already did in the months slider's. That alone took it from register names only (0.9322 in quick_diff, the three small blocks of the months slider on rotated registers) to every instruction. Readability, all measured equal: the lists of cases that only break are gone from both switches on the slider; the two step cases use ++ and --, as the invasion slider's do, and no longer the limit's local; no cast on the byte fields, read or written; the parameters are slider and scrollbarEvent, as main's other slider handlers have the second; the amount sliders' cases are written as their event type plus one (the function compares the type with slider - 1). Uses the header commit before this one (the invasion's limit is an int field). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0042D140 100.0% Reimplemented SinglePlayerMapChoice::MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands, rewritten from the listing on top of gynt's draft: 582f0a0 and 6918f23 (14.3%, upstream's reimpl/UI-MenuItems), 47663d0 (29.50%, his fork's development), 1ff44c3 to eaf674d (20.55% to 44.64%, his fork's reimpl/UI-MenuItems), b4b1f65 (45.29%) and dd1a7c4 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our dcaa477, 53bea5f and 07a33e2 in draft sourcehold#328 read 46.8%. Behaviour: unchanged. The draft cleared DAT_ButtonUnknownZero after the switch for buttons 2 and 65; here each of the two clears it itself, before its call, as the original does. The draft's gotos into a shared text call are gone. What the match needed: - every case breaks to one store of the draw buffer at the end (the compiler copies it into the arms, with pop edi before it, as the original has it); the draft stored and returned in every arm; - each text is drawn by a call of its own in each arm of the colour test, and renderBasicButton is called in each of button 74's three arms and button 77's two; - case 78 is written out with its own store and return: the original's switch has a table entry for it, though it ends in the same block as the default (with a plain break, or left to the default, the range check reads cmp eax, 178 where the original has 179); - the map-index sum in button 65 is DAT_MapSelectionScrollOffset + DAT_MapSelectionRelativeSelected: the other order loads the two fields the other way round (reccmp 99.6%; quick_diff does not see it). Readability, measured equal: X + W / 2 and X + W - 10 for the text positions. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004708F0 80.4% Reimplemented, register choice only WindowAndDirectDraw::reinitWindow's status line carries its measured percentage instead of 100% (the review asked for the lower percentage with a remark). A narrow build of this branch's head c6df741, both resolver sets on, sourcehold's reccmp with --ignore-security-cookie: 80.4% raw, 80.5% normalised. Both sides have the same 56 instructions in the same order with the same memory operands; the difference is which of eax, ecx and edx loads this->windowHandle in front of the SetFocus, ClientToScreen and UpdateWindow calls (sourcehold#414). The code is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Dec 2, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
MenuItemActionHandler_InGameMenu_UnitSelectionAndControlsUnkMenuItemActionHandler_NewEventAction_MainMoved out of this draft at 100%:
MenuItemRenderFunction_TextEditor_Buttons(0x0045DE40) goes out in the ready PR of round 18,reimpl/UI-B-round18-100.MenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClick(0x00442640) is in the ready UI: three more functions at 100%: the lobby's start button, the save list's header and the mission rows #423.MenuItemActionHandler_General_EventSlider(0x004B9E50) is in the ready UI: more functions at 100% from our drafts #313, #327 and #328, with two header changes #417.MenuItemRenderFunction_General_CreateEventCallbackFunction(0x004BBA60) andMenuItemRenderFunction_HistoricCampaignSelect_Main(0x004255D0) are on main.This draft now has 4 files: the two functions, the status list and the /GL list (
cmake/compiler-flags-gl.txt, forUnitSelectionAndControlsUnk). It has no header changes.Measured.
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.NewEventAction_Mainwas measured on 942d855 and reads 97.1%, 0.3 below its status line's 97.4%. Since then the branch only removed the text editor's file and its status line (2ab3c7d) and changedUnitSelectionAndControlsUnk(2424331).UnitSelectionAndControlsUnkwas measured again for 2424331, in a narrow build with the file on /GL, and reads what its status line says: 57.2% raw, 54.5% normalised (50.2% / 42.1% before). Its commit body names the tree it was built on, whose headers for this file match this branch's apart from one field type the file does not use.UnitSelectionAndControlsUnkgoes on the /GL list, next toSetTribesPatrolButtonPressed, which is on it already. The original comparesecxwith 2 right after the call toSetTribesPatrolButtonPressed(0x004376E6). Only with /GL does the compiler know that the call leavesecxalone; the rest of the function compiles the same either way.MenuItemActionHandler_InGameMenu_UnitSelectionAndControlsUnkhas names for its locals and labels now, but it still has the draft's gotos, casts on globals and declarations at the top.NewEventAction_Mainhas no gotos, but still usesparam_1.Behaviour fixed compared with the drafts
Each one is read from the original's asm, and the commit body gives the address.
distance > limit, as the original compares them (0x00434E9E-0x00434EAA).Proposed, not changed here
setSliderParameters' destination is anint*.The original's oddities, kept
getBuildingHasHealthPropertytwice (0x00435B48, 0x00435B5A), and its engineer test usesUS_JESTER_ROAM_TO(109).🤖 Generated with Claude Code