From dcb47ae0a2408cc16bb2719cd96c07cc13cacb28 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 20:43:38 +0100 Subject: [PATCH 1/8] reimplement: SHC_3BB0A8C1_0x004708F0 100.0% Reimplemented, register allocation only (#414) WindowAndDirectDraw::reinitWindow, moved out of our draft #313 with one comment line added. The draft came from gynt's version on his fork's reimpl/UI-Rendering-development (376808732 at 56.90%, a8b64eb00 at 56.9%, and 63cc49fb3 of 2026-10-25, his newest commit on the file) and reached 80.4% in 685b03934. Register allocation only, per #414: reccmp reads 80.4 (normalized 80.5), and the 56 instructions of both sides are the same instructions in the same order with the same memory operands. What differs is which of eax, ecx and edx holds each reload of windowHandle (and the address of the second corner) before it is pushed: eleven lines. if/else, nested and early-return shapes of the two branches all compile to the same code. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../WindowAndDirectDraw/reinitWindow.cpp | 34 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/WindowAndDirectDraw/reinitWindow.cpp diff --git a/src/OpenSHC/UI/Rendering/WindowAndDirectDraw/reinitWindow.cpp b/src/OpenSHC/UI/Rendering/WindowAndDirectDraw/reinitWindow.cpp new file mode 100644 index 0000000000..b7e5164266 --- /dev/null +++ b/src/OpenSHC/UI/Rendering/WindowAndDirectDraw/reinitWindow.cpp @@ -0,0 +1,34 @@ +#include "../WindowAndDirectDraw.func.hpp" + +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace Rendering { + + // FUNCTION: STRONGHOLDCRUSADER 0x004708F0 + void WindowAndDirectDraw::reinitWindow() + { + HWND const window = this->windowHandle; + if (GetForegroundWindow() != window) { + return; + } + this->isNotProcessingInputEvents = FALSE; + // the fullscreen flag is read through the global instance, as in the original + if (DAT_WindowAndDirectDraw::instance.runGameAsExclusiveFullscreen) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::WindowAndDirectDraw_Func::prepareWindowAndDDrawUnk, this)(); + SetRect( + &this->clientOnScreenCoords, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); + SetFocus(this->windowHandle); + return; + } + GetClientRect(window, &this->clientOnScreenCoords); + ClientToScreen(this->windowHandle, (LPPOINT) & this->clientOnScreenCoords.left); + ClientToScreen(this->windowHandle, (LPPOINT) & this->clientOnScreenCoords.right); + UpdateWindow(this->windowHandle); + SetFocus(this->windowHandle); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..4fb3ffecf6 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -21255,7 +21255,7 @@ SHC_3BB0A8C1_0x004706E0 | 0.0% | Pending SHC_3BB0A8C1_0x004707F0 | 0.0% | Pending -SHC_3BB0A8C1_0x004708F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004708F0 | 100.0% | Reimplemented, register allocation only (#414) SHC_3BB0A8C1_0x004709B0 | 100.0% | Reimplemented From 0e22f7264bfaec1c4696b6f70e71028f0f9d18ec Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 20:55:18 +0100 Subject: [PATCH 2/8] reimplement: SHC_3BB0A8C1_0x00493E20 100.0% Reimplemented VideoOptions::MenuItemActionHandler_VideoOptions_Main, rewritten from the listing on top of gynt's draft: aae2c08d5 (57.14%, his fork's development), cd76e7f37 (57.7%, upstream's reimpl/UI-MenuItems), 8725ec523 (61.5%, his fork's reimpl/UI-MenuItems-development) and 8ca78619c of 2026-10-27, his newest commit on the file (his fork's reimpl/Wilps-2026-10-18: the same code with newer field names). Our mechanical pass b2d7696ac in draft #328 read 61.5% as well. What the match needed: - case 11 keeps the resolution in a local through the loop and stores it once after it; the draft worked on the field, which stores it in every round; - case 18 reads the new resolution once and calls setExtraActiveModalDialog in every arm of the chain, in the original's order of arms. The draft set two position locals and called once, which shares the pushes. Two neighbouring arms with the same position joined by || read 0.8055 in quick_diff, so each resolution has its arm; - popModalDialog is called at the end of case 18 and in case 17: the compiler shares the one tail jump; - no goto and no position locals are left, and the loop is a for with its exit test in the header (a BOOLEnum that stands in for the original's do-while): the compiler puts the test at the end of the round, where the original has it. Names instead of numbers: CT_WINDOWS_LIKE_CURSOR, CT_ANI_CURSOR and SS_NORMAL. The parameter is button, as in most handlers on main; the buttons have no enum, so each case says what it does. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ...enuItemActionHandler_VideoOptions_Main.cpp | 157 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/VideoOptions/MenuItemActionHandler_VideoOptions_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/VideoOptions/MenuItemActionHandler_VideoOptions_Main.cpp b/src/OpenSHC/UI/MenuItems/VideoOptions/MenuItemActionHandler_VideoOptions_Main.cpp new file mode 100644 index 0000000000..459bd47ec6 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/VideoOptions/MenuItemActionHandler_VideoOptions_Main.cpp @@ -0,0 +1,157 @@ +#include "../VideoOptions.func.hpp" + +#include "OpenSHC/Input/MouseState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/UI/MenuItems/BuildingAndStatusMenu.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/UI/MenuTextInputState.func.hpp" +#include "OpenSHC/UI/Rendering/WindowAndDirectDraw.func.hpp" +#include "OpenSHC/Rendering/ScreenResolutionEnum.hpp" +#include "OpenSHC/UI/Enums/CursorType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/UI/ScrollSpeed.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_MenuModalComposition3.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_ScrollingHandler.hpp" +#include "OpenSHC/Globals/DAT_UIDragDropDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x00493E20 + void VideoOptions::MenuItemActionHandler_VideoOptions_Main(int button, ...) + { + switch (button) { + case 11: { // resolution: the next one that the screen supports, in the menu's order + int resolution = DAT_MenuTextInputState::instance.menuCurrentlySelectedResolution; + for (OpenSHC::WindowsHelper::Enums::BOOLEnum supported = FALSE; !supported; + supported = DAT_WindowAndDirectDraw::instance.resolutionSupported_0x68.array[resolution]) { + if (resolution == OpenSHC::Rendering::SRE_800x600) { + resolution = OpenSHC::Rendering::SRE_1024x600; + } else if (resolution == OpenSHC::Rendering::SRE_1024x600) { + resolution = OpenSHC::Rendering::SRE_1024x768; + } else if (resolution == OpenSHC::Rendering::SRE_1280x1024) { + resolution = OpenSHC::Rendering::SRE_1360x768; + } else if (resolution == OpenSHC::Rendering::SRE_1360x768) { + resolution = OpenSHC::Rendering::SRE_1366x768; + } else { + resolution++; + if (resolution == OpenSHC::Rendering::SRE_1360x768) { + resolution = OpenSHC::Rendering::SRE_800x600; + } + } + } + DAT_MenuTextInputState::instance.menuCurrentlySelectedResolution = resolution; + return; + } + case 12: // zoomed out, on or off + DAT_MenuTextInputState::instance.unknownZoomRelatedFlag01 ^= 1; + return; + case 16: // scroll speed + DAT_MenuTextInputState::instance.menuScrollSpeedSetting++; + // after the third speed comes the first again + if (DAT_MenuTextInputState::instance.menuScrollSpeedSetting >= 3) { + DAT_MenuTextInputState::instance.menuScrollSpeedSetting = OpenSHC::UI::SS_NORMAL; + } + return; + case 18: // apply the settings, then close + if (DAT_MenuTextInputState::instance.menuCurrentlySelectedResolution + != DAT_WindowAndDirectDraw::instance.currentGameResolution) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::WindowAndDirectDraw_Func::prepareWindowAndDDraw_2Unk, + DAT_WindowAndDirectDraw::ptr)(DAT_WindowAndDirectDraw::instance.runGameAsExclusiveFullscreen, + (OpenSHC::Rendering::ScreenResolutionEnum) + DAT_MenuTextInputState::instance.menuCurrentlySelectedResolution); + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::resetupViewportThunk, + DAT_ViewportRenderState::ptr)(); + MACRO_CALL(OpenSHC::UI::MenuItems::BuildingAndStatusMenu_Func:: + MenuItemActionHandler_BuildingAndStatusMenu_StopBuildingOrPeasantBinkPlayback)(); + DAT_UIDragDropDefinedData::instance.MenuView_TriggerInitial = TRUE; + if (DAT_MenuModalComposition3::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR) { + // the tactical power bar sits 55 pixels from the right edge of the new resolution + int const resolution = DAT_WindowAndDirectDraw::instance.currentGameResolution; + if (resolution == OpenSHC::Rendering::SRE_800x600) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 745, 50); + } else if (resolution == OpenSHC::Rendering::SRE_1024x768) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 969, 56); + } else if (resolution == OpenSHC::Rendering::SRE_1024x600) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 969, 56); + } else if (resolution == OpenSHC::Rendering::SRE_1600x1200) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 1545, 56); + } else if (resolution == OpenSHC::Rendering::SRE_1280x1024) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 1225, 56); + } else if (resolution == OpenSHC::Rendering::SRE_1280x720) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 1225, 56); + } else if (resolution == OpenSHC::Rendering::SRE_1440x900) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 1385, 56); + } else if (resolution == OpenSHC::Rendering::SRE_1920x1080) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 1865, 56); + } else if (resolution == OpenSHC::Rendering::SRE_1920x1200) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 1865, 56); + } else if (resolution == OpenSHC::Rendering::SRE_2560x1440) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 2505, 56); + } else if (resolution == OpenSHC::Rendering::SRE_2560x1600) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 2505, 56); + } else if (resolution == OpenSHC::Rendering::SRE_1366x768) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 1311, 56); + } else if (resolution == OpenSHC::Rendering::SRE_1360x768) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 1305, 56); + } else if (resolution == OpenSHC::Rendering::SRE_1680x1050) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 1625, 56); + } else if (resolution == OpenSHC::Rendering::SRE_1600x900) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::setExtraActiveModalDialog, + DAT_MenuModalComposition3::ptr)(OpenSHC::UI::Enums::MMT_TACTICAL_POWER_BAR, 1545, 56); + } + } + } + if (DAT_MenuTextInputState::instance.unknownZoomRelatedFlag01 + != DAT_ViewportRenderState::instance.viewportState.isZoomedOutUnk) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::resetupViewport, + DAT_ViewportRenderState::ptr)(DAT_MenuTextInputState::instance.unknownZoomRelatedFlag01); + DAT_WindowAndDirectDraw::instance.unk_resetViewportRelated = 2; + DAT_UIDragDropDefinedData::instance.MenuView_TriggerInitial = TRUE; + } + if (DAT_MenuTextInputState::instance.menuCursorType != DAT_MouseState::instance.cursorType) { + DAT_MouseState::instance.cursorType = DAT_MenuTextInputState::instance.menuCursorType; + MACRO_CALL_MEMBER( + OpenSHC::Input::MouseState_Func::makeSelectedCursorTypeCurrent, DAT_MouseState::ptr)(); + } + DAT_ScrollingHandler::instance.scrollSpeedSetting_0x38 + = DAT_MenuTextInputState::instance.menuScrollSpeedSetting; + MACRO_CALL_MEMBER(OpenSHC::UI::MenuTextInputState_Func::popModalDialog, DAT_MenuTextInputState::ptr)(); + return; + case 17: // close without applying + MACRO_CALL_MEMBER(OpenSHC::UI::MenuTextInputState_Func::popModalDialog, DAT_MenuTextInputState::ptr)(); + return; + case -10: // cursor type + DAT_MenuTextInputState::instance.menuCursorType = OpenSHC::UI::Enums::CT_WINDOWS_LIKE_CURSOR; + return; + case -20: + DAT_MenuTextInputState::instance.menuCursorType = OpenSHC::UI::Enums::CT_ANI_CURSOR; + return; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 4fb3ffecf6..ad1cae7ac3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23837,7 +23837,7 @@ SHC_3BB0A8C1_0x00493E16 | 0.0% | Pending SHC_3BB0A8C1_0x00493E17 | 0.0% | Pending -SHC_3BB0A8C1_0x00493E20 | 0.0% | Pending +SHC_3BB0A8C1_0x00493E20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0049404E | 0.0% | Pending From 89fe4f4c0b948071f63eec76d84b2ed36c082299 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 21:09:32 +0100 Subject: [PATCH 3/8] reimplement: SHC_3BB0A8C1_0x004C0CF0 100.0% Reimplemented SiegeAttackingForceAndStartGoods::MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main, rewritten from the listing on top of gynt's draft: ce671d7c9 and 37bf917bf (40.1%, upstream's reimpl/UI-MenuItems), f0479fcf2, b83dff2d0 and d7600c8e0 (44.39% to 52.82%, his fork's reimpl/UI-MenuItems), then 25b481abc (54.75%), 97435546a (52.49%) and 6aa5d327b of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our mechanical pass 7b18743ed and 53bea5fdf in draft #328 read 53.8%. What the match needed: - one if / else-if chain with the draw buffer set back once, at the end. The draft returned from every arm, each with its own store; written once, the compiler copies the store into the arms as the original has it, and esi is pushed before the first branch; - renderGM for a unit's picture is written in both arms that draw one (rows 20 to 29 and 40 to 49). Shared after the chain it reads 0.7479 in quick_diff; - the row is -1 - button (or esi, -1 / sub esi, eax), not -button - 1; - every amount is drawn by a call in each arm of the colour test. One call with the colour as a ?: reads 0.9320 (neg / sbb / and / add for the colour), with a colour local 0.9608. Behaviour: none of the draft's forms differed in what they draw. Readability, all measured equal: rows 20 to 29 read SEC_SiegeInformation[index - 20] and rows 40 to 49 SEC_Section1067.siegeEngineCounts[index - 40] (the draft indexed SEC_StartingResources[index + 5] for both, which is the same address); the picture's height comes from DAT_GMImageHeaders as in TriggerInvasion_Main, not from a cast on PTR_ARRAY_Unknown_UnitGMHeights; index >= 40 && index < 50 for the unsigned range test. reccmp: 99.2% raw. The two lines that differ are the picture table's address 0x00B98782 (imh[first + picture - 1] .height), 14 bytes before DAT_GMImageHeaders: reccmp prints it as a number on the original's side and, on ours, as an offset from whichever variable of our DLL lies there (Instance+2, DAT_ButtonX's instance). Only the name of the resolved address differs, which the project records as 100% (TriggerInvasion_Main in #349 has the same two lines). Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ..._SiegeAttackingForceAndStartGoods_Main.cpp | 179 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/SiegeAttackingForceAndStartGoods/MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/SiegeAttackingForceAndStartGoods/MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main.cpp b/src/OpenSHC/UI/MenuItems/SiegeAttackingForceAndStartGoods/MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main.cpp new file mode 100644 index 0000000000..dd8449a16f --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/SiegeAttackingForceAndStartGoods/MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main.cpp @@ -0,0 +1,179 @@ +#include "../SiegeAttackingForceAndStartGoods.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eGM.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/RoundedBoxEdgeRoundingLevel.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/COL_BLUE.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonH.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004C0CF0 + void SiegeAttackingForceAndStartGoods::MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main( + int button, ...) + { + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + if (button < 0) { + // the negative buttons are the rows of the two lists + int const index = -1 - button; + if (index < 20) { + // a starting good: its amount and icon, on any map but a siege + if (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == OpenSHC::Map::MT_SIEGE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_MapPropertiesState::instance + .SEC_StartingResources[DAT_MissionAestheticsDefinedData::instance.field_0x345c[index]], + DAT_ButtonX::instance + DAT_ButtonW::instance - 10, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, 0); + } else { + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_MapPropertiesState::instance + .SEC_StartingResources[DAT_MissionAestheticsDefinedData::instance.field_0x345c[index]], + DAT_ButtonX::instance + DAT_ButtonW::instance - 10, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + } + int icon = DAT_MissionAestheticsDefinedData::instance.field_0x345c[index] * 2 + 141; + if (icon == 157) { + icon = 155; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, icon, + DAT_ButtonX::instance + 10, + DAT_ButtonY::instance + - DAT_GMImageHeaders::instance + .imh[GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2] + icon + - 1] + .height + / 2 + + 15); + } else if (index < 30) { + // a unit of the attacking force, on a siege map + if (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 != OpenSHC::Map::MT_SIEGE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_MapPropertiesState::instance.SEC_SiegeInformation[index - 20], + DAT_ButtonX::instance + DAT_ButtonW::instance - 10, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, 0); + } else { + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_MapPropertiesState::instance.SEC_SiegeInformation[index - 20], + DAT_ButtonX::instance + DAT_ButtonW::instance - 10, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + } + int imageID = index - 19; + if (index == 29) { + imageID = index - 18; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_ARMY_UNITS, imageID, + DAT_ButtonX::instance, + DAT_ButtonY::instance + - DAT_GMImageHeaders::instance + .imh[GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_ARMY_UNITS] + imageID - 1] + .height + / 2 + + 15); + } else if (index == 30) { + // "Popularity" + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, 79, DAT_ButtonX::instance + DAT_ButtonW::instance / 2, + DAT_ButtonY::instance + 6, OpenSHC::Text::TTA_CENTER, + OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, 79, DAT_ButtonX::instance + DAT_ButtonW::instance / 2, + DAT_ButtonY::instance + 6, OpenSHC::Text::TTA_CENTER, + OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE); + } + } else if (index >= 40 && index < 50) { + // a siege engine of the attacking force; row 46 reads tunnelersCount, which follows the engines + if (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 != OpenSHC::Map::MT_SIEGE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_MapPropertiesState::instance.SEC_Section1067.siegeEngineCounts[index - 40], + DAT_ButtonX::instance + DAT_ButtonW::instance - 10, DAT_ButtonY::instance + 8, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, 0); + } else { + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_MapPropertiesState::instance.SEC_Section1067.siegeEngineCounts[index - 40], + DAT_ButtonX::instance + DAT_ButtonW::instance - 10, DAT_ButtonY::instance + 8, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + } + int imageID = index - 28; + if (index == 45) { + imageID = 10; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_ARMY_UNITS, imageID, + DAT_ButtonX::instance, + DAT_ButtonY::instance + - DAT_GMImageHeaders::instance + .imh[GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_ARMY_UNITS] + imageID - 1] + .height + / 2 + + 15); + } + } else if (button < 1000) { + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(button); + } else if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBoxWithRoundedEdges, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonX::instance + DAT_ButtonW::instance, DAT_ButtonY::instance + DAT_ButtonH::instance, + OpenSHC::UI::Enums::RBERL_SLIGHT); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBoxWithRoundedEdgesAndColor, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonX::instance + DAT_ButtonW::instance, DAT_ButtonY::instance + DAT_ButtonH::instance, + COL_BLUE::instance.shortValue, OpenSHC::UI::Enums::RBERL_SLIGHT); + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ad1cae7ac3..be1a57a576 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33185,7 +33185,7 @@ SHC_3BB0A8C1_0x004C0CE6 | 0.0% | Pending SHC_3BB0A8C1_0x004C0CE7 | 0.0% | Pending -SHC_3BB0A8C1_0x004C0CF0 | 0.0% | Pending +SHC_3BB0A8C1_0x004C0CF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C1070 | 100.0% | Reimplemented From 0ea4fcfc7ee447d5e125d4d70e3066a0455dfca4 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 21:24:39 +0100 Subject: [PATCH 4/8] headers: DAT_SentOrRequestedGoodsAmount is an int The amount the send / request goods dialog works with is compared as a signed value wherever it is read in MenuItemActionHandler_AlliesSendAndRequestGoods_Main (0x004B14C0): - 0x004B15E6: mov ecx, [0x00DF428C] / test ecx, ecx / jle: no amount chosen. An unsigned test would be je; - 0x004B16ED: mov ecx, [0x00DF428C] / cmp eax, ecx / jge against the room getResourceSpace returned; - 0x004B183A: cmp [the player's gold], esi / jge, and 0x004B1863 jl, 0x004B1870 cmp eax, esi / jge, with the amount in esi. As undefined4 (unsigned) each of these needs an (int) cast. Its only user on main, MenuItemActionHandler_Allies_Main (0x004B12D0), assigns to it and stays at 100.0% with the change. Co-Authored-By: Claude Fable 5.2 --- src/OpenSHC/Globals/DAT_SentOrRequestedGoodsAmount.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Globals/DAT_SentOrRequestedGoodsAmount.hpp b/src/OpenSHC/Globals/DAT_SentOrRequestedGoodsAmount.hpp index 709387f73e..bb93de17c4 100644 --- a/src/OpenSHC/Globals/DAT_SentOrRequestedGoodsAmount.hpp +++ b/src/OpenSHC/Globals/DAT_SentOrRequestedGoodsAmount.hpp @@ -9,11 +9,11 @@ #pragma once // GLOBAL: STRONGHOLDCRUSADER 0x00DF428C -// StructResolver::Instance::instance +// StructResolver::Instance::instance namespace OpenSHC { -MACRO_STRUCT_RESOLVER(undefined4, false, Address::SHC_3BB0A8C1_0x00DF428C) DAT_SentOrRequestedGoodsAmount; +MACRO_STRUCT_RESOLVER(int, false, Address::SHC_3BB0A8C1_0x00DF428C) DAT_SentOrRequestedGoodsAmount; } // namespace OpenSHC MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00DF428C); From 375dff12553350632b964767f72ff332abff202c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 21:24:40 +0100 Subject: [PATCH 5/8] reimplement: SHC_3BB0A8C1_0x004B14C0 100.0% Reimplemented AlliesSendAndRequestGoods::MenuItemActionHandler_AlliesSendAndRequestGoods_Main, rewritten from the listing on top of gynt's draft: c7cfed8b2 and 8ee562332 (32.9%, upstream's reimpl/UI-MenuItems), cbc63a3da, 17cbc68d6 and df54f4e0a (56.22% to 57.83%, his fork's reimpl/UI-MenuItems), 8725ec523 (58.2%) and 0e551f689 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our 1f2997859 in draft #328 read 60.5%. Behaviour, where the draft differed from the original: - buttons 21 and 50 to 53 return after their one store, and any other button but 100 returns after opening the allies dialog. The draft went on from each of them into button 100's path; - button 102 (cancel) queues its command only when the send dialog is open and DAT_00df4284 is set. The draft queued it always; - when a request fails for want of a building or of room, the original plays at most the one warning that fits the fail state and closes the dialog. The draft played the third warning in every case and, after a missing building, went on to the room test; - a request that is accepted queues the command and closes the dialog; the draft also played the "goods not sent" clip after it; - button 100 does nothing after the request path. The draft fell into the send path. What the match needed: - button 100 holds the whole confirm path and the other buttons' activateModalDialog comes last, which puts the return block where the original has it (with the test turned round it read 0.9305 in quick_diff); - the request path is one if / else-if chain that closes the dialog once at its end, with the five command stores and queueCommand written in both arms that send. The "not enough" arm comes first in the second (accepted first reads 0.9732); - good <= -1, as the original compares with -1 (good < 0 reads 0.9923); - the send path has one local for the resource, one for the type it is stored as, and one for the amount. Uses the header commit before this one (the amount is an int), so no cast on it is left. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ...Handler_AlliesSendAndRequestGoods_Main.cpp | 260 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/AlliesSendAndRequestGoods/MenuItemActionHandler_AlliesSendAndRequestGoods_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/AlliesSendAndRequestGoods/MenuItemActionHandler_AlliesSendAndRequestGoods_Main.cpp b/src/OpenSHC/UI/MenuItems/AlliesSendAndRequestGoods/MenuItemActionHandler_AlliesSendAndRequestGoods_Main.cpp new file mode 100644 index 0000000000..b1b03ea811 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/AlliesSendAndRequestGoods/MenuItemActionHandler_AlliesSendAndRequestGoods_Main.cpp @@ -0,0 +1,260 @@ +#include "../AlliesSendAndRequestGoods.func.hpp" + +#include "OpenSHC/AI/AICState.func.hpp" +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/Actions.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/Resources/ResourceType.hpp" +#include "OpenSHC/Game/Resources/ResourceTypeMin1.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_00df4284.hpp" +#include "OpenSHC/Globals/DAT_AICState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LastTeamMemberIndex.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_RequestedGoodsByWhoArray.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_SentOrRequestedGoodsAmount.hpp" +#include "OpenSHC/Globals/DAT_SomeTeamMemberPlayerIDArray.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B14C0 + void AlliesSendAndRequestGoods::MenuItemActionHandler_AlliesSendAndRequestGoods_Main(int button, ...) + { + int const playerID = DAT_SomeTeamMemberPlayerIDArray::instance[DAT_LastTeamMemberIndex::instance]; + if (button == 40) { + return; + } + if (button <= 20) { + // a good's button: the list skips RTM_PARTIALSTONE and RTM_PITCH, and has iron armour in gold's place + DAT_RequestedGoodsByWhoArray::instance[0] = button; + if (button >= 4) { + DAT_RequestedGoodsByWhoArray::instance[0] = button + 1; + } + if (button >= 5) { + DAT_RequestedGoodsByWhoArray::instance[0]++; + } + if (DAT_RequestedGoodsByWhoArray::instance[0] == OpenSHC::Game::Resources::RTM_GOLD) { + DAT_RequestedGoodsByWhoArray::instance[0] = OpenSHC::Game::Resources::RTM_IRONARMOR; + } + return; + } + // gold + if (button == 21) { + DAT_RequestedGoodsByWhoArray::instance[0] = OpenSHC::Game::Resources::RTM_GOLD; + return; + } + // the amount's buttons + if (button == 50) { + DAT_SentOrRequestedGoodsAmount::instance += 10; + return; + } + if (button == 51) { + DAT_SentOrRequestedGoodsAmount::instance += 25; + return; + } + if (button == 52) { + DAT_SentOrRequestedGoodsAmount::instance += 100; + return; + } + if (button == 53) { + DAT_SentOrRequestedGoodsAmount::instance += 5; + return; + } + if (button == 54) { + DAT_SentOrRequestedGoodsAmount::instance += 500; + return; + } + // cancel: the choice is cleared, and an ally whose request this dialog answers gets command 3 + if (button == 102) { + DAT_RequestedGoodsByWhoArray::instance[0] = -1; + DAT_SentOrRequestedGoodsAmount::instance = 0; + if (DAT_MenuModalComposition1::instance.activeModalDialogID + != OpenSHC::UI::Enums::MMT_ALLIES_SEND_GOODS) { + return; + } + if (!DAT_00df4284::instance) { + return; + } + DAT_GameSynchronyState::instance.DAT_GameCommandParam4 + = DAT_GameSynchronyState::instance.currentPlayerSlotID; + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 3; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = playerID; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_SEND_PLAYER_TO_PLAYER_REQUEST); + return; + } + // confirm, once a good and an amount are chosen + if (button == 100) { + if (DAT_RequestedGoodsByWhoArray::instance[0] <= -1) { + return; + } + if (DAT_SentOrRequestedGoodsAmount::instance <= 0) { + return; + } + if (DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_ALLIES_REQUEST_GOODS) { + if (DAT_RequestedGoodsByWhoArray::instance[0] + 1 == OpenSHC::Game::Resources::RT_GOLD) { + if (!MACRO_CALL_MEMBER( + OpenSHC::AI::AICState_Func::isResourceLargerOrEqualThanMinimumGoodsRequiredAfterTrade, + DAT_AICState::ptr)(playerID, + (OpenSHC::Game::Resources::ResourceType)(DAT_RequestedGoodsByWhoArray::instance[0] + 1), + DAT_SentOrRequestedGoodsAmount::instance)) { + MACRO_CALL_MEMBER( + OpenSHC::AI::AICState_Func::playGoodsNotSentBikFromPlayer, DAT_AICState::ptr)(playerID); + } else { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 1; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = playerID; + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 + = DAT_RequestedGoodsByWhoArray::instance[0]; + DAT_GameSynchronyState::instance.DAT_GameCommandParam3 + = DAT_SentOrRequestedGoodsAmount::instance; + DAT_GameSynchronyState::instance.DAT_GameCommandParam4 + = DAT_GameSynchronyState::instance.currentPlayerSlotID; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_SEND_PLAYER_TO_PLAYER_REQUEST); + } + } else { + int const space = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::getResourceSpace, DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + (OpenSHC::Game::Resources::ResourceType)(DAT_RequestedGoodsByWhoArray::instance[0] + 1)); + if (space == -1) { + // no building to put it in: the fail state says which one is missing + MACRO_CALL(OpenSHC::UI::Actions_Func::SetStorageMarketFailState)( + 3, (OpenSHC::Game::Resources::ResourceType)DAT_RequestedGoodsByWhoArray::instance[0]); + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .storageMarketFailState + == 6) { + // "No stockpile built" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_space_warning2_wav_005a5950); + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .storageMarketFailState + == 5) { + // "No granary built" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_space_warning1_wav_005a593c); + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .storageMarketFailState + == 7) { + // "No armory built" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_space_warning3_wav_005a5928); + } + } else if (space < DAT_SentOrRequestedGoodsAmount::instance) { + // not enough room in it + MACRO_CALL(OpenSHC::UI::Actions_Func::SetStorageMarketFailState)( + 4, (OpenSHC::Game::Resources::ResourceType)DAT_RequestedGoodsByWhoArray::instance[0]); + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .storageMarketFailState + == 9) { + // "No space in the stockpile" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_space_warning5_wav_005a50b0); + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .storageMarketFailState + == 8) { + // "No space in the granary" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_space_warning4_wav_005a5914); + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .storageMarketFailState + == 10) { + // "No space in the armory" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_space_warning6_wav_005a5900); + } + } else if ( + !MACRO_CALL_MEMBER( + OpenSHC::AI::AICState_Func::isResourceLargerOrEqualThanMinimumGoodsRequiredAfterTrade, + DAT_AICState::ptr)(playerID, + (OpenSHC::Game::Resources::ResourceType)(DAT_RequestedGoodsByWhoArray::instance[0] + 1), + DAT_SentOrRequestedGoodsAmount::instance)) { + MACRO_CALL_MEMBER( + OpenSHC::AI::AICState_Func::playGoodsNotSentBikFromPlayer, DAT_AICState::ptr)(playerID); + } else { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 1; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = playerID; + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 + = DAT_RequestedGoodsByWhoArray::instance[0]; + DAT_GameSynchronyState::instance.DAT_GameCommandParam3 + = DAT_SentOrRequestedGoodsAmount::instance; + DAT_GameSynchronyState::instance.DAT_GameCommandParam4 + = DAT_GameSynchronyState::instance.currentPlayerSlotID; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_SEND_PLAYER_TO_PLAYER_REQUEST); + } + } + DAT_MenuModalComposition1::instance.activeModalDialogID = OpenSHC::UI::Enums::MMT_NONE; + return; + } + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_ALLIES, FALSE); + // sending: the ally needs room for it and the player has to have it; gold needs no room + int const resource = DAT_RequestedGoodsByWhoArray::instance[0] + 1; + int storedAs = resource; + if (resource == OpenSHC::Game::Resources::RT_PARTIALPITCH) { + storedAs = resource - 1; + } + int amount = DAT_SentOrRequestedGoodsAmount::instance; + if (resource == OpenSHC::Game::Resources::RT_GOLD) { + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[OpenSHC::Game::Resources::RT_GOLD] + < amount) { + return; + } + } else { + int const space = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getResourceSpace, + DAT_BuildingsState::ptr)(playerID, (OpenSHC::Game::Resources::ResourceType)storedAs); + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[storedAs] + < amount) { + return; + } + if (space < 0) { + return; + } + if (space < amount) { + amount = space; + } + } + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 2; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = playerID; + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 = resource; + DAT_GameSynchronyState::instance.DAT_GameCommandParam3 = amount; + DAT_GameSynchronyState::instance.DAT_GameCommandParam4 + = DAT_GameSynchronyState::instance.currentPlayerSlotID; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_SEND_PLAYER_TO_PLAYER_REQUEST); + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_NONE, FALSE); + return; + } + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_ALLIES, FALSE); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index be1a57a576..665c4a5812 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -25979,7 +25979,7 @@ SHC_3BB0A8C1_0x004B1410 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B1471 | 0.0% | Pending -SHC_3BB0A8C1_0x004B14C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004B14C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B18D0 | 100.0% | Reimplemented From 6da693458e993dbfc60425274a7c226f5077ae14 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 21:39:39 +0100 Subject: [PATCH 6/8] headers: IngameInvasionEventItemContent has an int at 0xA4 MenuItemActionHandler_General_EventSlider (0x004B9E50) reads the four bytes at 0xA4 as one int, the highest value of the invasion's slider: mov eax, dword ptr [0x01667EEC] at 0x004B9E86 (DAT_MapPropertiesState's invasionEventContent + 0xA4), which it then stores to *maxValue and clamps field_0xa8 with. The header had them as undefined1 padding_0xa4[4], which needs *(int*)&...padding_0xa4[0] to read. Named field_0xa4 like its neighbours field_0xa0 and field_0xa8; the struct's size and layout are unchanged, and nothing on main names the padding. Co-Authored-By: Claude Fable 5.2 --- .../Game/ScenarioEvents/IngameInvasionEventItemContent.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/Game/ScenarioEvents/IngameInvasionEventItemContent.hpp b/src/OpenSHC/Game/ScenarioEvents/IngameInvasionEventItemContent.hpp index 5ba6015795..55aa7eef88 100644 --- a/src/OpenSHC/Game/ScenarioEvents/IngameInvasionEventItemContent.hpp +++ b/src/OpenSHC/Game/ScenarioEvents/IngameInvasionEventItemContent.hpp @@ -26,7 +26,7 @@ namespace Game { int markerIDUnk; // 0x00000078 length: 4 undefined1 padding_0x7c[36]; // 0x0000007C length: 36 int field_0xa0; // 0x000000A0 length: 4 - undefined1 padding_0xa4[4]; // 0x000000A4 length: 4 + int field_0xa4; // 0x000000A4 length: 4 int field_0xa8; // 0x000000A8 length: 4 undefined1 padding_0xac[4]; // 0x000000AC length: 4 From 2e9808d4018cf57569390d4d97d7098d0d3e66ae Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 21:39:39 +0100 Subject: [PATCH 7/8] reimplement: SHC_3BB0A8C1_0x004B9E50 100.0% Reimplemented General::MenuItemActionHandler_General_EventSlider, from gynt's draft: cbdee606c and 7c31877d1 (45.3%, upstream's reimpl/UI-MenuItems), d0aa6c7f4 and 899dcd240 (55.93% and 69.21%, his fork's reimpl/UI-MenuItems), 514b9073b (83.26%) and dd1a7c48c of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our 200153404 and bddd6bea0 in draft #327 read 88.0%. What the match needed, on top of the draft: - the two range tests against the limit compare *currentValue > limit (cmp [ecx], eax / jle); the draft had limit < *currentValue, which swaps the operands; - in the repeat slider's switch, case 7 comes before case 4, as it already did in the months slider's. That alone took it from register names only (0.9322 in quick_diff, the three small blocks of the months slider on rotated registers) to every instruction. Readability, all measured equal: the lists of cases that only break are gone from both switches on the slider; the two step cases use ++ and --, as the invasion slider's do, and no longer the limit's local; no cast on the byte fields, read or written; the parameters are slider and scrollbarEvent, as main's other slider handlers have the second; the amount sliders' cases are written as their event type plus one (the function compares the type with slider - 1). Uses the header commit before this one (the invasion's limit is an int field). Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ...uItemActionHandler_General_EventSlider.cpp | 263 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/General/MenuItemActionHandler_General_EventSlider.cpp diff --git a/src/OpenSHC/UI/MenuItems/General/MenuItemActionHandler_General_EventSlider.cpp b/src/OpenSHC/UI/MenuItems/General/MenuItemActionHandler_General_EventSlider.cpp new file mode 100644 index 0000000000..7fd366ca3b --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/General/MenuItemActionHandler_General_EventSlider.cpp @@ -0,0 +1,263 @@ +#include "../General.func.hpp" + +#include "OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventType.hpp" + +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B9E50 + void General::MenuItemActionHandler_General_EventSlider( + int slider, int scrollbarEvent, int* minValue, int* maxValue, int* currentValue) + { + // the highest amount: by event type for the amount sliders, whose number is the type plus one + int limit = 0; + switch (slider) { + case OpenSHC::Game::ScenarioEvents::Enums::SET_LION_AWAKES + 1: + limit = 10; + break; + case OpenSHC::Game::ScenarioEvents::Enums::SET_PLAGUE + 1: + case OpenSHC::Game::ScenarioEvents::Enums::SET_LION_ATTACK + 1: + limit = 5; + break; + case OpenSHC::Game::ScenarioEvents::Enums::SET_BANDITS + 1: + case OpenSHC::Game::ScenarioEvents::Enums::SET_ARCHERS + 1: + limit = 20; + break; + case -10: + limit = DAT_MapPropertiesState::instance.invasionEventContent.field_0xa4; + break; + } + // scrollbarEvent 1 sets a slider up, 2 and 3 store its value, 4 brings the stored value into range, + // 5 and 6 step it, and 7 sets the two repeat sliders to 1 + switch (slider) { + case -1: + // how often the event repeats, 0 to 60, for the events that can repeat + switch (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.ScenarioEventType) { + case OpenSHC::Game::ScenarioEvents::Enums::SET_TRAVELING_FAIR: + case OpenSHC::Game::ScenarioEvents::Enums::SET_PLAGUE: + case OpenSHC::Game::ScenarioEvents::Enums::SET_WHEAT_DISEASE: + case OpenSHC::Game::ScenarioEvents::Enums::SET_HOPS_WEEVIL: + case OpenSHC::Game::ScenarioEvents::Enums::SET_APPLE_BLIGHT: + case OpenSHC::Game::ScenarioEvents::Enums::SET_TREE_FUNGUS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_RABBIT_EXPLOSION: + case OpenSHC::Game::ScenarioEvents::Enums::SET_LION_ATTACK: + case OpenSHC::Game::ScenarioEvents::Enums::SET_BANDITS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_MAD_COWS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_ARCHERS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_THEFT_FROM_GRANARY: + case OpenSHC::Game::ScenarioEvents::Enums::SET_FIRE: + switch (scrollbarEvent) { + case 1: + *minValue = 0; + *maxValue = 60; + *currentValue = DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.repeat; + return; + case 2: + case 3: + *minValue = 0; + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.repeat = *currentValue; + return; + case 7: + *currentValue = 1; + break; + case 4: + *currentValue = DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.repeat; + *minValue = 0; + *maxValue = 60; + if (*currentValue > 60) { + *currentValue = 60; + DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.repeat = *maxValue; + } + if (*currentValue < *minValue) { + *currentValue = *minValue; + DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.repeat = *minValue; + } + break; + } + } + break; + case -2: + // the months between two repeats, 1 to 10 + switch (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.ScenarioEventType) { + case OpenSHC::Game::ScenarioEvents::Enums::SET_TRAVELING_FAIR: + case OpenSHC::Game::ScenarioEvents::Enums::SET_PLAGUE: + case OpenSHC::Game::ScenarioEvents::Enums::SET_WHEAT_DISEASE: + case OpenSHC::Game::ScenarioEvents::Enums::SET_HOPS_WEEVIL: + case OpenSHC::Game::ScenarioEvents::Enums::SET_APPLE_BLIGHT: + case OpenSHC::Game::ScenarioEvents::Enums::SET_TREE_FUNGUS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_RABBIT_EXPLOSION: + case OpenSHC::Game::ScenarioEvents::Enums::SET_LION_ATTACK: + case OpenSHC::Game::ScenarioEvents::Enums::SET_BANDITS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_MAD_COWS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_ARCHERS: + case OpenSHC::Game::ScenarioEvents::Enums::SET_THEFT_FROM_GRANARY: + case OpenSHC::Game::ScenarioEvents::Enums::SET_FIRE: + switch (scrollbarEvent) { + case 1: + *minValue = 1; + *maxValue = 10; + *currentValue = DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.repeatMonths; + return; + case 2: + case 3: + *minValue = 1; + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.repeatMonths = *currentValue; + return; + case 7: + *currentValue = 1; + break; + case 4: + *currentValue = DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.repeatMonths; + *minValue = 1; + *maxValue = 10; + if (*currentValue > 10) { + *currentValue = 10; + DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.repeatMonths = *maxValue; + } + if (*currentValue < *minValue) { + *currentValue = *minValue; + DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.repeatMonths = *minValue; + } + break; + } + } + break; + case OpenSHC::Game::ScenarioEvents::Enums::SET_LION_AWAKES + 1: + case OpenSHC::Game::ScenarioEvents::Enums::SET_PLAGUE + 1: + case OpenSHC::Game::ScenarioEvents::Enums::SET_LION_ATTACK + 1: + case OpenSHC::Game::ScenarioEvents::Enums::SET_BANDITS + 1: + case OpenSHC::Game::ScenarioEvents::Enums::SET_ARCHERS + 1: + // the amount of the event that this slider belongs to + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.ScenarioEventType + == slider - 1) { + switch (scrollbarEvent) { + case 1: + *minValue = 1; + *maxValue = limit; + *currentValue = DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData; + return; + case 2: + case 3: + *minValue = 1; + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData = *currentValue; + return; + case 4: + *currentValue = DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData; + *minValue = 1; + *maxValue = limit; + if (*currentValue > limit) { + *currentValue = limit; + DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData = *maxValue; + } + if (*currentValue < *minValue) { + *currentValue = *minValue; + DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData = *minValue; + } + break; + case 5: + if (DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData + < *maxValue) { + ++DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData; + } + *currentValue = DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData; + return; + case 6: + if (DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData + > 0) { + --DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData; + } + *currentValue = DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.actionData; + break; + } + } + break; + case -10: + // the invasion's amount + switch (scrollbarEvent) { + case 1: + *minValue = 1; + *maxValue = limit; + *currentValue = DAT_MapPropertiesState::instance.invasionEventContent.field_0xa8; + return; + case 2: + case 3: + *minValue = 1; + DAT_MapPropertiesState::instance.invasionEventContent.field_0xa8 = *currentValue; + return; + case 4: + *currentValue = DAT_MapPropertiesState::instance.invasionEventContent.field_0xa8; + *minValue = 1; + *maxValue = limit; + if (*currentValue > limit) { + *currentValue = limit; + DAT_MapPropertiesState::instance.invasionEventContent.field_0xa8 = *maxValue; + } + if (*currentValue < *minValue) { + *currentValue = *minValue; + DAT_MapPropertiesState::instance.invasionEventContent.field_0xa8 = *minValue; + } + break; + case 5: + if (DAT_MapPropertiesState::instance.invasionEventContent.field_0xa8 < *maxValue) { + ++DAT_MapPropertiesState::instance.invasionEventContent.field_0xa8; + } + *currentValue = DAT_MapPropertiesState::instance.invasionEventContent.field_0xa8; + return; + case 6: + if (DAT_MapPropertiesState::instance.invasionEventContent.field_0xa8 > 0) { + --DAT_MapPropertiesState::instance.invasionEventContent.field_0xa8; + } + *currentValue = DAT_MapPropertiesState::instance.invasionEventContent.field_0xa8; + } + break; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 665c4a5812..151a56b8c7 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -28653,7 +28653,7 @@ SHC_3BB0A8C1_0x004B9E4E | 0.0% | Pending SHC_3BB0A8C1_0x004B9E4F | 0.0% | Pending -SHC_3BB0A8C1_0x004B9E50 | 0.0% | Pending +SHC_3BB0A8C1_0x004B9E50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BA2A0 | 0.0% | Pending From 04856c69dd85d99dd49554394b4ad2b86dd13398 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 22:12:12 +0100 Subject: [PATCH 8/8] reimplement: SHC_3BB0A8C1_0x0042D140 100.0% Reimplemented SinglePlayerMapChoice::MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands, rewritten from the listing on top of gynt's draft: 582f0a002 and 6918f2387 (14.3%, upstream's reimpl/UI-MenuItems), 47663d013 (29.50%, his fork's development), 1ff44c3aa to eaf674d99 (20.55% to 44.64%, his fork's reimpl/UI-MenuItems), b4b1f6584 (45.29%) and dd1a7c48c of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our dcaa477ea, 53bea5fdf and 07a33e2bb in draft #328 read 46.8%. Behaviour: unchanged. The draft cleared DAT_ButtonUnknownZero after the switch for buttons 2 and 65; here each of the two clears it itself, before its call, as the original does. The draft's gotos into a shared text call are gone. What the match needed: - every case breaks to one store of the draw buffer at the end (the compiler copies it into the arms, with pop edi before it, as the original has it); the draft stored and returned in every arm; - each text is drawn by a call of its own in each arm of the colour test, and renderBasicButton is called in each of button 74's three arms and button 77's two; - case 78 is written out with its own store and return: the original's switch has a table entry for it, though it ends in the same block as the default (with a plain break, or left to the default, the range check reads cmp eax, 178 where the original has 179); - the map-index sum in button 65 is DAT_MapSelectionScrollOffset + DAT_MapSelectionRelativeSelected: the other order loads the two fields the other way round (reccmp 99.6%; quick_diff does not see it). Readability, measured equal: X + W / 2 and X + W - 10 for the text positions. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ..._SingleplayerMapChoice_ButtonsAndHands.cpp | 176 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/SinglePlayerMapChoice/MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands.cpp diff --git a/src/OpenSHC/UI/MenuItems/SinglePlayerMapChoice/MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands.cpp b/src/OpenSHC/UI/MenuItems/SinglePlayerMapChoice/MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands.cpp new file mode 100644 index 0000000000..f762db2d98 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/SinglePlayerMapChoice/MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands.cpp @@ -0,0 +1,176 @@ +#include "../SinglePlayerMapChoice.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/DAT_00b960dc.hpp" +#include "OpenSHC/Globals/DAT_ButtonBackgroundBlendStrength.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MapMissionType.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_SH1_SiegeAdvancedMode.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x0042D140 + void SinglePlayerMapChoice::MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands(int button, ...) + { + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + switch (button) { + // the scroll arrows of the two lists + case -10: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, + DAT_PencilRenderCore::ptr)(0, DAT_ButtonBackgroundBlendStrength::instance); + break; + case -11: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, + DAT_PencilRenderCore::ptr)(1, DAT_ButtonBackgroundBlendStrength::instance); + break; + case -100: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, + DAT_PencilRenderCore::ptr)(0, DAT_ButtonBackgroundBlendStrength::instance); + break; + case -101: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, + DAT_PencilRenderCore::ptr)(1, DAT_ButtonBackgroundBlendStrength::instance); + break; + case 2: + // the blend strength goes through * 32 / 32, as the original computes it (shl 5, then a signed divide) + DAT_ButtonUnknownZero::instance = FALSE; + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderCurrentButtonToScreenMenuWithBlendingUnk)( + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + break; + case 69: + // "Difficulty" and its setting, where the mission has one + if (DAT_MapMissionType::instance != 0 && DAT_GameCore::instance.mapU4Int1_2 == 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)( + DAT_ButtonBackgroundBlendStrength::instance, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + if (DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MAINOPTIONS, 24, + DAT_ButtonX::instance + 10, DAT_ButtonY::instance + 8, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MAINOPTIONS, 24, + DAT_ButtonX::instance + 10, DAT_ButtonY::instance + 8, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MAINOPTIONS, + DAT_GameState::instance.mapAndTime.difficulty + 19, + DAT_ButtonX::instance + DAT_ButtonW::instance - 10, DAT_ButtonY::instance + 8, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_00FF00, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + break; + case 74: + // "Advanced", for the second player of a siege; shown as pressed while the advanced mode is on + if (DAT_MapMissionType::instance == 2 && DAT_GameSynchronyState::instance.currentPlayerSlotID == 2 + && DAT_GameCore::instance.mapU4Int1_2 == 0) { + if (DAT_SH1_SiegeAdvancedMode::instance != 0 && DAT_00b960dc::instance == 0) { + DAT_ButtonCurrentlyInteracting::instance = TRUE; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)( + DAT_ButtonBackgroundBlendStrength::instance, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, button, + DAT_ButtonX::instance + DAT_ButtonW::instance / 2, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } else if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)( + DAT_ButtonBackgroundBlendStrength::instance, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, button, + DAT_ButtonX::instance + DAT_ButtonW::instance / 2, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)( + DAT_ButtonBackgroundBlendStrength::instance, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, button, + DAT_ButtonX::instance + DAT_ButtonW::instance / 2, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + } + break; + case 77: + // the side the player is on: text 77, or 78 for the first player + if (DAT_MapMissionType::instance == 2) { + if (DAT_GameSynchronyState::instance.currentPlayerSlotID == 1) { + button = 78; + } + if (DAT_GameCore::instance.mapU4Int1_2 == 0) { + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(DAT_ButtonBackgroundBlendStrength::instance, + OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, button, + DAT_ButtonX::instance + DAT_ButtonW::instance / 2, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(DAT_ButtonBackgroundBlendStrength::instance, + OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, button, + DAT_ButtonX::instance + DAT_ButtonW::instance / 2, DAT_ButtonY::instance + 7, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + } + } + break; + case 65: { + // at half strength, and never as pressed, while no map is selected + DAT_ButtonUnknownZero::instance = FALSE; + int factor = 32; + if (DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected + < 0) { + factor = 16; + DAT_ButtonCurrentlyInteracting::instance = FALSE; + } + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderCurrentButtonToScreenMenuWithBlendingUnk)( + 32 - (32 - DAT_ButtonBackgroundBlendStrength::instance) * factor / 32); + break; + } + case 78: + // nothing to draw; written out, since the original's switch has this case of its own + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 151a56b8c7..0fd6a59ec7 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -7481,7 +7481,7 @@ SHC_3BB0A8C1_0x0042D138 | 0.0% | Pending SHC_3BB0A8C1_0x0042D13C | 0.0% | Pending -SHC_3BB0A8C1_0x0042D140 | 0.0% | Pending +SHC_3BB0A8C1_0x0042D140 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0042D554 | 0.0% | Pending