Repository navigation
TroopValueState leftovers: 4 functions, 2 at 100% #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7f24824
adca57f
e86e1b4
9d5e827
d7eb8e8
77b5904
d2865b5
dbed5c6
1814e77
088e56e
63085ac
9f5d4fe
b48efc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| THIS FILE IS AUTO GENERATED | ||
| Communicate changes to the dev team (e.g. via a Pull Request). | ||
| Changes get lost otherwise. | ||
|
|
||
| path: 'OpenSHC/Globals/DAT_ARRAY_00b4c7cc.hpp' | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "OpenSHC/Commands/MappersEnum.hpp" | ||
|
|
||
| // GLOBAL: STRONGHOLDCRUSADER 0x00B4C7CC | ||
| // StructResolver::Instance<enum OpenSHC::Commands::MappersEnum [9],11847628>::instance | ||
|
|
||
| namespace OpenSHC { | ||
|
|
||
| using OpenSHC::Commands::MappersEnum; | ||
|
|
||
| MACRO_STRUCT_RESOLVER(MappersEnum[9], false, Address::SHC_3BB0A8C1_0x00B4C7CC) DAT_ARRAY_00b4c7cc; | ||
| } // namespace OpenSHC | ||
|
|
||
| MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00B4C7CC); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /** | ||
| THIS FILE IS AUTO GENERATED | ||
| Communicate changes to the dev team (e.g. via a Pull Request). | ||
| Changes get lost otherwise. | ||
|
|
||
| path: 'OpenSHC/Globals/INT_ARRAY_00b4d0f0.hpp' | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| // GLOBAL: STRONGHOLDCRUSADER 0x00B4D0F0 | ||
| // StructResolver::Instance<int [9],11849968>::instance | ||
|
|
||
| namespace OpenSHC { | ||
|
|
||
| MACRO_STRUCT_RESOLVER(int[9], false, Address::SHC_3BB0A8C1_0x00B4D0F0) INT_ARRAY_00b4d0f0; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same answer as for |
||
| } // namespace OpenSHC | ||
|
|
||
| MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00B4D0F0); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #include "../TribesState.func.hpp" | ||
|
|
||
| #include "OpenSHC/Globals/DAT_UnitSelectionDefinedData.hpp" | ||
| #include "OpenSHC/Globals/DAT_UnitsState.hpp" | ||
|
|
||
| namespace OpenSHC { | ||
| namespace Map { | ||
| namespace Units { | ||
|
|
||
| // FUNCTION: STRONGHOLDCRUSADER 0x00522590 | ||
| void TribesState::addUnitToTribe(uint unitID, int tribeID) | ||
| { | ||
| this->tribes[tribeID].size = this->tribes[tribeID].size + 1; | ||
| int const bitFlagsIndex = (int)unitID / 16; | ||
| int const bitMaskIndex = (int)unitID % 16; | ||
| this->tribes[tribeID].unitSelectionBitMasked[bitFlagsIndex] | ||
| |= DAT_UnitSelectionDefinedData::instance.BitMaskHelper[bitMaskIndex]; | ||
| if (this->tribes[tribeID].selectionTargetUnitID == 0) { | ||
| this->tribes[tribeID].selectionTargetUnitID = unitID; | ||
| } | ||
| DAT_UnitsState::instance.units[unitID].selectionTargetUnitID = this->tribes[tribeID].selectionTargetUnitID; | ||
| DAT_UnitsState::instance.units[unitID].tribeID = tribeID; | ||
| DAT_UnitsState::instance.units[unitID].tribeUID = this->tribes[tribeID].uid; | ||
| DAT_UnitsState::instance.units[unitID].idInTribe = this->tribes[tribeID].size; | ||
| MACRO_CALL_MEMBER(TribesState_Func::setWhetherTribeContainsAnyUnits, this)(tribeID); | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #include "../../../Map.func.hpp" | ||
|
|
||
| #include "OpenSHC/Map/Units/TribesState.func.hpp" | ||
| #include "OpenSHC/Map/Units/TroopValueState.func.hpp" | ||
| #include "OpenSHC/AI/Tribes/AITribeType.hpp" | ||
| #include "OpenSHC/Map/Units/UnitLogicState.hpp" | ||
| #include "OpenSHC/Map/Units/UnitType.hpp" | ||
| #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" | ||
|
|
||
| #include "OpenSHC/Globals/DAT_TribesState.hpp" | ||
| #include "OpenSHC/Globals/DAT_TroopValueState.hpp" | ||
| #include "OpenSHC/Globals/DAT_UnitsState.hpp" | ||
|
|
||
| namespace OpenSHC { | ||
| namespace Map { | ||
| namespace Units { | ||
|
|
||
| using AI::Tribes::AITribeType; | ||
| using Map::Units::UnitLogicState; | ||
| using Map::Units::UnitType; | ||
| using WindowsHelper::Enums::BOOLEnum; | ||
|
|
||
| // FUNCTION: STRONGHOLDCRUSADER 0x0051CCB0 | ||
| void TroopValueState::assignMacemenAndKnightsNotFromPlayer1ToTribes() | ||
| { | ||
| int const playerID = DAT_TroopValueState::instance.attackInfo.pitchRelatedPlayerID; | ||
| int macemenCount = 0; | ||
| int knightCount = 0; | ||
| for (int unitID = 1; unitID < DAT_UnitsState::instance.maxUnitCount; unitID++) { | ||
| if (DAT_UnitsState::instance.units[unitID].logicalState == Map::Units::ULS_INVISIBLE | ||
| || !MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)( | ||
| DAT_UnitsState::instance.units[unitID].owner)) { | ||
| continue; | ||
| } | ||
| if (DAT_UnitsState::instance.units[unitID].unitType == Map::Units::UT_E_MACE) { | ||
| macemenCount = macemenCount + 1; | ||
| } else if (DAT_UnitsState::instance.units[unitID].unitType == Map::Units::UT_E_KNIGHT) { | ||
| knightCount = knightCount + 1; | ||
| } else { | ||
| continue; | ||
| } | ||
| MACRO_CALL_MEMBER(Map::Units::TribesState_Func::removeUnitFromTribe, DAT_TribesState::ptr)( | ||
| unitID, DAT_UnitsState::instance.units[unitID].tribeID); | ||
| } | ||
| int macemenLimit; | ||
| if (macemenCount > 40) { | ||
| macemenLimit = 10; | ||
| } else if (macemenCount > 20) { | ||
| macemenLimit = 8; | ||
| } else { | ||
| macemenLimit = 5; | ||
| } | ||
| int knightLimit; | ||
| if (knightCount > 18) { | ||
| knightLimit = 6; | ||
| } else if (knightCount > 12) { | ||
| knightLimit = 4; | ||
| } else { | ||
| knightLimit = 2; | ||
| } | ||
| if (macemenCount <= 0) { | ||
| DAT_TroopValueState::instance.attackInfo.macemenTribeCount = 0; | ||
| } else if (macemenCount <= macemenLimit) { | ||
| DAT_TroopValueState::instance.attackInfo.macemenTribeCount = 1; | ||
| } else { | ||
| DAT_TroopValueState::instance.attackInfo.macemenTribeCount = macemenCount / macemenLimit + 1; | ||
| if (DAT_TroopValueState::instance.attackInfo.macemenTribeCount > 100) { | ||
| DAT_TroopValueState::instance.attackInfo.macemenTribeCount = 100; | ||
| } | ||
| } | ||
| if (knightCount <= 0) { | ||
| DAT_TroopValueState::instance.attackInfo.knightTribeCount = 0; | ||
| } else if (knightCount <= knightLimit) { | ||
| DAT_TroopValueState::instance.attackInfo.knightTribeCount = 1; | ||
| } else { | ||
| DAT_TroopValueState::instance.attackInfo.knightTribeCount = knightCount / knightLimit + 1; | ||
| if (DAT_TroopValueState::instance.attackInfo.knightTribeCount > 100) { | ||
| DAT_TroopValueState::instance.attackInfo.knightTribeCount = 100; | ||
| } | ||
| } | ||
| int macemenUnitID = 0; | ||
| int tribeIndex; | ||
| for (tribeIndex = 0; tribeIndex < DAT_TroopValueState::instance.attackInfo.macemenTribeCount; | ||
| tribeIndex++) { | ||
| int const tribeID | ||
| = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, DAT_TribesState::ptr)(playerID, 0); | ||
| DAT_TroopValueState::instance.attackInfo.macemenTribeArray[tribeIndex] = tribeID; | ||
| DAT_TribesState::instance.tribes[tribeID].tribeType = AI::Tribes::AITT_MACEMEN; | ||
| for (int assigned = 0; assigned < macemenLimit;) { | ||
| macemenUnitID = macemenUnitID + 1; | ||
| if (DAT_UnitsState::instance.units[macemenUnitID].logicalState != Map::Units::ULS_INVISIBLE | ||
| && MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)( | ||
| DAT_UnitsState::instance.units[macemenUnitID].owner) | ||
| && DAT_UnitsState::instance.units[macemenUnitID].unitType == Map::Units::UT_E_MACE) { | ||
| MACRO_CALL_MEMBER(Map::Units::TribesState_Func::addUnitToTribe, DAT_TribesState::ptr)( | ||
| macemenUnitID, tribeID); | ||
| macemenCount = macemenCount - 1; | ||
| if (macemenCount <= 0) { | ||
| break; | ||
| } | ||
| assigned = assigned + 1; | ||
| } | ||
| } | ||
| if (macemenCount <= 0) { | ||
| break; | ||
| } | ||
| } | ||
| int knightUnitID = 0; | ||
| for (tribeIndex = 0; tribeIndex < DAT_TroopValueState::instance.attackInfo.knightTribeCount; tribeIndex++) { | ||
| int const tribeID | ||
| = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createTribe, DAT_TribesState::ptr)(playerID, 0); | ||
| DAT_TroopValueState::instance.attackInfo.knightTribeArray[tribeIndex] = tribeID; | ||
| DAT_TribesState::instance.tribes[tribeID].tribeType = AI::Tribes::AITT_KNIGHTS; | ||
| for (int assigned = 0; assigned < knightLimit;) { | ||
| knightUnitID = knightUnitID + 1; | ||
| if (DAT_UnitsState::instance.units[knightUnitID].logicalState != Map::Units::ULS_INVISIBLE | ||
| && MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getPlayerNot1AndHasKeep, this)( | ||
| DAT_UnitsState::instance.units[knightUnitID].owner) | ||
| && DAT_UnitsState::instance.units[knightUnitID].unitType == Map::Units::UT_E_KNIGHT) { | ||
| MACRO_CALL_MEMBER(Map::Units::TribesState_Func::addUnitToTribe, DAT_TribesState::ptr)( | ||
| knightUnitID, tribeID); | ||
| knightCount = knightCount - 1; | ||
| if (knightCount <= 0) { | ||
| return; | ||
| } | ||
| assigned = assigned + 1; | ||
| } | ||
| } | ||
| if (knightCount <= 0) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #include "../TroopValueState.func.hpp" | ||
|
|
||
| #include "OpenSHC/Map.func.hpp" | ||
| #include "OpenSHC/Game/GameMode2.hpp" | ||
| #include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" | ||
| #include "OpenSHC/Map/MapType2.hpp" | ||
| #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" | ||
|
|
||
| #include "OpenSHC/Globals/DAT_GameCore.hpp" | ||
| #include "OpenSHC/Globals/DAT_GameState.hpp" | ||
| #include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" | ||
|
|
||
| namespace OpenSHC { | ||
| namespace Map { | ||
| namespace Units { | ||
|
|
||
| using WindowsHelper::Enums::BOOLEnum; | ||
|
|
||
| // FUNCTION: STRONGHOLDCRUSADER 0x0051BDE0 | ||
| BOOLEnum TroopValueState::getPlayerNot1AndHasKeep(int playerID) | ||
| { | ||
| if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk | ||
| && DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 == Map::MT_SIEGE) { | ||
| if (playerID == 1) { | ||
| return TRUE; | ||
| } | ||
| } else if (playerID != 1 | ||
| && 0 < DAT_GameState::instance.playerDataArray[playerID] | ||
| .buildingEntryInfos[Game::Player::Enums::BEIE_KEEP] | ||
| .id) { | ||
| return TRUE; | ||
| } | ||
| return FALSE; | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this new hpp file really necsesary, why is this not part of AttackInfoDefinedData?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it, and yes, the separate global is necessary for the match.
Both tables do sit inside
AttackInfoDefinedData(0xB4C704): this one isfield_0xc8, andINT_ARRAY_00b4d0f0isfield_0x9ec. So I removed both headers and readDAT_AttackInfoDefinedData::instance.field_0xc8[k]and((int*)...field_0x9ec)[k]instead. With both resolver sets on,placeSiegeTentsAndAssignEngineerswent from 97.4% to 91.0% (normalized 88.7% → 82.4%).addUnitToTribeandgetPlayerNot1AndHasKeepstayed at 100%.The reason is visible in the diff. The original indexes both tables from one zero-based counter:
Once both are fields of one struct, MSVC knows they are
0x924apart. It walks one pointer instead, and reaches the other table at a fixed offset from it:The original compiler did not do that, so it saw two unrelated objects. In the original source these are separate globals, not members of
AttackInfoDefinedData. That is why I am keepingDAT_ARRAY_00b4c7ccandINT_ARRAY_00b4d0f0as they are.One follow-up: the merge with main took main's
AttackInfoDefinedData.hpp, which still declaresfield_0xc8..field_0xe8andfield_0x9ec[72]over the same memory. The real fix is in Ghidra: shrinkAttackInfoDefinedData(or mark those ranges as gaps) so the two tables are standalone globals there too. That has no effect on codegen.