Repository navigation
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
Open
Four functions on main back to 100%: two signed tick compares, a selection slot and a load order#478kotijekriv wants to merge 4 commits into
kotijekriv wants to merge 4 commits into
Conversation
…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
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.
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%).Rendering::DisplayMapDescriptionAndAllocatePlayersToSlotsGameSynchronyState::queueCommandHoveredState::clearInvalidatedHoverStatesBuildMenu::MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroopsDeselectHelperEach commit credits gynt as co-author.
The two tick compares (queueCommand, clearInvalidatedHoverStates)
cmp ecx, eaxandjleat 0x00489183 (againstmapTimeInTicksSinglePlayer), andcmp edx, [eax + 8]andjlat 0x005010FF (against each hover entry's time).GameCore::mapTimeInTicksauint. 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 anint.(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).The deselect helper tests its own slot again (behaviour fix)
selectionSlots[slotID - 20] == -1:cmp dword ptr [eax*4 + 0x13884b8], -1at 0x0043939D isUnitsState+ 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.int selectionUnitType[27]from 0x564, and the build repair 6b49b55 of the same day wroteselectionUnitType[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.selectionSlots[slotID - 20], as the imported stub had it (selectionSlots[param_1 + -0x14]), with the parameter asint slotIDlike the two sibling functions. The UnitSelectionEnumInt include andusinggo, and the button flag is set with TRUE / FALSE as in 0x00439160.DisplayMapDescriptionAndAllocatePlayersToSlots: the selected map's two parts
DAT_MapSelectionScrollOffsetinto eax, thenDAT_MapSelectionRelativeSelectedinto ecx, and adds into ecx (0x004410E4 to 0x004410F4). Ours loaded them the other way round, and the second sum at 0x004411E8 swapped with it.int constlocals, the scroll offset first, and tested asrelativeSelected + 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.Measured
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./GLlist (none of these files is on it), and with 0x004314E0 (theMapEditorLandscaping_GeneralButtonshandler) left out and its resolver off, as in main's baseline: 0 failed, 99.59 over 2,441 functions.DisplayMapDescriptionAndAllocatePlayersToSlots,queueCommand,clearInvalidatedHoverStatesandMenuItemRenderFunction_BuildMenu_CurrentlySelectedTroopsDeselectHelperread 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) andMenu::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'sMenuModalRenderFunction_ProgressBarBoxand its constructor, UI: the single-player game launch at 100% #466'sLaunchSinglePlayerGameUnk) (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)./GLlist (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.../*.func.hppfirst (the same header), queueCommand is clang-formatted (two continuation lines move), and the deselect helper sets its BOOLEnum flag with TRUE / FALSE.(int)casts onDAT_GameCore::instance.mapTimeInTicks(below). Our local fixer finds nothing to change.Proposed, not changed here
GameCore::mapTimeInTicksback toint? It becameuintin a521bf7. The original uses it signed in the two functions here, in the three places where main already casts it with(int)(BuildEnemyPlayerList, getCommandIDFromCommandSelectionStuff, and processSingleTimeTick's% 200), and in teamIsWeakRelativeToEnemy (jgeat 0x004D01F5 and 0x004D0246) and lightUpBuilding (jleat 0x0041C8DC). Those two read 87.3% and 99.3% in a full build of main, and gynt's Reimplement 90 AI::AICState functions at 100% #371 and reimpl/BuildingsState #234 put the same(int)back in them. One use is unsigned in the original: playRandomAmbientMusic's200 < mapTimeInTicks - someSoundMatchTime_1isjbeat 0x0047B95C, so anintfield needs a(uint)there (or someSoundMatchTime_1 asuint). processSyncPacket takes the absolute value of its difference, the same either way; the other users on main mask, add, xor or store it. Open PRs add users that would have to be measured too (Reimpl/map units updatefunctions #204's% 40tests, the casts in Reimplement native multiplayer command selection and ordering #221, Reimpl/units state #238, Reimpl/TribesState development #279, Reimplement 9 GameSynchronyState and UI::Helpers functions (draft: 7 below 100%, 2 wait on a header question) #321), so this PR keeps the casts.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%) andTriggerInvasion_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 onepush edischeduled three instructions later than the original; ten declaration orders of its locals don't move it.🤖 Generated with Claude Code