From 8a7edacfeb2779d0dc498e88ae3c3e14b27d66e3 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 23 Nov 2026 02:30:44 +0100 Subject: [PATCH] reimplement: SHC_3BB0A8C1_0x00454F00 100.0% Reimplemented TextureRenderCore::moveOverlappingMenuPartsToMapSurface: copies the parts of the open menu tab that reach over the map from the menu surface onto the map surface, all but the magenta pixels. The tab's records hold x, y, width and height; -1 ends them, and the records after a -2 lie outside the 800 pixels of the menu, so at 800x600 the function stops there. The pixel copy is the original's handwritten loop, as inline assembly. From gynt's draft: his 68.0% c2e547420a ("Asm copy loop recovered, fixed missing return at 800x600") on sourcehold's reimpl/TextureRenderCore, the newest cee658d885 (2026-11-02) on his fork's reimpl/UI-MenuItems-development. Behaviour against the draft: at 800x600 the original returns at the first -2 marker (0x00454F64), so the records behind it are not drawn. c2e547420a and 8ca78619cd have that return; 4696942cd2 / 196c54f192 (the 24.6% file, which is what #255 had when it closed), 81e1041dda, 5c82ddb658, dd1433183e, 63cc49fb3f and cee658d885 have an empty `if` there and draw them anyway. What the match needed: the zero-based tab (`tab - 1`) as a value of its own (written into the -1 test's index, its -5 is folded into that address); the record index computed a second time in a local of its own, as the original does; the four record pointers in the original's order; the end test at the bottom of a `for (;;)`. Measured in a narrow build of this file on main 0e4a83b5d with both resolver sets on: 100.0% raw and normalised. Not run in game. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../moveOverlappingMenuPartsToMapSurface.cpp | 103 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/TextureRenderCore/moveOverlappingMenuPartsToMapSurface.cpp diff --git a/src/OpenSHC/UI/Rendering/TextureRenderCore/moveOverlappingMenuPartsToMapSurface.cpp b/src/OpenSHC/UI/Rendering/TextureRenderCore/moveOverlappingMenuPartsToMapSurface.cpp new file mode 100644 index 0000000000..2bf35b7d9b --- /dev/null +++ b/src/OpenSHC/UI/Rendering/TextureRenderCore/moveOverlappingMenuPartsToMapSurface.cpp @@ -0,0 +1,103 @@ +#include "../TextureRenderCore.func.hpp" + +#include "OpenSHC/Rendering/ScreenResolutionEnum.hpp" + +#include "OpenSHC/Globals/COL_MAGENTA.hpp" +#include "OpenSHC/Globals/DAT_BlendingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_MenuHandlerState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // The copy loop is handwritten assembly in the original, transcribed here from the binary. + + // FUNCTION: STRONGHOLDCRUSADER 0x00454F00 + void TextureRenderCore::moveOverlappingMenuPartsToMapSurface() + { + // copies the open tab's parts that reach over the map onto the map surface, all but the magenta pixels + int const tab = this->activeMenuTabIndex; + if (tab == 0) { + return; + } + // the zero-based tab as a value of its own (tab - 1 written into the index loses the match) + int const tabIndex = tab - 1; + // a tab's ten records (x, y, width, height) take five rows of eight ints; -1 ends them + if (DAT_BlendingDefinedData::instance.field_0x3014[tabIndex * 5][0] == -1) { + return; + } + // the asm below names COL_MAGENTA, which inline asm can only do once C++ code has instantiated it + (void)sizeof(COL_MAGENTA::instance); + // the record index once more, as the original computes it a second time (one shared index loses the match) + int const record = tabIndex * 5; + // four pointers stepping through the records, as the original keeps them (one index loses the match) + int* width = &DAT_BlendingDefinedData::instance.field_0x3014[record][2]; + int* x = &DAT_BlendingDefinedData::instance.field_0x3014[record][0]; + int* height = &DAT_BlendingDefinedData::instance.field_0x3014[record][3]; + int* y = &DAT_BlendingDefinedData::instance.field_0x3014[record][1]; + // the end test at the bottom, as in the original (in the for's header it loses the match) + for (;;) { + // -2: the records after it lie outside the 800 pixels of the menu, so 800x600 stops here + if (*x == -2) { + if (DAT_WindowAndDirectDraw::instance.currentGameResolution == OpenSHC::Rendering::SRE_800x600) { + return; + } + y += 4; + height += 4; + width += 4; + x += 4; + } + ushort* const screen = (ushort*)((byte*)DAT_WindowAndDirectDraw::instance.surfacePointer_screenMenu + + (*y + DAT_MenuHandlerState::instance.y) + * DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine + + (DAT_MenuHandlerState::instance.x + *x) * 2); + // the map surface is 4056 pixels wide + ushort* const map = DAT_WindowAndDirectDraw::instance.surfacePointer_mapGame + + (*y + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetY + + DAT_MenuHandlerState::instance.y) + * 4056 + + *x + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetX + + DAT_MenuHandlerState::instance.x; + int const mapLineJump = (4056 - *width) * 2; + int const screenLineJump = DAT_WindowAndDirectDraw::instance.byteSizeOfOneHorizontalLine - *width * 2; + int const partHeight = *height; + int const partWidth = *width; + // clang-format off + __asm { + mov esi, screen + mov edi, map + mov ecx, partHeight + mov bx, COL_MAGENTA::instance.shortValue + rowLoop: + mov edx, partWidth + pixelLoop: + mov ax, word ptr [esi] + cmp ax, bx + je skipPixel + mov word ptr [edi], ax + skipPixel: + add esi, 2 + add edi, 2 + sub edx, 1 + jne pixelLoop + add esi, screenLineJump + add edi, mapLineJump + sub ecx, 1 + jne rowLoop + } + // clang-format on + y += 4; + height += 4; + width += 4; + x += 4; + if (*x == -1) { + break; + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e8a6864d03..02f510bba5 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -17003,7 +17003,7 @@ SHC_3BB0A8C1_0x00454EE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00454EF0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00454F00 | 0.0% | Pending +SHC_3BB0A8C1_0x00454F00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00455050 | 100.0% | Reimplemented