From cfc7e1dd084943fe28493a6fd99a02ce03da7e3e Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 14 Nov 2026 01:05:02 +0100 Subject: [PATCH 1/6] headers: MenuModalComposition's slider minimum and maximum are ints sliderMinimum and sliderMaximum were dword. The original treats them as signed: the OverlaySlider handler (0x004AA600) tests `sliderMaximum - sliderMinimum > 200` with jle (0x4aa630, 0x4aa697, 0x4aa7a3) and divides by 5 signed (0x4aa635, 0x4aa6c4). With the fields as int the handler measures 100.0 instead of 57.1 (reccmp, main 1d819b797; the same again on 341649866). The only other users of the two fields, setSliderParameters and setSliderParameters2, only store to them, so they compile the same. sliderValue stays dword: the original only copies it, and the handler compiles to the same code either way. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/MenuModalComposition.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/UI/MenuModalComposition.hpp b/src/OpenSHC/UI/MenuModalComposition.hpp index 582f483a43..bc8886afd3 100644 --- a/src/OpenSHC/UI/MenuModalComposition.hpp +++ b/src/OpenSHC/UI/MenuModalComposition.hpp @@ -34,8 +34,8 @@ namespace UI { dword modalDragDropUnk; // 0x00000030 length: 4 dword mouseRelativeX; // 0x00000034 length: 4 dword mouseRelativeY; // 0x00000038 length: 4 - dword sliderMinimum; // 0x0000003C length: 4 - dword sliderMaximum; // 0x00000040 length: 4 + int sliderMinimum; // 0x0000003C length: 4 + int sliderMaximum; // 0x00000040 length: 4 undefined1 padding_0x44[8]; // 0x00000044 length: 8 int textGroup; // 0x0000004C length: 4 int textIndex; // 0x00000050 length: 4 From 1566007f5165336ed88234f783c8f195d7962fef Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 14 Nov 2026 01:05:02 +0100 Subject: [PATCH 2/6] reimplement: SHC_3BB0A8C1_0x004AA600 100.0% Reimplemented MenuItemActionHandler_OverlaySlider_Slider, from our own drafts at 89.8% and 91.5% (local, never pushed), themselves rewritten from gynt's draft (593c4ef61 at 47.37% on his fork's reimpl/UI-MenuItems-development; his last style pass on the file is f6c6b8b15). It needs the slider minimum and maximum as ints (the MenuModalComposition header commit before this one); with them reccmp reads 100.0, normalised 100.0. The fix: case 1 stores the current value once, after the large-range and small-range branches, rather than at the end of each. MSVC then gives the small-range branch the original's scratch registers, and case 2 and 3 follow (the store in each branch measured 91.5). Case 7 tests `*currentValue > *maxValue / 2` for the step of 1, which gives the original's setle. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...ItemActionHandler_OverlaySlider_Slider.cpp | 98 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/OverlaySlider/MenuItemActionHandler_OverlaySlider_Slider.cpp diff --git a/src/OpenSHC/UI/MenuItems/OverlaySlider/MenuItemActionHandler_OverlaySlider_Slider.cpp b/src/OpenSHC/UI/MenuItems/OverlaySlider/MenuItemActionHandler_OverlaySlider_Slider.cpp new file mode 100644 index 0000000000..b86e22dfd2 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/OverlaySlider/MenuItemActionHandler_OverlaySlider_Slider.cpp @@ -0,0 +1,98 @@ +#include "../OverlaySlider.func.hpp" + +#include "OpenSHC/Globals/DAT_MenuModalComposition2.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004AA600 + void OverlaySlider::MenuItemActionHandler_OverlaySlider_Slider( + int unused, int scrollbarEvent, int* minValue, int* maxValue, int* currentValue) + { + // a range over 200 gets a slider 1.6 times as long: its first half moves a value in steps of 1/4, the + // second half in steps of 1 + switch (scrollbarEvent) { + case 1: { + int const range = DAT_MenuModalComposition2::instance.sliderMaximum + - DAT_MenuModalComposition2::instance.sliderMinimum; + // stored first and overwritten below, as the original does + *maxValue = range; + if (range > 200) { + *maxValue = range * 3 / 5 + range; + *minValue = 0; + } else { + *minValue = DAT_MenuModalComposition2::instance.sliderMinimum; + *maxValue = DAT_MenuModalComposition2::instance.sliderMaximum; + } + *currentValue = DAT_MenuModalComposition2::instance.sliderValue; + return; + } + case 2: + case 3: + // the slider moved: write the value it stands for + if (DAT_MenuModalComposition2::instance.sliderMaximum + - DAT_MenuModalComposition2::instance.sliderMinimum + > 200) { + DAT_MenuModalComposition2::instance.sliderValue = *currentValue; + if (*currentValue > *maxValue / 2) { + if (DAT_MenuModalComposition2::instance.destination != NULL) { + *DAT_MenuModalComposition2::instance.destination = *currentValue + - DAT_MenuModalComposition2::instance.sliderMaximum * 3 / 5 + + DAT_MenuModalComposition2::instance.sliderMinimum; + if (*currentValue == *maxValue) { + *DAT_MenuModalComposition2::instance.destination + = DAT_MenuModalComposition2::instance.sliderMaximum; + } + return; + } + // short operands, for the original's 16-bit subtract and add + *DAT_MenuModalComposition2::instance.destination2 = (short)*currentValue + - (short)(DAT_MenuModalComposition2::instance.sliderMaximum * 3 / 5) + + (short)DAT_MenuModalComposition2::instance.sliderMinimum; + if (*currentValue == *maxValue) { + *DAT_MenuModalComposition2::instance.destination2 + = DAT_MenuModalComposition2::instance.sliderMaximum; + } + return; + } + if (DAT_MenuModalComposition2::instance.destination != NULL) { + *DAT_MenuModalComposition2::instance.destination + = *currentValue / 4 + DAT_MenuModalComposition2::instance.sliderMinimum; + return; + } + *DAT_MenuModalComposition2::instance.destination2 + = *currentValue / 4 + DAT_MenuModalComposition2::instance.sliderMinimum; + return; + } + DAT_MenuModalComposition2::instance.sliderValue = *currentValue; + if (DAT_MenuModalComposition2::instance.destination != NULL) { + *DAT_MenuModalComposition2::instance.destination = *currentValue; + return; + } + *DAT_MenuModalComposition2::instance.destination2 = *currentValue; + return; + case 4: + case 5: + case 6: + return; + case 7: + // a click on the track: the step it moves the slider by + if (DAT_MenuModalComposition2::instance.sliderMaximum + - DAT_MenuModalComposition2::instance.sliderMinimum + > 200) { + if (*currentValue > *maxValue / 2) { + *currentValue = 1; + } else { + *currentValue = 4; + } + return; + } + *currentValue = 1; + return; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3a97b43162..7c48776c87 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -25497,7 +25497,7 @@ SHC_3BB0A8C1_0x004AA480 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004AA540 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004AA600 | 0.0% | Pending +SHC_3BB0A8C1_0x004AA600 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004AA7D8 | 0.0% | Pending From b607ec8bff208ea3cb44da59baeb27d493412d41 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 14 Nov 2026 01:18:17 +0100 Subject: [PATCH 3/6] reimplement: SHC_3BB0A8C1_0x004255D0 100.0% Reimplemented MenuItemRenderFunction_HistoricCampaignSelect_Main, from the draft #327 (reimpl/UI-MenuItems-3-development, 90d128473 at 98.7%; the file's newest commit on the draft is 446f9fa17), itself rewritten from gynt's draft (d07873bdd at 97.44%, after his 61351fe92 at 82.1% and 245178bb8 at 94.87%; on his fork's reimpl/UI-MenuItems-development the function is 04f12f873 at 67.10%, his newest reimplement commit on the file is 8725ec523 and his last style pass 50849804c). reccmp 100.0, quick_diff 78/78 at 1.0000. The last difference was the getTextStringInGroupAtOffset call loading ecx after both its pushes, where the original loads it between them. The campaign name is drawn by two calls that are the same, one per hover state, each with the position read into `int const textY` then `textX`: MSVC merges them completely and keeps the original's order. It is the same form as in MainMenu's render (0x00424F50), the sibling this function was copied from. The early returns, the branch order, the sound ID SEID_UNKNOWN_0x92 and the campaign names from cr.tex were already in the draft. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...erFunction_HistoricCampaignSelect_Main.cpp | 98 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/HistoricCampaignSelect/MenuItemRenderFunction_HistoricCampaignSelect_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/HistoricCampaignSelect/MenuItemRenderFunction_HistoricCampaignSelect_Main.cpp b/src/OpenSHC/UI/MenuItems/HistoricCampaignSelect/MenuItemRenderFunction_HistoricCampaignSelect_Main.cpp new file mode 100644 index 0000000000..74fbbbafad --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/HistoricCampaignSelect/MenuItemRenderFunction_HistoricCampaignSelect_Main.cpp @@ -0,0 +1,98 @@ +#include "../HistoricCampaignSelect.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/MenuItems/General.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/Audio/SFX/SoundEffectID.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/IO/Graphics/GmID.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" + +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonGmDataIndex.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonPictureInGm.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_UIButtonDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UnknownGFXIndex.hpp" +#include "OpenSHC/Globals/INT_00b95abc.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004255D0 + void HistoricCampaignSelect::MenuItemRenderFunction_HistoricCampaignSelect_Main(int button, ...) + { + if (DAT_UnknownGFXIndex::instance == 1) { + return; + } + if (button != 5 && !DAT_ButtonCurrentlyInteracting::instance) { + if (button == INT_00b95abc::instance) { + INT_00b95abc::instance = -1; + } + if (DAT_TextureRenderCoreObject::instance.unknownSfxAndGmRelatedFlag && button < 5) { + DAT_CurrentButtonGmDataIndex::instance = 353; + } + MACRO_CALL(OpenSHC::UI::MenuItems::General_Func:: + MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface)(); + } else { + if (DAT_TextureRenderCoreObject::instance.unknownSfxAndGmRelatedFlag && button < 5) { + DAT_CurrentButtonGmDataIndex::instance = 353; + } + MACRO_CALL(OpenSHC::UI::MenuItems::General_Func:: + MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface)(); + DAT_CurrentButtonPictureInGm::instance + = DAT_UIButtonDefinedData::instance.ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .pictureInGm_0x4; + if (button >= 5) { + return; + } + if (INT_00b95abc::instance != button) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, DAT_SFXState::ptr)( + OpenSHC::Audio::SFX::SEID_UNKNOWN_0x92); + } + INT_00b95abc::instance = button; + } + if (button >= 5) { + return; + } + // the campaign's name, "Heads on Spikes" to "Crusader States" + // one call per hover state, the two the same, for the match + if (!DAT_ButtonCurrentlyInteracting::instance) { + int const textY = DAT_ButtonY::instance + 15; + int const textX = DAT_ButtonX::instance + 30; + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_BUBBLE_HELP_TEXT, button + 309), + textX, textY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 0, 16, FALSE, 0); + } else { + int const textY = DAT_ButtonY::instance + 15; + int const textX = DAT_ButtonX::instance + 30; + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_BUBBLE_HELP_TEXT, button + 309), + textX, textY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 0, 16, FALSE, 0); + } + if (!DAT_ButtonCurrentlyInteracting::instance) { + return; + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_ICONS_FRONT_END, 1, + DAT_ButtonX::instance - 85, DAT_ButtonY::instance - 28, OpenSHC::IO::Graphics::GID_ICONS_FRONT_END, 2, + 0); + 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 7c48776c87..d87c84f977 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -6711,7 +6711,7 @@ SHC_3BB0A8C1_0x00425500 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00425580 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004255D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004255D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00425720 | 100.0% | Reimplemented From 133c2c2add9a46f2a1daf673386cf63fbc3f965e Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 14 Nov 2026 01:22:09 +0100 Subject: [PATCH 4/6] reimplement: SHC_3BB0A8C1_0x00492FD0 100.0% Reimplemented MenuItemRenderFunction_SaveLoadMap_TableHeader, from gynt's draft (78de101ef at 97.44% on his fork's reimpl/UI-MenuItems, after his 0747a3caf; on his reimpl/UI-MenuItems-development the file has 200247358, and his newest reimplement commit on it there is 8725ec523; quick_diff 0.9744 on main). reccmp 100.0, quick_diff 39/39 at 1.0000. The draft's only difference was the getTextStringInGroupAtOffset call loading ecx after both its pushes, where the original loads it between them. As in HistoricCampaignSelect's render (0x004255D0, earlier on this branch), the header text is written as two calls that are the same, one per hover state, each with `int const textY` then `textX`: MSVC merges them completely, leaving no branch, and keeps the original's order. Position locals alone measured the same as the draft. The column switch and its text numbers were already gynt's ("Name", "Date" and "Mission" in TEXT_GAME_OPTIONS); the colour is COL_CCFAFF, the font size 18, and the parameter is the column. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...RenderFunction_SaveLoadMap_TableHeader.cpp | 56 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/SaveLoadMap/MenuItemRenderFunction_SaveLoadMap_TableHeader.cpp diff --git a/src/OpenSHC/UI/MenuItems/SaveLoadMap/MenuItemRenderFunction_SaveLoadMap_TableHeader.cpp b/src/OpenSHC/UI/MenuItems/SaveLoadMap/MenuItemRenderFunction_SaveLoadMap_TableHeader.cpp new file mode 100644 index 0000000000..1b43279631 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/SaveLoadMap/MenuItemRenderFunction_SaveLoadMap_TableHeader.cpp @@ -0,0 +1,56 @@ +#include "../SaveLoadMap.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" + +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x00492FD0 + void SaveLoadMap::MenuItemRenderFunction_SaveLoadMap_TableHeader(int column, ...) + { + int textNumInGroup = -1; + switch (column) { + case 2: + textNumInGroup = 29; // "Mission" + break; + case 1: + textNumInGroup = 28; // "Date" + break; + case 0: + textNumInGroup = 27; // "Name" + break; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawTableCellBackground, + DAT_PencilRenderCore::ptr)(FALSE, 1, 0); + // one call per hover state, the two the same: the form that compiles to the original's code + if (!DAT_ButtonCurrentlyInteracting::instance) { + int const textY = DAT_ButtonY::instance + 3; + int const textX = DAT_ButtonX::instance + 8; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_GAME_OPTIONS, textNumInGroup), + textX, textY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + } else { + int const textY = DAT_ButtonY::instance + 3; + int const textX = DAT_ButtonX::instance + 8; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_GAME_OPTIONS, textNumInGroup), + textX, textY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d87c84f977..dc5e43c638 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23545,7 +23545,7 @@ SHC_3BB0A8C1_0x00492FC0 | 0.0% | Pending SHC_3BB0A8C1_0x00492FC4 | 0.0% | Pending -SHC_3BB0A8C1_0x00492FD0 | 0.0% | Pending +SHC_3BB0A8C1_0x00492FD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00493050 | 100.0% | Reimplemented, Security Cookie mismatches From cf7b873a30790d5e11e48159ef14574e0812223e Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 14 Nov 2026 11:18:46 +0100 Subject: [PATCH 5/6] reimplement: SHC_3BB0A8C1_0x004D8EC0 100.0% Reimplemented MenuItemActionHandler_CrusadeMap_Main, rewritten from the binary. It starts from gynt's draft (00e21e37a, 59034dfb2 and 98dc1155f on his fork's reimpl/UI-MenuItems, 33.48% there; 3d6fb54a0 at 34.80% on his reimpl/UI-MenuItems-development, his newest reimplement commit on the file) and our mechanical pass of it in #328 (2d468df23, 35.2%). reccmp 100.0 (normalized 100.0), quick_diff 215/215 at 0.9907, the rest being the timeGetTime import call, which reccmp resolves. The buttons are Skip Current Mission (1000), the lord's face for the mission briefing (10), back to the choice of crusade (11), a click on the map (1) and the rankings (99), in the original's block order with early returns. What the match needed: - Skip Current Mission repeats the setStartDateUnk call and everything after it in each trail's branch. MSVC merges the three copies into the first one, as the original has them, and the constant 1 then goes to ebp; one call after the trail branches, or a switch on the trail type, measured 0.9395 and 0.8419. - The click test reads each position as `left = x - 10` and `top = y - 10`, compared with `left + 20` and `top + 20`, which is how the original computes both bounds (0.6075 with x - 10 and x + 10). Fixes against the draft: - The first edition and extreme trails tested the click's y the wrong way round (Ghidra's `y + -clickY >= 10`, that is clickY <= y - 10, where the original tests clickY >= y - 10), so a mission could only be picked by clicking above it. - The warchest and extreme searches went one mission too far (`> 30` and `20 <`), reading one position past the end of the warchest table; the original stops below 30 and 20. Cleanup: a click wrote all three trails' progress back, two of them unchanged; the original stores only the trail being played. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../MenuItemActionHandler_CrusadeMap_Main.cpp | 191 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/CrusadeMap/MenuItemActionHandler_CrusadeMap_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/CrusadeMap/MenuItemActionHandler_CrusadeMap_Main.cpp b/src/OpenSHC/UI/MenuItems/CrusadeMap/MenuItemActionHandler_CrusadeMap_Main.cpp new file mode 100644 index 0000000000..1b4a186f50 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/CrusadeMap/MenuItemActionHandler_CrusadeMap_Main.cpp @@ -0,0 +1,191 @@ +#include "../CrusadeMap.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Audio/SFX/SoundEffectID.hpp" +#include "OpenSHC/Game/TrailType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MissionDefinedData.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_SkirmishTrailRelated1.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DWORD_00ed27a8.hpp" +#include "OpenSHC/Globals/DWORD_00ed311c.hpp" +#include "OpenSHC/Globals/INT_00eb9b48.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004D8EC0 + void CrusadeMap::MenuItemActionHandler_CrusadeMap_Main(int button, ...) + { + // Skip Current Mission: the trail's next mission is marked skipped with the chicken (-1200 months) + if (button == 1000) { + if (DAT_SkirmishTrailRelated1::instance <= 0) { + return; + } + // the trails have 50, 30 and 20 missions + if (DAT_GameCore::instance.currentTrailType == OpenSHC::Game::TT_FIRST_EDITION) { + int const mission = DAT_GameCore::instance.furthestSkirmishTrailMission; + if (mission >= countof(DAT_MissionDefinedData::instance.SkirmishTrailMissionPositions) - 1) { + return; + } + DAT_GameCore::instance.skirmishTrailProgress = mission; + if (DAT_GameCore::instance.skirmishTrailMonthsTakenOrChicken[mission] != -1) { + return; + } + DAT_GameCore::instance.skirmishTrailMonthsTakenOrChicken[mission] = -1200; + if (DAT_GameCore::instance.skirmishTrailProgress + == countof(DAT_MissionDefinedData::instance.SkirmishTrailMissionPositions) - 1) { + return; + } + ++DAT_GameCore::instance.skirmishTrailProgress; + ++DAT_GameCore::instance.furthestSkirmishTrailMission; + // this call and the code after it are repeated in each trail's branch, for the match + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::setStartDateUnk, DAT_GameCore::ptr)(1); + --DAT_SkirmishTrailRelated1::instance; + DWORD_00ed311c::instance = timeGetTime(); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setSoundWithVariation, DAT_SFXState::ptr)( + 258, 100); + return; + } + if (DAT_GameCore::instance.currentTrailType == OpenSHC::Game::TT_WARCHEST) { + int const mission = DAT_GameCore::instance.furthestWarchestTrailMission; + if (mission >= countof(DAT_MissionDefinedData::instance.WarchestTrailMissionPositions) - 1) { + return; + } + DAT_GameCore::instance.warchestTrailProgress = mission; + if (DAT_GameCore::instance.warchestTrailMonthsTakenOrChicken[mission] != -1) { + return; + } + DAT_GameCore::instance.warchestTrailMonthsTakenOrChicken[mission] = -1200; + if (DAT_GameCore::instance.warchestTrailProgress + == countof(DAT_MissionDefinedData::instance.WarchestTrailMissionPositions) - 1) { + return; + } + ++DAT_GameCore::instance.warchestTrailProgress; + ++DAT_GameCore::instance.furthestWarchestTrailMission; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::setStartDateUnk, DAT_GameCore::ptr)(2); + --DAT_SkirmishTrailRelated1::instance; + DWORD_00ed311c::instance = timeGetTime(); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setSoundWithVariation, DAT_SFXState::ptr)( + 258, 100); + return; + } + if (DAT_GameCore::instance.currentTrailType == OpenSHC::Game::TT_EXTREME) { + int const mission = DAT_GameCore::instance.furthestExtremeTrailMission; + if (mission >= 19) { + return; + } + DAT_GameCore::instance.extremeTrailProgress = mission; + if (DAT_GameCore::instance.extremeTrailMonthsTakenOrChicken[mission] != -1) { + return; + } + DAT_GameCore::instance.extremeTrailMonthsTakenOrChicken[mission] = -1200; + if (DAT_GameCore::instance.extremeTrailProgress == 19) { + return; + } + ++DAT_GameCore::instance.extremeTrailProgress; + ++DAT_GameCore::instance.furthestExtremeTrailMission; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::setStartDateUnk, DAT_GameCore::ptr)(3); + --DAT_SkirmishTrailRelated1::instance; + DWORD_00ed311c::instance = timeGetTime(); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setSoundWithVariation, DAT_SFXState::ptr)( + 258, 100); + } + return; + } + // the lord picked: his face goes into the player's face slot, then the mission briefing + if (button == 10) { + MACRO_CALL(OpenSHC::OS_Func::_memcpy)(DAT_TextureRenderCoreObject::instance.bitmapsFaces_0x94 + + (DAT_GameSynchronyState::instance.currentPlayerSlotID + 19) * 66 * 64, + DAT_TextureRenderCoreObject::instance.bitmapsFaces_0x94 + + (DAT_GameCore::instance.lordIconUnk - 2) * 66 * 64, + 66 * 64 * sizeof(ushort)); + DAT_TextureRenderCoreObject::instance + .bitmapFaceSizes[DAT_GameSynchronyState::instance.currentPlayerSlotID + 19] + = 66 * 64 * sizeof(ushort); + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_CRUSADE_MISSION_INTRO, 0); + return; + } + // back to the choice of crusade + if (button == 11) { + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_SELECT_CRUSADE, 0); + return; + } + // a click on the map picks the mission under the mouse, up to the furthest one reached + if (button == 1) { + int const clickX = DAT_MouseState::instance.screenSpaceX - DAT_ButtonX::instance; + int const clickY = DAT_MouseState::instance.screenSpaceY - DAT_ButtonY::instance; + if (DAT_GameCore::instance.currentTrailType == OpenSHC::Game::TT_FIRST_EDITION) { + for (int mission = 0; + mission < countof(DAT_MissionDefinedData::instance.SkirmishTrailMissionPositions); ++mission) { + if (mission > DAT_GameCore::instance.furthestSkirmishTrailMission) { + return; + } + int const left + = DAT_MissionDefinedData::instance.SkirmishTrailMissionPositions[mission][0] - 10; + int const top = DAT_MissionDefinedData::instance.SkirmishTrailMissionPositions[mission][1] - 10; + if (clickX >= left && clickX <= left + 20 && clickY >= top && clickY <= top + 20) { + DAT_GameCore::instance.skirmishTrailProgress = mission; + INT_00eb9b48::instance = 1; + DWORD_00ed27a8::instance = timeGetTime(); + return; + } + } + } else if (DAT_GameCore::instance.currentTrailType == OpenSHC::Game::TT_WARCHEST) { + for (int mission = 0; + mission < countof(DAT_MissionDefinedData::instance.WarchestTrailMissionPositions); ++mission) { + if (mission > DAT_GameCore::instance.furthestWarchestTrailMission) { + return; + } + int const left + = DAT_MissionDefinedData::instance.WarchestTrailMissionPositions[mission][0] - 10; + int const top = DAT_MissionDefinedData::instance.WarchestTrailMissionPositions[mission][1] - 10; + if (clickX >= left && clickX <= left + 20 && clickY >= top && clickY <= top + 20) { + DAT_GameCore::instance.warchestTrailProgress = mission; + INT_00eb9b48::instance = 1; + DWORD_00ed27a8::instance = timeGetTime(); + return; + } + } + } else if (DAT_GameCore::instance.currentTrailType == OpenSHC::Game::TT_EXTREME) { + // only the first 20 of the 30 positions are missions + for (int mission = 0; mission < 20; ++mission) { + if (mission > DAT_GameCore::instance.furthestExtremeTrailMission) { + return; + } + int const left = DAT_MissionDefinedData::instance.ExtremeTrailMissionPositions[mission][0] - 10; + int const top = DAT_MissionDefinedData::instance.ExtremeTrailMissionPositions[mission][1] - 10; + if (clickX >= left && clickX <= left + 20 && clickY >= top && clickY <= top + 20) { + DAT_GameCore::instance.extremeTrailProgress = mission; + INT_00eb9b48::instance = 1; + DWORD_00ed27a8::instance = timeGetTime(); + return; + } + } + } + return; + } + // the rankings + if (button == 99) { + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_RANKING_GAMES, 0); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, DAT_SFXState::ptr)( + OpenSHC::Audio::SFX::SEID_UNKNOWN_0xFD); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index dc5e43c638..4b94d6bc36 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -36013,7 +36013,7 @@ SHC_3BB0A8C1_0x004D8DC0 | 0.0% | Pending SHC_3BB0A8C1_0x004D8DF0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004D8EC0 | 0.0% | Pending +SHC_3BB0A8C1_0x004D8EC0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D91D0 | 100.0% | Reimplemented From b1710dbeb73fd124039a381a724d567ef54198f0 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 14 Nov 2026 12:00:47 +0100 Subject: [PATCH 6/6] reimplement: SHC_3BB0A8C1_0x00444410 100.0% Reimplemented MenuItemActionHandler_General_ToolbarButtonPressed, from gynt's draft (d2993ae82, 6e178081d, 8a2193967 and b984b98b6 on his fork's reimpl/UI-MenuItems, 65.02% there; a1c4156d5 at 67.59% and 9dc4216cd at 67.74% on his reimpl/UI-MenuItems-development, 9dc4216cd being his newest reimplement commit on the file) and our own draft in #318 (c00f64a0c at 71.40% on reimpl/batch2-development), rearranged from the binary. The function leaves #318 with this commit. reccmp 100.0 (normalized 100.0). quick_diff reads 0.8939 because it stops the original after the siege-engine case. On main the draft needed only renames to compile: buildingEntryInfos for the eight building references, unitIDSelectedCatapultOrTrebuchet and field_0x30. What the match needed: - The switch cases in the original's block order. The siege engines (with the Arab ballista) and the tunnel are plain cases that break to the code after the switch, and the three stances each make their own call (quick_diff 0.6693 -> 0.7085). - The eight building buttons each move the view to their building in their own copy of that code. MSVC merges the copies into the granary's, where the original has them, followed by the code after the switch (0.7085 -> 0.8915); one shared label puts the block after the last of them instead: reccmp 75.2 (normalized 61.3) against 100.0. - The tunnel button tests for no tunneler first. Fixes against the draft: - With one catapult or trebuchet selected and under 10 stone, the original only plays the lack-of-stone sound; the draft queued the command anyway. - After queueing the command for one engine or for the selection, the original returns; the draft went on to clear the patrol button and mark an engineer as selected. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...onHandler_General_ToolbarButtonPressed.cpp | 427 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 428 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/General/MenuItemActionHandler_General_ToolbarButtonPressed.cpp diff --git a/src/OpenSHC/UI/MenuItems/General/MenuItemActionHandler_General_ToolbarButtonPressed.cpp b/src/OpenSHC/UI/MenuItems/General/MenuItemActionHandler_General_ToolbarButtonPressed.cpp new file mode 100644 index 0000000000..72aec10bf8 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/General/MenuItemActionHandler_General_ToolbarButtonPressed.cpp @@ -0,0 +1,427 @@ +#include "../General.func.hpp" + +#include "OpenSHC/Audio/MissingResourceState.func.hpp" +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Game.func.hpp" +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/Audio/SFX/ResourceLackSFX.hpp" +#include "OpenSHC/Audio/SFX/SoundEffectID.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Game/Resources/ResourceType.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/DAT_00b96110.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MissingResourceState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_StopHandlingMenuItems.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + using OpenSHC::Commands::MappersEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00444410 + void General::MenuItemActionHandler_General_ToolbarButtonPressed(MappersEnum buttonID) + { + if (DAT_GameSynchronyState::instance.syncStatus != 0) { + return; + } + if (DAT_GameSynchronyState::instance.saveRelated != 0) { + return; + } + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + != 0) { + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SOLITARY) { + return; + } + if (DAT_GameState::instance.mapAndTime.gameOver + != DAT_GameSynchronyState::instance.currentPlayerSlotID) { + return; + } + } + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .lordKilledByPlayerID + != 0) { + return; + } + if (DAT_GameCore::instance.gamePausedLogical != 0) { + return; + } + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CRUSADER_TUTORIAL) { + if (!MACRO_CALL(OpenSHC::Game_Func::Tutorial_IsActionAllowed)(1, + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(buttonID))) { + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTutorialHintActiveWithTimestamp)(); + return; + } + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTutorialBuildingActionState)(6, + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(buttonID)); + } + DAT_00b96110::instance = 0; + // cases in the original's block order, for the match + switch (buttonID) { + case OpenSHC::Commands::M_MAPPER_WALL: + case OpenSHC::Commands::M_MAPPER_CRENAL: + case OpenSHC::Commands::M_MAPPER_STAIR: + case OpenSHC::Commands::M_MAPPER_WOODWALL: + if (MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::getWallTilesThatCanBeBuilt, DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, OpenSHC::Game::Resources::RT_STONE) + == 0) { + MACRO_CALL_MEMBER(OpenSHC::Audio::MissingResourceState_Func::playResourceLackSFX, + DAT_MissingResourceState::ptr)(1, OpenSHC::Audio::SFX::RLSFX_STONE); + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_NULL; + return; + } + break; + case OpenSHC::Commands::M_MAPPER_DELETE: + DAT_TileMapState::instance.placementOnWall = 0; + break; + case OpenSHC::Commands::M_MAPPER_MOAT: + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_EDITOR + || DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SIEGE_THAT) { + buttonID = OpenSHC::Commands::M_MAPPER_DUGMOAT; + } + break; + case OpenSHC::Commands::M_MAPPER_ANTIMOAT: + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_EDITOR + || DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SIEGE_THAT) { + buttonID = OpenSHC::Commands::M_MAPPER_UNDUGMOAT; + } + break; + case OpenSHC::Commands::M_MAPPER_TOTEST: + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_MAP_EDITOR_LANDSCAPING, 0); + return; + case OpenSHC::Commands::M_MAPPER_PATROL: + if (MACRO_CALL_MEMBER( + OpenSHC::Map::Units::UnitsState_Func::getUnitTypeOfFirstSelectedUnit, DAT_UnitsState::ptr)() + == OpenSHC::Map::Units::UT_INVALID) { + return; + } + if (DAT_TribesState::instance.patrolButtonPressed) { + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTribesPatrolButtonPressed)(FALSE); + DAT_TribesState::instance.rallyCount = 1; + return; + } + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTribesPatrolButtonPressed)(TRUE); + DAT_TribesState::instance.rallyCount = 1; + return; + // each building case has its own copy; MSVC merges them into the first, as the original has it + case OpenSHC::Commands::M_MAPPER_GRANARY: { + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::validateBuildingCategoryReference, DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, OpenSHC::Game::Player::Enums::BEIE_GRANARY); + int const buildingID + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_GRANARY] + .id; + if (buildingID != 0 + && DAT_BuildingsState::instance.buildings[buildingID].surfaceAreaUnk + != DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight + * DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, + DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].x + 1, + DAT_BuildingsState::instance.buildings[buildingID].y + 1); + } + break; + } + case OpenSHC::Commands::M_MAPPER_STORES: { + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::validateBuildingCategoryReference, DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, OpenSHC::Game::Player::Enums::BEIE_STOCKPILE); + int const buildingID + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_STOCKPILE] + .id; + if (buildingID != 0 + && DAT_BuildingsState::instance.buildings[buildingID].surfaceAreaUnk + != DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight + * DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, + DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].x + 1, + DAT_BuildingsState::instance.buildings[buildingID].y + 1); + } + break; + } + case OpenSHC::Commands::M_MAPPER_ARMOURY: { + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::validateBuildingCategoryReference, DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, OpenSHC::Game::Player::Enums::BEIE_ARMORY); + int const buildingID + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_ARMORY] + .id; + if (buildingID != 0 + && DAT_BuildingsState::instance.buildings[buildingID].surfaceAreaUnk + != DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight + * DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, + DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].x + 1, + DAT_BuildingsState::instance.buildings[buildingID].y + 1); + } + break; + } + case OpenSHC::Commands::M_MAPPER_BARRACKS_EURO: { + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::validateBuildingCategoryReference, + DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + OpenSHC::Game::Player::Enums::BEIE_MERCENARYPOST); + int const buildingID + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_MERCENARYPOST] + .id; + if (buildingID != 0 + && DAT_BuildingsState::instance.buildings[buildingID].surfaceAreaUnk + != DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight + * DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, + DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].x + 1, + DAT_BuildingsState::instance.buildings[buildingID].y + 1); + } + break; + } + case OpenSHC::Commands::M_MAPPER_BARRACKS_ARAB: { + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::validateBuildingCategoryReference, DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, OpenSHC::Game::Player::Enums::BEIE_BARRACKS); + int const buildingID + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_BARRACKS] + .id; + if (buildingID != 0 + && DAT_BuildingsState::instance.buildings[buildingID].surfaceAreaUnk + != DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight + * DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, + DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].x + 1, + DAT_BuildingsState::instance.buildings[buildingID].y + 1); + } + break; + } + case OpenSHC::Commands::M_MAPPER_ENGINEERS_GUILD: { + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::validateBuildingCategoryReference, + DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + OpenSHC::Game::Player::Enums::BEIE_ENGINEERSGUILD); + int const buildingID + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_ENGINEERSGUILD] + .id; + if (buildingID != 0 + && DAT_BuildingsState::instance.buildings[buildingID].surfaceAreaUnk + != DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight + * DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, + DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].x + 1, + DAT_BuildingsState::instance.buildings[buildingID].y + 1); + } + break; + } + case OpenSHC::Commands::M_MAPPER_TUNNELERS_GUILD: { + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::validateBuildingCategoryReference, + DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + OpenSHC::Game::Player::Enums::BEIE_TUNNELERSGUILD); + int const buildingID + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_TUNNELERSGUILD] + .id; + if (buildingID != 0 + && DAT_BuildingsState::instance.buildings[buildingID].surfaceAreaUnk + != DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight + * DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, + DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].x + 1, + DAT_BuildingsState::instance.buildings[buildingID].y + 1); + } + break; + } + case OpenSHC::Commands::M_MAPPER_TRADEPOST: { + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::validateBuildingCategoryReference, + DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + OpenSHC::Game::Player::Enums::BEIE_MARKETPLACE); + int const buildingID + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_MARKETPLACE] + .id; + if (buildingID != 0 + && DAT_BuildingsState::instance.buildings[buildingID].surfaceAreaUnk + != DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight + * DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, + DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].x + 1, + DAT_BuildingsState::instance.buildings[buildingID].y + 1); + } + break; + } + case OpenSHC::Commands::M_MAPPER_HEADS: + DAT_TileMapState::instance.decorationVariantIndex = SEC_RNG::instance.currentNumber1 % 7; + MACRO_CALL_MEMBER(OpenSHC::Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); + break; + case OpenSHC::Commands::M_MAPPER_TUNNEL_CONSTRUCTION: + if (!MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::getTunnelerIDOnlyIfFirstSelected, + DAT_UnitsState::ptr)()) { + DAT_StopHandlingMenuItems::instance = 0; + return; + } + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTribesPatrolButtonPressed)(FALSE); + break; + case OpenSHC::Commands::M_MAPPER_GATE_WOOD1A: + case OpenSHC::Commands::M_MAPPER_GATE_WOOD1B: + case OpenSHC::Commands::M_MAPPER_GATE_WOOD1C: + case OpenSHC::Commands::M_MAPPER_GATE_WOOD1D: + buttonID = (MappersEnum)((DAT_TileMapState::instance.mapOrientation / 2 + - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A + buttonID) + % 4 + + OpenSHC::Commands::M_MAPPER_GATE_WOOD1A); + break; + case OpenSHC::Commands::M_MAPPER_GATE_STONE1A: + case OpenSHC::Commands::M_MAPPER_GATE_STONE1B: + buttonID = (MappersEnum)(((DAT_TileMapState::instance.mapOrientation / 2 + buttonID) & 1) + + OpenSHC::Commands::M_MAPPER_GATE_STONE1A); + break; + case OpenSHC::Commands::M_MAPPER_GATE_STONE2A: + case OpenSHC::Commands::M_MAPPER_GATE_STONE2B: + buttonID = (MappersEnum)(((DAT_TileMapState::instance.mapOrientation / 2 + buttonID) & 1) + + OpenSHC::Commands::M_MAPPER_GATE_STONE2A); + break; + case OpenSHC::Commands::M_MAPPER_STANCE_STAND: + MACRO_CALL_MEMBER(OpenSHC::Map::Units::TribesState_Func::queueUnitStance, DAT_TribesState::ptr)( + DAT_TribesState::instance.DAT_CurrentTribeID, 0); + return; + case OpenSHC::Commands::M_MAPPER_STANCE_DEFENSIVE: + MACRO_CALL_MEMBER(OpenSHC::Map::Units::TribesState_Func::queueUnitStance, DAT_TribesState::ptr)( + DAT_TribesState::instance.DAT_CurrentTribeID, 1); + return; + case OpenSHC::Commands::M_MAPPER_STANCE_AGGRESSIVE: + MACRO_CALL_MEMBER(OpenSHC::Map::Units::TribesState_Func::queueUnitStance, DAT_TribesState::ptr)( + DAT_TribesState::instance.DAT_CurrentTribeID, 2); + return; + case OpenSHC::Commands::M_MAPPER_CATAPULT: + case OpenSHC::Commands::M_MAPPER_TREBUCHET: + case OpenSHC::Commands::M_MAPPER_SIEGE_TOWER: + case OpenSHC::Commands::M_MAPPER_BATTERING_RAM: + case OpenSHC::Commands::M_MAPPER_PORTABLE_SHIELD: + case OpenSHC::Commands::M_MAPPER_ARAB_BALLISTA: + if (MACRO_CALL_MEMBER( + OpenSHC::Map::Units::UnitsState_Func::returnFirstSelectedEngineer, DAT_UnitsState::ptr)()) { + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTribesPatrolButtonPressed)(FALSE); + break; + } + DAT_StopHandlingMenuItems::instance = 0; + return; + case OpenSHC::Commands::M_MAPPER_ENGINEER_BUILD: + if (!MACRO_CALL_MEMBER( + OpenSHC::Map::Units::UnitsState_Func::returnFirstSelectedEngineer, DAT_UnitsState::ptr)()) { + int const siegeEngines + = MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::countSelectedCatapultsAndTrebuchets, + DAT_UnitsState::ptr)(); + if (siegeEngines == 0) { + DAT_StopHandlingMenuItems::instance = 0; + return; + } + if (siegeEngines == 1) { + // one catapult or trebuchet: the command needs 10 stone + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[OpenSHC::Game::Resources::RT_STONE] + < 10) { + MACRO_CALL_MEMBER(OpenSHC::Audio::MissingResourceState_Func::playResourceLackSFX, + DAT_MissingResourceState::ptr)(1, OpenSHC::Audio::SFX::RLSFX_STONE); + return; + } + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 + = DAT_UnitsState::instance.unitIDSelectedCatapultOrTrebuchet; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_UNKNOWN_86); + return; + } + if (siegeEngines == 2) { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 + = DAT_TribesState::instance.DAT_CurrentTribeID; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = 1; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_UNKNOWN_86); + return; + } + } + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTribesPatrolButtonPressed)(FALSE); + DAT_UnitsState::instance.hasEngineerSelected = TRUE; + return; + case OpenSHC::Commands::M_MAPPER_BUILD_BACK: + DAT_UnitsState::instance.hasEngineerSelected = FALSE; + return; + } + if (MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(buttonID) + != OpenSHC::Map::Buildings::BT_NONE) { + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::checkRequiredResourcesForBuildingOrPlanToBuy, + DAT_GameState::ptr)(buttonID, DAT_GameSynchronyState::instance.currentPlayerSlotID, TRUE); + } + DAT_TileMapState::instance.currentMapperCommand = buttonID; + DAT_TileMapState::instance.unitPlacementCount = 1; + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, DAT_SFXState::ptr)( + OpenSHC::Audio::SFX::SEID_UNKNOWN_0x87); + if (buttonID != OpenSHC::Commands::M_MAPPER_CATAPULT + && buttonID != OpenSHC::Commands::M_MAPPER_ARAB_BALLISTA + && buttonID != OpenSHC::Commands::M_MAPPER_TREBUCHET + && buttonID != OpenSHC::Commands::M_MAPPER_SIEGE_TOWER + && buttonID != OpenSHC::Commands::M_MAPPER_BATTERING_RAM + && buttonID != OpenSHC::Commands::M_MAPPER_PORTABLE_SHIELD + && buttonID != OpenSHC::Commands::M_MAPPER_TUNNEL_CONSTRUCTION + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT1 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT2 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT3 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT4 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT5 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT6 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINT7 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM1 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM2 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM3 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM4 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM5 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM6 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTM7 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTE1 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTE2 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTT1 + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_PLACE_ASSEMBLY_POINTK1 + && DAT_GameCore::instance.activeMenuTab.tabType != DAT_GameCore::instance.field_0x30) { + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType = DAT_GameCore::instance.field_0x30; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_BUILD_MENU, 0); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 4b94d6bc36..fe9d919a55 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -14869,7 +14869,7 @@ SHC_3BB0A8C1_0x0044440A | 0.0% | Pending SHC_3BB0A8C1_0x0044440B | 0.0% | Pending -SHC_3BB0A8C1_0x00444410 | 0.0% | Pending +SHC_3BB0A8C1_0x00444410 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00444A14 | 0.0% | Pending