Repository navigation
Five more functions at 100%: InGameMenu MainButtons, Roundtable handler, BuySell, UpdateGhost and UpdateHopsFarmer - #416
Open
kotijekriv wants to merge 7 commits into
Conversation
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>
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>
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>
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>
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>
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>
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>
This was referenced Nov 17, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Five more functions at 100%, with no header changes. Three are UI functions from our draft #328, and two are Map::Units functions from gynt's units branch
reimpl/map-units-updatefunctions(his draft #204), by way of our unpushed units dev branches. All five start from gynt's drafts; each commit cites the drafts it builds on and credits him as co-author. Two of them count as 100% under the rule gynt set in #414 (a function whose only difference is register allocation), and for those the raw reccmp number and the evidence are below.InGameMenu::MenuItemRenderFunction_InGameMenu_MainButtons/GLRoundtable::MenuItemActionHandler_Roundtable_Main/GLBuildingAndStatusMenu::MenuItemActionHandler_BuildingAndStatusMenu_BuySellMenuButtonsAndHandsUnits::UpdateGhost/GLUnits::UpdateHopsFarmer/GLMeasured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie.InitBlendFilterArraysUnk, normalised 95.0% to 100.0% (97.9% raw both times). The review fixes since that build compile to the same code./GLlist plus the new lines, every resolver of those files on: UpdateGhost 100.0%, UpdateHopsFarmer 99.7%, its three callees 100.0%, nothing else moved..cppswitched on (2,449 functions against 2,439). All five read as above, and so do the/GLcallees: Hops',isAIPlayer,getPictureNumberInGm, and Ghost'shasUnitReachedDestinationandmakeUnitStopWalkingByClearingPathProgressState. No function on main reads lower.InitBlendFilterArraysUnkreads higher normalised (95.0 to 100.0, raw unchanged), as with this branch alone.UI::Menu::handleMenuItemsandConstructor_Menushow the known0x11000000naming artefact in the larger build: their instructions are the same, reccmp names the constant after a symbol of our DLL that sits at that address, and both read 100 with this branch alone. MapEditorLandscaping's GeneralButtons handler, which doesn't compile on main since the last sync, was left out (Reimplement 88 Map::TileMapState functions at 100% #366 changes it). That build had Hops before its last style pass and withUpdateWorker_ConsiderTakingABreakUnkon the list; the final Hops reads the same 0.9971 in quick_diff, and that callee was dropped from the list because it made no difference.tools/): MainButtons, the Roundtable handler and UpdateGhost read 100.0% raw and normalised, UpdateHopsFarmer 99.7% (90.9% normalised) and BuySell 93.9% (85.9% normalised), with the same differing lines as described below. No function on main reads lower, apart from the0x11000000naming artefact onhandleMenuItemsandConstructor_Menu./GL: nothing takes its address then, so LTCG gives it a private calling convention and drops the load of its argument.openshc-pr-fixfinds nothing to change, andopenshc-pr-checkgives 0 ERROR.The two at 100% per #414
The maintainers haven't settled this on #414: gynt set the rule, and TheRedDaemon wrote that he'd accept such functions for now as non-100%. If the status lines should carry the raw numbers (93.9% and 99.7%) instead, say so and we'll change them.
imul ..., 0x39f4player-index computations use ecx and edx the other way round, and one load and one store use edx where the original has eax. The other two arejnes whose displacement is one byte off, because the original'smov [global], eaxtakes eax's shorter moffs encoding. Those two displacements are why reccmp's own register-swap check (effective) doesn't pass it yet. Same instruction count, same mnemonics in the same order, same memory operands. diff_triage's register-blind ratio is 1.000 (0.859 raw).getBuildingThatCanStoreThisResourcewithmovsx ecx, [owner]; push ecx, ours with eax: the same two instructions and memory operand. Owner locals, int or short casts, and reading it throughunitIDor the slot all tie or lose, and a symbol-count sweep (0 to 95 dummy typedefs) reads the same at every count.What got them to 100%
getPictureNumberInGm(0x004630B0), which only LTCG can know is safe, so it needs/GL; without it the zero, the one and the picture offset land in other registers (80.8%).DAT_RoundTableOrderArray(the decompiler hadmapSendRequestStatePerPlayer + button + 26), the group numbers are char reads into ints, the highest group is a plain loop over players 1 to 8 that MSVC unrolls into the original's eight copies, and the buttons after the seat logic are an if chain with returns. Under/GL, reading the chosen lord's seat before the target's gives eax and ecx the original's roles. 87.2% without/GLin every form./GLall tie or lose (/GLdrops it to 80.2%).owneris read once at the top throughDAT_CurrentUnitSlotID::instanceinto anint constlocal, as the original keeps it in ecx up tofindNextReachableDefensiveBuildingForPlayer.hasUnitReachedDestinationand the finalmakeUnitStopWalkingByClearingPathProgressStateget the slot, and inUS_IDLEUnkeverything from thedestinationNeededstore after thetimeGetTimetest indexesunits[]through it, as the original reads the slot again after those calls.addResourceToStockpileback onunitID. In the delivery state, the can-store and reachable-storage paths are the then-arms of their tests.Behaviour fixed compared with the drafts
Lines added to
cmake/compiler-flags-gl.txtMenuItemRenderFunction_InGameMenu_MainButtons.cpp: 100.0% with it, 80.8% without.getPictureNumberInGmis on main's list already.MenuItemActionHandler_Roundtable_Main.cppandisAIPlayer.cpp: 100.0% with them, 87.2% without. OnlyisAIPlayerhas to be visible.UpdateGhost.cpp: 100.0% with it, 49.3% without, ashasUnitReachedDestinationandmakeUnitStopWalkingByClearingPathProgressState(both on main's list) have to be visible.UpdateHopsFarmer.cppand three callees it needs visible:ComputeGoodsProduced(quick_diff without it 0.9599),IncrementAndOptionalUpdateAVValueRelated(0.8182) andSetStateToFreetimeWalking(0.9899); with none of them on the list Hops reads 0.5950. All three are 100% on main, stay 100.0% on the list, and no other file on the list calls them.UpdateWorker_ConsiderTakingABreakUnkmade no difference and stays off.Kept as they are
GM_CRUSADER_TUTORIAL ||next to the!= GM_CAMPAIGN_MISSIONtests, and the inner!= GM_SIEGE_THATthat repeats the outer one, look redundant, but the original makes both compares (0x004644AC and 0x0046459F).isSkirmishTrail != TRUEstays because the original compares the flag with 1.(char)byte-table reads and the(short)operands and stores, as in main'ssetFacingDirectionToward*.What some placeholders hold
DAT_00df423c: the chosen lord's seat at the round table.INT_00df4244: set when that seat is clicked again.DAT_00df4240/DAT_00df4298: the rat's / the sultan's genie line has been played (BOOLEnumcandidates).DAT_GameCore.field_0x6c: greys button -5 in campaign missions.farmGrowState: holds the farmer's nextUnitState(3 or 5), not a grow state.Proposed, not changed here
PlayerData::storageMarketFailState, whose values 1 to 10 BuySell sets (the market's failure messages).BuildMenuTabTypevalue: MainButtons compares the open tab with 48, which isBuildingsAndStatusMenuTabType::BASMTT_STOCKS, so the source reads it throughactiveMenuTab.tabType; and the 47 at MainButtons :122 (DAT_MenuOptionsActionParameter == 47) has no enum at all.charfor byte fields read as signed:Unit::disappearFadeAlphaCountdownand the AnimationFrameData frame tables arebytein the headers, but the original compares them as signed. Ascharthe casts could go.Three functions leave #328
InGameMenu::MenuItemRenderFunction_InGameMenu_MainButtons(0x004643F0)Roundtable::MenuItemActionHandler_Roundtable_Main(0x004AEA50)BuildingAndStatusMenu::MenuItemActionHandler_BuildingAndStatusMenu_BuySellMenuButtonsAndHands(0x00467040)#328 gets one commit that removes their three
.cppfiles and puts their status lines back to main's (5ef28e7). The two units were never in our open drafts.Other PRs
🤖 Generated with Claude Code