From ea60207ff3a3f9b6748054e2a7659663b7529f08 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:09:52 +0100 Subject: [PATCH 1/6] reimplement: SHC_3BB0A8C1_0x004BFFA0 87.6% MenuItemRenderFunction_General_EventButtonAndData, register allocation differs Taken from draft #530 with the style pass applied. Measured on main 592a17d94 with the four files of this PR in .local, both resolver sets enabled, full build and reccmp. Style: itemIndex instead of param_1, named const text position, COL_C2F0EB/COL_CCFAFF, decimal literals, no redundant cast or unused usings. The only remaining difference is how the colour argument reaches the call: the original pushes the colour immediate in each arm, with the three constant pushes before it hoisted above the branch, while ours keeps the colour in edx and pushes all four after the arms join. The values, the argument order and the call are the same. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...derFunction_General_EventButtonAndData.cpp | 57 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_EventButtonAndData.cpp diff --git a/src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_EventButtonAndData.cpp b/src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_EventButtonAndData.cpp new file mode 100644 index 0000000000..8f0fe73b29 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_EventButtonAndData.cpp @@ -0,0 +1,57 @@ +#include "../General.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Rendering/Colors/BGR24.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + using OpenSHC::Rendering::Colors::BGR24; + + // FUNCTION: STRONGHOLDCRUSADER 0x004BFFA0 + void General::MenuItemRenderFunction_General_EventButtonAndData(int itemIndex, ...) + { + int month; + BGR24 color; + if (itemIndex != -1) { + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderScenarioButtonWithText)(itemIndex); + return; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + int const textX = DAT_ButtonW::instance / 2 + DAT_ButtonX::instance; + int const textY = DAT_ButtonY::instance + 6; + if (!DAT_ButtonCurrentlyInteracting::instance) { + month = DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .header.month; + color = OpenSHC::Rendering::Colors::COL_C2F0EB; + } else { + month = DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .header.month; + color = OpenSHC::Rendering::Colors::COL_CCFAFF; + } + 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_MONTHS, month + 12), + textX, textY, OpenSHC::Text::TTA_CENTER, color, 18, FALSE, 0); + } + + } // namespace MenuItems +} // namespace UI +} // namespace OpenSHC diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b31ea5fc2b..d07c530b91 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -32107,7 +32107,7 @@ SHC_3BB0A8C1_0x004BFE13 | 0.0% | Pending SHC_3BB0A8C1_0x004BFE20 | 0.0% | Pending -SHC_3BB0A8C1_0x004BFFA0 | 0.0% | Pending +SHC_3BB0A8C1_0x004BFFA0 | 87.6% | Register allocation differs SHC_3BB0A8C1_0x004C0040 | 100.0% | Reimplemented, only the atol call target differs From 1984abb2eb98b236bdc2a19de1b2d6dfef91c82d Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:09:53 +0100 Subject: [PATCH 2/6] reimplement: SHC_3BB0A8C1_0x004AEF70 97.2% MenuItemRenderFunction_Roundtable_Main, register allocation differs Taken from draft #530 with the style pass applied. Measured on main 592a17d94 with the four files of this PR in .local, both resolver sets enabled, full build and reccmp. Style: itemIndex instead of param_1, decimal literals, no unused usings. The only remaining differences are allocation ones: the two waiting-room text index loads (currentAIArray and aiVariationArray) are loaded in the other order into other registers, and the base/index registers of the 9*ai + variation + 231 lea differ. The code is one byte shorter, which moves branch offsets; reccmp's trailing +ret is an artefact of it cutting the original at our length. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...MenuItemRenderFunction_Roundtable_Main.cpp | 241 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/Roundtable/MenuItemRenderFunction_Roundtable_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/Roundtable/MenuItemRenderFunction_Roundtable_Main.cpp b/src/OpenSHC/UI/MenuItems/Roundtable/MenuItemRenderFunction_Roundtable_Main.cpp new file mode 100644 index 0000000000..ecb47338c9 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/Roundtable/MenuItemRenderFunction_Roundtable_Main.cpp @@ -0,0 +1,241 @@ +#include "../Roundtable.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/MenuItems/General.func.hpp" +#include "OpenSHC/UI/Rendering.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/IO/Graphics/GmID.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_00df423c.hpp" +#include "OpenSHC/Globals/DAT_00df4288.hpp" +#include "OpenSHC/Globals/DAT_BlendingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ButtonBackgroundBlendStrength.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.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_MouseState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_RenderingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004AEF70 + void Roundtable::MenuItemRenderFunction_Roundtable_Main(int itemIndex, ...) + { + int aiType = 0; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + if (itemIndex <= 8) { + int const playerID = DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[itemIndex]; + if (playerID <= 0) { + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + int const group = DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[playerID]; + DAT_ButtonUnknownZero::instance = 1; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] != -1 + || DAT_GameSynchronyState::instance.currentAIArray[playerID] != 0) { + if (DAT_GameSynchronyState::instance.isHost) { + DAT_ButtonUnknownZero::instance = 0; + } + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] == -1) { + aiType = DAT_GameSynchronyState::instance.currentAIArray[playerID]; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, playerID + 546, + DAT_ButtonX::instance, DAT_ButtonY::instance); + if (aiType == 0) { + if (DAT_GameCore::instance.lordIcons[playerID] == 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, 539, + DAT_ButtonX::instance, DAT_ButtonY::instance); + } else if (DAT_GameCore::instance.lordIcons[playerID] == 1) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, 540, + DAT_ButtonX::instance, DAT_ButtonY::instance); + } else if (DAT_TextureRenderCoreObject::instance.bitmapFaceSizes[playerID + 19] > 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, 541, + DAT_ButtonX::instance, DAT_ButtonY::instance); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::drawBitmapFace, + DAT_TextureRenderCoreObject::ptr)( + playerID + 19, DAT_ButtonX::instance + 4, DAT_ButtonY::instance + 4); + } + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, aiType + 522, + DAT_ButtonX::instance, DAT_ButtonY::instance); + } + if (DAT_00df423c::instance == itemIndex) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::dimBox, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonX::instance + 71, DAT_ButtonY::instance + 71); + } + if (DAT_ButtonCurrentlyInteracting::instance) { + if (DAT_00df423c::instance == 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 514, + DAT_ButtonX::instance - 6, DAT_ButtonY::instance - 6, + OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 513, 0); + } + if (DAT_ButtonCurrentlyInteracting::instance) { + DAT_00df4288::instance = 1; + } + } + if (group != 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, group * 2 + 493, + DAT_ButtonX::instance - 10, DAT_ButtonY::instance - 8); + } + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] != -1) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, + DAT_TextManagerObject::ptr)(DAT_GameSynchronyState::instance.DAT_PlayerNames[playerID], + DAT_ButtonX::instance + 32, DAT_ButtonY::instance + 80, OpenSHC::Text::TTA_CENTER, + DAT_RenderingDefinedData::instance + .ColorTable1[DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[playerID]], + 0, 19, FALSE, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + 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_XPLAY_WAITING_ROOM, + DAT_GameSynchronyState::instance.currentAIArray[playerID] * 9 + 231 + + DAT_GameSynchronyState::instance.aiVariationArray[playerID]), + DAT_ButtonX::instance + 32, DAT_ButtonY::instance + 80, OpenSHC::Text::TTA_CENTER, + DAT_RenderingDefinedData::instance + .ColorTable1[DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[playerID]], + 0, 18, FALSE, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + } else { + if (itemIndex <= 18) { + int const playerID = DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[itemIndex - 10]; + if (playerID > 0 && DAT_00df423c::instance != 0 && DAT_ButtonCurrentlyInteracting::instance + && itemIndex - 10 != DAT_00df423c::instance + && (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] != -1 + || MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::isAIPlayer, + DAT_GameSynchronyState::ptr)(playerID))) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 514, + DAT_ButtonX::instance + 62, DAT_ButtonY::instance - 1, + OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 513, 0); + } + } + if (itemIndex == 20) { + if (DAT_ButtonCurrentlyInteracting::instance) { + DAT_00df4288::instance = 1; + if (DAT_00df423c::instance == 0) { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + } + } + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderCurrentButtonToScreenMenuWithBlendingUnk)( + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + if (itemIndex == 100 || itemIndex == 101) { + DAT_ButtonUnknownZero::instance = DAT_00df423c::instance != 0; + if (DAT_GameSynchronyState::instance.isHost) { + MACRO_CALL(OpenSHC::UI::MenuItems::General_Func:: + MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface)(); + if (DAT_ButtonCurrentlyInteracting::instance) { + DAT_00df4288::instance = 1; + } + } else { + DAT_ButtonUnknownZero::instance = 1; + } + } + if (itemIndex == 200) { + aiType = 0; + if (DAT_00df423c::instance != 0 && DAT_GameSynchronyState::instance.isHost) { + if (DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[DAT_00df423c::instance] == 0) { + DAT_00df423c::instance = 0; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + int const playerID + = DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[DAT_00df423c::instance]; + if (playerID >= 1) { + int x = DAT_MouseState::instance.screenSpaceX + - DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth; + int y = DAT_MouseState::instance.screenSpaceY + - DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight; + if (y < 4) { + y = 4; + } else if (y > 364) { + y = 364; + } + if (x < 4) { + x = 4; + } else if (x > 724) { + x = 724; + } + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] == -1) { + aiType = DAT_GameSynchronyState::instance.currentAIArray[playerID]; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, + playerID + 546, DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + x, + DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight + y); + if (aiType == 0) { + if (DAT_GameCore::instance.lordIcons[playerID] == 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, 539, + DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + x, + DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight + y); + } else if (DAT_GameCore::instance.lordIcons[playerID] == 1) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, 540, + DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + x, + DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight + y); + } else if (DAT_TextureRenderCoreObject::instance.bitmapFaceSizes[playerID + 19] > 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, 541, + DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + x, + DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight + y); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::drawBitmapFace, + DAT_TextureRenderCoreObject::ptr)(playerID + 19, + DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + x + 4, + DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight + y + 4); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, + aiType + 522, DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + x, + DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight + y); + } + } + } + } + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + } + + } // namespace MenuItems +} // namespace UI +} // namespace OpenSHC diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d07c530b91..1cafc77814 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -25897,7 +25897,7 @@ SHC_3BB0A8C1_0x004AEF5C | 0.0% | Pending SHC_3BB0A8C1_0x004AEF60 | 0.0% | Pending -SHC_3BB0A8C1_0x004AEF70 | 0.0% | Pending +SHC_3BB0A8C1_0x004AEF70 | 97.2% | Register allocation differs SHC_3BB0A8C1_0x004AF4C0 | 100.0% | Reimplemented From 90a27ce61d1458cc3aa4efb5b015aa1a8ee7b38c Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:09:53 +0100 Subject: [PATCH 3/6] reimplement: SHC_3BB0A8C1_0x004940B0 86.6% MenuItemActionHandler_SoundOptions_Buttons, register allocation differs Taken from draft #530 with the style pass applied. Measured on main 592a17d94 with the four files of this PR in .local, both resolver sets enabled, full build and reccmp. Style: clickType instead of param_1, minValue/maxValue instead of local_4/local_8, BOOLEnum for the genie toggle, comment on the parameter slot reuse. The only remaining differences are allocation ones: the original holds the zero for the sound toggle in eax (xor eax, eax) where ours uses immediates, and the two VolumeSlider out-locals swap stack slots. The jump table entries move by the resulting size difference. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...ItemActionHandler_SoundOptions_Buttons.cpp | 75 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_Buttons.cpp diff --git a/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_Buttons.cpp b/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_Buttons.cpp new file mode 100644 index 0000000000..9bc1aa1fc0 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_Buttons.cpp @@ -0,0 +1,75 @@ +#include "../SoundOptions.func.hpp" + +#include "OpenSHC/Audio/MSS/SoundSystem.func.hpp" +#include "OpenSHC/UI/MenuItems/SoundOptions.func.hpp" +#include "OpenSHC/UI/MenuTextInputState.func.hpp" +#include "OpenSHC/UI/Enums/SoundMenuClickType.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + using OpenSHC::UI::Enums::SoundMenuClickType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004940B0 + void SoundOptions::MenuItemActionHandler_SoundOptions_Buttons(SoundMenuClickType clickType, ...) + { + switch (clickType) { + case OpenSHC::UI::Enums::SMCT_TOGGLE_SOUND_ACTIVEUnk: + if (DAT_MenuTextInputState::instance.DAT_SoundActiveMenuVar != 0) { + DAT_MenuTextInputState::instance.DAT_SoundActiveMenuVar = 0; + MACRO_CALL_MEMBER(OpenSHC::Audio::MSS::SoundSystem_Func::deactivateSoundFromMenuFuncUnk, + DAT_SoundSystemState::ptr)(); + return; + } + DAT_MenuTextInputState::instance.DAT_SoundActiveMenuVar = 1; + MACRO_CALL_MEMBER( + OpenSHC::Audio::MSS::SoundSystem_Func::activateSoundFromMenuFuncUnk, DAT_SoundSystemState::ptr)(); + return; + case OpenSHC::UI::Enums::SMCT_TOGGLE_GENIE: { + OpenSHC::WindowsHelper::Enums::BOOLEnum genieVoiceActive = FALSE; + if (DAT_MenuTextInputState::instance.DAT_GenieVoiceActiveMenuVar == 0) { + genieVoiceActive = TRUE; + } + DAT_MenuTextInputState::instance.DAT_GenieVoiceActiveMenuVar = genieVoiceActive; + DAT_GameCore::instance.genieVoiceActive = genieVoiceActive; + return; + } + case OpenSHC::UI::Enums::SMCT_SOUND_MENU_RETURNUnk: + MACRO_CALL_MEMBER(OpenSHC::UI::MenuTextInputState_Func::popModalDialog, DAT_MenuTextInputState::ptr)(); + return; + case OpenSHC::UI::Enums::SMCT_RESET_MUSIC_VOLUME: { + // The default volume goes through the parameter's own stack slot, as in the original. + int maxValue; + int minValue; + clickType = (SoundMenuClickType)90; + MACRO_CALL(OpenSHC::UI::MenuItems::SoundOptions_Func::MenuItemActionHandler_SoundOptions_VolumeSlider)( + 0, 3, &minValue, &maxValue, (int*)&clickType); + return; + } + case OpenSHC::UI::Enums::SMCT_RESET_SFX_VOLUME: { + int maxValue; + int minValue; + clickType = (SoundMenuClickType)80; + MACRO_CALL(OpenSHC::UI::MenuItems::SoundOptions_Func::MenuItemActionHandler_SoundOptions_VolumeSlider)( + 1, 3, &minValue, &maxValue, (int*)&clickType); + return; + } + case OpenSHC::UI::Enums::SMCT_RESET_SPEECH_VOLUME: { + int maxValue; + int minValue; + clickType = (SoundMenuClickType)85; + MACRO_CALL(OpenSHC::UI::MenuItems::SoundOptions_Func::MenuItemActionHandler_SoundOptions_VolumeSlider)( + 2, 3, &minValue, &maxValue, (int*)&clickType); + return; + } + } + } + + } // namespace MenuItems +} // namespace UI +} // namespace OpenSHC diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1cafc77814..473b6e94ae 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23935,7 +23935,7 @@ SHC_3BB0A8C1_0x004940A9 | 0.0% | Pending SHC_3BB0A8C1_0x004940AA | 0.0% | Pending -SHC_3BB0A8C1_0x004940B0 | 0.0% | Pending +SHC_3BB0A8C1_0x004940B0 | 86.6% | Register allocation differs SHC_3BB0A8C1_0x004941A0 | 0.0% | Pending From b8f9ba483e65929ff3c355d3003096738f505b93 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:09:53 +0100 Subject: [PATCH 4/6] reimplement: SHC_3BB0A8C1_0x0045EF90 82.4% MenuItemRenderFunction_TextEditor_Scrollbar, register allocation differs Taken from draft #530 with the style pass applied. Measured on main 592a17d94 with the four files of this PR in .local, both resolver sets enabled, full build and reccmp. Style: += for the bottom edge. The only remaining differences are allocation ones: y and x+20 live in other callee-saved registers (edi/ebp swapped), and ours computes top = y - 22 into ebx before the first call where the original computes it after the second; the value and every use are the same. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...temRenderFunction_TextEditor_Scrollbar.cpp | 44 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/TextEditor/MenuItemRenderFunction_TextEditor_Scrollbar.cpp diff --git a/src/OpenSHC/UI/MenuItems/TextEditor/MenuItemRenderFunction_TextEditor_Scrollbar.cpp b/src/OpenSHC/UI/MenuItems/TextEditor/MenuItemRenderFunction_TextEditor_Scrollbar.cpp new file mode 100644 index 0000000000..7278be8fc0 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/TextEditor/MenuItemRenderFunction_TextEditor_Scrollbar.cpp @@ -0,0 +1,44 @@ +#include "../TextEditor.func.hpp" + +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" + +#include "OpenSHC/Globals/COL_VERY_SOFT_YELLOW.hpp" +#include "OpenSHC/Globals/DAT_ButtonH.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x0045EF90 + void TextEditor::MenuItemRenderFunction_TextEditor_Scrollbar( + int param_1, int thumbYPos, int param_3, int thumbHeight, BOOLEnum isDragged) + { + int const height = DAT_ButtonH::instance; + int const y = DAT_ButtonY::instance; + int const x = DAT_ButtonX::instance; + int const top = y - 22; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawScrollbar, DAT_PencilRenderCore::ptr)( + x, y, height, thumbYPos, isDragged, thumbHeight, 0); + int const right = x + 20; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x, y - 1, right - 1, y - 1, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x, top, right - 1, top, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + int bottom = y + height; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x, bottom, right - 1, bottom, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + bottom += 21; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x, bottom, right - 1, bottom, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + x - 1, top, x - 1, bottom, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + right, top, right, bottom, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + } + + } // namespace MenuItems +} // namespace UI +} // namespace OpenSHC diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 473b6e94ae..1e991e26a4 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -18707,7 +18707,7 @@ SHC_3BB0A8C1_0x0045EF80 | 0.0% | Pending SHC_3BB0A8C1_0x0045EF84 | 0.0% | Pending -SHC_3BB0A8C1_0x0045EF90 | 0.0% | Pending +SHC_3BB0A8C1_0x0045EF90 | 82.4% | Register allocation differs SHC_3BB0A8C1_0x0045F080 | 100.0% | Reimplemented From f8f25cafcd4db9df0988734e998d6a28b8ffc36a Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 16:52:26 +0100 Subject: [PATCH 5/6] review: pre-review pass on the #530 functions - SoundOptions_Buttons: the reset-volume cases pass their own currentValue local instead of reusing the click-type parameter's slot through an enum cast, the comment explaining that form is gone, and the genie toggle tests the flag by truthiness. Re-measured on main 592a17d94 with a full build and reccmp, unchanged: 87.6 / 97.2 / 86.6 / 82.4, all still register allocation only. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- ...MenuItemActionHandler_SoundOptions_Buttons.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_Buttons.cpp b/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_Buttons.cpp index 9bc1aa1fc0..371202a4fc 100644 --- a/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_Buttons.cpp +++ b/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_Buttons.cpp @@ -32,7 +32,7 @@ namespace UI { return; case OpenSHC::UI::Enums::SMCT_TOGGLE_GENIE: { OpenSHC::WindowsHelper::Enums::BOOLEnum genieVoiceActive = FALSE; - if (DAT_MenuTextInputState::instance.DAT_GenieVoiceActiveMenuVar == 0) { + if (!DAT_MenuTextInputState::instance.DAT_GenieVoiceActiveMenuVar) { genieVoiceActive = TRUE; } DAT_MenuTextInputState::instance.DAT_GenieVoiceActiveMenuVar = genieVoiceActive; @@ -43,28 +43,27 @@ namespace UI { MACRO_CALL_MEMBER(OpenSHC::UI::MenuTextInputState_Func::popModalDialog, DAT_MenuTextInputState::ptr)(); return; case OpenSHC::UI::Enums::SMCT_RESET_MUSIC_VOLUME: { - // The default volume goes through the parameter's own stack slot, as in the original. int maxValue; int minValue; - clickType = (SoundMenuClickType)90; + int currentValue = 90; MACRO_CALL(OpenSHC::UI::MenuItems::SoundOptions_Func::MenuItemActionHandler_SoundOptions_VolumeSlider)( - 0, 3, &minValue, &maxValue, (int*)&clickType); + 0, 3, &minValue, &maxValue, ¤tValue); return; } case OpenSHC::UI::Enums::SMCT_RESET_SFX_VOLUME: { int maxValue; int minValue; - clickType = (SoundMenuClickType)80; + int currentValue = 80; MACRO_CALL(OpenSHC::UI::MenuItems::SoundOptions_Func::MenuItemActionHandler_SoundOptions_VolumeSlider)( - 1, 3, &minValue, &maxValue, (int*)&clickType); + 1, 3, &minValue, &maxValue, ¤tValue); return; } case OpenSHC::UI::Enums::SMCT_RESET_SPEECH_VOLUME: { int maxValue; int minValue; - clickType = (SoundMenuClickType)85; + int currentValue = 85; MACRO_CALL(OpenSHC::UI::MenuItems::SoundOptions_Func::MenuItemActionHandler_SoundOptions_VolumeSlider)( - 2, 3, &minValue, &maxValue, (int*)&clickType); + 2, 3, &minValue, &maxValue, ¤tValue); return; } } From 27a6892591b3ff13c83413968e688302ca7230a7 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 23:39:35 +0100 Subject: [PATCH 6/6] review: drop redundant casts Each removed cast leaves the generated code and the warnings unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../MenuItemRenderFunction_TextEditor_Scrollbar.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OpenSHC/UI/MenuItems/TextEditor/MenuItemRenderFunction_TextEditor_Scrollbar.cpp b/src/OpenSHC/UI/MenuItems/TextEditor/MenuItemRenderFunction_TextEditor_Scrollbar.cpp index 7278be8fc0..31d9a9cd0b 100644 --- a/src/OpenSHC/UI/MenuItems/TextEditor/MenuItemRenderFunction_TextEditor_Scrollbar.cpp +++ b/src/OpenSHC/UI/MenuItems/TextEditor/MenuItemRenderFunction_TextEditor_Scrollbar.cpp @@ -24,19 +24,19 @@ namespace UI { x, y, height, thumbYPos, isDragged, thumbHeight, 0); int const right = x + 20; MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - x, y - 1, right - 1, y - 1, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + x, y - 1, right - 1, y - 1, COL_VERY_SOFT_YELLOW::instance.shortValue); MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - x, top, right - 1, top, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + x, top, right - 1, top, COL_VERY_SOFT_YELLOW::instance.shortValue); int bottom = y + height; MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - x, bottom, right - 1, bottom, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + x, bottom, right - 1, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); bottom += 21; MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - x, bottom, right - 1, bottom, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + x, bottom, right - 1, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - x - 1, top, x - 1, bottom, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + x - 1, top, x - 1, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - right, top, right, bottom, (ushort)(COL_VERY_SOFT_YELLOW::instance.shortValue)); + right, top, right, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); } } // namespace MenuItems