Skip to content

Reimplement 3 UI::MenuItems functions from gynt's drafts (not yet 100%) - #328

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

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

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Three of gynt's UI::MenuItems drafts from his fork (reimpl/UI-MenuItems and -development), brought onto main so others can continue from them. No header changes. Two lines are added to cmake/compiler-flags-gl.txt (see TextInputRelatedUnk below the table).

Two more are at 100% now and left this draft for #434 (106a282, c5e065d): PeasantBuildAndRightClickMenuSelection (0x00434350) and ScenarioDescription's render function (0x004D8250), both rewritten from the binary here first. A third followed in #439 (8f1e257): LobbyMenu's MapSelectHeader (0x00440A50), rewritten from the original's listing. A fourth followed in #440 (d7cff49): BuildMenu's UnitActionButtons render function (0x00438BE0), rewritten from the original's listing. A fifth followed in #441 (1319211): MapEditorProperties' MainButtons handler (0x00443070), rewritten from the original's listing; that PR also gives the description box's handler its parameter list in the header. A sixth followed in #442 (76eb7a7): General's LaunchOrQuitMultiplayerGameUnk (0x00494950), rewritten from the original's listing, with one behaviour fix (the draft never reached its case for the question -7). A seventh followed in #443 (3919ea8): NewEventCondition's Main handler (0x004B9620), rewritten from the original's listing; that PR also gives the event conditions' option table its int[32][25] type in the header. An eighth followed in #446 (dd901ee): LobbyMenu's PlayerListAndNpcButtons render function (0x00427810), rewritten from the original's listing, with seven behaviour fixes (its ranges of item numbers were not chained). A ninth followed in #447 (98ffddb): Allies' Main render function (0x004AC7A0), rewritten from the original's listing, with behaviour fixes (most of the draft's ranges of item numbers had no return). A tenth followed in #448 (b250213): General's AdvancedGameOptions render function (0x00428AC0), rewritten from the original's listing, with behaviour fixes (most of its items had no return, and one never returned). An eleventh followed in #468 (86e650b): InGameMenu's ProcessScribeAnimationChange handler (0x00433370), rewritten from the original's listing here first (b730ba6, 93.3%); its last difference, the zero's register, went away with the animation phase read and written as the global itself.

Rewritten from the binary (3):

  • AlliesSendAndRequestGoods_Main (0x004AD920). Rewritten in 077d2c3, with two behaviour fixes; see below the table.
  • TextEditor_TextInputRelatedUnk (0x00461570). Rewritten in 48fac64, with two behaviour fixes and two /GL lines; see below the table.
  • QueueCommandCallback (0x00443A30). Rewritten in 356f824, with six behaviour fixes, and taken to 99.5% in cc33a2b; see below the table.

No mechanical draft is left. Every commit body says what changed.

Functions

Every number in the "Measured raw" and "Normalised" columns is from a narrow build on main 3458fea; the all-on build described below (ecef1ca) has none of the three as they are now. The head is 86e650b now: on top of ecef1ca two move-out commits, then b730ba6, which changes ProcessScribeAnimationChange, then a third move-out, 8f1e257, then 077d2c3, which rewrites AlliesSendAndRequestGoods_Main, then a fourth move-out, d7cff49, then 48fac64, which rewrites TextEditor_TextInputRelatedUnk, then a fifth, a sixth and a seventh move-out, 1319211, 76eb7a7 and 3919ea8, then 356f824, which rewrites QueueCommandCallback, then an eighth, a ninth and a tenth move-out, dd901ee, 98ffddb and b250213, then cc33a2b, which changes QueueCommandCallback, then an eleventh move-out, 86e650b. None of the eleven move-outs changes a source file that is left. QueueCommandCallback's numbers are from cc33a2b, in a narrow build on main 3458fea of that file as committed together with the nine finished functions it calls, with the struct resolvers and those functions' resolvers on. AlliesSendAndRequestGoods_Main's numbers are from 077d2c3, in a narrow build of that file as committed, alone, on main 3458fea. TextEditor_TextInputRelatedUnk's numbers are from 48fac64, in a narrow build on main 3458fea of that file as committed together with helpToken.cpp, both in the /GL list, with the struct resolvers and the three functions' resolvers on. "Best before" is the best score on gynt's and 6and8's branches, as recorded in the earlier version of this text.

