From 6bb5cc5389256c027d905a81bcd8be4ddaf11cc1 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 17 Nov 2026 04:30:27 +0100 Subject: [PATCH 01/45] reimplement: SHC_3BB0A8C1_0x004845B0 100.0% Reimplemented CommandSpawnEntity, gynt's version as it stands on reimpl/Synchrony-Commands (upstream ca943baa1 and his fork's 6fa5eaa53), where the status line still reads 73.5% (Style pass, asm differs): the file was last changed in his 461be1447 ("reimplement: SHC_3BB0A8C1_0x004845B0 100.0% Reimplemented", 2026-10-03), which left the status line of 3b215e12d in place. Taken unchanged; it compiles on main's headers as it is. With both resolver sets on it reads reccmp 100.0 (normalized 100.0). What main's style rules need on top follows in our own commit, which also sets the status line. Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/CommandSpawnEntity.cpp | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 src/OpenSHC/Synchrony/Commands/CommandSpawnEntity.cpp diff --git a/src/OpenSHC/Synchrony/Commands/CommandSpawnEntity.cpp b/src/OpenSHC/Synchrony/Commands/CommandSpawnEntity.cpp new file mode 100644 index 0000000000..80f001363a --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/CommandSpawnEntity.cpp @@ -0,0 +1,125 @@ +#include "../../Synchrony.func.hpp" +#include "../Commands.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/WallAndPitchState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/Resources/ResourceType.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_WallAndPitchState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + using OpenSHC::Commands::GameCommandParameterLocation; + using OpenSHC::Commands::GameCommandParameterReadWrite; + using OpenSHC::Commands::GameCommandScheduling; + using OpenSHC::Commands::MappersEnum; + using OpenSHC::Game::GameMode2; + using OpenSHC::Game::Resources::ResourceType; + using OpenSHC::Map::Entities::EntityType; + + /* + WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names + */ + /* + WARNING: Enum "DPERRInt": Some values do not have unique names + */ + /* + WARNING: Enum "MappersEnum": Some values do not have unique names + */ + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004845B0 + void Commands::CommandSpawnEntity() + { + uint entityID; + int local_8; + int local_4; + DAT_GameSynchronyState::instance.DAT_CommandSize = 9; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam2, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam3, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam4, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam5, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&local_8, 1, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = (int)(char)local_8; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&local_8, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = (int)(short)local_8; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&local_8, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 = (int)(short)local_8; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&local_8, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam3 = (int)(short)local_8; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&local_8, 1, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam4 = (EntityType)(char)local_8; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&local_8, 1, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam5 = (uint)(char)local_8; + entityID = MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, + DAT_EntityState::ptr)(0, DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + (uint)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam5)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam1)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam2)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam3)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam1)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam2)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam3)), + (EntityType)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4)), 0); + if ((DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SIEGE_THAT) + && (DAT_GameSynchronyState::instance.DAT_GameCommandParam4 == OpenSHC::Map::Entities::ET_BRAZIER)) { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingCost, + DAT_BuildingsState::ptr)(OpenSHC::Commands::M_MAPPER_BRAZIER, &local_4, &local_8); + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processResourceLoss, + DAT_BuildingsState::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + OpenSHC::Game::Resources::RT_GOLD, local_8, 0); + } + if (DAT_GameSynchronyState::instance.protocolInvokerPlayerID + == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + MACRO_CALL_MEMBER(OpenSHC::Map::WallAndPitchState_Func::startEntityDestructionConfirmation, + DAT_WallAndPitchState::ptr)(entityID); + } + } + } + +} +} From 07579c66c6f9d780a099b7b8d4e1e9d37afdc285 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 04:30:28 +0100 Subject: [PATCH 02/45] style: CommandSpawnEntity (0x004845B0) follows the style guide On top of gynt's version in the commit before; the code is the same, reccmp 100.0 (normalized 100.0) and quick_diff 147/147 at 1.0000 before and after. - The first include is ../Commands.func.hpp, once; the using lines and the imported block comments are gone. - The execute half is an early return, and entityID is declared where it gets its value. - local_8 is `readBuffer`: the buffer each parameter is read into. It also receives the brazier's gold cost, as in gynt's version and in the original: a `goldCost` of its own makes the frame 12 bytes where the original has 8 (quick_diff 0.9592). local_4 is `stoneCost`. - The doubled `(int)((int)(...))` casts on the six parameters are gone, and the narrowing casts are `(char)` and `(short)` alone. The status line goes to 100.0% (Reimplemented) with this commit. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/CommandSpawnEntity.cpp | 125 ++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 54 insertions(+), 73 deletions(-) diff --git a/src/OpenSHC/Synchrony/Commands/CommandSpawnEntity.cpp b/src/OpenSHC/Synchrony/Commands/CommandSpawnEntity.cpp index 80f001363a..7631844fbc 100644 --- a/src/OpenSHC/Synchrony/Commands/CommandSpawnEntity.cpp +++ b/src/OpenSHC/Synchrony/Commands/CommandSpawnEntity.cpp @@ -1,4 +1,3 @@ -#include "../../Synchrony.func.hpp" #include "../Commands.func.hpp" #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" @@ -22,32 +21,10 @@ namespace OpenSHC { namespace Synchrony { - using OpenSHC::Commands::GameCommandParameterLocation; - using OpenSHC::Commands::GameCommandParameterReadWrite; - using OpenSHC::Commands::GameCommandScheduling; - using OpenSHC::Commands::MappersEnum; - using OpenSHC::Game::GameMode2; - using OpenSHC::Game::Resources::ResourceType; - using OpenSHC::Map::Entities::EntityType; - - /* - WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names - */ - /* - WARNING: Enum "DPERRInt": Some values do not have unique names - */ - /* - WARNING: Enum "MappersEnum": Some values do not have unique names - */ - /* - decompilerscript: committed: 2025-01-30 21:57:43.216000 - */ // FUNCTION: STRONGHOLDCRUSADER 0x004845B0 void Commands::CommandSpawnEntity() { - uint entityID; - int local_8; - int local_4; + // the player, the position (x, y and height), the entity type and the owner colour DAT_GameSynchronyState::instance.DAT_CommandSize = 9; if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, @@ -70,54 +47,58 @@ namespace Synchrony { OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); return; } - if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) { - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&local_8, 1, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = (int)(char)local_8; - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&local_8, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = (int)(short)local_8; - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&local_8, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - DAT_GameSynchronyState::instance.DAT_GameCommandParam2 = (int)(short)local_8; - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&local_8, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - DAT_GameSynchronyState::instance.DAT_GameCommandParam3 = (int)(short)local_8; - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&local_8, 1, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - DAT_GameSynchronyState::instance.DAT_GameCommandParam4 = (EntityType)(char)local_8; - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&local_8, 1, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - DAT_GameSynchronyState::instance.DAT_GameCommandParam5 = (uint)(char)local_8; - entityID = MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, - DAT_EntityState::ptr)(0, DAT_GameSynchronyState::instance.DAT_GameCommandParam0, - (uint)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam5)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam1)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam2)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam3)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam1)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam2)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam3)), - (EntityType)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4)), 0); - if ((DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SIEGE_THAT) - && (DAT_GameSynchronyState::instance.DAT_GameCommandParam4 == OpenSHC::Map::Entities::ET_BRAZIER)) { - MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingCost, - DAT_BuildingsState::ptr)(OpenSHC::Commands::M_MAPPER_BRAZIER, &local_4, &local_8); - MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processResourceLoss, - DAT_BuildingsState::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0, - OpenSHC::Game::Resources::RT_GOLD, local_8, 0); - } - if (DAT_GameSynchronyState::instance.protocolInvokerPlayerID - == DAT_GameSynchronyState::instance.currentPlayerSlotID) { - MACRO_CALL_MEMBER(OpenSHC::Map::WallAndPitchState_Func::startEntityDestructionConfirmation, - DAT_WallAndPitchState::ptr)(entityID); - } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + int readBuffer; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&readBuffer, 1, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = (char)readBuffer; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&readBuffer, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = (short)readBuffer; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&readBuffer, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 = (short)readBuffer; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&readBuffer, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam3 = (short)readBuffer; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&readBuffer, 1, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam4 = (char)readBuffer; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&readBuffer, 1, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam5 = (char)readBuffer; + int const entityID = MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, + DAT_EntityState::ptr)(0, DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + DAT_GameSynchronyState::instance.DAT_GameCommandParam5, + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + DAT_GameSynchronyState::instance.DAT_GameCommandParam2, + DAT_GameSynchronyState::instance.DAT_GameCommandParam3, + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + DAT_GameSynchronyState::instance.DAT_GameCommandParam2, + DAT_GameSynchronyState::instance.DAT_GameCommandParam3, + (OpenSHC::Map::Entities::EntityType)DAT_GameSynchronyState::instance.DAT_GameCommandParam4, 0); + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SIEGE_THAT + && DAT_GameSynchronyState::instance.DAT_GameCommandParam4 == OpenSHC::Map::Entities::ET_BRAZIER) { + // readBuffer also receives the gold cost (a local of its own adds a stack slot) + int stoneCost; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingCost, DAT_BuildingsState::ptr)( + OpenSHC::Commands::M_MAPPER_BRAZIER, &stoneCost, &readBuffer); + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processResourceLoss, + DAT_BuildingsState::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + OpenSHC::Game::Resources::RT_GOLD, readBuffer, 0); + } + if (DAT_GameSynchronyState::instance.protocolInvokerPlayerID + == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + MACRO_CALL_MEMBER(OpenSHC::Map::WallAndPitchState_Func::startEntityDestructionConfirmation, + DAT_WallAndPitchState::ptr)(entityID); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6ec8017690..49d0a41fe3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22705,7 +22705,7 @@ SHC_3BB0A8C1_0x00484450 | 0.0% | Pending SHC_3BB0A8C1_0x004844A0 | 0.0% | Pending -SHC_3BB0A8C1_0x004845B0 | 0.0% | Pending +SHC_3BB0A8C1_0x004845B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004847B0 | 0.0% | Pending From 0da8c550e3effad65906cb021787ef4cd22a69e6 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 17 Nov 2026 04:30:28 +0100 Subject: [PATCH 03/45] reimplement: SHC_3BB0A8C1_0x00486140 100.0% Reimplemented SendPlayerToPlayerRequestOrResponse, gynt's version as it stands on reimpl/Synchrony-Commands (upstream ca943baa1 and his fork's 6fa5eaa53), where the status line still reads 70.8% (Style pass, asm differs): the file was last changed in his 655eb2f58 ("reimplement: SHC_3BB0A8C1_0x00486140 100.0% Reimplemented", 2026-10-03), which left the status line of ffed63ed6 in place. Taken unchanged; it compiles on main's headers as it is. With both resolver sets on it reads reccmp 100.0 (normalized 100.0). What main's style rules need on top follows in our own commit, which also sets the status line. Co-Authored-By: Claude Fable 5.2 --- .../SendPlayerToPlayerRequestOrResponse.cpp | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/OpenSHC/Synchrony/Commands/SendPlayerToPlayerRequestOrResponse.cpp diff --git a/src/OpenSHC/Synchrony/Commands/SendPlayerToPlayerRequestOrResponse.cpp b/src/OpenSHC/Synchrony/Commands/SendPlayerToPlayerRequestOrResponse.cpp new file mode 100644 index 0000000000..ea1122733e --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/SendPlayerToPlayerRequestOrResponse.cpp @@ -0,0 +1,111 @@ +#include "../../Synchrony.func.hpp" +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony/Actions.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Game/Resources/ResourceType.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + using OpenSHC::Commands::GameCommandParameterLocation; + using OpenSHC::Commands::GameCommandParameterReadWrite; + using OpenSHC::Commands::GameCommandScheduling; + using OpenSHC::Game::Resources::ResourceType; + + /* + WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names + */ + /* + WARNING: Enum "DPERRInt": Some values do not have unique names + */ + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x00486140 + void Commands::SendPlayerToPlayerRequestOrResponse() + { + short local_4[2]; + DAT_GameSynchronyState::instance.DAT_CommandSize = 0x12; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam2, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam3, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam4, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(local_4, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = (int)local_4[0]; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam2, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam3, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam4, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { + case 0: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyRequestAttackDefense)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam2)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam3)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); + return; + case 1: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyRequestingGoods)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam2)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam3)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); + return; + case 2: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyGoodsRequest)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + (ResourceType)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam2)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam3)), + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); + return; + case 3: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyDeniesRequest)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); + return; + case 4: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyAcceptsRequest)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); + return; + case 5: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyDeniesRequest2)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); + } + } + } + +} +} From d3626136753f2db90aea2dfe0c4ee6c2051152fd Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 04:30:30 +0100 Subject: [PATCH 04/45] style: SendPlayerToPlayerRequestOrResponse (0x00486140) follows the style guide On top of gynt's version in the commit before; the code is the same, reccmp 100.0 (normalized 100.0) and quick_diff 136/136 at 1.0000 before and after. - The first include is ../Commands.func.hpp, once; the using lines and the imported block comments are gone. - The execute half is an early return, and the switch cases end in break. - `short local_4[2]` is `short messageKind`, read straight into DAT_GameCommandParam0 with no cast. - The doubled `(int)((int)(...))` casts on the parameters are gone, and the command size is decimal. The six message kinds stay numbers: the headers have no enum for them, and main's two senders (Allies and AlliesOrder) write numbers too. The status line goes to 100.0% (Reimplemented) with this commit. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../SendPlayerToPlayerRequestOrResponse.cpp | 130 ++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 60 insertions(+), 72 deletions(-) diff --git a/src/OpenSHC/Synchrony/Commands/SendPlayerToPlayerRequestOrResponse.cpp b/src/OpenSHC/Synchrony/Commands/SendPlayerToPlayerRequestOrResponse.cpp index ea1122733e..d1151dcc72 100644 --- a/src/OpenSHC/Synchrony/Commands/SendPlayerToPlayerRequestOrResponse.cpp +++ b/src/OpenSHC/Synchrony/Commands/SendPlayerToPlayerRequestOrResponse.cpp @@ -1,4 +1,3 @@ -#include "../../Synchrony.func.hpp" #include "../Commands.func.hpp" #include "OpenSHC/Synchrony/Actions.func.hpp" @@ -13,25 +12,11 @@ namespace OpenSHC { namespace Synchrony { - using OpenSHC::Commands::GameCommandParameterLocation; - using OpenSHC::Commands::GameCommandParameterReadWrite; - using OpenSHC::Commands::GameCommandScheduling; - using OpenSHC::Game::Resources::ResourceType; - - /* - WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names - */ - /* - WARNING: Enum "DPERRInt": Some values do not have unique names - */ - /* - decompilerscript: committed: 2025-01-30 21:57:43.216000 - */ // FUNCTION: STRONGHOLDCRUSADER 0x00486140 void Commands::SendPlayerToPlayerRequestOrResponse() { - short local_4[2]; - DAT_GameSynchronyState::instance.DAT_CommandSize = 0x12; + // the kind of message, then four values that depend on it + DAT_GameSynchronyState::instance.DAT_CommandSize = 18; if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 2, @@ -50,60 +35,63 @@ namespace Synchrony { OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); return; } - if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) { - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(local_4, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = (int)local_4[0]; - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, - OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam2, 4, - OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam3, 4, - OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam4, 4, - OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { - case 0: - MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyRequestAttackDefense)( - DAT_GameSynchronyState::instance.DAT_GameCommandParam1, - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam2)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam3)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); - return; - case 1: - MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyRequestingGoods)( - DAT_GameSynchronyState::instance.DAT_GameCommandParam1, - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam2)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam3)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); - return; - case 2: - MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyGoodsRequest)( - DAT_GameSynchronyState::instance.DAT_GameCommandParam1, - (ResourceType)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam2)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam3)), - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); - return; - case 3: - MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyDeniesRequest)( - DAT_GameSynchronyState::instance.DAT_GameCommandParam1, - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); - return; - case 4: - MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyAcceptsRequest)( - DAT_GameSynchronyState::instance.DAT_GameCommandParam1, - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); - return; - case 5: - MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyDeniesRequest2)( - DAT_GameSynchronyState::instance.DAT_GameCommandParam1, - (int)((int)(DAT_GameSynchronyState::instance.DAT_GameCommandParam4))); - } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + short messageKind; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&messageKind, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = messageKind; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam2, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam3, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam4, 4, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { + case 0: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyRequestAttackDefense)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + DAT_GameSynchronyState::instance.DAT_GameCommandParam2, + DAT_GameSynchronyState::instance.DAT_GameCommandParam3, + DAT_GameSynchronyState::instance.DAT_GameCommandParam4); + break; + case 1: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyRequestingGoods)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + DAT_GameSynchronyState::instance.DAT_GameCommandParam2, + DAT_GameSynchronyState::instance.DAT_GameCommandParam3, + DAT_GameSynchronyState::instance.DAT_GameCommandParam4); + break; + case 2: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyGoodsRequest)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + (OpenSHC::Game::Resources::ResourceType)DAT_GameSynchronyState::instance.DAT_GameCommandParam2, + DAT_GameSynchronyState::instance.DAT_GameCommandParam3, + DAT_GameSynchronyState::instance.DAT_GameCommandParam4); + break; + case 3: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyDeniesRequest)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + DAT_GameSynchronyState::instance.DAT_GameCommandParam4); + break; + case 4: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyAcceptsRequest)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + DAT_GameSynchronyState::instance.DAT_GameCommandParam4); + break; + case 5: + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::ProcessAllyDeniesRequest2)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + DAT_GameSynchronyState::instance.DAT_GameCommandParam4); + break; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 49d0a41fe3..d151dd4983 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22977,7 +22977,7 @@ SHC_3BB0A8C1_0x00485F20 | 0.0% | Pending SHC_3BB0A8C1_0x00486040 | 0.0% | Pending -SHC_3BB0A8C1_0x00486140 | 0.0% | Pending +SHC_3BB0A8C1_0x00486140 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00486304 | 0.0% | Pending From 3eaeba0cbd88459a0d8be0f7c3268a5354683d3c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 04:02:53 +0100 Subject: [PATCH 05/45] reimplement: SHC_3BB0A8C1_0x00489C80 100.0% Reimplemented CommandLoadMapHeader, from gynt's draft on reimpl/Synchrony-Commands (604e1bce3, 96.2% there; the file was last changed in 4242ae2ab, "Synchrony/Commands: drop the hand-written /GS cookie"). reccmp 100.0 (normalized 100.0). quick_diff 104/104 at 0.9904 (the draft: 0.9808 on main's headers); the rest is the /GS cookie load, which reccmp is told to ignore. What the match needed: the map name lookup is written inside the call that converts it, multiByteToWideCharWithSize(wideMapName, mapNames_getLoadedMapNameForIndex(...), 1000). The original pushes the 1000 before it calls the lookup; with the name in a local first, as in the draft, the 1000 is pushed after the call. The checksum's lookup is nested the same way. Wilps' version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already nests the first lookup like this. The buffers' sizes are the original's frame: 0xfc8 = 4 (checksum) + 4 (index) + 2020 (WCHAR[1010]) + 2008 (char[2008]) + 4 (cookie). mapChecksum and wideMapName serve both halves: with one local per half the frame grows to 0x17b0 and gets a _chkstk call (quick_diff -s 0.8134 with 105 instructions, against 0.9519 with 104). mapIndex and mapName are declared where they are first filled. DAT_CommandSize keeps the original's 1008 (the three parameters take 2008 bytes); its comment says the value is the original's. Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return, and the locals have names (mapChecksum, mapIndex, wideMapName, mapName). Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/CommandLoadMapHeader.cpp | 79 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/CommandLoadMapHeader.cpp diff --git a/src/OpenSHC/Synchrony/Commands/CommandLoadMapHeader.cpp b/src/OpenSHC/Synchrony/Commands/CommandLoadMapHeader.cpp new file mode 100644 index 0000000000..a70699fbf6 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/CommandLoadMapHeader.cpp @@ -0,0 +1,79 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Util/WideCharMultiByteState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_WideCharMultiByteState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00489C80 + void Commands::CommandLoadMapHeader() + { + dword mapChecksum; + WCHAR wideMapName[1010]; + // the original's value + DAT_GameSynchronyState::instance.DAT_CommandSize = 1008; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + // the map's name (1000 wide characters), its checksum and its index in the sender's map list + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::multiByteToWideCharWithSize, + DAT_WideCharMultiByteState::ptr)(wideMapName, + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0), + 1000); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideMapName, 2000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + mapChecksum = MACRO_CALL_MEMBER( + OpenSHC::IO::ResourceManager_Func::getChecksumOfMapByName, DAT_ResourceManager::ptr)( + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0)); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&mapChecksum, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideMapName, 2000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + char mapName[2008]; + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::wideCharToMultiByteWithSize, + DAT_WideCharMultiByteState::ptr)(mapName, wideMapName, 1000); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&mapChecksum, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + int mapIndex; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&mapIndex, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + // a client whose copy of the map differs tells the host so + if (!DAT_GameSynchronyState::instance.isHost + && MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::getChecksumOfMapByName, DAT_ResourceManager::ptr)( + mapName) + != mapChecksum) { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 0; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = mapIndex; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_ACKNOLEDGE_MAP_EXISTENCE); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d151dd4983..7e07d2742f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23107,7 +23107,7 @@ SHC_3BB0A8C1_0x00489A10 | 0.0% | Pending SHC_3BB0A8C1_0x00489AC0 | 0.0% | Pending -SHC_3BB0A8C1_0x00489C80 | 0.0% | Pending +SHC_3BB0A8C1_0x00489C80 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00489E30 | 0.0% | Pending From 12835b7cce3b08c0c5ad5f56852f525843959ae2 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 03:31:45 +0100 Subject: [PATCH 06/45] reimplement: SHC_3BB0A8C1_0x00485C10 100.0% Reimplemented StartSendingMapFile, from gynt's draft on reimpl/Synchrony-Commands (cf8d0fd43 and c48c8e600 at 80.5%, b6a3f5064 at 93.6%, his newest commit on the file; the branch's status line reads 80.5%). reccmp 100.0 (normalized 100.0), quick_diff 46/46 at 1.0000 (the draft: 0.9783 on main's headers). On main the draft needed one rename to compile: field282_0x109d98 is mapTransferStatePerPlayer. The name is gynt's, from his 51126b793 ("names: four GameSynchronyState lobby and map-transfer fields", 2026-10-05); main has it since the Ghidra sync b734082c3 (#260). What the match needed: the host's note of the answer is an if/else that stores 2 or 1. The draft's `(local_1 != 0) + 1` is added in 16 bits now that the field is a short (add dx, 1); the original adds in 32 bits (add edx, 1) and stores dx, which is what the if/else compiles to. Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return, local_1 is `hasMap`, hasMap and isHost are tested by truth and the loop bound is countof(). Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/StartSendingMapFile.cpp | 58 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/StartSendingMapFile.cpp diff --git a/src/OpenSHC/Synchrony/Commands/StartSendingMapFile.cpp b/src/OpenSHC/Synchrony/Commands/StartSendingMapFile.cpp new file mode 100644 index 0000000000..07615c3f84 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/StartSendingMapFile.cpp @@ -0,0 +1,58 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00485C10 + void Commands::StartSendingMapFile() + { + DAT_GameSynchronyState::instance.DAT_CommandSize = 1; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 1, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + char hasMap; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&hasMap, 1, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + // the host notes who has the map (2) and who waits for it (1) + if (DAT_GameSynchronyState::instance.isHost) { + if (hasMap) { + DAT_GameSynchronyState::instance + .mapTransferStatePerPlayer[DAT_GameSynchronyState::instance.protocolInvokerPlayerID] = 2; + } else { + DAT_GameSynchronyState::instance + .mapTransferStatePerPlayer[DAT_GameSynchronyState::instance.protocolInvokerPlayerID] = 1; + } + } + // once every player has a state, the dialog that sends the map opens + for (int playerID = 1; playerID < countof(DAT_GameSynchronyState::instance.mapTransferStatePerPlayer); + ++playerID) { + if (DAT_GameSynchronyState::instance.mapTransferStatePerPlayer[playerID] == 0) { + return; + } + } + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, DAT_MenuModalComposition1::ptr)( + OpenSHC::UI::Enums::MMT_SEND_MAP_TO, FALSE); + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7e07d2742f..d8183fac95 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22967,7 +22967,7 @@ SHC_3BB0A8C1_0x00485C01 | 0.0% | Pending SHC_3BB0A8C1_0x00485C02 | 0.0% | Pending -SHC_3BB0A8C1_0x00485C10 | 0.0% | Pending +SHC_3BB0A8C1_0x00485C10 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00485CC0 | 0.0% | Pending From 507b1ec90de8c878043c3c8079d2a4f9554b00ca Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 03:31:46 +0100 Subject: [PATCH 07/45] reimplement: SHC_3BB0A8C1_0x00484F30 100.0% Reimplemented KickPlayerUnk, from gynt's draft on reimpl/Synchrony-Commands (576022058 at 86.2%, 227a8cdbd at 91.7%, his newest commit on the file). reccmp 100.0 (normalized 100.0). quick_diff 55/55 at 0.9636 (the draft: 54 instructions at 0.8991 on main's headers); the rest is the timeGetTime import call, which reccmp resolves, and quick_diff reading the sound flags as an address. What the match needed: - One RemovePositionOfPlayer call after an if / else if, where the draft had the call in each branch with a return between them. The original pops the menu call's argument before the shared call (add esp, 4 ... pop ecx), and keeps the player in eax on both paths; two calls in the source give one add esp, 8 and the player in ecx. - getFileNameOfCurrentActiveResource is called inside playSoundOnStream3Unk's argument list, so the flags are pushed before the call, as in the original. Wilps' version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already nests it like this. The AI slot is tested before it is cleared: a plain store measures quick_diff 0.8704 with 53 instructions. Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return, "insult1.wav" is s_insult1_wav_005a6e14, the sound flags are the three FLAG_SOUND_* names | 1 (as in main's playVideoOverMap) and 0x16 is 22. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/KickPlayerUnk.cpp | 69 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/KickPlayerUnk.cpp diff --git a/src/OpenSHC/Synchrony/Commands/KickPlayerUnk.cpp b/src/OpenSHC/Synchrony/Commands/KickPlayerUnk.cpp new file mode 100644 index 0000000000..09b8dcbed4 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/KickPlayerUnk.cpp @@ -0,0 +1,69 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/Audio/MSS/SoundSystem.func.hpp" +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/Synchrony/Actions.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/MenuItems/General.func.hpp" +#include "OpenSHC/Audio/mss/SoundFlagsAndLoopCountBitwiseFlagEnum.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/IO/FileResourceType.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00484F30 + void Commands::KickPlayerUnk() + { + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + DAT_GameSynchronyState::instance.DAT_CommandSize = 4; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 + == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + // the kicked player hears an insult and leaves the game + // "insult1.wav" + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_GFX_SPEECH, s_insult1_wav_005a6e14); + MACRO_CALL_MEMBER(OpenSHC::Audio::MSS::SoundSystem_Func::playSoundOnStream3Unk, DAT_SoundSystemState::ptr)( + MACRO_CALL_MEMBER( + OpenSHC::IO::ResourceManager_Func::getFileNameOfCurrentActiveResource, DAT_ResourceManager::ptr)(), + OpenSHC::Audio::MSS::FLAG_SOUND_UNINTERRUPTABLE | OpenSHC::Audio::MSS::FLAG_SOUND_UNKNOWN_FLAG_2 + | OpenSHC::Audio::MSS::FLAG_SOUND_UNKNOWN_FLAG_1 | 1); + DAT_GameSynchronyState::instance.kickedAtTime = timeGetTime(); + DAT_GameSynchronyState::instance.currentGameMode = OpenSHC::Game::GM_MULTIPLAYER_END_OF_GAME; + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; + MACRO_CALL( + OpenSHC::UI::MenuItems::General_Func::MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)(22); + } else if (DAT_GameSynchronyState::instance + .currentAIArray[DAT_GameSynchronyState::instance.DAT_GameCommandParam0] + != 0) { + // an AI player's slot is cleared, tested before the store (a plain store loses the match) + DAT_GameSynchronyState::instance.currentAIArray[DAT_GameSynchronyState::instance.DAT_GameCommandParam0] = 0; + } + MACRO_CALL(OpenSHC::Synchrony::Actions_Func::RemovePositionOfPlayer)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam0); + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d8183fac95..611731ff1c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22727,7 +22727,7 @@ SHC_3BB0A8C1_0x00484E10 | 0.0% | Pending SHC_3BB0A8C1_0x00484E70 | 0.0% | Pending -SHC_3BB0A8C1_0x00484F30 | 0.0% | Pending +SHC_3BB0A8C1_0x00484F30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00485020 | 0.0% | Pending From aff2ce3a370434f74b83a88bf95f934f9ea786d0 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 17 Nov 2026 04:30:31 +0100 Subject: [PATCH 08/45] reimplement: SHC_3BB0A8C1_0x004840C0 100.0% Reimplemented ResyncShortLayer, gynt's version as it stands on upstream's reimpl/Synchrony-Commands (ca943baa1), where the status line still reads 52.8% (Style pass, asm differs): the file was last changed in his 684e4f376 ("reimplement: SHC_3BB0A8C1_0x004840C0 100.0% Reimplemented", 2026-10-03), which left the status line of 8f145c396 in place. His fork's branch (6fa5eaa53) has the file of 5d768872f, one commit older. Taken unchanged; it compiles on main's headers as it is. With both resolver sets on it reads reccmp 100.0 (normalized 100.0). What main's style rules need on top follows in our own commit, which also sets the status line. Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/ResyncShortLayer.cpp | 199 ++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 src/OpenSHC/Synchrony/Commands/ResyncShortLayer.cpp diff --git a/src/OpenSHC/Synchrony/Commands/ResyncShortLayer.cpp b/src/OpenSHC/Synchrony/Commands/ResyncShortLayer.cpp new file mode 100644 index 0000000000..fd1a48d20d --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/ResyncShortLayer.cpp @@ -0,0 +1,199 @@ +#include "../../Synchrony.func.hpp" +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + using OpenSHC::Commands::GameCommandParameterLocation; + using OpenSHC::Commands::GameCommandParameterReadWrite; + using OpenSHC::Commands::GameCommandScheduling; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + /* + WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names + */ + /* + WARNING: Enum "DPERRInt": Some values do not have unique names + */ + /* + WARNING: Enum "MappersEnum": Some values do not have unique names + */ + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004840C0 + void Commands::ResyncShortLayer() + { + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + DAT_GameSynchronyState::instance.DAT_CommandSize = 2520; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { + case 1: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.RandomLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + case 2: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.WalkLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + case 3: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.OrganismLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + case 4: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.BuildingLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + case 5: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.UnitLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + case 6: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.EntityLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + case 7: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.CertainPathLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + case 8: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.PathConnectionLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + case 9: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.MacroLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + default: + return; + } + } else { + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + if (DAT_GameSynchronyState::instance.isHost != FALSE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { + case 1: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.RandomLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + return; + case 2: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.WalkLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + return; + case 3: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.OrganismLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + return; + case 4: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.BuildingLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + return; + case 5: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.UnitLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + return; + case 6: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.EntityLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + return; + case 7: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.CertainPathLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + return; + case 8: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.PathConnectionLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + return; + case 9: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.MacroLayer + + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + return; + default: + return; + } + return; + } + } + +} +} From c0635f98230115867d0dec20b3f553b22ce0bd61 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 04:30:33 +0100 Subject: [PATCH 09/45] style: ResyncShortLayer (0x004840C0) follows the style guide On top of gynt's version in the commit before; the code is the same, reccmp 100.0 (normalized 100.0) and quick_diff 186/186 at 1.0000 before and after. - The first include is ../Commands.func.hpp, once; the using lines and the imported block comments are gone. - The execute half is an early return (wrong action plan, or the host), and the switch cases end in break. - Each layer's chunk is `&layer[chunk * 1256]` in place of `layer + chunk * 0x4e8`, and the sizes are decimal (2512 for both `0x9d0` and `(size_t)((int)(2512))`). The nine layer numbers stay numbers: the headers have no enum for them. The status line goes to 100.0% (Reimplemented) with this commit. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/ResyncShortLayer.cpp | 261 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 126 insertions(+), 137 deletions(-) diff --git a/src/OpenSHC/Synchrony/Commands/ResyncShortLayer.cpp b/src/OpenSHC/Synchrony/Commands/ResyncShortLayer.cpp index fd1a48d20d..f020f1b43a 100644 --- a/src/OpenSHC/Synchrony/Commands/ResyncShortLayer.cpp +++ b/src/OpenSHC/Synchrony/Commands/ResyncShortLayer.cpp @@ -1,11 +1,9 @@ -#include "../../Synchrony.func.hpp" #include "../Commands.func.hpp" #include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" #include "OpenSHC/Commands/GameCommandParameterLocation.hpp" #include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" #include "OpenSHC/Commands/GameCommandScheduling.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" @@ -13,28 +11,12 @@ namespace OpenSHC { namespace Synchrony { - using OpenSHC::Commands::GameCommandParameterLocation; - using OpenSHC::Commands::GameCommandParameterReadWrite; - using OpenSHC::Commands::GameCommandScheduling; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - - /* - WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names - */ - /* - WARNING: Enum "DPERRInt": Some values do not have unique names - */ - /* - WARNING: Enum "MappersEnum": Some values do not have unique names - */ - /* - decompilerscript: committed: 2025-01-30 21:57:43.216000 - */ // FUNCTION: STRONGHOLDCRUSADER 0x004840C0 void Commands::ResyncShortLayer() { DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] .time = 0; + // the layer's number, the chunk's number and one chunk of the layer: 1256 tiles, 2512 bytes DAT_GameSynchronyState::instance.DAT_CommandSize = 2520; if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; @@ -47,151 +29,158 @@ namespace Synchrony { switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { case 1: MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.RandomLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .RandomLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; + break; case 2: MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.WalkLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .WalkLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; + break; case 3: MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.OrganismLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .OrganismLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; + break; case 4: MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.BuildingLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .BuildingLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; + break; case 5: MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.UnitLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .UnitLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; + break; case 6: MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.EntityLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .EntityLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; + break; case 7: MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.CertainPathLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .CertainPathLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; + break; case 8: MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.PathConnectionLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; + break; case 9: MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.MacroLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .MacroLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; - default: - return; - } - } else { - if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { - return; - } - if (DAT_GameSynchronyState::instance.isHost != FALSE) { - return; + break; } + return; + } + // only the clients take the host's copy of the layer + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE + || DAT_GameSynchronyState::instance.isHost) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { + case 1: MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, - OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance.RandomLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 2: MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, - OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { - case 1: - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.RandomLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - return; - case 2: - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.WalkLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - return; - case 3: - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.OrganismLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - return; - case 4: - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.BuildingLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - return; - case 5: - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.UnitLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - return; - case 6: - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.EntityLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - return; - case 7: - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.CertainPathLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - return; - case 8: - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.PathConnectionLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - (size_t)((int)(2512)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - return; - case 9: - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_TileMapState::instance.MacroLayer - + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x4e8, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - return; - default: - return; - } - return; + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance.WalkLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 3: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .OrganismLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 4: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .BuildingLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 5: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance.UnitLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 6: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance.EntityLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 7: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .CertainPathLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 8: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .PathConnectionLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 9: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance.MacroLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 1256], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 611731ff1c..738f0b6e89 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22661,7 +22661,7 @@ SHC_3BB0A8C1_0x004840B0 | 0.0% | Pending SHC_3BB0A8C1_0x004840B4 | 0.0% | Pending -SHC_3BB0A8C1_0x004840C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004840C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004843A8 | 0.0% | Pending From 00dcf99587a4d8eb4cd0ca50561df31c54f910e7 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 17 Nov 2026 04:30:33 +0100 Subject: [PATCH 10/45] reimplement: SHC_3BB0A8C1_0x0048A7C0 100.0% Reimplemented SendResyncIntLayer, gynt's version as it stands on upstream's reimpl/Synchrony-Commands (ca943baa1), where the status line still reads 87.5% (Style pass, asm differs): the file was last changed in his c8d9db835 ("reimplement: SHC_3BB0A8C1_0x0048A7C0 100.0% Reimplemented", 2026-10-03), which left the status line of 9675ea58b in place. His fork's branch (6fa5eaa53) has the older file. Taken unchanged; it compiles on main's headers as it is. With both resolver sets on it reads reccmp 100.0 (normalized 100.0). What main's style rules need on top follows in our own commit, which also sets the status line. Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/SendResyncIntLayer.cpp | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/OpenSHC/Synchrony/Commands/SendResyncIntLayer.cpp diff --git a/src/OpenSHC/Synchrony/Commands/SendResyncIntLayer.cpp b/src/OpenSHC/Synchrony/Commands/SendResyncIntLayer.cpp new file mode 100644 index 0000000000..10137cc07c --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/SendResyncIntLayer.cpp @@ -0,0 +1,70 @@ +#include "../../Synchrony.func.hpp" +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + using OpenSHC::Commands::GameCommandParameterLocation; + using OpenSHC::Commands::GameCommandParameterReadWrite; + using OpenSHC::Commands::GameCommandScheduling; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + /* + WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names + */ + /* + WARNING: Enum "DPERRInt": Some values do not have unique names + */ + /* + WARNING: Enum "MappersEnum": Some values do not have unique names + */ + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x0048A7C0 + void Commands::SendResyncIntLayer() + { + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + DAT_GameSynchronyState::instance.DAT_CommandSize = 2520; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + DAT_TileMapState::instance.LogicLayer + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x274, + 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if ((DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) + && (DAT_GameSynchronyState::instance.isHost == FALSE)) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + int layerOffset = DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x274; + MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)( + (char*)(DAT_TileMapState::instance.LogicLayer + layerOffset), 0x9d0, layerOffset); + } + } + +} +} From c287ae3634094e0570ac5c112447057e0c4c42b1 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 04:30:35 +0100 Subject: [PATCH 11/45] style: SendResyncIntLayer (0x0048A7C0) follows the style guide On top of gynt's version in the commit before; the code is the same, reccmp 100.0 (normalized 100.0) and quick_diff 55/55 at 1.0000 before and after. - The first include is ../Commands.func.hpp, once; the using lines and the imported block comments are gone. - The execute half is an early return (wrong action plan, or the host). - The chunk is `&LogicLayer[chunk * 628]` in place of `LogicLayer + chunk * 0x274`, the size is 2512 and layerOffset is `int const chunkStart`. The status line goes to 100.0% (Reimplemented) with this commit. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/SendResyncIntLayer.cpp | 48 +++++++------------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/OpenSHC/Synchrony/Commands/SendResyncIntLayer.cpp b/src/OpenSHC/Synchrony/Commands/SendResyncIntLayer.cpp index 10137cc07c..c26a826bea 100644 --- a/src/OpenSHC/Synchrony/Commands/SendResyncIntLayer.cpp +++ b/src/OpenSHC/Synchrony/Commands/SendResyncIntLayer.cpp @@ -1,4 +1,3 @@ -#include "../../Synchrony.func.hpp" #include "../Commands.func.hpp" #include "OpenSHC/Synchrony.func.hpp" @@ -6,7 +5,6 @@ #include "OpenSHC/Commands/GameCommandParameterLocation.hpp" #include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" #include "OpenSHC/Commands/GameCommandScheduling.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" @@ -14,28 +12,12 @@ namespace OpenSHC { namespace Synchrony { - using OpenSHC::Commands::GameCommandParameterLocation; - using OpenSHC::Commands::GameCommandParameterReadWrite; - using OpenSHC::Commands::GameCommandScheduling; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - - /* - WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names - */ - /* - WARNING: Enum "DPERRInt": Some values do not have unique names - */ - /* - WARNING: Enum "MappersEnum": Some values do not have unique names - */ - /* - decompilerscript: committed: 2025-01-30 21:57:43.216000 - */ // FUNCTION: STRONGHOLDCRUSADER 0x0048A7C0 void Commands::SendResyncIntLayer() { DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] .time = 0; + // two parameters, the second being the chunk's number, and one chunk of the logic layer: 628 tiles, 2512 bytes DAT_GameSynchronyState::instance.DAT_CommandSize = 2520; if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; @@ -47,23 +29,25 @@ namespace Synchrony { OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, DAT_GameSynchronyState::ptr)( - DAT_TileMapState::instance.LogicLayer + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x274, - 0x9d0, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + &DAT_TileMapState::instance.LogicLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 628], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); return; } - if ((DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) - && (DAT_GameSynchronyState::instance.isHost == FALSE)) { - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, - OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, - OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - int layerOffset = DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 0x274; - MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)( - (char*)(DAT_TileMapState::instance.LogicLayer + layerOffset), 0x9d0, layerOffset); + // only the clients take the host's copy of the layer + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE + || DAT_GameSynchronyState::instance.isHost) { + return; } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + int const chunkStart = DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 628; + MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)( + (char*)&DAT_TileMapState::instance.LogicLayer[chunkStart], 2512, chunkStart); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 738f0b6e89..1475a338c2 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23127,7 +23127,7 @@ SHC_3BB0A8C1_0x0048A510 | 0.0% | Pending SHC_3BB0A8C1_0x0048A710 | 0.0% | Pending -SHC_3BB0A8C1_0x0048A7C0 | 0.0% | Pending +SHC_3BB0A8C1_0x0048A7C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048A8A0 | 0.0% | Pending From 6a0d1ae11ef3de1b0e434fab213904d221e9bdb5 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 17 Nov 2026 04:30:35 +0100 Subject: [PATCH 12/45] reimplement: SHC_3BB0A8C1_0x00480BE0 100.0% Reimplemented AnnounceTeamsAndPositions, gynt's version as it stands on upstream's reimpl/Synchrony-Commands (ca943baa1), where the status line still reads 80.7% (Style pass, asm differs): the file was last changed in his 52aa7027c ("reimplement: SHC_3BB0A8C1_0x00480BE0 97.5% Reimplemented", 2026-10-03), which made the nine team bytes a memcpy and left the status line of eb34b1d21 in place. The file also carries his 9bf755f36 ("reimplement: SHC_3BB0A8C1_0x0048A2E0 86.6% Reimplemented", whose body is about this function: it restored the single 9-byte buffer). His fork's branch (6fa5eaa53) has the older file. Taken unchanged; it compiles on main's headers as it is. With both resolver sets on it now reads reccmp 100.0 (normalized 100.0), where his commit measured 97.5. What main's style rules need on top follows in our own commit, which also sets the status line. Co-Authored-By: Claude Fable 5.2 --- .../Commands/AnnounceTeamsAndPositions.cpp | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/OpenSHC/Synchrony/Commands/AnnounceTeamsAndPositions.cpp diff --git a/src/OpenSHC/Synchrony/Commands/AnnounceTeamsAndPositions.cpp b/src/OpenSHC/Synchrony/Commands/AnnounceTeamsAndPositions.cpp new file mode 100644 index 0000000000..6f4fbe39b1 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/AnnounceTeamsAndPositions.cpp @@ -0,0 +1,94 @@ +#include "../../Synchrony.func.hpp" +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + using OpenSHC::Commands::GameCommandParameterLocation; + using OpenSHC::Commands::GameCommandParameterReadWrite; + using OpenSHC::Commands::GameCommandScheduling; + + /* + WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names + */ + /* + WARNING: Enum "DPERRInt": Some values do not have unique names + */ + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x00480BE0 + void Commands::AnnounceTeamsAndPositions() + { + int _isHost; + byte local_10[9]; + DAT_GameSynchronyState::instance.DAT_CommandSize = 33; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue + + DAT_GameSynchronyState::instance.currentPlayerSlotID, + 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + DAT_GameSynchronyState::instance.currentAIArray + DAT_GameSynchronyState::instance.currentPlayerSlotID, + 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.aiVariationArray + + DAT_GameSynchronyState::instance.currentPlayerSlotID, + 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.isHost, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray, 9, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.playerPositionsArray, 8, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + ; + return; + } + if ((DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) + && (DAT_GameSynchronyState::instance.protocolInvokerPlayerID - 1U <= 7)) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue + + DAT_GameSynchronyState::instance.protocolInvokerPlayerID, + 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + DAT_GameSynchronyState::instance.currentAIArray + DAT_GameSynchronyState::instance.currentPlayerSlotID, + 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.aiVariationArray + + DAT_GameSynchronyState::instance.currentPlayerSlotID, + 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&_isHost, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(local_10, 9, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.playerPositionsArray, 8, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (_isHost != 0) { + memcpy(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray, local_10, 9); + } + }; + } + +} +} From d8e536f81e777c63c7e499aa0d3b7cb247d275af Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 04:30:36 +0100 Subject: [PATCH 13/45] style: AnnounceTeamsAndPositions (0x00480BE0) follows the style guide On top of gynt's version in the commit before; the code is the same, reccmp 100.0 (normalized 100.0) and quick_diff 121/121 at 0.9917 before and after (the rest is the /GS cookie load, which reccmp is told to ignore). - The first include is ../Commands.func.hpp, once; the using lines and the imported block comments are gone. - The execute half is an early return, and the sender test is `< 1 || > 8` in place of `- 1U <= 7`. - The slot values are `&array[slot]` in place of `array + slot`, and every size in the file is sizeof() of what is read or written. - `_isHost` is `BOOLEnum senderIsHost`, tested by truth; `byte local_10[9]` is `char receivedGroups[9]`, the type of DAT_PlayerGroupArray. Both are declared where they are filled. The status line goes to 100.0% (Reimplemented) with this commit. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/AnnounceTeamsAndPositions.cpp | 118 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/OpenSHC/Synchrony/Commands/AnnounceTeamsAndPositions.cpp b/src/OpenSHC/Synchrony/Commands/AnnounceTeamsAndPositions.cpp index 6f4fbe39b1..8e5659314f 100644 --- a/src/OpenSHC/Synchrony/Commands/AnnounceTeamsAndPositions.cpp +++ b/src/OpenSHC/Synchrony/Commands/AnnounceTeamsAndPositions.cpp @@ -1,4 +1,3 @@ -#include "../../Synchrony.func.hpp" #include "../Commands.func.hpp" #include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" @@ -11,83 +10,84 @@ namespace OpenSHC { namespace Synchrony { - using OpenSHC::Commands::GameCommandParameterLocation; - using OpenSHC::Commands::GameCommandParameterReadWrite; - using OpenSHC::Commands::GameCommandScheduling; - - /* - WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names - */ - /* - WARNING: Enum "DPERRInt": Some values do not have unique names - */ - /* - decompilerscript: committed: 2025-01-30 21:57:43.216000 - */ // FUNCTION: STRONGHOLDCRUSADER 0x00480BE0 void Commands::AnnounceTeamsAndPositions() { - int _isHost; - byte local_10[9]; + // three values of the sender's slot, whether the sender is the host, the nine teams and the eight positions DAT_GameSynchronyState::instance.DAT_CommandSize = 33; DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] .time = 0; if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue - + DAT_GameSynchronyState::instance.currentPlayerSlotID, - 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, DAT_GameSynchronyState::ptr)( - DAT_GameSynchronyState::instance.currentAIArray + DAT_GameSynchronyState::instance.currentPlayerSlotID, - 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + &DAT_GameSynchronyState::instance + .DAT_PlayerSlotArraySomeValue[DAT_GameSynchronyState::instance.currentPlayerSlotID], + sizeof(DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[0]), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.aiVariationArray - + DAT_GameSynchronyState::instance.currentPlayerSlotID, - 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::ptr)( + &DAT_GameSynchronyState::instance.currentAIArray[DAT_GameSynchronyState::instance.currentPlayerSlotID], + sizeof(DAT_GameSynchronyState::instance.currentAIArray[0]), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.isHost, 4, + DAT_GameSynchronyState::ptr)( + &DAT_GameSynchronyState::instance + .aiVariationArray[DAT_GameSynchronyState::instance.currentPlayerSlotID], + sizeof(DAT_GameSynchronyState::instance.aiVariationArray[0]), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray, 9, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.isHost, + sizeof(DAT_GameSynchronyState::instance.isHost), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray, + sizeof(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.playerPositionsArray, 8, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.playerPositionsArray, + sizeof(DAT_GameSynchronyState::instance.playerPositionsArray), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; - ; return; } - if ((DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) - && (DAT_GameSynchronyState::instance.protocolInvokerPlayerID - 1U <= 7)) { - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue - + DAT_GameSynchronyState::instance.protocolInvokerPlayerID, - 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)( - DAT_GameSynchronyState::instance.currentAIArray + DAT_GameSynchronyState::instance.currentPlayerSlotID, - 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.aiVariationArray - + DAT_GameSynchronyState::instance.currentPlayerSlotID, - 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&_isHost, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(local_10, 9, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, - OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.playerPositionsArray, 8, - OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - if (_isHost != 0) { - memcpy(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray, local_10, 9); - } - }; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE + || DAT_GameSynchronyState::instance.protocolInvokerPlayerID < 1 + || DAT_GameSynchronyState::instance.protocolInvokerPlayerID > 8) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_GameSynchronyState::instance + .DAT_PlayerSlotArraySomeValue[DAT_GameSynchronyState::instance.protocolInvokerPlayerID], + sizeof(DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[0]), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_GameSynchronyState::instance.currentAIArray[DAT_GameSynchronyState::instance.currentPlayerSlotID], + sizeof(DAT_GameSynchronyState::instance.currentAIArray[0]), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_GameSynchronyState::instance.aiVariationArray[DAT_GameSynchronyState::instance.currentPlayerSlotID], + sizeof(DAT_GameSynchronyState::instance.aiVariationArray[0]), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + BOOLEnum senderIsHost; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&senderIsHost, sizeof(senderIsHost), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + char receivedGroups[9]; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(receivedGroups, sizeof(receivedGroups), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.playerPositionsArray, + sizeof(DAT_GameSynchronyState::instance.playerPositionsArray), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + // only the host's teams are taken over + if (senderIsHost) { + memcpy(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray, receivedGroups, + sizeof(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray)); + } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1475a338c2..6f514ed506 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22441,7 +22441,7 @@ SHC_3BB0A8C1_0x00480980 | 0.0% | Pending SHC_3BB0A8C1_0x00480B10 | 0.0% | Pending -SHC_3BB0A8C1_0x00480BE0 | 0.0% | Pending +SHC_3BB0A8C1_0x00480BE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00480DB0 | 0.0% | Pending From 844256ba0471ab04f886c9b9138b2b00775550cc Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 04:30:37 +0100 Subject: [PATCH 14/45] reimplement: SHC_3BB0A8C1_0x00480980 100.0% Reimplemented ShareGameSeedAndMultiplayerSettingsAndStartGame, from gynt's draft on reimpl/Synchrony-Commands (6c834c08d, 93.9% there; the file was last changed in 4242ae2ab, "Synchrony/Commands: drop the hand-written /GS cookie"). On main's headers the draft reads reccmp 96.9 (normalized 88.5), and now 100.0 (normalized 100.0). quick_diff 98/98 at 0.9898 (the draft: 0.9592); the rest is the /GS cookie load, which reccmp is told to ignore. What the match needed: - The map name lookup is written inside the call that converts it, so the 1000 is pushed before the lookup is called, as in the original. - The map index is `relative + scroll offset`: the original loads the relative selection first. quick_diff can't see this (both are globals to it); the compiler's listing and reccmp can. With scroll + relative reccmp reads 98.0 (normalized 90.9); a comment line keeps the order from being "fixed". Fix against the draft on main's headers: the draft read DAT_ArrayOfMapIndices[scroll + relative - 1]. Its branch has the array at 0x884 with 500 entries; main has it at 0x880 with 501, so on main the `- 1` reads the entry before the one the original reads (the original's address is the array's start plus the sum). Wilps' version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already nests the lookup and indexes the list without the `- 1` (his header has it at 0x880); his sum is scroll + relative. Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return, and local_7d8 is wideMapName. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ...SeedAndMultiplayerSettingsAndStartGame.cpp | 75 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/ShareGameSeedAndMultiplayerSettingsAndStartGame.cpp diff --git a/src/OpenSHC/Synchrony/Commands/ShareGameSeedAndMultiplayerSettingsAndStartGame.cpp b/src/OpenSHC/Synchrony/Commands/ShareGameSeedAndMultiplayerSettingsAndStartGame.cpp new file mode 100644 index 0000000000..b582c19b4f --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/ShareGameSeedAndMultiplayerSettingsAndStartGame.cpp @@ -0,0 +1,75 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/Actions.func.hpp" +#include "OpenSHC/Util/WideCharMultiByteState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_WideCharMultiByteState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00480980 + void Commands::ShareGameSeedAndMultiplayerSettingsAndStartGame() + { + WCHAR wideMapName[1002]; + // the random seed, the autosave interval, the game speed and the map's name (1000 wide characters) + DAT_GameSynchronyState::instance.DAT_CommandSize = 2012; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&SEC_RNG::instance.seed, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.skirmishAutoSaveEveryMinutes, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.skirmishGameSpeedLevel, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + // the map index sum is relative + scroll offset here (the other order loses the match) + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::multiByteToWideCharWithSize, + DAT_WideCharMultiByteState::ptr)(wideMapName, + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected + + DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset]), + 1000); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideMapName, 2000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&SEC_RNG::instance.seed, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.skirmishAutoSaveEveryMinutes, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.skirmishGameSpeedLevel, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideMapName, 2000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::wideCharToMultiByteWithSize, + DAT_WideCharMultiByteState::ptr)(DAT_GameSynchronyState::instance.mapName, wideMapName, 1000); + MACRO_CALL_MEMBER( + OpenSHC::Synchrony::GameSynchronyState_Func::setSessionDescription, DAT_GameSynchronyState::ptr)(); + MACRO_CALL(OpenSHC::UI::Actions_Func::LaunchSkirmishGame)(0); + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6f514ed506..44a6875f14 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22437,7 +22437,7 @@ SHC_3BB0A8C1_0x00480680 | 0.0% | Pending SHC_3BB0A8C1_0x00480710 | 0.0% | Pending -SHC_3BB0A8C1_0x00480980 | 0.0% | Pending +SHC_3BB0A8C1_0x00480980 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00480B10 | 0.0% | Pending From 8b1228f80cbb174214cc6fc5972951666fa06270 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 03:31:58 +0100 Subject: [PATCH 15/45] reimplement: SHC_3BB0A8C1_0x00483290 100.0% Reimplemented CommandChangeMapSelection, from gynt's draft on reimpl/Synchrony-Commands (3e3269dfb at 93.0%, bcac16532 at 95.3%, his newest commit on the file). On main's headers the draft reads reccmp 93.0 (normalized 85.4), and now 100.0 (normalized 100.0). quick_diff 86/86 at 0.9884 (the draft: 0.9535); the rest is the /GS cookie load, which reccmp is told to ignore. What the match needed: the map name lookup is written inside the call that converts it, so the 1000 is pushed before the map index and the lookup's call, as in the original. The map index keeps its if/else and its local: with `int mapIndex = 0;` and one if, quick_diff reads 0.9357 with 85 instructions. Fix against the draft on main's headers: the draft read DAT_ArrayOfMapIndices[selectionIndex - 1]. Its branch has the array at 0x884 with 500 entries; main has it at 0x880 with 501, so on main the `- 1` reads the entry before the one the original reads. Wilps' version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) indexes the list without the `- 1` too (his header has it at 0x880); it keeps the lookup in a local. Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return, _mapName is wideMapName and the command size is decimal. isSkirmishTrail is compared with TRUE, as the original compares it with 1 (main does the same in MenuItemActionHandler_InGameMenu_MainButtons). Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/CommandChangeMapSelection.cpp | 76 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/CommandChangeMapSelection.cpp diff --git a/src/OpenSHC/Synchrony/Commands/CommandChangeMapSelection.cpp b/src/OpenSHC/Synchrony/Commands/CommandChangeMapSelection.cpp new file mode 100644 index 0000000000..a39d8d503b --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/CommandChangeMapSelection.cpp @@ -0,0 +1,76 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/Util/WideCharMultiByteState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Game/GameMode.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_WideCharMultiByteState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00483290 + void Commands::CommandChangeMapSelection() + { + int selectionIndex; + WCHAR wideMapName[1002]; + // the selected row of the map list and the map's name (1000 wide characters) + DAT_GameSynchronyState::instance.DAT_CommandSize = 2004; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + selectionIndex = DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&selectionIndex, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + int mapIndex; + if (selectionIndex < 0) { + mapIndex = 0; + } else { + mapIndex = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[selectionIndex]; + } + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::multiByteToWideCharWithSize, + DAT_WideCharMultiByteState::ptr)(wideMapName, + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(mapIndex), + 1000); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideMapName, 2000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&selectionIndex, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + // a skirmish trail game keeps its own map name; compared with TRUE: the original tests isSkirmishTrail == 1 + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER + || DAT_GameCore::instance.isSkirmishTrail != TRUE) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideMapName, 2000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::wideCharToMultiByteWithSize, + DAT_WideCharMultiByteState::ptr)(DAT_GameSynchronyState::instance.mapName, wideMapName, 1000); + } + if (selectionIndex < 0) { + DAT_GameSynchronyState::instance.mapName[0] = '\0'; + } + MACRO_CALL(OpenSHC::UI::Rendering_Func::DisplayMapDescriptionAndAllocatePlayersToSlots)(); + DAT_GameSynchronyState::instance.skirmishRelated1 = -1; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 44a6875f14..b01af4a0ad 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22573,7 +22573,7 @@ SHC_3BB0A8C1_0x00482BB0 | 0.0% | Pending SHC_3BB0A8C1_0x00482C80 | 0.0% | Pending -SHC_3BB0A8C1_0x00483290 | 0.0% | Pending +SHC_3BB0A8C1_0x00483290 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004833F0 | 0.0% | Pending From c5ba0dd358597a9a01cc7ed8105bf515f8986c98 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 17 Nov 2026 04:30:38 +0100 Subject: [PATCH 16/45] reimplement: SHC_3BB0A8C1_0x00484B10 100.0% Reimplemented RemoveTowerSiegeEngine, gynt's version as it stands on upstream's reimpl/Synchrony-Commands (ca943baa1), where the status line still reads 75.0% (Style pass, asm differs): the file was last changed in his d47a46955 ("reimplement: SHC_3BB0A8C1_0x00484B10 100.0% Reimplemented", 2026-10-03), which left the status line in place. His fork's branch (6fa5eaa53) has the older file. One change so that it builds on main: Building::containsSiegeMangonel1OrBallista2 is defensiveTowerEngineType there (two lines); nothing else changed. With both resolver sets on it reads reccmp 100.0 (normalized 100.0). What main's style rules need on top follows in our own commit, which also sets the status line. Co-Authored-By: Claude Fable 5.2 --- .../Commands/RemoveTowerSiegeEngine.cpp | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/OpenSHC/Synchrony/Commands/RemoveTowerSiegeEngine.cpp diff --git a/src/OpenSHC/Synchrony/Commands/RemoveTowerSiegeEngine.cpp b/src/OpenSHC/Synchrony/Commands/RemoveTowerSiegeEngine.cpp new file mode 100644 index 0000000000..fc3565eb26 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/RemoveTowerSiegeEngine.cpp @@ -0,0 +1,98 @@ +#include "../../Synchrony.func.hpp" +#include "../Commands.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeShort.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + using OpenSHC::Commands::GameCommandParameterLocation; + using OpenSHC::Commands::GameCommandParameterReadWrite; + using OpenSHC::Commands::GameCommandScheduling; + using OpenSHC::Map::Units::UnitLogicState; + using OpenSHC::Map::Units::UnitType; + using OpenSHC::Map::Units::UnitTypeShort; + + /* + WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names + */ + /* + WARNING: Enum "DPERRInt": Some values do not have unique names + */ + /* + WARNING: Enum "MappersEnum": Some values do not have unique names + */ + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x00484B10 + void Commands::RemoveTowerSiegeEngine() + { + UnitTypeShort UVar1; + int iVar2; + int _entity; + short local_4[2]; + DAT_GameSynchronyState::instance.DAT_CommandSize = 4; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(local_4, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = (int)local_4[0]; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(local_4, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + _entity = (int)local_4[0]; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = _entity; + switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { + case 2: + UVar1 = DAT_UnitsState::instance.units[_entity].unitType; + iVar2 = (int)DAT_TileMapState::instance.BuildingLayer[DAT_UnitsState::instance.units[_entity].tile]; + if (UVar1 == OpenSHC::Map::Units::UT_S_MANGONEL) { + if (iVar2 != 0) { + DAT_BuildingsState::instance.buildings[iVar2].defensiveTowerEngineType = 0; + } + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::giveBackResourceForDestroyedBuilding, + DAT_BuildingsState::ptr)( + -3, (int)((int)(DAT_GameSynchronyState::instance.protocolInvokerPlayerID)), 100); + } else if (UVar1 == OpenSHC::Map::Units::UT_S_BALLISTA) { + if (iVar2 != 0) { + DAT_BuildingsState::instance.buildings[iVar2].defensiveTowerEngineType = 0; + } + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::giveBackResourceForDestroyedBuilding, + DAT_BuildingsState::ptr)( + -4, (int)((int)(DAT_GameSynchronyState::instance.protocolInvokerPlayerID)), 100); + } + DAT_UnitsState::instance.units[_entity].logicalState = OpenSHC::Map::Units::ULS_REMOVE; + return; + case 1: + DAT_EntityState::instance.entityArray[_entity].logicalState = 3; + return; + } + } + +} +} From 47afdcd2805ce63f53b29d0942472eabb36f5e49 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 05:24:38 +0100 Subject: [PATCH 17/45] style: RemoveTowerSiegeEngine (0x00484B10) follows the style guide On top of gynt's version in the commit before; the code is the same, reccmp 100.0 (normalized 100.0) and quick_diff 81/81 at 1.0000 before and after. - The first include is ../Commands.func.hpp, once; the using lines and the imported block comments are gone. - The switch cases end in break, and the doubled `(int)((int)(...))` casts are gone. - Names: `short local_4[2]` is `short readBuffer`, `_entity` is `id` (a unit's or an entity's, by the kind), `iVar2` is `buildingID` and `UVar1` is `unitType`, each declared where it gets its value. unitType stays a UnitTypeShort: as an int it is loaded with movsx and compared in 32 bits, where the original compares cx (quick_diff 0.9630). - A comment line names the two refund codes, -3 for a tower mangonel and -4 for a tower ballista. The engine field is cleared with 0: DefensiveTowerEngineType has names for the mangonel (1) and the ballista (2) only. The status line goes to 100.0% (Reimplemented) with this commit. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/RemoveTowerSiegeEngine.cpp | 73 +++++++------------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/OpenSHC/Synchrony/Commands/RemoveTowerSiegeEngine.cpp b/src/OpenSHC/Synchrony/Commands/RemoveTowerSiegeEngine.cpp index fc3565eb26..4f611b92d7 100644 --- a/src/OpenSHC/Synchrony/Commands/RemoveTowerSiegeEngine.cpp +++ b/src/OpenSHC/Synchrony/Commands/RemoveTowerSiegeEngine.cpp @@ -1,4 +1,3 @@ -#include "../../Synchrony.func.hpp" #include "../Commands.func.hpp" #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" @@ -19,32 +18,10 @@ namespace OpenSHC { namespace Synchrony { - using OpenSHC::Commands::GameCommandParameterLocation; - using OpenSHC::Commands::GameCommandParameterReadWrite; - using OpenSHC::Commands::GameCommandScheduling; - using OpenSHC::Map::Units::UnitLogicState; - using OpenSHC::Map::Units::UnitType; - using OpenSHC::Map::Units::UnitTypeShort; - - /* - WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names - */ - /* - WARNING: Enum "DPERRInt": Some values do not have unique names - */ - /* - WARNING: Enum "MappersEnum": Some values do not have unique names - */ - /* - decompilerscript: committed: 2025-01-30 21:57:43.216000 - */ // FUNCTION: STRONGHOLDCRUSADER 0x00484B10 void Commands::RemoveTowerSiegeEngine() { - UnitTypeShort UVar1; - int iVar2; - int _entity; - short local_4[2]; + // what to remove (1 an entity, 2 a unit) and its ID DAT_GameSynchronyState::instance.DAT_CommandSize = 4; if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, @@ -58,39 +35,43 @@ namespace Synchrony { if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { return; } + short readBuffer; MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(local_4, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)(&readBuffer, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = (int)local_4[0]; + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = readBuffer; MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(local_4, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)(&readBuffer, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - _entity = (int)local_4[0]; - DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = _entity; + int const id = readBuffer; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = id; switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { - case 2: - UVar1 = DAT_UnitsState::instance.units[_entity].unitType; - iVar2 = (int)DAT_TileMapState::instance.BuildingLayer[DAT_UnitsState::instance.units[_entity].tile]; - if (UVar1 == OpenSHC::Map::Units::UT_S_MANGONEL) { - if (iVar2 != 0) { - DAT_BuildingsState::instance.buildings[iVar2].defensiveTowerEngineType = 0; + case 2: { + // a unit is removed; a tower's mangonel or ballista also clears the tower's engine and refunds its cost + OpenSHC::Map::Units::UnitTypeShort const unitType = DAT_UnitsState::instance.units[id].unitType; + int const buildingID = DAT_TileMapState::instance.BuildingLayer[DAT_UnitsState::instance.units[id].tile]; + if (unitType == OpenSHC::Map::Units::UT_S_MANGONEL) { + if (buildingID != 0) { + DAT_BuildingsState::instance.buildings[buildingID].defensiveTowerEngineType = 0; } + // -3 asks for a tower mangonel's cost MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::giveBackResourceForDestroyedBuilding, - DAT_BuildingsState::ptr)( - -3, (int)((int)(DAT_GameSynchronyState::instance.protocolInvokerPlayerID)), 100); - } else if (UVar1 == OpenSHC::Map::Units::UT_S_BALLISTA) { - if (iVar2 != 0) { - DAT_BuildingsState::instance.buildings[iVar2].defensiveTowerEngineType = 0; + DAT_BuildingsState::ptr)(-3, DAT_GameSynchronyState::instance.protocolInvokerPlayerID, 100); + } else if (unitType == OpenSHC::Map::Units::UT_S_BALLISTA) { + if (buildingID != 0) { + DAT_BuildingsState::instance.buildings[buildingID].defensiveTowerEngineType = 0; } + // -4 asks for a tower ballista's cost MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::giveBackResourceForDestroyedBuilding, - DAT_BuildingsState::ptr)( - -4, (int)((int)(DAT_GameSynchronyState::instance.protocolInvokerPlayerID)), 100); + DAT_BuildingsState::ptr)(-4, DAT_GameSynchronyState::instance.protocolInvokerPlayerID, 100); } - DAT_UnitsState::instance.units[_entity].logicalState = OpenSHC::Map::Units::ULS_REMOVE; - return; + DAT_UnitsState::instance.units[id].logicalState = OpenSHC::Map::Units::ULS_REMOVE; + break; + } case 1: - DAT_EntityState::instance.entityArray[_entity].logicalState = 3; - return; + // 3 marks it destroyed, as markEntityDestroyed does + DAT_EntityState::instance.entityArray[id].logicalState = 3; + break; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b01af4a0ad..79510c5f96 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22717,7 +22717,7 @@ SHC_3BB0A8C1_0x00484A00 | 0.0% | Pending SHC_3BB0A8C1_0x00484A70 | 0.0% | Pending -SHC_3BB0A8C1_0x00484B10 | 0.0% | Pending +SHC_3BB0A8C1_0x00484B10 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00484C40 | 0.0% | Pending From 2ec0bbe726cdaf79e3f05cfc0b3cf3545ce60e44 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 17 Nov 2026 04:30:40 +0100 Subject: [PATCH 18/45] reimplement: SHC_3BB0A8C1_0x00485140 100.0% Reimplemented VoteKick_K_D_B_G_J, gynt's version as it stands on upstream's reimpl/Synchrony-Commands (ca943baa1), where the status line still reads 52.8% (Style pass, asm differs): the file was last changed in his 42cfbd8bd ("reimplement: SHC_3BB0A8C1_0x00485140 100.0% Reimplemented", 2026-10-03), which left the status line in place. His fork's branch (6fa5eaa53) has the older file. One change so that it builds on main: GameSynchronyState::DPLAYX_4A is an IDirectPlay4* there, so the test against `(IDirectPlay4A**)0x0` is a test against NULL (one line); nothing else changed. With both resolver sets on it reads reccmp 100.0 (normalized 100.0). What main's style rules need on top follows in our own commit, which also sets the status line. Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/VoteKick_K_D_B_G_J.cpp | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/OpenSHC/Synchrony/Commands/VoteKick_K_D_B_G_J.cpp diff --git a/src/OpenSHC/Synchrony/Commands/VoteKick_K_D_B_G_J.cpp b/src/OpenSHC/Synchrony/Commands/VoteKick_K_D_B_G_J.cpp new file mode 100644 index 0000000000..bc5e28c18e --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/VoteKick_K_D_B_G_J.cpp @@ -0,0 +1,69 @@ +#include "../../Synchrony.func.hpp" +#include "../Commands.func.hpp" + +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/MenuItems/General.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + using OpenSHC::Commands::GameCommandParameterLocation; + using OpenSHC::Commands::GameCommandParameterReadWrite; + using OpenSHC::Commands::GameCommandScheduling; + using OpenSHC::UI::Enums::MenuViewType; + + /* + WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names + */ + /* + WARNING: Enum "DPERRInt": Some values do not have unique names + */ + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x00485140 + void Commands::VoteKick_K_D_B_G_J() + { + DAT_GameSynchronyState::instance.DAT_CommandSize = 4; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + if (DAT_GameSynchronyState::instance.DPLAYX_4A != NULL) { + ((IDirectPlay4A*)DAT_GameSynchronyState::instance.DPLAYX_4A)->CancelMessage(0, 0); + } + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0) { + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; + MACRO_CALL( + OpenSHC::UI::MenuItems::General_Func::MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)( + 0x16); + return; + } + memset(DAT_GameState::instance.mapAndTime.playerIsAlive, 0, + sizeof(DAT_GameState::instance.mapAndTime.playerIsAlive)); + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); + } + } + +} +} From 2b83f18e3902448b8a94542c9f959bf299f36353 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 04:30:41 +0100 Subject: [PATCH 19/45] style: VoteKick_K_D_B_G_J (0x00485140) follows the style guide On top of gynt's version in the commit before; the code is the same, reccmp 100.0 (normalized 100.0) and quick_diff 50/50 at 0.9800 before and after (the rest is the call through the DirectPlay interface, which quick_diff reads as a direct call on our side). - The first include is ../Commands.func.hpp, once; the using lines and the imported block comments are gone. - The execute half is an early return. - CancelMessage is called on DPLAYX_4A as it is typed on main, with no cast, as disconnectDPlay does. - 0x16 is 22. The status line goes to 100.0% (Reimplemented) with this commit. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/VoteKick_K_D_B_G_J.cpp | 49 +++++++------------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/src/OpenSHC/Synchrony/Commands/VoteKick_K_D_B_G_J.cpp b/src/OpenSHC/Synchrony/Commands/VoteKick_K_D_B_G_J.cpp index bc5e28c18e..e4ed2b844a 100644 --- a/src/OpenSHC/Synchrony/Commands/VoteKick_K_D_B_G_J.cpp +++ b/src/OpenSHC/Synchrony/Commands/VoteKick_K_D_B_G_J.cpp @@ -1,4 +1,3 @@ -#include "../../Synchrony.func.hpp" #include "../Commands.func.hpp" #include "OpenSHC/Game/GameCore.func.hpp" @@ -17,20 +16,6 @@ namespace OpenSHC { namespace Synchrony { - using OpenSHC::Commands::GameCommandParameterLocation; - using OpenSHC::Commands::GameCommandParameterReadWrite; - using OpenSHC::Commands::GameCommandScheduling; - using OpenSHC::UI::Enums::MenuViewType; - - /* - WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names - */ - /* - WARNING: Enum "DPERRInt": Some values do not have unique names - */ - /* - decompilerscript: committed: 2025-01-30 21:57:43.216000 - */ // FUNCTION: STRONGHOLDCRUSADER 0x00485140 void Commands::VoteKick_K_D_B_G_J() { @@ -41,28 +26,30 @@ namespace Synchrony { MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + // every message still waiting to be sent is dropped if (DAT_GameSynchronyState::instance.DPLAYX_4A != NULL) { - ((IDirectPlay4A*)DAT_GameSynchronyState::instance.DPLAYX_4A)->CancelMessage(0, 0); + DAT_GameSynchronyState::instance.DPLAYX_4A->CancelMessage(0, 0); } DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; return; } - if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) { - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, - OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0) { - DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; - MACRO_CALL( - OpenSHC::UI::MenuItems::General_Func::MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)( - 0x16); - return; - } - memset(DAT_GameState::instance.mapAndTime.playerIsAlive, 0, - sizeof(DAT_GameState::instance.mapAndTime.playerIsAlive)); - MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( - OpenSHC::UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0) { + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; + MACRO_CALL( + OpenSHC::UI::MenuItems::General_Func::MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)(22); + return; } + // nobody is left alive, and the mission ends + memset(DAT_GameState::instance.mapAndTime.playerIsAlive, 0, + sizeof(DAT_GameState::instance.mapAndTime.playerIsAlive)); + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 79510c5f96..b29f8437c4 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22733,7 +22733,7 @@ SHC_3BB0A8C1_0x00485020 | 0.0% | Pending SHC_3BB0A8C1_0x004850E0 | 0.0% | Pending -SHC_3BB0A8C1_0x00485140 | 0.0% | Pending +SHC_3BB0A8C1_0x00485140 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00485210 | 0.0% | Pending From 2a12e103fc065d29cd950375621015b3fb5d4d85 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 17 Nov 2026 04:30:42 +0100 Subject: [PATCH 20/45] reimplement: SHC_3BB0A8C1_0x0048A510 100.0% Reimplemented SendResyncUnknown, gynt's version as it stands on upstream's reimpl/Synchrony-Commands (ca943baa1), where the status line still reads 75.9% (Style pass, asm differs): the file was last changed in his f2f2c13e4 ("reimplement: SHC_3BB0A8C1_0x0048A510 92.7% Reimplemented", 2026-10-03), which left the status line in place. His fork's branch (6fa5eaa53) has the older file. One change so that it builds on main: MapAndTimeState::field192_0x194 is syncedStateBase there (three lines); nothing else changed. With both resolver sets on it now reads reccmp 100.0 (normalized 100.0), where his commit measured 92.7. What main's style rules need on top follows in our own commit, which also sets the status line. Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/SendResyncUnknown.cpp | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/OpenSHC/Synchrony/Commands/SendResyncUnknown.cpp diff --git a/src/OpenSHC/Synchrony/Commands/SendResyncUnknown.cpp b/src/OpenSHC/Synchrony/Commands/SendResyncUnknown.cpp new file mode 100644 index 0000000000..1d8a1bcb80 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/SendResyncUnknown.cpp @@ -0,0 +1,101 @@ +#include "../../Synchrony.func.hpp" +#include "../Commands.func.hpp" + +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Synchrony.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_AIVState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + using OpenSHC::Commands::GameCommandParameterLocation; + using OpenSHC::Commands::GameCommandParameterReadWrite; + using OpenSHC::Commands::GameCommandScheduling; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + /* + WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names + */ + /* + WARNING: Enum "DPERRInt": Some values do not have unique names + */ + /* + WARNING: Enum "MappersEnumShort": Some values do not have unique names + */ + /* + decompilerscript: committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x0048A510 + void Commands::SendResyncUnknown() + { + char local_3ec[1000]; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + DAT_GameSynchronyState::instance.DAT_CommandSize = 14570; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 < 0x12) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)((void*)((int)&DAT_GameState::instance.mapAndTime.syncedStateBase + + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 14566), + (size_t)((int)(14566)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0x12) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameState::instance.mapAndTime.startingTroops[7] + 0x10, 0x10, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0x13) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_AIVState::instance.mapExtraInfo, 0x330, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + return; + } else if ((DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) + && (DAT_GameSynchronyState::instance.isHost == FALSE)) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 < 0x12) { + MACRO_CALL(OpenSHC::OS_Func::_sprintf)( + local_3ec, "Glob %d", DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 0x38e6 + 0x194); + MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)( + (char*)((int)&DAT_GameState::instance.mapAndTime.syncedStateBase + + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 0x38e6), + (size_t)((int)(14566)), DAT_GameSynchronyState::instance.DAT_GameCommandParam0); + return; + } + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0x12) { + MACRO_CALL(OpenSHC::OS_Func::_sprintf)(local_3ec, "Glob %d", 0x401c0); + MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)( + (char*)((int)&DAT_GameState::instance.mapAndTime.syncedStateBase + + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 0x38e6), + (size_t)((int)(16)), DAT_GameSynchronyState::instance.DAT_GameCommandParam0); + return; + } + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0x13) { + MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)( + (char*)&DAT_AIVState::instance.mapExtraInfo, (size_t)((int)(816)), 0x13); + } + }; + } + +} +} From 22eaaeac7b9bf7ea83629ba1b23fc4006af3be6f Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 05:24:39 +0100 Subject: [PATCH 21/45] style: SendResyncUnknown (0x0048A510) follows the style guide On top of gynt's version in the commit before; the code is the same, reccmp 100.0 (normalized 100.0) and quick_diff 123/123 at 0.9919 before and after (the rest is the /GS cookie load, which reccmp is told to ignore). - The first include is ../Commands.func.hpp, once; the using lines and the imported block comments are gone. - The execute half is an early return (wrong action plan, or the host), and the three kinds of part are one if / else if chain in each half. - Each part's address is `(char*)&mapAndTime.syncedStateBase + part * 14566`, in place of the sum through `(int)`. Part 18 is written the same way in both halves; the sending half had `startingTroops[7] + 0x10` for the same address, and the compiler folds the sum to it there, since the part is known to be 18. - The sizes are decimal, and the AIV map info's is sizeof(). - "Glob %d" is s_Glob__d_005a74a0, local_3ec is partName, and the offsets in the text are `part * 14566 + offsetof(MapAndTimeState, syncedStateBase)` in place of `0x194` and `0x401c0`. - Part 19 passes the part number in place of the literal 0x13 (the same code: the compiler knows it is 19 there). The status line goes to 100.0% (Reimplemented) with this commit. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/SendResyncUnknown.cpp | 110 ++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 49 insertions(+), 63 deletions(-) diff --git a/src/OpenSHC/Synchrony/Commands/SendResyncUnknown.cpp b/src/OpenSHC/Synchrony/Commands/SendResyncUnknown.cpp index 1d8a1bcb80..402a11a933 100644 --- a/src/OpenSHC/Synchrony/Commands/SendResyncUnknown.cpp +++ b/src/OpenSHC/Synchrony/Commands/SendResyncUnknown.cpp @@ -1,4 +1,3 @@ -#include "../../Synchrony.func.hpp" #include "../Commands.func.hpp" #include "OpenSHC/OS.func.hpp" @@ -7,7 +6,7 @@ #include "OpenSHC/Commands/GameCommandParameterLocation.hpp" #include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" #include "OpenSHC/Commands/GameCommandScheduling.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" +#include "OpenSHC/string-literals.hpp" #include "OpenSHC/Globals/DAT_AIVState.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" @@ -16,85 +15,72 @@ namespace OpenSHC { namespace Synchrony { - using OpenSHC::Commands::GameCommandParameterLocation; - using OpenSHC::Commands::GameCommandParameterReadWrite; - using OpenSHC::Commands::GameCommandScheduling; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - - /* - WARNING: Enum "DPSEND_EnumInt": Some values do not have unique names - */ - /* - WARNING: Enum "DPERRInt": Some values do not have unique names - */ - /* - WARNING: Enum "MappersEnumShort": Some values do not have unique names - */ - /* - decompilerscript: committed: 2025-01-30 21:57:43.216000 - */ // FUNCTION: STRONGHOLDCRUSADER 0x0048A510 void Commands::SendResyncUnknown() { - char local_3ec[1000]; DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] .time = 0; + // the part's number and one part of the data, 14566 bytes at most DAT_GameSynchronyState::instance.DAT_CommandSize = 14570; + // parts 0 to 17 are the map and time state from syncedStateBase on, part 18 is its last 16 bytes and part 19 + // is the AIV state's map info if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 < 0x12) { + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 < 18) { MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)((void*)((int)&DAT_GameState::instance.mapAndTime.syncedStateBase - + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 14566), - (size_t)((int)(14566)), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)((char*)&DAT_GameState::instance.mapAndTime.syncedStateBase + + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 14566, + 14566, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; - } - if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0x12) { + } else if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 18) { MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(DAT_GameState::instance.mapAndTime.startingTroops[7] + 0x10, 0x10, - OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)((char*)&DAT_GameState::instance.mapAndTime.syncedStateBase + + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 14566, + 16, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; - } - if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0x13) { + } else if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 19) { MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_AIVState::instance.mapExtraInfo, 0x330, - OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + DAT_GameSynchronyState::ptr)(&DAT_AIVState::instance.mapExtraInfo, + sizeof(DAT_AIVState::instance.mapExtraInfo), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); - return; } return; - } else if ((DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_EXECUTE) - && (DAT_GameSynchronyState::instance.isHost == FALSE)) { - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, - DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, - OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); - if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 < 0x12) { - MACRO_CALL(OpenSHC::OS_Func::_sprintf)( - local_3ec, "Glob %d", DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 0x38e6 + 0x194); - MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)( - (char*)((int)&DAT_GameState::instance.mapAndTime.syncedStateBase - + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 0x38e6), - (size_t)((int)(14566)), DAT_GameSynchronyState::instance.DAT_GameCommandParam0); - return; - } - if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0x12) { - MACRO_CALL(OpenSHC::OS_Func::_sprintf)(local_3ec, "Glob %d", 0x401c0); - MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)( - (char*)((int)&DAT_GameState::instance.mapAndTime.syncedStateBase - + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 0x38e6), - (size_t)((int)(16)), DAT_GameSynchronyState::instance.DAT_GameCommandParam0); - return; - } - if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0x13) { - MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)( - (char*)&DAT_AIVState::instance.mapExtraInfo, (size_t)((int)(816)), 0x13); - } - }; + } + // only the clients take the host's copy + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE + || DAT_GameSynchronyState::instance.isHost) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + // the text names the part by its offset in the map and time state; nothing reads it + char partName[1000]; + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 < 18) { + // "Glob %d" + MACRO_CALL(OpenSHC::OS_Func::_sprintf)(partName, s_Glob__d_005a74a0, + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 14566 + + offsetof(OpenSHC::Game::State::MapAndTimeState, syncedStateBase)); + MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)( + (char*)&DAT_GameState::instance.mapAndTime.syncedStateBase + + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 14566, + 14566, DAT_GameSynchronyState::instance.DAT_GameCommandParam0); + } else if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 18) { + // "Glob %d" + MACRO_CALL(OpenSHC::OS_Func::_sprintf)(partName, s_Glob__d_005a74a0, + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 14566 + + offsetof(OpenSHC::Game::State::MapAndTimeState, syncedStateBase)); + MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)( + (char*)&DAT_GameState::instance.mapAndTime.syncedStateBase + + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 * 14566, + 16, DAT_GameSynchronyState::instance.DAT_GameCommandParam0); + } else if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 19) { + MACRO_CALL(OpenSHC::Synchrony_Func::MemCopyFromParameter)((char*)&DAT_AIVState::instance.mapExtraInfo, + sizeof(DAT_AIVState::instance.mapExtraInfo), DAT_GameSynchronyState::instance.DAT_GameCommandParam0); + } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b29f8437c4..c0c70eee94 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23123,7 +23123,7 @@ SHC_3BB0A8C1_0x0048A350 | 0.0% | Pending SHC_3BB0A8C1_0x0048A460 | 0.0% | Pending -SHC_3BB0A8C1_0x0048A510 | 0.0% | Pending +SHC_3BB0A8C1_0x0048A510 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048A710 | 0.0% | Pending From 74267e2d039e42c322d22fb473662a8bdceda738 Mon Sep 17 00:00:00 2001 From: Gynt Date: Tue, 17 Nov 2026 05:24:39 +0100 Subject: [PATCH 22/45] reimplement: SHC_3BB0A8C1_0x00465700 100.0% Reimplemented QueueChangeTaxes, as it stands on gynt's fork's reimpl/Synchrony-Commands at 6fa5eaa53 ("Adopt the Wilps implementations that measure better here (#20)", 2026-11-02). The body is Wilps's, from gynt's fork's reimpl/Wilps-2026-10-18 (8ca78619c): gynt ported it over his own draft of 60ff6ebad, which upstream's branch still has, and measured it at quick_diff 0.9231 on that branch's headers; the status line there reads 0.0% (Pending, not matched by reccmp). Taken unchanged; it compiles on main's headers as it is. With both resolver sets on it reads reccmp 100.0 (normalized 100.0). What main's style rules need on top follows in our own commit, which also sets the status line. Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/QueueChangeTaxes.cpp | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/OpenSHC/Synchrony/Commands/QueueChangeTaxes.cpp diff --git a/src/OpenSHC/Synchrony/Commands/QueueChangeTaxes.cpp b/src/OpenSHC/Synchrony/Commands/QueueChangeTaxes.cpp new file mode 100644 index 0000000000..78ec9c2568 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/QueueChangeTaxes.cpp @@ -0,0 +1,63 @@ +#include "../../Synchrony.func.hpp" +#include "../Commands.func.hpp" + +#include "OpenSHC/Game.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + using OpenSHC::Commands::GameCommandType; + using OpenSHC::Game::GameMode2; + using OpenSHC::Map::Buildings::BuildingType; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + /* the local player moved the tax slider: queue a change-taxes command. In the tutorial a refused change puts the + slider back, shows the hint and stops (tail jump to SetTutorialHintActiveWithTimestamp at 0x46574C). */ + // FUNCTION: STRONGHOLDCRUSADER 0x00465700 + void Commands::QueueChangeTaxes() + { + int taxesSliderUI = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSliderUI; + if (taxesSliderUI + != DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSetting2) { + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CRUSADER_TUTORIAL) { + if (MACRO_CALL(OpenSHC::Game_Func::Tutorial_IsActionAllowed)(4, taxesSliderUI) == FALSE) { + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSliderUI + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSetting2; + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTutorialHintActiveWithTimestamp)(); + return; + } + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTutorialBuildingActionState)(0xd, + (BuildingType)(DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSliderUI)); + } + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .timeTaxesOrRationsChange + = timeGetTime(); + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].taxesSetting2 + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSliderUI; + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSliderUI; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_CHANGE_TAXES); + } + } + +} +} From 078743f20e87b171d346c0e548dd1fb68a381fc2 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 04:30:45 +0100 Subject: [PATCH 23/45] style: QueueChangeTaxes (0x00465700) follows the style guide On top of Wilps's body in the commit before; the code is the same, reccmp 100.0 (normalized 100.0) and quick_diff 39/39 at 0.9487 before and after (the rest is the timeGetTime import call and the tail jump into SetTutorialHintActiveWithTimestamp, both of which reccmp resolves). - The first include is ../Commands.func.hpp, once; the using lines and the block comment above the function are gone. - An unchanged slider is an early return, and the slider is read from its field where it is used. - The refused tutorial change is tested by truth (`!Tutorial_IsActionAllowed(...)`), and 0xd is 13. Two things in Wilps's body carry the match, and both stay: the return after the tutorial hint (the original jumps into the hint function and ends there), and the player data indexed through currentPlayerSlotID each time, with no slot local (with one, the slider is read once after timeGetTime where the original reads it twice). The status line goes to 100.0% (Reimplemented) with this commit. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/QueueChangeTaxes.cpp | 64 ++++++++----------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/OpenSHC/Synchrony/Commands/QueueChangeTaxes.cpp b/src/OpenSHC/Synchrony/Commands/QueueChangeTaxes.cpp index 78ec9c2568..171ec760a8 100644 --- a/src/OpenSHC/Synchrony/Commands/QueueChangeTaxes.cpp +++ b/src/OpenSHC/Synchrony/Commands/QueueChangeTaxes.cpp @@ -1,4 +1,3 @@ -#include "../../Synchrony.func.hpp" #include "../Commands.func.hpp" #include "OpenSHC/Game.func.hpp" @@ -7,7 +6,6 @@ #include "OpenSHC/Commands/GameCommandType.hpp" #include "OpenSHC/Game/GameMode2.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_GameCore.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" @@ -16,47 +14,41 @@ namespace OpenSHC { namespace Synchrony { - using OpenSHC::Commands::GameCommandType; - using OpenSHC::Game::GameMode2; - using OpenSHC::Map::Buildings::BuildingType; - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - - /* the local player moved the tax slider: queue a change-taxes command. In the tutorial a refused change puts the - slider back, shows the hint and stops (tail jump to SetTutorialHintActiveWithTimestamp at 0x46574C). */ // FUNCTION: STRONGHOLDCRUSADER 0x00465700 void Commands::QueueChangeTaxes() { - int taxesSliderUI = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .taxesSliderUI; - if (taxesSliderUI - != DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].taxesSliderUI + == DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .taxesSetting2) { - if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CRUSADER_TUTORIAL) { - if (MACRO_CALL(OpenSHC::Game_Func::Tutorial_IsActionAllowed)(4, taxesSliderUI) == FALSE) { + return; + } + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CRUSADER_TUTORIAL) { + if (!MACRO_CALL(OpenSHC::Game_Func::Tutorial_IsActionAllowed)(4, DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .taxesSliderUI - = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .taxesSetting2; - MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTutorialHintActiveWithTimestamp)(); - return; - } - MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTutorialBuildingActionState)(0xd, - (BuildingType)(DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .taxesSliderUI)); + .taxesSliderUI)) { + // the tutorial doesn't allow the change yet: the slider goes back + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSliderUI + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSetting2; + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTutorialHintActiveWithTimestamp)(); + return; } - DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .timeTaxesOrRationsChange - = timeGetTime(); - DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].taxesSetting2 - = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .taxesSliderUI; - DAT_GameSynchronyState::instance.DAT_GameCommandParam0 - = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .taxesSliderUI; - MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( - OpenSHC::Commands::GCT_CHANGE_TAXES); + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTutorialBuildingActionState)(13, + (OpenSHC::Map::Buildings::BuildingType)DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSliderUI); } + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .timeTaxesOrRationsChange = timeGetTime(); + DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].taxesSetting2 + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSliderUI; + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .taxesSliderUI; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_CHANGE_TAXES); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index c0c70eee94..a5f313f1c6 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -19901,7 +19901,7 @@ SHC_3BB0A8C1_0x00465630 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004656A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00465700 | 0.0% | Pending +SHC_3BB0A8C1_0x00465700 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004657B0 | 100.0% | Reimplemented From 4d085b94aaafcc49a7d5b04a9225dd62c4d3a0fa Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 04:21:21 +0100 Subject: [PATCH 24/45] reimplement: SHC_3BB0A8C1_0x00481D90 100.0% Reimplemented ClickPlaceBuilding, from gynt's draft on upstream's reimpl/Synchrony-Commands (ebb7be7b9, 91.7% there, his newest commit on the file; the status line reads 89.6%). On main's headers the draft reads reccmp 91.7 (normalized 65.5), and now 100.0 (normalized 100.0). quick_diff 120/120 at 1.0000 (the draft: 0.9250). On main the draft needed one rename to compile: field299_0x109e7c is editorPlacementPlayerID. What the match needed: one placeBuilding call in each branch of the map editor test, the editor's chosen player in one and the command's sender in the other. The original pushes the five other arguments first and picks the player last. With the player in a local chosen before a single call (the draft), or as a conditional inside the call's arguments, the compiler picks the player first and pushes afterwards (quick_diff 0.9250 for both). Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return, the resource check is tested by truth in place of `(iVar1 = ..., iVar1 == 0)`, and the doubled brackets around the arguments are gone. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/ClickPlaceBuilding.cpp | 107 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/ClickPlaceBuilding.cpp diff --git a/src/OpenSHC/Synchrony/Commands/ClickPlaceBuilding.cpp b/src/OpenSHC/Synchrony/Commands/ClickPlaceBuilding.cpp new file mode 100644 index 0000000000..95fc7df6b5 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/ClickPlaceBuilding.cpp @@ -0,0 +1,107 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.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_TileMapState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00481D90 + void Commands::ClickPlaceBuilding() + { + // the position (x, y), the building, its size and orientation, and the dragged tile count + DAT_GameSynchronyState::instance.DAT_CommandSize = 10; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam2, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam3, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam4, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam5, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + // each parameter is cleared first, because only its low one or two bytes are read + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 = OpenSHC::Commands::M_MAPPER_NULL; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam2, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam3 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam3, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam4 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam4, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam5 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam5, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY + && !MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::checkRequiredResourcesForBuildingOrPlanToBuy, + DAT_GameState::ptr)( + (OpenSHC::Commands::MappersEnum)DAT_GameSynchronyState::instance.DAT_GameCommandParam2, + DAT_GameSynchronyState::instance.protocolInvokerPlayerID, FALSE)) { + return; + } + DAT_BuildingsState::instance.DAT_DraggedTileCountVerified + = DAT_GameSynchronyState::instance.DAT_GameCommandParam5; + // in the map editor the building goes to the editor's chosen player (one call with the player chosen first + // loses the match) + if (DAT_GameCore::instance.currentMenuViewType == OpenSHC::UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, DAT_TileMapState::ptr)( + DAT_GameSynchronyState::instance.editorPlacementPlayerID, + DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + (OpenSHC::Commands::MappersEnum)(ushort)DAT_GameSynchronyState::instance.DAT_GameCommandParam2, + DAT_GameSynchronyState::instance.DAT_GameCommandParam3, + DAT_GameSynchronyState::instance.DAT_GameCommandParam4); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, DAT_TileMapState::ptr)( + DAT_GameSynchronyState::instance.protocolInvokerPlayerID, + DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + (OpenSHC::Commands::MappersEnum)(ushort)DAT_GameSynchronyState::instance.DAT_GameCommandParam2, + DAT_GameSynchronyState::instance.DAT_GameCommandParam3, + DAT_GameSynchronyState::instance.DAT_GameCommandParam4); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a5f313f1c6..e468ba5f04 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22469,7 +22469,7 @@ SHC_3BB0A8C1_0x00481B50 | 0.0% | Pending SHC_3BB0A8C1_0x00481C80 | 0.0% | Pending -SHC_3BB0A8C1_0x00481D90 | 0.0% | Pending +SHC_3BB0A8C1_0x00481D90 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00481F40 | 0.0% | Pending From ac7f76e62565270076433cd3ffc0dca9062a9f36 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 06:18:24 +0100 Subject: [PATCH 25/45] reimplement: SHC_3BB0A8C1_0x00480710 100.0% Reimplemented AnnouncePlayerInformationSuchAsNameLordTypeAndAvailableAIVS, from gynt's draft on upstream's reimpl/Synchrony-Commands (2d091b7f0 and ca6251580 at 91.4%; the file was last changed in 4242ae2ab, "Synchrony/Commands: drop the hand-written /GS cookie"). On main's headers the draft reads reccmp 93.3 (normalized 80.4), and now 100.0 (normalized 100.0). quick_diff 162/162 at 0.9938 (the draft: 0.9321); the rest is the /GS cookie load, which reccmp is told to ignore. What the match needed: - The three copy loops over pointers are strcpy calls: the sender's name into the final results, this machine's own name into its slot, and that name into the final results. The first loop then gets the original's form, one pointer and the distance between the two strings. - The own name's lookup is written inside the call that converts it, so the 250 is pushed before the lookup is called. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already nests it; his copies are loops. Style: the strcpy pragma, the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half and the empty sender slot are early returns, the locals have names (senderSlot, lordIcon, lordType, wideName) and are declared where they are filled, the scalar and AIV list sizes are sizeof(), the text array index is TAIT_ZERO, and the host test is by truth after the two lord stores. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ...tionSuchAsNameLordTypeAndAvailableAIVS.cpp | 107 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/AnnouncePlayerInformationSuchAsNameLordTypeAndAvailableAIVS.cpp diff --git a/src/OpenSHC/Synchrony/Commands/AnnouncePlayerInformationSuchAsNameLordTypeAndAvailableAIVS.cpp b/src/OpenSHC/Synchrony/Commands/AnnouncePlayerInformationSuchAsNameLordTypeAndAvailableAIVS.cpp new file mode 100644 index 0000000000..c679621b8e --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/AnnouncePlayerInformationSuchAsNameLordTypeAndAvailableAIVS.cpp @@ -0,0 +1,107 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#include "../Commands.func.hpp" + +#include "OpenSHC/AI/AIVState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/Util/WideCharMultiByteState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Text/TextArrayIndexType.hpp" + +#include "OpenSHC/Globals/DAT_AIVState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" +#include "OpenSHC/Globals/DAT_WideCharMultiByteState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00480710 + void Commands::AnnouncePlayerInformationSuchAsNameLordTypeAndAvailableAIVS() + { + WCHAR wideName[500]; // the size of the original's buffer + // the sender's slot, lord icon and lord type, the name (250 wide characters) and which AIV files it has + DAT_GameSynchronyState::instance.DAT_CommandSize = 592; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.currentPlayerSlotID, + sizeof(DAT_GameSynchronyState::instance.currentPlayerSlotID), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameCore::instance.lordIconUnk, + sizeof(DAT_GameCore::instance.lordIconUnk), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameCore::instance.selectedLordTypeUnk, + sizeof(DAT_GameCore::instance.selectedLordTypeUnk), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::multiByteToWideCharWithSize, + DAT_WideCharMultiByteState::ptr)(wideName, + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::getTextArrayPointer, + DAT_UserTextHandlerState::ptr)(OpenSHC::Text::TAIT_ZERO), + 250); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 500, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_AIVState::instance.aivFileAvailabilityPerAIArray, + sizeof(DAT_AIVState::instance.aivFileAvailabilityPerAIArray), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + int senderSlot; + int lordIcon; + int lordType; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&senderSlot, sizeof(senderSlot), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&lordIcon, sizeof(lordIcon), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&lordType, sizeof(lordType), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (senderSlot == 0) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 500, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER( + OpenSHC::Util::WideCharMultiByteState_Func::wideCharToMultiByteWithSize, DAT_WideCharMultiByteState::ptr)( + DAT_GameSynchronyState::instance.DAT_PlayerNames[senderSlot], wideName, 250); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + DAT_GameSynchronyState::instance.DAT_ReceivedAIVFileAvailabilityPerAIArray[senderSlot], + sizeof(DAT_GameSynchronyState::instance.DAT_ReceivedAIVFileAvailabilityPerAIArray[senderSlot]), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + strcpy(DAT_GameSynchronyState::instance.finalResults.names[senderSlot], + DAT_GameSynchronyState::instance.DAT_PlayerNames[senderSlot]); + DAT_GameSynchronyState::instance.isIncludedPlayer[senderSlot] = TRUE; + // this machine's own name is refreshed too + strcpy(DAT_GameSynchronyState::instance.DAT_PlayerNames[DAT_GameSynchronyState::instance.currentPlayerSlotID], + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)( + OpenSHC::Text::TAIT_ZERO)); + strcpy( + DAT_GameSynchronyState::instance.finalResults.names[DAT_GameSynchronyState::instance.currentPlayerSlotID], + DAT_GameSynchronyState::instance.DAT_PlayerNames[DAT_GameSynchronyState::instance.currentPlayerSlotID]); + DAT_GameCore::instance.lordIcons[senderSlot] = lordIcon; + DAT_GameCore::instance.selectedLordTypes[senderSlot] = lordType; + if (DAT_GameSynchronyState::instance.isHost) { + MACRO_CALL_MEMBER(OpenSHC::AI::AIVState_Func::hostChecksLobbyAIVAvailability, DAT_AIVState::ptr)(); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e468ba5f04..4c2fbb44ba 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22435,7 +22435,7 @@ SHC_3BB0A8C1_0x00480640 | 0.0% | Pending SHC_3BB0A8C1_0x00480680 | 0.0% | Pending -SHC_3BB0A8C1_0x00480710 | 0.0% | Pending +SHC_3BB0A8C1_0x00480710 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00480980 | 100.0% | Reimplemented From 654cffbb612fb0cc0685029a3029f5e36af97336 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:06 +0100 Subject: [PATCH 26/45] reimplement: SHC_3BB0A8C1_0x0048F870 100.0% Reimplemented AskForPlayerSlotAssignment, from gynt's draft on upstream's reimpl/Synchrony-Commands (c8da6f297 at 52.6%, 864e522b2 at 53.9%, 5cfd575d1 at 87.0%, his newest commit on the file; the status line reads 53.9%). On main's headers the draft reads reccmp 87.0 (normalized 71.5), and now 100.0 (normalized 100.0). quick_diff 135/135 at 1.0000 (the draft: 134 instructions at 0.8848). On main the draft needed one rename to compile: TextureRenderCore's field69_0x98 is bitmapFaceSizes. What the match needed: - One addPlayerToCurrentPlayerArray call in each branch of the single player test, with 1 in one and the received player ID in the other. The original pushes the argument in each branch and shares the call; with the argument in a local chosen before one call the compiler picks it first. - The face copies are written on the ushort pointer, `bitmapsFaces_0x94 + (slot + 19) * 66 * 64`, as drawBitmapFace indexes it, in place of byte sums through `(int)`. The original loads the lord icon first and forms `icon - 2` with lea; the sums through int load in another order. - The delay test is `> -1` (cmp -1 / jle), not `>= 0`. gynt's 6cbbfc2bd on his fork's reimpl/UI-MenuItems-development (2026-11-02, "flip 3 comparisons in Synchrony") writes the delay test as `-delay > 1`. That is another test (delay < -1), so it is not taken. Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half, the solitary game and the client are early returns, the eight stores of -1 are a loop over the ID array (slot 1 gets its 1 after it; the same code), `_commandOriginPlayer` is senderSlot, and the face size is a FACE_SIZE constant (66 * 64 * 2, as setBMPFacesToMagenta has it) in place of 0x2100, with FACE_HEIGHT and FACE_WIDTH for the 66 and 64 of the pixel offsets. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/AskForPlayerSlotAssignment.cpp | 123 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/AskForPlayerSlotAssignment.cpp diff --git a/src/OpenSHC/Synchrony/Commands/AskForPlayerSlotAssignment.cpp b/src/OpenSHC/Synchrony/Commands/AskForPlayerSlotAssignment.cpp new file mode 100644 index 0000000000..b00f6d5bc1 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/AskForPlayerSlotAssignment.cpp @@ -0,0 +1,123 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Synchrony.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // one face: 66 rows of 64 pixels of two bytes + int const FACE_HEIGHT = 66; + int const FACE_WIDTH = 64; + int const FACE_SIZE = FACE_HEIGHT * FACE_WIDTH * 2; + + // FUNCTION: STRONGHOLDCRUSADER 0x0048F870 + void Commands::AskForPlayerSlotAssignment() + { + DAT_GameSynchronyState::instance.DAT_CommandSize = 1; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.isHost, 1, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SOLITARY) { + // alone, the player takes slot 1 and every other slot is empty + for (int slot = 0; slot < countof(DAT_GameSynchronyState::instance.currentPlayerFullIDArray); ++slot) { + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[slot] = -1; + } + DAT_GameSynchronyState::instance.currentPlayerSlotID = 1; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[1] = 1; + // the chosen lord's face becomes the slot's face (the players' faces follow the 20 lords' faces; the slots + // start at 1) + MACRO_CALL(OpenSHC::OS_Func::_memcpy)(DAT_TextureRenderCoreObject::instance.bitmapsFaces_0x94 + + (DAT_GameSynchronyState::instance.currentPlayerSlotID + 19) * FACE_HEIGHT * FACE_WIDTH, + DAT_TextureRenderCoreObject::instance.bitmapsFaces_0x94 + + (DAT_GameCore::instance.lordIconUnk - 2) * FACE_HEIGHT * FACE_WIDTH, + FACE_SIZE); + DAT_TextureRenderCoreObject::instance + .bitmapFaceSizes[DAT_GameSynchronyState::instance.currentPlayerSlotID + 19] = FACE_SIZE; + return; + } + char senderIsHost; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&senderIsHost, sizeof(senderIsHost), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (senderIsHost) { + DAT_GameSynchronyState::instance.DAT_TwoIfNotHost = 2; + } + if (!DAT_GameSynchronyState::instance.isHost) { + return; + } + // the host gives the sender a slot; in a single player skirmish the sender is player 1 + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + DAT_GameSynchronyState::instance.protocolInvokerPlayerID + = MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addPlayerToCurrentPlayerArray, + DAT_GameSynchronyState::ptr)(1); + } else { + DAT_GameSynchronyState::instance.protocolInvokerPlayerID + = MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addPlayerToCurrentPlayerArray, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DPLAYX_ReceivedPlayerID); + } + MACRO_CALL(OpenSHC::Synchrony_Func::PutPlayerIntoRandomSlot)( + DAT_GameSynchronyState::instance.protocolInvokerPlayerID); + // clearing the command entry must not lose the new slot + int const senderSlot = DAT_GameSynchronyState::instance.protocolInvokerPlayerID; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::clearGameCommandEntry, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID); + DAT_GameSynchronyState::instance.protocolInvokerPlayerID = senderSlot; + if (DAT_GameSynchronyState::instance.currentPlayerSlotID == 0) { + // the host itself had no slot yet + DAT_GameSynchronyState::instance.currentPlayerSlotID = senderSlot; + if (DAT_GameCore::instance.lordIconUnk >= 2) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_SHARE_AIV_HASH); + } + MACRO_CALL(OpenSHC::OS_Func::_memcpy)(DAT_TextureRenderCoreObject::instance.bitmapsFaces_0x94 + + (DAT_GameSynchronyState::instance.currentPlayerSlotID + 19) * FACE_HEIGHT * FACE_WIDTH, + DAT_TextureRenderCoreObject::instance.bitmapsFaces_0x94 + + (DAT_GameCore::instance.lordIconUnk - 2) * FACE_HEIGHT * FACE_WIDTH, + FACE_SIZE); + DAT_TextureRenderCoreObject::instance + .bitmapFaceSizes[DAT_GameSynchronyState::instance.currentPlayerSlotID + 19] = FACE_SIZE; + } else { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_ASSIGN_PLAYERID_TO_PLAYER_SLOT); + } + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[senderSlot] = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_HOST_SHARE_LOBBY_STATE); + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 1; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_TRIGGER_LOBBY_PLAYER_INFORMATION_REFRESH); + if (DAT_GameCore::instance.currentMenuViewType != OpenSHC::UI::Enums::MVT_CRUSADE_MISSION_INTRO + || DAT_GameCore::instance.menuSwitchDelay > -1) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_CHANGE_MAP_SELECTION); + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_CHANGE_GAME_INTENSITY_OR_BALANCE); + MACRO_CALL_MEMBER( + OpenSHC::Synchrony::GameSynchronyState_Func::reorderTeamsAndPositions, DAT_GameSynchronyState::ptr)(); + DAT_GameSynchronyState::instance.reparseMaps = TRUE; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 4c2fbb44ba..cef0539a5f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23359,7 +23359,7 @@ SHC_3BB0A8C1_0x0048F842 | 0.0% | Pending SHC_3BB0A8C1_0x0048F850 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0048F870 | 0.0% | Pending +SHC_3BB0A8C1_0x0048F870 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048FAA0 | 0.0% | Pending From 7ebe29125bbf0246c9a5da9127f5532689864184 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 06:18:24 +0100 Subject: [PATCH 27/45] reimplement: SHC_3BB0A8C1_0x00485F20 100.0% Reimplemented HostAnnounceRoundTable, rewritten from the binary. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) is the same function. gynt's draft on upstream's reimpl/Synchrony-Commands (eacec5faf, then 7c73f7845 at 76.4%, "Return recovered, merged slot differs"; the status line reads 0.0%) reads reccmp 76.4 (normalized 76.4) on main's headers, and this 100.0 (normalized 100.0). quick_diff 75/75 at 1.0000 (the draft: 72 instructions at 0.8299). The file is named after the function now (HostAnnounceRoundTable.cpp; the draft's was HostAnnounceRoundtable.cpp). The original keeps two bytes on the stack: - roundTableOpen starts at 0 and becomes 1 when this machine's active dialog is the round table; the sending half serializes it and returns. - The receiving half reads the host's flag into a second byte and copies it over the first, which the tests then read (reading the second byte loses the match: quick_diff 0.9730 with 73 instructions). For the host or in the lobby menu: with no dialog open and the flag set, the round table opens; with no dialog open and the flag clear, nothing more happens; and a clear flag closes an open round table. Fix against the draft (7c73f7845): the byte it sent, `local_2`, was never set. The draft read an incoming ecx, which the function doesn't have, into the byte the receiving half deserializes into, so that read had no effect. It already returned on a clear flag with no dialog open; only the earlier eacec5faf opened the round table regardless. Style: the first include is ../Commands.func.hpp, sizes are sizeof(), the tests are early returns. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/HostAnnounceRoundTable.cpp | 79 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/HostAnnounceRoundTable.cpp diff --git a/src/OpenSHC/Synchrony/Commands/HostAnnounceRoundTable.cpp b/src/OpenSHC/Synchrony/Commands/HostAnnounceRoundTable.cpp new file mode 100644 index 0000000000..6e1a9455e9 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/HostAnnounceRoundTable.cpp @@ -0,0 +1,79 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00485F20 + void Commands::HostAnnounceRoundTable() + { + // the nine teams, the nine round table seats and whether the host's round table is open + DAT_GameSynchronyState::instance.DAT_CommandSize = 19; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + char roundTableOpen = 0; + if (DAT_MenuModalComposition1::instance.activeModalDialogID == OpenSHC::UI::Enums::MMT_ROUNDTABLE) { + roundTableOpen = 1; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray, + sizeof(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray, + sizeof(DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&roundTableOpen, sizeof(roundTableOpen), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray, + sizeof(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray, + sizeof(DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + char hostRoundTableOpen; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&hostRoundTableOpen, sizeof(hostRoundTableOpen), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + // the tests below read the first flag (reading the received one loses the match) + roundTableOpen = hostRoundTableOpen; + if (!DAT_GameSynchronyState::instance.isHost + && DAT_GameCore::instance.currentMenuViewType != OpenSHC::UI::Enums::MVT_LOBBY_MENU) { + return; + } + // the round table opens and closes with the host's + if (DAT_MenuModalComposition1::instance.activeModalDialogID == OpenSHC::UI::Enums::MMT_NONE) { + if (!roundTableOpen) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_ROUNDTABLE, FALSE); + } + if (!roundTableOpen + && DAT_MenuModalComposition1::instance.activeModalDialogID == OpenSHC::UI::Enums::MMT_ROUNDTABLE) { + DAT_MenuModalComposition1::instance.activeModalDialogID = OpenSHC::UI::Enums::MMT_NONE; + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index cef0539a5f..bf4395d40e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22973,7 +22973,7 @@ SHC_3BB0A8C1_0x00485CC0 | 0.0% | Pending SHC_3BB0A8C1_0x00485E80 | 0.0% | Pending -SHC_3BB0A8C1_0x00485F20 | 0.0% | Pending +SHC_3BB0A8C1_0x00485F20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00486040 | 0.0% | Pending From 13cc8d04fbdd3db0f0ccb9423b2240763e94a0a2 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 06:18:25 +0100 Subject: [PATCH 28/45] reimplement: SHC_3BB0A8C1_0x00485CC0 100.0% Reimplemented StartReceivingMapFile, from gynt's draft on upstream's reimpl/Synchrony-Commands (70b9f632d at 76.1%, ed4a057a4 at 81.4%, his newest commit on that branch's file; the status line reads 76.1%). His other branches carry an older form, 46b7c9413 at 70.37%. On main's headers the draft reads reccmp 84.1 (normalized 79.8), and now 100.0 (normalized 100.0). quick_diff 111/111 at 0.9910 (the draft: 0.8288); the rest is the /GS cookie load, which reccmp is told to ignore. What the match needed: - The map name lookup is written inside the first serialize call, so the size and the two flags are pushed before the lookup is called. - The name's copy and the two searches for its end are strcpy and strcat, with ".map" as the macro S__MAP_005A2294, because the original copies it inline (as main's MenuItemActionHandler_SendReceiveMap_Main does). Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has all three: the nested lookup, strcpy and strcat. Style: the strcpy pragma, the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half and the host are early returns, "wb" is s_wb_005a5510, and the file name is a `char* const` where the original keeps it (it is fetched before "wb" is pushed). Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/StartReceivingMapFile.cpp | 85 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/StartReceivingMapFile.cpp diff --git a/src/OpenSHC/Synchrony/Commands/StartReceivingMapFile.cpp b/src/OpenSHC/Synchrony/Commands/StartReceivingMapFile.cpp new file mode 100644 index 0000000000..ccac96e78a --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/StartReceivingMapFile.cpp @@ -0,0 +1,85 @@ +// disable deprecation warnings for strcpy and strcat +#pragma warning(disable : 4996) + +#include "../Commands.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/IO/FileResourceType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/string-literals.hpp" +#include "OpenSHC/string-macros.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00485CC0 + void Commands::StartReceivingMapFile() + { + char mapName[1008]; // the size of the original's buffer + // the map's name (1000 characters) and the file's size + DAT_GameSynchronyState::instance.DAT_CommandSize = 1004; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0), + 1000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.mapSendingFileSize, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + // the sender makes the map file the active resource, and the command goes to one player only + strcpy(mapName, + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0)); + // ".map" + strcat(mapName, S__MAP_005A2294); + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_MAPS, mapName); + DAT_GameSynchronyState::instance.DAT_PlayerIDReceiver + = DAT_GameSynchronyState::instance + .currentPlayerFullIDArray[DAT_GameSynchronyState::instance.DAT_GameCommandParam1]; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(mapName, 1000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.mapSendingFileSize, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (DAT_GameSynchronyState::instance.isHost) { + return; + } + // the receiver opens the map file for writing and shows the progress dialog + // ".map" + strcat(mapName, S__MAP_005A2294); + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_MAPS, mapName); + char* const fileName = MACRO_CALL_MEMBER( + OpenSHC::IO::ResourceManager_Func::getFileNameOfCurrentActiveResource, DAT_ResourceManager::ptr)(); + // "wb" + DAT_GameSynchronyState::instance.FILEPTR_ReceivedMapFile + = MACRO_CALL(OpenSHC::OS_Func::_fopen)(fileName, s_wb_005a5510); + DAT_GameSynchronyState::instance.DAT_MapFileReceivingState = 2; + DAT_GameSynchronyState::instance.mapSendingByteBufferAddress[0] = 0; + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, DAT_MenuModalComposition1::ptr)( + OpenSHC::UI::Enums::MMT_RECEIVE_MAP_FROM, FALSE); + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bf4395d40e..832778baa0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22969,7 +22969,7 @@ SHC_3BB0A8C1_0x00485C02 | 0.0% | Pending SHC_3BB0A8C1_0x00485C10 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00485CC0 | 0.0% | Pending +SHC_3BB0A8C1_0x00485CC0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00485E80 | 0.0% | Pending From 5c26568bed4ffb187c6420b91ca6e334a90c5f03 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 06:18:25 +0100 Subject: [PATCH 29/45] reimplement: SHC_3BB0A8C1_0x0048B330 100.0% Reimplemented ShareQuitGameVote, from gynt's draft on upstream's reimpl/Synchrony-Commands (c7021d2e0 at 70.8%, 5153b247d at 69.2%, "Dropped return recovered, asm form differs", his newest commit on the file; the status line reads 70.8%). On main's headers the draft reads reccmp 69.2 (normalized 58.6), and now 100.0 (normalized 100.0). quick_diff 109/109 at 1.0000 (the draft: 100 instructions at 0.7656). On main the draft needed one rename to compile: field122_0xc70 is quitGameVoteArray. What the match needed: - The test of the eight votes is a loop that clears a flag for every slot that hasn't voted yes, then one test of the flag. The original has it unrolled (`mov eax, 1`, then `xor eax, eax` after each failed test); the draft's chain of eight `&&` jumps out at the first no. - The vote is stored at `quitGameVoteArray[voter]`, with the local that holds the sender: the original indexes with the register it keeps the sender in (0.9315 with the field read again). - The two message copies are strcpy calls. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has all three: the loop over the slots, the vote stored through the local, and the two strcpy calls. Style: the strcpy pragma, the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return, subjectPlayerID is `voter`, the text numbers are decimal with the text above them ("No", "Yes"), and the loop bound is countof(). Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/ShareQuitGameVote.cpp | 90 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/ShareQuitGameVote.cpp diff --git a/src/OpenSHC/Synchrony/Commands/ShareQuitGameVote.cpp b/src/OpenSHC/Synchrony/Commands/ShareQuitGameVote.cpp new file mode 100644 index 0000000000..48506ad5f8 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/ShareQuitGameVote.cpp @@ -0,0 +1,90 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x0048B330 + void Commands::ShareQuitGameVote() + { + // the vote: 0 yes, 1 no, 2 the vote is called off + DAT_GameSynchronyState::instance.DAT_CommandSize = 4; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + int const voter = DAT_GameSynchronyState::instance.protocolInvokerPlayerID; + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 2 + || DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 1) { + // a no, or the vote called off, ends the vote + DAT_GameSynchronyState::instance.quitGameVoteRelated = 0; + if (DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_ONLINE_VOTE_QUIT_GAME) { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_NONE, FALSE); + } + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 1) { + // "No" + strcpy(DAT_GameSynchronyState::instance.receivedChatMessage, + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_GAME_OPTIONS, 23)); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addChatMessageToDisplayList, + DAT_GameSynchronyState::ptr)(voter, 0); + } + } else if (DAT_GameSynchronyState::instance.quitGameVoteRelated == 2) { + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 != 0) { + return; + } + // a yes is noted, and once every slot has voted yes the game is ended for everyone + DAT_GameSynchronyState::instance.quitGameVoteArray[voter] = 1; + BOOLEnum everyoneAgrees = TRUE; + for (int slot = 1; slot < countof(DAT_GameSynchronyState::instance.quitGameVoteArray); ++slot) { + if (DAT_GameSynchronyState::instance.quitGameVoteArray[slot] == 0) { + everyoneAgrees = FALSE; + } + } + if (everyoneAgrees) { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 1; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_KILL_GAME); + } + } + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == 0) { + // "Yes" + strcpy(DAT_GameSynchronyState::instance.receivedChatMessage, + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_GAME_OPTIONS, 22)); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addChatMessageToDisplayList, + DAT_GameSynchronyState::ptr)(voter, 0); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 832778baa0..48c2e46669 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23145,7 +23145,7 @@ SHC_3BB0A8C1_0x0048B170 | 0.0% | Pending SHC_3BB0A8C1_0x0048B280 | 0.0% | Pending -SHC_3BB0A8C1_0x0048B330 | 0.0% | Pending +SHC_3BB0A8C1_0x0048B330 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048B4E0 | 0.0% | Pending From a3b7223319901dd12da5af67b9cc36095342fec0 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:07 +0100 Subject: [PATCH 30/45] reimplement: SHC_3BB0A8C1_0x0048B6C0 100.0% Reimplemented ShareMapHashForMapName, from gynt's draft on upstream's reimpl/Synchrony-Commands (97bf40d8e at 73.4%, ca943baa1 at 75.3%, his newest commit on that branch's file; the status line reads 70.5%). His other branches carry an older form, 3d9f30daa at 68.44%. On main's headers the draft reads reccmp 78.1 (normalized 77.8), and now 100.0 (normalized 100.0). quick_diff 141/143 at 0.9789 (the draft: 138 at 0.8470); the rest is the /GS cookie load and two alignment jumps the listing doesn't show. On main the draft needed one rename to compile: field282_0x109d98 is mapTransferStatePerPlayer. What the match needed: - The map name lookup is written inside the first serialize call, so the size and the two flags are pushed before the lookup is called. - The name's copy and the two searches for its end are strcpy and strcat, with ".map" as the macro S__MAP_005A2294 (the original copies it inline). The copy into unknownMapName_01 is a strcpy too. - The loop over the slots is a for loop with countof(). Fix against the draft: a client whose own copy of the map hashes differently only gets the quit dialog. The original returns there; the draft went on to queue the command that asks for the map file. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has the nested lookup, strcpy and strcat. It queues the command in an else after the dialog, so it already behaves as the original does. Style: the strcpy pragma, the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half and the host are early returns, _mapHash is `int mapHash` (the hash function returns int), and 0x3ec is 1004. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/ShareMapHashForMapName.cpp | 96 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/ShareMapHashForMapName.cpp diff --git a/src/OpenSHC/Synchrony/Commands/ShareMapHashForMapName.cpp b/src/OpenSHC/Synchrony/Commands/ShareMapHashForMapName.cpp new file mode 100644 index 0000000000..7c2327e8df --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/ShareMapHashForMapName.cpp @@ -0,0 +1,96 @@ +// disable deprecation warnings for strcpy and strcat +#pragma warning(disable : 4996) + +#include "../Commands.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/MenuTextInputState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/IO/FileResourceType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/string-macros.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x0048B6C0 + void Commands::ShareMapHashForMapName() + { + int mapHash; + char mapName[1008]; // the size of the original's buffer + // the map's name (1000 characters) and the hash of the map file + DAT_GameSynchronyState::instance.DAT_CommandSize = 1004; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0), + 1000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + strcpy(mapName, + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0)); + // ".map" + strcat(mapName, S__MAP_005A2294); + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_MAPS, mapName); + mapHash = MACRO_CALL_MEMBER( + OpenSHC::IO::ResourceManager_Func::fileHashFunctionByteByByte, DAT_ResourceManager::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&mapHash, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + // every other player still has to answer; empty slots and this machine's own count as having the map + for (int slot = 1; slot < countof(DAT_GameSynchronyState::instance.mapTransferStatePerPlayer); ++slot) { + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[slot] == -1 + || slot == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + DAT_GameSynchronyState::instance.mapTransferStatePerPlayer[slot] = 2; + } else { + DAT_GameSynchronyState::instance.mapTransferStatePerPlayer[slot] = 0; + } + } + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(mapName, 1000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&mapHash, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (DAT_GameSynchronyState::instance.isHost) { + return; + } + strcpy(DAT_GameSynchronyState::instance.unknownMapName_01, mapName); + // ".map" + strcat(mapName, S__MAP_005A2294); + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_MAPS, mapName); + // a client whose own copy of the map hashes differently is asked to quit; one with the same map answers + if (MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::fileHashFunctionByteByByte, DAT_ResourceManager::ptr)() + != mapHash) { + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 2000; + MACRO_CALL_MEMBER(OpenSHC::UI::MenuTextInputState_Func::activateModalDialogAndClearText, + DAT_MenuTextInputState::ptr)(OpenSHC::UI::Enums::MMT_QUIT_DIALOG); + return; + } + // parameter 0 is the flag StartSendingMapFile reads: this machine has the map + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 1; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_START_OR_STOP_SEND_MAP_FILEUnk); + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 48c2e46669..b66b03a2e3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23151,7 +23151,7 @@ SHC_3BB0A8C1_0x0048B4E0 | 0.0% | Pending SHC_3BB0A8C1_0x0048B5B0 | 0.0% | Pending -SHC_3BB0A8C1_0x0048B6C0 | 0.0% | Pending +SHC_3BB0A8C1_0x0048B6C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048B7B0 | 0.0% | Pending From 662ba0af983da8f1a11be49bb210a0de48f0825f Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:07 +0100 Subject: [PATCH 31/45] reimplement: SHC_3BB0A8C1_0x004863A0 100.0% Reimplemented UpdateSkirmishGameMenuFaceBitmap, from gynt's draft on upstream's reimpl/Synchrony-Commands (f48368635 and c2eea52e2 at 66.7%, "Buffer overflow fixed, match unchanged", his newest commit on the file). On main's headers the draft reads reccmp 69.4 (normalized 69.4), and now 100.0 (normalized 100.0). quick_diff 103/103 at 0.9515 (the draft: 113 instructions at 0.7778); the rest is the /GS cookie load. On main the draft needed one rename to compile: TextureRenderCore's field69_0x98 is bitmapFaceSizes. What the match needed: - The row is a `byte*` taken from the ushort face pointer, `bitmapsFaces_0x94 + (rowIndex + face * 66) * 64`, and the two loops index it with `pixel * 2` and `pixel * 2 + 1`. The draft summed bytes through `(int)` with the counter inside the sum, which gives a second pointer that walks. - The three locals are declared slot, rowIndex, rowBytes[128], which is the original's frame: the row index is read first into the second slot. - The slot test is `< 1 || > 8`. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) also takes the row as a byte pointer; his loops are do-while. Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half and a slot out of range are early returns, the buffer's size is sizeof(), and the face size is a FACE_SIZE constant (66 * 64 * 2, as setBMPFacesToMagenta has it) in place of 0x2100, with FACE_HEIGHT and FACE_WIDTH for the 66 and 64 of the rows, the loops and the buffer. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../UpdateSkirmishGameMenuFaceBitmap.cpp | 78 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/UpdateSkirmishGameMenuFaceBitmap.cpp diff --git a/src/OpenSHC/Synchrony/Commands/UpdateSkirmishGameMenuFaceBitmap.cpp b/src/OpenSHC/Synchrony/Commands/UpdateSkirmishGameMenuFaceBitmap.cpp new file mode 100644 index 0000000000..2a5e7f3320 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/UpdateSkirmishGameMenuFaceBitmap.cpp @@ -0,0 +1,78 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // one face: 66 rows of 64 pixels of two bytes + int const FACE_HEIGHT = 66; + int const FACE_WIDTH = 64; + int const FACE_SIZE = FACE_HEIGHT * FACE_WIDTH * 2; + + // FUNCTION: STRONGHOLDCRUSADER 0x004863A0 + void Commands::UpdateSkirmishGameMenuFaceBitmap() + { + int slot; + int rowIndex; + byte rowBytes[FACE_WIDTH * 2]; + // one row of the sender's face: the row's number, the sender's slot and the row's 64 pixels, as their 64 low + // bytes followed by their 64 high bytes + DAT_GameSynchronyState::instance.DAT_CommandSize = 136; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + // the row comes from the chosen lord's face + byte* const row = (byte*)(DAT_TextureRenderCoreObject::instance.bitmapsFaces_0x94 + + (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 + + (DAT_GameCore::instance.lordIconUnk - 2) * FACE_HEIGHT) + * FACE_WIDTH); + for (int pixel = 0; pixel < FACE_WIDTH; ++pixel) { + rowBytes[pixel] = row[pixel * 2]; + rowBytes[pixel + FACE_WIDTH] = row[pixel * 2 + 1]; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(rowBytes, sizeof(rowBytes), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&rowIndex, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&slot, 4, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (slot < 1 || slot > 8) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(rowBytes, sizeof(rowBytes), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + // the row goes into the slot's face (the players' faces follow the 20 lords' faces; the slots start at 1) + byte* const row = (byte*)(DAT_TextureRenderCoreObject::instance.bitmapsFaces_0x94 + + (rowIndex + (slot + 19) * FACE_HEIGHT) * FACE_WIDTH); + for (int pixel = 0; pixel < FACE_WIDTH; ++pixel) { + row[pixel * 2] = rowBytes[pixel]; + row[pixel * 2 + 1] = rowBytes[pixel + FACE_WIDTH]; + } + DAT_TextureRenderCoreObject::instance.bitmapFaceSizes[slot + 19] = FACE_SIZE; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b66b03a2e3..e804f26197 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22993,7 +22993,7 @@ SHC_3BB0A8C1_0x00486318 | 0.0% | Pending SHC_3BB0A8C1_0x00486320 | 0.0% | Pending -SHC_3BB0A8C1_0x004863A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004863A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00486530 | 0.0% | Pending From c26dd507dc8952f77879d8bf098289deb013162c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:07 +0100 Subject: [PATCH 32/45] reimplement: SHC_3BB0A8C1_0x00485380 100.0% Reimplemented SomePlayerNameUpdateCommand, from gynt's draft on upstream's reimpl/Synchrony-Commands (9720c0ea1 at 27.9%, e52878b8d at 70.7%, "Dispatch form fixed, string copies differ", his newest commit on the file; the status line reads 27.9%). On main's headers the draft reads reccmp 73.5 (normalized 70.8), and now 100.0 (normalized 100.0). quick_diff 105/105 at 0.9905 (the draft: 109 instructions at 0.7944); the rest is the /GS cookie load. What the match needed: - The own name's lookup is written inside the call that converts it, so the 250 is pushed before the lookup is called. - The copy into the final results and the two copies into the chat lines' name arrays are strcpy calls, in a for loop over DAT_ChatEventArray with countof(); the subject's name array is named (DAT_ChatMessageSubjectPlayerNameArray) in place of an offset of -20 rows from the object's. - protocolInvokerPlayerID is read where it is used, with no local: the original reads it again after each copy. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has two of the copies as strcpy and the loop over the chat lines. Style: the strcpy pragma, the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return, an unused chat line is a continue (its flag is compared with TRUE, as the original tests it with 1), local_20c is wideName[MAX_PATH], and the text array index is TAIT_ZERO. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/SomePlayerNameUpdateCommand.cpp | 76 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/SomePlayerNameUpdateCommand.cpp diff --git a/src/OpenSHC/Synchrony/Commands/SomePlayerNameUpdateCommand.cpp b/src/OpenSHC/Synchrony/Commands/SomePlayerNameUpdateCommand.cpp new file mode 100644 index 0000000000..028971a440 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/SomePlayerNameUpdateCommand.cpp @@ -0,0 +1,76 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/Util/WideCharMultiByteState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Text/TextArrayIndexType.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" +#include "OpenSHC/Globals/DAT_WideCharMultiByteState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00485380 + void Commands::SomePlayerNameUpdateCommand() + { + WCHAR wideName[MAX_PATH]; + // the sender's name (250 wide characters) + DAT_GameSynchronyState::instance.DAT_CommandSize = 500; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::multiByteToWideCharWithSize, + DAT_WideCharMultiByteState::ptr)(wideName, + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::getTextArrayPointer, + DAT_UserTextHandlerState::ptr)(OpenSHC::Text::TAIT_ZERO), + 250); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 500, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 500, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER( + OpenSHC::Util::WideCharMultiByteState_Func::wideCharToMultiByteWithSize, DAT_WideCharMultiByteState::ptr)( + DAT_GameSynchronyState::instance.DAT_PlayerNames[DAT_GameSynchronyState::instance.protocolInvokerPlayerID], + wideName, 250); + strcpy(DAT_GameSynchronyState::instance.finalResults + .names[DAT_GameSynchronyState::instance.protocolInvokerPlayerID], + DAT_GameSynchronyState::instance.DAT_PlayerNames[DAT_GameSynchronyState::instance.protocolInvokerPlayerID]); + // the chat lines that name the player get the new name + for (int line = 0; line < countof(DAT_GameSynchronyState::instance.DAT_ChatEventArray); ++line) { + // compared with TRUE: the original tests the flag == 1 + if (DAT_GameSynchronyState::instance.DAT_ChatEventArray[line].flag != TRUE) { + continue; + } + if (DAT_GameSynchronyState::instance.DAT_ChatEventArray[line].subjectPlayer + == DAT_GameSynchronyState::instance.protocolInvokerPlayerID) { + strcpy(DAT_GameSynchronyState::instance.DAT_ChatMessageSubjectPlayerNameArray[line], + DAT_GameSynchronyState::instance + .DAT_PlayerNames[DAT_GameSynchronyState::instance.protocolInvokerPlayerID]); + } + if (DAT_GameSynchronyState::instance.DAT_ChatEventArray[line].objectPlayer + == DAT_GameSynchronyState::instance.protocolInvokerPlayerID) { + strcpy(DAT_GameSynchronyState::instance.DAT_ChatMessageObjectPlayerNameArray[line], + DAT_GameSynchronyState::instance + .DAT_PlayerNames[DAT_GameSynchronyState::instance.protocolInvokerPlayerID]); + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e804f26197..bca9420963 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22741,7 +22741,7 @@ SHC_3BB0A8C1_0x004852D0 | 0.0% | Pending SHC_3BB0A8C1_0x00485330 | 0.0% | Pending -SHC_3BB0A8C1_0x00485380 | 0.0% | Pending +SHC_3BB0A8C1_0x00485380 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00485520 | 0.0% | Pending From e564be3d13dd0483aa7c1960f5ebe7db3160c4ee Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:07 +0100 Subject: [PATCH 33/45] reimplement: SHC_3BB0A8C1_0x00483A00 100.0% Reimplemented SendResyncCharLayer, from gynt's draft on upstream's reimpl/Synchrony-Commands (aeaf655ac, 76.8%, his only commit on it there). The draft doesn't compile on main (it assigns a char layer to a `byte*`), so it has no score here; this reads reccmp 100.0 (normalized 100.0). quick_diff 390/390 at 0.9333, where every differing line is a TileMapState offset above 0x400000 that quick_diff reads as an address. His fork's development branch has an older form of the file, ff484f59c at 66.75%. What the match needed: one serialize call per layer in both halves, as in ResyncShortLayer. The draft's receiving half kept the decompiler's form, where seven cases set a `destination` and share one call after the switch; that sharing is the compiler's, and it comes back from the plain cases. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has one call per case in both halves. Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return (wrong action plan, or the host), each chunk is `&layer[chunk * 2512]`, and the sizes and the nineteen case labels are decimal (10 to 28; the headers have no enum for the layer numbers). Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/SendResyncCharLayer.cpp | 358 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/SendResyncCharLayer.cpp diff --git a/src/OpenSHC/Synchrony/Commands/SendResyncCharLayer.cpp b/src/OpenSHC/Synchrony/Commands/SendResyncCharLayer.cpp new file mode 100644 index 0000000000..c20efeb11d --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/SendResyncCharLayer.cpp @@ -0,0 +1,358 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00483A00 + void Commands::SendResyncCharLayer() + { + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + // the layer's number, the chunk's number and one chunk of the layer: 2512 tiles of one byte each + DAT_GameSynchronyState::instance.DAT_CommandSize = 2520; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { + case 10: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .DamageLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 11: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .LuminesenceLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 12: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .WallOwnerLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 13: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .PathLinkageLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 14: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .OccupancyLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 15: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .HeightLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 16: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .AIInfoLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 17: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .AIZoneLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 18: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_TileMap1104[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 19: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .unitDeathHeatMap[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 20: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[0] + [DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 21: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[1] + [DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 22: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[2] + [DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 23: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[3] + [DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 24: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[4] + [DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 25: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[5] + [DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 26: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[6] + [DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 27: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[7] + [DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + case 28: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[8] + [DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + break; + } + return; + } + // only the clients take the host's copy of the layer + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE + || DAT_GameSynchronyState::instance.isHost) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 4, + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + switch (DAT_GameSynchronyState::instance.DAT_GameCommandParam0) { + case 10: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance.DamageLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 11: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .LuminesenceLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 12: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .WallOwnerLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 13: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .PathLinkageLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 14: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .OccupancyLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 15: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance.HeightLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 16: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance.AIInfoLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 17: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance.AIZoneLayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 18: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_TileMap1104[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 19: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .unitDeathHeatMap[DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 20: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[0][DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 21: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[1][DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 22: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[2][DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 23: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[3][DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 24: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[4][DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 25: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[5][DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 26: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[6][DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 27: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[7][DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + case 28: + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)( + &DAT_TileMapState::instance + .SEC_PathfindingCostTileMap1105[8][DAT_GameSynchronyState::instance.DAT_GameCommandParam1 * 2512], + 2512, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + break; + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bca9420963..057bfdb088 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22583,7 +22583,7 @@ SHC_3BB0A8C1_0x00483570 | 0.0% | Pending SHC_3BB0A8C1_0x00483850 | 0.0% | Pending -SHC_3BB0A8C1_0x00483A00 | 0.0% | Pending +SHC_3BB0A8C1_0x00483A00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00484020 | 0.0% | Pending From 52526f746ae60491042ef4838b833bfa3ba4143e Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:08 +0100 Subject: [PATCH 34/45] headers: GameCommandType gets GCT_UNKNOWN_53 The enum has no name for command 53. SetPlayerNameUnk, the next commit, queues it. Evidence in the original: - 53 is queued in one place: 0x00489C50 `push 0x35`, then 0x00489C61 `call 0x00489100` (queueCommand), in SetPlayerNameUnk. A scan of the 215 calls to queueCommand finds no other immediate 53. - queueCommand stores the type at 0x0048916E, `mov byte ptr [ecx + esi + 0x3c684], bl`, and dispatches it at 0x004891DF, `movsx ecx, byte ptr [eax + esi + 0x3c684]`, then 0x004891E7 `mov edx, [ecx*4 + 0x00B38E10]` and `call edx`. The receive paths at 0x0048017F, 0x0048034A and 0x0048041E index the same table. - The table's entry 53, at 0x00B38EE4, is 0x00483850, Commands::SharePlayerName. The name follows the enum's other unnamed values (GCT_UNKNOWN_33, _37, _40). Wilps's header, on the fork of gynt (reimpl/Wilps-2026-10-18, 8ca78619c), calls it GCT_SHARE_PLAYER_NAME. Co-Authored-By: Claude Fable 5.2 --- src/OpenSHC/Commands/GameCommandType.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenSHC/Commands/GameCommandType.hpp b/src/OpenSHC/Commands/GameCommandType.hpp index fe1071aee4..871bac1018 100644 --- a/src/OpenSHC/Commands/GameCommandType.hpp +++ b/src/OpenSHC/Commands/GameCommandType.hpp @@ -58,6 +58,7 @@ namespace Commands { GCT_LOAD_MAP_HEADER = 48, // 0x00000030 GCT_ACKNOLEDGE_MAP_EXISTENCE = 49, // 0x00000031 GCT_CHANGE_GAME_INTENSITY_OR_BALANCE = 52, // 0x00000034 + GCT_UNKNOWN_53 = 53, // 0x00000035 GCT_GAME_DESYNCUnk = 54, // 0x00000036 GCT_CHECK_GAME_SYNCUnk = 55, // 0x00000037 GCT_SEND_RESYNC_UNIT = 56, // 0x00000038 From a92142a70ce6772e2e09b31519816ec93cbde03c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:08 +0100 Subject: [PATCH 35/45] reimplement: SHC_3BB0A8C1_0x00489AC0 100.0% Reimplemented SetPlayerNameUnk, from gynt's draft on upstream's reimpl/Synchrony-Commands (46e2f889d at 40.69%, 808cb707c and 7e98673c8 at 53.1%, 5597d2994 at 61.4%, his newest commit on the file; the status line reads 53.1%). On main's headers, with field215_0x106e1c renamed to main's lobbyStateReceived, the draft reads reccmp 63.9 (normalized 54.0), and now 100.0 (normalized 100.0). quick_diff 120/120 at 0.9917 (the draft: 0.6639); the rest is the /GS cookie load. 46e2f889d is only on his fork (development); upstream's branch has the file from 808cb707c on. What the match needed: - The host's arm comes first, and each arm has its own deserialize call: the original pushes the call's last three arguments before it tests isHost and the buffer's address after it. - The wide string's length is wcslen(), in place of a pointer loop. - The second copy of the players' IDs and names is a for loop over the slots 1 to 8 with a strcpy, in place of two walking pointers. - The faces' copy steps the ushort face pointer by faces (28 * 66 * 64 and 20 * 66 * 64) in place of byte offsets on an int cast. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has the first three: the host's arm first, wcslen and the loop with strcpy. The behaviour is the draft's. Style: the strcpy pragma, the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return, local_58 and local_4c are base64State and wideName, the loop's bound is countof(), the size of shortMapName is sizeof(), the faces' size is 8 * FACE_SIZE (66 * 64 * 2, as setBMPFacesToMagenta has it) in place of 0x10800, with FACE_HEIGHT and FACE_WIDTH for the pixel offsets, the wide string's size is wcslen() * sizeof(WCHAR), and the numbers are decimal. The command type is GCT_UNKNOWN_53, which the commit before this one adds to the enum. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/SetPlayerNameUnk.cpp | 92 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/SetPlayerNameUnk.cpp diff --git a/src/OpenSHC/Synchrony/Commands/SetPlayerNameUnk.cpp b/src/OpenSHC/Synchrony/Commands/SetPlayerNameUnk.cpp new file mode 100644 index 0000000000..b292af0d09 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/SetPlayerNameUnk.cpp @@ -0,0 +1,92 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#include "../Commands.func.hpp" + +#include "OpenSHC/IO.func.hpp" +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Synchrony.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Util/WideCharMultiByteState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/IO/Base64State.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_WideCharMultiByteState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // one face: 66 rows of 64 pixels of two bytes + int const FACE_HEIGHT = 66; + int const FACE_WIDTH = 64; + int const FACE_SIZE = FACE_HEIGHT * FACE_WIDTH * 2; + + // FUNCTION: STRONGHOLDCRUSADER 0x00489AC0 + void Commands::SetPlayerNameUnk() + { + OpenSHC::IO::Base64State base64State; + WCHAR wideName[36]; // the size of the original's buffer + // the short map name (33 wide characters) + DAT_GameSynchronyState::instance.DAT_CommandSize = 66; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::multiByteToWideCharWithSize, + DAT_WideCharMultiByteState::ptr)(wideName, DAT_GameSynchronyState::instance.shortMapName, 33); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 66, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + if (DAT_GameSynchronyState::instance.isHost) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 66, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::wideCharToMultiByteWithSize, + DAT_WideCharMultiByteState::ptr)(DAT_GameSynchronyState::instance.shortMapName, wideName, 1000); + } else { + // a client keeps the name Base64 encoded + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 66, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL(OpenSHC::IO_Func::Base64EncodeInit)(&base64State); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_IntegerValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_GameSynchronyState::instance.shortMapName), 0, + DAT_GameSynchronyState::instance.shortMapName); + MACRO_CALL(OpenSHC::IO_Func::Base64Encode)((char*)wideName, wcslen(wideName) * sizeof(WCHAR), + DAT_GameSynchronyState::instance.shortMapName, &base64State); + } + // the players' IDs and names get a second copy + for (int slot = 1; slot < countof(DAT_GameSynchronyState::instance.DAT_CurrentPlayerFullIDArray2); ++slot) { + DAT_GameSynchronyState::instance.DAT_CurrentPlayerFullIDArray2[slot] + = DAT_GameSynchronyState::instance.currentPlayerFullIDArray[slot]; + strcpy(DAT_GameSynchronyState::instance.playerNames2[slot], + DAT_GameSynchronyState::instance.DAT_PlayerNames[slot]); + } + // and so do the eight players' faces (they follow the 20 lords' faces) + MACRO_CALL(OpenSHC::OS_Func::_memcpy)( + DAT_TextureRenderCoreObject::instance.bitmapsFaces_0x94 + 28 * FACE_HEIGHT * FACE_WIDTH, + DAT_TextureRenderCoreObject::instance.bitmapsFaces_0x94 + 20 * FACE_HEIGHT * FACE_WIDTH, 8 * FACE_SIZE); + DAT_GameSynchronyState::instance.DAT_SomePlayerID = DAT_GameSynchronyState::instance.currentPlayerSlotID; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::clearChatEvents, DAT_GameSynchronyState::ptr)(); + MACRO_CALL_MEMBER( + OpenSHC::Synchrony::GameSynchronyState_Func::setSessionDescription, DAT_GameSynchronyState::ptr)(); + MACRO_CALL(OpenSHC::Synchrony_Func::ProgressBarRelated)(); + DAT_GameSynchronyState::instance.lobbyStateReceived = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_UNKNOWN_53); + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 057bfdb088..2c74705315 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23105,7 +23105,7 @@ SHC_3BB0A8C1_0x00489880 | 0.0% | Pending SHC_3BB0A8C1_0x00489A10 | 0.0% | Pending -SHC_3BB0A8C1_0x00489AC0 | 0.0% | Pending +SHC_3BB0A8C1_0x00489AC0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00489C80 | 100.0% | Reimplemented From 7c54a0367c6496b0a80489e8a3e518b9735418be Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:08 +0100 Subject: [PATCH 36/45] headers: GameCommandType gets GCT_UNKNOWN_51 The enum has no name for command 51. SubmitMSVMapIndexAndProperties, the next commit, queues it. Evidence in the original: - 51 is queued at 0x0048A0B1 `push 0x33`, then 0x0048A0C3 `call 0x00489100` (queueCommand), in SubmitMSVMapIndexAndProperties. A scan of the 215 calls to queueCommand finds no other immediate 51. - queueCommand dispatches the type through the table at 0x00B38E10 (0x004891E7 `mov edx, [ecx*4 + 0x00B38E10]`, then `call edx`), as the commit that adds GCT_UNKNOWN_53 shows. - The table's entry 51, at 0x00B38EDC, is 0x004834B0, Commands::ShareMSVMapIndex. Wilps's header, on the fork of gynt (reimpl/Wilps-2026-10-18, 8ca78619c), calls it GCT_SHARE_MSV_MAP_INDEX. Co-Authored-By: Claude Fable 5.2 --- src/OpenSHC/Commands/GameCommandType.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenSHC/Commands/GameCommandType.hpp b/src/OpenSHC/Commands/GameCommandType.hpp index 871bac1018..fbcf9dc046 100644 --- a/src/OpenSHC/Commands/GameCommandType.hpp +++ b/src/OpenSHC/Commands/GameCommandType.hpp @@ -57,6 +57,7 @@ namespace Commands { GCT_CHANGE_MAP_SELECTION = 47, // 0x0000002F GCT_LOAD_MAP_HEADER = 48, // 0x00000030 GCT_ACKNOLEDGE_MAP_EXISTENCE = 49, // 0x00000031 + GCT_UNKNOWN_51 = 51, // 0x00000033 GCT_CHANGE_GAME_INTENSITY_OR_BALANCE = 52, // 0x00000034 GCT_UNKNOWN_53 = 53, // 0x00000035 GCT_GAME_DESYNCUnk = 54, // 0x00000036 From e1ca8f95de0f317150b7ffde47b317c0ef707a68 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:08 +0100 Subject: [PATCH 37/45] reimplement: SHC_3BB0A8C1_0x00489E30 100.0% Reimplemented SubmitMSVMapIndexAndProperties, from gynt's draft on upstream's reimpl/Synchrony-Commands (19c8ce297 at 34.97%, 7455923aa at 44.5%, 82db2ef7a at 52.3%, "Buffer fixes, frame still short", his newest commit on the file; the status line reads 44.5%). On main's headers the draft reads reccmp 52.8 (normalized 53.3), and now 99.5 (normalized 100.0). The one difference left is the name of a call target: the stack probe, `call ` in the original and `call _chkstk` in ours. The review of #298 (b5499a69c) counted that as a match, so the status line says 100.0%. quick_diff 187/188 at 0.9920 (the draft: 182 instructions at 0.6973); the rest is the /GS cookie load and an alignment jmp. 19c8ce297 is only on his fork (development); upstream's branch has the file from 7455923aa on. What the match needed: - The answer to the host (parameter 0 cleared, the map's index as parameter 1, command 51) is written twice: once where the save file doesn't exist, and once where its time or its units' hash differs. The compiler merges the two copies into the one the original has, but the second zero is what makes it keep 0 in ebx for the whole function (push ebx, cmp cl, bl, mov [...], ebx), and the two copies shift the registers of the last compares to the original's ecx, edx, eax. Written once (the draft's goto, an early return, a flag, or one condition), the function uses immediates and reads quick_diff 0.8248 with 183 instructions. - The buffers are char[2008] and WCHAR[2006], the original's frame of 0x17a0 with its stack probe: 12 (three ints) + 12 (Base64State) + 2008 + 4012 + 4 (cookie). - The map's name lookup is written inside the call that converts it, so the 1000 is pushed before the lookup is called; the second lookup is inside a strcpy. - strcpy and strcat for the save's name (".msv" as the macro), and wcslen() for the wide string's length. Behaviour fixed against the draft on main: DAT_ArrayOfMapIndices is indexed with parameter 0, as the original does (mov edx, [ecx*4 + 0x1126e28]). The draft's `parameter 0 - 1` was right on its branch, where the array starts at 0x884; on main it starts at 0x880. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has strcpy, strcat and wcslen. Style: the strcpy pragma, the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half and the host are early returns, the goto is gone, the locals have names (saveName, wideName, mapIndex, mapTime, unitsHash, base64State) and are declared where they are filled, the scalar sizes are sizeof(), the wide string's size is wcslen() * sizeof(WCHAR), and the numbers are decimal. The command type is GCT_UNKNOWN_51, which the commit before this one adds to the enum. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../SubmitMSVMapIndexAndProperties.cpp | 127 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/SubmitMSVMapIndexAndProperties.cpp diff --git a/src/OpenSHC/Synchrony/Commands/SubmitMSVMapIndexAndProperties.cpp b/src/OpenSHC/Synchrony/Commands/SubmitMSVMapIndexAndProperties.cpp new file mode 100644 index 0000000000..a92f00edae --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/SubmitMSVMapIndexAndProperties.cpp @@ -0,0 +1,127 @@ +// disable deprecation warnings for strcpy and strcat +#pragma warning(disable : 4996) + +#include "../Commands.func.hpp" + +#include "OpenSHC/IO.func.hpp" +#include "OpenSHC/IO/FilePackager.func.hpp" +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Util/WideCharMultiByteState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/IO/Base64State.hpp" +#include "OpenSHC/IO/FileResourceType.hpp" +#include "OpenSHC/string-macros.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_WideCharMultiByteState.hpp" +#include "OpenSHC/Globals/FilePackagerObj.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00489E30 + void Commands::SubmitMSVMapIndexAndProperties() + { + char saveName[2008]; // the size of the original's buffer + WCHAR wideName[2006]; // the size of the original's buffer + // the map's name (1000 wide characters), its index, and the time and the units' hash of its save + DAT_GameSynchronyState::instance.DAT_CommandSize = 2012; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::multiByteToWideCharWithSize, + DAT_WideCharMultiByteState::ptr)(wideName, + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_GameCommandParam0]), + 1000); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 2000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + sizeof(DAT_GameSynchronyState::instance.DAT_GameCommandParam0), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + // the save of the map: its name with ".msv" + strcpy(saveName, + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_GameCommandParam0])); + // ".msv" + strcat(saveName, S__MSV_005A7498); + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_UNKNOWN, saveName); + MACRO_CALL_MEMBER(OpenSHC::IO::FilePackager_Func::readMapHeader, FilePackagerObj::ptr)(FALSE); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.savedMapTimeInTicks, + sizeof(DAT_GameSynchronyState::instance.savedMapTimeInTicks), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.savedUnitsCRC32Hash, + sizeof(DAT_GameSynchronyState::instance.savedUnitsCRC32Hash), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 2000, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + // the save's name on this machine: the received name, Base64 encoded, with ".msv" + OpenSHC::IO::Base64State base64State; + MACRO_CALL(OpenSHC::IO_Func::Base64EncodeInit)(&base64State); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_IntegerValue, DAT_LowLevelMemory::ptr)( + 1010, 0, saveName); + MACRO_CALL(OpenSHC::IO_Func::Base64Encode)( + (char*)wideName, wcslen(wideName) * sizeof(WCHAR), saveName, &base64State); + int mapIndex; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&mapIndex, sizeof(mapIndex), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + int mapTime; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&mapTime, sizeof(mapTime), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + int unitsHash; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&unitsHash, sizeof(unitsHash), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (DAT_GameSynchronyState::instance.isHost) { + return; + } + // ".msv" + strcat(saveName, S__MSV_005A7498); + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_UNKNOWN, saveName); + // a client without the save, or with a save of another time or with other units, answers with the map's + // index; the answer is written in both places (written once, it loses the match) + if (!MACRO_CALL_MEMBER( + OpenSHC::IO::ResourceManager_Func::doesFileOfActiveResourceExist, DAT_ResourceManager::ptr)()) { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 0; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = mapIndex; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_UNKNOWN_51); + return; + } + MACRO_CALL_MEMBER(OpenSHC::IO::FilePackager_Func::readMapHeader, FilePackagerObj::ptr)(FALSE); + if (DAT_GameSynchronyState::instance.savedMapTimeInTicks != mapTime + || DAT_GameSynchronyState::instance.savedUnitsCRC32Hash != unitsHash) { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 0; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = mapIndex; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_UNKNOWN_51); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2c74705315..be213f4353 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23109,7 +23109,7 @@ SHC_3BB0A8C1_0x00489AC0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00489C80 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00489E30 | 0.0% | Pending +SHC_3BB0A8C1_0x00489E30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048A050 | 0.0% | Pending From 65fb23e0b411399d717ec951f039c9b1e9f13bc2 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:08 +0100 Subject: [PATCH 38/45] reimplement: SHC_3BB0A8C1_0x0048B8F0 100.0% Reimplemented ShareMapPart, from gynt's draft on upstream's reimpl/Synchrony-Commands (3bc194b69 at 26.91%, 540414210 at 33.2%, fc3a51fbb and 8f6faf18f at 66.7%, "Gotos removed, match unchanged", his newest commit on the file; the status line reads 33.2%). On main's headers the draft reads reccmp 68.2 (normalized 65.4), and now 100.0 (normalized 100.0). quick_diff 202/202 at 0.9950 (the draft: 0.7268); the rest is the /GS cookie load. gynt's newest commit on the file on any branch, 6cbbfc2bd (2026-11-02, his fork's reimpl/UI-MenuItems-development), writes the length test as `-(int)_buffer2 > 1`; this doesn't build on it: the original tests `>= 0`. 3bc194b69 is only on his fork (development); upstream's branch has the file from 540414210 on. What the match needed: - The part that ends the transfer (parameter 0 is -1) returns after its three serialize calls, as the original does (pop ebx, the cookie check and ret at 0x0048B9AD). - The sender's test is the file's end first (`>= mapSendingFileSize`, which closes the file) with the tenth part in the else-if, and one condition for the request state: the flag, the receiver's ID and the receiver not being this machine. - The flag is a bool that starts false before the plan is tested and is cleared again in the ending part (the original stores it twice; without the second store the function has 201 instructions). - `+=` for the two byte counters, and `>= 0` for the length test (cmp eax, ebx; jl). Behaviour fixed against the draft: the ending part. The draft had no return there, so after sending the empty part of length -1 it went on to read the file and send a second part in the same command. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has that return and the file's end test with the else-if. Style: the first include is ../Commands.func.hpp, the using lines and block comments (with the draft's TODO) are gone, the execute half is an early return, the locals have names (answerExpected, receivedAnswerExpected, byteCount, part) and the two flags are declared where they are first set, the sizes are sizeof(), NULL for the file pointers, the command type is GCT_UNKNOWN_107 in place of an or of two other names, and the numbers are decimal. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/ShareMapPart.cpp | 137 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/ShareMapPart.cpp diff --git a/src/OpenSHC/Synchrony/Commands/ShareMapPart.cpp b/src/OpenSHC/Synchrony/Commands/ShareMapPart.cpp new file mode 100644 index 0000000000..a54de0327e --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/ShareMapPart.cpp @@ -0,0 +1,137 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x0048B8F0 + void Commands::ShareMapPart() + { + int byteCount; + char part[1024]; + // a part of the map file (1024 bytes), its length, and whether the receiver has to answer it + DAT_GameSynchronyState::instance.DAT_CommandSize = 1029; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + bool answerExpected = false; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + if (DAT_GameSynchronyState::instance + .mapSendingFileHandles[DAT_GameSynchronyState::instance.DAT_GameCommandParam1] + == NULL) { + return; + } + // part -1 ends the transfer: an empty part with the length -1 + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 == -1) { + MACRO_CALL(OpenSHC::OS_Func::_memset)(part, 0, sizeof(part)); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(part, sizeof(part), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + // cleared again, as in the original (without this line the match is lost) + answerExpected = false; + byteCount = -1; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&byteCount, sizeof(byteCount), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&answerExpected, sizeof(answerExpected), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + byteCount = MACRO_CALL(OpenSHC::OS_Func::_fread)(part, 1, sizeof(part), + DAT_GameSynchronyState::instance + .mapSendingFileHandles[DAT_GameSynchronyState::instance.DAT_GameCommandParam1]); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(part, sizeof(part), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&byteCount, sizeof(byteCount), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + DAT_GameSynchronyState::instance + .mapSendingByteBufferAddress[DAT_GameSynchronyState::instance.DAT_GameCommandParam1] += byteCount; + DAT_GameSynchronyState::instance.DAT_PlayerIDReceiver + = DAT_GameSynchronyState::instance + .currentPlayerFullIDArray[DAT_GameSynchronyState::instance.DAT_GameCommandParam1]; + // the receiver answers the last part and every tenth part, and the sender waits for that answer + if (DAT_GameSynchronyState::instance + .mapSendingByteBufferAddress[DAT_GameSynchronyState::instance.DAT_GameCommandParam1] + >= DAT_GameSynchronyState::instance.mapSendingFileSize) { + answerExpected = true; + MACRO_CALL(OpenSHC::OS_Func::_fclose)(DAT_GameSynchronyState::instance + .mapSendingFileHandles[DAT_GameSynchronyState::instance.DAT_GameCommandParam1]); + DAT_GameSynchronyState::instance + .mapSendingFileHandles[DAT_GameSynchronyState::instance.DAT_GameCommandParam1] = NULL; + } else if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 % 10 == 9) { + answerExpected = true; + } + if (answerExpected + && DAT_GameSynchronyState::instance + .currentPlayerFullIDArray[DAT_GameSynchronyState::instance.DAT_GameCommandParam1] + != -1 + && DAT_GameSynchronyState::instance.DAT_GameCommandParam1 + != DAT_GameSynchronyState::instance.currentPlayerSlotID) { + DAT_GameSynchronyState::instance + .mapSendRequestStatePerPlayer[DAT_GameSynchronyState::instance.DAT_GameCommandParam1] = 1; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&answerExpected, sizeof(answerExpected), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(part, sizeof(part), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&byteCount, sizeof(byteCount), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + bool receivedAnswerExpected; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&receivedAnswerExpected, sizeof(receivedAnswerExpected), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + answerExpected = receivedAnswerExpected; + if (DAT_GameSynchronyState::instance.FILEPTR_ReceivedMapFile != NULL) { + if (byteCount >= 0) { + MACRO_CALL(OpenSHC::OS_Func::_fwrite)( + part, 1, byteCount, DAT_GameSynchronyState::instance.FILEPTR_ReceivedMapFile); + DAT_GameSynchronyState::instance.mapSendingByteBufferAddress[0] += byteCount; + } + // the file is complete, or the sender ended the transfer: the maps are read again + if (DAT_GameSynchronyState::instance.mapSendingByteBufferAddress[0] + >= DAT_GameSynchronyState::instance.mapSendingFileSize + || byteCount == -1) { + MACRO_CALL(OpenSHC::OS_Func::_fclose)(DAT_GameSynchronyState::instance.FILEPTR_ReceivedMapFile); + DAT_GameSynchronyState::instance.FILEPTR_ReceivedMapFile = NULL; + DAT_GameSynchronyState::instance.DAT_MapFileReceivingState = 0; + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_NONE, FALSE); + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::loadMapHeaders, DAT_ResourceManager::ptr)(FALSE); + DAT_GameSynchronyState::instance.reparseMaps = TRUE; + } + } + if (answerExpected) { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_UNKNOWN_107); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index be213f4353..8e9ec163ee 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23157,7 +23157,7 @@ SHC_3BB0A8C1_0x0048B7B0 | 0.0% | Pending SHC_3BB0A8C1_0x0048B850 | 0.0% | Pending -SHC_3BB0A8C1_0x0048B8F0 | 0.0% | Pending +SHC_3BB0A8C1_0x0048B8F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048BBE0 | 0.0% | Pending From b5d3722af3918c15e1dbfff3fe7e87e51f01b84b Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:09 +0100 Subject: [PATCH 39/45] reimplement: SHC_3BB0A8C1_0x00489880 100.0% Reimplemented AutoSaveTriggered, from gynt's draft on upstream's reimpl/Synchrony-Commands (ba3fec84f and ef8dff7b7 at 41.50%, 22f995f50 at 52.1%, 714136520 at 59.9%, his newest commit on the file; the status line reads 52.1%). On main's headers the draft reads reccmp 61.9 (normalized 61.9), and now 100.0 (normalized 100.0). quick_diff 161/162 at 0.9474 with -s (the draft: 0.6262); the rest is the /GS cookie load, an alignment jmp and the timeGetTime import. ba3fec84f and ef8dff7b7 are only on his fork (development); upstream's branch has the file from 22f995f50 on. What the match needed: - The host's arm comes first, and each arm has its own deserialize call: the original pushes the call's last three arguments before it tests isHost and the buffer's address after it. - A client returns after shouldSendAnnouncementUnk is set (the original has a second epilogue there); only the host stores the announcement time and clears announcementReceivedBool. - wcslen() for the wide string's length, and a for loop over the slots 1 to 8. Behaviour fixed against the draft: the end of the execute half. The draft went on to store the announcement time and clear announcementReceivedBool on a client too; the original does that on the host only. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has the host's arm first, wcslen, and the client and host ends as an if and else. Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return, local_59, _base64State and local_4c are isSaving (the name of ShowProgressBarSaveLoadDialog's parameter), base64State and wideName, declared where they are filled, the loop's bound is countof(), the scalar sizes are sizeof() (parameter 2 keeps its 1: one byte of it is sent), the wide string's size is wcslen() * sizeof(WCHAR), and the numbers are decimal. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/AutoSaveTriggered.cpp | 106 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/AutoSaveTriggered.cpp diff --git a/src/OpenSHC/Synchrony/Commands/AutoSaveTriggered.cpp b/src/OpenSHC/Synchrony/Commands/AutoSaveTriggered.cpp new file mode 100644 index 0000000000..dbd86a5400 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/AutoSaveTriggered.cpp @@ -0,0 +1,106 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/IO.func.hpp" +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/Util/WideCharMultiByteState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/IO/Base64State.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_WideCharMultiByteState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00489880 + void Commands::AutoSaveTriggered() + { + WCHAR wideName[36]; // the size of the original's buffer + // the save's time, the hash of its units, whether the game is being saved (one byte), and the short map name + // (33 wide characters) + DAT_GameSynchronyState::instance.DAT_CommandSize = 75; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + sizeof(DAT_GameSynchronyState::instance.DAT_GameCommandParam0), + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + sizeof(DAT_GameSynchronyState::instance.DAT_GameCommandParam1), + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam2, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::multiByteToWideCharWithSize, + DAT_WideCharMultiByteState::ptr)(wideName, DAT_GameSynchronyState::instance.shortMapName, 33); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 66, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + // every other player still has to answer; empty slots and this machine's own count as answered + for (int slot = 1; slot < countof(DAT_GameSynchronyState::instance.announcementReceivedByPlayer); ++slot) { + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[slot] == -1 + || slot == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + DAT_GameSynchronyState::instance.announcementReceivedByPlayer[slot] = 1; + } else { + DAT_GameSynchronyState::instance.announcementReceivedByPlayer[slot] = 0; + } + } + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + sizeof(DAT_GameSynchronyState::instance.DAT_GameCommandParam0), + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + sizeof(DAT_GameSynchronyState::instance.DAT_GameCommandParam1), + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + char isSaving; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&isSaving, sizeof(isSaving), + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 = isSaving; + if (DAT_GameSynchronyState::instance.isHost) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 66, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::wideCharToMultiByteWithSize, + DAT_WideCharMultiByteState::ptr)(DAT_GameSynchronyState::instance.shortMapName, wideName, 1000); + } else { + // a client keeps the name Base64 encoded + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideName, 66, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + OpenSHC::IO::Base64State base64State; + MACRO_CALL(OpenSHC::IO_Func::Base64EncodeInit)(&base64State); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_IntegerValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_GameSynchronyState::instance.shortMapName), 0, + DAT_GameSynchronyState::instance.shortMapName); + MACRO_CALL(OpenSHC::IO_Func::Base64Encode)((char*)wideName, wcslen(wideName) * sizeof(WCHAR), + DAT_GameSynchronyState::instance.shortMapName, &base64State); + } + DAT_GameSynchronyState::instance.savedMapTimeInTicks = DAT_GameSynchronyState::instance.DAT_GameCommandParam0; + DAT_GameSynchronyState::instance.savedUnitsCRC32Hash = DAT_GameSynchronyState::instance.DAT_GameCommandParam1; + MACRO_CALL(OpenSHC::UI::Helpers_Func::ShowProgressBarSaveLoadDialog)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam2); + DAT_GameSynchronyState::instance.lastAutoSaveTime = timeGetTime(); + DAT_GameSynchronyState::instance.saveRelated = 1; + // a client announces its save; the host waits for the announcements + if (!DAT_GameSynchronyState::instance.isHost) { + DAT_GameSynchronyState::instance.shouldSendAnnouncementUnk = 1; + return; + } + DAT_GameSynchronyState::instance.announcementReceiveTime = timeGetTime(); + DAT_GameSynchronyState::instance.announcementReceivedBool = FALSE; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 8e9ec163ee..4f6231b392 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23101,7 +23101,7 @@ SHC_3BB0A8C1_0x004895E0 | 0.0% | Pending SHC_3BB0A8C1_0x00489810 | 0.0% | Pending -SHC_3BB0A8C1_0x00489880 | 0.0% | Pending +SHC_3BB0A8C1_0x00489880 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00489A10 | 0.0% | Pending From d991122527c5cd3d60a7291ead6d3ca9ef1585d6 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:09 +0100 Subject: [PATCH 40/45] headers: ProtocolDefinedData::insultWavFiles is char* [21] The header has `char** insultWavFiles[21]` at offset 0x240 (0x00B38DBC). The original's data there is 21 plain char pointers: element 0 is NULL, and elements 1 to 20 point at "insult1.wav" (0x005A6E14) to "insult20.wav" (0x005A6D04). ClickTauntOrChat passes an element as the file name: 0x004897C1 `mov ecx, [eax*4 + 0x00B38DBC]`, `push ecx`, `push 0x12`, then 0x004897D0 `call 0x00478360` (resolveResourceFileName, whose second parameter is a `char const*`). Nothing else on main uses the field. ClickTauntOrChat, the next commit, passes it with no cast. Co-Authored-By: Claude Fable 5.2 --- src/OpenSHC/Synchrony/ProtocolDefinedData.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/Synchrony/ProtocolDefinedData.hpp b/src/OpenSHC/Synchrony/ProtocolDefinedData.hpp index a4920a8d35..3c4fc72d6a 100644 --- a/src/OpenSHC/Synchrony/ProtocolDefinedData.hpp +++ b/src/OpenSHC/Synchrony/ProtocolDefinedData.hpp @@ -23,7 +23,7 @@ namespace Synchrony { int field_0x4[12][2]; // 0x00000004 length: 96 int field_0x64[39][3]; // 0x00000064 length: 468 undefined1 padding_0x238[8]; // 0x00000238 length: 8 - char** insultWavFiles[21]; // 0x00000240 length: 84 + char* insultWavFiles[21]; // 0x00000240 length: 84 NoArgCallback* commandFunctions[120]; // 0x00000294 length: 480 int field_0x474[32]; // 0x00000474 length: 128 char* field_0x4f4; // 0x000004F4 length: 4 From dc6c595dcdb2d2e42bfc0c1189d008f76eaef8a6 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:09 +0100 Subject: [PATCH 41/45] reimplement: SHC_3BB0A8C1_0x004895E0 100.0% Reimplemented ClickTauntOrChat, from gynt's draft on upstream's reimpl/Synchrony-Commands (443827328 at 24.40%, 69d7f6aab and f9399c57d at 30.3%, a9a04a1f4 at 55.4%, "Dispatch form fixed, remainder unanalysed", his newest commit on the file; the status line reads 30.3%). On main's headers the draft reads reccmp 56.5 (normalized 56.5), and now 100.0 (normalized 100.0). quick_diff 172/173 at 0.9449 with -s (the draft: 0.6551); the rest is the /GS cookie load, an alignment jmp and the sound flags' constant, which quick_diff reads as an address. 443827328 is only on his fork (development); upstream's branch has the file from 69d7f6aab on. What the match needed: - The execute half starts with the sender's range test (add eax, -1; cmp eax, 7; ja): only the players 1 to 8. - The receivers are an array of their own, `int receivers[9] = { 0 }`, indexed by this machine's slot; the taunt is an int of its own in front of it. The draft had one array of ten with the taunt as its first element and cleared the other nine one by one. - addChatMessageToDisplayList is called in three places: with 0 for taunt 10000, with parameter 0 for a negative taunt, with the sender otherwise. The original pushes the two zeros of the first call by themselves. - The lookups are written inside the calls that use them: the typed text inside the conversion, the insult's text inside a strcpy, the sound's file name inside playSoundOnStream3Unk. Behaviour fixed against the draft: - The draft had no range test for the sender. - The sound's file name comes from insultWavFiles, which is what main's header has at 0x00B38DBC. The draft read commandFunctions, which was at that address on its branch. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has the range test, the receivers array with its initializer, the three calls, the strcpy calls and the typed text's lookup inside the conversion. Style: the strcpy pragma, the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half, a message for other players and the first two kinds of taunt are early returns, the locals have names (taunt, receivers, wideMessage[MAX_PATH]), the sizes of the scalars and of the receivers are sizeof(), the sound flags are the enum's names as in KickPlayerUnk, the sound's file name is passed with no cast (the commit before this one makes insultWavFiles a char* array), and the numbers are decimal. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/ClickTauntOrChat.cpp | 131 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/ClickTauntOrChat.cpp diff --git a/src/OpenSHC/Synchrony/Commands/ClickTauntOrChat.cpp b/src/OpenSHC/Synchrony/Commands/ClickTauntOrChat.cpp new file mode 100644 index 0000000000..440987df09 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/ClickTauntOrChat.cpp @@ -0,0 +1,131 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#include "../Commands.func.hpp" + +#include "OpenSHC/Audio/MSS/SoundSystem.func.hpp" +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/Util/WideCharMultiByteState.func.hpp" +#include "OpenSHC/Audio/mss/SoundFlagsAndLoopCountBitwiseFlagEnum.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/IO/FileResourceType.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_ProtocolDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" +#include "OpenSHC/Globals/DAT_WideCharMultiByteState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x004895E0 + void Commands::ClickTauntOrChat() + { + WCHAR wideMessage[MAX_PATH]; + // the taunt, the message (250 wide characters), the receivers and parameter 0 + DAT_GameSynchronyState::instance.DAT_CommandSize = 544; + DAT_GameSynchronyState::instance.DAT_GameCommandArray[DAT_GameSynchronyState::instance.DAT_CurrentGameCommandID] + .time = 0; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_ChatTauntOrMessage, + sizeof(DAT_GameSynchronyState::instance.DAT_ChatTauntOrMessage), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::multiByteToWideCharWithSize, + DAT_WideCharMultiByteState::ptr)(wideMessage, + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::getCurrentText, DAT_UserTextHandlerState::ptr)(), + 250); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideMessage, 500, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray, + sizeof(DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + sizeof(DAT_GameSynchronyState::instance.DAT_GameCommandParam0), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + DAT_GameSynchronyState::instance.DAT_CommandActionPlan = OpenSHC::Commands::GCS_EXECUTE; + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + // only the eight players chat + if (DAT_GameSynchronyState::instance.protocolInvokerPlayerID < 1 + || DAT_GameSynchronyState::instance.protocolInvokerPlayerID > 8) { + return; + } + int receivers[9] = { 0 }; + int taunt; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&taunt, sizeof(taunt), OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(wideMessage, 500, OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Util::WideCharMultiByteState_Func::wideCharToMultiByteWithSize, + DAT_WideCharMultiByteState::ptr)(DAT_GameSynchronyState::instance.receivedChatMessage, wideMessage, 250); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(receivers, sizeof(receivers), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + sizeof(DAT_GameSynchronyState::instance.DAT_GameCommandParam0), + OpenSHC::Commands::GCPL_FIXED_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + if (receivers[DAT_GameSynchronyState::instance.currentPlayerSlotID] == 0) { + return; + } + // 10000 is a message without a sender + if (taunt == 10000) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addChatMessageToDisplayList, + DAT_GameSynchronyState::ptr)(0, 0); + return; + } + // a negative taunt is an insult for the player in parameter 0: its text replaces the message and its sound + // is played + if (taunt < 0) { + taunt = -1 - taunt; + strcpy(DAT_GameSynchronyState::instance.receivedChatMessage, + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_INSULTS, taunt)); + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_GFX_SPEECH, DAT_ProtocolDefinedData::instance.insultWavFiles[taunt]); + MACRO_CALL_MEMBER(OpenSHC::Audio::MSS::SoundSystem_Func::playSoundOnStream3Unk, DAT_SoundSystemState::ptr)( + MACRO_CALL_MEMBER( + OpenSHC::IO::ResourceManager_Func::getFileNameOfCurrentActiveResource, DAT_ResourceManager::ptr)(), + OpenSHC::Audio::MSS::FLAG_SOUND_UNINTERRUPTABLE | OpenSHC::Audio::MSS::FLAG_SOUND_UNKNOWN_FLAG_2 + | OpenSHC::Audio::MSS::FLAG_SOUND_UNKNOWN_FLAG_1 | 1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addChatMessageToDisplayList, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 0); + return; + } + // a positive taunt is an insult from the sender; 0 is a typed message + if (taunt != 0) { + strcpy(DAT_GameSynchronyState::instance.receivedChatMessage, + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_INSULTS, taunt)); + MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + OpenSHC::IO::FRT_GFX_SPEECH, DAT_ProtocolDefinedData::instance.insultWavFiles[taunt]); + MACRO_CALL_MEMBER(OpenSHC::Audio::MSS::SoundSystem_Func::playSoundOnStream3Unk, DAT_SoundSystemState::ptr)( + MACRO_CALL_MEMBER( + OpenSHC::IO::ResourceManager_Func::getFileNameOfCurrentActiveResource, DAT_ResourceManager::ptr)(), + OpenSHC::Audio::MSS::FLAG_SOUND_UNINTERRUPTABLE | OpenSHC::Audio::MSS::FLAG_SOUND_UNKNOWN_FLAG_2 + | OpenSHC::Audio::MSS::FLAG_SOUND_UNKNOWN_FLAG_1 | 1); + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addChatMessageToDisplayList, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.protocolInvokerPlayerID, 0); + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 4f6231b392..793382070d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23097,7 +23097,7 @@ SHC_3BB0A8C1_0x00489410 | 0.0% | Pending SHC_3BB0A8C1_0x004894F0 | 0.0% | Pending -SHC_3BB0A8C1_0x004895E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004895E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00489810 | 0.0% | Pending From 501c9c4317b3f79f6c5c671bfe268fae0d87092d Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:09 +0100 Subject: [PATCH 42/45] reimplement: SHC_3BB0A8C1_0x00485830 100.0% Reimplemented SetUnitAssemblyPoint, from gynt's draft on upstream's reimpl/Synchrony-Commands (c2f8efa70 at 50.22%, 09840aa88 at 60.8%, abd24c294 at 62.2%, fe31c3382 at 64.5%, "EXTEND fixed, allocator differs", his newest commit on the file; the status line reads 62.2%). The draft doesn't compile on main: tunnelersGuildAssemblyPointX/Y and cathedralAssemblyPointX/Y are specialBuildingAssemblyPoints[2] and [3] there. With those two renames it reads quick_diff 0.6283 with 234 instructions, and this reads 218/218 at 1.0000; reccmp 100.0 (normalized 100.0). c2f8efa70 is only on his fork (development); upstream's branch has the file from 09840aa88 on. What the match needed: - The unit category has no local: parameter 0 is written in every index. With a local the compiler moves the store of x behind the building lookup in the first three blocks (quick_diff 0.9725); the original stores x, then y, then looks the building up. - One int receives the three parameters, read back as its first byte and its first two bytes; the sender, x and y are locals, y from the received value and x from parameter 1. - The five kinds of assembly point are early returns in place of an else-if chain. - Kept from the draft: the int local for the building type where two types are tested, and the switch for the barracks' and the mercenary post's five types. Fields on main: the third block's points are specialBuildingAssemblyPoints[category - 20], the same bytes the draft reached as mercenaryAssemblyPoints[category + 1]. The behaviour is the draft's. Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half and the tests of the point, the building and its owner are early returns, the locals have names (received, playerID, x, y, buildingID, buildingType) and are declared where they are filled, the switches end in a break, the map's limits are MC_MAP_XY_LIMIT_INCLUSIVE and MC_MAP_XY_LIMIT, and the numbers are decimal. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/SetUnitAssemblyPoint.cpp | 198 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/SetUnitAssemblyPoint.cpp diff --git a/src/OpenSHC/Synchrony/Commands/SetUnitAssemblyPoint.cpp b/src/OpenSHC/Synchrony/Commands/SetUnitAssemblyPoint.cpp new file mode 100644 index 0000000000..a2feb710cd --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/SetUnitAssemblyPoint.cpp @@ -0,0 +1,198 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x00485830 + void Commands::SetUnitAssemblyPoint() + { + // the unit category (one byte) and the point's x and y (two bytes each) + DAT_GameSynchronyState::instance.DAT_CommandSize = 5; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam2, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + // the three parameters are received one after the other into the same four bytes, as in the original + int received; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&received, 1, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = (char)received; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&received, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = (short)received; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&received, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + int const playerID = DAT_GameSynchronyState::instance.protocolInvokerPlayerID; + uint const x = DAT_GameSynchronyState::instance.DAT_GameCommandParam1; + uint const y = (short)received; + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 = y; + // the point has to be on the map + if (x > OpenSHC::Map::MC_MAP_XY_LIMIT_INCLUSIVE || y > OpenSHC::Map::MC_MAP_XY_LIMIT_INCLUSIVE) { + return; + } + if (!DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * OpenSHC::Map::MC_MAP_XY_LIMIT + x]) { + return; + } + // the category is read from the parameter each time (a local for it loses the match) + // 0 to 9, the barracks' units: a point on the sender's own barracks, mercenary post or parade ground clears it + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 < 10) { + DAT_GameState::instance.playerDataArray[playerID] + .barracksAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0] + .x = x; + DAT_GameState::instance.playerDataArray[playerID] + .barracksAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0] + .y = y; + int const buildingID + = DAT_TileMapState::instance + .BuildingLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x]; + if (buildingID == 0) { + return; + } + if (DAT_BuildingsState::instance.buildings[buildingID].owner != playerID) { + return; + } + switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { + case OpenSHC::Map::Buildings::BT_MERCENARYPOST: + case OpenSHC::Map::Buildings::BT_BARRACKS: + case OpenSHC::Map::Buildings::BT_PARADEGROUND2: + case OpenSHC::Map::Buildings::BT_PARADEGROUND3: + case OpenSHC::Map::Buildings::BT_PARADEGROUND4: + DAT_GameState::instance.playerDataArray[playerID] + .barracksAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0] + .x = 0; + DAT_GameState::instance.playerDataArray[playerID] + .barracksAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0] + .y = 0; + break; + } + return; + } + // 10 to 19, the mercenary post's units, cleared on the same buildings + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 < 20) { + DAT_GameState::instance.playerDataArray[playerID] + .mercenaryAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0 - 10][0] = x; + DAT_GameState::instance.playerDataArray[playerID] + .mercenaryAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0 - 10][1] = y; + int const buildingID + = DAT_TileMapState::instance + .BuildingLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x]; + if (buildingID == 0) { + return; + } + if (DAT_BuildingsState::instance.buildings[buildingID].owner != playerID) { + return; + } + switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { + case OpenSHC::Map::Buildings::BT_MERCENARYPOST: + case OpenSHC::Map::Buildings::BT_BARRACKS: + case OpenSHC::Map::Buildings::BT_PARADEGROUND2: + case OpenSHC::Map::Buildings::BT_PARADEGROUND3: + case OpenSHC::Map::Buildings::BT_PARADEGROUND4: + DAT_GameState::instance.playerDataArray[playerID] + .mercenaryAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0 - 10][0] = 0; + DAT_GameState::instance.playerDataArray[playerID] + .mercenaryAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0 - 10][1] = 0; + break; + } + return; + } + // 20 to 29, the engineers guild's units + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 < 30) { + DAT_GameState::instance.playerDataArray[playerID] + .specialBuildingAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0 - 20] + .x = x; + DAT_GameState::instance.playerDataArray[playerID] + .specialBuildingAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0 - 20] + .y = y; + int const buildingID + = DAT_TileMapState::instance + .BuildingLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x]; + if (buildingID == 0) { + return; + } + if (DAT_BuildingsState::instance.buildings[buildingID].owner != playerID) { + return; + } + int const buildingType = DAT_BuildingsState::instance.buildings[buildingID].buildingType; + if (buildingType == OpenSHC::Map::Buildings::BT_ENGINEERSGUILD + || buildingType == OpenSHC::Map::Buildings::BT_PARADEGROUND) { + DAT_GameState::instance.playerDataArray[playerID] + .specialBuildingAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0 - 20] + .x = 0; + DAT_GameState::instance.playerDataArray[playerID] + .specialBuildingAssemblyPoints[DAT_GameSynchronyState::instance.DAT_GameCommandParam0 - 20] + .y = 0; + } + return; + } + // 30 to 39, the tunnelers guild's units + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 < 40) { + DAT_GameState::instance.playerDataArray[playerID].specialBuildingAssemblyPoints[2].x = x; + DAT_GameState::instance.playerDataArray[playerID].specialBuildingAssemblyPoints[2].y = y; + int const buildingID + = DAT_TileMapState::instance + .BuildingLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x]; + if (buildingID == 0) { + return; + } + if (DAT_BuildingsState::instance.buildings[buildingID].owner != playerID) { + return; + } + int const buildingType = DAT_BuildingsState::instance.buildings[buildingID].buildingType; + if (buildingType == OpenSHC::Map::Buildings::BT_TUNNELERSGUILD + || buildingType == OpenSHC::Map::Buildings::BT_PARADEGROUND5) { + DAT_GameState::instance.playerDataArray[playerID].specialBuildingAssemblyPoints[2].x = 0; + DAT_GameState::instance.playerDataArray[playerID].specialBuildingAssemblyPoints[2].y = 0; + } + return; + } + // 40 to 49, the cathedral's units + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 < 50) { + DAT_GameState::instance.playerDataArray[playerID].specialBuildingAssemblyPoints[3].x = x; + DAT_GameState::instance.playerDataArray[playerID].specialBuildingAssemblyPoints[3].y = y; + int const buildingID + = DAT_TileMapState::instance + .BuildingLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x]; + if (buildingID == 0) { + return; + } + if (DAT_BuildingsState::instance.buildings[buildingID].owner != playerID) { + return; + } + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_CATHEDRAL) { + DAT_GameState::instance.playerDataArray[playerID].specialBuildingAssemblyPoints[3].x = 0; + DAT_GameState::instance.playerDataArray[playerID].specialBuildingAssemblyPoints[3].y = 0; + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 793382070d..583b506f12 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22753,7 +22753,7 @@ SHC_3BB0A8C1_0x004856E0 | 0.0% | Pending SHC_3BB0A8C1_0x00485790 | 0.0% | Pending -SHC_3BB0A8C1_0x00485830 | 0.0% | Pending +SHC_3BB0A8C1_0x00485830 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00485B8C | 0.0% | Pending From 689efc46b005d37fd921583502c13d7f353b9232 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:09 +0100 Subject: [PATCH 43/45] reimplement: SHC_3BB0A8C1_0x004827E0 100.0% Reimplemented ClickPlaceSiegeTent, from gynt's draft on upstream's reimpl/Synchrony-Commands (915e32a44 at 52.03%, c8cf62d6d at 61.0%, e4dcca62c at 65.7%, 380fe5e68 at 65.3%, 9997d6da2 at 68.2%, "EXTEND fixed, allocator differs", his newest commit on the file; the status line reads 61.0%). The draft doesn't compile on main: containsSiegeMangonel1OrBallista2 is defensiveTowerEngineType there and field261_0x2fa is tileScanCountdown. With those two renames it reads quick_diff 0.7176 with 168 instructions, and this reads 172/172 at 1.0000; reccmp 100.0 (normalized 100.0). 915e32a44 is only on his fork (development); upstream's branch has the file from c8cf62d6d on. What the match needed: - The mapper for the resource check starts as M_MAPPER_NULL, becomes the mangonel's or the ballista's, and the check runs when it isn't null. The compiler turns that into the original's jumps (cmp 0x29, mov eax, 0xd2, jmp; cmp 0x3d, mov eax, 0xd3), so the draft's goto isn't needed. One condition with an if and else for the mapper puts the mangonel's arm out of line (0.9826); a ternary and two calls read 0.9623 and 0.9769. - processPlacementResourceLossForBuildingType is called in two places, once per engine: the original loads the sender and pushes the arguments in each arm. - The tile coordinates are `/ 8` (cdq, and 7, add, sar 3), and the tower's building type is an int local. - The parameters are read from the globals each time, with no locals. The behaviour is the draft's. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has the divisions and the two processPlacementResourceLossForBuildingType calls. Style: the first include is ../Commands.func.hpp, the using lines and block comments are gone, both gotos are gone, the building lookups are named locals in place of a comma expression and a repeated index, the locals are declared where they are filled (mapper, buildingID, unitID, buildingType), and the numbers are decimal. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Commands/ClickPlaceSiegeTent.cpp | 137 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/ClickPlaceSiegeTent.cpp diff --git a/src/OpenSHC/Synchrony/Commands/ClickPlaceSiegeTent.cpp b/src/OpenSHC/Synchrony/Commands/ClickPlaceSiegeTent.cpp new file mode 100644 index 0000000000..4aa2b4f199 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/ClickPlaceSiegeTent.cpp @@ -0,0 +1,137 @@ +#include "../Commands.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Map/WallAndPitchState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WallAndPitchState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x004827E0 + void Commands::ClickPlaceSiegeTent() + { + // the unit's x, y and terrain height (two bytes each) and its type (one byte) + DAT_GameSynchronyState::instance.DAT_CommandSize = 7; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam2, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam3, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + // each parameter is cleared before its low bytes are received + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam2, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam3 = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam3, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + // outside single player the sender needs the resources for the engine + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + OpenSHC::Commands::MappersEnum mapper = OpenSHC::Commands::M_MAPPER_NULL; + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam3 == OpenSHC::Map::Units::UT_S_MANGONEL) { + mapper = OpenSHC::Commands::M_MAPPER_MANGONEL; + } else if (DAT_GameSynchronyState::instance.DAT_GameCommandParam3 == OpenSHC::Map::Units::UT_S_BALLISTA) { + mapper = OpenSHC::Commands::M_MAPPER_BALLISTA; + } + if (mapper != OpenSHC::Commands::M_MAPPER_NULL + && !MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::checkRequiredResourcesForBuildingOrPlanToBuy, + DAT_GameState::ptr)(mapper, DAT_GameSynchronyState::instance.protocolInvokerPlayerID, FALSE)) { + return; + } + } + // a tower that already carries an engine takes no second one + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam3 == OpenSHC::Map::Units::UT_S_MANGONEL + || DAT_GameSynchronyState::instance.DAT_GameCommandParam3 == OpenSHC::Map::Units::UT_S_BALLISTA) { + int const buildingID + = DAT_TileMapState::instance.BuildingLayer + [DAT_ViewportRenderState::instance + .translationMatrix[(int)DAT_GameSynchronyState::instance.DAT_GameCommandParam1 / 8] + .addXgetTile + + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 / 8]; + if (buildingID != 0 && DAT_BuildingsState::instance.buildings[buildingID].defensiveTowerEngineType != 0) { + return; + } + } + int const unitID = MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.protocolInvokerPlayerID, + DAT_GameSynchronyState::instance.protocolInvokerPlayerID, + DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + DAT_GameSynchronyState::instance.DAT_GameCommandParam1, + DAT_GameSynchronyState::instance.DAT_GameCommandParam2, + (OpenSHC::Map::Units::UnitType)DAT_GameSynchronyState::instance.DAT_GameCommandParam3); + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam3 == OpenSHC::Map::Units::UT_S_MANGONEL) { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processPlacementResourceLossForBuildingType, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.protocolInvokerPlayerID, OpenSHC::Map::Buildings::BT_MANGONEL, 0); + } else if (DAT_GameSynchronyState::instance.DAT_GameCommandParam3 == OpenSHC::Map::Units::UT_S_BALLISTA) { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processPlacementResourceLossForBuildingType, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.protocolInvokerPlayerID, OpenSHC::Map::Buildings::BT_BALLISTA, 0); + } + // the tower under the new engine counts as occupied + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam3 == OpenSHC::Map::Units::UT_S_MANGONEL + || DAT_GameSynchronyState::instance.DAT_GameCommandParam3 == OpenSHC::Map::Units::UT_S_BALLISTA) { + int const buildingID + = DAT_TileMapState::instance.BuildingLayer + [DAT_ViewportRenderState::instance + .translationMatrix[(int)DAT_GameSynchronyState::instance.DAT_GameCommandParam1 / 8] + .addXgetTile + + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 / 8]; + if (buildingID != 0) { + int const buildingType = DAT_BuildingsState::instance.buildings[buildingID].buildingType; + if (buildingType == OpenSHC::Map::Buildings::BT_TOWER1 + || buildingType == OpenSHC::Map::Buildings::BT_TOWER4) { + DAT_BuildingsState::instance.buildings[buildingID].hasUnitsOntop = 1; + DAT_BuildingsState::instance.buildings[buildingID].tileScanCountdown = 100; + } + } + } + if (DAT_GameSynchronyState::instance.protocolInvokerPlayerID + == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + MACRO_CALL_MEMBER(OpenSHC::Map::WallAndPitchState_Func::startUnitDestructionConfirmation, + DAT_WallAndPitchState::ptr)(unitID); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 583b506f12..f831c551c7 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -22563,7 +22563,7 @@ SHC_3BB0A8C1_0x00482620 | 0.0% | Pending SHC_3BB0A8C1_0x004826C0 | 0.0% | Pending -SHC_3BB0A8C1_0x004827E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004827E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00482A40 | 0.0% | Pending From a1f4c471686f4151160778133fed75bb3301979d Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 17 Nov 2026 07:56:10 +0100 Subject: [PATCH 44/45] reimplement: SHC_3BB0A8C1_0x0048A8A0 100.0% Reimplemented DestroyPlayer, from gynt's draft. His commits on the file, in date order: 7291ee4c2 at 62.71% on his fork's development branch, 1431eb3db at 77.0% and cf5944a34 at 79.7% on upstream's reimpl/Synchrony-Commands (cf5944a34 is the newest there, and what this builds on), then 00845955e at 69.49% on his fork again (2026-10-03 22:45), his newest commit on the file. The status line reads 77.0%. The draft doesn't compile on main: field261_0x109298 is connectionNoticeShown there, and DPLAYX_4A is an IDirectPlay4*, so its cast to IDirectPlay4A** goes. With those two changes it reads quick_diff 0.8273 with 123 instructions, and this reads 125/126 at 0.9880; reccmp 100.0 (normalized 100.0). The rest in quick_diff is the call through the DirectPlay interface and an alignment jmp. What the match needed: - The first block returns: the original has its own epilogue after the leaving player's name is cleared, and the second block then still has the slot and the text's number in registers. - The leaving player's slot is a local for the lord's lookup and for the last three stores, but the first two stores (currentPlayerFullIDArray and DAT_PlayerSlotArraySomeValue) read it from parameter 0. That split gives the original's `lea eax, [edx*4]` and its one reload of the parameter; with the local in all of them the function reads 0.8880, with the parameter in all of them 0.8854. - strcpy for the two messages, with the text's lookup inside the call. The behaviour is the draft's: its two blocks exclude each other, so the return changes nothing. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, 2026-10-27) already has the two strcpy calls. It puts the second block in an else-if; here the first block returns and the second is a plain if. The blocks exclude each other, so both forms behave the same. Style: the strcpy pragma, the first include is ../Commands.func.hpp, the using lines and block comments are gone, the execute half is an early return, the locals have names (readBuffer, playerID, lordID) and are declared where they are filled, DPLAYX_4A->DestroyPlayer is called with no cast, NULL for the interface pointer, connectionNoticeShown is tested by truth, and the numbers are decimal. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../Synchrony/Commands/DestroyPlayer.cpp | 101 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/DestroyPlayer.cpp diff --git a/src/OpenSHC/Synchrony/Commands/DestroyPlayer.cpp b/src/OpenSHC/Synchrony/Commands/DestroyPlayer.cpp new file mode 100644 index 0000000000..99b8a13519 --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/DestroyPlayer.cpp @@ -0,0 +1,101 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#include "../Commands.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x0048A8A0 + void Commands::DestroyPlayer() + { + // the player's slot and the number of the connection text + DAT_GameSynchronyState::instance.DAT_CommandSize = 4; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + short readBuffer; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&readBuffer, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = readBuffer; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&readBuffer, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = readBuffer; + DAT_GameSynchronyState::instance.unknownIncrementBy40_01 -= 40; + if (DAT_GameSynchronyState::instance + .currentPlayerFullIDArray[DAT_GameSynchronyState::instance.DAT_GameCommandParam0] + != -1 + && DAT_GameSynchronyState::instance.DAT_GameCommandParam0 + != DAT_GameSynchronyState::instance.currentPlayerSlotID) { + // another player leaves: out of the session, out of the game and out of the lobby's lists + if (DAT_GameSynchronyState::instance.DPLAYX_4A != NULL) { + DAT_GameSynchronyState::instance.DPLAYX_4A->DestroyPlayer(DAT_GameSynchronyState::instance + .currentPlayerFullIDArray[DAT_GameSynchronyState::instance.DAT_GameCommandParam0]); + } + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::destroyPlayerCompletely, DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.DAT_GameCommandParam0); + int const playerID = DAT_GameSynchronyState::instance.DAT_GameCommandParam0; + int const lordID = DAT_GameState::instance.playerDataArray[playerID].lordID; + if (DAT_UnitsState::instance.units[lordID].uid + == DAT_GameState::instance.playerDataArray[playerID].lordUID) { + DAT_UnitsState::instance.units[lordID].lastEncounteredEnemyPlayerID = 0; + } + // these two read the slot from the parameter, the three after them from the local (the local or the + // parameter in all five loses the match) + DAT_GameSynchronyState::instance + .currentPlayerFullIDArray[DAT_GameSynchronyState::instance.DAT_GameCommandParam0] = -1; + DAT_GameSynchronyState::instance + .DAT_PlayerSlotArraySomeValue[DAT_GameSynchronyState::instance.DAT_GameCommandParam0] = 0; + DAT_GameSynchronyState::instance.isIncludedPlayer[playerID] = FALSE; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[playerID] = 0; + DAT_GameSynchronyState::instance.DAT_MultiplayerGameVersions[playerID] = 0; + // "has left the game" + strcpy(DAT_GameSynchronyState::instance.receivedChatMessage, + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, 89)); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addChatMessageToDisplayList, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 0); + DAT_GameSynchronyState::instance.DAT_PlayerNames[DAT_GameSynchronyState::instance.DAT_GameCommandParam0][0] + = '\0'; + return; + } + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 + == DAT_GameSynchronyState::instance.currentPlayerSlotID + && !DAT_GameSynchronyState::instance.connectionNoticeShown) { + // this machine is the one removed: it shows the connection text once + DAT_GameSynchronyState::instance.connectionNoticeShown = 1; + strcpy(DAT_GameSynchronyState::instance.receivedChatMessage, + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MULTIPLAYER_CONNECTION, + DAT_GameSynchronyState::instance.DAT_GameCommandParam1)); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addChatMessageToDisplayList, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, 0); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f831c551c7..4fae299f76 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23129,7 +23129,7 @@ SHC_3BB0A8C1_0x0048A710 | 0.0% | Pending SHC_3BB0A8C1_0x0048A7C0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0048A8A0 | 0.0% | Pending +SHC_3BB0A8C1_0x0048A8A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048A9F0 | 0.0% | Pending From ca026fa5d7f1733cdedf3159bae7f43b0910fed0 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Wed, 18 Nov 2026 11:50:08 +0100 Subject: [PATCH 45/45] reimplement: SHC_3BB0A8C1_0x0048ACB0 100.0% Reimplemented CommandSwitchTeams, from gynt's draft. His reimplement commits on the file, in date order: 4b3b813ad at 20.73% on his fork's development branch, then 1030ebbbf at 36.3% and 73efa0f29 at 40.9% ("Flag widened, register allocation differs") on upstream's reimpl/Synchrony-Commands, his newest on upstream's branch; the status line reads 36.3%. He has five more commits on the file: 81e1041dd (block comments removed), dd1433183 (truth tests), cb45952ec ("remove claimed"), 8ca78619c (Wilps's content, below) and d74f096c2 of 2026-11-02 (style rules, on his fork's reimpl/UI-MenuItems-development), his newest commit on the file. On main's headers the draft reads reccmp 40.9 (normalized 40.9), and this 100.0 (normalized 100.0), built under /GL with its two callees. What the match needed: - Link-time code generation. The file and the two callees that are finished on main, countPlayersInSameTeam and addChatMessageToDisplayList, are in cmake/compiler-flags-gl.txt. The original keeps the flag and the constant 0 in one register (ebx, set after the sending half) and tests the flag with `test ebx, ebx`. Without /GL the same source gets a zero register of its own at the top of the function and the flag in a second one (quick_diff 0.6609, 349 instructions against 344). Both callees still read 100.0 under /GL, and so does receiveAllTransmittedCommands (0x00490690), which is on /GL already and calls addChatMessageToDisplayList. - The original has 347 instructions: the 344 that quick_diff counts and three alignment fillers in front of loop heads: `mov edi, edi` at 0x0048AE9E before request 0's inline strcpy copy, `mov edi, edi` at 0x0048AF7E before the search loop, and `nop` at 0x0048AFAF before request 2's inline strcpy copy. The clears, counts and marks over the teams 1 to 8 and the slots 1 to 8 are plain for loops that the compiler unrolls; the draft wrote those copies out by hand. The search loop for the first empty team (0x0048AF80) stays a loop in the original, as in the draft. - One int receives both parameters, read back as its first two bytes and its first byte. - The three kinds of request are separate ifs with early returns, in the original's order 0, 2, 1. - The flag is a BOOLEnum that is FALSE before the plan is tested for GCS_EXECUTE. Measured under /GL: declared just above its test, or as one const expression there, the function reads 66.3. teamCount is zeroed before the clears in requests 0 and 1; declared just above its counting loop, either copy alone reads 97.1 and both together 83.3. `received` and `teamCounts` are declared at their first use, which measures the same as at the top. - strcpy for the three messages, with the text's lookup inside the call. The behaviour is the draft's. Wilps's version on gynt's fork (reimpl/Wilps-2026-10-18, 8ca78619c, a commit of gynt's of 2026-10-27) has the search loop and an int flag, as gynt's 73efa0f29 does; it keeps the other loops written out. Style: the strcpy pragma, the first include is ../Commands.func.hpp, the using lines and block comments are gone, the locals have names (received, teamCounts, teamCount, canSwitch), the loop bounds are countof(), the numbers are decimal, and each text lookup has its text above it. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- cmake/compiler-flags-gl.txt | 3 + .../Synchrony/Commands/CommandSwitchTeams.cpp | 162 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 3 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/Synchrony/Commands/CommandSwitchTeams.cpp diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 18dce0ff70..2576bae655 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -137,3 +137,6 @@ src/OpenSHC/Map/Units/UpdateQuarryMason.cpp src/OpenSHC/Map/Units/UpdateDrunkard.cpp src/OpenSHC/Map/Units/UpdateInnkeeper.cpp src/OpenSHC/Map/Units/UpdateMerchant.cpp +src/OpenSHC/Synchrony/Commands/CommandSwitchTeams.cpp +src/OpenSHC/Synchrony/GameSynchronyState/countPlayersInSameTeam.cpp +src/OpenSHC/Synchrony/GameSynchronyState/addChatMessageToDisplayList.cpp diff --git a/src/OpenSHC/Synchrony/Commands/CommandSwitchTeams.cpp b/src/OpenSHC/Synchrony/Commands/CommandSwitchTeams.cpp new file mode 100644 index 0000000000..b6f712ddab --- /dev/null +++ b/src/OpenSHC/Synchrony/Commands/CommandSwitchTeams.cpp @@ -0,0 +1,162 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#include "../Commands.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/Commands/GameCommandParameterLocation.hpp" +#include "OpenSHC/Commands/GameCommandParameterReadWrite.hpp" +#include "OpenSHC/Commands/GameCommandScheduling.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace Synchrony { + + // FUNCTION: STRONGHOLDCRUSADER 0x0048ACB0 + void Commands::CommandSwitchTeams() + { + // a player's slot (two bytes) and what is asked for it (one byte) + DAT_GameSynchronyState::instance.DAT_CommandSize = 3; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan == OpenSHC::Commands::GCS_SCHEDULE_AND_SEND) { + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam0, 2, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&DAT_GameSynchronyState::instance.DAT_GameCommandParam1, 1, + OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, OpenSHC::Commands::GCPRW_SERIALIZE_INTO_PARAM_1); + return; + } + // FALSE before the plan is tested, as in the original: the flag shares its register with the constant 0 + // (declared above its test, or as one const expression, it loses the match under /GL too) + BOOLEnum canSwitch = FALSE; + if (DAT_GameSynchronyState::instance.DAT_CommandActionPlan != OpenSHC::Commands::GCS_EXECUTE) { + return; + } + // both parameters are received into the same four bytes, as in the original + int received; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&received, 2, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = (short)received; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::serializeOrDeserializeCommandParameter, + DAT_GameSynchronyState::ptr)(&received, 1, OpenSHC::Commands::GCPL_DYNAMIC_COMMAND_DATA_ADDRESS, + OpenSHC::Commands::GCPRW_DESERIALIZE_FROM_PARAM1); + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = (char)received; + // one entry per team number, 1 to 8 (entry 0 is not used) + int teamCounts[9]; + // 0: the sender asks the player in parameter 0 for an alliance; only that player's machine shows it + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam1 == 0) { + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam0 + != DAT_GameSynchronyState::instance.currentPlayerSlotID) { + return; + } + // zeroed before the clears, here and in request 1, as in the original (declared above its counting + // loop, either one loses the match) + int teamCount = 0; + for (int team = 1; team < countof(teamCounts); ++team) { + teamCounts[team] = 0; + } + for (int slot = 1; slot < countof(DAT_GameSynchronyState::instance.currentPlayerFullIDArray); ++slot) { + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[slot] != -1) { + teamCounts[DAT_GameState::instance.mapAndTime.playerTeams[slot]]++; + } + } + for (int team = 1; team < countof(teamCounts); ++team) { + if (teamCounts[team] != 0) { + teamCount++; + } + } + // shown with more than two teams in the game, or when the team numbered like the sender's slot doesn't + // hold exactly one player + if (teamCount > 2 || teamCounts[DAT_GameSynchronyState::instance.protocolInvokerPlayerID] != 1) { + DAT_GameSynchronyState::instance + .unknownPlayerInfoArray_01[DAT_GameSynchronyState::instance.protocolInvokerPlayerID] + = timeGetTime(); + // "wishes to become an ally." + strcpy(DAT_GameSynchronyState::instance.receivedChatMessage, + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MULTIPLAYER_CONNECTION, 37)); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addChatMessageToDisplayList, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.protocolInvokerPlayerID, 0); + } + return; + } + // 2: the sender leaves its team and takes the first team that no player is in + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam1 == 2) { + for (int team = 1; team < countof(teamCounts); ++team) { + teamCounts[team] = 0; + } + // here an entry only marks that its team has a player + for (int slot = 1; slot < countof(DAT_GameSynchronyState::instance.currentPlayerFullIDArray); ++slot) { + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[slot] != -1) { + teamCounts[DAT_GameState::instance.mapAndTime.playerTeams[slot]] = 1; + } + } + for (int team = 1; team < countof(teamCounts); ++team) { + if (teamCounts[team] == 0) { + DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.protocolInvokerPlayerID] = team; + break; + } + } + // "has cancelled the alliance" + strcpy(DAT_GameSynchronyState::instance.receivedChatMessage, + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MULTIPLAYER_CONNECTION, 39)); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addChatMessageToDisplayList, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.protocolInvokerPlayerID, 0); + return; + } + if (DAT_GameSynchronyState::instance.DAT_GameCommandParam1 != 1) { + return; + } + // 1: the player in parameter 0 joins the sender's team, if each of the two is alone in its team and the + // same count test as for request 0 holds, here for parameter 0's slot + int teamCount = 0; + for (int team = 1; team < countof(teamCounts); ++team) { + teamCounts[team] = 0; + } + for (int slot = 1; slot < countof(DAT_GameSynchronyState::instance.currentPlayerFullIDArray); ++slot) { + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[slot] != -1) { + teamCounts[DAT_GameState::instance.mapAndTime.playerTeams[slot]]++; + } + } + for (int team = 1; team < countof(teamCounts); ++team) { + if (teamCounts[team] != 0) { + teamCount++; + } + } + if (teamCount > 2 || teamCounts[DAT_GameSynchronyState::instance.DAT_GameCommandParam0] != 1) { + canSwitch = TRUE; + } + if (MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::countPlayersInSameTeam, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0) + > 1) { + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::countPlayersInSameTeam, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.protocolInvokerPlayerID) + > 1) { + return; + } + if (!canSwitch) { + return; + } + DAT_GameState::instance.mapAndTime.playerTeams[DAT_GameSynchronyState::instance.DAT_GameCommandParam0] + = DAT_GameState::instance.mapAndTime.playerTeams[DAT_GameSynchronyState::instance.protocolInvokerPlayerID]; + // "has joined with" + strcpy(DAT_GameSynchronyState::instance.receivedChatMessage, + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MULTIPLAYER_CONNECTION, 38)); + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::addChatMessageToDisplayList, + DAT_GameSynchronyState::ptr)(DAT_GameSynchronyState::instance.DAT_GameCommandParam0, + DAT_GameSynchronyState::instance.protocolInvokerPlayerID); + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5ee1aa4b02..d00ce8f4f2 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23139,7 +23139,7 @@ SHC_3BB0A8C1_0x0048AB40 | 0.0% | Pending SHC_3BB0A8C1_0x0048ABF0 | 0.0% | Pending -SHC_3BB0A8C1_0x0048ACB0 | 0.0% | Pending +SHC_3BB0A8C1_0x0048ACB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048B170 | 0.0% | Pending