From c022ebb8fb27a555eec9f72df9f5229f1bb39735 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 21:37:47 +0100 Subject: [PATCH 1/5] reimplement: SHC_3BB0A8C1_0x004AE720 100.0% Reimplemented From gynt's reimpl/UI-MenuItems (PR #254, closed), 62.9% there. Behaviour fix: the original returns after drawing the sorted column's header (ret at 0x004AE7B6); the draft went on to RenderButtonImageWithBlending and drew the default picture over it. The position goes straight into the renderGM call, as the original pushes it before calling getPictureNumberInGm. quick_diff leaves only ret / ret 0; reccmp 100% in a trial build. Co-Authored-By: Claude Opus 5.5 --- ...nuItemRenderFunction_GreatestLord_Main.cpp | 49 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/GreatestLord/MenuItemRenderFunction_GreatestLord_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/GreatestLord/MenuItemRenderFunction_GreatestLord_Main.cpp b/src/OpenSHC/UI/MenuItems/GreatestLord/MenuItemRenderFunction_GreatestLord_Main.cpp new file mode 100644 index 0000000000..ed5fcc325f --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/GreatestLord/MenuItemRenderFunction_GreatestLord_Main.cpp @@ -0,0 +1,49 @@ +#include "../GreatestLord.func.hpp" + +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/ButtonGmData.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eGM.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_GreatestLordDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_UIButtonDefinedData.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004AE720 + void GreatestLord::MenuItemRenderFunction_GreatestLord_Main(int button, ...) + { + // the header of the column the table is sorted by (11 for 1, 12 for 0, 10 for -1) gets its own picture + if ((button == 11 && DAT_GreatestLordDefinedData::instance.tableSortBy == 1) + || (button == 12 && DAT_GreatestLordDefinedData::instance.tableSortBy == 0) + || (button == 10 && DAT_GreatestLordDefinedData::instance.tableSortBy == -1)) { + // 14 pictures on from the hovered one, 1 for header 12 + int pictureOffset = 14; + if (button == 12) { + pictureOffset = 1; + } + DAT_ButtonCurrentlyInteracting::instance = TRUE; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((OpenSHC::DE::SHCDE::eGM)DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .gmId_0x0, + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::ButtonGmData_Func::getPictureNumberInGm, + &DAT_UIButtonDefinedData::instance.ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance])( + TRUE) + + pictureOffset, + DAT_ButtonX::instance, DAT_ButtonY::instance); + return; + } + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderButtonImageWithBlending)(); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d195ecb365..6bd317e0b7 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -25869,7 +25869,7 @@ SHC_3BB0A8C1_0x004AE0F0 | 0.0% | Pending SHC_3BB0A8C1_0x004AE4F0 | 0.0% | Pending -SHC_3BB0A8C1_0x004AE720 | 0.0% | Pending +SHC_3BB0A8C1_0x004AE720 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004AE7C0 | 100.0% | Reimplemented From 3164af0fec59ba2bf139cf8b9da2f0550e823d4c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 21:37:47 +0100 Subject: [PATCH 2/5] reimplement: SHC_3BB0A8C1_0x004D8DF0 100.0% Reimplemented From gynt's reimpl/UI-MenuItems (PR #254, closed), 64.3% there. The hover caption is drawn in two calls, "Skip Current Mission" while skips are left and "No Chickens Left" otherwise (cr.tex section 256, texts 0 and 1), which MSVC merges but for the text index, as the original's push 0 at 0x004D8E90 and push 1 at 0x004D8EA8; the draft's (count < 1) index compiled to a setl. The caption's position is computed before the test, y first. DAT_SkirmishTrailRelated1 is declared unsigned and the original compares it signed (jle at 0x004D8E8E), hence the (int). reccmp 100% in a trial build. Co-Authored-By: Claude Opus 5.5 --- ...unction_General_CrusadeMapAndEndscreen.cpp | 66 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_CrusadeMapAndEndscreen.cpp diff --git a/src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_CrusadeMapAndEndscreen.cpp b/src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_CrusadeMapAndEndscreen.cpp new file mode 100644 index 0000000000..e255516201 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_CrusadeMapAndEndscreen.cpp @@ -0,0 +1,66 @@ +#include "../General.func.hpp" + +#include "OpenSHC/Text/TextManager.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_SkirmishTrailRelated1.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" +#include "OpenSHC/Globals/INT_00ed2bdc.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004D8DF0 + void General::MenuItemRenderFunction_General_CrusadeMapAndEndscreen(int button, ...) + { + if (button == 1000) { + // the skip-mission button, with the number of skips (chickens) left + // cleared, then set when hovered (a copy of the hover flag: quick_diff 0.9464 -> 0.8000) + INT_00ed2bdc::instance = FALSE; + if (DAT_ButtonCurrentlyInteracting::instance) { + INT_00ed2bdc::instance = TRUE; + } + MACRO_CALL(OpenSHC::UI::MenuItems::General_Func:: + MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface)(); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumber2, DAT_TextManagerObject::ptr)( + DAT_SkirmishTrailRelated1::instance, DAT_ButtonX::instance + 53, DAT_ButtonY::instance + 98, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_C2F0EB, 0, 15, FALSE, 0); + if (!INT_00ed2bdc::instance) { + return; + } + // hovered: a caption 400 and 583 pixels in from the menu's corner; the count is compared signed + // y then x, before the test (x first: quick_diff 0.9464 -> 0.8750) + int const textY = DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight + 583; + int const textX = DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + 400; + // one call per caption, merged but for the index (an index local: quick_diff 0.9464 -> 0.8468) + if ((int)DAT_SkirmishTrailRelated1::instance > 0) { + // "Skip Current Mission" + 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_CHEATS, 0), + textX, textY, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + return; + } + // "No Chickens Left" + 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_CHEATS, 1), + textX, textY, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + return; + } + if (button == 10 || button == 11 || button == 99) { + MACRO_CALL(OpenSHC::UI::MenuItems::General_Func:: + MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface)(); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6bd317e0b7..7729af03a0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -36011,7 +36011,7 @@ SHC_3BB0A8C1_0x004D8CB0 | 0.0% | Pending SHC_3BB0A8C1_0x004D8DC0 | 0.0% | Pending -SHC_3BB0A8C1_0x004D8DF0 | 0.0% | Pending +SHC_3BB0A8C1_0x004D8DF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D8EC0 | 0.0% | Pending From 8fe0ef8ed323e3e6e201a255123f2af80b5c8f33 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 21:37:47 +0100 Subject: [PATCH 3/5] reimplement: SHC_3BB0A8C1_0x00437ED0 100.0% Reimplemented From gynt's reimpl/UI-MenuItems (PR #254, closed), 70.3% there, after main's renames (field_0x0, wallDragButtonUp, field_0x1dc). Behaviour fix: the original returns after drawing the wall preview while the drag goes on (ret at 0x0043805E), so the wall is only placed once the drag has stopped; the draft went on and could queue GCT_PLACE_WALL during the drag. The arms of three ifs now come in the original's order: the click first, the flat view's setupMouseTileXY2 first, the illegal build first. The six command parameters are set in address order, which MSVC compiles to the original's store order (Param1, Param0, Param2, Param4, Param3, Param5 from 0x0043809B on); the draft had copied that compiled order, and written so ours came out in address order (reccmp 93.3%). quick_diff 0.8186 -> 0.9748, which leaves only ret / ret 0. Co-Authored-By: Claude Opus 5.5 --- ...ler_InGameMenu_TriggerPlaceWallCommand.cpp | 111 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_TriggerPlaceWallCommand.cpp diff --git a/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_TriggerPlaceWallCommand.cpp b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_TriggerPlaceWallCommand.cpp new file mode 100644 index 0000000000..0218d20296 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_TriggerPlaceWallCommand.cpp @@ -0,0 +1,111 @@ +#include "../InGameMenu.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/Resources/ResourceType.hpp" +#include "OpenSHC/Map/Buildings/BuildingFailReasonEnum.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_ScrollingHandler.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x00437ED0 + void InGameMenu::MenuItemActionHandler_InGameMenu_TriggerPlaceWallCommand() + { + if (DAT_GameSynchronyState::instance.syncStatus != 0) { + return; + } + if (DAT_GameSynchronyState::instance.saveRelated != 0) { + return; + } + // only for the wall, wooden wall, stairs and crenel tools + if (DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_WALL + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_WOODWALL + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_STAIR + && DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_CRENAL) { + return; + } + if (!DAT_ViewportRenderState::instance.viewportState.field_0x0) { + return; + } + DAT_MouseState::instance.field_0x1dc = 1000; + // the tile under the mouse + if (DAT_TileMapState::instance.flatViewToggleValue1) { + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::setupMouseTileXY2, DAT_ViewportRenderState::ptr)(); + } else { + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::setupMouseTileXY, DAT_ViewportRenderState::ptr)(); + } + // a click starts the drag, a held button or a finished drag moves its end, no button puts both ends here + if (DAT_MouseState::instance.leftClickStart) { + DAT_TileMapState::instance.dragStartX = DAT_ViewportRenderState::instance.viewportState.mouseTileX; + DAT_TileMapState::instance.dragStartY = DAT_ViewportRenderState::instance.viewportState.mouseTileY; + } else if (DAT_MouseState::instance.draggingStopped || DAT_MouseState::instance.leftClickState) { + DAT_TileMapState::instance.dragEndX = DAT_ViewportRenderState::instance.viewportState.mouseTileX; + DAT_TileMapState::instance.dragEndY = DAT_ViewportRenderState::instance.viewportState.mouseTileY; + } else { + if (DAT_ScrollingHandler::instance.isScrolling_0x0) { + return; + } + DAT_TileMapState::instance.dragStartX = DAT_ViewportRenderState::instance.viewportState.mouseTileX; + DAT_TileMapState::instance.dragStartY = DAT_ViewportRenderState::instance.viewportState.mouseTileY; + DAT_TileMapState::instance.dragEndX = DAT_ViewportRenderState::instance.viewportState.mouseTileX; + DAT_TileMapState::instance.dragEndY = DAT_ViewportRenderState::instance.viewportState.mouseTileY; + } + DAT_TileMapState::instance.buildingPlacementFailReason + = OpenSHC::Map::Buildings::BFRE_DEFAULT_CANT_PLACE_THAT_THERE; + DAT_TileMapState::instance.wallPlacementCost = 0; + DAT_TileMapState::instance.constructionTileCount = MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::getWallTilesThatCanBeBuilt, DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, OpenSHC::Game::Resources::RT_STONE); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::validateWallBuildPath, DAT_TileMapState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, DAT_TileMapState::instance.dragStartX, + DAT_TileMapState::instance.dragStartY, DAT_TileMapState::instance.dragEndX, + DAT_TileMapState::instance.dragEndY, (ushort)DAT_TileMapState::instance.currentMapperCommand); + // until the drag stops, only the preview is drawn + if (!DAT_MouseState::instance.draggingStopped) { + DAT_TileMapState::instance.wallDragButtonUp = !DAT_MouseState::instance.leftClickState; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::renderWallDragPreview, DAT_TileMapState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, DAT_TileMapState::instance.dragStartX, + DAT_TileMapState::instance.dragStartY, DAT_TileMapState::instance.dragEndX, + DAT_TileMapState::instance.dragEndY, (ushort)DAT_TileMapState::instance.currentMapperCommand); + return; + } + if (DAT_TileMapState::instance.illegalBuild) { + // the panel feedback text with the fail reason's number + if (DAT_TileMapState::instance.buildingPlacementFailReason + != OpenSHC::Map::Buildings::BFRE_DEFAULT_CANT_PLACE_THAT_THERE) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, + DAT_TileMapState::instance.buildingPlacementFailReason, 0, 100, 6000); + } + return; + } + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = DAT_TileMapState::instance.dragStartX; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = DAT_TileMapState::instance.dragStartY; + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 = DAT_TileMapState::instance.dragEndX; + DAT_GameSynchronyState::instance.DAT_GameCommandParam3 = DAT_TileMapState::instance.dragEndY; + DAT_GameSynchronyState::instance.DAT_GameCommandParam4 = DAT_TileMapState::instance.currentMapperCommand; + DAT_GameSynchronyState::instance.DAT_GameCommandParam5 = DAT_TileMapState::instance.constructionTileCount; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_PLACE_WALL); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7729af03a0..805d7a44b5 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -12677,7 +12677,7 @@ SHC_3BB0A8C1_0x00437CB0 | 0.0% | Pending SHC_3BB0A8C1_0x00437CC0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00437ED0 | 0.0% | Pending +SHC_3BB0A8C1_0x00437ED0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004380E0 | 100.0% | Reimplemented From 5270c40b3eb80408adaa8ad487daaf3db775c6ce Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 21:37:47 +0100 Subject: [PATCH 4/5] reimplement: SHC_3BB0A8C1_0x00463FF0 100.0% Reimplemented From gynt's reimpl/UI-MenuItems (PR #254, closed), 53.0% there. Built with /GL (added to cmake/compiler-flags-gl.txt): the original keeps the button's address in ecx across getPictureNumberInGm (0x004630B0, 100% and already in the list) and reads the GM ID through it afterwards (mov ecx, [ecx] at 0x00464040). Each use indexes the array afresh: the original computes the byte offset once and forms the address in each path (lea ecx at 0x00464028 and 0x00464081), where a pointer local moved it ahead of the branch (70.7% with /GL). reccmp 100% in a clean alone build. Co-Authored-By: Claude Opus 5.5 --- cmake/compiler-flags-gl.txt | 1 + ...ithPossibleAlphaTexOnScreenMenuSurface.cpp | 63 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface.cpp diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index ea680bf4b3..7a4a662301 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -114,3 +114,4 @@ src/OpenSHC/UI/Rendering/RenderCurrentNotActiveButtonWithPossibleAlphaTexOnCurre src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_DrawbridgeOpenClose.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_GatehouseOpenClose.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_WorkshopWeaponSelection.cpp +src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface.cpp diff --git a/src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface.cpp b/src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface.cpp new file mode 100644 index 0000000000..aa638e19cf --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/General/MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface.cpp @@ -0,0 +1,63 @@ +#include "../General.func.hpp" + +#include "OpenSHC/UI/Rendering/ButtonGmData.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eGM.hpp" +#include "OpenSHC/IO/Graphics/GmID.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" + +#include "OpenSHC/Globals/DAT_ButtonBlendStrength.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_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_UIButtonDefinedData.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x00463FF0 + void General::MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface() + { + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + if (DAT_UIButtonDefinedData::instance.ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .alphaGmIdUnk_0xc + != 0) { + // a button with an alpha GM is drawn blended, and not at all at blend strength 32 + if (DAT_ButtonBlendStrength::instance != 32) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)((OpenSHC::IO::Graphics::GmID)DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .gmId_0x0, + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::ButtonGmData_Func::getPictureNumberInGm, + &DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance])( + DAT_ButtonCurrentlyInteracting::instance), + DAT_ButtonX::instance, DAT_ButtonY::instance, DAT_ButtonBlendStrength::instance); + } + DAT_CurrentButtonPictureInGm::instance + = DAT_UIButtonDefinedData::instance.ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .pictureInGm_0x4; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((OpenSHC::DE::SHCDE::eGM)DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .gmId_0x0, + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::ButtonGmData_Func::getPictureNumberInGm, + &DAT_UIButtonDefinedData::instance.ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance])( + DAT_ButtonCurrentlyInteracting::instance), + DAT_ButtonX::instance, DAT_ButtonY::instance); + DAT_CurrentButtonPictureInGm::instance + = DAT_UIButtonDefinedData::instance.ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .pictureInGm_0x4; + 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 805d7a44b5..60f2fba81e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -19751,7 +19751,7 @@ SHC_3BB0A8C1_0x00463A00 | 0.0% | Pending SHC_3BB0A8C1_0x00463A90 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00463FF0 | 0.0% | Pending +SHC_3BB0A8C1_0x00463FF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004640D0 | 100.0% | Reimplemented From fcaa896af3240ea2e84b096ed85a89850a00652f Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 21:37:48 +0100 Subject: [PATCH 5/5] reimplement: SHC_3BB0A8C1_0x004D9730 100.0% Reimplemented From gynt's fork branch reimpl/UI-MenuItems-development, 54.6% there. The game's results are copied with one struct assignment (rep movsd of 0x1DE dwords at 0x004D97B6) and the end-screen picture names with plain strcpy calls from the S_* literals, which MSVC inlines as the original does (six dword moves, five dword moves, rep movsd plus movsb, and five dwords and a byte); the draft had a hand-written loop and a memcpy with a masked byte. Button 11 is an if/else of the two switchToMenuView calls followed by one store of the stored game mode, which MSVC duplicates into both paths with the original's registers (two separate returns: quick_diff 0.9506 -> 0.8519). The scroll offset and the game count are main's INT_00ed3120 and INT_00eb9b60, declared int since 7621d4f1d. quick_diff then leaves only its spelling of rep movsd and ret / ret 0. Co-Authored-By: Claude Opus 5.5 --- ...enuItemActionHandler_RankingGames_Main.cpp | 139 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/RankingGames/MenuItemActionHandler_RankingGames_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/RankingGames/MenuItemActionHandler_RankingGames_Main.cpp b/src/OpenSHC/UI/MenuItems/RankingGames/MenuItemActionHandler_RankingGames_Main.cpp new file mode 100644 index 0000000000..8f3d1ff79c --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/RankingGames/MenuItemActionHandler_RankingGames_Main.cpp @@ -0,0 +1,139 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#include "../RankingGames.func.hpp" + +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Game/Skirmish.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/string-macros.hpp" + +#include "OpenSHC/Globals/CHAR_ARRAY_00eb9ac8.hpp" +#include "OpenSHC/Globals/DAT_00ed2788.hpp" +#include "OpenSHC/Globals/DAT_00ed3124.hpp" +#include "OpenSHC/Globals/DAT_CurrentMenuID_3.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MissionDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" +#include "OpenSHC/Globals/DAT_StoredGameMode.hpp" +#include "OpenSHC/Globals/INT_00eb9b60.hpp" +#include "OpenSHC/Globals/INT_00ed3120.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00eb96d8.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004D9730 + void RankingGames::MenuItemActionHandler_RankingGames_Main(int button, ...) + { + // buttons -10 and -11 scroll the list, which shows 8 rows + if (button == -10) { + if (INT_00ed3120::instance > 0) { + --INT_00ed3120::instance; + } + return; + } + if (button == -11) { + if (INT_00ed3120::instance < INT_00eb9b60::instance - 8) { + ++INT_00ed3120::instance; + } + return; + } + // buttons 0 to 7 are the rows: a row shows that game's end screen + if (button < 8 && INT_00ed3120::instance + button < INT_00eb9b60::instance) { + int const game = INT_ARRAY_00eb96d8::instance[INT_00ed3120::instance + button]; + DAT_GameSynchronyState::instance.finalResults = DAT_SkMasters2DataArray::instance[game].results; + DAT_GameCore::instance.gameMode_2 = OpenSHC::Game::GM_SKIRMISH_AND_MULTIPLAYER; + DAT_GameSynchronyState::instance.currentGameMode = OpenSHC::Game::GM_SKIRMISH_END_OF_GAME_SINGLE_PLAYER; + if (DAT_SkMasters2DataArray::instance[game].aliveArray[1] != 0) { + // "win_screen_crusader.tgx" + strcpy(CHAR_ARRAY_00eb9ac8::instance, S_WIN_SCREEN_CRUSADER_TGX_005AB024); + if (DAT_SkMasters2DataArray::instance[game].lordType != 0) { + // "win_screen_arab.tgx" + strcpy(CHAR_ARRAY_00eb9ac8::instance, S_WIN_SCREEN_ARAB_TGX_005AB010); + } + } else { + // "lose_screen_crusader.tgx" + strcpy(CHAR_ARRAY_00eb9ac8::instance, S_LOSE_SCREEN_CRUSADER_TGX_005AAFF4); + if (DAT_SkMasters2DataArray::instance[game].lordType != 0) { + // "lose_screen_arab.tgx" + strcpy(CHAR_ARRAY_00eb9ac8::instance, S_LOSE_SCREEN_ARAB_TGX_005AAFDC); + } + } + DAT_GameCore::instance.skipStoreSKMasters = 1; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); + } + // buttons from 40 on delete the game in that row, after asking + if (button >= 40 && INT_00ed3120::instance + button - 40 < INT_00eb9b60::instance) { + DAT_00ed2788::instance = INT_ARRAY_00eb96d8::instance[INT_00ed3120::instance + button - 40]; + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_DELETE_GAME_RECORD, FALSE); + } + // button 11 goes back where the rankings were opened from + if (button == 11) { + if (DAT_CurrentMenuID_3::instance == OpenSHC::UI::Enums::MVT_CRUSADE_MAP) { + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_CRUSADE_MAP, 0); + } else { + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_LOBBY_MENU, 0); + } + DAT_GameSynchronyState::instance.currentGameMode = DAT_StoredGameMode::instance; + return; + } + // headers 20 to 29 sort by columns 1 to 10: again on the same column turns the order round + if (button >= 20 && button <= 29) { + if (DAT_MissionDefinedData::instance.sortColumn != button - 19) { + DAT_MissionDefinedData::instance.sortColumn = button - 19; + DAT_MissionDefinedData::instance.descending = TRUE; + } else { + // (!descending: quick_diff 0.9506 -> 0.9354) + DAT_MissionDefinedData::instance.descending = 1 - DAT_MissionDefinedData::instance.descending; + } + MACRO_CALL(OpenSHC::Game::Skirmish_Func::Skirmish_PrepareLeaderboardView)(); + int lastFirstRow = INT_00eb9b60::instance - 8; + if (lastFirstRow < 0) { + lastFirstRow = 0; + } + if (INT_00ed3120::instance > lastFirstRow) { + INT_00ed3120::instance = lastFirstRow; + } + } + // headers 30 and 31 turn the "Crusader Trail Only" (1) and "Custom Games Only" (2) filters on and off; 0 is + // "All Games" + if (button == 30) { + if (DAT_00ed3124::instance != 1) { + DAT_00ed3124::instance = 1; + } else { + DAT_00ed3124::instance = 0; + } + } else if (button == 31) { + if (DAT_00ed3124::instance != 2) { + DAT_00ed3124::instance = 2; + } else { + DAT_00ed3124::instance = 0; + } + } else { + return; + } + MACRO_CALL(OpenSHC::Game::Skirmish_Func::Skirmish_PrepareLeaderboardView)(); + int lastFirstRow = INT_00eb9b60::instance - 8; + if (lastFirstRow < 0) { + lastFirstRow = 0; + } + if (INT_00ed3120::instance > lastFirstRow) { + INT_00ed3120::instance = lastFirstRow; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 60f2fba81e..dfddd24a25 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -36029,7 +36029,7 @@ SHC_3BB0A8C1_0x004D9520 | 0.0% | Pending SHC_3BB0A8C1_0x004D9700 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004D9730 | 0.0% | Pending +SHC_3BB0A8C1_0x004D9730 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D99F0 | 0.0% | Pending