Class Function Address Status line Measured raw Normalised Best before (where) Left, or notes
AlliesSendAndRequestGoods MenuItemRenderFunction_AlliesSendAndRequestGoods_Main 0x004AD920 92.5% 92.5% (077d2c3, narrow build on main 3458fea) 83.1% 51.2% (gynt's reimpl/UI-MenuItems-development) rewritten from the listing; behind the amount test three scratch registers differ, see below
MapEditorLandscaping MenuItemActionHandler_MapEditorLandscaping_QueueCommandCallback 0x00443A30 99.5% 99.5% (cc33a2b, narrow build on main 3458fea) 89.2% 23.3% (gynt's reimpl/UI-MenuItems) rewritten from the listing; two places in the click part differ, see below
TextEditor MenuItemActionHandler_TextEditor_TextInputRelatedUnk 0x00461570 90.2% 90.2% (48fac64, narrow /GL build on main 3458fea) 71.2% 40.9% (gynt's reimpl/UI-MenuItems-development) rewritten from the listing; the character's register and the place of the insert's entry test differ, see below

AlliesSendAndRequestGoods_Main: two behaviour fixes, and what is left. The draft, like gynt's text on both of his branches, tested actionParam < 20 for the resource buttons where the original takes the numbers up to and including 20 (cmp esi, 0x14; jg at 0x004AD925), so button 20 was not drawn. And in the panel's frame it returned where the original goes on to the next column (cmp esi, 7; je to the loop's step at 0x004ADAF6), which ended the whole function at a middle row's second column: no further rows, no box and no text. Both are fixed in 077d2c3, which writes the function from the listing. Both sides have 359 instructions now. What is left is three scratch registers from the amount test on: the original has the amount in eax, the y in ecx and x + 36 in edx; ours has x + 36 in eax and the amount in edx. The three text calls behind them are rotated by one: TEXT_ALLIES 14 at 0x004ADB79, TEXT_ALLIES 13 (the goods <= 0 case) at 0x004ADBA1 and TEXT_GOODS at 0x004ADC2C. The compiler ranks the two coordinates above the amount (keys 64 and 54) and serves it last; in the original it is served first. The commit body lists what was tried.

TextEditor_TextInputRelatedUnk: two behaviour fixes, two /GL lines, and what is left. The function handles one key of the help window's text: with the alternate tab off it scrolls, otherwise it edits the custom text.

  • The fixes. Backspace (key 248) and delete (key 249) move the rest of the text down in a loop. The original runs that loop when index < length + advance (cmp ecx, edx; jge at 0x0046189E, and cmp ecx, edi; jge at 0x0046190D). The draft ran it when length > index + advance, taken over from ccd2b04 on gynt's reimpl/UI-MenuItems-development; his reimpl/UI-MenuItems has the original's test. With the draft's test a removal at the text's end did not copy the terminator down.
  • The /GL lines. Behind three calls of helpToken_getHelpTokenAdvanceLength (0x0045F080) the original still has the cursor in edx (0x004617CE, 0x00461815, 0x00461894), so the caller has to see that the callee leaves edx alone. 48fac64 adds src/OpenSHC/UI/MenuItems/TextEditor/MenuItemActionHandler_TextEditor_TextInputRelatedUnk.cpp and src/OpenSHC/Text/TextEditorState/helpToken.cpp to cmake/compiler-flags-gl.txt. With the two lines the function reads 90.2%, without them 69.0% (62.4% normalised). helpToken.cpp's two functions (0x0045F080 and 0x0045F0D0) read 100.0% with the lines, in the same narrow build.
  • What is left. Both sides have 285 instructions up to the last ret, alignment fill included, and the scrolling half matches completely. In the editing half the typed character sits in edx in ours and in esi in the original, so the inlined wcslen's temporary (0x004616D6), the shift loop's temporary and one pair of loads use other registers. And the insert's entry test (0x004616F7) stands where the typed-character path falls into it in the original, behind key 241's code in ours.
  • A lead for whoever continues. With one more call on the typed-character path that the compiler cannot see into, the character goes to esi and every register behind it is the original's, but the text pointer's early load (0x00461699) is lost. So in the original something on that path costs edx without touching memory.
  • The gotos stay. The original has one copy of the insert, entered from keys 240 and 241 with the token in a register (mov esi, 9 at 0x00461728, mov esi, 6 at 0x0046173B, both jumping to 0x004616F7). The draft had three gotos; the rewrite has two, both to that block. With the insert behind a flag the function reads 75.5%, with the insert written out three times 67.7%.

QueueCommandCallback: six behaviour fixes, and what is left. The function is the landscaping view's callback in the map editor: it handles the mouse's event, previews the mapper under the mouse, and on a left click queues the mapper's command through one switch with 35 blocks.

  • The fixes, each visible in the draft's own listing:
    • Event 5 (the flat view) returned right after toggleFlatView. The original goes on and runs the rest (0x00443AE8 falls into 0x00443AED).
    • The "people left to place" element was switched with 2300 < unitCount. The original has >= 2300 (cmp with 0x8fc, jl at 0x00443AFD).
    • Three returns were missing: after HandleWallTerrainMouseDrag and after storeXYAndResetMouseState (the original leaves through each with a tail jump, 0x00443B1C and 0x00443B31), and after renderWallPlacementPreview (0x00443BF2). The draft ran on into the code after them.
    • The river, foam and ripple case had no return after its first queueCommand: the river and the ripple queued their GCT_SET_TERRAIN and then a second one with the foam's param (16). The original queues once on each path (0x00443F7D with a ret at 0x00443F85, 0x00443FA9 with a ret at 0x00443FB1).
  • What brought it close. All 508 instructions are there, and every jump and every jump table entry lands where the original's does.
    • The two 0 / 1 arguments are an if / else with a call in each arm. With that the compiler keeps 0, 1 and 2 in ebx, esi and edi, as the original does; as conditional expressions it emits sete / setge.
    • The switch is on the field, with no local for the command.
    • Every case is written out in full. The shapes of the original's cases come from that by themselves: the scratch register for the brush size rotates from case to case, and the compiler shares the cases' tails with the last case's code (16 jumps enter it at four places).
  • The orientation is read in each arm of the second leftClickStart test (cc33a2b). Read in front of the test, it took ebx, and the test compared with an immediate 0. Read in the arms, the test compares with ebx, the zero register, as the original's does (0x00443C1C). The compare is the original's length again, so every jump over it and every jump table entry after it lands where the original's does: reccmp's diff went from 82 lines to 8, and the function from 94.7% to 99.5%.
  • What is left: two places in the click part, the 8 lines of reccmp's diff.
    • The orientation is the last of the four loads behind that test, just before the jump at 0x00443C3A; the original loads it second, after the snap mode (0x00443C28). No order of the reads, in the arms or in front of the test, moved it.
    • The logic layer's index goes through eax in the original and through edx in ours: three instructions (0x00443C5B, 0x00443C62, 0x00443C6E).
  • A /GL build with the nine finished callees reads 54.7%, so /GL is not it. The two commit bodies list what else was tried.

Moved out of this draft since the last version of this text

Function Address Where it went
MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange 0x00433370 #468 (100%)
MenuItemRenderFunction_General_AdvancedGameOptions 0x00428AC0 #448 (100%)
MenuItemRenderFunction_Allies_Main 0x004AC7A0 #447 (100%)
MenuItemRenderFunction_LobbyMenu_PlayerListAndNpcButtons 0x00427810 #446 (100%)
MenuItemActionHandler_NewEventCondition_Main 0x004B9620 #443 (100%)
MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk 0x00494950 #442 (100%)
MenuItemActionHandler_MapEditorProperties_MainButtons 0x00443070 #441 (100%)
MenuItemRenderFunction_BuildMenu_UnitActionButtons 0x00438BE0 #440 (100%)
MenuItemActionHandler_LobbyMenu_MapSelectHeader 0x00440A50 #439 (100%)
MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection 0x00434350 #434 (100%)
MenuItemRenderFunction_ScenarioDescription_Main 0x004D8250 #434 (100%)
MenuItemRenderFunction_VideoOptions_Main 0x00492170 on main, #406
MenuItemActionHandler_ChooseNetworkServiceProvider_Buttons 0x004909E0 on main, #407
MenuItemActionHandler_SingleplayerMapChoice_ButtonsAndHands 0x0042D640 on main, #407
MenuItemActionHandler_CrusadeMap_Main 0x004D8EC0 on main, #410
MenuItemRenderFunction_InGameMenu_MainButtons 0x004643F0 ready #416
MenuItemActionHandler_Roundtable_Main 0x004AEA50 ready #416
MenuItemActionHandler_BuildingAndStatusMenu_BuySellMenuButtonsAndHands 0x00467040 ready #416
MenuItemActionHandler_AlliesSendAndRequestGoods_Main 0x004B14C0 ready #417
MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main 0x004C0CF0 ready #417
MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands 0x0042D140 ready #417
MenuItemActionHandler_VideoOptions_Main 0x00493E20 ready #417

Measured

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • This branch, ecef1ca: an all-on build with 0 failed, 99.33 over 2,410 functions.
  • Without ProcessScribeAnimationChange, a8b3225: 0 failed, 99.33 over 2,409 functions. Between the two builds the only difference is that function.
  • TextEditor_TextInputRelatedUnk since 48fac64: 90.2% raw, 71.2% normalised, in a narrow build on main 3458fea of src/OpenSHC/UI/MenuItems/TextEditor/MenuItemActionHandler_TextEditor_TextInputRelatedUnk.cpp and helpToken.cpp, both compiled with /GL, with the struct resolvers and the three functions' resolvers on. The all-on builds above have it as it was at ecef1ca, at 40.9%, and without the two /GL lines. No all-on build was run with the two new /GL lines, so their effect on the other /GL functions is not measured.
  • The branch's base, e086ba7, alone: 0 failed, 99.57 over 2,396 functions. No function that exists there moves in a8b3225.
  • Not comparable with main's average: this branch is based on e086ba7, so the functions main gained after that commit are not in these builds.
  • Not run in game.

Two readings that are lower than on current main

Both functions read 100.0 raw and normalised in an all-on build of main f489b72 (3458fea only adds files under tools/). They read lower in all three builds above: e086ba7, a8b3225 and ecef1ca.

Function Address f489b72 e086ba7, a8b3225 and ecef1ca What differs
UpdateFireBallistaBuilding 0x0041E240 100.0 / 100.0 99.6 / 95.5 one mov edx from an int global sits at a different place
MenuItemActionHandler_InGameMenu_MainButtons 0x00444B80 100.0 / 100.0 99.8 / 100.0 one jmp distance, -0x8a6 against -0xa8a

What we know: the base commit alone shows both readings, so neither comes from this draft's functions. The source files of these two functions are the same on e086ba7, on this branch and on main.

What we don't know: why the same source reads 100 on current main and lower on e086ba7. UpdateFireBallistaBuilding is compiled with /GL, and we are still testing whether the symbol-count effect from #366 explains its move. We have not rebuilt this branch on top of current main.

🤖 Generated with Claude Code

kotijekriv and others added 30 commits November 5, 2026 01:33
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>
…ass; register allocation and structure

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings); quick_diff output identical.

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings); quick_diff output identical.

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings); quick_diff output identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…al pass; structure

gynt's draft. Compiles at a521bf7 again (GameModeInt include). The map-name extension is a strcat with the string-macros.hpp literal (the draft's hand-made scan and strcpy into the end), and auto_backup_map.map is STR_AutoBackupMap; quick_diff 0.6907 -> 0.7065. The rest is the mechanical pass. Both PlayerSlotUnitColor copies are for loops (identical code).

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

gynt's draft. Compiles at a521bf7 again: the menu tabs to switch to are ActiveMenuTab structs now (.tabType). auto_backup_map.map is STR_AutoBackupMap; the rest is the mechanical pass (identical code). The player IDs are set by a for loop (identical code). Re-measured on main 06d4938, where sourcehold#319 and sourcehold#322 reimplement callees of this function: 50.6% -> 53.2% (same code as before).

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

gynt's draft. Compiles at a521bf7 again: the byte the draft wrote through units[0x9bb].field_0x3e3 (a field the header no longer has) is addressed from that unit's start + 0x3e3, the same address; the target is not really in a unit, see the PR text. The rest is the mechanical pass (identical code).

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings); quick_diff output identical.

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings); quick_diff output identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BuildMenu_UnitActionButtons' render function tests the selected unit's type against -1 (no unit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
InGameMenu_PeasantBuildAndRightClickMenuSelection compares the active build-menu tab with 49.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It copies the text it is given into the active text slot and does not write to it (0x00472C30), so its
parameter is const. EditScenario_BaseMenuButtons passes the string pointer for "", which is const; readUserConfig
on main passes a char* and compiles to the same code (quick_diff identical).

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

gynt's draft. Compiles at a521bf7 again: getResourceSpace takes a ResourceType now (the draft passed (int*)(int)x). Gold is RT_GOLD; the rest is the mechanical pass (identical code).

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

gynt's draft with the mechanical pass; the no-unit test uses UT_NONE (header commit). quick_diff output identical.

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

gynt's draft. Compiles at a521bf7 again (InGameEventUnionVersion using). The %d and empty strings are their string-literals.hpp pointers (copyIntoTextArray takes a char const* now, header commit), the starting resources are indexed by RT_GOLD / RT_PARTIALPITCH; the rest is the mechanical pass. The new event's condition stores name their fields (conditions[k].subType and .enabled) instead of byte offsets, identical code; conditions 5-7 stay written out, since a for loop loses the match (quick_diff 0.6452 -> 0.5879).

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

gynt's draft. Compiles at a521bf7 again (AlphaAndButtonSurface's processBuildingClickBonus and selectUnitAndOpenStatusMenu were renamed). Tab 49 is BMTT_UNKNOWN_49 (header commit); the rest is the mechanical pass (identical code).

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings); quick_diff output identical.

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings); quick_diff output identical. The group maximum and the group count are for loops and the copy of the saved groups is a memcpy (67.4% -> 71.2% in the combined build).

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

gynt's draft with the mechanical pass; no pending token is HTT_NONE (header commit), and the character tests compare with 32 without a HelpTextToken cast. quick_diff output identical.

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>
…ass; structure

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings, enum names for cast numbers); quick_diff output identical. The PlayerSlotUnitColor copy is a for loop (identical code).

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings, enum names for cast numbers); quick_diff output identical.

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings, enum names for cast numbers); quick_diff output identical.

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings, enum names for cast numbers); quick_diff output identical.

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings, enum names for cast numbers); quick_diff output identical.

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings, enum names for cast numbers); quick_diff output identical.

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings, enum names for cast numbers); quick_diff output identical.

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

gynt's draft with the mechanical pass (decimal numbers, prefix steps, truthiness tests, unused usings, enum names for cast numbers); quick_diff output identical. The cost tests are for loops (identical code).

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>
kotijekriv added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 24, 2026
…er, BuySell, UpdateGhost and UpdateHopsFarmer (sourcehold#416)

* cmake: /GL for InGameMenu MainButtons render function

MenuItemRenderFunction_InGameMenu_MainButtons (0x004643F0, next commit) only matches with link-time code generation.
The original keeps the button's data pointer in ecx across ButtonGmData::getPictureNumberInGm (0x004630B0), which
leaves ecx alone, and reads the button's gm ID through it after the call; MSVC can only do that with both functions
under /GL. getPictureNumberInGm is already in this list on main.

MainButtons measures 100.0 with /GL (reccmp, all-on build on main f489b72: the Globals and every finished function
resolver on, so both functions' resolvers too). On main 3416498 it measured 80.8 without /GL, and 83.8 under /GL
with MainButtons' own resolver off: nothing then takes its address, and LTCG drops the load of its argument.

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

* reimplement: SHC_3BB0A8C1_0x004643F0 100.0% Reimplemented

MenuItemRenderFunction_InGameMenu_MainButtons, rewritten from the binary with gynt's draft for the names
(e6a4dba, 7f2191d and b9a9e27 on his fork's reimpl/UI-MenuItems, 48.75% there; 793ac41 at 57.73% and
616eb44 at 47.63% on his reimpl/UI-MenuItems-development, 616eb44 being his newest reimplement commit on the file)
and our mechanical pass of it in sourcehold#328 (ee10c60, 49.0%; quick_diff 0.6164 on main). The function leaves sourcehold#328 with
this commit.

reccmp 100.0 (normalized 100.0) in an all-on build on main f489b72 under /GL (the cmake commit before this one),
which has its function resolver and getPictureNumberInGm's (0x004630B0) on; 80.8 without /GL (main 3416498). The original keeps the button's data pointer
in ecx across that call, which only LTCG can know is safe; without it the pointer has to survive the call some other
way, and the zero, the one and the picture offset go to ebx, ebp and edi in another order than the original's.

Fixes against the draft:
- In the barracks and the mercenary post the original greys the buttons above -10 but the scribe (71) and -4; the
  draft greyed those at -10 and below (616eb44 turned the bound round).
- The greys of -1, -5 and -6 set the flags and go on to the build-menu test and the draw, so the button is still drawn;
  the draft returned at once for -1 and for one -5 case.

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

* cmake: /GL for Roundtable's click handler and isAIPlayer

MenuItemActionHandler_Roundtable_Main (0x004AEA50, next commit) only matches with link-time code generation. It calls
GameSynchronyState::isAIPlayer (0x004010B0) for each seat, and isAIPlayer changes only eax; with both under /GL MSVC
knows that, and gives the handler the original's registers (eax for the chosen lord's seat, ecx for the button where
the seats are read). Without /GL the handler reads 87.2 in every source form tried.

isAIPlayer is 100% on main with its function resolver on and stays at 100.0 under /GL (reccmp, all-on build on main
f489b72, built with the handler). It is the only callee the handler needs there: on main 3416498, with the
handler's other five finished callees (resetMouseState2, nextRandomNumber1, playWAVSFX, scheduleSFXVariation,
shouldSoundXNotBePlaying) also under /GL, the result was the same 100.0. No other file in this list calls isAIPlayer.

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

* reimplement: SHC_3BB0A8C1_0x004AEA50 100.0% Reimplemented

MenuItemActionHandler_Roundtable_Main, from gynt's draft (c53b2b9 and 18ddd79 on his fork's reimpl/UI-MenuItems,
61.09% there; 65013b9 at 66.46% and a04df2a at 67.08% on his reimpl/UI-MenuItems-development, a04df2a being
his newest reimplement commit on the file), our mechanical pass of it in sourcehold#328 (15884ad, 71.2%) and our own rewrite
from the binary at 87.2% (local, never pushed). The function leaves sourcehold#328 with this commit.

reccmp 100.0 (normalized 100.0) in an all-on build on main f489b72 under /GL (the cmake commit before this one),
which has its function resolver and isAIPlayer's on; 87.2 without /GL (main 3416498).

From the binary: the chosen lord's and the target's seats are read from DAT_RoundTableOrderArray (the decompiler had
them as mapSendRequestStatePerPlayer + button + 26), the group numbers are char reads into ints with no casts, the
highest group in use is a plain loop over players 1 to 8 (MSVC unrolls it into the original's eight copies, as it does
the group count of button 100), the new group is one local stored twice, and the buttons after the seat logic are an
if chain with returns. The last difference under /GL was which of eax and ecx held the chosen seat and the button: the
original's comes from reading the chosen lord's seat before the target's.

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

* reimplement: SHC_3BB0A8C1_0x00467040 100.0% Reimplemented

MenuItemActionHandler_BuildingAndStatusMenu_BuySellMenuButtonsAndHands, from gynt's draft (7cbb7b8 and fb51a06
on his fork's reimpl/UI-MenuItems, 83.17% there; 30ace91 at 83.81% on his reimpl/UI-MenuItems-development) and
our pass of it in sourcehold#328 (74bdd12, 83.8%; 60ea82a, 93.3%). The function leaves sourcehold#328 with this commit.

Register allocation only, per sourcehold#414, so the status line records 100.0. reccmp's own score is 93.9 in an all-on build
on main f489b72, and diff_triage's register-blind ratio is 1.000 (0.859 before renaming registers): every
remaining difference is a register name. Ten line pairs differ. In eight, the two `imul ..., 0x39f4` player-index
computations use ecx and edx the other way round and one load and one store use edx where the original uses eax.
The other two are jumps one byte off, because the original's `mov [global], eax` takes the shorter moffs encoding
that edx has not. Same instruction count, same mnemonics in the same order, same memory operands.

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

* reimplement: SHC_3BB0A8C1_0x00543B80 100.0% Reimplemented

Units::UpdateGhost, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (9fd4871 at 52.63%,
e248d10 at 60.35%), under /GL:
- owner is read once at the top through DAT_CurrentUnitSlotID::instance, into an int const local that the
  nonInteractiveCitizenCountUnk increment and findNextReachableDefensiveBuildingForPlayer's first argument use: the
  original loads it before the stateBasedSpeed store and keeps it in ecx up to that call (quick_diff with the /GL
  callees in the unit 0.9568 -> 0.9784; the local read through unitID 0.7071, a short local 0.5833);
- makeUnitStopWalkingByClearingPathProgressState at the end and hasUnitReachedDestination get the slot, and in
  US_IDLEUnk every statement from the destinationNeeded store after the timeGetTime test to the end of the state
  indexes units[] through it, as the original reads the slot again after playSFXAtLocation and timeGetTime. unitID
  is then not live across those calls, and the timeGetTime pointer gets esi as in the original (0.9424 -> 0.9568;
  starting one statement later 0.9429). The other statements use unitID or the slot as a greedy quick_diff search
  picked them one statement per step;
- states 108 and 2 are US_UNKNOWN_108 and US_STATE_2Unk;
- three stores in blocks that otherwise use unitID stay through the slot (no comment, per gynt on sourcehold#393): the
  US_IDLEUnk state store in US_DETERMINE_NEXT_STATEUnk (through unitID: quick_diff 0.9784 -> 0.9640), the
  field_0x30_animRelated store in US_MELEE_ATTACK (0.9712) and the clamp to 32 in state 2 (0.9712);
- compiler-flags-gl.txt lists UpdateGhost.cpp: 100% with the line, 49.3% without it, as hasUnitReachedDestination
  and makeUnitStopWalkingByClearingPathProgressState, both on main's list, have to be visible.

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

* reimplement: SHC_3BB0A8C1_0x00552F80 100.0% Reimplemented

Units::UpdateHopsFarmer, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (4c7f4b4 at 50.99%),
through an earlier version on our dev branch at 99.7%: every unit access goes through
DAT_CurrentUnitSlotID::instance with the worker-helper callees visible, the states form one else-if chain, and a
block-level quick_diff search put the storage lookup back on unitID; the solitary-or-not goods amount is an if/else
with the call in each arm; in the delivery state the can-store path is the then-arm of canBuildingStoreTheAmount
and the reachable-storage path the then-arm of buildingIsAccessible. Kept forms (quick_diff with the /GL
callees in the unit; the first and last with a one-line why, the slot indexing without, per gynt on sourcehold#393):
- the delivery state's else arm reads the slot into unitID again, as the original does (without it 0.9949);
- setDestinationForUnit in the walk-to-field state takes unitID, as the original keeps the slot across
  UpdateWorker_ConsiderTakingABreakUnk there (through the slot 0.9864);
- ownFarm reads workplaceBuildingID_1 again after the calls next to farm (reusing farm 0.9272).
Style on top, all the same code (0.9971 before and after): DNE_UNKNOWN_2 for (DestinationNeededEnum)2 and no using
line, no casts on the stores into short fields and on the coordinate operands, BOOLEnum results tested by
truthiness, ++/--, int const storage, no unused BOOLEnum include.

compiler-flags-gl.txt gets UpdateHopsFarmer.cpp and the three callees it needs visible, each 100% on main and
called by no other file on the list: ComputeGoodsProduced (quick_diff without it 0.9599),
IncrementAndOptionalUpdateAVValueRelated (0.8182) and SetStateToFreetimeWalking (0.9899); with no callee bodies at
all, i.e. off the list, 0.5950. UpdateWorker_ConsiderTakingABreakUnk makes no difference (0.9971 without it) and
stays off. reccmp in a build of main's whole /GL list with every resolver of those files on: UpdateHopsFarmer
99.7%, the three callees 100.0%, nothing else moved.

The one difference left is register allocation only (sourcehold#414): the owner pushed for
getBuildingThatCanStoreThisResource is loaded into eax where the original uses ecx, the same two instructions and
memory operand. Owner locals, an int or short cast, and reading it through unitID or the slot all tie or lose; a
symbol-count sweep (0..95 dummy typedefs, after the includes and at the top) reads 0.9971 at every count.

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 kotijekriv/OpenSHC that referenced this pull request Nov 24, 2026
* reimplement: SHC_3BB0A8C1_0x004559B0 100.0% Reimplemented

TextureRenderCore::loadGMFile. gynt's drafts: 071726e at 77.8% on sourcehold's reimpl/UI-Rendering, and 84.5% in
the status line of his fork's reimpl/UI-Rendering-development (63cc49f); the newest commit on the file, 15e5712,
is on his fork's reimpl/UI-MenuItems-development. Our draft d29d51d (93.1%, in the draft PR sourcehold#363) was written from
the original's instructions with his draft for the reads.

What was left was the loop's test whether a picture shares another one's data. The original tests the flag first
(0x00455B70). With the flag set it reads the colour byte once, into cl, and tests it twice: zero copies the picture,
bit 2 (value 4) takes the previous picture's offset, anything else the alternative picture's (0x00455B82 to
0x00455B9A). Without the flag it tests bit 2 in memory and runs on into the same blocks (0x00455B9C). The draft had
one condition, (flag && colour != 0) || (colour & 4): with it the compiler tested bit 2 again behind the zero test
and based the header pointer on the colour byte.

Written as the listing has it:

- The flag's two arms, each with its own sharing and its own copying. The compiler merges the two copies of the
  copying and lets the second arm run into the first arm's stores, as the original does. With the copying written
  once the match is lost: behind the draft's one test quick_diff reads 0.9326, behind a flag variable or a continue
  0.70 to 0.77.

- The colour byte in a local in the flag's arm. Without it the rest is the same, but the copying adds its source
  address the other way round (0.9610 against 0.9714).

Measured: quick_diff 0.9714 with 192 instructions against 193, also with the stack slots kept. What still differs
there is not in the code: four calls through the import table, the jmp over the padding in front of the loop
(0x00455B66), and the previous offset's address, which the original's listing shows folded (0x00D0BA0C). reccmp
100.0% (normalized 100.0%) alone, data resolvers and its own resolver on. Not run in game.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* reimplement: SHC_3BB0A8C1_0x00440A50 100.0% Reimplemented

LobbyMenu::MenuItemActionHandler_LobbyMenu_MapSelectHeader, rewritten from the original's listing. gynt's drafts:
7a1fcbd at 32.66% on his fork's reimpl/UI-MenuItems, and d0d28fd at 45.93% ("comparison operand order") on his
fork's reimpl/UI-MenuItems-development, whose status line records 45.9%; the newest commit on the file, dd1a7c4,
is on that branch too. Our draft c792435 (46.3%, in the draft PR sourcehold#328) was his code with a mechanical pass.

The function sorts the lobby's map list by name, by players or by balance: on a click on a column or, with a
negative argument, by a stored order again. The drafts had the decompiler's text, with seven iVar and two uVar
locals. Written out with names, six things decide the match:

- The non-negative arm stands first. The original falls through into the modal checks and jumps away for a
  negative argument (jl at 0x00440A64).

- A stored order is compared after it is negated (neg eax at 0x00440B29, then cmp eax, 1 and so on). In each arm
  the source sets the column in front of the order. The listing loads the order's value first, then the column,
  and stores the order last (mov ecx, 4; mov eax, 2; mov [order], ecx, from 0x00440B5E); with the order set first
  in the source the match is lost.

- In every bubble pass the second index is taken in front of the first, as the name sort's listing has it
  (0x00440D10). With the first one first the match is lost.

- The players' sort reads the list's length in its loop condition each time (0x00440C8F); the other two sorts take
  it once.

- The players' sort counts its seven tries in the parameter's own slot (mov dword ptr [esp + 0x18], 7 at
  0x00440C29), which is why the argument is copied at the top (0x00440A57). A local for the tries loses the match.

- The search for the chosen map is a plain for loop over the list that handles the hit inside (0x00440DC0 to
  0x00440DFD). The drafts' while loop with a second test of the length has four instructions more.

The sorts' repeat-until-nothing-swapped loops are for loops (for (int swaps = 1; swaps != 0;)), which compile to
the same code as do-while loops.

Measured: quick_diff 0.9766 with 253 instructions against 259. The six lines are the original's jmp over the padding
in front of its loops, which our listing shows as padding; the rest is how the two listings print two constants and
the tail call. reccmp 100.0% (normalized 100.0%) alone, data resolvers and its own resolver on. Not run in game.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

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
…#440)

BuildMenu::MenuItemRenderFunction_BuildMenu_UnitActionButtons, rewritten from the original's listing. gynt's drafts:
19176b8 at 39.09% ("bug fix, costs 0.6% match") on his fork's reimpl/UI-MenuItems, whose status line records
39.1%, and 0523265 at 40.73% ("if/else") on his fork's reimpl/UI-MenuItems-development, whose status line records
40.7%; the newest commit on the file, dd1a7c4, is on that branch too. Our draft (72d2bc1, then ae5a920 and
07a33e2; 40.9% in the draft PR sourcehold#328) was his code with a mechanical pass and a fix for button 376.

The function decides for each unit action button whether it is drawn: one switch over the button's picture
(DAT_CurrentButtonGmDataIndex, a GmDataIndex value), dispatched at 0x00438C35 through the jump table at 0x0043907C
and the byte table at 0x004390AC. A hidden button stores TRUE in DAT_ButtonUnknownZero and returns; a shown one is
rendered and stores FALSE. The drafts reached the shared render, the shared renderNumber call and the stance
buttons' common end by goto (seven gotos to three labels), carried renderNumber's seven arguments there in seven
locals, and reached part of the hides by break to a store behind the switch. Written without them, five things
decide the match:

- One render stands behind the switch and the shown paths leave by break. In the original 374, 216, 211 to 215 with
  558, and default all jump to one render block (0x00438EC1); each path that falls into the render has a copy.

- Three plain renders are written out all the same: at 218's end (0x00438CFA), in 219's ranged arm (0x00438EC1,
  the block the breaks land on) and at 219's end (0x00438EF3). With a break at 218's or 219's end the compiler keeps
  a copy of the hide there and jumps to the render, where the original jumps to the hide. With a break in the ranged
  arm the render block goes to the function's end and case 217 keeps code of its own (288 instructions against 277).

- Every hide is written where it is decided (DAT_ButtonUnknownZero = TRUE; return;). The original keeps the 1 in
  esi in the cases that also compare with it, and the 0 in edi; its hides share two blocks, 0x00439048 for the
  register and 0x0043906C for the immediate.

- The hides in front of a written-out render are one || test (218, 219's end), and so is the test of default and
  217. As separate ifs the match is lost each time. Case 220's six conditions are one test as well; there one test
  and separate ifs compile the same.

- case 217 has a body of its own, the same as default's. The original's jump table has twelve entries, one of them
  for 217 alone, and it leads to default's code (0x00439051). With `case 217:` in front of `default:` the table has
  eleven entries and the byte table other values, while the instructions stay the same.

The two cases that draw a number each write their renderNumber call; the compiler shares the call's end
(0x00438E95), as the original does.

hasEngineerSelected is compared with TRUE in 376 and in 211 to 215 with 558, because the original compares with 1
there (0x00438C41, 0x0043902E); a truth test loses the match in both places. The case labels and the stores to
DAT_CurrentButtonGmDataIndex use GmDataIndex's names; the siege engine unit types and the two colours use their
enum names too.

Measured: quick_diff 0.9964 with 277 instructions on both sides; the one difference is how the two listings print
376's tail call. All 45 local jumps land on the same instruction and both switch tables are the same, compared by
a script because quick_diff prints every local jump alike. reccmp 100.0% (normalized 100.0%) alone, data resolvers
and its own resolver on. Not run in game.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
kotijekriv added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 24, 2026
…#442)

General::MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk, rewritten from the original's listing.
gynt's draft is the file on his fork's reimpl/UI-MenuItems-development (first in 4e57118, newest commit on it
b3069fd); his status line has no number for it. Our draft (791f92c, then d79d89d; 64.2% in the draft PR sourcehold#328)
was his code with a mechanical pass and strcat for the map name's extension.

The function answers the two buttons of a confirmation dialog: 22 carries out what the dialog asks
(DAT_MenuOptionsActionParameter), 23 declines it. Every path ends in resetMouseState2 except a multiplayer game's
return to its lobby. 22 is one switch over the question (-7, 7, 9, 30, 43, 44, 47, 49, 1000, 2000 and a default),
dispatched through a compare tree, the byte table at 0x00495084 and the jump table at 0x00495070.

One behaviour fix. Question -7 is asked by the scenario description's handler (it stores -7 into
DAT_MenuOptionsActionParameter). The draft, like gynt's text, first tested the question with `< 44` on the field as
the header types it (undefined4, unsigned) and compiled to an unsigned compare. So -7 never reached its case: it
took the other side and ended in the default, and "yes" only closed the dialog. The original compares signed (jg at
0x004949E2) and has -7 in the jump table: it puts the player colours back to their defaults and then runs 7's and
1000's code, which for -7 ends in the single-player map choice. The fix comes from having one switch over all
questions; the (int) makes its dispatch the original's.

What decided the match, each measured with one thing changed (reccmp in the narrow build described below; the
variants were built on the text before its last edits, which do not change the listing):

- The switch is on (int) of the field. On the field as it is: 71.4% (26.0% normalized). Main has the same cast on
  the same field in MenuModalRenderFunction_YesNoDialog (0x00493390).

- resetMouseState2 is called once, after the outer switch, and every path leaves by break. The original has a copy
  of it at every path's end and only the conditional jumps (button neither 22 nor 23, three trail tests) go to the
  last one. With `reset; return;` written out in every path, which also means the leaving code has to stand after
  the inner switch (two changes in this variant): 83.7% (71.5%).

- The leaving code (7, 1000 and, after the colours, -7) stands inside `case 7: case 1000:`. The compiler puts its
  first test at 7's place and the rest after the last case, as in the original.

- In that code the multiplayer exit tests the field and the local for the game mode is read after the test. Read
  before it, the game mode and the constant 1 swap esi and edi in the whole function: 95.8% (89.7%). Without a
  local: 85.4% (85.1%).

- Case 30 is one if / else with one break after it. The currentModalDialog test at the end of the leaving code
  shares the call of clearAnyOtherModalDialogs with 43 (jne at 0x00495056 to 0x00494B4A); with a break in 30's
  first arm it shares 30's: 99.8% (95.2%).

- Case 49 closes the dialog itself and default does the same in its own two lines. With 49 falling into a default
  written right after it, the compiler folds default's code into 2000's equal end, and default's three jumps and its
  table entry land after 2000's code (the original has them after 49's, 0x00494D78): 99.2% (95.2%).

- In 44 the trail part is `if (isSkirmishTrail == TRUE) { the three trail tests }` with the lobby restore after it;
  the draft had `!= TRUE` with the restore first: 87.0% (73.5%). The original compares with 1 there (cmp with edi
  at 0x00494C2C); as a truth test: 99.6% (90.9%).

- The menu to return to is chosen by nested if / else in the original's order, with switchToMenuView written in
  every arm; the compiler shares the call itself (pushes in the arms, one call at 0x00495046). The two mission
  select views as one call with ?: read 92.8% (79.3%).

These compile to the same listing, and the plainer form stands: the three trail tests as one if / else-if chain
with one break; `case 22` before `case 23`; gameMode_2 read from the field in 44; the inner cases in ascending
order with default last (the compare tree decides where their code goes); no braces around case 22;
Game::GameModeInt for the local; FALSE for field_0x6c; and the backup map's name as the string-macros.hpp macro,
because the file uses a macro for strcat's inline copy and must not include string-literals.hpp beside it.

Measured in a narrow build on main 3458fea of this file with the two finished functions it refers to in the
sources list, their resolvers on: RenderLoadAndSaveBar (0x00493690), whose address it stores, and resetMouseState2
(0x004689D0), which every path but the multiplayer exit tail-calls. reccmp 100.0, normalized 100.0, and both of them
stay at 100.0. Without resetMouseState2's file in the list the function reads 97.2% (100.0% normalized): each tail
jump then shows as a trampoline. The draft read 58.3 (65.7 normalized) in the same build without resetMouseState2.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
kotijekriv added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 24, 2026
…#446)

LobbyMenu::MenuItemRenderFunction_LobbyMenu_PlayerListAndNpcButtons, rewritten from the original's listing. gynt's
draft: f0e6b48 at 56.46% ("Style pass, asm differs") on his fork's reimpl/UI-MenuItems, whose status line records
56.5%; his reimpl/UI-MenuItems-development records 56.5% too ("Reimplemented, asm differs"; the newest commits on
the file there are 8725ec5, a reimplementation commit, and 5084980, a style commit). Our draft (8c967b4, then
five style commits up to 07a33e2; 58.8% in the draft PR sourcehold#328) was his code with a mechanical pass.

The function draws the parts of the lobby's player list, one menu item per call, chosen by the item's number: 0 the
three headings; above 10 a seat's row (its group's icons, the help texts under the mouse, and text 402 for a player
or the AI lord's text); 1 to 10 a seat's picture, a second one for the host's seat, and the player's or the AI
lord's name; -1 to -9 a seat's button; -101 to -103 three single buttons; -200 and below a seat's button for the
host. Each range ends in a return; the last three leave through RenderCurrentButtonToScreenMenuWithBlendingUnk.

Seven behaviour fixes against the draft. The draft's ranges were separate ifs without an else and partly without a
return, so:

- For the host, after the headings (0) it ran on into the code for -1 to -9, with the seat at index 0 (visible in
  the draft's listing: a jmp to that code's single-player test, which returns in a single player skirmish).
- After a seat's name (1 to 10) it ran on into the same code with the seat at index -button, before the array, and
  cleared ButtonUnknownZero again, which the original leaves set.
- Above 10 it went on to the AI lord's text after a player's text, and drew it whenever the seat also had an AI
  type; 1 to 10 it drew the AI lord's text (for a seat without an AI lord too) and then the name. The original draws
  one of the two: it returns after the player's (0x00427BBE and 0x00427D65) and draws the AI lord's only for a seat
  that has one.
- An AI lord's seat button (-1 to -9, and -200 and below) was drawn twice for the host: after the button the draft
  ran on to the function's last lines, which draw the current button. The original leaves through the first draw
  (tail jumps at 0x00427EB7 and 0x00428025).
- In the last range a player's seat ran on after its button was drawn too: it then called isAIPlayer with the alpha
  value in place of the seat's number and could draw the button again.
- -102 set ButtonUnknownZero only for someone who is not the host. The original sets it first (0x00427F0E), so for
  the host it stays set while another dialog is open.
- -103 outside a single player skirmish set ButtonUnknownZero, cleared it again and went on to the button. The
  original returns with it set (0x00427F40 to 0x0042802A).

The first two, the AI lord's button and -102 are in the draft's listing; the others are read from its source.

What decided the match, each measured with that one thing changed (reccmp in the narrow build described below):

- The two headings with an x offset take x through a local. Written in the call, x is loaded late: 96.2% (79.2%
  normalized).
- Where two or three calls differ in one argument, each arm has its own call, and the compiler shares the call:
  the three help texts (their number in a local: 92.3%, 82.7%) and the two colours of a name (the colour in a
  local: 92.7%, 83.4%).
- A player's seat button takes its picture number, 206 or 207, by if / else. As the draft's `207 - (value != 0)`:
  96.2% (82.7%).
- The last range is `if (isHost) { ... return; }` with the code for everyone else after it; that code is also
  -103's exit. With `if (!isHost) { ...; return; }` first: 96.1% (81.8%).
- -101 looks for an empty seat with a flag set in the loop. With the loop's index tested after it: 96.8% (85.9%).

Measured later with our own exact listing compare against the original's 604 instructions (differing lines, the
final text has 0): text 402's two colours take a call in each arm too (the colour in a local and one call: 328; set
by if / else: 107), and the group array is read again after the help text's call where the original reads it again
(with the `group` local there: 330).

These compile to the same listing, and the plainer form stands: the flag in -101 where the draft had a goto into
-103's clear; the AI type switched from the field where a local would do; the two icon rows in either order; the
picture number by if / else where a conditional expression would do.

The text numbers carry their texts from the game's cr.tex (group 79) as comments, and the button pictures 206, 207,
626 and 627 are named from GmDataIndex. Neither changes the listing: this text compiles to the same instructions,
line for line, as the text the builds below measured (the tree of 12b9d934e).

Measured in a narrow build on main 3458fea of that text and the five finished functions it calls, their resolvers
on: AModalDialogIsActiveButIsNotQuitting (0x00427210), renderGMWithAlphaMask (0x004557B0), renderGMWithBlending
(0x00455390), isAIPlayer (0x004010B0) and RenderCurrentButtonToScreenMenuWithBlendingUnk (0x00464370), which five
paths tail-call. reccmp 100.0, normalized 100.0, no diff line. Without the callees' files in the list the function
reads 99.4% (100.0% normalized): the tail jumps then go to a trampoline, and four of the five read differently.

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
* reimplement: SHC_3BB0A8C1_0x004AC7A0 100.0% Reimplemented

Allies::MenuItemRenderFunction_Allies_Main, rewritten from the original's listing. gynt's draft: 1f983fe at 52.27%
("reordered stores") on his fork's reimpl/UI-MenuItems-development, whose status line records 52.3% (the newest
commit on the file there is dd1a7c4, a style commit); his reimpl/UI-MenuItems has 8533b17 at 47.09%, status line
47.1% ("Style pass, asm differs"). Our draft (89a680f, then f8721e5 and 07a33e2; 52.8% in the draft PR sourcehold#328)
was his code with a mechanical pass.

The function draws the allies screen, one menu item per call, chosen by the item's number: 1 to 6 an ally's portrait
with its signs (the resource it asks for, help needed, its orders); 10 the panel, its frame tile by tile and the
selected ally's name, request, orders and help text; 200 the help line, whose text items 20 to 22 choose while the
mouse is on them; the items above 19 and -1 a plain button; 110 and 111 the selected ally's button, shown while it
needs help or has asked you to attack. Without allies every item but -1 is off.

Behaviour fixes against the draft, each in the draft's own listing. Most of its ranges were separate ifs without a
return, so:

- Without allies it set the two flags and went on to draw the item. The original returns (0x004AC7D6).
- 110 and 111 ran on after their button into the code for 200 and the rest, which drew the plain button too. The
  original leaves through the first (a tail jump at 0x004AD0FC).
- 200 ran on after the help line, cleared ButtonUnknownZero and drew the plain button. The original returns after
  the text (0x004AC841).
- 7 to 19 other than 10, and 22 while the mouse is on it, drew the panel. The original returns for them (jne at
  0x004ACB92 to the return at 0x004ACB89, 0x004AD0AA).
- A portrait item past the number of allies cleared ButtonUnknownZero and went on with that index. The original
  returns (jge at 0x004AC86C).
- An unselected ally's portrait returned after its picture when it showed lord icon 0 or 1 or an AI lord, so the
  signs on it were not drawn. The original goes on to the signs (0x004ACA42 falls into 0x004ACA47).
- The selected ally's portrait returned after its frame: no signs either (0x004ACA77 falls into 0x004ACA7C).
- The ally's request that you attack: with a player as the target the draft drew the face and its frame, then the
  target's picture a second time and an AI lord's picture over them. The original returns after the frame
  (0x004AD012).

What decided the match. The counts are differing lines of our own exact listing compare against the original's 702
instructions (operands with the original's addresses and every jump's landing), each with that one thing changed
from the final code, which has 0:

- The parameter is reused: the portrait steps it to the ally's index, copies that, and then stores the ally's player
  ID in it; the panel stores the selected ally's player ID in it too. A variable of its own for the player: 281; for
  the index: 169; for the panel's player: 13. The code reuses `button` for both, as AlliesOrder_Main on main does.
- The resource asked for is counted from wood on in a statement of its own (`resource -= RT_WOOD`), in both places.
  Inside the test: 155 and 123.
- The code for the items above 19 stands after the portraits' and the panel's (before them: 62), and the panel's
  after the portraits' (before them: 577).
- The portrait's blend (8 for the unselected ones) by if. As a conditional expression: 88.
- An unselected portrait's picture with a call in each arm. Its number in a local and one call: 80.
- Smaller: the panel's resource test `< 0` with the "no request" text first (the other way: 8), the player's ID read
  once into a local (twice: 12), the target picture's x before its y (20), new variables for the last picture's
  position rather than changing x and y (4), the frame's row number with no first value (7 as its first value: 36),
  the target's picture called in each arm of its test, in both places (called once before the test: 73 and 41).

These gave the same code, and the plainer form stands: 110 and 111 first with a return (the original has their code
at the end), their flag by an early return or by if / else, the AI lord's text number's operands in either order,
the frame's row number by if / else or by conditional expressions, the range test 0 to 19 as two compares or as one
unsigned compare, the step to the index as `button--` or `-= 1`, the frame's middle columns skipped by an else-if or
by a nested if, `button` written directly or named through a reference, and 20 to 22 as an else-if chain or as ifs
that each return.

The text numbers carry their texts from the game's cr.tex (TEXT_ALLIES) as comments. Neither they nor the other
comments change the listing: this code compiles to the same instructions, line for line, as the code the narrow
build with the callees and the full build measured (0aae52a5f's).

Measured in a narrow build on main 3458fea of that code and the eight finished functions it calls, struct
resolvers and their resolvers on: renderGM (0x00455300), drawBitmapFace (0x0044CD40), renderGMWithBlending
(0x00455390), renderGMWithAlphaMask (0x004557B0), renderFacesSmallUnk (0x0044CE00), isAIPlayer (0x004010B0),
RenderCurrentNotActiveButtonWithPossibleAlphaTexOnCurrentSurfaceUnk (0x004640D0) and RenderButtonImageWithBlending
(0x004641A0), which 110 and 111 tail-call. reccmp 100.0, normalized 100.0, no diff line. The two of them on main's
/GL list read lower in that build (RenderCurrentNotActiveButton... 54.8, RenderButtonImageWithBlending 58.3), as
their own callees are not in it. With only this file, as committed, in the list, the callees' resolvers off, the
function reads 100.0 (100.0 normalized) too. Not run in game.

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

* fix: Allies_Main reads PlayerData's goods requests by their new names

Main's Ghidra sync 1af4c70 (for sourcehold#403) renames PlayerData::requestedGoodsArray1Unk and requestedGoodsArray2Unk to
goodsRequestTypeByPlayer and goodsRequestAmountByPlayer (the same offsets and types), so the three reads here use
the new names. No other change.

Measured: quick_diff on 48f7e94's headers gives the same listing as the pushed head's text on main 0e4a83b's.

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
…#448)

General::MenuItemRenderFunction_General_AdvancedGameOptions, rewritten from the original's listing. gynt's draft:
fd61234 at 40.37% ("reordered stores") on his fork's reimpl/UI-MenuItems-development, whose status line records
40.4% (the newest commit on the file there is e63ae30, a style commit); his reimpl/UI-MenuItems has 2c82038 at
40.03%, status line 40.0% ("Style pass, asm differs"), after 77fde36 at 41.32%, his highest there. Our draft
(530c671, then 53bea5f and 07a33e2; 42.5% in the draft PR sourcehold#328) was his code with a mechanical pass.

The function draws the advanced game options of the lobby and the skirmish setup, one menu item per call, chosen by
the item's number: a label at the left and the option's value at the right (a text, a number, or a tick picture for
the on / off options). It draws nothing behind the map dialogs, the round table and the lord choices, only the
skirmish options' own items while those are open, and some items only for the host or outside a single player
skirmish.

Behaviour fixes against the draft, each in the draft's own listing. Most of its items had no return, so they ran on
into the code that draws the other items' label, with their own number as the text's number:

- 31 (tech level), 36 (win condition), 83 (troops) and -1000 (the Back button) drew a second text after theirs, text
  number 31, 36, 83 or -1000 of TEXT_XPLAY_WAITING_ROOM. The original returns after each (0x00428C8F, 0x00428CE6,
  0x00428D8A, 0x00428E8B).
- 103 did the same after its button, and with the colour unset. The original leaves through the button's function (a
  tail jump at 0x00428E97).
- -11 (no dogs) and -13 (extreme mode) drew that second text after their tick picture. The original returns
  (0x004290E5, 0x00428FBA).
- -12 (no rush) drew it after the value text for setting 5. The original returns (0x00429318).
- 99 (strong walls) never returned: after its picture the draft went back to its own text and picture, an endless
  loop. The original returns (0x004290E5). gynt's fd61234 and 2c82038 end 99 with the same goto into -11's block
  and loop too; his 77fde36 has a return in that block's ticked arm, so there 99 loops only with strong walls off,
  and with them on it returns without the picture, leaving drawBufferChoiceValue at RT_SCREEN_MENU (2c82038, "bug
  fix", took that return out).
- 100 (alliances) drew both value texts, 101 and then 102, when alliances are off. The original draws one of the two
  (0x004295D3).

What decided the match. The counts are differing lines of our own exact listing compare against the original's 961
instructions (operands with the original's addresses and every jump's landing), each with that one thing changed
from the final code, which has 0:

- The item blocks in the original's order, each ending in a return: 36 before 31: 217; 103 before -1000: 32; 99
  before -10: 56; -12 before -10: 486.
- 83's value text number is held in the parameter: the code stores 84 in `button` for troops that cost gold, as
  AlliesOrder_Main on main does. With a variable of its own: 877; with a call in each arm: 802.
- The colour is set before the call in the interacting arm and after it in the other (the other way: 342 and 2), and
  it has no first value: 103 never sets it (with `= 0`: 30).
- The flag items' tick picture with a renderGM call in each arm. One call with a conditional expression: 705.
- The alpha written out in every call. One local for the items from -10 on: 352.
- No-rush and auto-save test each value in its own if. As else-if chains: 43 and 27.
- Smaller: the tech level's text number computed whole before the first call (only `/ 2` early: 4; in the call: 19),
  109's number in a local with one call (a call in each arm: 44), 100's alliances as a truth test (`== 0` with the
  arms swapped: 6).

These gave the same code, and the plainer form stands: the modal filter as one else-if (nested ifs tie), the single
player filter as one condition, 103's flag in a nested if, 109's number by if / else (where the draft added a
comparison to 109), the value's x as W + X - 20 or W - 20 + X, and 83's number in `button` written directly or named
through a reference.

The text numbers carry their texts from the game's cr.tex (TEXT_XPLAY_WAITING_ROOM, TEXT_SKIRMISH_MISC,
TEXT_GAME_OPTIONS) as comments. Neither they nor the other new comments change the listing: this code compiles to
the same instructions, line for line, as the code the narrow build with the callees and the full build measured.

Measured in a narrow build on main 3458fea of that code and the four finished functions it calls, struct resolvers
and their resolvers on: renderGM (0x00455300), renderBasicButton (0x00463A90), renderNonInteractingButtonBackground
(0x004246E0) and MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface
(0x00463FF0), which 103 tail-calls. reccmp 100.0, normalized 100.0, no diff line. The last of the four is on main's
/GL list and reads 67.3 in that build, as its own callee is not in it. With only this file, as committed, in the
list, the callees' resolvers off, the function reads 100.0 (100.0 normalized) too. Not run in game.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt added a commit to kotijekriv/OpenSHC that referenced this pull request Nov 24, 2026
…#468)

InGameMenu::MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange, rewritten against the original
instructions from Gynt's draft (d5895e2 at 29.4%, the file's newest commit on his fork's reimpl/UI-MenuItems;
before it 24.6% at 668d05f, 26.74% at cee8a6a and 35.68% at 1831d14; 29.1% at 8725ec5 on his
reimpl/UI-MenuItems-development; the 24.6% text, as cf563c2, on 20 of his other branches). The rewrite was first
in our draft sourcehold#328 (85.2% at ecef1ca, 93.3% at b730ba6).
One thing in the behaviour differs from his newest copies, as the original has it: the frame's copy
(scribeAnimationFrameCopy) gets the frame after a step of phase 0 or 2, where his 29% texts (from 65a026c on)
compare and store a local that those steps do not update (the original: 0x0043352B and 0x00433545 with the stepped
value). The returns he got right himself: his 24.6% text has empty bodies for the three returns (0x00433378,
0x00433381, 0x004333AF), which he restored in cee8a6a (the 60 ms one) and 1831d14 (the game modes);
cee8a6a also returned behind every step and at a sequence's end, which he took out in 65a026c ("switch was
unreachable"), as the original has it (0x00433485, 0x0043348A, 0x0043352B). Here the returns are the original's.
The 93.3% text had the original's 129 instructions with one difference: the zero the compiler keeps in a register
was in ebp, where the original has ebx (0x0043338F), and ebx was unused. Here:
- the phase is the global itself at each use, not a local that is loaded from it and stored back. A local is one
  more candidate for a register and took one in front of the zero; with the global the compiler keeps the phase in
  edi itself (0x004333B5, 0x00433472) and the zero gets ebx;
- the frame is written the same way (a local for it gives the same listing);
- each entry of a setting's sequence is read into a local and tested (the 93.3% text read the table twice, which
  this form no longer needs);
- the phase switch's cases are in the order 0, 1, 2, as the animation runs (the same listing).

No line for cmake/compiler-flags-gl.txt: the file reads 100.0% off the /GL list, and 100.0% on it too.

reccmp in a build of main's whole /GL list (the 133 files that exist) and this file, off the list, with every
resolver of those files on: 144 functions, average 99.56. The function 100.0% raw and normalised, no differing
line, and the same with the file on the list. The other 143 functions of main's list read the same as without the
file. The sources are main's at 3458fea; main's two commits since (02fab42, 812d149) add cmake files only,
with the new option off.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
kotijekriv and others added 4 commits November 24, 2026 10:29
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

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

This PR puts MenuItemActionHandler_TextEditor_TextInputRelatedUnk and Text/TextEditorState/helpToken.cpp on
cmake/compiler-flags-gl.txt. The handler calls helpToken_getHelpTokenAdvanceLength, below it, and gets an entry at
its address with that callee. The /GL lines stay as they are.

Measured as sourcehold#398's edges were: the handler's file compiled with helpToken.cpp in its unit, against the handler
alone, quick_diff on this head merged with main 7c2e4d6, every function resolver that has a .cpp and every
struct resolver on: 0.8291 alone, 0.9350 with helpToken.cpp. helpToken.cpp's two functions call no /GL-listed
function, so they get no entry of their own.

With every .cpp of that merge as the build list, cmake/function-visibility-units.py makes 25 units holding 110
source files (24 and 108 before): the handler and helpToken.cpp form a unit of their own. No internal names clash,
and the 13 names it skips are the ones main's manifest skips.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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>
kotijekriv and others added 2 commits November 30, 2026 10:06
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv and others added 2 commits December 4, 2026 18:16
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept.

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

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