From bf1c822a523648ac69cee4cc3de03e0126ecf4c9 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 23 Nov 2026 05:12:42 +0100 Subject: [PATCH 1/4] reimplement: SHC_3BB0A8C1_0x004410D0 100.0% the selected map's two parts 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 (#311), from Gynt's draft (64ea8f99c; his newest reimplement commit on the file is 63cc49fb3f); only the first test changes, with a one-line comment above the two locals saying why they are there. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../DisplayMapDescriptionAndAllocatePlayersToSlots.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/UI/Rendering/DisplayMapDescriptionAndAllocatePlayersToSlots.cpp b/src/OpenSHC/UI/Rendering/DisplayMapDescriptionAndAllocatePlayersToSlots.cpp index c8825476d7..6c5ec971b5 100644 --- a/src/OpenSHC/UI/Rendering/DisplayMapDescriptionAndAllocatePlayersToSlots.cpp +++ b/src/OpenSHC/UI/Rendering/DisplayMapDescriptionAndAllocatePlayersToSlots.cpp @@ -31,9 +31,10 @@ namespace UI { // FUNCTION: STRONGHOLDCRUSADER 0x004410D0 void Rendering::DisplayMapDescriptionAndAllocatePlayersToSlots() { - if (DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset - + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected - >= 0 + // both read up front, the scroll offset first: the plain sum loads them the other way round + int const scrollOffset = DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset; + int const relativeSelected = DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected; + if (relativeSelected + scrollOffset >= 0 || (!DAT_GameSynchronyState::instance.isHost && strlen(DAT_GameSynchronyState::instance.mapName) != 0)) { char mapFileName[1008]; strcpy(mapFileName, DAT_GameSynchronyState::instance.mapName); From 50131f2f0007e6e03f5fae0c80402007f3c19b15 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 23 Nov 2026 05:12:43 +0100 Subject: [PATCH 2/4] reimplement: SHC_3BB0A8C1_0x00489100 100.0% the tick compare signed again, 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 a521bf7bd (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 d230e6b12 (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 (0d29e132b7 in #272, from his draft 93d8290ca; his newest reimplement commit on the file is aa0652f1ed). 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 Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Synchrony/GameSynchronyState/queueCommand.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/Synchrony/GameSynchronyState/queueCommand.cpp b/src/OpenSHC/Synchrony/GameSynchronyState/queueCommand.cpp index 1e8010d234..2bb5693a1c 100644 --- a/src/OpenSHC/Synchrony/GameSynchronyState/queueCommand.cpp +++ b/src/OpenSHC/Synchrony/GameSynchronyState/queueCommand.cpp @@ -26,7 +26,8 @@ namespace Synchrony { this->DAT_GameCommandArray[this->DAT_CurrentGameCommandID].stateUnk = Commands::GCS_UNPROCESSED; this->DAT_GameCommandArray[this->DAT_CurrentGameCommandID].playerUnk = this->DPLAYX_PlayerHandle; this->DAT_GameCommandArray[this->DAT_CurrentGameCommandID].commandType = commandType; - if (DAT_GameCore::instance.mapTimeInTicks > this->mapTimeInTicksSinglePlayer) { + // a signed compare, though mapTimeInTicks is a uint + if ((int)DAT_GameCore::instance.mapTimeInTicks > this->mapTimeInTicksSinglePlayer) { this->DAT_GameCommandArray[this->DAT_CurrentGameCommandID].time = this->commandDelay + DAT_GameCore::instance.mapTimeInTicks; } else { @@ -39,7 +40,7 @@ namespace Synchrony { // Calls the callback function for a specific command. See "GameCommandType" for possible // commands: placing buildings, walls, moving units, ... DAT_ProtocolDefinedData::instance - .commandFunctions[this->DAT_GameCommandArray[this->DAT_CurrentGameCommandID].commandType](); + .commandFunctions[this->DAT_GameCommandArray[this->DAT_CurrentGameCommandID].commandType](); this->DAT_CommandParameterOffset = 0; dword _time = this->DAT_GameCommandArray[this->DAT_CurrentGameCommandID].time; if (0 < (int)_time) { @@ -65,7 +66,7 @@ namespace Synchrony { this->DPLAYX_ReceivedPlayerID = this->DPLAYX_PlayerHandle; this->protocolInvokerPlayerID = this->currentPlayerSlotID; DAT_ProtocolDefinedData::instance - .commandFunctions[this->DAT_GameCommandArray[this->DAT_CurrentGameCommandID].commandType](); + .commandFunctions[this->DAT_GameCommandArray[this->DAT_CurrentGameCommandID].commandType](); } MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::clearGameCommandEntry, this)( this->DAT_CurrentGameCommandID); From 66bceec3741a72e3a175d985a2ccdaf168b13421 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 23 Nov 2026 05:12:44 +0100 Subject: [PATCH 3/4] reimplement: SHC_3BB0A8C1_0x005010E0 100.0% the tick compare signed again, 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 a521bf7bd (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 d230e6b12 (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 (8a3481fad, on main since #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 Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/HoveredState/clearInvalidatedHoverStates.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/UI/HoveredState/clearInvalidatedHoverStates.cpp b/src/OpenSHC/UI/HoveredState/clearInvalidatedHoverStates.cpp index 11e1cde1a3..723f6e5a3f 100644 --- a/src/OpenSHC/UI/HoveredState/clearInvalidatedHoverStates.cpp +++ b/src/OpenSHC/UI/HoveredState/clearInvalidatedHoverStates.cpp @@ -1,4 +1,5 @@ -#include "OpenSHC/UI/HoveredState.func.hpp" +#include "../HoveredState.func.hpp" + #include "OpenSHC/Commands/MappersEnum.hpp" #include "OpenSHC/Game/GameMode.hpp" #include "OpenSHC/UI/HoveredStateElement.hpp" @@ -20,8 +21,9 @@ namespace UI { return; } for (int i = 0; i < 20; ++i) { + // a signed compare, though mapTimeInTicks is a uint if (this->elements[i].type != OpenSHC::Commands::M_MAPPER_NULL - && DAT_GameCore::instance.mapTimeInTicks >= this->elements[i].time) { + && (int)DAT_GameCore::instance.mapTimeInTicks >= this->elements[i].time) { this->elements[i].type = OpenSHC::Commands::M_MAPPER_NULL; } } From d75f1b4e1f353e0ee1945f1d8e6b37f70fffaaa8 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 23 Nov 2026 05:12:44 +0100 Subject: [PATCH 4/4] reimplement: SHC_3BB0A8C1_0x00439390 100.0% the deselect buttons test 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 6a5bead07 and Gynt's 7ec817ccb7 wrote the same address as `(&selectionEngineers)[i]`. The Ghidra sync 5474d5dc9 (2026-10-25) replaced the per-type fields with `int selectionUnitType[27]` from 0x564, and the build repair 6b49b5553 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 (7ec817ccb7, on main since #199; sourcehold's 6a5bead07 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 Co-Authored-By: Claude Opus 5.5 --- ...nu_CurrentlySelectedTroopsDeselectHelper.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroopsDeselectHelper.cpp b/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroopsDeselectHelper.cpp index 61b5b48e2f..bd65eb0d7e 100644 --- a/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroopsDeselectHelper.cpp +++ b/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroopsDeselectHelper.cpp @@ -1,5 +1,4 @@ -#include "OpenSHC/UI/MenuItems/BuildMenu.func.hpp" -#include "OpenSHC/Map/Units/Selection/UnitSelectionEnumInt.hpp" +#include "../BuildMenu.func.hpp" #include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" #include "OpenSHC/Globals/DAT_UnitsState.hpp" @@ -9,19 +8,17 @@ namespace UI { namespace MenuItems { namespace BuildMenu { - using Map::Units::Selection::UnitSelectionEnumInt; - // FUNCTION: STRONGHOLDCRUSADER 0x00439390 - void MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroopsDeselectHelper( - UnitSelectionEnumInt selectionIndex, ...) + void MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroopsDeselectHelper(int slotID, ...) { if (DAT_UnitsState::instance.nHasOwnedUnitInSelection == 0) { - DAT_ButtonUnknownZero::instance = 1; + DAT_ButtonUnknownZero::instance = TRUE; return; } - DAT_ButtonUnknownZero::instance = 0; - if (DAT_UnitsState::instance.selectionUnitType[selectionIndex] == -1) { - DAT_ButtonUnknownZero::instance = 1; + DAT_ButtonUnknownZero::instance = FALSE; + // the deselect buttons are slot IDs 20 to 27 + if (DAT_UnitsState::instance.selectionSlots[slotID - 20] == -1) { + DAT_ButtonUnknownZero::instance = TRUE; } }