From 5b92d36790171706ef619bddb918655212c580b4 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 1 Dec 2026 21:45:33 +0100 Subject: [PATCH 1/6] reimplement: SHC_3BB0A8C1_0x0052F5B0 100.0% Reimplemented UnitsState::ifAnyUnitOnSameTileIsLadderInRightDirection from 62.9% (gynt's text, on main since #238) to 100%. The wall bit is tested apart from the other eleven bits of the mask, in all four directions. MSVC makes one test of 0x4a5015b1 out of the two, as the original has it, and the first one loads the layer into a register (0x0052F5C5). With all bits in one mask it keeps the mask in ebx over the function and nothing after the prolog lines up. The other eleven bits are the mask findFreeTileNearby and findRecentOrSignpostSpawnLocation test on main. A loop over the four even directions reads 0.3297 (quick_diff). The body is gynt's (aa4f048769, 57.6%). Measured with real builds of this branch's tree on main 4591b6fe72 (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). The comment's new wording came after those builds. A small build with it off of the final text (this branch merged with the prepareProjectileTarget one, 550 files, 560 functions) reads every function as the earlier small build with it off did. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...UnitOnSameTileIsLadderInRightDirection.cpp | 30 +++++++++++-------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/OpenSHC/Map/Units/UnitsState/ifAnyUnitOnSameTileIsLadderInRightDirection.cpp b/src/OpenSHC/Map/Units/UnitsState/ifAnyUnitOnSameTileIsLadderInRightDirection.cpp index 5894db828f..f3108e9701 100644 --- a/src/OpenSHC/Map/Units/UnitsState/ifAnyUnitOnSameTileIsLadderInRightDirection.cpp +++ b/src/OpenSHC/Map/Units/UnitsState/ifAnyUnitOnSameTileIsLadderInRightDirection.cpp @@ -14,14 +14,15 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x0052F5B0 BOOLEnum UnitsState::ifAnyUnitOnSameTileIsLadderInRightDirection(int tile, int y) { - /* the original is written out per direction rather than looped */ + // written out per direction, the wall bit tested apart (a loop, and one mask, lose the match) int _neighbourTile = DAT_TileMapState::instance.directionTranslationMatrix[y][0] + tile; if ((DAT_TileMapState::instance.LogicLayer[_neighbourTile] & (LogicHelpers::L_SEA | LogicHelpers::L_BORDER | LogicHelpers::L_BORDER_EDGE - | LogicHelpers::L_ROCKY | LogicHelpers::L_WALL_OR_GATEHOUSE | LogicHelpers::L_BUILDING - | LogicHelpers::L_TREE | LogicHelpers::L_RIVER | LogicHelpers::L_CRENEL_VARIATIONUnk - | LogicHelpers::L_FARM_FIELD_HOP | LogicHelpers::L_FARM_FIELD_DAIRY | LogicHelpers::L_MOAT)) + | LogicHelpers::L_ROCKY | LogicHelpers::L_BUILDING | LogicHelpers::L_TREE + | LogicHelpers::L_RIVER | LogicHelpers::L_CRENEL_VARIATIONUnk | LogicHelpers::L_FARM_FIELD_HOP + | LogicHelpers::L_FARM_FIELD_DAIRY | LogicHelpers::L_MOAT)) == 0 + && (DAT_TileMapState::instance.LogicLayer[_neighbourTile] & LogicHelpers::L_WALL_OR_GATEHOUSE) == 0 && DAT_TileMapState::instance.UnitLayer[_neighbourTile] != 0 && MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::ifAnyUnitOnSameTileIsLadder, this)( _neighbourTile)) { @@ -30,10 +31,11 @@ namespace Map { _neighbourTile = DAT_TileMapState::instance.directionTranslationMatrix[y][2] + tile; if ((DAT_TileMapState::instance.LogicLayer[_neighbourTile] & (LogicHelpers::L_SEA | LogicHelpers::L_BORDER | LogicHelpers::L_BORDER_EDGE - | LogicHelpers::L_ROCKY | LogicHelpers::L_WALL_OR_GATEHOUSE | LogicHelpers::L_BUILDING - | LogicHelpers::L_TREE | LogicHelpers::L_RIVER | LogicHelpers::L_CRENEL_VARIATIONUnk - | LogicHelpers::L_FARM_FIELD_HOP | LogicHelpers::L_FARM_FIELD_DAIRY | LogicHelpers::L_MOAT)) + | LogicHelpers::L_ROCKY | LogicHelpers::L_BUILDING | LogicHelpers::L_TREE + | LogicHelpers::L_RIVER | LogicHelpers::L_CRENEL_VARIATIONUnk | LogicHelpers::L_FARM_FIELD_HOP + | LogicHelpers::L_FARM_FIELD_DAIRY | LogicHelpers::L_MOAT)) == 0 + && (DAT_TileMapState::instance.LogicLayer[_neighbourTile] & LogicHelpers::L_WALL_OR_GATEHOUSE) == 0 && DAT_TileMapState::instance.UnitLayer[_neighbourTile] != 0 && MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::ifAnyUnitOnSameTileIsLadder, this)( _neighbourTile)) { @@ -42,10 +44,11 @@ namespace Map { _neighbourTile = DAT_TileMapState::instance.directionTranslationMatrix[y][4] + tile; if ((DAT_TileMapState::instance.LogicLayer[_neighbourTile] & (LogicHelpers::L_SEA | LogicHelpers::L_BORDER | LogicHelpers::L_BORDER_EDGE - | LogicHelpers::L_ROCKY | LogicHelpers::L_WALL_OR_GATEHOUSE | LogicHelpers::L_BUILDING - | LogicHelpers::L_TREE | LogicHelpers::L_RIVER | LogicHelpers::L_CRENEL_VARIATIONUnk - | LogicHelpers::L_FARM_FIELD_HOP | LogicHelpers::L_FARM_FIELD_DAIRY | LogicHelpers::L_MOAT)) + | LogicHelpers::L_ROCKY | LogicHelpers::L_BUILDING | LogicHelpers::L_TREE + | LogicHelpers::L_RIVER | LogicHelpers::L_CRENEL_VARIATIONUnk | LogicHelpers::L_FARM_FIELD_HOP + | LogicHelpers::L_FARM_FIELD_DAIRY | LogicHelpers::L_MOAT)) == 0 + && (DAT_TileMapState::instance.LogicLayer[_neighbourTile] & LogicHelpers::L_WALL_OR_GATEHOUSE) == 0 && DAT_TileMapState::instance.UnitLayer[_neighbourTile] != 0 && MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::ifAnyUnitOnSameTileIsLadder, this)( _neighbourTile)) { @@ -54,10 +57,11 @@ namespace Map { _neighbourTile = DAT_TileMapState::instance.directionTranslationMatrix[y][6] + tile; if ((DAT_TileMapState::instance.LogicLayer[_neighbourTile] & (LogicHelpers::L_SEA | LogicHelpers::L_BORDER | LogicHelpers::L_BORDER_EDGE - | LogicHelpers::L_ROCKY | LogicHelpers::L_WALL_OR_GATEHOUSE | LogicHelpers::L_BUILDING - | LogicHelpers::L_TREE | LogicHelpers::L_RIVER | LogicHelpers::L_CRENEL_VARIATIONUnk - | LogicHelpers::L_FARM_FIELD_HOP | LogicHelpers::L_FARM_FIELD_DAIRY | LogicHelpers::L_MOAT)) + | LogicHelpers::L_ROCKY | LogicHelpers::L_BUILDING | LogicHelpers::L_TREE + | LogicHelpers::L_RIVER | LogicHelpers::L_CRENEL_VARIATIONUnk | LogicHelpers::L_FARM_FIELD_HOP + | LogicHelpers::L_FARM_FIELD_DAIRY | LogicHelpers::L_MOAT)) == 0 + && (DAT_TileMapState::instance.LogicLayer[_neighbourTile] & LogicHelpers::L_WALL_OR_GATEHOUSE) == 0 && DAT_TileMapState::instance.UnitLayer[_neighbourTile] != 0 && MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::ifAnyUnitOnSameTileIsLadder, this)( _neighbourTile)) { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 98c4514966..830dd375f0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -49335,7 +49335,7 @@ SHC_3BB0A8C1_0x0052F550 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052F570 | 0.0% | Pending -SHC_3BB0A8C1_0x0052F5B0 | 62.9% | Asm differs +SHC_3BB0A8C1_0x0052F5B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0052F680 | 100.0% | Reimplemented From cae5ec91e9a66636c24d3f2c1de80fef0b4135fc Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 1 Dec 2026 21:45:33 +0100 Subject: [PATCH 2/6] reimplement: SHC_3BB0A8C1_0x00533D50 100.0% Reimplemented UnitsState::updateUnitFadeAndVisibilityNearStructures from 85.1% / 75.2% (gynt's text, on main since #238) to 100%. Three edits, each measured with quick_diff (0.8032 before): - `vanish = 0` is stored in the two arms it belongs to instead of in one arm behind an `||`. MSVC makes one store of them again (0x00533F23), but with two it keeps the 0 in edx from 0x00533EAC to the last test, as the original does: 0.9600. - The four locals that start at 0 are declared in the order fade type, on a structure, tower, gate: 0.9760. - destinationBuildingID is read in front of destinationFlags, which puts the destination tile in esi (0x00533E5D): 1.0000. The body is gynt's (e3df755f45 56.3%, c6efbfcf12 77.0%, f2e1b62abf 85.1%). Measured with real builds of this branch's tree on main 4591b6fe72 (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...ateUnitFadeAndVisibilityNearStructures.cpp | 40 +++++++++++-------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/OpenSHC/Map/Units/UnitsState/updateUnitFadeAndVisibilityNearStructures.cpp b/src/OpenSHC/Map/Units/UnitsState/updateUnitFadeAndVisibilityNearStructures.cpp index 658ef5d8a0..8bccb61ea7 100644 --- a/src/OpenSHC/Map/Units/UnitsState/updateUnitFadeAndVisibilityNearStructures.cpp +++ b/src/OpenSHC/Map/Units/UnitsState/updateUnitFadeAndVisibilityNearStructures.cpp @@ -19,12 +19,12 @@ namespace Map { void UnitsState::updateUnitFadeAndVisibilityNearStructures(int unitID) { int _fadeType = 0; + BOOLEnum _isOnDefensiveStructure = FALSE; + int _towerFadeType = 0; + int _gateFadeType = 0; int _tile = DAT_UnitsState::instance.units[unitID].tile; int const buildingID = DAT_TileMapState::instance.BuildingLayer[_tile]; uint _logicFlags = DAT_TileMapState::instance.LogicLayer[_tile]; - int _gateFadeType = 0; - BOOLEnum _isOnDefensiveStructure = FALSE; - int _towerFadeType = 0; if (DAT_UnitsState::instance.units[unitID].unknownCountdown_0x402 != 0) { --DAT_UnitsState::instance.units[unitID].unknownCountdown_0x402; } @@ -73,12 +73,12 @@ namespace Map { } } if (_gateFadeType != 0) { - uint const destinationFlags - = DAT_TileMapState::instance - .LogicLayer[DAT_UnitsState::instance.units[unitID].destinationTilePosition]; int const destinationBuildingID = DAT_TileMapState::instance .BuildingLayer[DAT_UnitsState::instance.units[unitID].destinationTilePosition]; + uint const destinationFlags + = DAT_TileMapState::instance + .LogicLayer[DAT_UnitsState::instance.units[unitID].destinationTilePosition]; if ((destinationFlags & LogicHelpers::L_WALL_OR_GATEHOUSE) != 0 && (destinationFlags & LogicHelpers::L_STOCKPILEUnk) == 0) { DAT_UnitsState::instance.units[unitID].unknownCountdown_0x402 = 0; @@ -98,18 +98,24 @@ namespace Map { } else { DAT_UnitsState::instance.units[unitID].field_0x308 = 0; } - if (DAT_UnitsState::instance.units[unitID].unknownCountdown_0x402 == 0 - || (DAT_TileMapState::instance.MiscDisplayLayer[DAT_UnitsState::instance.units[unitID].nextTileUnk] - & LogicHelpers::MD_BATCHED_SPRITES) - != 0) { + // 0 is stored in both arms (one arm behind an || loses the match) + if (DAT_UnitsState::instance.units[unitID].unknownCountdown_0x402 != 0) { + if ((DAT_TileMapState::instance.MiscDisplayLayer[DAT_UnitsState::instance.units[unitID].nextTileUnk] + & LogicHelpers::MD_BATCHED_SPRITES) + == 0) { + if ((DAT_TileMapState::instance + .MiscDisplayLayer[DAT_UnitsState::instance.units[unitID].currentTilePosition_2Unk] + & LogicHelpers::MD_BATCHED_SPRITES) + != 0) { + DAT_UnitsState::instance.units[unitID].vanish = 15; + } else if (DAT_UnitsState::instance.units[unitID].vanish <= 0) { + DAT_UnitsState::instance.units[unitID].vanish = 1; + } + } else { + DAT_UnitsState::instance.units[unitID].vanish = 0; + } + } else { DAT_UnitsState::instance.units[unitID].vanish = 0; - } else if ((DAT_TileMapState::instance - .MiscDisplayLayer[DAT_UnitsState::instance.units[unitID].currentTilePosition_2Unk] - & LogicHelpers::MD_BATCHED_SPRITES) - != 0) { - DAT_UnitsState::instance.units[unitID].vanish = 15; - } else if (DAT_UnitsState::instance.units[unitID].vanish <= 0) { - DAT_UnitsState::instance.units[unitID].vanish = 1; } if (_fadeType != 0) { DAT_UnitsState::instance.units[unitID].fadeType = _fadeType; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 830dd375f0..e608a2da0e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -50693,7 +50693,7 @@ SHC_3BB0A8C1_0x00533C70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00533CA0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00533D50 | 77.0% | Asm differs +SHC_3BB0A8C1_0x00533D50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00533F48 | 0.0% | Pending From ee70bf67963a59bb3e50949c91abbff589f6f52c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 1 Dec 2026 21:45:34 +0100 Subject: [PATCH 3/6] reimplement: SHC_3BB0A8C1_0x00536780 100.0% Reimplemented UnitsState::isTowerTileOvercrowdedByCurrentPlayer from 66.2% / 56.9% to 100% by taking it off the /GL list. The text is gynt's but for its two comments, the name of the loop's index and the result written as TRUE / FALSE (bcbf6a4df5 73.7%; 01185835d0, where he recorded 100%). The original reads the building's widthOrHeight again for each call in the loop (0x00536817) and loads currentPlayerSlotID in front of the unit loop (0x00536850): it did not see into getBuildingSizeIndexMappingData, which is on main's /GL list. No .cpp on main calls the function, so nothing else sees its body. The do loop stays: a for reads 0.8882 against 0.9733 (quick_diff; what is left of the 0.9733 is notation), and so does the selection loop's `<= countof(...) - 1`: `<` compares with 27 and jl where the original has 26 and jle (0.9600). Measured with real builds of this branch's tree on main 4591b6fe72 (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). The name of the loop's index and the result written as TRUE / FALSE came after those builds. A small build with it off of the final text (this branch merged with the prepareProjectileTarget one, 550 files, 560 functions) reads every function as the earlier small build with it off did. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- cmake/compiler-flags-gl.txt | 1 - .../isTowerTileOvercrowdedByCurrentPlayer.cpp | 22 ++++++++++++------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index cb59c23cfb..5653597e04 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -294,7 +294,6 @@ src/OpenSHC/Map/Units/UnitsState/giveMoveCommand.cpp src/OpenSHC/Map/Units/UnitsState/handleUnitMovementWhenTargetingBuildings.cpp src/OpenSHC/Map/Units/UnitsState/harassBuildingsWithSiegeAI.cpp src/OpenSHC/Map/Units/UnitsState/ifAnyUnitOnSameTileIsLadderInRightDirection.cpp -src/OpenSHC/Map/Units/UnitsState/isTowerTileOvercrowdedByCurrentPlayer.cpp src/OpenSHC/Map/Units/UnitsState/isWorkerAtProductionIdleState.cpp src/OpenSHC/Map/Units/UnitsState/prepareProjectileTarget.cpp src/OpenSHC/Map/Units/UnitsState/processEntityDamageToUnit.cpp diff --git a/src/OpenSHC/Map/Units/UnitsState/isTowerTileOvercrowdedByCurrentPlayer.cpp b/src/OpenSHC/Map/Units/UnitsState/isTowerTileOvercrowdedByCurrentPlayer.cpp index 2d00e5ce8e..3d908bb7e5 100644 --- a/src/OpenSHC/Map/Units/UnitsState/isTowerTileOvercrowdedByCurrentPlayer.cpp +++ b/src/OpenSHC/Map/Units/UnitsState/isTowerTileOvercrowdedByCurrentPlayer.cpp @@ -40,10 +40,10 @@ namespace Map { } int _buildingY = DAT_BuildingsState::instance.buildings[_buildingID].y; int _buildingX = DAT_BuildingsState::instance.buildings[_buildingID].x; - /* The original counts the own units in the parameter's stack slot. */ + // the original counts the own units in the parameter's stack slot tile = 0; int _constructionTile = 0; - /* a do-while: the original runs the body once even when there is no construction tile */ + // a do-while: the body runs once even without a construction tile (a for loses the match) do { MACRO_CALL_MEMBER( OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, DAT_TileMapState::ptr)( @@ -68,14 +68,20 @@ namespace Map { } _tileCapacity -= tile; int _selectedUnitCount = 0; - for (int i = 0; i <= countof(this->selectionUnitType) - 1; ++i) { - if (i != Selection::USE_E_KNIGHTS && i != Selection::USE_E_LADDERMEN - && i != Selection::USE_E_BATTERING_RAMS && i != Selection::USE_E_TREBUCHETS - && i != Selection::USE_E_CATAPULTS && i != Selection::USE_E_SIEGETOWERS) { - _selectedUnitCount += this->selectionUnitType[i]; + for (int selectionType = 0; selectionType <= countof(this->selectionUnitType) - 1; + ++selectionType) { + if (selectionType != Selection::USE_E_KNIGHTS && selectionType != Selection::USE_E_LADDERMEN + && selectionType != Selection::USE_E_BATTERING_RAMS + && selectionType != Selection::USE_E_TREBUCHETS + && selectionType != Selection::USE_E_CATAPULTS + && selectionType != Selection::USE_E_SIEGETOWERS) { + _selectedUnitCount += this->selectionUnitType[selectionType]; } } - return _selectedUnitCount > _tileCapacity * 2; + if (_selectedUnitCount > _tileCapacity * 2) { + return TRUE; + } + return FALSE; } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e608a2da0e..896172f54b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -51143,7 +51143,7 @@ SHC_3BB0A8C1_0x00536690 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00536710 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00536780 | 73.7% | Asm differs +SHC_3BB0A8C1_0x00536780 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00536860 | 0.0% | Pending From 207da14324d96f563b42638b824f2e54ce6fc43e Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 1 Dec 2026 21:45:35 +0100 Subject: [PATCH 4/6] reimplement: SHC_3BB0A8C1_0x00536E30 100.0% Reimplemented UnitsState::giveMoveCommand from 94.5% / 93.1% (gynt's text, on main since #238) to 100%. Only the stack slots of _mostFrequentUnitType and _canReachDestination were swapped. MSVC hands the dead parameters' slots out by reference count, counted before it merges equal code. `_canReachDestination = FALSE` now stands in an arm of its own for the blocked tile and for the failed path instead of once behind an `||`; the two stores become one again (0x00536F60), but the variable counts one reference more and takes the first slot. The two calls that return BOOLEnum are tested by truthiness (the same listing). The body is gynt's (742a29f44f 74.4%, c0b593b221 94.5%). Measured with real builds of this branch's tree on main 4591b6fe72 (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). The second truth test and the plain 0 for maximumCount came after those builds. A small build with it off of the final text (this branch merged with the prepareProjectileTarget one, 550 files, 560 functions) reads every function as the earlier small build with it off did. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../Map/Units/UnitsState/giveMoveCommand.cpp | 21 +++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/OpenSHC/Map/Units/UnitsState/giveMoveCommand.cpp b/src/OpenSHC/Map/Units/UnitsState/giveMoveCommand.cpp index 9643d89b19..c6891c11b7 100644 --- a/src/OpenSHC/Map/Units/UnitsState/giveMoveCommand.cpp +++ b/src/OpenSHC/Map/Units/UnitsState/giveMoveCommand.cpp @@ -36,9 +36,8 @@ namespace Map { DAT_GameSynchronyState::instance.DAT_GameCommandParam4 = matchUnitSpeeds; MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( OpenSHC::Commands::GCT_UNITS_MOVE); - UnitType _mostFrequentUnitType - = MACRO_CALL_MEMBER(OpenSHC::Map::Units::TribesState_Func::getMajoritySelectedUnitType, - DAT_TribesState::ptr)(tribeID, (int*)0); + UnitType _mostFrequentUnitType = MACRO_CALL_MEMBER( + OpenSHC::Map::Units::TribesState_Func::getMajoritySelectedUnitType, DAT_TribesState::ptr)(tribeID, 0); dword _areaAtDestination = DAT_TileMapState::instance .PathConnectionLayer[DAT_ViewportRenderState::instance.viewportState.cursorTile]; @@ -64,19 +63,19 @@ namespace Map { _canReachDestination = TRUE; } if (MACRO_CALL_MEMBER( - OpenSHC::Map::Units::UnitsState_Func::selectionHasMobileAssaultUnits, DAT_UnitsState::ptr)() - != 0) { + OpenSHC::Map::Units::UnitsState_Func::selectionHasMobileAssaultUnits, DAT_UnitsState::ptr)()) { int _destinationY = DAT_ViewportRenderState::instance .tileTranslationMatrix_YComponent[DAT_ViewportRenderState::instance.viewportState.cursorTile]; int _destinationX = DAT_ViewportRenderState::instance.viewportState.cursorTile - DAT_ViewportRenderState::instance.translationMatrix[_destinationY].addXgetTile; - if (_blockedAtDestination != 0 - || MACRO_CALL_MEMBER( - OpenSHC::Map::Navigation::PathFindingState_Func::calculatePathKeepAndWallsGatesNotAllowed, - DAT_PathFindingState::ptr)(DAT_UnitsState::instance.units[_combatUnitID].x, - DAT_UnitsState::instance.units[_combatUnitID].y, _destinationX, _destinationY, 100000) - == 0) { + // stored in both arms (one store behind an || loses the match) + if (_blockedAtDestination != 0) { + _canReachDestination = FALSE; + } else if (!MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func:: + calculatePathKeepAndWallsGatesNotAllowed, + DAT_PathFindingState::ptr)(DAT_UnitsState::instance.units[_combatUnitID].x, + DAT_UnitsState::instance.units[_combatUnitID].y, _destinationX, _destinationY, 100000)) { _canReachDestination = FALSE; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 896172f54b..10db104370 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -51217,7 +51217,7 @@ SHC_3BB0A8C1_0x00536DE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00536E10 | 0.0% | Pending -SHC_3BB0A8C1_0x00536E30 | 94.5% | Asm differs +SHC_3BB0A8C1_0x00536E30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00537070 | 100.0% | Reimplemented From af418d138ee48d9626fb9190f71879f0f32b6d64 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 1 Dec 2026 21:45:35 +0100 Subject: [PATCH 5/6] reimplement: SHC_3BB0A8C1_0x0053A070 100.0% Reimplemented UnitsState::isWorkerAtProductionIdleState from 48.1% / 46.2% (gynt's text, on main since #238) to 100%. Each unit type has its own arm, in the order of the type's value, instead of one arm per state. MSVC folds the equal arms (the jump table's order is the one the types give), but counts their references first, and the state then takes eax as in the original (0x0053A07C) and the pointer and the type ecx (quick_diff 0.5057 -> 1.0000). selectWorkerSpeechOrMoraleStateID 0x0053DDD0, which calls it, goes back from 83.9% / 71.1% to 100.0% / 100.0% with its text unchanged: our function no longer uses edx. gynt described that in 1fab2cfcaa and had it at 100% before (390b34b98e). Its status line (74.4%) follows. The body here is gynt's (69a106e68b 64.0%, 1fab2cfcaa 48.1%). Measured with real builds of this branch's tree on main 4591b6fe72 (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). The name US_UNKNOWN_10 for the state 10 came after those builds. A small build with it off of the final text (this branch merged with the prepareProjectileTarget one, 550 files, 560 functions) reads every function as the earlier small build with it off did. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../isWorkerAtProductionIdleState.cpp | 64 +++++++++++++++---- status/addresses-SHC-3BB0A8C1.txt | 4 +- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/OpenSHC/Map/Units/UnitsState/isWorkerAtProductionIdleState.cpp b/src/OpenSHC/Map/Units/UnitsState/isWorkerAtProductionIdleState.cpp index 50ab2829c3..f88b488528 100644 --- a/src/OpenSHC/Map/Units/UnitsState/isWorkerAtProductionIdleState.cpp +++ b/src/OpenSHC/Map/Units/UnitsState/isWorkerAtProductionIdleState.cpp @@ -14,33 +14,24 @@ namespace Map { BOOLEnum UnitsState::isWorkerAtProductionIdleState(int unitID) { int const _state = this->units[unitID].state.generic; + // one arm per type (one arm per state loses the match) switch (this->units[unitID].unitType) { case OpenSHC::Map::Units::UT_WOODCUTTER: - case OpenSHC::Map::Units::UT_HOPSFARMER: - case OpenSHC::Map::Units::UT_MILLER: - case OpenSHC::Map::Units::UT_BREWER: - case OpenSHC::Map::Units::UT_POLETURNER: - case OpenSHC::Map::Units::UT_SMITH: - case OpenSHC::Map::Units::UT_ARMORER: - case OpenSHC::Map::Units::UT_TANNER: if (_state == OpenSHC::Map::Units::States::US_STAND_UPUnk) { return TRUE; } break; case OpenSHC::Map::Units::UT_FLETCHER: - case OpenSHC::Map::Units::UT_APPLEFARMER: if (_state == OpenSHC::Map::Units::States::US_LOOK_AROUNDUnk) { return TRUE; } break; case OpenSHC::Map::Units::UT_HUNTER: - case OpenSHC::Map::Units::UT_DAIRYFARMER: if (_state == OpenSHC::Map::Units::States::US_AIM_WEAPONUnk) { return TRUE; } break; case OpenSHC::Map::Units::UT_QUARRYWORKER: - case OpenSHC::Map::Units::UT_PITCHMAN: if (_state == OpenSHC::Map::Units::States::US_STATE_3Unk) { return TRUE; } @@ -50,8 +41,33 @@ namespace Map { return TRUE; } break; + case OpenSHC::Map::Units::UT_PITCHMAN: + if (_state == OpenSHC::Map::Units::States::US_STATE_3Unk) { + return TRUE; + } + break; case OpenSHC::Map::Units::UT_WHEATFARMER: - if (_state == (UnitState)10) { + if (_state == OpenSHC::Map::Units::States::US_UNKNOWN_10) { + return TRUE; + } + break; + case OpenSHC::Map::Units::UT_HOPSFARMER: + if (_state == OpenSHC::Map::Units::States::US_STAND_UPUnk) { + return TRUE; + } + break; + case OpenSHC::Map::Units::UT_APPLEFARMER: + if (_state == OpenSHC::Map::Units::States::US_LOOK_AROUNDUnk) { + return TRUE; + } + break; + case OpenSHC::Map::Units::UT_DAIRYFARMER: + if (_state == OpenSHC::Map::Units::States::US_AIM_WEAPONUnk) { + return TRUE; + } + break; + case OpenSHC::Map::Units::UT_MILLER: + if (_state == OpenSHC::Map::Units::States::US_STAND_UPUnk) { return TRUE; } break; @@ -60,10 +76,36 @@ namespace Map { return TRUE; } break; + case OpenSHC::Map::Units::UT_BREWER: + if (_state == OpenSHC::Map::Units::States::US_STAND_UPUnk) { + return TRUE; + } + break; + case OpenSHC::Map::Units::UT_POLETURNER: + if (_state == OpenSHC::Map::Units::States::US_STAND_UPUnk) { + return TRUE; + } + break; + case OpenSHC::Map::Units::UT_SMITH: + if (_state == OpenSHC::Map::Units::States::US_STAND_UPUnk) { + return TRUE; + } + break; + case OpenSHC::Map::Units::UT_ARMORER: + if (_state == OpenSHC::Map::Units::States::US_STAND_UPUnk) { + return TRUE; + } + break; + case OpenSHC::Map::Units::UT_TANNER: + if (_state == OpenSHC::Map::Units::States::US_STAND_UPUnk) { + return TRUE; + } + break; case OpenSHC::Map::Units::UT_TRANSPORTMINER: if (_state == OpenSHC::Map::Units::States::US_RELOAD_WEAPONUnk) { return TRUE; } + break; } return FALSE; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 10db104370..0c44c13908 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -59427,7 +59427,7 @@ SHC_3BB0A8C1_0x0053A018 | 0.0% | Pending SHC_3BB0A8C1_0x0053A020 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0053A070 | 64.0% | Asm differs +SHC_3BB0A8C1_0x0053A070 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0053A108 | 0.0% | Pending @@ -60037,7 +60037,7 @@ SHC_3BB0A8C1_0x0053DCB4 | 0.0% | Pending SHC_3BB0A8C1_0x0053DCC0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0053DDD0 | 74.4% | Style pass, asm differs +SHC_3BB0A8C1_0x0053DDD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0053E330 | 0.0% | Pending From 6b1c1bc97682b64c70bc94b86b876d657a3b2bcc Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 1 Dec 2026 21:45:36 +0100 Subject: [PATCH 6/6] reimplement: SHC_3BB0A8C1_0x0053E440 100.0% Reimplemented UnitsState::spawnUnit from 94.5% / 89.6% (gynt's text, on main since #238) to 100%. Store order only. The unit's time is stored from mapTimeInTicks directly behind the uid (no local), and the height behind the two micro positions: the scheduler then gives the original's order from 0x0053E491 on (quick_diff 0.9484 -> 0.9871). movementRelated is set in front of field_0xe8 (0x0053E58B), which swaps the last two stores: the same listing as the original. The catapult and trebuchet arms stay apart: the original has both, and one test with || reads 0.8467. The rest is gynt's (f0121098c8 53.1%, 77ba3d701a 92.9%, 351b48a113 94.5%). Measured with real builds of this branch's tree on main 4591b6fe72 (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): 100.0 / 100.0 in a small build with OPENSHC_FUNCTION_VISIBILITY_UNITS off, in one with it on, and in a full build with it off (of this branch merged with the prepareProjectileTarget one). The names of the constants, the last slot written from countof and the comment came after those builds. A small build with it off of the final text (this branch merged with the prepareProjectileTarget one, 550 files, 560 functions) reads every function as the earlier small build with it off did. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../Map/Units/UnitsState/spawnUnit.cpp | 22 ++++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/OpenSHC/Map/Units/UnitsState/spawnUnit.cpp b/src/OpenSHC/Map/Units/UnitsState/spawnUnit.cpp index fef375364e..4b2ffd69a5 100644 --- a/src/OpenSHC/Map/Units/UnitsState/spawnUnit.cpp +++ b/src/OpenSHC/Map/Units/UnitsState/spawnUnit.cpp @@ -2,6 +2,7 @@ #include "OpenSHC/Random/RNG.func.hpp" #include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Map/Buildings/Enums/DefensiveTowerEngineType.hpp" #include "OpenSHC/Map/Units/UnitInstructionType.hpp" #include "OpenSHC/Map/Units/UnitLogicState.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" @@ -25,13 +26,12 @@ namespace Map { int UnitsState::spawnUnit(int playerID, int displayColor, int microXPosition, int microYPosition, int terrainHeight, UnitType unitType) { - /* Loop until we find free slot. */ int _unitID = 1; for (; _unitID < countof(this->units); ++_unitID) { if (this->units[_unitID].logicalState == OpenSHC::Map::Units::ULS_INVISIBLE) { break; } - if (_unitID >= 2499) { + if (_unitID >= countof(this->units) - 1) { return 0; } } @@ -39,14 +39,13 @@ namespace Map { this->maxUnitCount = _unitID + 1; } this->units[_unitID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; - dword _time = DAT_GameCore::instance.mapTimeInTicks; ++DAT_GameCore::instance.uniqueGameObjectTracker; + this->units[_unitID].time = DAT_GameCore::instance.mapTimeInTicks; this->units[_unitID].logicalState = (UnitLogicState)1; this->units[_unitID].owner = playerID; - this->units[_unitID].terrainOrClimbHeight = terrainHeight; this->units[_unitID].microXPosition = microXPosition + 4; - this->units[_unitID].time = _time; this->units[_unitID].microYPosition = microYPosition + 4; + this->units[_unitID].terrainOrClimbHeight = terrainHeight; this->units[_unitID].calculatedOwnerPlayerIndex = (short)displayColor; this->units[_unitID].facingDirection = 0; this->units[_unitID].displayColorPlayerID = displayColor; @@ -57,7 +56,8 @@ namespace Map { } else if (unitType == OpenSHC::Map::Units::UT_CAGEDOG) { this->units[_unitID].calculatedOwnerPlayerIndex = 0; } - this->units[_unitID].field_0xe8 = 0; + this->units[_unitID].movementRelated = 8; + this->units[_unitID].field_0xe8 = FALSE; int _x = this->units[_unitID].microXPosition / 8; int _y = this->units[_unitID].microYPosition / 8; this->units[_unitID].mimicCurrentYPosition = _y; @@ -66,12 +66,12 @@ namespace Map { this->units[_unitID].mimicCurrentXPosition = _x; this->units[_unitID].x = _x; this->units[_unitID].destinationX_2Unk = _x; - this->units[_unitID].movementRelated = 8; this->units[_unitID].tile = this->units[_unitID].x + DAT_ViewportRenderState::instance.translationMatrix[this->units[_unitID].y].addXgetTile; - this->units[_unitID].targetingType = (UnitInstructionType)0; + this->units[_unitID].targetingType = OpenSHC::Map::Units::UIT_NONE; this->units[_unitID].fixedRng = SEC_RNG::instance.currentNumber2; MACRO_CALL_MEMBER(OpenSHC::Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + // the original has the catapult and trebuchet arms apart (one test with || loses the match) if (unitType == OpenSHC::Map::Units::UT_S_CATAPULT) { if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] != -1) { this->units[_unitID].stoneAmmunition = 20; @@ -91,12 +91,14 @@ namespace Map { } else if (unitType == OpenSHC::Map::Units::UT_S_MANGONEL) { int const buildingID = DAT_TileMapState::instance.BuildingLayer[this->units[_unitID].tile]; if (buildingID != 0) { - DAT_BuildingsState::instance.buildings[buildingID].defensiveTowerEngineType = 1; + DAT_BuildingsState::instance.buildings[buildingID].defensiveTowerEngineType + = OpenSHC::Map::Buildings::Enums::DTET_MANGONEL; } } else if (unitType == OpenSHC::Map::Units::UT_S_BALLISTA) { int const buildingID = DAT_TileMapState::instance.BuildingLayer[this->units[_unitID].tile]; if (buildingID != 0) { - DAT_BuildingsState::instance.buildings[buildingID].defensiveTowerEngineType = 2; + DAT_BuildingsState::instance.buildings[buildingID].defensiveTowerEngineType + = OpenSHC::Map::Buildings::Enums::DTET_BALLISTA; } } else if (unitType == OpenSHC::Map::Units::UT_CHILD) { if ((this->units[_unitID].fixedRng & 0x80) != 0) { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 0c44c13908..4ff5573a62 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -60085,7 +60085,7 @@ SHC_3BB0A8C1_0x0053E384 | 0.0% | Pending SHC_3BB0A8C1_0x0053E390 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0053E440 | 92.9% | Asm differs +SHC_3BB0A8C1_0x0053E440 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0053E6C0 | 100.0% | Reimplemented