From 9e1147bf071e731ab14dbb654d0a922b328518c8 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 19:01:34 +0100 Subject: [PATCH 1/9] reimplement: SHC_3BB0A8C1_0x004B66C0 97.6% The siege engines' colour index, two loads and the colour's push differ MinimapViewState::drawMinimap, the minimap: it copies the terrain picture from the minimap buffer to the screen (or to the loaded map's preview), draws every unit as a dot in its player's colour (with the wildlife hidden: own team and enemies in two colours), and draws the viewport's box. 946 instructions, rewritten from the original's listing, with gynt's draft beside it for the names: his best version is 10280b1610 on his fork's reimpl/UI-Core-development ("32.8% | Reimplemented, asm differs"), his own commits for it f3cc8dd1a8 (23.32%) and 34548c6b31 (19.14%), on #256 c899be140 and 95d388a35, the newest e9bc49c129 on reimpl/UI-MenuItems-development (23.3%). Behaviour against the draft (every version): - `mapSize <= 200` where the draft has `< 200`: on a 200-tile map the draft reads the picture 100 columns and 100 rows away from where the original reads it; - the viewport box: the original returns where the draft has two empty ifs, so when the box sticks out on both sides it draws none (gynt has the returns himself in 8ca78619cd on reimpl/Wilps-2026-10-18); - with the wildlife hidden, the original shows an enemy assassin up to and including distance 160; the draft only below 160 (mode 1's test is right in the draft); - the minimap buffer through `this` as in the original (the draft goes through the global instance; the same while `this` is that instance, and all five call sites pass their own `this`). What the match needed: the blit and the four pixel stores are handwritten assembly in the original (inline assembly here; it also brings the frame pointer); the loop variables of the two unit loops declared once at the function's level (declared per loop, their stack slots differ); the box position as two locals and the two offsets as the tile position; MC_MAP_SIZE_400 - mapSize written out each time; the first ten initialisations in the order found by a search over the orders; the colour switch in the original's block order. The numbers are main's map and screen-tile-table constants, as on #465. Left (five instructions, found by a slot-blind comparison): the siege engines' colour index (2), where the original keeps a - 8 in the lea and its table base 0x00B39560, player 1's entry (every spelling tried folds it into the base); two loads swapped in front of the first unit loop's pixel loops (2); and the box's colour, pushed as -1 by the original and as 0xffff here (1): drawBorderBox's colour is `ushort` in the header, and `short` gives the original's push (gynt's open #294 has drawBorderBox with `ushort`, so it is not changed here). Measured in a narrow build of this file on main 812d14969: 97.6% raw, 90.1% normalised. Not run in game. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 Co-Authored-By: Claude Opus 5.5 --- .../UI/MinimapViewState/drawMinimap.cpp | 565 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 566 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp diff --git a/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp b/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp new file mode 100644 index 0000000000..c8a1cc09ba --- /dev/null +++ b/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp @@ -0,0 +1,565 @@ +#include "../MinimapViewState.func.hpp" + +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Rendering/ColorMode.hpp" +#include "OpenSHC/Rendering/Enums/ViewportConstants.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BlendingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MiniMapDefinedData.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_LONG_ROW; + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_SHORT_ROW; + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_SIZE; + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_START; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // A row of the minimap picture (200 pixels) in bytes, for the assembly (it cannot name a qualified constant). + enum { PICTURE_ROW_BYTES = Map::MC_MAP_XY_LIMIT / 2 * sizeof(ushort) }; + + // Draws the minimap: the terrain picture, every unit as a dot in its player's colour, and the viewport's box. + // FUNCTION: STRONGHOLDCRUSADER 0x004B66C0 + void MinimapViewState::drawMinimap(int xPos, int yPos, int width, int height, uint flags, int xOffset, int yOffset, + int widthFactor, int heightFactor, int intoPreview) + { + // in this order (in another order the first stores move; found by a search over the orders) + BOOLEnum isRGB565 = FALSE; + int rowBase = VC_SCREEN_POINT_TABLE_START; + int scale = 1; + int blitWidth = width; + int blitHeight = height; + ushort* const buffer = this->field_0x44; + int sourceColumnBase = 0; + int sourceRowBase = 0; + BOOLEnum showBox = TRUE; + int mapSize = DAT_TileMapState::instance.mapSize; + if (mapSize == 0) { + mapSize = Map::MC_MAP_SIZE_400; + } + int minX; + int minY; + int maxY; + int maxX; + int quarterMargin; + int halfMargin; + // MC_MAP_SIZE_400 - mapSize written out each time (a local for it changes the stack slots) + if (width < 200) { + quarterMargin = (Map::MC_MAP_SIZE_400 - mapSize) / 4; + minX = quarterMargin + 1; + halfMargin = (Map::MC_MAP_SIZE_400 - mapSize) / 2; + minY = halfMargin + 2; + maxX = (Map::MC_MAP_SIZE_400 - halfMargin) / 2 - 2; + maxY = Map::MC_MAP_SIZE_400 - halfMargin; + } else { + quarterMargin = (Map::MC_MAP_SIZE_400 - mapSize) / 4; + halfMargin = (Map::MC_MAP_SIZE_400 - mapSize) / 2; + minX = quarterMargin; + minY = halfMargin; + maxX = (Map::MC_MAP_SIZE_400 - halfMargin) / 2; + maxY = Map::MC_MAP_SIZE_400 - halfMargin; + } + if (DAT_MiniMapDefinedData::instance.cachedMapOrientation != DAT_TileMapState::instance.mapOrientation) { + MACRO_CALL_MEMBER(MinimapViewState_Func::setTileColorsDependingOnMapSize, this)(0, 100); + MACRO_CALL_MEMBER(MinimapViewState_Func::setMapPropertyDependingOnMapSize, this)(0, 100); + DAT_MiniMapDefinedData::instance.cachedMapOrientation = DAT_TileMapState::instance.mapOrientation; + } + if (this->field_0x38 != 0) { + if (this->field_0x34 == 0) { + MACRO_CALL_MEMBER(MinimapViewState_Func::setTileColorsDependingOnMapSize, this)(this->field_0x34, 2); + MACRO_CALL_MEMBER(MinimapViewState_Func::setMapPropertyDependingOnMapSize, this)(this->field_0x34, 2); + MACRO_CALL_MEMBER(Map::TileMapState_Func::collectCliffEdgeTilesForClimbData, DAT_TileMapState::ptr)(); + this->field_0x34 += 2; + } else { + MACRO_CALL_MEMBER(MinimapViewState_Func::setTileColorsDependingOnMapSize, this)(this->field_0x34, 2); + MACRO_CALL_MEMBER(MinimapViewState_Func::setMapPropertyDependingOnMapSize, this)(this->field_0x34, 2); + this->field_0x34 += 2; + // (int): the original compares signed (the header has undefined4) + if ((int)this->field_0x34 >= 100) { + --this->field_0x38; + if ((int)this->field_0x38 > 0) { + this->field_0x34 = 0; + } else { + this->field_0x38 = 0; + } + } + } + } + if (flags & 4) { + scale = 2; + } + // a small map sits in the middle of the 400 by 400 picture + if (DAT_TileMapState::instance.mapSize <= Map::MC_MAP_SIZE_200) { + sourceColumnBase = (Map::MC_MAP_XY_LIMIT - Map::MC_MAP_SIZE_200) / 2; + sourceRowBase = (Map::MC_MAP_XY_LIMIT - Map::MC_MAP_SIZE_200) / 2; + } + this->width = width; + this->height = height; + this->widthFactor = widthFactor; + this->heightFactor = heightFactor; + this->x = xPos; + this->y = yPos; + this->oneOrTwo = scale; + int const viewWidth = DAT_ViewportRenderState::instance.viewportState.viewportHeight - 5; + int boxWidth = viewWidth * widthFactor / scale + widthFactor / scale - 1; + int boxHeight = DAT_ViewportRenderState::instance.viewportState.viewportWidth * heightFactor / scale - 1; + // width and height count tiles from here on, as in the original, which keeps the counts in their stack slots + width = width / widthFactor * scale; + height = height / heightFactor * scale; + if (DAT_WindowAndDirectDraw::instance.colorBitMode == OpenSHC::Rendering::RGB_565) { + isRGB565 = TRUE; + } + int boxX = xOffset; + int boxY = yOffset; + int const half = mapSize / 2; + if (half < width) { + xOffset = quarterMargin - (width - half) / 2; + yOffset = halfMargin - (height - mapSize) / 2; + boxX -= viewWidth / 2; + boxY -= DAT_ViewportRenderState::instance.viewportState.viewportWidth / 2; + if (boxX < minX) { + boxWidth = half * widthFactor / scale; + boxX = minX; + showBox = FALSE; + } + if (boxY < minY) { + boxHeight = mapSize * heightFactor / scale; + boxY = minY; + showBox = FALSE; + } + } else { + if (flags & 1) { + xOffset -= width / 2; + yOffset -= height / 2; + boxX -= viewWidth / 2; + boxY -= DAT_ViewportRenderState::instance.viewportState.viewportWidth / 2; + } + if (xOffset < minX) { + xOffset = minX; + } else if (xOffset > maxX - width) { + xOffset = maxX - width; + } + if (yOffset < minY) { + yOffset = minY; + } else if (yOffset > maxY - height - 1) { + yOffset = maxY - height - 1; + } + if (boxX < minX) { + boxX = minX; + } else if (boxX > maxX - DAT_ViewportRenderState::instance.viewportState.viewportHeight + 5) { + boxX = maxX - DAT_ViewportRenderState::instance.viewportState.viewportHeight + 5; + } + if (boxY < minY) { + boxY = minY; + } else if (boxY > maxY - DAT_ViewportRenderState::instance.viewportState.viewportWidth - 1) { + boxY = maxY - DAT_ViewportRenderState::instance.viewportState.viewportWidth - 1; + } + } + boxX = (boxX - xOffset) * widthFactor / scale + xPos; + this->tileOffsetY = yOffset; + this->tileOffsetX = xOffset; + boxY = (boxY - yOffset) * heightFactor / scale + yPos; + int const halfY = yOffset / 2; + int const viewportHeight = DAT_ViewportRenderState::instance.viewportState.viewportHeight; + int const otherParity = viewportHeight + 1; + int rowParity = otherParity; + if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_NORTH) { + rowBase = VC_SCREEN_POINT_TABLE_START; + } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_WEST) { + rowBase = VC_SCREEN_POINT_TABLE_START + VC_SCREEN_POINT_TABLE_SIZE; + } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_SOUTH) { + rowBase = VC_SCREEN_POINT_TABLE_START + 2 * VC_SCREEN_POINT_TABLE_SIZE; + } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_EAST) { + rowBase = VC_SCREEN_POINT_TABLE_START + 3 * VC_SCREEN_POINT_TABLE_SIZE; + } + int sourceX = xOffset * widthFactor / scale; + int const sourceY = halfY * heightFactor; + rowBase += halfY * (VC_SCREEN_POINT_SHORT_ROW + VC_SCREEN_POINT_LONG_ROW) + xOffset + 1; + // the loaded map's preview, or the screen + if (intoPreview > 0) { + DAT_PencilRenderCore::instance.surfacePtr = (ushort*)this->loadedMiniMap; + DAT_PencilRenderCore::instance.horizontalByteSize = sizeof(this->loadedMiniMap[0]); + this->someMiniMapCounterTill4 = 0; + } else { + MACRO_CALL_MEMBER(Rendering::PencilRenderCore_Func::setupPencilSurface, DAT_PencilRenderCore::ptr)(); + } + if (intoPreview != 0) { + if (DAT_TileMapState::instance.mapSize == Map::MC_MAP_SIZE_160) { + blitWidth -= 5; + xPos += 3; + } else if (DAT_TileMapState::instance.mapSize == Map::MC_MAP_SIZE_200) { + xPos += 3; + ++sourceX; + blitWidth -= 4; + } + } + // handwritten in the original: the minimap picture copied to the surface row by row + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, xPos + add eax, eax + add edi, eax + mov eax, yPos + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + mov esi, buffer + mov eax, sourceX + sub eax, sourceColumnBase + add eax, eax + add esi, eax + mov eax, sourceY + sub eax, sourceRowBase + mov edx, PICTURE_ROW_BYTES + mul edx + add esi, eax + mov edx, blitHeight + next_row: + mov ecx, blitWidth + mov ebx, 0 + next_pixel: + mov ax, word ptr [esi + ebx] + mov word ptr [edi + ebx], ax + add ebx, 2 + dec ecx + jne next_pixel + add esi, PICTURE_ROW_BYTES + add edi, DAT_PencilRenderCore::instance.horizontalByteSize + dec edx + jne next_row + } + // 160 keeps its shift and 200 keeps one of its three pixels (the original tests 160 first) + if (intoPreview != 0) + { + if (DAT_TileMapState::instance.mapSize == Map::MC_MAP_SIZE_160) { + } else if (DAT_TileMapState::instance.mapSize == Map::MC_MAP_SIZE_200) { + xPos -= 2; + } + } + // per player four animation frames in the two colour modes + typedef ushort PlayerUnitColors[4][2]; + PlayerUnitColors const* const playerColors + = (PlayerUnitColors const*)DAT_MiniMapDefinedData::instance.PlayerColorColors; + uint color; + // declared once for both unit loops (declared in each loop they take other stack slots) + int row; + int column; + int rowLength; + int start; + int pixelX; + int pixelY; + int unit; + int baseX; + int baseY; + int offsetX; + int offsetY; + int x; + int y; + int px; + if (!DAT_GameCore::instance.altRToggleMinimapHideWildlife) { + for (row = 0; row < height; ++row, rowBase += rowLength) { + pixelY = row * heightFactor; + if (rowParity == otherParity) { + rowParity = viewportHeight; + start = widthFactor / 2; + rowLength = VC_SCREEN_POINT_SHORT_ROW; + } else { + rowParity = otherParity; + start = 0; + rowLength = VC_SCREEN_POINT_LONG_ROW; + } + if (scale != 2 || !(pixelY & 1)) { + for (column = -2; column < width; ++column) { + pixelX = column * widthFactor + start; + unit = DAT_TileMapState::instance.UnitLayer[DAT_ViewportRenderState::instance + .screenPointToTileNumber[rowBase + column]]; + if (unit == 0) { + if (scale != 2) { + continue; + } + unit = DAT_TileMapState::instance.UnitLayer[DAT_ViewportRenderState::instance + .screenPointToTileNumber[column + rowLength + rowBase]]; + if (unit == 0) { + continue; + } + } + short const owner = DAT_UnitsState::instance.units[unit].owner; + if (owner == 0) { + color = playerColors[0][2][isRGB565]; + } else { + int colorPlayer; + if (DAT_UnitsState::instance.units[unit].isSelectable_OR_matchTime != 0) { + switch (DAT_UnitsState::instance.units[unit].unitType) { + case Map::Units::UT_E_KNIGHT: + case Map::Units::UT_A_HARCHER: + colorPlayer = DAT_UnitsState::instance.units[unit].displayColorPlayerID; + break; + case Map::Units::UT_S_TOWER: + colorPlayer = owner; + break; + default: + colorPlayer = DAT_UnitsState::instance.units[unit].calculatedOwnerPlayerIndex; + break; + } + } else { + colorPlayer = owner; + } + if (colorPlayer <= 0) { + colorPlayer = 1; + } + switch (DAT_UnitsState::instance.units[unit].unitType) { + case Map::Units::UT_A_ASSASSIN: + color = playerColors[DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[colorPlayer]] + [0][isRGB565]; + if (DAT_GameState::instance.mapAndTime.playerTeams[owner] + != DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + && DAT_UnitsState::instance.units[unit].assassinsMicroDistanceToEnemyUnk > 160 + && DAT_UnitsState::instance.units[unit].state.generic + != Map::Units::States::US_MELEE_ATTACK + && DAT_UnitsState::instance.units[unit].state.generic + != Map::Units::States::US_MELEE_ATTACK_WALL + && (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + || DAT_UnitsState::instance.units[unit].idleCounterUnk <= 2400)) { + continue; + } + break; + case Map::Units::UT_COW: + case Map::Units::UT_HUNTERDOG: + case Map::Units::UT_CHICKEN: + color = playerColors[0][2][isRGB565]; + break; + case Map::Units::UT_S_CATAPULT: + case Map::Units::UT_S_TREBUCHET: + case Map::Units::UT_S_MANGONEL: + case Map::Units::UT_S_TOWER: + case Map::Units::UT_S_BATTERINGRAM: + case Map::Units::UT_S_SHIELD: + case Map::Units::UT_S_BALLISTA: + case Map::Units::UT_S_FBALLISTA: + color = playerColors[DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[colorPlayer]] + [this->someMiniMapCounterTill4][isRGB565]; + break; + default: + color = playerColors[DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[colorPlayer]] + [0][isRGB565]; + break; + } + } + if (scale == 1) { + baseX = pixelX + xPos; + baseY = pixelY + yPos; + for (offsetX = 0; offsetX < widthFactor; ++offsetX) { + if (baseX + offsetX >= xPos && baseX + offsetX < width * widthFactor + xPos) { + for (offsetY = 0; offsetY < heightFactor; ++offsetY) { + // handwritten in the original: one pixel + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, baseX + add eax, offsetX + add eax, eax + add edi, eax + mov eax, baseY + add eax, offsetY + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + mov ax, word ptr color + mov word ptr [edi], ax + } + } + } + } + } else { + for (offsetX = pixelX & 1; offsetX < widthFactor; offsetX += 2) { + px = pixelX + offsetX; + if (px >= 0 && px < width * widthFactor) { + x = px / scale + xPos; + for (offsetY = 0; offsetY < heightFactor; ++offsetY) { + y = (pixelY + offsetY) / scale + yPos; + // handwritten in the original: one pixel + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, x + add eax, eax + add edi, eax + mov eax, y + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + mov ax, word ptr color + mov word ptr [edi], ax + } + } + } + } + } + } + } + } + } else { + // with the wildlife hidden: own team and enemies in two colours + uint const ownColor = playerColors[DAT_BlendingDefinedData::instance + .PlayerSlotUnitColor[DAT_GameSynchronyState::instance.currentPlayerSlotID]][0][isRGB565]; + uint enemyColor = 0; + for (int player = 1; player < countof(DAT_GameState::instance.mapAndTime.playerTeams); ++player) { + if (DAT_GameState::instance.mapAndTime.playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + != DAT_GameState::instance.mapAndTime.playerTeams[player]) { + enemyColor + = playerColors[DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[player]][0][isRGB565]; + break; + } + } + for (row = 0; row < height; ++row, rowBase += rowLength) { + pixelY = row * heightFactor; + if (rowParity == otherParity) { + rowParity = viewportHeight; + start = widthFactor / 2; + rowLength = VC_SCREEN_POINT_SHORT_ROW; + } else { + rowParity = otherParity; + start = 0; + rowLength = VC_SCREEN_POINT_LONG_ROW; + } + if (scale != 2 || !(pixelY & 1)) { + for (column = -2; column < width; ++column) { + pixelX = column * widthFactor + start; + unit = DAT_TileMapState::instance.UnitLayer[DAT_ViewportRenderState::instance + .screenPointToTileNumber[rowBase + column]]; + if (unit == 0) { + if (scale != 2) { + continue; + } + unit = DAT_TileMapState::instance.UnitLayer[DAT_ViewportRenderState::instance + .screenPointToTileNumber[column + rowLength + rowBase]]; + if (unit == 0) { + continue; + } + } + short const owner = DAT_UnitsState::instance.units[unit].owner; + if (owner == 0) { + continue; + } + switch (DAT_UnitsState::instance.units[unit].unitType) { + case Map::Units::UT_COW: + case Map::Units::UT_HUNTERDOG: + case Map::Units::UT_CHICKEN: + continue; + case Map::Units::UT_A_ASSASSIN: + if (DAT_GameState::instance.mapAndTime.playerTeams[owner] + != DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + && DAT_UnitsState::instance.units[unit].assassinsMicroDistanceToEnemyUnk > 160 + && DAT_UnitsState::instance.units[unit].state.generic + != Map::Units::States::US_MELEE_ATTACK + && DAT_UnitsState::instance.units[unit].state.generic + != Map::Units::States::US_MELEE_ATTACK_WALL + && (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + || DAT_UnitsState::instance.units[unit].idleCounterUnk <= 2400)) { + continue; + } + break; + default: + break; + } + if (DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + == DAT_GameState::instance.mapAndTime.playerTeams[owner]) { + color = (ushort)ownColor; + } else { + color = (ushort)enemyColor; + } + if (scale == 1) { + baseX = pixelX + xPos; + baseY = pixelY + yPos; + for (offsetX = 0; offsetX < widthFactor; ++offsetX) { + if (baseX + offsetX >= xPos && baseX + offsetX < width * widthFactor + xPos) { + for (offsetY = 0; offsetY < heightFactor; ++offsetY) { + // handwritten in the original: one pixel + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, baseX + add eax, offsetX + add eax, eax + add edi, eax + mov eax, baseY + add eax, offsetY + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + mov ax, word ptr color + mov word ptr [edi], ax + } + } + } + } + } else { + for (offsetX = pixelX & 1; offsetX < widthFactor; offsetX += 2) { + px = pixelX + offsetX; + if (px >= 0 && px < width * widthFactor) { + x = px / scale + xPos; + for (offsetY = 0; offsetY < heightFactor; ++offsetY) { + y = (pixelY + offsetY) / scale + yPos; + // handwritten in the original: one pixel + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, x + add eax, eax + add edi, eax + mov eax, y + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + mov ax, word ptr color + mov word ptr [edi], ax + } + } + } + } + } + } + } + } + } + if ((flags & 2) && showBox) { + if (boxX < xPos) { + if (boxX + boxWidth >= blitWidth + xPos) { + return; + } + boxWidth += boxX - xPos; + boxX = xPos; + } else if (boxX + boxWidth >= blitWidth + xPos) { + boxWidth = blitWidth - boxX + xPos - 1; + } + if (boxY < yPos) { + if (boxY + boxHeight >= blitHeight + yPos) { + return; + } + boxHeight += boxY - yPos; + boxY = yPos; + } else if (boxY + boxHeight >= yPos + blitHeight) { + boxHeight = blitHeight - boxY + yPos; + } + MACRO_CALL_MEMBER(Rendering::PencilRenderCore_Func::drawBorderBox, DAT_PencilRenderCore::ptr)( + boxX, boxY, boxX + boxWidth, boxY + boxHeight, -1); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 39ecce8cfe..b85077580c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -26919,7 +26919,7 @@ SHC_3BB0A8C1_0x004B6640 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B6680 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B66C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004B66C0 | 97.6% | The siege engines' colour index, two loads and the colour's push differ SHC_3BB0A8C1_0x004B6C20 | 0.0% | Pending From cb7d61e1272abe46adfb41dcc96e347c1bcd0a2a Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 20:06:40 +0100 Subject: [PATCH 2/9] MinimapViewState::drawMinimap: why the half-size loops step by two The style bot suggests letting MSVC unroll the two `offsetX += 2` loops. They draw every other pixel at half size, as in renderMinimapTileStripWithLuminescence (#465), and get the same one-line comment. Written as a plain loop that skips the odd pixels, the function no longer matches: in a quick compile 378 lines differ instead of 10. Comments only; the listing is the same as before. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp b/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp index c8a1cc09ba..1314decea7 100644 --- a/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp +++ b/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp @@ -387,6 +387,7 @@ namespace UI { } } } else { + // Every other pixel at half the position (a plain loop skipping odd ones loses the match). for (offsetX = pixelX & 1; offsetX < widthFactor; offsetX += 2) { px = pixelX + offsetX; if (px >= 0 && px < width * widthFactor) { @@ -510,6 +511,7 @@ namespace UI { } } } else { + // Every other pixel at half the position (a plain loop skipping odd ones loses the match). for (offsetX = pixelX & 1; offsetX < widthFactor; offsetX += 2) { px = pixelX + offsetX; if (px >= 0 && px < width * widthFactor) { From 956eaae93ef2fb1e92b8be553660a87d22a4e26c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Wed, 25 Nov 2026 00:10:22 +0100 Subject: [PATCH 3/9] headers: PlayerUnitColors, the unit colours of one player on the minimap A new generated-form typedef, UI::MiniMap::PlayerUnitColors = ushort[4][2]: per player the four animation frames' colours in the two colour modes. drawMinimap reads MiniMapDefinedData::PlayerColorColors through it, which declared the type inside the function until now (gynt on #488: new types go in .hpp files, not in .cpp files). Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/MiniMap/PlayerUnitColors.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/OpenSHC/UI/MiniMap/PlayerUnitColors.hpp diff --git a/src/OpenSHC/UI/MiniMap/PlayerUnitColors.hpp b/src/OpenSHC/UI/MiniMap/PlayerUnitColors.hpp new file mode 100644 index 0000000000..62b2ea379d --- /dev/null +++ b/src/OpenSHC/UI/MiniMap/PlayerUnitColors.hpp @@ -0,0 +1,19 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/UI/MiniMap/PlayerUnitColors.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace UI { + namespace MiniMap { + typedef ushort PlayerUnitColors[4][2]; + + static_assert_cpp98_obj(sizeof(PlayerUnitColors) == 16, PlayerUnitColors); + } // namespace MiniMap +} // namespace UI +} // namespace OpenSHC From a325841ee4d1631668b5215acab2ac8e3fede79e Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Wed, 25 Nov 2026 00:10:22 +0100 Subject: [PATCH 4/9] drawMinimap takes PlayerUnitColors and the buffer row from headers The function-local typedef goes: the type is PlayerUnitColors from the header commit before this one. The file-local PICTURE_ROW_BYTES goes too: it is the same 400-byte row of a minimap buffer that main's MinimapConstants names MMC_BUFFER_ROW_BYTES, and the assembly's two uses take it through a using-declaration, since inline assembly cannot name a qualified constant. The function's listing is the same instruction for instruction. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp b/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp index 1314decea7..8436fe03cd 100644 --- a/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp +++ b/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp @@ -9,6 +9,8 @@ #include "OpenSHC/Map/Units/UnitType.hpp" #include "OpenSHC/Rendering/ColorMode.hpp" #include "OpenSHC/Rendering/Enums/ViewportConstants.hpp" +#include "OpenSHC/UI/Enums/MinimapConstants.hpp" +#include "OpenSHC/UI/MiniMap/PlayerUnitColors.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_BlendingDefinedData.hpp" @@ -29,10 +31,11 @@ namespace UI { using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_SHORT_ROW; using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_SIZE; using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_START; + using OpenSHC::UI::MiniMap::PlayerUnitColors; using OpenSHC::WindowsHelper::Enums::BOOLEnum; - // A row of the minimap picture (200 pixels) in bytes, for the assembly (it cannot name a qualified constant). - enum { PICTURE_ROW_BYTES = Map::MC_MAP_XY_LIMIT / 2 * sizeof(ushort) }; + // A row of the minimap picture (200 pixels) in bytes, named here for the assembly (it cannot name a qualified one). + using OpenSHC::UI::Enums::MMC_BUFFER_ROW_BYTES; // Draws the minimap: the terrain picture, every unit as a dot in its player's colour, and the viewport's box. // FUNCTION: STRONGHOLDCRUSADER 0x004B66C0 @@ -226,7 +229,7 @@ namespace UI { add esi, eax mov eax, sourceY sub eax, sourceRowBase - mov edx, PICTURE_ROW_BYTES + mov edx, MMC_BUFFER_ROW_BYTES mul edx add esi, eax mov edx, blitHeight @@ -239,7 +242,7 @@ namespace UI { add ebx, 2 dec ecx jne next_pixel - add esi, PICTURE_ROW_BYTES + add esi, MMC_BUFFER_ROW_BYTES add edi, DAT_PencilRenderCore::instance.horizontalByteSize dec edx jne next_row @@ -253,7 +256,6 @@ namespace UI { } } // per player four animation frames in the two colour modes - typedef ushort PlayerUnitColors[4][2]; PlayerUnitColors const* const playerColors = (PlayerUnitColors const*)DAT_MiniMapDefinedData::instance.PlayerColorColors; uint color; From 81451bc693fd1b68ffad25647aa73ddf59216409 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 28 Nov 2026 10:44:32 +0100 Subject: [PATCH 5/9] headers: drawBorderBox's colour is a short drawMinimap passes drawBorderBox -1 for the viewport box's colour, and the original pushes it as a dword (0x004B727E push -1). With the header's ushort the call compiles to push 0xffff; with short it compiles to the original's push. The colour is a 16-bit pixel value either way, so the width stays. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/Rendering/PencilRenderCore.func.hpp | 2 +- src/OpenSHC/UI/Rendering/PencilRenderCore.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/UI/Rendering/PencilRenderCore.func.hpp b/src/OpenSHC/UI/Rendering/PencilRenderCore.func.hpp index 534337a3c0..4c3b4b3a6d 100644 --- a/src/OpenSHC/UI/Rendering/PencilRenderCore.func.hpp +++ b/src/OpenSHC/UI/Rendering/PencilRenderCore.func.hpp @@ -79,7 +79,7 @@ namespace UI { Address::SHC_3BB0A8C1_0x004710A0, &PencilRenderCore::drawBoxWithRoundedEdges) drawBoxWithRoundedEdges; - MACRO_FUNCTION_RESOLVER(void (PencilRenderCore::*)(int, int, int, int, ushort), false, + MACRO_FUNCTION_RESOLVER(void (PencilRenderCore::*)(int, int, int, int, short), false, Address::SHC_3BB0A8C1_0x004711B0, &PencilRenderCore::drawBorderBox) drawBorderBox; diff --git a/src/OpenSHC/UI/Rendering/PencilRenderCore.hpp b/src/OpenSHC/UI/Rendering/PencilRenderCore.hpp index e16265999a..7062c22aeb 100644 --- a/src/OpenSHC/UI/Rendering/PencilRenderCore.hpp +++ b/src/OpenSHC/UI/Rendering/PencilRenderCore.hpp @@ -89,7 +89,7 @@ namespace UI { void drawBoxWithRoundedEdges( int left, int top, int right, int bottom, RoundedBoxEdgeRoundingLevel roundingLevel); - void drawBorderBox(int left, int top, int right, int bottom, ushort color); + void drawBorderBox(int left, int top, int right, int bottom, short color); void drawDiagonalHeigherThanWideUnk(); From 66a6efeccd17e341a02b2d4d00e2142c747a3a32 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 28 Nov 2026 10:52:11 +0100 Subject: [PATCH 6/9] headers: MinimapDrawFlags, the three flags of drawMinimap A new generated-form enum for MinimapViewState::drawMinimap's flags argument: 1 centres the picture on the given offsets (0x004B6970 test 1), 2 draws the viewport's box (0x004B71FF test 2), 4 draws at half size (0x004B6814 test 4). The callers on main pass 5 and 7, so the parameter stays a uint. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/Enums/MinimapDrawFlags.hpp | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/OpenSHC/UI/Enums/MinimapDrawFlags.hpp diff --git a/src/OpenSHC/UI/Enums/MinimapDrawFlags.hpp b/src/OpenSHC/UI/Enums/MinimapDrawFlags.hpp new file mode 100644 index 0000000000..c8ddf9719f --- /dev/null +++ b/src/OpenSHC/UI/Enums/MinimapDrawFlags.hpp @@ -0,0 +1,25 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/UI/Enums/MinimapDrawFlags.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace UI { + namespace Enums { + typedef enum MinimapDrawFlags { + + MDF_CENTER_ON_OFFSETS = 1, // 0x00000001 + MDF_VIEWPORT_BOX = 2, // 0x00000002 + MDF_HALF_SIZE = 4 // 0x00000004 + + } MinimapDrawFlags; + + static_assert_cpp98_obj(sizeof(MinimapDrawFlags) == 4, MinimapDrawFlags); + } // namespace Enums +} // namespace UI +} // namespace OpenSHC From 33693e8654cdc8b5dbb051ccae0233ace763caa4 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 28 Nov 2026 10:52:35 +0100 Subject: [PATCH 7/9] headers: MiniMapDefinedData's PlayerColorColors is ushort[9][4][2] drawMinimap reads the table at 0x1EC per colour slot (0 to 8), per animation frame (four) and per colour mode (two): [slot][0][mode] for most units (0x004B6CEA, 0x004B6D8F) and for the two colours with the wildlife hidden (0x004B6F01, 0x004B6F3D), [slot][frame][mode] for the siege engines (0x004B6D75), [0][2][mode] for the animals and the units without an owner (0x004B6C72, 0x004B6D51). Nine slots of 16 bytes end at 0x27C, where MinimapColorByLogicBit starts. The header had ushort[2][2] there and 68 single fields behind it (AnimalMinimapColour_RGB15/16 = [0][2], PlayerColorColors_entry2 = [1][0][0], field_0x1f8 to field_0x27a), all inside the table; none of them is used on main. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/MiniMap/MiniMapDefinedData.hpp | 70 +------------------ 1 file changed, 1 insertion(+), 69 deletions(-) diff --git a/src/OpenSHC/UI/MiniMap/MiniMapDefinedData.hpp b/src/OpenSHC/UI/MiniMap/MiniMapDefinedData.hpp index 154ee9ec64..980efff798 100644 --- a/src/OpenSHC/UI/MiniMap/MiniMapDefinedData.hpp +++ b/src/OpenSHC/UI/MiniMap/MiniMapDefinedData.hpp @@ -41,75 +41,7 @@ namespace UI { ushort ScrubMinimapColors[8]; // 0x00000164 length: 16 ushort ThickScrubMinimapColors[8]; // 0x00000174 length: 16 ushort OasisGrassMinimapColors[52]; // 0x00000184 length: 104 - ushort PlayerColorColors[2][2]; // 0x000001EC length: 8 - ushort AnimalMinimapColour_RGB15; // 0x000001F4 length: 2 - ushort AnimalMinimapColour_RGB16; // 0x000001F6 length: 2 - ushort field_0x1f8; // 0x000001F8 length: 2 - ushort field_0x1fa; // 0x000001FA length: 2 - ushort PlayerColorColors_entry2; // 0x000001FC length: 2 - ushort field_0x1fe; // 0x000001FE length: 2 - ushort field_0x200; // 0x00000200 length: 2 - ushort field_0x202; // 0x00000202 length: 2 - ushort field_0x204; // 0x00000204 length: 2 - ushort field_0x206; // 0x00000206 length: 2 - ushort field_0x208; // 0x00000208 length: 2 - ushort field_0x20a; // 0x0000020A length: 2 - ushort field_0x20c; // 0x0000020C length: 2 - ushort field_0x20e; // 0x0000020E length: 2 - ushort field_0x210; // 0x00000210 length: 2 - ushort field_0x212; // 0x00000212 length: 2 - ushort field_0x214; // 0x00000214 length: 2 - ushort field_0x216; // 0x00000216 length: 2 - ushort field_0x218; // 0x00000218 length: 2 - ushort field_0x21a; // 0x0000021A length: 2 - ushort field_0x21c; // 0x0000021C length: 2 - ushort field_0x21e; // 0x0000021E length: 2 - ushort field_0x220; // 0x00000220 length: 2 - ushort field_0x222; // 0x00000222 length: 2 - ushort field_0x224; // 0x00000224 length: 2 - ushort field_0x226; // 0x00000226 length: 2 - ushort field_0x228; // 0x00000228 length: 2 - ushort field_0x22a; // 0x0000022A length: 2 - ushort field_0x22c; // 0x0000022C length: 2 - ushort field_0x22e; // 0x0000022E length: 2 - ushort field_0x230; // 0x00000230 length: 2 - ushort field_0x232; // 0x00000232 length: 2 - ushort field_0x234; // 0x00000234 length: 2 - ushort field_0x236; // 0x00000236 length: 2 - ushort field_0x238; // 0x00000238 length: 2 - ushort field_0x23a; // 0x0000023A length: 2 - ushort field_0x23c; // 0x0000023C length: 2 - ushort field_0x23e; // 0x0000023E length: 2 - ushort field_0x240; // 0x00000240 length: 2 - ushort field_0x242; // 0x00000242 length: 2 - ushort field_0x244; // 0x00000244 length: 2 - ushort field_0x246; // 0x00000246 length: 2 - ushort field_0x248; // 0x00000248 length: 2 - ushort field_0x24a; // 0x0000024A length: 2 - ushort field_0x24c; // 0x0000024C length: 2 - ushort field_0x24e; // 0x0000024E length: 2 - ushort field_0x250; // 0x00000250 length: 2 - ushort field_0x252; // 0x00000252 length: 2 - ushort field_0x254; // 0x00000254 length: 2 - ushort field_0x256; // 0x00000256 length: 2 - ushort field_0x258; // 0x00000258 length: 2 - ushort field_0x25a; // 0x0000025A length: 2 - ushort field_0x25c; // 0x0000025C length: 2 - ushort field_0x25e; // 0x0000025E length: 2 - ushort field_0x260; // 0x00000260 length: 2 - ushort field_0x262; // 0x00000262 length: 2 - ushort field_0x264; // 0x00000264 length: 2 - ushort field_0x266; // 0x00000266 length: 2 - ushort field_0x268; // 0x00000268 length: 2 - ushort field_0x26a; // 0x0000026A length: 2 - ushort field_0x26c; // 0x0000026C length: 2 - ushort field_0x26e; // 0x0000026E length: 2 - ushort field_0x270; // 0x00000270 length: 2 - ushort field_0x272; // 0x00000272 length: 2 - ushort field_0x274; // 0x00000274 length: 2 - ushort field_0x276; // 0x00000276 length: 2 - ushort field_0x278; // 0x00000278 length: 2 - ushort field_0x27a; // 0x0000027A length: 2 + ushort PlayerColorColors[9][4][2]; // 0x000001EC length: 144 MapColorRelatedStructure1 MinimapColorByLogicBit[8]; // 0x0000027C length: 64 int cachedKeepEnclosed; // 0x000002BC length: 4 int cachedMapOrientation; // 0x000002C0 length: 4 From eac9a8bbd5851145584ee3b781b56aa850b48c7a Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 28 Nov 2026 10:53:24 +0100 Subject: [PATCH 8/9] drawMinimap names its flags and indexes the colour table by its header type The three flag tests take MinimapDrawFlags, and the colour reads index MiniMapDefinedData::PlayerColorColors directly now that the header gives it its [9][4][2] shape, so the cast to PlayerUnitColors goes. The listing is the same as with the cast. With drawBorderBox's colour a short (the header commit before), the viewport box's colour is pushed as -1 as in the original (0x004B727E), and the two loads in front of the first unit loop's pixel loops come in the original's order (0x004B6DC5, widthFactor before heightFactor). The pair of loads at that loop's back edge (0x004B6E21, widthFactor before xPos in the original) is the other way round now. Narrow build: 98.3 raw and 91.6 normalised, from 97.6 and 90.1. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../UI/MinimapViewState/drawMinimap.cpp | 41 ++++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp b/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp index 8436fe03cd..e83ab13f75 100644 --- a/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp +++ b/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp @@ -10,7 +10,7 @@ #include "OpenSHC/Rendering/ColorMode.hpp" #include "OpenSHC/Rendering/Enums/ViewportConstants.hpp" #include "OpenSHC/UI/Enums/MinimapConstants.hpp" -#include "OpenSHC/UI/MiniMap/PlayerUnitColors.hpp" +#include "OpenSHC/UI/Enums/MinimapDrawFlags.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_BlendingDefinedData.hpp" @@ -31,7 +31,9 @@ namespace UI { using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_SHORT_ROW; using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_SIZE; using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_START; - using OpenSHC::UI::MiniMap::PlayerUnitColors; + using OpenSHC::UI::Enums::MDF_CENTER_ON_OFFSETS; + using OpenSHC::UI::Enums::MDF_HALF_SIZE; + using OpenSHC::UI::Enums::MDF_VIEWPORT_BOX; using OpenSHC::WindowsHelper::Enums::BOOLEnum; // A row of the minimap picture (200 pixels) in bytes, named here for the assembly (it cannot name a qualified one). @@ -104,7 +106,7 @@ namespace UI { } } } - if (flags & 4) { + if (flags & MDF_HALF_SIZE) { scale = 2; } // a small map sits in the middle of the 400 by 400 picture @@ -147,7 +149,7 @@ namespace UI { showBox = FALSE; } } else { - if (flags & 1) { + if (flags & MDF_CENTER_ON_OFFSETS) { xOffset -= width / 2; yOffset -= height / 2; boxX -= viewWidth / 2; @@ -255,9 +257,7 @@ namespace UI { xPos -= 2; } } - // per player four animation frames in the two colour modes - PlayerUnitColors const* const playerColors - = (PlayerUnitColors const*)DAT_MiniMapDefinedData::instance.PlayerColorColors; + // the colour table: per colour slot four animation frames in the two colour modes uint color; // declared once for both unit loops (declared in each loop they take other stack slots) int row; @@ -303,7 +303,7 @@ namespace UI { } short const owner = DAT_UnitsState::instance.units[unit].owner; if (owner == 0) { - color = playerColors[0][2][isRGB565]; + color = DAT_MiniMapDefinedData::instance.PlayerColorColors[0][2][isRGB565]; } else { int colorPlayer; if (DAT_UnitsState::instance.units[unit].isSelectable_OR_matchTime != 0) { @@ -327,8 +327,9 @@ namespace UI { } switch (DAT_UnitsState::instance.units[unit].unitType) { case Map::Units::UT_A_ASSASSIN: - color = playerColors[DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[colorPlayer]] - [0][isRGB565]; + color = DAT_MiniMapDefinedData::instance + .PlayerColorColors[DAT_BlendingDefinedData::instance + .PlayerSlotUnitColor[colorPlayer]][0][isRGB565]; if (DAT_GameState::instance.mapAndTime.playerTeams[owner] != DAT_GameState::instance.mapAndTime .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] @@ -345,7 +346,7 @@ namespace UI { case Map::Units::UT_COW: case Map::Units::UT_HUNTERDOG: case Map::Units::UT_CHICKEN: - color = playerColors[0][2][isRGB565]; + color = DAT_MiniMapDefinedData::instance.PlayerColorColors[0][2][isRGB565]; break; case Map::Units::UT_S_CATAPULT: case Map::Units::UT_S_TREBUCHET: @@ -355,12 +356,14 @@ namespace UI { case Map::Units::UT_S_SHIELD: case Map::Units::UT_S_BALLISTA: case Map::Units::UT_S_FBALLISTA: - color = playerColors[DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[colorPlayer]] - [this->someMiniMapCounterTill4][isRGB565]; + color = DAT_MiniMapDefinedData::instance.PlayerColorColors + [DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[colorPlayer]] + [this->someMiniMapCounterTill4][isRGB565]; break; default: - color = playerColors[DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[colorPlayer]] - [0][isRGB565]; + color = DAT_MiniMapDefinedData::instance + .PlayerColorColors[DAT_BlendingDefinedData::instance + .PlayerSlotUnitColor[colorPlayer]][0][isRGB565]; break; } } @@ -418,14 +421,14 @@ namespace UI { } } else { // with the wildlife hidden: own team and enemies in two colours - uint const ownColor = playerColors[DAT_BlendingDefinedData::instance + uint const ownColor = DAT_MiniMapDefinedData::instance.PlayerColorColors[DAT_BlendingDefinedData::instance .PlayerSlotUnitColor[DAT_GameSynchronyState::instance.currentPlayerSlotID]][0][isRGB565]; uint enemyColor = 0; for (int player = 1; player < countof(DAT_GameState::instance.mapAndTime.playerTeams); ++player) { if (DAT_GameState::instance.mapAndTime.playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] != DAT_GameState::instance.mapAndTime.playerTeams[player]) { - enemyColor - = playerColors[DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[player]][0][isRGB565]; + enemyColor = DAT_MiniMapDefinedData::instance.PlayerColorColors[DAT_BlendingDefinedData::instance + .PlayerSlotUnitColor[player]][0][isRGB565]; break; } } @@ -541,7 +544,7 @@ namespace UI { } } } - if ((flags & 2) && showBox) { + if ((flags & MDF_VIEWPORT_BOX) && showBox) { if (boxX < xPos) { if (boxX + boxWidth >= blitWidth + xPos) { return; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 84989e9b3f..ff7623ff7c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -26919,7 +26919,7 @@ SHC_3BB0A8C1_0x004B6640 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B6680 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B66C0 | 97.6% | The siege engines' colour index, two loads and the colour's push differ +SHC_3BB0A8C1_0x004B66C0 | 98.3% | The siege engines' colour index and two loads differ SHC_3BB0A8C1_0x004B6C20 | 0.0% | Pending From 91879941d66379182eff0f4c7942bd1cd677e86f Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 28 Nov 2026 10:53:25 +0100 Subject: [PATCH 9/9] headers: PlayerUnitColors goes, the colour table has the type itself MiniMapDefinedData::PlayerColorColors is ushort[9][4][2] now, so the per-slot typedef this branch added for drawMinimap's cast has no user left. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/MiniMap/PlayerUnitColors.hpp | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/OpenSHC/UI/MiniMap/PlayerUnitColors.hpp diff --git a/src/OpenSHC/UI/MiniMap/PlayerUnitColors.hpp b/src/OpenSHC/UI/MiniMap/PlayerUnitColors.hpp deleted file mode 100644 index 62b2ea379d..0000000000 --- a/src/OpenSHC/UI/MiniMap/PlayerUnitColors.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/** - THIS FILE IS AUTO GENERATED - Communicate changes to the dev team (e.g. via a Pull Request). - Changes get lost otherwise. - - path: 'OpenSHC/UI/MiniMap/PlayerUnitColors.hpp' -*/ - -#pragma once - -namespace OpenSHC { -namespace UI { - namespace MiniMap { - typedef ushort PlayerUnitColors[4][2]; - - static_assert_cpp98_obj(sizeof(PlayerUnitColors) == 16, PlayerUnitColors); - } // namespace MiniMap -} // namespace UI -} // namespace OpenSHC