Skip to content

Four functions on main back to 100%: two signed tick compares, a selection slot and a load order - #478

Open
kotijekriv wants to merge 4 commits into
sourcehold:mainfrom
kotijekriv:reimpl/main-A-round1-100
Open

kotijekriv wants to merge 4 commits into
sourcehold:mainfrom
kotijekriv:reimpl/main-A-round1-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

Four functions on main that read below 100% in a full build of main with every resolver on, although their status lines say 100%. Each change is a line or two, and one of them is a behaviour fix (the deselect helper, below). No header change, no line for cmake/compiler-flags-gl.txt, and the status lines stay as they are (100.0%).

Function Address Reimplemented by Full build of main (raw / normalised) Now
Rendering::DisplayMapDescriptionAndAllocatePlayersToSlots 0x004410D0 us in #311, from gynt's draft (64ea8f9) 94.8% / 85.7% 100.0% / 100.0%
GameSynchronyState::queueCommand 0x00489100 gynt (0d29e13 in #272; draft 93d8290) 99.1% / 95.2% 100.0% / 100.0%
HoveredState::clearInvalidatedHoverStates 0x005010E0 gynt (8a3481f, #199) 92.9% / 92.9% 100.0% / 100.0%
BuildMenu::MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroopsDeselectHelper 0x00439390 gynt (7ec817c, #199; sourcehold's 6a5bead before it) 87.5% / 87.5% 100.0% / 100.0%

Each commit credits gynt as co-author.

The two tick compares (queueCommand, clearInvalidatedHoverStates)

  • The original compares the game's tick count as a signed number in both: cmp ecx, eax and jle at 0x00489183 (against mapTimeInTicksSinglePlayer), and cmp edx, [eax + 8] and jl at 0x005010FF (against each hover entry's time).
  • Main's Ghidra sync a521bf7 (2026-11-04) made GameCore::mapTimeInTicks a uint. Since then these two compares, which had no cast, have been unsigned (jbe, jb); that one instruction is each function's whole difference. The casts had been dropped in d230e6b (2026-10-23), while the field was still an int.
  • Here the (int) is back, with a one-line comment on each, as main's other signed uses of the field already have it (processSingleTimeTick, getCommandIDFromCommandSelectionStuff, BuildEnemyPlayerList).
  • gynt's d230e6b dropped the same cast in teamIsWeakRelativeToEnemy, and his open Reimplement 90 AI::AICState functions at 100% #371 puts it back there (and in lightUpBuilding in his draft reimpl/BuildingsState #234), so the cast is the form already in use for this field.

The deselect helper tests its own slot again (behaviour fix)

  • The helper renders the selection panel's second row of eight buttons, slot IDs 20 to 27 (menu items 0x005F5B98 to 0x005F5DC8). The original tests selectionSlots[slotID - 20] == -1: cmp dword ptr [eax*4 + 0x13884b8], -1 at 0x0043939D is UnitsState + 0x5D0 - 20 * 4. That is the same access the rows' click handler 0x004393C0 makes for slot IDs from 20 (0x00439403), and the test 0x00439160 makes for the first row. An empty slot is -1, and its button is switched off.
  • The Ghidra sync 5474d5d (2026-10-25) replaced the per-type fields with int selectionUnitType[27] from 0x564, and the build repair 6b49b55 of the same day wrote selectionUnitType[selectionIndex], 28 bytes earlier. gynt's 7ec817c had (&selectionEngineers)[selectionIndex], the original's address. For slot IDs 20 to 27 the repair's form reads the Arabian troops' counts (never -1) and one past the array's end, so seven of the eight buttons have stayed on for an empty slot, and the eighth has tested the first slot instead of its own.
  • Here it reads selectionSlots[slotID - 20], as the imported stub had it (selectionSlots[param_1 + -0x14]), with the parameter as int slotID like the two sibling functions. The UnitSelectionEnumInt include and using go, and the button flag is set with TRUE / FALSE as in 0x00439160.

DisplayMapDescriptionAndAllocatePlayersToSlots: the selected map's two parts

  • The original's first test loads DAT_MapSelectionScrollOffset into eax, then DAT_MapSelectionRelativeSelected into ecx, and adds into ecx (0x004410E4 to 0x004410F4). Ours loaded them the other way round, and the second sum at 0x004411E8 swapped with it.
  • Read into two int const locals, the scroll offset first, and tested as relativeSelected + scrollOffset >= 0, the test compiles to the original's four instructions, and the second sum follows. That sum reads the fields again after the calls, as the original does. A one-line comment above the two locals says why they are there.
  • The plain expression gives the swapped loads in either operand order in a build with the precompiled header (a compile without it happens to give the original's order, so this one only shows in a real build).

Measured

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), the struct resolvers and the function resolvers enabled locally (not committed), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • Full build: an all-on build of this branch on main 0e4a83b, with both resolver sets on and main's own /GL list (none of these files is on it), and with 0x004314E0 (the MapEditorLandscaping_GeneralButtons handler) left out and its resolver off, as in main's baseline: 0 failed, 99.59 over 2,441 functions. DisplayMapDescriptionAndAllocatePlayersToSlots, queueCommand, clearInvalidatedHoverStates and MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroopsDeselectHelper read 100.0 raw and normalised there, with no diff entry (94.8, 99.1, 92.9 and 87.5 in the same build of main). Two main functions read lower, and it is how reccmp prints a constant, not their code: Menu::handleMenuItems (0x004F6280) reads 97.9 (91.4 normalised) and Menu::Constructor_Menu (0x004F4100) 98.4 (95.2), both 100.0 before. Both compare a menu item's type with the constant 0x11000000, five compares in all; in this build's layout a symbol of our DLL lies at exactly that address, so reccmp prints the constant as that symbol's name on our side, and the instructions are the same on both sides (UI: the single-player game launch at 100% #466 describes the same two readings). Every other function reads exactly what it read before; against main's own build (made at f489b72, 2,439 functions) the only other changes are main's since then (One more UI::MenuModals function at 100%: ProgressBarBox #467's MenuModalRenderFunction_ProgressBarBox and its constructor, UI: the single-player game launch at 100% #466's LaunchSinglePlayerGameUnk) (unrounded 99.5878 raw and 99.5631 normalised, 2,327 functions at 100.0 raw; with the two 0x11000000 readings at 100.0, 99.5893 and 99.5686, 2,329; main 0e4a83b alone: 99.5788 and 99.5528 over 2,441, 2,325 at 100.0).
  • Our narrower run: main's /GL list (the 133 files that exist) and the four files in this PR's texts, with their resolvers on: each of the four reads 100.0% raw and normalised with no diff entry, and every other function reads as in the same build without them.
  • Style fixes in the touched files: clearInvalidatedHoverStates and the deselect helper now include their folder's own ../*.func.hpp first (the same header), queueCommand is clang-formatted (two continuation lines move), and the deselect helper sets its BOOLEnum flag with TRUE / FALSE.
  • Checks: our local style checker gives 0 ERROR and 2 CHECK: the two (int) casts on DAT_GameCore::instance.mapTimeInTicks (below). Our local fixer finds nothing to change.
  • Not run in game.

Proposed, not changed here

Looked at in the same pass, nothing to change in the source

Other functions on main that read below 100% for reasons the source can't change:

  • NewInvasion_UnitButtons (99.2%) and TriggerInvasion_Main (99.2%): one address that reccmp can't name on the original's side ([eax + 0xb98782], the same address);
  • invokeDirectPlayEnumConnections (99.1%): the callback is still the original's (a trampoline on our side);
  • InitBlendFilterArraysUnk (97.9%): the loop's end address takes the next global's name.

someChatMessageSelection (99.2%) keeps its one push edi scheduled three instructions later than the original; ten declaration orders of its locals don't move it.

🤖 Generated with Claude Code

kotijekriv and others added 4 commits November 23, 2026 05:12
…rts read into locals first

The original's first test loads DAT_MapSelectionScrollOffset into eax, then DAT_MapSelectionRelativeSelected into
ecx, and adds into ecx (0x004410E4 to 0x004410F4). Ours loaded them the other way round, and the second sum at
0x004411E8 swapped with it: a full build of main read 94.8%, those lines. With the two read into `int const`
locals, the scroll offset first, and the test written `relativeSelected + scrollOffset >= 0`, the test compiles to
the original's four instructions and the second sum, which reads the fields again after the calls as the original
does, follows. The plain expression gives the swapped loads in either order in a build with the precompiled header;
quick_diff compiles without it and does not show the difference.

Measured with the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1...5387ac5a), the struct
resolvers on and every function resolver of the build list on, sourcehold's reccmp with --resolve-wrapped-calls
--ignore-security-cookie: a build of main's /GL list (the 133 files that exist) and this round's four files, in
these texts, reads 100.0% raw and normalised, no differing line; every other function reads as in the same build
without the four files. The file is not on the /GL list, and this does not add it.

The function is ours on main (sourcehold#311), from Gynt's draft (64ea8f9; his newest reimplement commit on the file is
63cc49f); only the first test changes, with a one-line comment above the two locals saying why they are there.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gain, as in the original

The original compares the game's tick count with mapTimeInTicksSinglePlayer as signed numbers (`cmp ecx, eax` and
`jle` at 0x00489183) before it picks the command's time. Main's Ghidra sync a521bf7 (2026-11-04) made
GameCore::mapTimeInTicks a uint, and since then the compare without a cast has been unsigned (`jbe`): a full build
of main with every resolver on read 99.1%, that one instruction. Gynt's d230e6b (2026-10-23) dropped the `(int)`
while the field was still an int; this puts it back, as main's other signed uses of the field already have it.

