Repository navigation
Reimplement 8 UI::MenuItems functions at 100% - #349
Merged
Merged
Conversation
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
This was referenced Nov 6, 2026
… 254-256) into reimpl/UI-MenuItems-9-100 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 6, 2026
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>
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>
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>
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>
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>
… 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>
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>
This was referenced Nov 7, 2026
The sync types DAT_SH1_SiegeAdvancedMode as int where 0bc6102 had BOOLEnum, and DAT_StoredGameMode as int where d4c1b5e had GameModeInt: main's headers are taken, and MenuItemActionHandler_SingleplayerMapChoice_MapTable stores 1 instead of TRUE. No file of this branch uses DAT_StoredGameMode. MissionDefinedData and DAT_SkirmishTrailRelated1 are on main as this branch had them, and TileMapState merges cleanly, so the branch no longer changes any header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 7, 2026
gynt
approved these changes
Nov 7, 2026
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.
Eight UI::MenuItems functions at 100%, each with its status line: the invasion trigger screen, the in-game menu's map scrolling, the skirmish type and balance buttons, the rankings screen, the single-player map table and its scrollbar, the "waiting for host" button and the text input display.
Three come from our drafts, which drop them in the same push: TriggerInvasion from #328, Scrolling from #327 and MapTable from #318. The other five continue gynt's drafts on his fork's
reimpl/UI-MenuItems(the branch of PR #254). Every commit body says what changed against the draft and why. No header change is left: gynt's Ghidra sync eef6f66 took this PR's five header changes into main, two of them with a different type, which this PR now follows (below), and main is merged in (e5c6b15). Its first two header changes are on main since gynt's sync 8125c61, and main is merged in.Other PRs: the ready #348 and #352, and the drafts #313, #318, #321, #327 and #328.
Built on top of
main(7621d4f) with the bundled MSVC1400-SP1, natively on Windows, against the SteamStronghold Crusader.exe(3bb0a8c1…5387ac5a). The branch was built clean on its own, with the struct and function resolvers enabled locally (not committed), using sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie. None of it has been run in game.It went through the same checks as #346: a fresh-eyes review of every file (behaviour checked against the original's disassembly, texts against cr.tex; its points applied and measured),
openshc-pr-checkwith no errors, andstatus_regression.py, which finds nothing below a known score on main or any fork.Header changes
Update: all five are on main since eef6f66. Main has
DAT_SH1_SiegeAdvancedModeandDAT_StoredGameModeas plainints rather than theBOOLEnumandGameModeIntbelow, and this PR follows main: MapTable stores1, and nothing on the branch usesDAT_StoredGameMode. Every function measures as in the table. The evidence below is kept for the record.Every user compiles the same (quick_diff before and after: main's RankingGames_Main 0.9506, RankingGames_Prepare 0.9091, CrusadeMapAndEndscreen 0.9464 and TriggerPlaceWallCommand 0.9748, which came in #351; this PR's MapTable 0.9807).
DAT_SH1_SiegeAdvancedModeis aBOOLEnum(0bc6102): stores^1at 0x0042D81F, 0 at 0x0042D855 / 0x00448DC2 and 1 at 0x00442E66; it's only read with== 0. MapTable storesTRUE(9b3d5a0).DAT_StoredGameModeis aGameModeInt(d4c1b5e): its one store copiesGameSynchronyState::currentGameMode(0x004D972A), and its one read copies it back.DAT_SkirmishTrailRelated1is anint(18f83c2): a count that goes below 0 (stores at 0x004D8D48 / 0x004D8DD5,subat 0x004D8F3B, clamped withjgeat 0x004D8DDB); CrusadeMapAndEndscreen drops its(int)cast (df6428e).MissionDefinedData::descendingis aBOOLEnum(b78dc7c): stores 1 at 0x004D995F, and1 - descendingat 0x004D9970 / 0x004D9976.TileMapState::wallDragButtonUpis aBOOLEnum(67b91e0): its one store (0x0043803E) writes asete(0x00438034).On main since 8125c61
MenuItemActionHandler_InGameMenu_Scrolling()takes no parameters (commit 181b559). The original ends withpush 1 / call RecordTutorialPlayerAction / pop ecx(0x00434200-0x00434207) and never reads an argument; it is referenced only by six menu-table dwords (0x005F4B6C, 0x005FA79C, 0x0060613C, 0x0060622C, 0x0060636C, 0x006081BC) and never called directly. Declared(int, ...), MSVC tail-calls through the argument slot instead (mov [esp + 4], 1 / jmp; quick_diff 0.9343 -> 0.9710 with the change). Main declares 16 such handlers(), for example WaitingForHost_ConnectToLobby.SEID_UNKNOWN_0xFE/0xFF/0x100(254-256) (commit 1572310): SkirmishTypeAndBalance plays them when the balance changes, 256 at either end (buttons 10 and 14), 255 one step from even (11, 13), 254 at even (12). They're pushed at 0x0042A888, 0x0042A8A1 and 0x0042A8B5, and setUpSFXToPlayUnk indexes the 270-entryDAT_SoundStructures2with them. The names follow the enum's existingSEID_UNKNOWN_0x101, next to main's new 0xFB and 0xFD.Behaviour compared with the drafts
None of the eight changes behaviour; each does what its draft did and what the original does.
RecordTutorialPlayerAction(1)is a call again.param_1 - 1U <= 2isbutton >= 1 && button <= 3(the same set), and the sound IDs, written(SoundEffectID)0x100and as ORs of unrelated names in the draft, now have names.MenuItemRenderFunction_TriggerInvasion_MainDAT_GMImageHeaders(as 0x004B92D0 on main).MenuItemActionHandler_InGameMenu_ScrollingMenuItemActionHandler_LobbyMenu_SkirmishTypeAndBalanceMenuItemRenderFunction_RankingGames_MainDAT_00ed3124to 1 and 2 and back to 0.MenuItemActionHandler_SingleplayerMapChoice_MapTableMenuItemRenderFunction_WaitingForHost_ButtonMenuItemActionHandler_SingleplayerMapChoice_ScrollbarMenuItemRenderFunction_TextInputDisplayKept as they are, and why
Each was measured; a one-line comment in the code says why.
== TRUE, since the original compares with 1.break, so the loop's exit jumps past the clearing as the original's does (jg 0x00442DE3 -> 0x00442E64; testing for the end after the loop: 0.9807 -> 0.9753). The siege army's 21 unit counts are read as one array, as the original does (nested[7][3]searches: 0.9807 -> 0.8696), andSEC_SiegeInformationas 20 ints.Proposed, not changed here
DAT_SiegeInformationArrayis read here asint[21]rather thanint[7][3], andSiegeUnitCountsasint[20](an array view would help). Index 10 is overwritten with 70% of the tunnelers right after the copy. (int[7][3]is right: main's SomeSiegeRelatedCopying indexes it[unit][value]; the flat view here is a code choice.)DAT_00ed3124-> something likerankingFilterUnk(0, 1, 2);DAT_00ed27a0->rankingHoveredHeaderUnk(button 20 clears it, a hovered header 20-31 stores itself).INT_00b95b74->mapDescriptionHeight(the height renderMultilineTextUnk mode 1 measures; MapDescriptionScrollbar's maximum is this - 231), andDAT_00b960f4->mapDescriptionScrollOffset.DAT_MapMissionType(buttons 66/67/68 set 0/1/2; 2 is siege) needs an enum of its own, since MapType2's numbering differs.RecordTutorialPlayerAction(int action): actions 1 (the view scrolled), 2 (rotation), 3, 4, 5 and 17 could be an enum.GameCore::isNameEntryActivereads inverted (as in Reimplement 5 UI::MenuItems SaveLoadMap and Unused functions at 100% #341 and Reimplement 6 UI::MenuItems text button renders at 100% #345): TextInputDisplay's field 3, the title box, is hidden while it is 1.gynt's other commits on these functions
Each commit body names the commits it continues. gynt has more on the same functions on his fork, and they are credited here too: his best-scoring commit on the address and his newest one on the file, where the body doesn't name them. Where one of them is at 100%, his version already matched the original, and a fix this text describes for that function was only against the earlier draft it names.
MenuItemRenderFunction_TriggerInvasion_MainMenuItemActionHandler_LobbyMenu_SkirmishTypeAndBalanceMenuItemRenderFunction_RankingGames_MainMenuItemActionHandler_SingleplayerMapChoice_MapTableMenuItemRenderFunction_WaitingForHost_ButtonMenuItemActionHandler_InGameMenu_ScrollingMenuItemActionHandler_SingleplayerMapChoice_ScrollbarMenuItemRenderFunction_General_TextInputDisplay🤖 Generated with Claude Code