Repository navigation
Reimplement 7 UI::MenuItems functions (draft, below 100%) - #327
Draft
kotijekriv wants to merge 71 commits into
Draft
kotijekriv wants to merge 71 commits into
kotijekriv wants to merge 71 commits into
Conversation
…ests fixed; block layout and register allocation gynt's draft (43.3% on his branch) with two fixes for the a521bf7 headers: setBottomLeftTextDisplayText takes an int as its 4th argument (the zeroed union local is gone), and Building's field at 0xC2 is field70_0xc2. The rest is the mechanical pass (decimal numbers, // comments, compound assignments, unused usings); quick_diff output identical. What is left is mostly block layout: 54 diff regions cover about 2000 of 2829 instructions. Behaviour fixes against the original's asm, which the draft still had: 18 dropped returns (the empty `if (...) {}` and five blocks that end in the original's epilogues or tail calls, e.g. 0x00434908, 0x0043492E, 0x00434C93, 0x00434CF8, 0x00436949); the six tactical-power range tests, where Ghidra's SBORROW had become an always-true compare (so a power was refused at every distance except exactly 2500 or 12544, and bVar15 / bVar16 got stray writes the function reads later), are `distance > limit` as the original's cmp / jle (0x00434E9E-0x00434EAA); and `extraout_ECX == 2` read an uninitialised local where the original's ecx still holds shiftRelated0or3 (0x004376E6). Mechanical: local_18 is an int, `+ TRUE` and the unitControlsRelated TRUEs are 1, `<= 200` / `<= 2401`, `--x == 0`, the shift as `shift ? 3 : 0`, and the decompiler's comments are gone. The `(-x & mask) + 2916` lines stay as they are: as a conditional they lose the match (0.5517 -> 0.4777 in quick_diff). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LobbyscreenStartButtonClick queues command 103 with the selected map's index as its parameter (button 105). The draft wrote it as GCT_SHARE_GAME_STATE_PARTIAL_HASHES | GCT_MULTIPLAYER_ANNOUNCE_HOST (100 | 3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Used by the drafts in the companion development PRs: LobbyscreenStartButtonClick and CrusadeMap_Main play sound 253 when they switch to the rankings screen. The LobbyscreenStartButtonClick draft wrote it as SEID_UNIT_DAMAGE3 | SEID_ARROW_SHOOT (248 | 5). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lobby's keep-position drag keeps the dragged player's position in DAT_00b95960 (-1 for none, compared signed: cmp/jl at 0x00442A29) and its slot index in DAT_00b95f64 (an array index). DAT_00b95b74 is the map description's height, used signed in the scroll limit. General_MenuMiniMap reads DAT_00b95960 here; the other users are drafts in the companion PRs (LobbyscreenStartButtonClick, MapEditorProperties_MainButtons, SingleplayerMapChoice_ButtonsAndHands). On main, DisplayMapDescriptionAndAllocatePlayersToSlots stores to DAT_00b95b74 and compiles to the same instructions with the int. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It is compared signed against 0 and 15 (cmp/jge at 0x00442683, jle at 0x0044269E). addChatMessageToDisplayList and clearChatEvents, its users on main, compile to the same code with the int (quick_diff identical). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xes; block layout Rewritten from gynt's draft (83.0%) as one switch: the original dispatches 105 and 413 with the table cases (cmp 0x69; jg; je; then the -201..4 jump table), so they are cases, not ifs before the switch, and the ~190 empty case labels are gone. Three behaviour fixes the original's asm shows: - load game (1) and start game (4) return as soon as an occupied slot is not ready (je to the epilogue at 0x004426CA / 0x0044282B); the draft only left the loop and carried on; - dropping a keep position (-201) ends with DAT_00b95960 = -1 on every path, and stops when no position is under the mouse; the draft's loop never ended in that case and skipped the reset after a swap. Command 103 and sound 253 have names (header commits), DAT_00b95960 / DAT_00b95f64 / DAT_00b95b74 and chatScrollOffset are ints, which removes the casts. The swap's temporary is an int, as the original's movsx shows. quick_diff 0.7976 -> 0.9274. Left: block layout - the original places the shared epilogue right after case -1 and falls into it there; ours puts it elsewhere, which shifts most jump displacements. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The TextEditor buttons render the label "Pic" (0x005A55E0, between "Link" and "ScrSize"), which had no entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… order, 3 behaviour fixes; scheduling gynt's draft (77.3% here) with the switches rebuilt from the original's tables: the outer cases in the original's layout order (-1, -2, -4, -5, the 1..15/20 buttons, 31..36), the button labels as a switch on the button number itself (it was param_1 + 5), and the first field52 switch with case 10 after case 3. Three behaviour fixes: button -5 drew its label twice when not pressed (the original returns after the first text call, 0x0045DF3B). Case -4 is an if/else with one call per arm. The 1..15/20 arm keeps the original's test of -4, which never matches there; one comment line says so. The "Pic" label has a string entry now (its own commit). Left: case -5's and the colour copy's scheduling. Pressed buttons 32 and 34 (arms 2, 3, 10 and 12) no longer return after setting the colours: the original goes on into the field52 switch (0x0045E5F8 -> 0x0045E617) and draws the box and "NEXT" (0x0045EAFA -> 0x0045EB0D). The no-op casts on DAT_Button* and textColor are gone, 255 is COL_0000FF, the alignment codes are plain numbers, and the "Back", "Exit" and "Pic" texts are commented (identical code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
InGameMenu_MainButtons plays sound 257 when it opens the pause menu, and 123, 124, 125, 126, 127 and 128 when it opens the build menu's tabs 10, 20, 30, 40, 25 and 28. The draft wrote most of them as ORs of unrelated sounds (SEID_SIEGE_EQUIPMENT_DESTROYED | SEID_INN is 124). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From gynt's draft (86.3% here). reccmp's raw 99.8% differs only in the target of the tail call to confirmAndQueueDestructionCommand; normalized 100.0%. The chain tests -1/-6 last (if (button != -1 && button != -6) ... else ...), as the original lays it out. Four behaviour fixes the original's asm shows: - pause button in siege-editor mode: the original returns after switching to the siege view (0x0044513E); the draft fell through and also opened the pause menu; - skirmish/scenario end (-5): the scenario-description path also switches the view and closes the three modal dialogs (the draft returned early); - buttons 71..79 in the editor or siege-editor mode clear DAT_StopHandlingMenuItems and return (0x00444ECC to 0x00444D60); the draft carried on into the menu switch; - closing the building help with those buttons carries on into the menu switch (call at 0x00444EE9, no return); the draft returned. Sounds 123-128 and 257 have names (header commit), the editor slot index is one local, the nine player-ID clears are a loop, and the keep-and-granary test calls its checks inline instead of through temporaries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er and store order; register allocation gynt's draft (83.3% here) with the -1 and -2 arms as the original lays them out: the repeat clamp in case 4 falls through into the minimum check (no early return), the minimum clamp stores the value first, both arms write case 7 out (the original shares one block between them, so the goto into -2's case 7 is gone) and -2's case 7 comes before case 4. The minimum, maximum and current values are stored in the original's order in -2's cases 1-3 and in the action arm's case 1 (stores through the three pointers keep source order). quick_diff 0.7797 -> 0.8373. Left: register choice in the -2 arm, one byte longer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SelectCrusade_Main clears the menu tab to switch to with 0 (no tab), and MissionEndscreen_Main stores 0 into the active tab. The ChooseNetworkServiceProvider_Buttons draft in the companion development PR uses it too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… are ints The map editor compares the active brush and the affect type signed (jle at 0x00431563 and 0x004315E3, jge at 0x004317D3) and halves the brush with sar. switchToMenuView on main and InGameMenu_MainButtons here compile to the same code (quick_diff identical); the other users are drafts in the companion development PRs (MapEditorLandscaping_GeneralButtons, MapEditorLandscaping_QueueCommandCallback). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed brush store gynt's draft (81.1% here) as one switch without gotos: AREA_BACK is a case of it (the original dispatches it next to the table, cmp 0x14b; je), AREA and AREA_BACK each write their brush step in full, and every big-rock case writes its odd-brush adjustment itself; MSVC merges the rock cases' identical tails again, as the original does. The brush, its half-size and the affect type are ints (header commit), so the compares are signed as in the original. quick_diff 0.7430 -> 0.8145. Left: the original shares one brush store between AREA's and AREA_BACK's adjustments (cross-jumps between the two cases); written out per branch, ours stores in each. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sound 146 is the menu buttons' hover sound: NewMapMapsize_Buttons and NewMapMaptype_Buttons play it when the cursor moves onto another button, and so does the HistoricCampaignSelect draft in the companion development PR. 251 has no user in these PRs: the main menu render function, which is not in them, plays it when the cursor first moves onto button 5. The drafts wrote them as SEID_CHILDREN_PLAY_MAYPOLE | SEID_WOOD_CHOP (144 | 2) and SEID_UNIT_DAMAGE3 | SEID_WOOD_SAW (248 | 3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (94.0%). The original returns as soon as a modal dialog is open (call, test, jne to the epilogue before any register is saved) and reads the button position afterwards; the draft read the position first and wrapped the body in an if. The position loop is a for loop instead of do-while, the locals are named (keepX, drawX, player, playerIndex) and the casts are gone: the fields are already char and int. Raw 98.5%: only the type name in the symbol of DAT_00b95960 differs (int here, unsigned int on the original side), the address is the same; normalized 100%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (89.1%). One behaviour fix the original's asm shows: in case 5 the original opens the quit dialog only when INT_00b95f68 is set, and otherwise only switches to the custom scenarios menu; the draft opened the quit dialog on both paths. The player slot is read once into a const local, as the original keeps it in a register for every playerDataArray store, startResources is indexed by RT_GOLD / RT_STONE, and the map name is STR_Mission22Map from string-literals.hpp. Left: the original loads ecx for importTradingCosts after the three playerDataArray stores, ours before them; reordering the stores around it made it worse. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DAT_TutorialCurrentStep and DAT_00df5554 are compared signed everywhere the original reads them (jl / jle in the tutorial box handler), so they are int, like DAT_00df5558, DAT_00df555c and DAT_00df556c, which main's header sync 7c6bb9e already has as int; that removes the casts in the tutorial box handler. Their other users compile to the same instructions (only the resolver symbols' type changes): GetCurrentTutorialStep on main and the tutorial box render function here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (88.0%, the same code). Named locals (traderIndex, resource, icon, imhIndex), GM_INTERFACE_ICONS2 for the GM index, early returns, no casts. The draft's comment on the second text said "On"; the game's text table has 173 as "Off". Left: register allocation in the text position sums; the compiler normalises the operand order, so no spelling moves it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…allocation Rewritten from gynt's draft (95.6%). One behaviour fix the original's asm shows: a crusader or arabian button that is not the current choice falls back to the default button render (jne to the RenderScenarioButtonWithText call); the draft fell through into the bandits case and drew it as a bandits button. The highlighted text is chosen by if/else around one call each, which MSVC merges into the original's single call with a branch on the colour push; a ternary compiles branch-free instead. The " - " string is s___005a2304 from string-literals.hpp, COL_CCFAFF names the highlight colour. Left: register allocation around the name width. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r allocation Rewritten from gynt's draft (96.8%). Two behaviour fixes the original's asm shows: the month button (-1) returns after drawing its text once, in the plain or the highlight colour; the draft drew the plain text and then the highlighted one over it. An invader button whose choice matches returns after drawing; the draft also fell into the default button render. The draft's comment "Crusader. Arabian. (...)" is replaced by the list of invaders the buttons stand for (cr.tex: rat, snake, pig, wolf, other, crusader, arabian). Left: one register choice in the invader text call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…al's order, no goto; scheduling Rewritten from gynt's draft (93.4%). The inner switch has its arms in the original's order (50, 100, then 10 falling into the slider set-up) and returns from default instead of jumping to a label. The second column's buttons adjust param_1 itself and a copy drives the inner switch, which is how the original keeps them (edx and esi); the slider value and destination are read in place rather than through a local pointer; the popup delay is stored first, as in the original. The pointer to the event type stays: without it the match halves. Left: one store scheduled differently and an lea / add choice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d; scheduling Rewritten from gynt's draft (96.9%). The draft computed the speech file name as a raw address (counter * 0x60 + 0xb3d810); it is MissionAestheticsDefinedData::field112_0x41e4[counter], a char[3][32] per entry. Taking a pointer to the name before the counter is incremented matches better than indexing in the call. The hand-written security cookie is gone (the compiler adds it for the char buffer), the tutorial counters are ints (header commit), early returns, and the player slot is read inside the step-14 test, as the original does. Left: the order of two loads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The old title menu's exit button renders the label "Exit" (0x005A22D0, between "FireFly's" and "Continue"), which had no entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The AI lord select handler queues command 112 with the slot it filled as its parameter, after a lobby AI is added (111 is GCT_SKIRMISH_ADD_AI_PLAYER). The draft wrote it as GCT_SEND_RESYNC_TILEMAPDATA2 | GCT_LOAD_MAP_HEADER (64 | 48). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (95.3%). One behaviour fix the original's asm shows: when no slot is free the original closes the dialog and returns (0x004AE82B); the draft's while loop reset the dialog but kept going past slot 8. The free-slot search is a for loop with a break, and the occupied-slot count a for loop that MSVC unrolls into the original's eight tests (writing them out by hand gives the same code). Command 112 has a name (header commit) instead of GCT_SEND_RESYNC_TILEMAPDATA2 | GCT_LOAD_MAP_HEADER. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (98.0%). One behaviour fix the original's asm shows: the larger font is for French, Italian and Spanish only (an unsigned range test, cmp 2 / ja); the draft's signed `gameLanguage - GL_FRENCH < 3` also took English, American and German. Written as GL_FRENCH <= language <= GL_SPANISH, which MSVC compiles to the same test. Sound 146 is SEID_UNKNOWN_0x92 (header commit), the text comments come from cr.tex, early returns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt's draft (97.3%) passed the literal "Exit", so reccmp saw our own copy of the string; with the string's entry at 0x005A22D0 (string commit) it is s_Exit_005a22d0 and the function matches. Also COL_0000FF for the text colour and no casts; the button width passed as the alignment stays, with a comment, because the original does that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (98.7%, the same code): early returns, the branches in the original's order, sound 146 as SEID_UNKNOWN_0x92, the campaign names from cr.tex. Left: the original loads ecx for getTextStringInGroupAtOffset between its two pushes; ours after them. No spelling of the text index or the position moves it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (98.4%, the same code). The draft read SEC_MercRecruitable[param_1 - 7], a negative index; the address is barracksRecruitability.array.barracksRecruitability[param_1], as the handler for the same screen reads it. Early returns, `param_1 >= 0 && param_1 <= 7` instead of the unsigned cast, COL_CCFAFF, no casts. Left: one push 0 that the original schedules before the sar of the text position. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6and8
pushed a commit
to 6and8/OpenSHC
that referenced
this pull request
Nov 8, 2026
* reimplement: SHC_3BB0A8C1_0x004BBF40 100.0% Reimplemented Moved here unchanged from the draft sourcehold#328 (reimpl/UI-MenuItems-3-development-2, 13fbfea). It was 100% before the header sync a9401a7 and 92.3% on sourcehold#328's base 72b2732, where MSVC stopped sharing the tails of its two number calls. On main 57d3334 it compiles to the original's 100 instructions again, with the shared tail. quick_diff is left with its own artefacts only: the jump-table spelling, the colour immediates, the picture table's address written as its base less 14, and ret / ret 0. reccmp: 99.2% raw and 100% normalized, where only the picture table's address differs (reccmp shows it as an offset into DAT_GMImageHeaders), which the project records as 100%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MenuItemActionHandler_InGameMenu_Scrolling takes no parameters The original ends with push 1 / call RecordTutorialPlayerAction / pop ecx (0x00434200 to 0x00434207). Declared (int, ...), our function tail-calls through its own argument slot instead (mov [esp + 4], 1 / jmp), which MSVC can only do when the function has a named parameter. Only the menu tables refer to it (six dwords, no call), and like WaitingForHost_ConnectToLobby it never reads an argument. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: SoundEffectID values 254 to 256 as SEID_UNKNOWN_<hex> LobbyMenu_SkirmishTypeAndBalance plays them when the balance changes: 256 at either end (buttons 10 and 14), 255 one step from even (11 and 13) and 254 at even (12); the pushes are at 0x0042A888, 0x0042A8A1 and 0x0042A8B5. The draft wrote them as (SoundEffectID)0x100 and as SEID_UNIT_DAMAGE3 | SEID_PEOPLE_ARE_COMING_TO_THE_CASTLE (248 | 7) and SEID_UNIT_DAMAGE3 | SEID_ARROW_KILL (248 | 6). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0042A840 100.0% Reimplemented From gynt's fork branch reimpl/UI-MenuItems-100, 97.6% there. On main's headers it compiles to the original's 41 instructions, and quick_diff differs only in its own ret / ret 0. The style pass names the parameter and the button ranges, and the three sound effects by the names the previous commit adds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004D99F0 100.0% Reimplemented From gynt's fork branch reimpl/UI-MenuItems-100, 97.6% there. Rewritten without the decompiler's gotos, it keeps the original's 85 instructions. quick_diff's differences are its own: ret / ret 0, and the tail jump to MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface at 0x004D9A4F, which our listing writes as jmp trampoline<4603888> (0x00463FF0) and quick_diff does not count as a function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00442C30 100.0% Reimplemented Moved from the draft sourcehold#318 (reimpl/batch2-development 49a51e7), 92.6% there. The search for a siege unit now sets a flag and leaves the loop, so its exit jumps past the clearing as the original's does (jg at 0x00442DE3 to 0x00442E64) instead of testing p == end after the loop: quick_diff 0.9753 -> 0.9807. A goto, a flag over the pointer loop and a flag over an index loop all measure the same; the index loop reads best. What is left is quick_diff's own: the security cookie, the timeGetTime import call, ret / ret 0, and the 11 bytes of alignment before the copy loop at 0x00442EA5, which the original's assembler wrote as a jmp over the filler. The style pass replaces the pointer loops with index loops over the 21 counts and returns early for maps that are not sieges. Clean alone build: reccmp 98.9% raw and 100% normalized. The two raw differences are one address, the end of the siege search loops (cmp eax, 0x00B95B1C, one past DAT_SiegeInformationArray), which reccmp resolves to the next global in the original and to our array's end in the DLL; the project records that as 100%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0047E420 100.0% Reimplemented From gynt's reimpl/UI-MenuItems (PR sourcehold#254, closed), 74.1% there. The label is drawn in two calls with the same colour, one per hover state, and the position goes through two locals computed before them: MSVC then merges the two calls but for the text ID's push (the jne at 0x0047E45D). One call is quick_diff 0.8136, the position inside each arm 0.5479, this form 0.9375, which leaves only the colour immediate and ret / ret 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00434120 100.0% Reimplemented Moved from the draft sourcehold#327 (reimpl/UI-MenuItems-3-development c1c152b), 89.9% there. With the header taking no parameters (previous commit) the closing RecordTutorialPlayerAction(1) is a call again rather than a tail call: quick_diff 0.9343 -> 0.9710, left with the jump-table spelling and ret / ret 0. The comments now say what -1000 does, and that the frame-rate formula makes up for only part of the slowdown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00442F40 100.0% Reimplemented From gynt's reimpl/UI-MenuItems (PR sourcehold#254, closed), 77.4% there. The cases now come in the original's order, 1, 2/3, 4, 7, 5, 6, as in LobbyMenu_MapSelectScrollbar on main: the original lays the blocks out in that order (case 7's store at 0x00442FDA sits between case 4 and case 5). quick_diff then differs only in its own jump-table spelling and ret / ret 0. The style pass names the parameters as the LobbyMenu scrollbar does and writes - 13 and ++ / --. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0047CCA0 100.0% Reimplemented From gynt's reimpl/UI-MenuItems (PR sourcehold#254, closed), 73.6% there, after main's renames (isNameEntryActive). Each case now computes the text's position, fetches the text and draws it itself: MSVC merges the copies of cases 0 to 3 into one tail but for the push of the text's index, as the original has push 5 / push 6 / push 7 / push 0 before its shared tail at 0x0047CDE7; case 4 keeps its own call and the surface reset. With one call after the switch the index goes through a register (quick_diff 0.9365); this form is 0.9664, which leaves the jump-table spelling, the colour immediates and ret / ret 0. The cursor's bottom is written DAT_ButtonY + DAT_ButtonH - 4, the order of the original's lea (0.9030 -> 0.9365 by itself). == TRUE stays: the original compares with 1, and a truthiness test is 0.9365. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: DAT_SH1_SiegeAdvancedMode is a BOOLEnum It was undefined4. Every store is 0 or 1: the toggle xor [0x00B960C8], 1 at 0x0042D81F, 0 at 0x0042D855 (edx, 0 in that handler) and 0x00448DC2 (ebx), 1 at 0x00442E66; the decompilation agrees (SingleplayerMapChoice's MapTable stores 1, ButtonsAndHands toggles it and stores 0, SingleplayerMapChoice_Prepare stores 0), and every read compares with 0 (spawnQueuedReinforcementWaves, LaunchSinglePlayerGameUnk). A linear sweep of the exe's code finds every absolute reference; reads and writes through a pointer to the struct are not covered by that, and the decompilation shows none. Its one user in the code, this PR's MenuItemActionHandler_SingleplayerMapChoice_MapTable (0x00442C30), stores 1 and compiles the same (quick_diff 0.9807 before and after); main has none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: DAT_StoredGameMode is a GameModeInt It was undefined4. Its one store, at 0x004D972A (MenuView_RankingGames_Prepare), copies GameSynchronyState.currentGameMode (0x0191DD80, a GameModeInt), and its one read, in MenuItemActionHandler_RankingGames_Main, copies it back. Both are on main and compile the same; the copy no longer converts between unsigned and int. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: DAT_SkirmishTrailRelated1 is an int It was undefined4. It is a count that can go below 0: MenuView_CrusadeMap_Prepare (0x004D8CB0) stores 3 (0x004D8D48), decrements it once per mission skipped with the chicken and stores the result (0x004D8DD5), then clamps it at 0 with a signed test (cmp edx, edi / jge at 0x004D8DDB); 0x004D8F3B subtracts from it in memory. Main's user, MenuItemRenderFunction_General_CrusadeMapAndEndscreen, tests it with a signed > 0 through an (int) cast, which the next commit drops; it compiles the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MissionDefinedData.descending is a BOOLEnum It was undefined4. MenuItemActionHandler_RankingGames_Main (0x004D9730) is its only writer: it stores 1 at 0x004D995F when a new column is picked and 1 - descending at 0x004D9970 / 0x004D9976 when the same column is picked again, so it only holds 0 and 1. A linear sweep of the exe's code finds every absolute reference; reads and writes through a pointer to the struct are not covered by that, and the decompilation shows none. The handler is on main and compiles the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: TileMapState.wallDragButtonUp is a BOOLEnum It was undefined4. Its only store, in MenuItemActionHandler_InGameMenu_TriggerPlaceWallCommand at 0x0043803E, writes the result of a sete (0x00438034), so it only holds 0 and 1. A linear sweep of the exe's code finds every absolute reference; reads and writes through a pointer to the struct are not covered by that, and the decompilation shows none. The handler is on main and compiles the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * CrusadeMapAndEndscreen: drop the (int) cast DAT_SkirmishTrailRelated1 no longer needs DAT_SkirmishTrailRelated1 is an int since the commit before this one, so the signed > 0 test needs no cast. It compiles the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * SingleplayerMapChoice_MapTable: store TRUE in DAT_SH1_SiegeAdvancedMode The global is a BOOLEnum since the header commit before this one. Same code (quick_diff 0.9807 before and after). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
6and8
pushed a commit
to 6and8/OpenSHC
that referenced
this pull request
Nov 8, 2026
…old#352) * reimplement: SHC_3BB0A8C1_0x004C1070 100.0% Reimplemented MenuItemRenderFunction_TraderSettings, from our draft on the fork branch reimpl/UI-MenuItems-3-development (88.0% there, in sourcehold#327). Each goods row shows the good's picture and "On" or "Off" (greyed out by blending when off); below 1000 are the dialog's own buttons, 1100 is the "Trader 1" header box and the rest is the goods list box. The "On" and "Off" texts take their position as locals, y then x (in the call: quick_diff 0.9570 -> 0.8865; x first: 0.9140), the draft's register blocker. The four kinds of button are one if/else-if chain with a single RT_MAP_GAME store at the end, which MSVC duplicates into each tail as the original has it (ties with the seven early returns). The parameter is button and the goods index row, as in main's TraderSettings handler; the shadow colours are COL_003E66 and COL_000000; partial pitch's picture is pitch's, with a comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004ABEB0 100.0% Reimplemented MenuItemActionHandler_EditorMapTypeQuickChange_Main, from our draft on the fork branch reimpl/UI-MenuItems-3-development (94.5% there, in sourcehold#327). The editor's quick buttons set the map lock state (0 to 2), the map type (3 to 6, unless the map has an event that needs another), single or multiplayer (10, 11), or the map size (20 to 23, MC_MAP_SIZE_*), which resets the map and everything that depends on its size. The parameter is button, as in main's render function of this menu. The map size chain has no else, as in the original: button is 20 to 23 in that case, and the original's unreachable else reads mapSize unset, which MSVC keeps in the parameter's stack slot (`mov eax, [esp + 8]` at 0x004ABF39). An else keeping button measures reccmp 94.5% (the draft); reassigning the parameter instead of a mapSize local: reccmp 89.5%. The sizes are compared in turn (a switch: reccmp 85.5%). For the PR text: an uninitialised read, but only on a path no caller can reach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004B8BF0 100.0% Reimplemented MenuItemRenderFunction_EditScenario_EventAndInvasionList, rewritten from the binary (gynt's draft from his fork's reimpl/UI-MenuItems-development, 79.5% in sourcehold#328). One row of the scenario editor's event list: the selection is clamped to the list, the row's background, the event's month and year, and then by its kind an invasion ("Invasion", its unit count and the repeat) or an event (its name and the repeat). The draft returned when an event's text index went past 155. The original adds 21 there and goes on (the event names have 21 other texts after the 28th), so events of those kinds lost their name and repeat in the draft. Both kinds end in "Month" or "Months" written out in each case, with one ")" after the switch: MSVC merges the two if/else copies into the original's one tail (a flag set in both cases and one if after the switch: quick_diff 0.9831 -> 0.7973). The month goes into a local first (in the call: 0.9831 -> 0.9155) and the event name takes its position as y then x locals (0.9696); without them the scratch registers rotate and the copies don't merge. The event index is written out at each use because the original re-reads eventListScrollOffset after every call (an eventID local: 0.6609). The colour is set in each branch (a default overridden: reccmp 100.0% -> 99.3%, which quick_diff can't see: it shows both colour constants as one token). quick_diff's 0.9831 is all artifacts (colour immediates, ret). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MapPropertiesState::sumUnitCounts returns int sumUnitCounts (0x004B8000) adds up the unit counts of the current event, stores the sum at this+0x14548 and leaves it in eax. EditScenario's TextBoxLike render (0x004BF1D0) pushes that eax straight into renderNumberToScreen2 for box 101, so the function returns the sum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MapPropertiesState::indexStored is an int indexStored (0x00013580) picks the starting good, unit or popularity that the scenario editor's text box edits. EditScenario's TextBoxLike render (0x004BF1D0) compares it signed (cmp eax, 0x14 / jge at 0x004BF37C and cmp eax, 0x1e / jge at 0x004BF3AF), so the field is an int, not undefined4. Main's two users, EditScenario's EventAndInvasionList handler and the TraderSettings handler, stay at 100% with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MapPropertiesState::SEC_SiegeInformation is an int[20] The scenario editor's starting units sit at MapPropertiesState+0xEC, right after SEC_StartingResources. EditScenario's TextBoxLike render (0x004BF1D0) stores box 3's typed value for indexStored 20 to 29 at [indexStored*4 + 0x016538F4] (0x004BF3C9, 0x004BF3F5), which is element indexStored - 20 of the 20 ints at +0xEC, and sumUnitPoints (0x004B7FA0) adds them up from +0xEC. As an array the code indexes it inside its bounds instead of past the end of SEC_StartingResources. The units are in SiegeUnitCounts' order (archers first). No .cpp on main reads the field; MapAndTimeState::siegeInformation keeps SiegeUnitCounts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: TextArrayIndexType gets TAIT_UNKNOWN_10, _12 and _14 EditScenario's TextBoxLike render (0x004BF1D0) compares the user text handler's textArrayIndex with 10, 12 and 14 (0x004BF281, 0x004BF331, 0x004BF426, 0x004BF47E) and reads those text slots, next to 11 and 15, which the enum already names TAIT_UNKNOWN_11 and TAIT_UNKNOWN_15. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004BF1D0 100.0% Reimplemented MenuItemRenderFunction_EditScenario_TextBoxLike, rewritten from the binary (gynt's draft from his fork's reimpl/UI-MenuItems-development, 81.2% in sourcehold#328). The scenario editor's text boxes: boxes 0 to 7 show a text slot of the user text handler, with the cursor when that slot is being typed into; box 3 stores the typed starting good, siege unit or popularity, box 7 an event condition value; 100 to 102 show unit totals. Each box renders its own text, as in the original: MSVC merges the identical endings, so each case keeps its own y, x and slot push before the shared getTextArrayPointer call (one call after the switch: quick_diff 0.9606 -> 0.9356). The y, x and text locals stay (positions in the call: 0.8724; the text in the call: 0.8459). The totals are read into locals before their render calls, as the original calls the sum first. quick_diff's 0.9606 is all artifacts (colour immediates, ret, the jump table). Box 3 with indexStored 20 to 29 stores into the siege units (SEC_SiegeInformation[indexStored - 20]); the draft wrote SEC_StartingResources[indexStored + 5], past the end of that array, which lands on the same address. reccmp reads 99.1%: only the call target of atol differs (the CRT's against the game's copy at 0x00583628), as in main's NewEvent handler, whose status line has the same remark. It needs the four header commits before it: sumUnitCounts returns int, indexStored is an int, SEC_SiegeInformation is an int[20], and TAIT_UNKNOWN_10/12/14. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: DAT_00eb0b24 is an int DAT_00eb0b24 (0x00EB0B24) is a counter that ScenarioDescription's Main handler (0x004D8570, button -4) steps and wraps against INT_00ed27c4: mov eax, [0x00EB0B24] / add eax, 1 / cmp eax, [0x00ED27C4] / jl at 0x004D89B2. The compare is signed, so the global is an int, not undefined4. Nothing on main uses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004D8570 100.0% Reimplemented MenuItemActionHandler_ScenarioDescription_Main, rewritten from the binary (gynt's draft from his fork's reimpl/UI-MenuItems-development, 64.5% in sourcehold#328). The mission briefing's buttons: 10 starts the mission (the map and its lord unless in the builder, then the build menu), 12 and 13 go back to the map choice in the builder, 11 goes back to the mission select (or asks first while a game is suspended), 6, 8 and 9 switch the help pages (9 opens mission<N>.hlp), -1 steps the difficulty, -2 views the briefing, -3 asks to restart the mission and -4 goes to the next description page. Three behaviour fixes against the draft, all from the binary: a mission number of 0 or less becomes 1 and the mission still starts (the draft returned), the difficulty wraps from 3 to 0 and is still stored (the draft returned), and -1 doesn't fall into -2 (the draft set DAT_00ed27bc there). Three more of the same kind: 11 with DAT_00ed27bc set clears it and returns, 11 outside a campaign mission returns after switching the menu, and 12 or 13 in the builder with a game suspended returns after the yes/no dialog (the draft fell through in all three). 12 and 13 fall into 11 outside the builder, as in the original. The build menu tab is BMTT_CASTLE (10; the draft had BASMTT_HUNTERSHUT, the same value in the building menu's enum) and the landscaping tab 231, as main's hideOrUnhideUI writes it. Needs the DAT_00eb0b24 header commit before it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: ScenarioDescription_Main after the INT_00eb0b24 rename The Ghidra header sync 8125c61 renamed the global DAT_00eb0b24 to INT_00eb0b24 (it took in this branch's own int retype, so the merge above drops that header commit's file in favour of main's). The ScenarioDescription render (0x004D8570) still includes and names it in the old form, so it no longer compiles on main's headers. This follows 8125c61, as sourcehold#350 did for INT_00ed3120: the include and the name become INT_00eb0b24, and clang-format re-sorts the include lines. The type is int either way, so the generated code is the same and the function keeps its 100% status line. Globals: DAT_00eb0b24 -> INT_00eb0b24 (8125c61) - UI/MenuItems/ScenarioDescription/MenuItemActionHandler_ScenarioDescription_Main.cpp Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: DAT_00ed27bc is a BOOLEnum The scenario description's "briefing is open" flag only ever holds 0 or 1. Its three stores in the exe: 1 at 0x004D895F ("View Briefing", -2), 0 at 0x004D8788 (11, esi, which ScenarioDescription_Main zeroes there) and 0 at 0x004DD2CD (esi, the same register that resets the page index to 0 at 0x004DD2B7). Its readers compare it with 1 or with a zero register (0x004D8296, 0x004D877F, 0x004DD42D, 0x004DD6F4). BOOLEnum is a typedef of int, so the size and every access stay the same. Its only user on main and in this PR is ScenarioDescription_Main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: ScenarioDescription_Main stores FALSE / TRUE into DAT_00ed27bc DAT_00ed27bc is a BOOLEnum since the header commit before this one; the two stores (11 closing the briefing, -2 opening it) use its names. The same code (reccmp 100.0%). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MenuItemActionHandler_ScenarioDescription_Main: use main's INT_00ed27bc gynt's header sync (eef6f66) renamed DAT_00ed27bc to INT_00ed27bc, an int; this branch had typed it a BOOLEnum (8f6a96a), and the merge before takes main's. It is tested against 1 and set to 1 and 0, so TRUE and FALSE become 1 and 0. reccmp 100.0%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
6and8
pushed a commit
to 6and8/OpenSHC
that referenced
this pull request
Nov 8, 2026
…ehold#354) * headers: IngameScenarioEventItemContent::allOrAnyCondition is a short The scenario event's all/any switch at +0x08 of the content (+0x18 of the event) is read and written as one word everywhere in the exe: initializeScenarioEvent sets it with mov word ptr [ecx + 0x18], 1 at 0x004B77B8; createScenarioEventForNextMonth and createChainedMissionOutcomeEvents clear it with mov word ptr [.. + 0x5C8], 0 at 0x004BDA3A, 0x004BDC16, 0x004BDD06 and 0x004BDDF8; the NewEventCondition handler toggles it with xor word ptr [eax + 0x01653E20], 1 at 0x004B965E; the NewEventCondition render (0x004C01B0) tests it with cmp word ptr [eax + 0x01653E20], 0 at 0x004C0296, and the in-game event check in 0x004C35B0 with cmp word ptr [ebp + 0x5C8], 0 at 0x004C37E7. Nothing touches +0x09 on its own, so the byte pair allOrAnyCondition / magic is one short (0 is "Any of these", 1 "All of these"). Nothing on main uses either field. gynt's open sourcehold#293 already writes the pair as one word (*(short*)&...allOrAnyCondition = 0 in createScenarioEventForNextMonth.cpp and three times in createChainedMissionOutcomeEvents.cpp) and still compiles with the short, where the cast becomes a no-op. The unused ScenarioEventItem.hpp keeps its old byte pair (and conditions[39]); it is left as it is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004C01B0 100.0% Reimplemented MenuItemRenderFunction_NewEventCondition_Main, rewritten from the binary (gynt's draft from his fork's reimpl/UI-MenuItems-development, 72.8% in sourcehold#328). The new-event-condition menu: -1 shows the event's month, 104 and 126 pick the button text from the event's all/any switch ("Any of these" / "All of these") and the current condition ("Active" / "Inactive"), 106 to 125 and 190 to 209 are the 40 condition rows (name, option text and value, grey when off; 209, "Win Timer", first checks whether any of ten conditions is on), 1000 to 2002 are the value boxes of the current condition, and everything else is a plain scenario button. The rows go through the condition structs (conditions[slot].enabled / subType / value) and the named tables (EventConditionMaxValue, EventConditionParamKind, EventConditionValueScale, EventConditionOptionTextOffsets) instead of the draft's pointer arithmetic and unknown3 offsets. The parameter is button, as in main's other render functions; enabled and allOrAnyCondition (0/1 only) are tested by truthiness; the literal text numbers and ParamKind 1/2 have comments. Kept forms: textNumber is copied from button before the 5000 check (copied after the check: quick_diff 0.9440 -> 0.8940); case 2000 comes before 1000 and every box case tests !interacting first, so the box blocks are shared as in the original (in turn: 0.9109; interacting first: 0.8223); the four box cases stay separate, as the original has four entry blocks. The month button's x is X + W / 2 (W / 2 + X, as in 2002: reccmp 99.7% -> 99.3%), and it keeps one call per colour (one call with a colour local: quick_diff 0.9440 -> 0.9237). Case 209's ten condition tests are written out (a loop over 4 to 7: 0.8543; over 20 to 22: 0.8708). default: is now the last label (a tie). quick_diff's 0.9440 is all artifacts (colour immediates, ret, jump tables, the tail calls' target). reccmp reads 99.7%: only the targets of two RenderScenarioButtonWithText tail calls differ (normalized 100.0%). Needs the allOrAnyCondition header commit before it. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004B8220 100.0% Reimplemented MenuItemActionHandler_EditScenario_BaseMenuButtons, rewritten from the binary (gynt's draft from his fork's reimpl/UI-MenuItems-development, 73.5% in sourcehold#328). The scenario editor's main buttons: 3 goes back to the map's properties with the typed start year, 38 opens the trader settings, 41 the attacking force (siege map) or the starting goods, 79 the starting popularity slider, -1 steps the start month, 42 and 43 add a new invasion or event, 168 and 169 the attacking force's gold and partial pitch sliders, 171 the building availability, and 61, 166 and 167 the scenario's gold, rations and taxes (with the extra options on). Against the draft: no gotos (the shared slider tail and the "not on a siege map" block come from MSVC merging the identical endings), the new event through scenarioEvents[currentEventID] instead of a pointer local, the attacking force's text through SEC_SiegeInformation[indexStored - 20] instead of SEC_StartingResources[indexStored + 5] past the array's end (the same address; the original reloads indexStored after the call), and the text slots by their TAIT names. Same behaviour. 43 formats the event's year and never uses it, as the original does at 0x004B86E5: a fixme line says so. The slider titles ("Popularity", "Starting Gold", "Starting Pitch", "Gold") and the attacking force's rows starting at 20 have comments; each of 41, 42 and 43 has its own text buffer, and 166 no longer has a return of its own (both ties). Kept forms: in 168, 169 and 61 textGroup is set before textIndex, so their tail is shared as in the original (textIndex first: quick_diff 0.9573 -> 0.9197). The new event's subType stores are written out (a for loop over 5 to 7: 0.9001). quick_diff's 0.9573 is all artifacts (the cookie symbol, ret, the jump table). reccmp reads 98.8%: only the atol call target and the slider callbacks' addresses differ (we push the SumUnitPoints / RestoreScenarioGold resolvers' trampolines where the original pushes the functions). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004C0860 100.0% Reimplemented MenuItemRenderFunction_NewEventAction_Main, rewritten from the binary (gynt's draft from his fork's reimpl/UI-MenuItems-development, 62.3% in sourcehold#328). The new-event-action menu: 37 to 40 are scenario buttons (38 to 40 show "Select Message", each only for its message action: Lose & Message 27, Win & Message 26, Message 2, otherwise hidden through DAT_ButtonUnknownZero); 128 to 155 and 177 to 187 are the action rows for event types 0 to 38: the current type's row is highlighted with its value (or "%" and the value for 178) and counts down the slider popup, the others are drawn plain; 146 and 148 show an icon after " - ", and 148 "Archers" is drawn with 146's text, "Bandits". It fixes three bugs of the draft: 38 to 40 drew "Select Message" and then hid it (the break led to DAT_ButtonUnknownZero = 1); 178's highlighted row fell into the plain draw and was hidden; the plain rows with an icon (146, 148) were hidden after drawing. This version returns where the original does. The parameter is button, as in main's other render functions. Kept forms: the row's text is copied from button before selectedButton, the copy the original keeps in the parameter's stack slot for the value switch at the end (selectedButton first: quick_diff 0.9184 -> 0.9143; decrementing a copy of the parameter instead: 0.2490). The not-highlighted row has the same draw on both sides of the hover test (one draw without the test: 0.7731), and iconOffset is declared at the top (at its first use in the rows' block: 0.8907). quick_diff's 0.9184 is all artifacts (colour immediates, ret, jump tables, the tail calls' target). reccmp reads 99.3%: only the targets of three RenderScenarioButtonWithText tail calls differ (normalized 100.0%). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004266E0 100.0% Reimplemented MenuModalRenderFunction_UnusedSetName, gynt's code from his fork, branch reimpl/UI-MenuModals-100 (97.9% "asm differs" there). Unchanged, it measures reccmp 100.0% here, with today's headers, the resolvers on and --ignore-security-cookie. This commit only restyles it: his reused iVar1 = (width + -400) / 2 becomes int const margin = (width - 400) / 2 and (x - iVar1) + width becomes x - margin + width; the text's position goes straight into the call (y + 15, width / 2 + x; a tie with locals); decimal constants, COL_CCFAFF, line comments in place of the script's block comments, a comment on the 400 pixel title box; the five unused using-declarations and the BOOLEnum.hpp include are dropped and BGR24.hpp becomes ColorsEnum.hpp. Same generated code (quick_diff and reccmp unchanged). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x004ABAB0 100.0% Reimplemented MenuModalRenderFunction_NewEventAction, gynt's code from his fork, branch reimpl/UI-MenuModals-100 (97.7% "asm differs" there). Unchanged, it measures reccmp 100.0% here, with today's headers, the resolvers on and --ignore-security-cookie. This commit only restyles it: his seven decompiler temporaries (xParam, iVar2, TVar3, BVar4, iVar5, iVar6, BVar7) go, with the constants and both labels' positions passed straight into the calls (a tie with locals), so the case needs no block; TEXT_SCENARIO for the banner's group; decimal case labels and constants; COL_CCFAFF; line comments in place of the script's block comments; the four unused using-declarations and the BOOLEnum.hpp include are dropped and BGR24.hpp becomes ColorsEnum.hpp. Same generated code (quick_diff and reccmp unchanged). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: ScenarioEventType enum for the scenario event types IngameScenarioEventItemContent::ScenarioEventType holds 0 to 38. The game names each type by a text of the scenario group (cr.tex group 199): the new-event-action menu (0x004C0860) draws type t's row with text 128 + t for 0 to 27 and 149 + t for 28 to 38 (rows 128-155 and 177-187, compared with item - 128 against ScenarioEventType), and the new-event dialog (0x004AB790) prints ScenarioEventType + 128, + 21 above 155. The enum takes its names from those texts: 0 Win, 1 Lose, 2 Message, ... 26 Win & Message, 27 Lose & Message, 28 Turn Off Repeating Invasions, 29 Theft from granary, 30 Fire!. Text 138 repeats "Message" for type 10 (SET_MESSAGE_10); types 31 to 38 only have placeholder texts ("Action 32" ..) and are SET_UNKNOWN_31 .. 38. The field stays an int, so nothing on main compiles differently; the new-event-action menu uses the names for its message types 27, 26 and 2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: ScenarioEventConditionIndex enum for the 40 event conditions The 40 entries of IngameScenarioEventItemContent::conditions have fixed meanings, and the exe uses the index both as an array index and in loops: MissionAestheticsDefinedData's EventConditionMaxValue, EventConditionParamKind and EventConditionValueScale are [40] tables indexed by it, the new-event dialog (0x004AB790) loops over all 40, and the new-event-condition menu (0x004C01B0) maps its rows 106-125 and 190-209 to conditions 0 to 39. So an enum for the index fits, not a struct. The names are the texts the game shows for them (cr.tex group 199, text 106 + i for 0 to 19 and 170 + i for 20 to 39): 0 Auto-Stop, 1 Population, ... 22 Maximum Cruelty, 23 Maximum Pleasantness, 39 Win Timer. Text 123 repeats "Weapons Acquired" for 17 (SECI_WEAPONS_ACQUIRED_17); 24 to 38 only have placeholder texts ("Event Condition 24" ..) and are SECI_UNKNOWN_24 .. 38. Nothing on main uses the conditions array by a literal index. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MapPropertiesState::flag is a BOOLEnum MapPropertiesState::flag (+0x13578) only ever holds 0 or 1: the exe's only store is the 1 in the scenario editor's new-event button (mov dword ptr [..+0x13578], 1 at 0x004B86CA in 0x004B8220), and its three readers test it against 0 (0x004BA57E, 0x004BFE3F, 0x004BFF1D). BOOLEnum is a typedef of int, so the size and every access stay the same. No function on main uses the field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MenuModalComposition::setSliderParameters takes int* and a void() callback setSliderParameters (0x004AA480) stores its destination into MenuModalComposition::destination, which the header already types int* (mov [ecx + 0x58], eax at 0x004AA512), and its callback into sliderCallbackFunction. Every caller in the exe passes the address of an int (MapPropertiesState::SEC_StartingPopularity, SEC_StartingResources[...], DAT_CopyOfScenarioGold) and a no-argument __cdecl function (Helpers::SumUnitPoints 0x004B8200, Helpers::RestoreScenarioGold 0x004B8210). The signature becomes (int minimum, int maximum, int value, int* destination, void(__cdecl* callbackFunction)()), here and in its resolver, and the scenario editor's four calls lose their (undefined*) / (void*) casts. Main has no other caller; the drafts in sourcehold#327 and batch4-development that call it with the old casts will need the same edit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: three functions use the new header names TheRedDaemon's review of sourcehold#354: the proven proposals become header changes (the commits before this one), and the functions use them. NewEventCondition_Main and NewEventAction_Main name the conditions by ScenarioEventConditionIndex and the event types by ScenarioEventType; BaseMenuButtons passes the slider destinations as int* and its callbacks without casts (setSliderParameters takes int* and void(__cdecl*)()), and stores TRUE in MapPropertiesState::flag. Same generated code: reccmp as before (99.7 / 98.8 / 99.3). The status remarks now say when the differences show: with the RenderScenarioButtonWithText (0x004BA910), SumUnitPoints (0x004B8200) and RestoreScenarioGold (0x004B8210) resolvers on, NewEventCondition_Main and NewEventAction_Main read 100.0% raw, and BaseMenuButtons 99.5% raw, where only its three atol calls differ (our CRT's atol against the game's copy). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MenuModalComposition::setSliderParameters takes a NoArgCallback* 7e208ed typed its callback void(__cdecl*)(); main already has that type as Util::FunctionTypes::NoArgCallback, so the parameter uses it, here and in the resolver. It is not a SliderActionHandler (void(int, int, int*, int*, int*)). The modal stores the callback in sliderCallbackFunction (+0x60), and the exe reads that field in three functions only (five reads), each right after activateModalDialog(MMT_NONE, FALSE), and calls it with no arguments: call eax with nothing pushed for it and no add esp after at 0x004B0F90 and 0x004B0FF2 (MenuItemActionHandler_OverlaySlider_Deselect, 0x004B0F70) and at 0x004B1020 and 0x004B1082 (MenuItemActionHandler_UnusedWinCondition_DeselectUnk, 0x004B1000), and a tail jmp eax at 0x004B10C0 (MenuItemActionHandler_UnusedWinCondition_Options, 0x004B1090, on main, which calls it as (void (*)())). The overlay slider's own SliderActionHandler is MenuItemActionHandler_OverlaySlider_Slider (0x004AA600, the MIT_SLIDER item at 0x005ED588); it writes the value through destination and destination2 and never reads +0x60. OverlaySlider_Deselect is the handler of the item before it (0x005ED538). 7e208ed named only the scenario editor's two callbacks. The exe calls setSliderParameters 14 times, from MenuItemActionHandler_General_AdvancedGameOptions (0x00429A40, four calls), MenuItemActionHandler_EditScenario_BaseMenuButtons (0x004B8220, four), MenuItemActionHandler_NewInvasion_UnitButtons (0x004B9110), MenuItemActionHandler_NewEventAction_Main (0x004B9C00), MenuItemActionHandler_SiegeAttackingForceAndStartGoods_Main (0x004BA5C0, three) and MenuItemActionHandler_TriggerInvasion_Main (0x004BBD90), and passes six different callbacks. All six read no stack argument and end in a plain ret, and main's resolvers already declare each void(__cdecl*)(): Synchrony::Commands::QueueChangeGameIntensityOrBalance (0x00429630, three calls), UI::Helpers::CallbackSetMultiplayerSpeedLevel (0x00429650, one), Global::DoNothing (0x00469F10, two), UI::Helpers::SumUnitPoints (0x004B8200, six; a tail jmp to a thiscall at 0x004B7FA0 that reads only ecx), UI::Helpers::RestoreScenarioGold (0x004B8210, one) and UI::Helpers::CaptureCurrentTimeToUnknownTime01 (0x004B9610, one). The two sibling setters are called once each, with two of the same callbacks: setSliderParameters2 (0x004B9762) with CaptureCurrentTimeToUnknownTime01 and setModalSliderParameters (0x00429C48) with QueueChangeGameIntensityOrBalance. The callers compile unchanged. The header commits of this series don't build on their own; measured in one alone build with all of them and the commit that updates the users (the last one before the merge of main): setSliderParameters2 (0x004AA540) and MenuItemActionHandler_UnusedWinCondition_Options (0x004B1090) read reccmp 100.0%, and MenuItemActionHandler_EditScenario_BaseMenuButtons (0x004B8220) reads 98.8% raw, as before (only the atol call and the callback trampolines differ, so it stays recorded at 100%). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MenuModalComposition::setSliderParameters2 takes a NoArgCallback* Its callbackFunction was undefined*. setSliderParameters2 (0x004AA540) stores it in sliderCallbackFunction (mov [ecx + 0x60], edx at 0x004AA5F0), which the exe calls with no arguments (see the commit before), and its one caller, MenuItemActionHandler_NewEventCondition_Main (call at 0x004B9762), passes UI::Helpers::CaptureCurrentTimeToUnknownTime01 (0x004B9610), a void(__cdecl*)() in main's resolver. So the parameter becomes a NoArgCallback*, here and in the resolver. This commit is header-only, as AGENTS.md asks: main's setSliderParameters2.cpp takes the new type in its own signature in the last commit of this series, and the build needs that commit; it then reads reccmp 100.0%. Main has no caller; the 0x004B9620 draft on reimpl/UI-MenuItems-3-development-2 casts its argument to undefined* and will need the cast dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MenuModalComposition::setSliderParameters2 takes a short* destination destination was a dword. setSliderParameters2 (0x004AA540) stores it in destination2 (mov [ecx + 0x5c], eax at 0x004AA5D2) and clears destination. destination2 is a short*, and the overlay slider's handler (0x004AA600) writes through it with word stores only (mov word ptr [edx], cx at 0x004AA71C, [ecx], dx at 0x004AA736 and [ecx], ax at 0x004AA762), where it writes through destination with dword stores. The one caller, MenuItemActionHandler_NewEventCondition_Main (call at 0x004B9762), passes the address of a short: it pushes lea eax, [eax*4 + 0x1653e24] as destination and, as value, what it reads from there with movsx eax, word ptr [eax]. So the parameter becomes a short*, here and in the resolver, and setSliderParameters2.cpp's (short*) cast goes in the commit that updates the users. Main has no caller; the 0x004B9620 draft on reimpl/UI-MenuItems-3-development-2 already holds it in a short* local and can drop its (dword) cast. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MenuModalComposition::setModalSliderParameters' last parameter is a NoArgCallback* param_6 was undefined*. setModalSliderParameters (0x004AA930) stores it in sliderCallbackFunction (mov edx, [esp + 0x18]; mov [ecx + 0x60], edx at 0x004AA956 and 0x004AA964), which the exe calls with no arguments, and its one caller, MenuItemActionHandler_General_AdvancedGameOptions (call at 0x00429C48, on DAT_MenuModalComposition1), passes Synchrony::Commands::QueueChangeGameIntensityOrBalance (0x00429630), a void(__cdecl*)() in main's resolver. So param_6 becomes a NoArgCallback*, here and in the resolver; the name stays Ghidra's. Main has no implementation or caller. gynt's 100% setModalSliderParameters on origin/reimpl/UI-Core (e31bef6, sourcehold#256) defines it with undefined* param_5, undefined* param_6, so his definition will need NoArgCallback* param_6 (and int* param_5, the next commit) to match this declaration (C2511 otherwise), as setSliderParameters2.cpp does in the last commit here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MenuModalComposition::setModalSliderParameters' param_5 is an int* param_5 was undefined*. setModalSliderParameters (0x004AA930) stores it in destination (mov edx, [esp + 0x14]; mov [ecx + 0x58], edx at 0x004AA94F and 0x004AA953), and param_4 in sliderValue. destination is an int*, and the overlay slider's handler (0x004AA600) writes through it with dword stores only (mov [edx], ecx at 0x004AA6E3, [ecx], edx at 0x004AA6F8 and [esi], eax at 0x004AA755). The one caller, MenuItemActionHandler_General_AdvancedGameOptions (call at 0x00429C48), passes 0x01A24658 as param_5 and, as param_4, the dword it reads from there (mov eax, [0x1a24658]). So param_5 becomes an int*, here and in the resolver; the name stays Ghidra's. Main has no implementation or caller. gynt's e31bef6 stores it as this->destination = (int*)param_5; with this commit and the one before, his definition changes once for both parameters, and the cast can go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * headers: MenuModalComposition::sliderCallbackFunction is a NoArgCallback* It was pointer (void*). The exe writes it only in the three setters (mov [ecx + 0x60], edx at 0x004AA530 in setSliderParameters, 0x004AA5F0 in setSliderParameters2, 0x004AA964 in setModalSliderParameters), whose callback parameters are NoArgCallback* since the commits before, and reads it only at 0x004B0F87, 0x004B0FE9, 0x004B1017, 0x004B1079 and 0x004B10B7, each a NULL test and then a call or tail jump with no arguments (see the first commit of this series). There is no other access to either instance's +0x60 (absolute 0x01FE7CF0 for DAT_MenuModalComposition1, 0x024036D8 for DAT_MenuModalComposition2). In the next commit main's setSliderParameters2.cpp takes the typed parameters in its signature and MenuItemActionHandler_UnusedWinCondition_Options drops its (void (*)()) cast. Measured with the commits before and the next one, in one alone build: setSliderParameters2 (0x004AA540) and MenuItemActionHandler_UnusedWinCondition_Options (0x004B1090) read reccmp 100.0%, and MenuItemActionHandler_EditScenario_BaseMenuButtons (0x004B8220) reads 98.8% raw, as before (only the atol call and the callback trampolines differ, so it stays recorded at 100%). gynt's OverlaySlider_Deselect (a2803eb, 100%, on his fork's reimpl/UI-MenuItems-development) compares the field with (undefined*)0x0, which will need to become NULL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * MenuModalComposition: setSliderParameters2 and UnusedWinCondition_Options use the typed parameters setSliderParameters2 (0x004AA540) takes short* destination and NoArgCallback* callbackFunction in its definition, as the header has since the commits before; the header commits are header-only, so this one makes the branch build again. destination goes into destination2 without its (short*) cast. MenuItemActionHandler_UnusedWinCondition_Options (0x004B1090) calls sliderCallbackFunction, a NoArgCallback* since the commit before, without its (void (*)()) cast; its first include is the relative ../Unused.func.hpp, as the checker asks of a touched file, and the unused using lines for MenuModalType and BOOLEnum go with the BOOLEnum.hpp include (MMT_NONE is written out in full and FALSE is the Windows macro). quick_diff unchanged; reccmp 100.0% for both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * NewEventAction: the event type switch uses ScenarioEventType's names gynt on sourcehold#354: the cases of MenuModalRenderFunction_NewEventAction's switch over the event's ScenarioEventType were numbers. They are now SET_TRAVELING_FAIR, SET_PLAGUE ... SET_ARCHERS, SET_THEFT_FROM_GRANARY and SET_FIRE (5, 11-20, 29, 30). The other switches in this branch are over button numbers (TEXT_SCENARIO text numbers, no enum yet) and stay numbers; its comparisons with an event type or a condition index already use the names. Codegen unchanged: quick_diff 0.9107 before and after, reccmp 100.0%. 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 asked on sourcehold#354 why the case labels do not use the enum names. In this draft the switched value has an enum on main in one place: MenuItemActionHandler_General_EventSlider's two switches on the current event's ScenarioEventType now name their 13 cases (SET_TRAVELING_FAIR, SET_PLAGUE ... SET_THEFT_FROM_GRANARY, SET_FIRE), and MenuItemActionHandler_NewEventAction_Main's test of the new type compares with SET_MESSAGE, SET_WIN_AND_MESSAGE and SET_LOSE_AND_MESSAGE. The other switches here are on button numbers, slider steps and fields with no enum (activeTacticalPower, unitControlsRelated, TextEditorState.field_0x23970), so they keep their numbers. The code is unchanged: quick_diff gives the same output for both files before and after. 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>
Main's 3a1c7f7 (merged in 0b412b2) types setSliderParameters' last parameter NoArgCallback*, so the (void*) cast on CaptureCurrentTimeToUnknownTime01 no longer compiles; the callback is passed as MACRO_CALL(...) as main's EditScenario calls do. Same instructions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 9, 2026
…und 11 PR With the bandits text's position read into y-then-x locals inside each colour path, the function reaches 100.0% (96.8% here), so it moves to the round 11 PR (reimpl/UI-B-round11-100, 69a3ba2). This draft drops it, and its status line goes back to main's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 13, 2026
Merged
HistoricCampaignSelect's render (0x004255D0) goes from 98.7% here to 100.0% in the round 13 PR (reimpl/UI-B-round13-100, b607ec8): the campaign name is drawn by two identical calls, one per hover state, which gives the original's load order for the text call. This draft drops its .cpp file, and its status line goes back to main's. Main doesn't have the function, and this draft changes no header, so nothing else goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…etMarker Main's Ghidra sync (1b36c0a) named Building's field at 0xC2 targetMarker, a BuildingTargetMarkerShort. The draft stored 2 into field_0xc2, which is BTM_ENGINEER_TARGET; it now says so. quick_diff 0.5332 on main e086ba7 (the draft did not compile there before). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 33 TextEditor keyword and button strings are the s_ pointers from string-literals.hpp instead of the S_ macros, cast to char* for renderText's parameter as elsewhere on main. quick_diff gives the same instructions as before (0.9743). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Seven UI::MenuItems functions below 100%, so others can continue from them (gynt's rule: ready functions in their own PR, the rest in a draft):
reimpl/UI-MenuItems: switches rebuilt from the original's jump tables, if-chains in the original's order, gotos gone. Each status line says what is left.Every commit body says what changed and what was measured.
This draft has 8 files. The batch's ready PRs: #329, #330 and #332 (merged), #331, #333 and #338; the other draft is #328, with 30 of gynt's drafts brought onto current main.
Built on top of
main(6306080, since merged with 72b2732 and its header sync) with the bundled MSVC1400-SP1, natively on Windows, against the SteamStronghold Crusader.exe(3bb0a8c1…5387ac5a), with the struct and function resolvers enabled locally (not committed), using sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie. Built on its own, the branch matches every status line. NewMapMapsize needs--ignore-security-cookieto reach 100%, so its status says "Security Cookie mismatches", as on main. None of it has been run in game. The points from the reviews of #311, #312 and #323 are applied; decompiler names (iVar1) are left in some of the functions below 100%.Behaviour fixed compared with the drafts
Each one is read from the original's asm; the commit body gives the address.
DAT_00b95960 = -1on every path, and stops when no position is under the mouse (the draft's loop never ended then, and skipped the reset after a swap).distance > limit, as the original compares them (0x00434E9E-0x00434EAA); the draft's always-true test also wrote stray values into two flags it reads later.Header changes, each in a commit of its own (gynt, 2026-11-05: they stay in the PR until main has them), with the functions that need them. Main's Ghidra sync a9401a7 took in the others (
SEID_UNKNOWN_0x92,BASMTT_NONE, the colours, and the three ints asINT_00b95960/INT_00b95f64/INT_00b95b74, the names LobbyscreenStartButtonClick uses now); main 72b2732 is merged in, and every function measures what its status line says in a clean build of the branch alone.SoundEffectIDgetsSEID_UNKNOWN_0xFBandSEID_UNKNOWN_0xFD(251 and 253): HistoricCampaignSelect plays 251 and LobbyscreenStartButtonClick 253; the drafts wrote them as ORs of unrelated sounds. The same lines are in Reimplement 24 UI::MenuItems functions from gynt's drafts (not yet 100%) #328.GameCommandTypegetsGCT_UNKNOWN_103, which LobbyscreenStartButtonClick queues with the selected map's index (the draft wroteGCT_SHARE_GAME_STATE_PARTIAL_HASHES | GCT_MULTIPLAYER_ANNOUNCE_HOST).GameSynchronyState::chatScrollOffsetis anint(compared signed with 0 and 15); its users on main compile to the same code.string-literals.hppgets "Pic" at 0x005A55E0 (a TextEditor button label).MenuItemActionHandler_General_EventSliderMenuItemRenderFunction_General_CreateEventCallbackFunctionMenuItemRenderFunction_HistoricCampaignSelect_MainMenuItemActionHandler_InGameMenu_UnitSelectionAndControlsUnkMenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClickMenuItemActionHandler_NewEventAction_MainMenuItemRenderFunction_TextEditor_ButtonsProposed, not changed here
renderText2andrenderTextToScreen2getDAT_ButtonWin theirTextAlignmentslot in the TextEditor buttons (0x0045E00E pushes the width) andTTA_CENTERelsewhere, so that parameter is a width, not aTextAlignment.renderTextToScreen2takes achar*, which is why that function uses the string macros.setSliderParameters' destination is anint*.UnitsState::pendingUnitControlModeis aBOOLEnumbut holds 20, so it is anint.DAT_ButtonX/DAT_ButtonYareundefined4but used signed.loadOrSaveGame(int)compares its argument with 10, asloadOrSaveMapdoes with itsMenuModalType(0x004968F1), so the lobby's9is probablyMMT_LOAD_MAP.BOOLEnumcandidates (stores still to be proven):INT_00b95f68,INT_00b960ec,INT_DisableTutorialRestrictions,DAT_PlayerSlotArraySomeValue(toggled with^= 1),PathFindingState::toggleUpdateSeparateAreaTileMapandTileMapState::forceUpdateMacroLayerFlag.getBuildingHasHealthPropertytwice (0x00435B48, 0x00435B5A), and its engineer test usesUS_JESTER_ROAM_TO(109).defaultcomes beforeM_MAPPER_TEST, in the original's order.crusaderArabianwith 0 and 1, the same values as the rat and the snake.🤖 Generated with Claude Code