Measured with the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1...5387ac5a), the struct
resolvers on and every function resolver of the build list on, sourcehold's reccmp with --resolve-wrapped-calls
--ignore-security-cookie: a build of main's /GL list (the 133 files that exist) and this round's four files, in
these texts, reads 100.0% raw and normalised, no differing line; every other function reads as in the same build
without the four files. The file is not on the /GL list, and this does not add it.

The function is Gynt's (0d29e13 in sourcehold#272, from his draft 93d8290; his newest reimplement commit on the file is
aa0652f). Besides the cast and a one-line comment on it, clang-format moves two continuation lines of the file
that were not formatted.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gain, as in the original

The original compares the game's tick count with each hover entry's time as signed numbers (`cmp edx, [eax + 8]`
and `jl` at 0x005010FF). Main's Ghidra sync a521bf7 (2026-11-04) made GameCore::mapTimeInTicks a uint, and since
then the compare without a cast has been unsigned (`jb`): a full build of main with every resolver on read 92.9%,
that one instruction. Gynt's d230e6b (2026-10-23) dropped the `(int)` while the field was still an int; this puts
it back, as main's other signed uses of the field already have it (processSingleTimeTick,
getCommandIDFromCommandSelectionStuff, BuildEnemyPlayerList).

Measured with the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1...5387ac5a), the struct
resolvers on and every function resolver of the build list on, sourcehold's reccmp with --resolve-wrapped-calls
--ignore-security-cookie: a build of main's /GL list (the 133 files that exist) and this round's four files, in
these texts, reads 100.0% raw and normalised, no differing line; every other function reads as in the same build
without the four files. The file is not on the /GL list, and this does not add it.

