From 44248ee0be0fa6d691f8ccacd00854db0c78f261 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 21 Nov 2026 04:48:18 +0100 Subject: [PATCH 1/2] headers: MissionAestheticsDefinedData::EventConditionOptionValues is int[32][25] MenuItemActionHandler_NewEventCondition_Main (0x004B9620) reads the option lists as dwords in rows of 25: the row is the condition's index times 25 (imul by 0x19 at 0x004B9834 and 0x004B998C), the entries are compared as dwords (cmp dword ptr [edi*4 + 0x00B3BA70], edx at 0x004B9841) and a list ends with -1 (cmp dword ptr [eax], -1 at 0x004B9880). The header had byte[32][100], the same 3,200 bytes. No .cpp on main uses the field. Co-Authored-By: Claude Fable 5.2 --- src/OpenSHC/Game/MissionAestheticsDefinedData.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/Game/MissionAestheticsDefinedData.hpp b/src/OpenSHC/Game/MissionAestheticsDefinedData.hpp index eaf30a679a..3cf868f032 100644 --- a/src/OpenSHC/Game/MissionAestheticsDefinedData.hpp +++ b/src/OpenSHC/Game/MissionAestheticsDefinedData.hpp @@ -114,7 +114,7 @@ namespace Game { int EventConditionMaxValue[40]; // 0x00002264 length: 160 int EventConditionValueScale[40]; // 0x00002304 length: 160 int EventConditionParamKind[40]; // 0x000023A4 length: 160 - byte EventConditionOptionValues[32][100]; // 0x00002444 length: 3200 + int EventConditionOptionValues[32][25]; // 0x00002444 length: 3200 int field_0x30c4[25]; // 0x000030C4 length: 100 int field_0x3128; // 0x00003128 length: 4 int BuildingAvailabilityRowOrder[174]; // 0x0000312C length: 696 From 50f446b48a22cb7b5f48de1dd9efe60c10735be7 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 21 Nov 2026 06:26:29 +0100 Subject: [PATCH 2/2] reimplement: SHC_3BB0A8C1_0x004B9620 100.0% Reimplemented, identical code; the folded address before MapPropertiesState is another global's on each side NewEventCondition::MenuItemActionHandler_NewEventCondition_Main, rewritten from the original's listing. gynt's draft is the file on his fork's reimpl/UI-MenuItems-development (first in 4e5711883, newest commit on it 5420320a2); his status line has no number for it. Our draft (f5da90246, then 6202bb00f; 64.0% in the draft PR #328) was his code with a mechanical pass. The function handles the buttons of the new event condition dialog: one switch over the button, dispatched through a compare tree and two pairs of tables (byte table 0x004B9AC0 with jump table 0x004B9AA8 for 19 to 209, byte table 0x004B9B8C with jump table 0x004B9B80 for 5106 to 5209). It works on the selected event's conditions: all-or-any (104), back to the event dialog (37), a condition's row (106 to 125, and 190 to 209 for conditions 20 to 39), the selected condition off (19), its value down and up (1000, 1001), its previous and next option (2000, 2001 and 2002), and a row switched off (5106 to 5125, and 5190 to 5209). The draft reached the conditions by pointer arithmetic on the event's data. The rewrite uses the fields main has for them (scenarioEvents[currentEventID].data.scenario.conditions[...], as main's MenuItemRenderFunction_NewEventCondition_Main does) and one switch. With that, all 283 instructions, every jump's landing and both jump tables are the original's. What it needed, each measured with that one thing changed (reccmp in the narrow build described below; the first four were built on an earlier form of the text with the same listing): - 2001 / 2002 keep the current option in an int local and search the option list with it. Compared from the field again: 91.2% (66.9% normalized). An option of 0 becomes RT_BREAD (10) first: the lists of the four conditions that have one hold ResourceType ids and all start with bread. - 2000's search for the list's last entry is a for loop to 100 that steps back and leaves at the -1. As a counted while loop: 85.0% (65.9%). The 100 is the original's (cmp ecx, 0x64 at 0x004B988B); it is a row's size in bytes, a row has 25 entries. - 37 leaves its search loop by break; with the dialog call and a return inside the loop: 98.0% (79.7%). - A row's enable store goes through the index just stored; through button - 106 again: 96.3% (87.2%). - The search index of 2000 and of 2001 / 2002 is declared before the test of the option kind. Declared at its search loop: 88.2% (70.8%). - The cases stand in the order of the original's code. In ascending order, as far as the two fall-throughs allow: 93.6% (81.3%). The header commit before this one gives the option lists their int[32][25] type; with byte[32][100] the dword compares need casts. One behaviour fix against the draft, with the struct resolvers on. The last case clears conditions[button - 5106].enabled. The draft, like the decompiler's text, wrote that byte through UnitsState (units[2491] plus 995, indexed by the event and the button). With the struct resolvers off that is the same byte; with them on it lies past our own copy of UnitsState, and the condition was never switched off. Recorded as 100% although reccmp shows 99.8% (95.2% normalized): one line differs, and it is the same instruction. Both compilers fold the -5106 * 4 of that last store into its address: mov byte ptr [eax*4 + K], 0 at 0x004B9A9C, where K is MapPropertiesState's instance minus 18937 on both sides (0x0164EE5F = 0x01653858 - 18937 in the original; our listing has the instance's symbol with [eax*4-18937]). K itself lies before the struct, inside UnitsState in the original's layout, and the store never touches it: with the button at 5106 or more it always lands on the condition. So reccmp cannot name K by the struct and names each side by whatever variable covers that address in that image: a plain number against MissionAestheticsDefinedData's instance + 6559 in the narrow build, UnitsState's instance + 2912039 against `cached` + 11 in a full build. The four bytes that are not the address are the same in every build (c6 04 85 .. .. .. .. 00). With MapPropertiesState's struct resolver off, so that the data is the original's by address, all eight bytes are the original's (c6 04 85 5f ee 64 01 00) and reccmp reads 100.0% (100.0% normalized). The line shows with the callees' resolvers on and off alike. Main records the same kind of difference as 100%: 0x0043C6A0 (#304) and 0x004DAF50 (#323), where a loop's end address resolves to the next global's symbol. Measured in a narrow build on main 3458fea34 of this file and the four finished functions it refers to, their resolvers on: activateModalDialog (0x004A9ED0), setExtraActiveModalDialog (0x004AA0A0), setSliderParameters2 (0x004AA540) and CaptureCurrentTimeToUnknownTime01 (0x004B9610), whose address it pushes. All four stay at 100.0. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ...emActionHandler_NewEventCondition_Main.cpp | 357 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 358 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemActionHandler_NewEventCondition_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemActionHandler_NewEventCondition_Main.cpp b/src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemActionHandler_NewEventCondition_Main.cpp new file mode 100644 index 0000000000..e01645c730 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/NewEventCondition/MenuItemActionHandler_NewEventCondition_Main.cpp @@ -0,0 +1,357 @@ +#include "../NewEventCondition.func.hpp" + +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Game/Resources/ResourceType.hpp" +#include "OpenSHC/Game/ScenarioEvents/Enums/ScenarioEventConditionIndex.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition2.hpp" +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UnknownTime_01.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B9620 + void NewEventCondition::MenuItemActionHandler_NewEventCondition_Main(int button, ...) + { + // the cases stand in the order of the original's code (in ascending order the match is lost) + switch (button) { + // all of the conditions, or any of them + case 104: + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.allOrAnyCondition ^= 1; + return; + // back to the event's dialog; the auto stop does not stay on beside another condition + case 37: + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[Game::ScenarioEvents::Enums::SECI_AUTO_STOP] + .enabled) { + for (int i = 1; i < countof(DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions); + ++i) { + if (DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[i] + .enabled) { + DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[Game::ScenarioEvents::Enums::SECI_AUTO_STOP] + .enabled = 0; + break; + } + } + } + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, DAT_MenuModalComposition1::ptr)( + UI::Enums::MMT_NEW_EVENT, FALSE); + return; + // conditions 20 to 39: the button less 64, then the code of 106 to 125 + case 190: + case 191: + case 192: + case 193: + case 194: + case 195: + case 196: + case 197: + case 198: + case 199: + case 200: + case 201: + case 202: + case 203: + case 204: + case 205: + case 206: + case 207: + case 208: + case 209: + button -= 64; + // conditions 0 to 19: selected, switched on, value at least its minimum; a slider if it has a maximum + case 106: + case 107: + case 108: + case 109: + case 110: + case 111: + case 112: + case 113: + case 114: + case 115: + case 116: + case 117: + case 118: + case 119: + case 120: + case 121: + case 122: + case 123: + case 124: + case 125: + DAT_MapPropertiesState::instance.invasionTroopIndex = button - 106; + // through the stored index (through button - 106 again, the match is lost) + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .enabled = 1; + DAT_UnknownTime_01::instance = 0; + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .value + < DAT_MissionAestheticsDefinedData::instance + .EventConditionMinValue[DAT_MapPropertiesState::instance.invasionTroopIndex]) { + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .value = DAT_MissionAestheticsDefinedData::instance + .EventConditionMinValue[DAT_MapPropertiesState::instance.invasionTroopIndex]; + } + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionMaxValue[DAT_MapPropertiesState::instance.invasionTroopIndex] + != 0) { + MACRO_CALL_MEMBER( + UI::MenuModalComposition_Func::setSliderParameters2, DAT_MenuModalComposition2::ptr)( + DAT_MissionAestheticsDefinedData::instance + .EventConditionMinValue[DAT_MapPropertiesState::instance.invasionTroopIndex], + DAT_MissionAestheticsDefinedData::instance + .EventConditionMaxValue[DAT_MapPropertiesState::instance.invasionTroopIndex], + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .value, + (dword)&DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .value, + MACRO_CALL(UI::Helpers_Func::CaptureCurrentTimeToUnknownTime01)); + MACRO_CALL_MEMBER( + UI::MenuModalComposition_Func::setExtraActiveModalDialog, DAT_MenuModalComposition2::ptr)( + UI::Enums::MMT_OVERLAY_SLIDER, DAT_ButtonX::instance + 58, DAT_ButtonY::instance + 28); + } + return; + // the selected condition off + case 19: + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .enabled = 0; + return; + // the selected condition's value one down, not below its minimum + case 1000: + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .value + > DAT_MissionAestheticsDefinedData::instance + .EventConditionMinValue[DAT_MapPropertiesState::instance.invasionTroopIndex]) { + --DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .value; + } + return; + // the selected condition's previous option + case 2000: { + // declared before the kind test (declared at its search loop, the match is lost) + int optionIndex = 0; + // option kinds: 0 none, 1 a list of goods (ResourceType ids, ended by -1), 2 an opponent (0 to 4) + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionParamKind[DAT_MapPropertiesState::instance.invasionTroopIndex] + == 0) { + return; + } + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionParamKind[DAT_MapPropertiesState::instance.invasionTroopIndex] + == 1) { + for (; DAT_MissionAestheticsDefinedData::instance + .EventConditionOptionValues[DAT_MapPropertiesState::instance.invasionTroopIndex] + [optionIndex] + != DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType; + ++optionIndex) {} + --optionIndex; + if (optionIndex < 0) { + // 100 is the original's bound: a row's bytes, not its 25 entries (a while loop loses the match) + int last = 0; + for (; last < 100; ++last) { + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionOptionValues[DAT_MapPropertiesState::instance.invasionTroopIndex] + [last] + == -1) { + --last; + break; + } + } + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType + = DAT_MissionAestheticsDefinedData::instance + .EventConditionOptionValues[DAT_MapPropertiesState::instance.invasionTroopIndex] + [last]; + } else { + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType + = DAT_MissionAestheticsDefinedData::instance + .EventConditionOptionValues[DAT_MapPropertiesState::instance.invasionTroopIndex] + [optionIndex]; + } + } + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionParamKind[DAT_MapPropertiesState::instance.invasionTroopIndex] + == 2) { + --DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType; + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType + < 0) { + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType = 4; + } + } + return; + } + // the selected condition's value one up, not above its maximum + case 1001: + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .value + < DAT_MissionAestheticsDefinedData::instance + .EventConditionMaxValue[DAT_MapPropertiesState::instance.invasionTroopIndex]) { + ++DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .value; + } + return; + // the selected condition's next option + case 2001: + case 2002: { + // declared before the kind test (declared at its search loop, the match is lost) + int optionIndex = 0; + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionParamKind[DAT_MapPropertiesState::instance.invasionTroopIndex] + == 0) { + return; + } + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionParamKind[DAT_MapPropertiesState::instance.invasionTroopIndex] + == 1) { + // a local for the option (compared from the field, the search loses the match) + int option = DAT_MapPropertiesState::instance + .scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType; + // an option of 0 is taken as bread, the first entry of every goods list + if (option == 0) { + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType = Game::Resources::RT_BREAD; + option = Game::Resources::RT_BREAD; + } + for (; DAT_MissionAestheticsDefinedData::instance + .EventConditionOptionValues[DAT_MapPropertiesState::instance.invasionTroopIndex] + [optionIndex] + != option; + ++optionIndex) {} + ++optionIndex; + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionOptionValues[DAT_MapPropertiesState::instance.invasionTroopIndex] + [optionIndex] + == -1) { + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType + = DAT_MissionAestheticsDefinedData::instance + .EventConditionOptionValues[DAT_MapPropertiesState::instance.invasionTroopIndex][0]; + } else { + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType + = DAT_MissionAestheticsDefinedData::instance + .EventConditionOptionValues[DAT_MapPropertiesState::instance.invasionTroopIndex] + [optionIndex]; + } + } + if (DAT_MissionAestheticsDefinedData::instance + .EventConditionParamKind[DAT_MapPropertiesState::instance.invasionTroopIndex] + == 2) { + ++DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType; + if (DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType + > 4) { + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[DAT_MapPropertiesState::instance.invasionTroopIndex] + .subType = 0; + } + } + return; + } + // conditions 20 to 39 off: the button less 64, then the code of 5106 to 5125 + case 5190: + case 5191: + case 5192: + case 5193: + case 5194: + case 5195: + case 5196: + case 5197: + case 5198: + case 5199: + case 5200: + case 5201: + case 5202: + case 5203: + case 5204: + case 5205: + case 5206: + case 5207: + case 5208: + case 5209: + button -= 64; + // conditions 0 to 19 off, unless a dialog is open or the slider's callback ran within the last second + case 5106: + case 5107: + case 5108: + case 5109: + case 5110: + case 5111: + case 5112: + case 5113: + case 5114: + case 5115: + case 5116: + case 5117: + case 5118: + case 5119: + case 5120: + case 5121: + case 5122: + case 5123: + case 5124: + case 5125: + if (DAT_MenuModalComposition2::instance.activeModalDialogID != UI::Enums::MMT_NONE) { + return; + } + if (timeGetTime() - DAT_UnknownTime_01::instance <= 1000 && DAT_UnknownTime_01::instance != 0) { + return; + } + DAT_UnknownTime_01::instance = 0; + DAT_MapPropertiesState::instance.scenarioEvents[DAT_MapPropertiesState::instance.currentEventID] + .data.scenario.conditions[button - 5106] + .enabled = 0; + return; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..759780cffc 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -27641,7 +27641,7 @@ SHC_3BB0A8C1_0x004B9530 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B9610 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B9620 | 0.0% | Pending +SHC_3BB0A8C1_0x004B9620 | 100.0% | Reimplemented, identical code; the folded address before MapPropertiesState is another global's on each side SHC_3BB0A8C1_0x004B9AA8 | 0.0% | Pending