The function is Gynt's (8a3481f, on main since sourcehold#199). Besides the cast and a one-line comment on it, the first
include is the folder's own `../HoveredState.func.hpp`, the same header (style guide rule 14).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… their own selection slot again

The helper is the render function of the selection panel's second row of eight buttons, slot IDs 20 to 27 (menu
items 0x005F5B98 to 0x005F5DC8, after their group item at 0x005F5B48). The original tests the button's slot: `cmp
dword ptr [eax*4 + 0x13884b8], -1` at 0x0043939D is UnitsState + 0x5D0 - 20 * 4, `selectionSlots[slotID - 20]`, the
access the rows' click handler 0x004393C0 makes for slot IDs from 20 (0x00439403). An empty slot holds -1, and the
button is switched off, as 0x00439160 does for the first row.

The imported stub read `selectionSlots[param_1 + -0x14]`; sourcehold's 6a5bead and Gynt's 7ec817c wrote the
same address as `(&selectionEngineers)[i]`. The Ghidra sync 5474d5d (2026-10-25) replaced the per-type fields
with `int selectionUnitType[27]` from 0x564, and the build repair 6b49b55 of the same day wrote
`selectionUnitType[selectionIndex]`, 28 bytes earlier. For slot IDs 20 to 27 that reads the Arabian troops' counts,
which are never -1, and one past the array's end, so seven of the eight buttons have stayed on for an empty slot. A
full build of main read 87.5%, that one compare. This reads `selectionSlots[slotID - 20]`, takes the parameter as
`int slotID` like the two sibling functions, and drops the UnitSelectionEnumInt include and using.

Measured with the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1...5387ac5a), the struct
resolvers on and every function resolver of the build list on, sourcehold's reccmp with --resolve-wrapped-calls
--ignore-security-cookie: a build of main's /GL list (the 133 files that exist) and this round's four files, in
these texts, reads 100.0% raw and normalised, no differing line; every other function reads as in the same build
without the four files. The file is not on the /GL list, and this does not add it.

The function is Gynt's (7ec817c, on main since sourcehold#199; sourcehold's 6a5bead before it). Besides the slot, the
first include is the folder's own `../BuildMenu.func.hpp`, the same header (style guide rule 14), and the button
flag is set TRUE/FALSE as in 0x00439160 (BOOLEnum, rule 5).

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant