id
int64
0
877k
file_name
stringlengths
3
109
file_path
stringlengths
13
185
content
stringlengths
31
9.38M
size
int64
31
9.38M
language
stringclasses
1 value
extension
stringclasses
11 values
total_lines
int64
1
340k
avg_line_length
float64
2.18
149k
max_line_length
int64
7
2.22M
alphanum_fraction
float64
0
1
repo_name
stringlengths
6
66
repo_stars
int64
94
47.3k
repo_forks
int64
0
12k
repo_open_issues
int64
0
3.4k
repo_license
stringclasses
11 values
repo_extraction_date
stringclasses
197 values
exact_duplicates_redpajama
bool
2 classes
near_duplicates_redpajama
bool
2 classes
exact_duplicates_githubcode
bool
2 classes
exact_duplicates_stackv2
bool
1 class
exact_duplicates_stackv1
bool
2 classes
near_duplicates_githubcode
bool
2 classes
near_duplicates_stackv1
bool
2 classes
near_duplicates_stackv2
bool
1 class
1,542,014
pickupdropinterf.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/pickupdropinterf.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "pickupdropinterf.h" #include "version.h" #include <array> namespace game::CPickUpDropInterfApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::Constructor)0x49d8a9, (Api::CreateButtonFunctor)0x49e905 }, // Russobit Api{ (Api::Constructor)0x49d8a9, (Api::CreateButtonFunctor)0x49e905 }, // Gog Api{ (Api::Constructor)0x49d216, (Api::CreateButtonFunctor)0x49e15c } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CPickUpDropInterfApi
1,452
C++
.cpp
46
28.173913
72
0.718772
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,015
mainview2.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/mainview2.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "mainview2.h" #include "version.h" #include <array> namespace game::CMainView2Api { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::ShowIsoDialog)0x4893a5, (Api::ShowDialog)0x4889d8, (Api::CreateToggleButtonFunctor)0x48c5d7, }, // Russobit Api{ (Api::ShowIsoDialog)0x4893a5, (Api::ShowDialog)0x4889d8, (Api::CreateToggleButtonFunctor)0x48c5d7, }, // Gog Api{ (Api::ShowIsoDialog)0x488f8e, (Api::ShowDialog)0x4885c1, (Api::CreateToggleButtonFunctor)0x48c19d, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMainView2Api
1,568
C++
.cpp
49
28.183673
72
0.708719
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,016
transformotherhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/transformotherhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "transformotherhooks.h" #include "attack.h" #include "batattacktransformother.h" #include "battleattackinfo.h" #include "battlemsgdata.h" #include "battlemsgdataview.h" #include "game.h" #include "gameutils.h" #include "globaldata.h" #include "itemview.h" #include "log.h" #include "midgardobjectmap.h" #include "midunit.h" #include "scripts.h" #include "settings.h" #include "unitgenerator.h" #include "unitimplview.h" #include "unitutils.h" #include "unitview.h" #include "ussoldier.h" #include "usunitimpl.h" #include "utils.h" #include "visitors.h" #include <fmt/format.h> namespace hooks { static int getTransformOtherLevel(const game::CMidUnit* unit, const game::CMidUnit* targetUnit, game::TUsUnitImpl* transformImpl, const game::IMidgardObjectMap* objectMap, const game::CMidgardID* unitOrItemId, const game::BattleMsgData* battleMsgData) { using namespace game; // The function is only accessed by the server thread - the single instance is enough. static std::optional<sol::environment> env; static std::optional<sol::function> getLevel; const auto path{scriptsFolder() / "transformOther.lua"}; if (!env && !getLevel) { getLevel = getScriptFunction(path, "getLevel", env, true, true); } if (!getLevel) { return 0; } try { const bindings::UnitView attacker{unit}; const bindings::UnitView target{targetUnit}; const bindings::UnitImplView impl{transformImpl}; const bindings::BattleMsgDataView battleView{battleMsgData, objectMap}; if (CMidgardIDApi::get().getType(unitOrItemId) == IdType::Item) { const bindings::ItemView itemView{unitOrItemId, objectMap}; return (*getLevel)(attacker, target, impl, &itemView, battleView); } else return (*getLevel)(attacker, target, impl, nullptr, battleView); } catch (const std::exception& e) { showErrorMessageBox(fmt::format("Failed to run '{:s}' script.\n" "Reason: '{:s}'", path.string(), e.what())); return 0; } } void __fastcall transformOtherAttackOnHitHooked(game::CBatAttackTransformOther* thisptr, int /*%edx*/, game::IMidgardObjectMap* objectMap, game::BattleMsgData* battleMsgData, game::CMidgardID* targetUnitId, game::BattleAttackInfo** attackInfo) { using namespace game; const auto& fn = gameFunctions(); CMidgardID targetGroupId{emptyId}; fn.getAllyOrEnemyGroupId(&targetGroupId, battleMsgData, targetUnitId, true); const auto targetPosition = fn.getUnitPositionInGroup(objectMap, &targetGroupId, targetUnitId); const CMidUnit* targetUnit = fn.findUnitById(objectMap, targetUnitId); const CMidgardID targetUnitImplId{targetUnit->unitImpl->id}; auto attackId = &thisptr->attack->id; CMidgardID transformImplId{emptyId}; fn.getSummonUnitImplIdByAttack(&transformImplId, attackId, targetPosition, isUnitSmall(targetUnit)); if (transformImplId == emptyId) return; if (userSettings().leveledTransformOtherAttack) { const auto& global = GlobalDataApi::get(); auto globalData = *global.getGlobalData(); auto transformImpl = static_cast<TUsUnitImpl*>( global.findById(globalData->units, &transformImplId)); const CMidUnit* unit = fn.findUnitById(objectMap, &thisptr->unitId); const auto transformLevel = getTransformOtherLevel(unit, targetUnit, transformImpl, objectMap, &thisptr->unitOrItemId, battleMsgData); CUnitGenerator* unitGenerator = globalData->unitGenerator; CMidgardID leveledImplId{transformImplId}; unitGenerator->vftable->generateUnitImplId(unitGenerator, &leveledImplId, &transformImplId, transformLevel); unitGenerator->vftable->generateUnitImpl(unitGenerator, &leveledImplId); transformImplId = leveledImplId; } const auto targetSoldier = fn.castUnitImplToSoldier(targetUnit->unitImpl); bool prevAttackTwice = targetSoldier && targetSoldier->vftable->getAttackTwice(targetSoldier); const auto& visitors = VisitorApi::get(); visitors.transformUnit(targetUnitId, &transformImplId, true, objectMap, 1); updateAttackCountAfterTransformation(battleMsgData, targetUnit, prevAttackTwice); BattleAttackUnitInfo info{}; info.unitId = *targetUnitId; info.unitImplId = targetUnitImplId; BattleAttackInfoApi::get().addUnitInfo(&(*attackInfo)->unitsInfo, &info); const auto& battle = BattleMsgDataApi::get(); battle.removeTransformStatuses(targetUnitId, battleMsgData); battle.setUnitStatus(battleMsgData, targetUnitId, BattleStatus::Transform, true); if (thisptr->attack->vftable->getInfinite(thisptr->attack)) battle.setUnitStatus(battleMsgData, targetUnitId, BattleStatus::TransformLong, true); auto targetUnitInfo = battle.getUnitInfoById(battleMsgData, targetUnitId); if (targetUnitInfo) targetUnitInfo->transformAppliedRound = battleMsgData->currentRound; battle.setUnitHp(battleMsgData, targetUnitId, targetUnit->currentHp); } } // namespace hooks
6,555
C++
.cpp
134
39.447761
99
0.668857
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,017
d2osexception.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/d2osexception.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "d2osexception.h" #include "version.h" #include <array> namespace game::os_exceptionApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::ThrowException)0x66d89c, }, // Russobit Api{ (Api::ThrowException)0x66d89c, }, // Gog Api{ (Api::ThrowException)0x66c1dc, }, // Scenario Editor Api{ (Api::ThrowException)0x5714ae, } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::os_exceptionApi
1,397
C++
.cpp
47
26.468085
72
0.70855
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,018
midgardmapfog.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/midgardmapfog.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "midgardmapfog.h" #include "version.h" #include <array> namespace game::CMidgardMapFogApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::GetFog)0x5f4f43, }, // Russobit Api{ (Api::GetFog)0x5f4f43, }, // Gog Api{ (Api::GetFog)0x5f3c10, }, // Scenario Editor Api{ (Api::GetFog)0x5004fe, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMidgardMapFogApi
1,370
C++
.cpp
47
25.893617
72
0.703338
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,019
attacktypepairvector.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/attacktypepairvector.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attacktypepairvector.h" #include "version.h" #include <array> namespace game::AttackTypePairVectorApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::PushBack)0x6479b0, }, // Russobit Api{ (Api::PushBack)0x6479b0, }, // Gog Api{ (Api::PushBack)0x6461e0, }, // Scenario Editor Api{ (Api::PushBack)nullptr, } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::AttackTypePairVectorApi
1,396
C++
.cpp
47
26.446809
72
0.709821
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,020
raceset.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/raceset.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "raceset.h" #include "version.h" #include <array> namespace game::RaceSetApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::Clear)0x424879, (Api::Add)0x4246d4, }, // Russobit Api{ (Api::Clear)0x424879, (Api::Add)0x4246d4, }, // Gog Api{ (Api::Clear)0x42434a, (Api::Add)0x4241e7, } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::RaceSetApi
1,360
C++
.cpp
46
26.173913
72
0.696715
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,021
racelist.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/racelist.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "racelist.h" #include "version.h" #include <array> namespace game::RaceCategoryListApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x424628, (Api::CopyConstructor)0x42c485, (Api::FreeNodes)0x40a549, (Api::FreeNode)0x4c8755, (Api::Add)0x42c546, (Api::GetPlayableRaces)0x4ec2a4, }, // Russobit Api{ (Api::Constructor)0x424628, (Api::CopyConstructor)0x42c485, (Api::FreeNodes)0x40a549, (Api::FreeNode)0x4c8755, (Api::Add)0x42c546, (Api::GetPlayableRaces)0x4ec2a4, }, // Gog Api{ (Api::Constructor)0x42413b, (Api::CopyConstructor)0x42bea5, (Api::FreeNodes)0x40a22b, (Api::FreeNode)0x5215fc, (Api::Add)0x42bf66, (Api::GetPlayableRaces)0x4eb764, }, // Scenario Editor Api{ (Api::Constructor)0x402fed, (Api::CopyConstructor)nullptr, (Api::FreeNodes)0x43ee56, (Api::FreeNode)0x4fd186, (Api::Add)0x419441, (Api::GetPlayableRaces)nullptr, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::RaceCategoryListApi
2,091
C++
.cpp
67
26.238806
72
0.677563
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,022
middiplomacy.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/middiplomacy.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "middiplomacy.h" #include "version.h" #include <array> namespace game::CMidDiplomacyApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::GetRelation)0x5f8bfc, (Api::GetRelation)0x5f8c79, (Api::GetBool)0x5f8cb0, (Api::GetAllianceTurn)0x5f8cf4, (Api::GetBool)0x5f8d2b, (Api::GetBool)0x5f8cd2, (Api::CheckRelationType)0x5f9101, (Api::CheckRelationType)0x5f912d, (Api::CheckRelationType)0x5f917d, }, // Russobit Api{ (Api::GetRelation)0x5f8bfc, (Api::GetRelation)0x5f8c79, (Api::GetBool)0x5f8cb0, (Api::GetAllianceTurn)0x5f8cf4, (Api::GetBool)0x5f8d2b, (Api::GetBool)0x5f8cd2, (Api::CheckRelationType)0x5f9101, (Api::CheckRelationType)0x5f912d, (Api::CheckRelationType)0x5f917d, }, // Gog Api{ (Api::GetRelation)0x5f788f, (Api::GetRelation)0x5f78c5, (Api::GetBool)0x5f78fc, (Api::GetAllianceTurn)0x5f7940, (Api::GetBool)0x5f7977, (Api::GetBool)0x5f791e, (Api::CheckRelationType)0x5f7d94, (Api::CheckRelationType)0x5f7dc0, (Api::CheckRelationType)0x5f7e10, }, // Scenario Editor Api{ (Api::GetRelation)0x4F7176, (Api::GetRelation)nullptr, (Api::GetBool)0x4F71F3, (Api::GetAllianceTurn)nullptr, (Api::GetBool)0x4F7237, (Api::GetBool)0x4F7215, (Api::CheckRelationType)nullptr, (Api::CheckRelationType)nullptr, (Api::CheckRelationType)nullptr, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } }
2,537
C++
.cpp
79
26.544304
72
0.674002
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,023
refreshinfo.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/refreshinfo.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "refreshinfo.h" #include "version.h" #include <array> namespace game::CRefreshInfoApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x47c3c7, (Api::Constructor2)0x47c3fd, (Api::Destructor)0x415c08, (Api::AddObject)0x47c471, }, // Russobit Api{ (Api::Constructor)0x47c3c7, (Api::Constructor2)0x47c3fd, (Api::Destructor)0x415c08, (Api::AddObject)0x47c471, }, // Gog Api{ (Api::Constructor)0x47bf45, (Api::Constructor2)0x47bf7b, (Api::Destructor)0x4158ee, (Api::AddObject)0x47bfef, }, // Scenario Editor Api{ (Api::Constructor)nullptr, (Api::Constructor2)nullptr, (Api::Destructor)nullptr, (Api::AddObject)nullptr, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } // clang-format off static std::array<CNetMsgVftable*, 4> vftables = {{ // Akella (CNetMsgVftable*)0x6d4f64, // Russobit (CNetMsgVftable*)0x6d4f64, // Gog (CNetMsgVftable*)0x6d2f04, // Scenario Editor (CNetMsgVftable*)nullptr, }}; // clang-format on CNetMsgVftable* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CRefreshInfoApi
2,180
C++
.cpp
75
24.866667
72
0.686368
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,024
scenedit.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/scenedit.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "scenedit.h" namespace game::CScenEditApi { // clang-format off Api functions{ (Api::Instance)0x4013af, }; // clang-format on Api& get() { return functions; } } // namespace game::CScenEditApi
1,028
C++
.cpp
30
32.266667
72
0.755287
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,025
intvector.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/intvector.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "intvector.h" #include "version.h" #include <array> namespace game::IntVectorApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Destructor)0x67fb63, (Api::Reserve)0x49f2e6, (Api::PushBack)0x620547, }, // Russobit Api{ (Api::Destructor)0x67fb63, (Api::Reserve)0x49f2e6, (Api::PushBack)0x620547, }, // Gog Api{ (Api::Destructor)0x51f68c, (Api::Reserve)0x49eb55, (Api::PushBack)0x61f03b, }, // Scenario Editor Api{ (Api::Destructor)0x458779, (Api::Reserve)0x4c8c99, (Api::PushBack)0x523973, } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::IntVectorApi
1,632
C++
.cpp
55
25.581818
72
0.685751
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,026
umattackhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/umattackhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "umattackhooks.h" #include "dbtable.h" #include "mempool.h" #include "umattack.h" #include "utils.h" namespace hooks { struct CUmAttackDataPatched : game::CUmAttackData { game::CAttackModified altAttackModified; }; game::CAttackModified* getAltAttackModified(const game::CUmAttack* umAttack) { auto data = (CUmAttackDataPatched*)umAttack->data; return &data->altAttackModified; } game::CUmAttack* __fastcall umAttackCtorHooked(game::CUmAttack* thisptr, int /*%edx*/, const game::CMidgardID* modifierId, game::CDBTable* dbTable, const game::GlobalData** globalData) { using namespace game; const auto& umAttackApi = CUmAttackApi::get(); const auto& umAttackVftable = CUmAttackApi::vftable(); const auto& attackModifiedApi = CAttackModifiedApi::get(); const auto& dbApi = CDBTableApi::get(); thisptr->usUnit.id = emptyId; CUmModifierApi::get().constructor(&thisptr->umModifier, modifierId, globalData); thisptr->data = (CUmAttackDataPatched*)Memory::get().allocate(sizeof(CUmAttackDataPatched)); umAttackApi.dataConstructor(thisptr->data); thisptr->usUnit.vftable = umAttackVftable.usUnit; thisptr->usSoldier.vftable = umAttackVftable.usSoldier; thisptr->umModifier.vftable = umAttackVftable.umModifier; if (dbApi.eof(dbTable)) dbApi.missingValueException(dbApi.getName(dbTable), idToString(modifierId).c_str()); for (; !dbApi.eof(dbTable); dbApi.next(dbTable)) umAttackApi.readData(dbTable, thisptr->data, globalData); auto& attackData = thisptr->data->attackModified.data; attackData->initiative = thisptr->data->initiative.value; attackData->power = thisptr->data->power.value; attackData->qtyDamage = thisptr->data->qtyDamage.value; attackData->attackDrain = thisptr->data->attackDrain.value; attackModifiedApi.copyConstructor(getAltAttackModified(thisptr), &thisptr->data->attackModified); return thisptr; } game::CUmAttack* __fastcall umAttackCopyCtorHooked(game::CUmAttack* thisptr, int /*%edx*/, const game::CUmAttack* src) { using namespace game; const auto& umAttackVftable = CUmAttackApi::vftable(); const auto& attackModifiedApi = CAttackModifiedApi::get(); thisptr->usUnit.id = src->usUnit.id; CUmModifierApi::get().copyConstructor(&thisptr->umModifier, &src->umModifier); thisptr->data = (CUmAttackDataPatched*)Memory::get().allocate(sizeof(CUmAttackDataPatched)); CUmAttackApi::get().dataCopyConstructor(thisptr->data, src->data); attackModifiedApi.copyConstructor(getAltAttackModified(thisptr), getAltAttackModified(src)); thisptr->usUnit.vftable = umAttackVftable.usUnit; thisptr->usSoldier.vftable = umAttackVftable.usSoldier; thisptr->umModifier.vftable = umAttackVftable.umModifier; return thisptr; } } // namespace hooks
3,973
C++
.cpp
82
41.012195
96
0.69726
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,027
menurandomscenariosingle.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/menurandomscenariosingle.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "menurandomscenariosingle.h" #include "mempool.h" #include "menuphase.h" #include "menurandomscenario.h" #include "utils.h" namespace hooks { /** Menu for single-player random scenario generation. */ struct CMenuRandomScenarioSingle : public CMenuRandomScenario { CMenuRandomScenarioSingle(game::CMenuPhase* menuPhase); ~CMenuRandomScenarioSingle() = default; }; static void startScenarioLocal(CMenuRandomScenario* menu) { prepareToStartRandomScenario(menu); // Switch to the next menu game::CMenuPhaseApi::get().setTransition(menu->menuBaseData->menuPhase, 0); } CMenuRandomScenarioSingle::CMenuRandomScenarioSingle(game::CMenuPhase* menuPhase) : CMenuRandomScenario(menuPhase, startScenarioLocal, "DLG_RANDOM_SCENARIO_SINGLE") { } game::CMenuBase* __stdcall createMenuRandomScenarioSingle(game::CMenuPhase* menuPhase) { const auto& allocateMem{game::Memory::get().allocate}; auto menu = (CMenuRandomScenarioSingle*)allocateMem(sizeof(CMenuRandomScenarioSingle)); new (menu) CMenuRandomScenarioSingle(menuPhase); return menu; } } // namespace hooks
1,921
C++
.cpp
47
38.446809
91
0.781652
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,028
targetslistutils.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/targetslistutils.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "targetslistutils.h" #include "midunitgroup.h" namespace hooks { game::CMidgardID getTargetUnitId(int unitPosition, const game::CMidUnitGroup* targetGroup, const game::CMidUnitGroup* otherGroup) { using namespace game; const auto& groupApi = CMidUnitGroupApi::get(); if (unitPosition >= 0) { return *groupApi.getUnitIdByPosition(targetGroup, unitPosition); } else { return *groupApi.getUnitIdByPosition(otherGroup, -(unitPosition + 1)); } } } // namespace hooks
1,392
C++
.cpp
34
36.264706
78
0.718195
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,029
fortcategory.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/fortcategory.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "fortcategory.h" #include "version.h" #include <array> namespace game::FortCategories { // clang-format off static std::array<Categories, 4> categories = {{ // Akella Categories{ (LFortCategory*)0x839ac0, (LFortCategory*)0x839ad0 }, // Russobit Categories{ (LFortCategory*)0x839ac0, (LFortCategory*)0x839ad0 }, // Gog Categories{ (LFortCategory*)0x837a70, (LFortCategory*)0x837a80 }, // Scenario Editor Categories{ (LFortCategory*)0x665698, (LFortCategory*)0x6656a8 } }}; // clang-format on Categories& get() { return categories[static_cast<int>(hooks::gameVersion())]; } } // namespace game::FortCategories
1,550
C++
.cpp
51
26.686275
72
0.712182
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,030
menunewskirmishhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/menunewskirmishhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "menunewskirmishhooks.h" #include "dialoginterf.h" #include "editboxinterf.h" #include "log.h" #include "netcustomservice.h" #include "originalfunctions.h" #include "roomservercreation.h" #include "utils.h" namespace hooks { static bool isRoomAndPlayerNamesValid(game::CMenuBase* menu) { using namespace game; auto& menuApi = CMenuBaseApi::get(); auto& dialogApi = CDialogInterfApi::get(); auto dialog = menuApi.getDialogInterface(menu); auto editGame = dialogApi.findEditBox(dialog, "EDIT_GAME"); if (!editGame || !std::strlen(editGame->data->editBoxData.inputString.string)) { return false; } auto editName = dialogApi.findEditBox(dialog, "EDIT_NAME"); if (!editName || !std::strlen(editName->data->editBoxData.inputString.string)) { return false; } return true; } void __fastcall menuNewSkirmishLoadScenarioCallbackHooked(game::CMenuBase* thisptr, int /*%edx*/) { auto service = getNetService(); if (!service) { // Current net service is not custom lobby, use default game logic getOriginalFunctions().menuNewSkirmishLoadScenario(thisptr); return; } logDebug("lobby.log", "Custom lobby net service!"); if (!isRoomAndPlayerNamesValid(thisptr)) { // Please enter valid game and player names showMessageBox(getInterfaceText("X005TA0867")); return; } startRoomAndServerCreation(thisptr, false); } } // namespace hooks
2,286
C++
.cpp
60
34.35
97
0.732611
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,031
globaldata.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/globaldata.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "globaldata.h" #include "version.h" #include <array> namespace game::GlobalDataApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::GetGlobalData)0x58004f, (Api::FindById)0x583c35, (Api::FindItemById)0x58452a, (Api::FindDynUpgradeById)0x598644, (Api::FindTextById)0x595b74, }, // Russobit Api{ (Api::GetGlobalData)0x58004f, (Api::FindById)0x583c35, (Api::FindItemById)0x58452a, (Api::FindDynUpgradeById)0x598644, (Api::FindTextById)0x595b74, }, // Gog Api{ (Api::GetGlobalData)0x57f707, (Api::FindById)0x592f25, (Api::FindItemById)0x5836dd, (Api::FindDynUpgradeById)0x597781, (Api::FindTextById)0x594c3c, }, // Scenario Editor Api{ (Api::GetGlobalData)0x5286ce, (Api::FindById)0x538beb, (Api::FindItemById)0x52d10b, (Api::FindDynUpgradeById)0x542c85, (Api::FindTextById)0x5396f7, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::GlobalDataApi
1,987
C++
.cpp
63
26.825397
72
0.687858
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,032
aimovestackaction.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/aimovestackaction.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "aimovestackaction.h" #include "version.h" #include <array> namespace game::CAiMoveStackActionApi { // clang-format off static std::array<Vftable, 4> vftables = {{ // Akella Vftable{ (IAiTacticActionVftable*)0x6d31e4, (IAiReactionVftable*)0x6d3174, }, // Russobit Vftable{ (IAiTacticActionVftable*)0x6d31e4, (IAiReactionVftable*)0x6d3174, }, // Gog Vftable{ (IAiTacticActionVftable*)0x6d1184, (IAiReactionVftable*)0x6d1114, }, // Scenario Editor Vftable{ (IAiTacticActionVftable*)nullptr, (IAiReactionVftable*)nullptr, }, }}; // clang-format on const Vftable& vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CAiMoveStackActionApi
1,617
C++
.cpp
51
28
72
0.720692
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,033
batattackshatter.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/batattackshatter.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "batattackshatter.h" #include "version.h" #include <array> namespace game::CBatAttackShatterApi { // clang-format off static std::array<IBatAttackVftable*, 4> vftables = {{ // Akella (IBatAttackVftable*)0x6f504c, // Russobit (IBatAttackVftable*)0x6f504c, // Gog (IBatAttackVftable*)0x6f2ffc, // Scenario Editor (IBatAttackVftable*)nullptr, }}; // clang-format on IBatAttackVftable* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CBatAttackShatterApi
1,357
C++
.cpp
39
32.307692
72
0.75019
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,034
chatinterf.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/chatinterf.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "chatinterf.h" #include "version.h" #include <array> namespace game::CChatInterfApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::ListBoxDisplayHandler)0x4BC34A, }, // Russobit Api{ (Api::ListBoxDisplayHandler)0x4BC34A, }, // Gog Api{ (Api::ListBoxDisplayHandler)0x4BB9A2, }, // Scenario Editor Api{ (Api::ListBoxDisplayHandler)nullptr, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CChatInterfApi
1,420
C++
.cpp
47
26.957447
72
0.714181
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,035
originalfunctions.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/originalfunctions.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "originalfunctions.h" namespace hooks { static OriginalFunctions originalFunctions; OriginalFunctions& getOriginalFunctions() { return originalFunctions; } } // namespace hooks
1,008
C++
.cpp
26
36.769231
72
0.775844
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,036
multilayerimg.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/multilayerimg.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "multilayerimg.h" #include "version.h" #include <array> namespace game::CMultiLayerImgApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x5b5c88, (Api::AddImage)0x5b5db1, }, // Russobit Api{ (Api::Constructor)0x5b5c88, (Api::AddImage)0x5b5db1, }, // Gog Api{ (Api::Constructor)0x5b4f54, (Api::AddImage)0x5b507d, }, // Scenario Editor Api{ (Api::Constructor)0x5607ba, (Api::AddImage)0x5608e3, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMultiLayerImgApi
1,522
C++
.cpp
51
26.137255
72
0.697817
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,037
scenariotemplates.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/scenariotemplates.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "scenariotemplates.h" #include "maptemplatereader.h" #include "utils.h" #include <sol/sol.hpp> namespace hooks { static ScenarioTemplates scenarioTemplates; bool loadScenarioTemplates() { namespace fs = std::filesystem; const auto& folder{templatesFolder()}; if (!fs::exists(folder)) { return true; } std::set<fs::path> templateFiles; // Make sure we read templates always in the same order (alphabetical) for (const auto& entry : fs::directory_iterator(folder)) { if (!entry.is_regular_file()) { continue; } if (entry.path().extension() == ".lua") { templateFiles.insert(entry.path()); } } for (const auto& templateFile : templateFiles) { try { // Create a new lua VM until we use environments. // Without them VM gets polluted with previous data and works incorrect sol::state lua; rsg::bindLuaApi(lua); scenarioTemplates.emplace_back(templateFile.string(), rsg::readTemplateSettings(templateFile, lua)); } catch (const std::exception&) { // Silently ignore lua files that are not templates } } return true; } void freeScenarioTemplates() { scenarioTemplates.clear(); } const ScenarioTemplates& getScenarioTemplates() { return scenarioTemplates; } } // namespace hooks
2,260
C++
.cpp
64
29.859375
89
0.681631
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,038
attackreachcat.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/attackreachcat.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attackreachcat.h" #include "version.h" #include <array> namespace game::AttackReachCategories { // clang-format off static std::array<Categories, 4> categories = {{ // Akella Categories{ (LAttackReach*)0x83a110, (LAttackReach*)0x83a120, (LAttackReach*)0x83a100 }, // Russobit Categories{ (LAttackReach*)0x83a110, (LAttackReach*)0x83a120, (LAttackReach*)0x83a100 }, // Gog Categories{ (LAttackReach*)0x8380c0, (LAttackReach*)0x8380d0, (LAttackReach*)0x8380b0 }, // Scenario Editor Categories{ (LAttackReach*)0x665908, (LAttackReach*)0x665918, (LAttackReach*)0x6658f8, }, }}; static std::array<const void*, 4> vftables = {{ // Akella (const void*)0x6ceacc, // Russobit (const void*)0x6ceacc, // Gog (const void*)0x6cca6c, // Scenario Editor (const void*)0x5df46c, }}; // clang-format on Categories& get() { return categories[static_cast<int>(hooks::gameVersion())]; } const void* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::AttackReachCategories namespace game::LAttackReachTableApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x5926dc, (Api::Init)0x59282c, (Api::ReadCategory)0x5928a4, (Api::InitDone)0x5927e7, (Api::FindCategoryById)0x40ad68, }, // Russobit Api{ (Api::Constructor)0x5926dc, (Api::Init)0x59282c, (Api::ReadCategory)0x5928a4, (Api::InitDone)0x5927e7, (Api::FindCategoryById)0x40ad68, }, // Gog Api{ (Api::Constructor)0x5917f4, (Api::Init)0x591944, (Api::ReadCategory)0x5919bc, (Api::InitDone)0x5918ff, (Api::FindCategoryById)0x40a9f4, }, // Scenario Editor Api{ (Api::Constructor)0x537abb, (Api::Init)0x537c0b, (Api::ReadCategory)0x537c83, (Api::InitDone)0x537bc6, (Api::FindCategoryById)0x54ece4, }, }}; static std::array<const void*, 4> vftables = {{ // Akella (const void*)0x6eb3ec, // Russobit (const void*)0x6eb3ec, // Gog (const void*)0x6e938c, // Scenario Editor (const void*)0x5df474, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } const void* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::LAttackReachTableApi
3,396
C++
.cpp
125
22.472
72
0.665746
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,039
testconditionhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/testconditionhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "testconditionhooks.h" #include "eventconditioncathooks.h" #include "midcondgamemode.h" #include "midcondownresource.h" #include "midcondplayertype.h" #include "midcondscript.h" #include "midcondvarcmp.h" #include "originalfunctions.h" namespace hooks { game::ITestCondition* __stdcall createTestConditionHooked(game::CMidEvCondition* eventCondition, bool samePlayer, const game::CMidgardID* triggererStackId) { const auto& conditions = customEventConditions(); const auto id = eventCondition->category.id; if (id == conditions.ownResource.category.id) { return createTestOwnResource(eventCondition); } if (id == conditions.gameMode.category.id) { return createTestGameMode(eventCondition); } if (id == conditions.playerType.category.id) { return createTestPlayerType(eventCondition); } if (id == conditions.variableCmp.category.id) { return createTestVarCmp(eventCondition); } if (id == conditions.script.category.id) { return createTestScript(eventCondition); } return getOriginalFunctions().createTestCondition(eventCondition, samePlayer, triggererStackId); } } // namespace hooks
2,123
C++
.cpp
51
36.019608
100
0.71678
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,040
batattackgiveattack.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/batattackgiveattack.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "batattackgiveattack.h" #include "version.h" #include <array> namespace game::CBatAttackGiveAttackApi { // clang-format off static std::array<IBatAttackVftable*, 4> vftables = {{ // Akella (IBatAttackVftable*)0x6f540c, // Russobit (IBatAttackVftable*)0x6f540c, // Gog (IBatAttackVftable*)0x6f33bc, // Scenario Editor (IBatAttackVftable*)nullptr, }}; // clang-format on IBatAttackVftable* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CBatAttackGiveAttackApi
1,366
C++
.cpp
39
32.538462
72
0.751891
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,041
menunewskirmishhotseathooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/menunewskirmishhotseathooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "menunewskirmishhotseathooks.h" #include "button.h" #include "dialoginterf.h" #include "menunewskirmishhotseat.h" #include "originalfunctions.h" namespace hooks { static void __fastcall showMenuRandomScenarioSingle(game::CMenuNewSkirmishHotseat* thisptr, int /*%edx*/) { using namespace game; // Transfer to a new random scenario generation menu, from state 30 to 39 CMenuPhase* menuPhase{thisptr->menuBaseData->menuPhase}; CMenuPhaseApi::get().setTransition(menuPhase, 1); } game::CMenuNewSkirmishHotseat* __fastcall menuNewSkirmishHotseatCtorHooked( game::CMenuNewSkirmishHotseat* thisptr, int /*%edx*/, game::CMenuPhase* menuPhase) { getOriginalFunctions().menuNewSkirmishHotseatCtor(thisptr, menuPhase); using namespace game; static const char buttonName[] = "BTN_RANDOM_MAP"; const auto& menuBase{CMenuBaseApi::get()}; const auto& dialogApi{CDialogInterfApi::get()}; CDialogInterf* dialog{menuBase.getDialogInterface(thisptr)}; // Check if we have new button for random scenario generator menu and setup its callback if (dialogApi.findControl(dialog, buttonName)) { const auto& button{CButtonInterfApi::get()}; SmartPointer functor; auto callback = (CMenuBaseApi::Api::ButtonCallback)showMenuRandomScenarioSingle; menuBase.createButtonFunctor(&functor, 0, thisptr, &callback); button.assignFunctor(dialog, buttonName, "DLG_HOTSEAT_NEW", &functor, 0); SmartPointerApi::get().createOrFreeNoDtor(&functor, nullptr); } return thisptr; } } // namespace hooks
2,461
C++
.cpp
55
40.145455
92
0.740075
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,042
netcustomplayer.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/netcustomplayer.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "netcustomplayer.h" #include "d2string.h" #include "log.h" #include "mempool.h" #include "mqnetplayer.h" #include "mqnetreception.h" #include "mqnetsystem.h" #include "netcustomsession.h" #include "netmsg.h" #include <fmt/format.h> #include <mutex> #include <string> namespace hooks { void playerLog(const std::string& message) { static std::mutex logMutex; std::lock_guard lock(logMutex); logDebug("lobby.log", message); } static void __fastcall netCustomPlayerDtor(CNetCustomPlayer* thisptr, int /*%edx*/, char flags) { playerLog("CNetCustomPlayer d-tor called"); thisptr->~CNetCustomPlayer(); if (flags & 1) { playerLog("CNetCustomPlayer free memory"); game::Memory::get().freeNonZero(thisptr); } } static game::String* __fastcall netCustomPlayerGetName(CNetCustomPlayer* thisptr, int /*%edx*/, game::String* string) { playerLog(fmt::format("CNetCustomPlayer {:s} getName", thisptr->name)); game::StringApi::get().initFromString(string, thisptr->name.c_str()); return string; } static int __fastcall netCustomPlayerGetNetId(CNetCustomPlayer* thisptr, int /*%edx*/) { playerLog(fmt::format("CNetCustomPlayer {:s} getNetId 0x{:x}", thisptr->name, thisptr->netId)); return static_cast<int>(thisptr->netId); } static game::IMqNetSession* __fastcall netCustomPlayerGetSession(CNetCustomPlayer* thisptr, int /*%edx*/) { playerLog(fmt::format("CNetCustomPlayer {:s} getSession", thisptr->name)); return thisptr->session; } static int __fastcall netCustomPlayerGetMessageCount(CNetCustomPlayer* thisptr, int /*%edx*/) { playerLog(fmt::format("CNetCustomPlayer {:s} getMessageCount", thisptr->name)); return 1; } static bool __fastcall netCustomPlayerSendMessage(CNetCustomPlayer* thisptr, int /*%edx*/, int idTo, const game::NetMessageHeader* message) { playerLog(fmt::format("CNetCustomPlayer {:s} sendMessage '{:s}' to {:d}", thisptr->name, message->messageClassName, idTo)); return true; } static int __fastcall netCustomPlayerReceiveMessage(CNetCustomPlayer* thisptr, int /*%edx*/, int* idFrom, game::NetMessageHeader* buffer) { playerLog(fmt::format("CNetCustomPlayer {:s} receiveMessage", thisptr->name)); return 0; } static void __fastcall netCustomPlayerSetNetSystem(CNetCustomPlayer* thisptr, int /*%edx*/, game::IMqNetSystem* netSystem) { playerLog(fmt::format("CNetCustomPlayer {:s} setNetSystem", thisptr->name)); if (thisptr->netSystem != netSystem) { if (thisptr->netSystem) { thisptr->netSystem->vftable->destructor(thisptr->netSystem, 1); } thisptr->netSystem = netSystem; } } static int __fastcall netCustomPlayerMethod8(CNetCustomPlayer* thisptr, int /*%edx*/, int a2) { playerLog(fmt::format("CNetCustomPlayer {:s} method8", thisptr->name)); return a2; } static game::IMqNetPlayerVftable netCustomPlayerVftable{ (game::IMqNetPlayerVftable::Destructor)netCustomPlayerDtor, (game::IMqNetPlayerVftable::GetName)netCustomPlayerGetName, (game::IMqNetPlayerVftable::GetNetId)netCustomPlayerGetNetId, (game::IMqNetPlayerVftable::GetSession)netCustomPlayerGetSession, (game::IMqNetPlayerVftable::GetMessageCount)netCustomPlayerGetMessageCount, (game::IMqNetPlayerVftable::SendNetMessage)netCustomPlayerSendMessage, (game::IMqNetPlayerVftable::ReceiveMessage)netCustomPlayerReceiveMessage, (game::IMqNetPlayerVftable::SetNetSystem)netCustomPlayerSetNetSystem, (game::IMqNetPlayerVftable::Method8)netCustomPlayerMethod8, }; CNetCustomPlayer::CNetCustomPlayer(CNetCustomSession* session, game::IMqNetSystem* netSystem, game::IMqNetReception* netReception, const char* name, NetworkPeer::PeerPtr&& peer, std::uint32_t netId) : name{name} , netPeer{std::move(peer)} , session{session} , netSystem{netSystem} , netReception{netReception} , netId{netId} { vftable = &netCustomPlayerVftable; } CNetCustomPlayer::~CNetCustomPlayer() { if (netSystem) { playerLog("CNetCustomPlayer delete netSystem"); netSystem->vftable->destructor(netSystem, 1); } if (netReception) { playerLog("CNetCustomPlayer delete netReception"); netReception->vftable->destructor(netReception, 1); } } } // namespace hooks
5,882
C++
.cpp
142
32.78169
99
0.647727
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,043
ussoldierimpl.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/ussoldierimpl.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "ussoldierimpl.h" #include "version.h" #include <array> namespace game::TUsSoldierImplApi { // clang-format off static std::array<IUsSoldierVftable*, 4> vftables = {{ // Akella (IUsSoldierVftable*)0x6ed164, // Russobit (IUsSoldierVftable*)0x6ed164, // Gog (IUsSoldierVftable*)0x6eb104, // Scenario Editor (IUsSoldierVftable*)0x5e12f4, }}; // clang-format on const IUsSoldierVftable* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::TUsSoldierImplApi
1,356
C++
.cpp
39
32.282051
72
0.749238
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,044
menurandomscenario.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/menurandomscenario.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "menurandomscenario.h" #include "autodialog.h" #include "button.h" #include "dialoginterf.h" #include "dynamiccast.h" #include "editboxinterf.h" #include "exceptions.h" #include "generationresultinterf.h" #include "globaldata.h" #include "image2outline.h" #include "listbox.h" #include "log.h" #include "mapgenerator.h" #include "maptemplatereader.h" #include "mempool.h" #include "menuphase.h" #include "multilayerimg.h" #include "nativegameinfo.h" #include "scenariotemplates.h" #include "spinbuttoninterf.h" #include "stringarray.h" #include "textboxinterf.h" #include "textids.h" #include "utils.h" #include "waitgenerationinterf.h" #include <chrono> #include <fmt/format.h> #include <set> #include <sol/sol.hpp> namespace hooks { static void __fastcall buttonGenerateHandler(CMenuRandomScenario* thisptr, int /*%edx*/); static const char templatesListName[] = "TLBOX_TEMPLATES"; static const char sizeSpinName[] = "SPIN_SIZE"; static const char forestSpinName[] = "SPIN_FOREST"; static const char roadsSpinName[] = "SPIN_ROADS"; static const char goldSpinName[] = "SPIN_GOLD"; static const char manaSpinName[] = "SPIN_MANA"; static const char descTextName[] = "TXT_DESC"; static const char btnRaceName[] = "BTN_RACE_"; static const int forestSpinStep{5}; static const int roadsSpinStep{5}; static const int goldSpinStep{100}; static const int manaSpinStep{50}; static game::RttiInfo<game::CInterfaceVftable> menuRttiInfo; static game::CInterfaceVftable::Destructor menuBaseDtor{nullptr}; static std::unique_ptr<NativeGameInfo> gameInfo; /** Maximum number of attempts to generate scenario map. */ static constexpr const std::uint32_t generationAttemptsMax{50}; static const char* getRaceImage(rsg::RaceType race) { switch (race) { case rsg::RaceType::Human: return "GOD_EMPIRE"; case rsg::RaceType::Dwarf: return "GOD_CLANS"; case rsg::RaceType::Undead: return "GOD_UNDEAD"; case rsg::RaceType::Heretic: return "GOD_LEGIONS"; case rsg::RaceType::Elf: return "GOD_ELVES"; default: case rsg::RaceType::Neutral: case rsg::RaceType::Random: return "GOD_RANDOM"; } } static int raceToImageIndex(rsg::RaceType race) { switch (race) { case rsg::RaceType::Human: return 1; case rsg::RaceType::Dwarf: return 2; case rsg::RaceType::Undead: return 3; case rsg::RaceType::Heretic: return 4; case rsg::RaceType::Elf: return 5; default: case rsg::RaceType::Neutral: case rsg::RaceType::Random: return 0; } } static rsg::RaceType imageIndexToRace(int index) { switch (index) { case 1: return rsg::RaceType::Human; case 2: return rsg::RaceType::Dwarf; case 3: return rsg::RaceType::Undead; case 4: return rsg::RaceType::Heretic; case 5: return rsg::RaceType::Elf; default: case 0: return rsg::RaceType::Random; } } static int spinSizeOptionToScenarioSize(const game::CSpinButtonInterf* spinButton, int sizeMin, int sizeMax) { const int size{sizeMin + spinButton->data->selectedOption * 24}; return std::clamp(size, sizeMin, sizeMax); } static void raceIndicesToRaces(std::vector<rsg::RaceType>& races, const CMenuRandomScenario::RaceIndices& indices) { for (int i = 0; i < 4; ++i) { const auto& pair{indices[i]}; const game::CButtonInterf* raceButton{pair.first}; if (!raceButton->vftable->isEnabled(raceButton)) { // Stop processing on first disabled button, // it means current and later race indices are not used return; } races.push_back(imageIndexToRace(pair.second)); } } static bool isRoomAndPlayerNamesValid(CMenuRandomScenario* menu) { using namespace game; const auto& dialogApi{CDialogInterfApi::get()}; CDialogInterf* dialog{CMenuBaseApi::get().getDialogInterface(menu)}; if (dialogApi.findControl(dialog, "EDIT_GAME")) { CEditBoxInterf* editGame{dialogApi.findEditBox(dialog, "EDIT_GAME")}; if (!editGame || !std::strlen(editGame->data->editBoxData.inputString.string)) { return false; } } if (dialogApi.findControl(dialog, "EDIT_NAME")) { CEditBoxInterf* editName{dialogApi.findEditBox(dialog, "EDIT_NAME")}; if (!editName || !std::strlen(editName->data->editBoxData.inputString.string)) { return false; } } return true; } static rsg::MapGenOptions createGeneratorOptions(const rsg::MapTemplate& mapTemplate, std::time_t seed) { const auto& settings{mapTemplate.settings}; const std::string seedString{std::to_string(seed)}; rsg::MapGenOptions options; options.mapTemplate = &mapTemplate; options.size = settings.size; options.name = std::string{"Random scenario "} + seedString; auto description{getInterfaceText(textIds().rsg.description.c_str())}; if (!description.empty()) { replace(description, "%TMPL%", settings.name); replace(description, "%SEED%", seedString); replace(description, "%GOLD%", std::to_string(settings.startingGold)); replace(description, "%ROADS%", std::to_string(settings.roads)); replace(description, "%FOREST%", std::to_string(settings.forest)); options.description = std::move(description); } else { options.description = fmt::format("Random scenario based on template '{:s}'. " "Seed: {:d}. " "Starting gold: {:d}. " "Roads: {:d}%. " "Forest: {:d}%.", settings.name, seed, settings.startingGold, settings.roads, settings.forest); } return options; } static void setupSpinButtonOptions(game::CSpinButtonInterf* spinButton, int first, int last, int step, const char* suffix = nullptr) { if (first > last) { return; } const int count = (last - first) / step; if (count <= 0) { return; } using namespace game; const auto& string{StringApi::get()}; const auto& stringArray{StringArrayApi::get()}; StringArray options{}; stringArray.reserve(&options, static_cast<const unsigned int>(count)); for (int i = first; i <= last; i += step) { char buffer[50] = {0}; std::snprintf(buffer, sizeof(buffer) - 1, "%d%s", i, (suffix ? suffix : "")); String str; string.initFromString(&str, buffer); stringArray.pushBack(&options, &str); string.free(&str); } CSpinButtonInterfApi::get().setOptions(spinButton, &options); stringArray.destructor(&options); } static void setupSizeSpinOptions(game::CSpinButtonInterf* spinButton, int sizeMin, int sizeMax) { if (sizeMin > sizeMax) { return; } constexpr int scenarioSizeStep{24}; const int count = 1 + (sizeMax - sizeMin) / scenarioSizeStep; using namespace game; const auto& string{StringApi::get()}; const auto& stringArray{StringArrayApi::get()}; StringArray options{}; stringArray.reserve(&options, static_cast<const unsigned int>(count)); for (int i = 0; i < count; ++i) { const int size = sizeMin + 24 * i; char buffer[50] = {0}; std::snprintf(buffer, sizeof(buffer) - 1, "%d x %d", size, size); String str; string.initFromString(&str, buffer); stringArray.pushBack(&options, &str); string.free(&str); } CSpinButtonInterfApi::get().setOptions(spinButton, &options); stringArray.destructor(&options); } static game::IMqImage2* createRaceButtonSelectedImage(game::CButtonInterf* button, rsg::RaceType race) { using namespace game; const auto& allocateMem{Memory::get().allocate}; const auto& loadImage{AutoDialogApi::get().loadImage}; const CMqRect* area{button->vftable->getArea((CInterface*)button)}; const CMqPoint size{area->right - area->left, area->bottom - area->top}; Color color{0x00b2d9f5u}; auto outline{(CImage2Outline*)allocateMem(sizeof(CImage2Outline))}; CImage2OutlineApi::get().constructor(outline, &size, &color, 0xff); auto multilayerImage{(CMultiLayerImg*)allocateMem(sizeof(CMultiLayerImg))}; const auto& multilayerApi{CMultiLayerImgApi::get()}; multilayerApi.constructor(multilayerImage); multilayerApi.addImage(multilayerImage, loadImage(getRaceImage(race)), -999, -999); multilayerApi.addImage(multilayerImage, outline, -999, -999); return multilayerImage; } static void raceButtonSetImages(game::CButtonInterf* button, rsg::RaceType race) { using namespace game; const auto& loadImage{AutoDialogApi::get().loadImage}; button->vftable->setImage(button, loadImage(getRaceImage(race)), ButtonState::Normal); auto hoveredImage{createRaceButtonSelectedImage(button, race)}; button->vftable->setImage(button, hoveredImage, ButtonState::Hovered); auto clickedImage{createRaceButtonSelectedImage(button, race)}; button->vftable->setImage(button, clickedImage, ButtonState::Clicked); // Disabled race buttons are invisible button->vftable->setImage(button, nullptr, ButtonState::Disabled); } static void removePopup(CMenuRandomScenario* menu) { if (menu->popup) { hideInterface(menu->popup); menu->popup->vftable->destructor(menu->popup, 1); menu->popup = nullptr; } } /** Updates menu UI according to selected index in templates list box. */ static void updateMenuUi(CMenuRandomScenario* menu, int selectedIndex) { const auto& templates{getScenarioTemplates()}; if (selectedIndex < 0 || selectedIndex >= (int)templates.size()) { return; } using namespace game; const auto& menuBase{CMenuBaseApi::get()}; const auto& dialogApi{CDialogInterfApi::get()}; const auto& spinBox{CSpinButtonInterfApi::get()}; const auto& textBox{CTextBoxInterfApi::get()}; const auto& button{CButtonInterfApi::get()}; const auto& settings{templates[selectedIndex].settings}; CDialogInterf* dialog{menuBase.getDialogInterface(menu)}; CSpinButtonInterf* forestSpin{dialogApi.findSpinButton(dialog, forestSpinName)}; if (forestSpin) { spinBox.setSelectedOption(forestSpin, settings.forest / forestSpinStep); } CSpinButtonInterf* roadsSpin{dialogApi.findSpinButton(dialog, roadsSpinName)}; if (roadsSpin) { spinBox.setSelectedOption(roadsSpin, settings.roads / roadsSpinStep); } CSpinButtonInterf* goldSpin{dialogApi.findSpinButton(dialog, goldSpinName)}; if (goldSpin) { spinBox.setSelectedOption(goldSpin, settings.startingGold / goldSpinStep); } CSpinButtonInterf* manaSpin{dialogApi.findSpinButton(dialog, manaSpinName)}; if (manaSpin) { spinBox.setSelectedOption(manaSpin, settings.startingNativeMana / manaSpinStep); } CTextBoxInterf* descText{dialogApi.findTextBox(dialog, descTextName)}; if (descText) { textBox.setString(descText, settings.description.c_str()); } CSpinButtonInterf* sizeSpin{dialogApi.findSpinButton(dialog, sizeSpinName)}; if (sizeSpin) { setupSizeSpinOptions(sizeSpin, settings.sizeMin, settings.sizeMax); // Select smallest scenario size by default CSpinButtonInterfApi::get().setSelectedOption(sizeSpin, 0); } if (dialogApi.findControl(dialog, "EDIT_GAME")) { CEditBoxInterf* editGame{dialogApi.findEditBox(dialog, "EDIT_GAME")}; CEditBoxInterfApi::get().setString(editGame, settings.name.c_str()); } // Setup initial race buttons state: random race image and index const rsg::RaceType race{rsg::RaceType::Random}; for (int i = 0; i < 4; ++i) { auto& pair{menu->raceIndices[i]}; CButtonInterf* raceButton{pair.first}; raceButtonSetImages(raceButton, race); // Disable buttons of unused race slots raceButton->vftable->setEnabled(raceButton, i < settings.maxPlayers); int& index{pair.second}; index = raceToImageIndex(race); } } static void __fastcall menuRandomScenarioDtor(CMenuRandomScenario* menu, int /*%edx*/, char flags) { logDebug("mss32Proxy.log", "CMenuRandomScenario d-tor called"); menu->~CMenuRandomScenario(); if (menuBaseDtor) { logDebug("mss32Proxy.log", "CMenuRandomScenario d-tor calls CMenuBase d-tor"); // This will properly destroy base class and free memory menuBaseDtor(menu, flags); } } static void __fastcall listBoxDisplayHandler(CMenuRandomScenario* thisptr, int /*%edx*/, game::String* string, bool, int selectedIndex) { const auto& templates{getScenarioTemplates()}; if (selectedIndex < 0 || selectedIndex >= (int)templates.size()) { return; } const char* templateName{templates[selectedIndex].settings.name.c_str()}; game::StringApi::get().initFromString(string, templateName); } static void __fastcall listBoxUpdateHandler(CMenuRandomScenario* thisptr, int /*%edx*/, int selectedIndex) { updateMenuUi(thisptr, selectedIndex); } /** * Changes index associated with race button depending on other race button indices. * Don't allow to select duplicates of playable races, * only random race can be selected multiple times. */ static void raceButtonHandler(CMenuRandomScenario* thisptr, game::CButtonInterf* button) { if (!button) { return; } auto& raceIndices{thisptr->raceIndices}; auto it{std::find_if(raceIndices.begin(), raceIndices.end(), [button](const auto& pair) { return pair.first == button; })}; if (it == raceIndices.end()) { return; } std::set<int> possibleIndices{raceToImageIndex(rsg::RaceType::Random), raceToImageIndex(rsg::RaceType::Human), raceToImageIndex(rsg::RaceType::Dwarf), raceToImageIndex(rsg::RaceType::Undead), raceToImageIndex(rsg::RaceType::Heretic), raceToImageIndex(rsg::RaceType::Elf)}; for (const auto& [raceButton, index] : raceIndices) { possibleIndices.erase(index); } const int currentIndex{it->second}; int nextIndex{raceToImageIndex(rsg::RaceType::Random)}; // Find possible index that is greater than current one auto greaterIt{possibleIndices.upper_bound(currentIndex)}; if (greaterIt != possibleIndices.end()) { // Found possible index that belongs to playable race, use it nextIndex = *greaterIt; } // Update button images and index const rsg::RaceType nextRace{imageIndexToRace(nextIndex)}; raceButtonSetImages(button, nextRace); it->second = nextIndex; } static void __fastcall button1Handler(CMenuRandomScenario* thisptr, int /*%edx*/) { raceButtonHandler(thisptr, thisptr->raceIndices[0].first); } static void __fastcall button2Handler(CMenuRandomScenario* thisptr, int /*%edx*/) { raceButtonHandler(thisptr, thisptr->raceIndices[1].first); } static void __fastcall button3Handler(CMenuRandomScenario* thisptr, int /*%edx*/) { raceButtonHandler(thisptr, thisptr->raceIndices[2].first); } static void __fastcall button4Handler(CMenuRandomScenario* thisptr, int /*%edx*/) { raceButtonHandler(thisptr, thisptr->raceIndices[3].first); } static void generateScenario(CMenuRandomScenario* menu, std::time_t seed) { menu->generationStatus = GenerationStatus::InProcess; using clock = std::chrono::high_resolution_clock; using ms = std::chrono::milliseconds; const auto start{clock::now()}; // Make sure we use different seed for each attempt. // Do not use std::time() for seed generation // because single generation attempt could finish faster than second passes for (std::uint32_t attempt = 0; attempt < generationAttemptsMax; ++attempt, ++seed) { try { // TODO: rework MapGenOptions, pass name and description only at serialization step // Use only necessary options (size, races, seed), or maybe template itself! // This will help with scenario loading auto options{createGeneratorOptions(menu->scenarioTemplate, seed)}; rsg::MapGenerator generator{options, seed}; // Check for cancel before and after generation because its the longest part if (menu->cancelGeneration) { menu->generationStatus = GenerationStatus::Canceled; return; } const auto beforeGeneration{clock::now()}; rsg::MapPtr scenario{generator.generate()}; if (menu->cancelGeneration) { menu->generationStatus = GenerationStatus::Canceled; return; } // Successfully generated, save results menu->scenario = std::move(scenario); menu->generator = std::make_unique<rsg::MapGenerator>(std::move(generator)); const auto end{clock::now()}; const auto genTime = std::chrono::duration_cast<ms>(end - beforeGeneration); const auto total = std::chrono::duration_cast<ms>(end - start); logDebug("mss32Proxy.log", fmt::format("Random scenario generation done in {:d} ms. " "Made {:d} attempts, {:d} ms total.", genTime.count(), attempt + 1, total.count())); // Report success only after saving results menu->generationStatus = GenerationStatus::Done; return; } catch (const rsg::LackOfSpaceException&) { // Try to generate again with a new seed continue; } catch (const std::exception& e) { // Critical error, abort generation logError("mssProxyError.log", e.what()); menu->generationStatus = GenerationStatus::Error; return; } } menu->generationStatus = GenerationStatus::LimitExceeded; } static void onGenerationResultAccepted(CMenuRandomScenario* menu) { // Player is satisfied with generation results, start scenario removePopup(menu); if (menu->startScenario) { menu->startScenario(menu); } } static void onGenerationResultRejected(CMenuRandomScenario* menu) { // Player rejected generation results, generate again menu->scenario.reset(nullptr); menu->generator.reset(nullptr); removePopup(menu); buttonGenerateHandler(menu, 0); } static void onGenerationResultCanceled(CMenuRandomScenario* menu) { // Player decided return back to random scenario menu menu->scenario.reset(nullptr); menu->generator.reset(nullptr); removePopup(menu); } static void __fastcall waitGenerationResults(CMenuRandomScenario* menu, int /*%edx*/) { const auto status{menu->generationStatus}; if (status == GenerationStatus::NotStarted || status == GenerationStatus::InProcess) { return; } // Disable event first so we don't handle it twice game::UiEventApi::get().destructor(&menu->uiEvent); // Make sure generator thread completely finished if (menu->generatorThread.joinable()) { menu->generatorThread.join(); } removePopup(menu); if (status == GenerationStatus::Done) { if (!menu->scenario) { // This should never happen showMessageBox("BUG!\nGeneration completed, but no scenario was created"); return; } menu->popup = createGenerationResultInterf(menu, onGenerationResultAccepted, onGenerationResultRejected, onGenerationResultCanceled); showInterface(menu->popup); return; } if (status == GenerationStatus::Error) { auto message{getInterfaceText(textIds().rsg.generationError.c_str())}; if (message.empty()) { message = "Error during random scenario map generation.\n" "See mssProxyError.log for details"; } showMessageBox(message); return; } if (status == GenerationStatus::LimitExceeded) { auto message{getInterfaceText(textIds().rsg.limitExceeded.c_str())}; if (!message.empty()) { replace(message, "%NUM%", std::to_string(generationAttemptsMax)); } else { message = fmt::format("Could not generate scenario map after {:d} attempts.\n" "Please, adjust template contents or settings", generationAttemptsMax); } showMessageBox(message); return; } } static void onGenerationCanceled(CMenuRandomScenario* menu) { game::CPopupDialogInterf* popup{menu->popup}; if (!popup) { return; } // Remove cancel button so player won't click it twice while waiting for generator thread game::CDialogInterf* dialog{*popup->dialog}; game::CDialogInterfApi::get().hideControl(dialog, "BTN_CANCEL"); menu->cancelGeneration = true; } static void __fastcall buttonGenerateHandler(CMenuRandomScenario* thisptr, int /*%edx*/) { using namespace game; const auto& menuBase{CMenuBaseApi::get()}; const auto& dialogApi{CDialogInterfApi::get()}; CDialogInterf* dialog{menuBase.getDialogInterface(thisptr)}; CListBoxInterf* templatesList{dialogApi.findListBox(dialog, templatesListName)}; if (!templatesList) { return; } const CSpinButtonInterf* sizeSpin{dialogApi.findSpinButton(dialog, sizeSpinName)}; const CSpinButtonInterf* forestSpin{dialogApi.findSpinButton(dialog, forestSpinName)}; const CSpinButtonInterf* roadsSpin{dialogApi.findSpinButton(dialog, roadsSpinName)}; const CSpinButtonInterf* goldSpin{dialogApi.findSpinButton(dialog, goldSpinName)}; const CSpinButtonInterf* manaSpin{dialogApi.findSpinButton(dialog, manaSpinName)}; if (!sizeSpin || !forestSpin || !roadsSpin || !goldSpin || !manaSpin) { return; } const int selectedIndex{CListBoxInterfApi::get().selectedIndex(templatesList)}; const auto& templates{getScenarioTemplates()}; if (selectedIndex < 0 || selectedIndex >= (int)templates.size()) { return; } if (!isRoomAndPlayerNamesValid(thisptr)) { // Please enter valid game and player names showMessageBox(getInterfaceText("X005ta0867")); return; } // Load and set game info the first time player generates scenario if (!gameInfo) { try { gameInfo = std::make_unique<NativeGameInfo>(gameFolder()); rsg::setGameInfo(gameInfo.get()); } catch (const std::exception&) { auto message{getInterfaceText(textIds().rsg.wrongGameData.c_str())}; if (message.empty()) { message = "Could not read game data needed for scenario generator.\n" "See mssProxyError.log for details"; } showMessageBox(message); return; } } try { thisptr->scenarioTemplate = rsg::MapTemplate(); auto& settings{thisptr->scenarioTemplate.settings}; // Make sure we start with a fresh settings settings = templates[selectedIndex].settings; // Update settings using player choices in UI settings.size = spinSizeOptionToScenarioSize(sizeSpin, settings.sizeMin, settings.sizeMax); raceIndicesToRaces(settings.races, thisptr->raceIndices); settings.forest = forestSpin->data->selectedOption * forestSpinStep; settings.roads = roadsSpin->data->selectedOption * roadsSpinStep; settings.startingGold = goldSpin->data->selectedOption * goldSpinStep; settings.startingNativeMana = manaSpin->data->selectedOption * manaSpinStep; rsg::RandomGenerator rnd; std::time_t seed{std::time(nullptr)}; rnd.setSeed(static_cast<std::size_t>(seed)); // Roll actual races instead of random settings.replaceRandomRaces(rnd); // TODO: handle this in a better way sol::state lua; rsg::bindLuaApi(lua); rsg::readTemplateSettings(templates[selectedIndex].filename, lua); // Create template contents depending on size and races rsg::readTemplateContents(thisptr->scenarioTemplate, lua); thisptr->popup = createWaitGenerationInterf(thisptr, onGenerationCanceled); showInterface(thisptr->popup); thisptr->generationStatus = GenerationStatus::NotStarted; thisptr->cancelGeneration = false; createTimerEvent(&thisptr->uiEvent, thisptr, waitGenerationResults, 50); // Start generation in another thread and wait until its done thisptr->generatorThread = std::thread( [thisptr, seed]() { generateScenario(thisptr, seed); }); } catch (const std::exception& e) { logError("mssProxyError.log", e.what()); showMessageBox(e.what()); return; } } static void setupMenuUi(CMenuRandomScenario* menu, const char* dialogName) { using namespace game; const auto& menuBase{CMenuBaseApi::get()}; const auto& dialogApi{CDialogInterfApi::get()}; const auto freeFunctor{SmartPointerApi::get().createOrFreeNoDtor}; CDialogInterf* dialog{menuBase.getDialogInterface(menu)}; SmartPointer functor; menuBase.createButtonFunctor(&functor, 0, menu, &menuBase.buttonBackCallback); const auto& button{CButtonInterfApi::get()}; button.assignFunctor(dialog, "BTN_BACK", dialogName, &functor, 0); freeFunctor(&functor, nullptr); using ButtonCallback = CMenuBaseApi::Api::ButtonCallback; auto buttonCallback = (ButtonCallback)buttonGenerateHandler; menuBase.createButtonFunctor(&functor, 0, menu, &buttonCallback); button.assignFunctor(dialog, "BTN_GENERATE", dialogName, &functor, 0); freeFunctor(&functor, nullptr); // Create spin button options, template selection will only change currently selected option CSpinButtonInterf* forestSpin{dialogApi.findSpinButton(dialog, forestSpinName)}; if (forestSpin) { setupSpinButtonOptions(forestSpin, 0, 100, forestSpinStep, "%"); } CSpinButtonInterf* roadsSpin{dialogApi.findSpinButton(dialog, roadsSpinName)}; if (roadsSpin) { setupSpinButtonOptions(roadsSpin, 0, 100, roadsSpinStep, "%"); } CSpinButtonInterf* goldSpin{dialogApi.findSpinButton(dialog, goldSpinName)}; if (goldSpin) { setupSpinButtonOptions(goldSpin, 0, 9999, goldSpinStep); } CSpinButtonInterf* manaSpin{dialogApi.findSpinButton(dialog, manaSpinName)}; if (manaSpin) { setupSpinButtonOptions(manaSpin, 0, 9999, manaSpinStep); } // Cache race buttons, assign initial indices and setup callbacks // clang-format off std::array<ButtonCallback, 4> buttonCallbacks{{ (ButtonCallback)button1Handler, (ButtonCallback)button2Handler, (ButtonCallback)button3Handler, (ButtonCallback)button4Handler }}; // clang-format on for (int i = 0; i < 4; ++i) { char name[50] = {0}; std::snprintf(name, sizeof(name) - 1, "%s%d", btnRaceName, i + 1); CButtonInterf* raceButton{dialogApi.findButton(dialog, name)}; if (!raceButton) { continue; } // Cache button and make sure we start with random race index menu->raceIndices[i] = {raceButton, raceToImageIndex(rsg::RaceType::Random)}; menuBase.createButtonFunctor(&functor, 0, menu, &buttonCallbacks[i]); button.assignFunctor(dialog, name, dialogName, &functor, 0); freeFunctor(&functor, nullptr); } const auto& listBox{CListBoxInterfApi::get()}; CListBoxInterf* templatesList{dialogApi.findListBox(dialog, templatesListName)}; if (templatesList) { using ListBoxDisplayCallback = CMenuBaseApi::Api::ListBoxDisplayTextCallback; ListBoxDisplayCallback displayCallback{}; // Show template names as list box contents displayCallback.callback = (ListBoxDisplayCallback::Callback)listBoxDisplayHandler; menuBase.createListBoxDisplayTextFunctor(&functor, 0, menu, &displayCallback); listBox.assignDisplayTextFunctor(dialog, templatesListName, dialogName, &functor, false); freeFunctor(&functor, nullptr); using Callback = CMenuBaseApi::Api::ListBoxCallback; // Update UI each time template changes Callback callback = (Callback)listBoxUpdateHandler; menuBase.createListBoxFunctor(&functor, 0, menu, &callback); listBox.assignFunctor(dialog, templatesListName, dialogName, &functor); freeFunctor(&functor, nullptr); listBox.setElementsTotal(templatesList, (int)getScenarioTemplates().size()); updateMenuUi(menu, listBox.selectedIndex(templatesList)); } } static void menuRandomScenarioCtor(CMenuRandomScenario* menu, game::CMenuPhase* menuPhase, const char* dialogName) { using namespace game; logDebug("mss32Proxy.log", "CMenuRandomScenario c-tor called"); const auto& menuBase{CMenuBaseApi::get()}; menuBase.constructor(menu, menuPhase); CInterfaceVftable* vftable = &menuRttiInfo.vftable; static bool firstTime{true}; if (firstTime) { firstTime = false; replaceRttiInfo(menuRttiInfo, menu->vftable); // Remember base class destructor menuBaseDtor = menu->vftable->destructor; // Make sure our vftable uses our own destructor vftable->destructor = (CInterfaceVftable::Destructor)&menuRandomScenarioDtor; } // Use our vftable menu->vftable = vftable; menuBase.createMenu(menu, dialogName); setupMenuUi(menu, dialogName); // TODO: show additional debug UI when debug mode is enabled } CMenuRandomScenario::CMenuRandomScenario(game::CMenuPhase* menuPhase, StartScenario startScenario, const char* dialogName) : startScenario{startScenario} { menuRandomScenarioCtor(this, menuPhase, dialogName); } CMenuRandomScenario::~CMenuRandomScenario() { if (generatorThread.joinable()) { generatorThread.join(); } if (scenario) { scenario.reset(nullptr); } if (generator) { generator.reset(nullptr); } game::UiEventApi::get().destructor(&uiEvent); removePopup(this); } void prepareToStartRandomScenario(CMenuRandomScenario* menu, bool networkGame) { const auto scenarioFilePath{exportsFolder() / "Random scenario.sg"}; // Serialize scenario so it can be read from disk later by game menu->scenario->serialize(scenarioFilePath); using namespace game; const auto& menuPhaseApi{CMenuPhaseApi::get()}; CMenuPhase* menuPhase{menu->menuBaseData->menuPhase}; // Set special (skirmish) campaign id CMidgardID campaignId; CMidgardIDApi::get().fromString(&campaignId, "C000CC0001"); menuPhaseApi.setCampaignId(menuPhase, &campaignId); const rsg::MapHeader* header{menu->scenario.get()}; menuPhaseApi.setScenarioFilePath(menuPhase, scenarioFilePath.string().c_str()); menuPhaseApi.setScenarioName(menuPhase, header->name.c_str()); menuPhaseApi.setScenarioDescription(menuPhase, header->description.c_str()); const auto& settings{menu->scenarioTemplate.settings}; const auto& listApi{RaceCategoryListApi::get()}; const GlobalData* globalData{*GlobalDataApi::get().getGlobalData()}; auto racesTable{globalData->raceCategories}; auto& findRaceById{LRaceCategoryTableApi::get().findCategoryById}; CMenuPhaseData* data = menuPhase->data; RaceCategoryList* races{&data->races}; listApi.freeNodes(races); // Template settings contain only playable races at this point for (const auto& race : settings.races) { const int raceId{static_cast<int>(race)}; LRaceCategory category{}; findRaceById(racesTable, &category, &raceId); listApi.add(races, &category); } data->networkGame = networkGame; data->unknown8 = true; data->suggestedLevel = 1; data->maxPlayers = static_cast<int>(settings.races.size()); } } // namespace hooks
34,001
C++
.cpp
789
35.39924
99
0.671998
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,045
idlistutils.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/idlistutils.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "idlistutils.h" namespace hooks { bool removeIdFromList(game::IdList& list, const game::CMidgardID* id) { using namespace game; const auto& listApi = IdListApi::get(); IdListIterator it; listApi.find(&it, list.begin(), list.end(), id); if (it != list.end()) { listApi.erase(&list, it); return true; } return false; } bool addUniqueIdToList(game::IdList& list, const game::CMidgardID* id) { using namespace game; const auto& listApi = IdListApi::get(); IdListIterator it; listApi.find(&it, list.begin(), list.end(), id); if (it == list.end()) { listApi.pushBack(&list, id); return true; } return false; } } // namespace hooks
1,546
C++
.cpp
45
30.777778
72
0.70604
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,046
midscenvariables.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/midscenvariables.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "midscenvariables.h" #include "version.h" #include <array> namespace game::CMidScenVariablesApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::FindById)0x5fe73d, }, // Russobit Api{ (Api::FindById)0x5fe73d, }, // Gog Api{ (Api::FindById)0x5fd39d, }, // Scenario Editor Api{ (Api::FindById)0x4e677a, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMidScenVariablesApi
1,387
C++
.cpp
47
26.255319
72
0.707116
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,047
attackclasscat.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/attackclasscat.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attackclasscat.h" #include "version.h" #include <array> namespace game { namespace AttackClassCategories { // clang-format off static std::array<Categories, 4> categories = {{ // Akella Categories{ (LAttackClass*)0x8394d0, (LAttackClass*)0x839590, (LAttackClass*)0x839470, (LAttackClass*)0x8395c8, (LAttackClass*)0x8394e0, (LAttackClass*)0x839480, (LAttackClass*)0x839510, (LAttackClass*)0x8394f0, (LAttackClass*)0x839560, (LAttackClass*)0x839540, (LAttackClass*)0x8395a0, (LAttackClass*)0x839490, (LAttackClass*)0x839500, (LAttackClass*)0x839520, (LAttackClass*)0x839550, (LAttackClass*)0x8394a0, (LAttackClass*)0x839580, (LAttackClass*)0x839530, (LAttackClass*)0x8395b8, (LAttackClass*)0x8394b0, (LAttackClass*)0x839570, (LAttackClass*)0x8394c0, (LAttackClass*)0x8395d8 }, // Russobit Categories{ (LAttackClass*)0x8394d0, (LAttackClass*)0x839590, (LAttackClass*)0x839470, (LAttackClass*)0x8395c8, (LAttackClass*)0x8394e0, (LAttackClass*)0x839480, (LAttackClass*)0x839510, (LAttackClass*)0x8394f0, (LAttackClass*)0x839560, (LAttackClass*)0x839540, (LAttackClass*)0x8395a0, (LAttackClass*)0x839490, (LAttackClass*)0x839500, (LAttackClass*)0x839520, (LAttackClass*)0x839550, (LAttackClass*)0x8394a0, (LAttackClass*)0x839580, (LAttackClass*)0x839530, (LAttackClass*)0x8395b8, (LAttackClass*)0x8394b0, (LAttackClass*)0x839570, (LAttackClass*)0x8394c0, (LAttackClass*)0x8395d8 }, // Gog Categories{ (LAttackClass*)0x837480, (LAttackClass*)0x837540, (LAttackClass*)0x837420, (LAttackClass*)0x837578, (LAttackClass*)0x837490, (LAttackClass*)0x837430, (LAttackClass*)0x8374c0, (LAttackClass*)0x8374a0, (LAttackClass*)0x837510, (LAttackClass*)0x8374f0, (LAttackClass*)0x837550, (LAttackClass*)0x837440, (LAttackClass*)0x8374b0, (LAttackClass*)0x8374d0, (LAttackClass*)0x837500, (LAttackClass*)0x837450, (LAttackClass*)0x837530, (LAttackClass*)0x8374e0, (LAttackClass*)0x837568, (LAttackClass*)0x837460, (LAttackClass*)0x837520, (LAttackClass*)0x837470, (LAttackClass*)0x837588 }, // Scenario Editor Categories{ (LAttackClass*)0x665728, (LAttackClass*)0x6657e8, (LAttackClass*)0x6656c8, (LAttackClass*)0x665820, (LAttackClass*)0x665738, (LAttackClass*)0x6656d8, (LAttackClass*)0x665768, (LAttackClass*)0x665748, (LAttackClass*)0x6657b8, (LAttackClass*)0x665798, (LAttackClass*)0x6657f8, (LAttackClass*)0x6656e8, (LAttackClass*)0x665758, (LAttackClass*)0x665778, (LAttackClass*)0x6657a8, (LAttackClass*)0x6656f8, (LAttackClass*)0x6657d8, (LAttackClass*)0x665788, (LAttackClass*)0x665810, (LAttackClass*)0x665708, (LAttackClass*)0x6657c8, (LAttackClass*)0x665718, (LAttackClass*)0x665830 } }}; static std::array<const void*, 4> vftables = {{ // Akella (const void*)0x6ceadc, // Russobit (const void*)0x6ceadc, // Gog (const void*)0x6cca7c, // Scenario Editor (const void*)0x5d295c }}; // clang-format on Categories& get() { return categories[static_cast<int>(hooks::gameVersion())]; } const void* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace AttackClassCategories namespace LAttackClassTableApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x585a1a, (Api::Init)0x585d36, (Api::ReadCategory)0x585dae, (Api::InitDone)0x585cf1, (Api::FindCategoryById)0x40adc7, }, // Russobit Api{ (Api::Constructor)0x585a1a, (Api::Init)0x585d36, (Api::ReadCategory)0x585dae, (Api::InitDone)0x585cf1, (Api::FindCategoryById)0x40adc7, }, // Gog Api{ (Api::Constructor)0x584bcd, (Api::Init)0x584ee9, (Api::ReadCategory)0x584f61, (Api::InitDone)0x584ea4, (Api::FindCategoryById)0x40aa53, }, // Scenario Editor Api{ (Api::Constructor)0x536288, (Api::Init)0x5365a4, (Api::ReadCategory)0x53661c, (Api::InitDone)0x53655f, (Api::FindCategoryById)0x4f2473, } }}; static std::array<const void*, 4> vftables = {{ // Akella (const void*)0x6e9eb4, // Russobit (const void*)0x6e9eb4, // Gog (const void*)0x6e7e54, // Scenario Editor (const void*)0x5df10c }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } const void* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace LAttackClassTableApi } // namespace game
6,045
C++
.cpp
207
22.874396
72
0.648867
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,048
roomscallback.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/roomscallback.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "roomscallback.h" #include "log.h" #include "netcustomplayer.h" #include "netcustomservice.h" #include <RoomsErrorCodes.h> #include <atomic> #include <fmt/format.h> namespace hooks { std::atomic_bool hostAddressSet{false}; SLNet::SystemAddress lobbyAddressToServerPlayer(const SLNet::SystemAddress& lobbyAddress) { auto addressString{lobbyAddress.ToString(false)}; auto serverAddress{SLNet::SystemAddress(addressString, CNetCustomPlayer::serverPort)}; logDebug("lobby.log", fmt::format("lobbyAddress: '{:s}', serverAddress '{:s}'", addressString, serverAddress.ToString())); return serverAddress; } void RoomsLoggingCallback::CreateRoom_Callback(const SLNet::SystemAddress& senderAddress, SLNet::CreateRoom_Func* callResult) { if (callResult->resultCode != SLNet::REC_SUCCESS) { logDebug("roomsCallbacks.log", fmt::format("Could not create a room. Reason: {:s}", SLNet::RoomsErrorCodeDescription::ToEnglish(callResult->resultCode))); return; } auto cell{callResult->roomDescriptor.GetProperty(DefaultRoomColumns::TC_ROOM_NAME)}; if (!cell) { logDebug("roomsCallbacks.log", fmt::format("Count not get room name cell")); return; } auto name{cell->c}; logDebug("roomsCallbacks.log", fmt::format("Player {:s} created room {:s}", callResult->userName.C_String(), name)); auto service = getNetService(); if (service) { logDebug("roomsCallbacks.log", "I am the room moderator, set my own address as a host."); // Get our own system address, convert it to server-player address service->roomOwnerAddress = lobbyAddressToServerPlayer( service->lobbyPeer.peer->GetMyBoundAddress()); hostAddressSet = true; } } void RoomsLoggingCallback::EnterRoom_Callback(const SLNet::SystemAddress& senderAddress, SLNet::EnterRoom_Func* callResult) { if (callResult->resultCode != SLNet::REC_SUCCESS) { logDebug("roomsCallbacks.log", fmt::format("Could not join room. Reason: {:s}", SLNet::RoomsErrorCodeDescription::ToEnglish(callResult->resultCode))); return; } auto& room{callResult->joinedRoomResult.roomDescriptor}; auto cell{room.GetProperty(DefaultRoomColumns::TC_ROOM_NAME)}; if (!cell) { logDebug("roomsCallbacks.log", fmt::format("Count not get room name cell")); return; } auto name{cell->c}; logDebug("roomsCallbacks.log", fmt::format("Player {:s} {:s} room {:s}", callResult->userName.C_String(), (callResult->createdRoom ? "tried to join and created new" : "joined the"), name)); auto& members = room.roomMemberList; logDebug("roomsCallbacks.log", fmt::format("Room has {:d} members", members.Size())); // remember room creator address for (unsigned int i = 0; i < members.Size(); ++i) { auto& member = members[i]; logDebug("roomsCallbacks.log", fmt::format("Check member {:d}, mode {:d}", i, (int)member.roomMemberMode)); if (member.roomMemberMode == RoomMemberMode::RMM_MODERATOR) { auto service = getNetService(); if (service) { logDebug("roomsCallbacks.log", "Found room moderator, assume its a game host."); // Get member system address, convert to server-player address service->roomOwnerAddress = lobbyAddressToServerPlayer(member.systemAddress); hostAddressSet = true; } } } } void RoomsLoggingCallback::LeaveRoom_Callback(const SLNet::SystemAddress& senderAddress, SLNet::LeaveRoom_Func* callResult) { logDebug("roomsCallbacks.log", fmt::format("Player {:s} left the room. Result {:s}", callResult->userName.C_String(), SLNet::RoomsErrorCodeDescription::ToEnglish(callResult->resultCode))); } void RoomsLoggingCallback::RoomMemberLeftRoom_Callback( const SLNet::SystemAddress& senderAddress, SLNet::RoomMemberLeftRoom_Notification* notification) { logDebug("roomsCallbacks.log", fmt::format("Notification to {:s}. {:s} has left the room", notification->recipient.C_String(), notification->roomMember.C_String())); } void RoomsLoggingCallback::RoomMemberJoinedRoom_Callback( const SLNet::SystemAddress& senderAddress, SLNet::RoomMemberJoinedRoom_Notification* notification) { logDebug("roomsCallbacks.log", fmt::format("Notification to {:s}. {:s} has joined the room", notification->recipient.C_String(), notification->joinedRoomResult->joiningMemberName.C_String())); } } // namespace hooks
5,806
C++
.cpp
124
38.459677
100
0.658661
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,049
batattackgroupupgrade.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/batattackgroupupgrade.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "batattackgroupupgrade.h" #include "version.h" #include <array> namespace game::CBatAttackGroupUpgradeApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::UpgradeGroup)0x666797, }, // Russobit Api{ (Api::UpgradeGroup)0x666797, }, // Gog Api{ (Api::UpgradeGroup)0x665217, }, // Scenario Editor Api{ }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CBatAttackGroupUpgradeApi
1,382
C++
.cpp
46
26.913043
72
0.716003
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,050
phase.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/phase.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "phase.h" #include "version.h" #include <array> namespace game::CPhaseApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::GetObjectMap)0x404f06, (Api::GetCurrentPlayerId)0x404e71, }, // Russobit Api{ (Api::GetObjectMap)0x404f06, (Api::GetCurrentPlayerId)0x404e71, }, // Gog Api{ (Api::GetObjectMap)0x404b8e, (Api::GetCurrentPlayerId)0x404af9, } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CPhaseApi
1,422
C++
.cpp
46
27.521739
72
0.71043
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,051
battleviewerinterfhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/battleviewerinterfhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "battleviewerinterfhooks.h" #include "attack.h" #include "batbigface.h" #include "batimagesloader.h" #include "battleviewerinterf.h" #include "batunitanim.h" #include "batviewer2dengine.h" #include "button.h" #include "customattacks.h" #include "customattackutils.h" #include "d2string.h" #include "dialoginterf.h" #include "game.h" #include "mempool.h" #include "middragdropinterf.h" #include "midgardobjectmap.h" #include "miditem.h" #include "midunitgroup.h" #include "musicfader.h" #include "togglebutton.h" #include "uievent.h" #include "uimanager.h" #include "unitinfolist.h" #include "unitpositionlist.h" #include "unitslotview.h" #include "unitutils.h" namespace hooks { void markAttackTarget(game::CBattleViewerInterf* viewer, const game::CMidgardID* targetId, bool targetIsAttacker, int targetPosition) { using namespace game; const auto& viewerApi = BattleViewerInterfApi::get(); const auto& rectApi = MqRectApi::get(); const auto& loaderApi = BatImagesLoaderApi::get(); const auto& engineApi = BatViewer2DEngineApi::get(); bool isUnitBig = false; bool isUnitRetreating = false; if (*targetId != emptyId) { isUnitBig = viewerApi.isUnitBig(&viewer->data->unknownUnitData, targetId); isUnitRetreating = viewerApi.isUnitRetreating(&viewer->data->unknownUnitData, targetId); } CMqRect unitRect{}; bool isUnitOnTheLeft = viewerApi.isUnitOnTheLeft(viewer, targetIsAttacker); viewerApi.getUnitRect(&unitRect, isUnitOnTheLeft ? &viewer->data->groupAreas2 : &viewer->data->groupAreas1, targetPosition, isUnitBig, isUnitRetreating); IMqImage2* image = loaderApi.loadMarkImage(viewer->data->imagesLoader, isUnitBig); if (image == nullptr) return; CMqPoint imageSize{}; image->vftable->getSize(image, &imageSize); CMqPoint unitCenter{}; rectApi.getCenter(&unitRect, &unitCenter); CMqPoint imagePosition{unitCenter.x - imageSize.x / 2, unitRect.bottom - imageSize.y / 2}; engineApi.drawTargetMark(viewer->data->batViewer2dEngine, image, &imagePosition, isUnitOnTheLeft, targetPosition); } void markAllAttackTargets(game::CBattleViewerInterf* viewer, const game::CMidUnitGroup* targetGroup, const game::UnitInfo* targetInfo, const game::UnitPositionMap* targetPositions) { using namespace game; const auto& groupApi = CMidUnitGroupApi::get(); for (const auto& position : *targetPositions) { if (position.first >= 0) { const CMidgardID* targetId = groupApi.getUnitIdByPosition(targetGroup, position.first); markAttackTarget(viewer, targetId, targetInfo->unitFlags.parts.attacker, position.first); } } } void markCustomAttackTargets(game::CBattleViewerInterf* viewer, const game::CMidgardID* targetGroupId, const game::CMidgardID* selectedUnitId, const game::UnitInfo* targetInfo, const game::IAttack* attack, bool isItemAttack, const CustomAttackReach& attackReach) { using namespace game; const auto& fn = gameFunctions(); CMidgardID unitGroupId{}; fn.getAllyOrEnemyGroupId(&unitGroupId, &viewer->data->battleMsgData, &viewer->data->unitId, true); CMidgardID attackUnitId = isItemAttack ? viewer->data->itemId : viewer->data->unitId; auto targets = getTargetsToMarkForCustomAttackReach(viewer->data->objectMap, &viewer->data->battleMsgData, attack, targetGroupId, selectedUnitId, &unitGroupId, &viewer->data->unitId, &attackUnitId, attackReach); for (const auto& target : targets) { CMidgardID targetId = target.getUnitId(); markAttackTarget(viewer, &targetId, targetInfo->unitFlags.parts.attacker, target.getPosition()); } } bool isUnitSelected(game::CBattleViewerInterf* viewer, const game::CMqPoint* mousePosition, const game::UnitInfo* targetInfo, game::CMidgardID* targetId) { using namespace game; const auto& id = CMidgardIDApi::get(); const auto& battle = BattleMsgDataApi::get(); const auto& rectApi = MqRectApi::get(); const auto& viewerApi = BattleViewerInterfApi::get(); id.validateId(targetId, targetInfo->unitId1); if (battle.getUnitStatus(&viewer->data->battleMsgData, targetId, BattleStatus::Dead) || battle.getUnitStatus(&viewer->data->battleMsgData, targetId, BattleStatus::Retreated) || battle.getUnitStatus(&viewer->data->battleMsgData, targetId, BattleStatus::Hidden)) { return false; } bool isUnitBig = viewerApi.isUnitBig(&viewer->data->unknownUnitData, targetId); bool isUnitRetreating = viewerApi.isUnitRetreating(&viewer->data->unknownUnitData, targetId); bool isUnitOnTheLeft = viewerApi.isUnitOnTheLeft(viewer, targetInfo->unitFlags.parts.attacker); CMqRect unitRect{}; viewerApi.getUnitRectPlusExtra(&unitRect, isUnitOnTheLeft ? &viewer->data->groupAreas2 : &viewer->data->groupAreas1, targetInfo->unitFlags.parts.indexInGroup, isUnitBig, isUnitRetreating); return rectApi.ptInRect(&unitRect, mousePosition); } bool markAttackTargetsForAllOrCustomAttackReach(game::CBattleViewerInterf* viewer, const game::CMidgardID* targetGroupId, const game::CMidgardID* selectedUnitId, const game::UnitInfo* targetInfo, const game::IAttack* attack, bool isBattleGoing, bool isItemAttack, const game::UnitPositionMap* targetPositions) { using namespace game; const auto& fn = gameFunctions(); const auto& mapApi = UnitPositionMapApi::get(); const auto& groupApi = CMidUnitGroupApi::get(); const auto& reaches = AttackReachCategories::get(); if (!isBattleGoing || attack == nullptr) return false; void* tmp{}; CMidUnitGroup* targetGroup = fn.getStackFortRuinGroup(tmp, viewer->data->objectMap, targetGroupId); int selectedPositionInTargetGroup = groupApi.getUnitPosition(targetGroup, selectedUnitId); if (selectedPositionInTargetGroup == -1) return false; UnitPositionPair positionPair; mapApi.findByPosition(&positionPair, targetPositions, targetInfo->unitFlags.parts.indexInGroup); if (!positionPair.second) return false; auto attackReach = attack->vftable->getAttackReach(attack); if (attackReach->id == reaches.all->id) { markAllAttackTargets(viewer, targetGroup, targetInfo, targetPositions); return true; } else { for (const auto& custom : getCustomAttacks().reaches) { if (attackReach->id == custom.reach.id) { if (!custom.markAttackTargets) break; markCustomAttackTargets(viewer, targetGroupId, selectedUnitId, targetInfo, attack, isItemAttack, custom); return true; } } } return false; } void markAttackTargets(game::CBattleViewerInterf* viewer, const game::CMidgardID* targetGroupId, const game::CMidgardID* selectedUnitId, const game::UnitInfo* targetInfo, bool setBigFace, const game::IAttack* attack, bool isBattleGoing, bool isItemAttack, const game::UnitPositionMap* targetPositions) { using namespace game; const auto& fn = gameFunctions(); const auto& viewerApi = BattleViewerInterfApi::get(); const auto& engineApi = BatViewer2DEngineApi::get(); const auto& bigFaceApi = BatBigFaceApi::get(); if (setBigFace) { CBatBigFace* bigFace = viewerApi.getBigFace(viewer); bigFaceApi.setUnitId(bigFace, selectedUnitId); } if (viewer->data2->selectedUnitId == *selectedUnitId) return; engineApi.clearTargetMarks(viewer->data->batViewer2dEngine); viewer->data2->selectedUnitId = *selectedUnitId; if (!markAttackTargetsForAllOrCustomAttackReach(viewer, targetGroupId, selectedUnitId, targetInfo, attack, isBattleGoing, isItemAttack, targetPositions)) { markAttackTarget(viewer, selectedUnitId, targetInfo->unitFlags.parts.attacker, targetInfo->unitFlags.parts.indexInGroup); } } bool markAttackTargetsIfUnitSelected(game::CBattleViewerInterf* viewer, const game::CMqPoint* mousePosition, bool setBigFace, const game::IAttack* attack, bool isBattleGoing, bool isItemAttack, const game::CMidgardID* targetGroupId, const game::UnitPositionMap* targetPositions) { using namespace game; const auto& battleApi = BattleMsgDataApi::get(); const auto& listApi = UnitInfoListApi::get(); UnitInfoList targetInfos{}; listApi.constructor(&targetInfos); battleApi.getUnitInfos(&viewer->data->battleMsgData, &targetInfos, true); listApi.sort(&targetInfos); bool result = false; for (const auto& unitInfo : targetInfos) { CMidgardID selectedUnitId{}; result = isUnitSelected(viewer, mousePosition, &unitInfo, &selectedUnitId); if (result) { markAttackTargets(viewer, targetGroupId, &selectedUnitId, &unitInfo, setBigFace, attack, isBattleGoing, isItemAttack, targetPositions); break; } } listApi.destructor(&targetInfos); return result; } bool unmarkAttackTargets(game::CBattleViewerInterf* viewer, const game::CMqPoint* mousePosition, bool setBigFace) { using namespace game; const auto& viewerApi = BattleViewerInterfApi::get(); const auto& engineApi = BatViewer2DEngineApi::get(); const auto& bigFaceApi = BatBigFaceApi::get(); engineApi.clearTargetMarks(viewer->data->batViewer2dEngine); viewer->data2->selectedUnitId = emptyId; CMidgardID selectedUnitId{}; viewerApi.getSelectedUnitId(viewerApi.isFlipped(viewer) ? viewer->data->batUnitGroup1 : viewer->data->batUnitGroup2, &selectedUnitId, mousePosition); if (selectedUnitId == emptyId) return false; if (setBigFace) { CBatBigFace* bigFace = viewerApi.getBigFace(viewer); bigFaceApi.setUnitId(bigFace, &selectedUnitId); } return true; } bool __fastcall markAttackTargetsHooked(game::CBattleViewerInterf* thisptr, int /*%edx*/, const game::CMqPoint* mousePosition, bool setBigFace) { using namespace game; const auto& fn = gameFunctions(); const auto& battle = BattleMsgDataApi::get(); if (thisptr->data->unitId == emptyId) return false; if (thisptr->dropManager.vftable->getDropSource(&thisptr->dropManager)) { if (thisptr->data->itemId == emptyId) return false; int itemIndex = battle.getLeaderEquippedBattleItemIndex(thisptr->data->objectMap, &thisptr->data->unitId, &thisptr->data->battleMsgData, &thisptr->data->itemId); auto attack = fn.getAttackById(thisptr->data->objectMap, &thisptr->data->itemId, 1, true); const auto& targetData = thisptr->data->targetData.items[itemIndex]; if (markAttackTargetsIfUnitSelected(thisptr, mousePosition, setBigFace, attack, true, true, &targetData.groupId, &targetData.unitPositions)) return true; } else { auto attack = fn.getAttackById(thisptr->data->objectMap, &thisptr->data->unitId, 1, true); const auto& targetData = thisptr->data->targetData.attack; if (markAttackTargetsIfUnitSelected(thisptr, mousePosition, setBigFace, attack, targetData.isBattleGoing, false, &targetData.groupId, &targetData.unitPositions)) return true; } return unmarkAttackTargets(thisptr, mousePosition, setBigFace); } void setTimerEvent(game::CBattleViewerInterf* viewer, game::BattleViewerInterfApi::Api::Callback callback) { using namespace game; SmartPointer functor; BattleViewerInterfApi::Api::ButtonCallback buttonCallback{callback}; BattleViewerInterfApi::get().createButtonFunctor(&functor, 0, viewer, &buttonCallback); const auto& uiManagerApi = CUIManagerApi::get(); UIManagerPtr uiManager; uiManagerApi.get(&uiManager); const auto& eventApi = UiEventApi::get(); UiEvent timerEvent; uiManagerApi.createTimerEvent(uiManager.data, &timerEvent, &functor, 5); eventApi.copy(&viewer->data2->autobattleTimerEvent, &timerEvent); eventApi.destructor(&timerEvent); SmartPointerApi::get().createOrFree((SmartPointer*)&uiManager, nullptr); SmartPointerApi::get().createOrFreeNoDtor(&functor, nullptr); } void updateForNormalAttack(game::CBattleViewerInterf* viewer) { using namespace game; const auto& fn = gameFunctions(); const auto& id = CMidgardIDApi::get(); const auto& viewerApi = BattleViewerInterfApi::get(); const auto& mapApi = UnitPositionMapApi::get(); const auto& listApi = UnitPositionListApi::get(); const auto& groupApi = CMidUnitGroupApi::get(); const auto& attackReaches = AttackReachCategories::get(); const auto& attackClasses = AttackClassCategories::get(); CMidgardID otherGroupId = invalidId; CMidgardID attackerGroupId{}; id.validateId(&attackerGroupId, viewer->data->battleMsgData.attackerGroupId); if (viewer->data->targetData.attack.groupId == attackerGroupId) { id.validateId(&otherGroupId, viewer->data->battleMsgData.defenderGroupId); } else { otherGroupId = attackerGroupId; } bool unknown = viewer->data->targetData.attack.unknown == false; viewerApi.unknownMethod4(&viewer->data->targetUnitData); void* tmp{}; auto targetGroup = fn.getStackFortRuinGroup(tmp, viewer->data->objectMap, &viewer->data->targetData.attack.groupId); auto otherGroup = fn.getStackFortRuinGroup(tmp, viewer->data->objectMap, &otherGroupId); UnitPositionMap targetPositions{}; mapApi.copyConstructor(&targetPositions, &viewer->data->targetData.attack.unitPositions); bool hasNegativePosition = mapApi.hasNegativePosition(&targetPositions); groupApi.unknownFunction(targetGroup, otherGroup, &targetPositions); UnitPositionList targetPositions2{}; listApi.constructor(&targetPositions2); viewerApi.fillTargetPositions(viewer->data->targetData.attack.unknown, &targetPositions, &targetPositions2); auto attack = fn.getAttackById(viewer->data->objectMap, &viewer->data->unitId, 1, true); auto attackClass = attack->vftable->getAttackClass(attack); viewer->data2->attackClass = *attackClass; bool isSupportAttack = fn.isSupportAttackClass(attackClass); auto attackReach = attack->vftable->getAttackReach(attack); bool isAllAttackReach = attackReach->id == attackReaches.all->id; if (isAllAttackReach) { for (auto group : {viewer->data->batUnitGroup1, viewer->data->batUnitGroup3, viewer->data->batUnitGroup2, viewer->data->batUnitGroup4}) { viewerApi.highlightGroupFrame(group, &viewer->data->targetData.attack.groupId, isSupportAttack); } } for (const auto& targetPosition : targetPositions2) { int absolutePosition; bool unknown2; CMidgardID targetUnitId = invalidId; if (targetPosition.first >= 0) { absolutePosition = targetPosition.first; unknown2 = viewer->data->targetData.attack.unknown; targetUnitId = *groupApi.getUnitIdByPosition(targetGroup, absolutePosition); } else { absolutePosition = -(targetPosition.first + 1); unknown2 = unknown; targetUnitId = *groupApi.getUnitIdByPosition(otherGroup, absolutePosition); } bool isTargetForSummonOrAttackTargetsBothGroups = hasNegativePosition; if (isTargetForSummonOrAttackTargetsBothGroups) { auto nonAltAttack = fn.getAttackById(viewer->data->objectMap, &viewer->data->unitId, 1, false); auto nonAltAttackClass = nonAltAttack->vftable->getAttackClass(nonAltAttack); isTargetForSummonOrAttackTargetsBothGroups = nonAltAttackClass->id != attackClasses.transformSelf->id; } bool isTargetForSummon = targetUnitId != viewer->data->unitId && (targetUnitId == emptyId || attackClass->id == attackClasses.summon->id); if (isTargetForSummon) { targetUnitId = emptyId; id.summonUnitIdFromPosition(&targetUnitId, absolutePosition); isTargetForSummonOrAttackTargetsBothGroups = true; if (!targetPosition.second) continue; viewerApi.unknownMethod3(unknown2 ? viewer->data->batUnitGroup1 : viewer->data->batUnitGroup2, &viewer->data->targetData.attack.groupId, absolutePosition); viewerApi.unknownMethod3(unknown2 ? viewer->data->batUnitGroup3 : viewer->data->batUnitGroup4, &viewer->data->targetData.attack.groupId, absolutePosition); } else if (targetPosition.second) { viewerApi.unknownMethod2(unknown2 ? viewer->data->batUnitGroup1 : viewer->data->batUnitGroup2, &targetUnitId, isSupportAttack); viewerApi.unknownMethod2(unknown2 ? viewer->data->batUnitGroup3 : viewer->data->batUnitGroup4, &targetUnitId, isSupportAttack); } bool canPerformAttackOnTargetOrAllAttackReach = targetPosition.second || (targetPosition.first >= 0 && isAllAttackReach); viewerApi.addTargetUnitData(viewer, targetPosition.first, &targetUnitId, unknown2, isTargetForSummonOrAttackTargetsBothGroups, isTargetForSummon, canPerformAttackOnTargetOrAllAttackReach); } if (viewerApi.isFlipped(viewer) != viewer->data->targetData.attack.unknown) viewerApi.setCheckedForRightUnitsToggleButton(viewer, viewer->data->targetData.attack.unknown); listApi.destructor(&targetPositions2); mapApi.destructor(&targetPositions); } void getMousePosition(game::CMqPoint* value) { using namespace game; const auto& uiManagerApi = CUIManagerApi::get(); const auto& smartPtrApi = SmartPointerApi::get(); UIManagerPtr uiManager; uiManagerApi.get(&uiManager); uiManagerApi.getMousePosition(uiManager.data, value); smartPtrApi.createOrFree((SmartPointer*)&uiManager, nullptr); } void __fastcall battleViewerInterfUpdateHooked(game::IBatViewer* thisptr, int /*%edx*/, const game::BattleMsgData* battleMsgData, const game::CMidgardID* unitId, const game::Set<game::BattleAction>* actions, const game::BatViewerTargetDataSet* targetData) { using namespace game; const auto& id = CMidgardIDApi::get(); const auto& battle = BattleMsgDataApi::get(); const auto& viewerApi = BattleViewerInterfApi::get(); const auto& animApi = BatUnitAnimApi::get(); const auto& dragDropApi = CDragAndDropInterfApi::get(); const auto& dialogApi = CDialogInterfApi::get(); const auto& toggleButtonApi = CToggleButtonApi::get(); const auto& bigFaceApi = BatBigFaceApi::get(); auto viewer = castBatViewerToBattleViewerInterf(thisptr); viewer->data->unknown6 = false; viewer->data->unitId = *unitId; battle.copyAssignment(&viewer->data->battleMsgData, battleMsgData); CMidgardID attackerGroupId{}; id.validateId(&attackerGroupId, viewer->data->battleMsgData.attackerGroupId); viewerApi.battleViewerTargetDataSetCtor(&viewer->data->targetData, targetData); viewerApi.battleViewerTargetDataSetSetAttacker(&viewer->data->targetData, &attackerGroupId); auto unitAnimation = *viewerApi.getUnitAnimation(viewer, unitId); animApi.update(unitAnimation, &viewer->data->battleMsgData, false); viewerApi.updateUnknown(viewer, false); viewer->data2->unknown4 = false; auto dialog = CDragAndDropInterfApi::get().getDialog(viewer); bool unknown2 = viewerApi.getUnknown2(&viewer->data->unknownUnitData, &viewer->data->unitId); bool autoBattle = unknown2 ? viewer->data2->unknown6 : viewer->data2->unknown7; if (viewer->data2->unknown8 != unknown2) { auto button = dialogApi.findToggleButton(dialog, "TOG_AUTOBATTLE"); toggleButtonApi.setChecked(button, autoBattle); viewer->data2->unknown8 = unknown2; } if (autoBattle) { setTimerEvent(viewer, viewerApi.autoBattleCallback); return; } if (viewer->data2->unknown10) { setTimerEvent(viewer, viewerApi.disableAutoBattleAndResolveCallback); return; } auto toggleRightUnits = dialogApi.findToggleButton(dialog, "TOG_RIGHTUNITS"); if (toggleRightUnits) { toggleRightUnits->vftable->setEnabled(toggleRightUnits, true); } viewer->data2->normalAttack = false; bool canUseItem = false; for (const auto& action : *actions) { switch (action) { case BattleAction::Attack: viewer->data2->normalAttack = true; break; case BattleAction::Retreat: { auto button = dialogApi.findButton(dialog, "BTN_RETREAT"); button->vftable->setEnabled(button, true); break; } case BattleAction::Wait: { auto button = dialogApi.findButton(dialog, "BTN_WAIT"); button->vftable->setEnabled(button, true); break; } case BattleAction::Defend: { auto button = dialogApi.findButton(dialog, "BTN_DEFEND"); button->vftable->setEnabled(button, true); break; } case BattleAction::UseItem: canUseItem = true; break; } } viewer->data2->unknown3 = 0; auto bigFace2 = viewerApi.getBigFace2(viewer); bigFaceApi.setUnknown(bigFace2, false); viewerApi.updateBattleItems(viewer, canUseItem); for (auto group : {viewer->data->batUnitGroup1, viewer->data->batUnitGroup3, viewer->data->batUnitGroup2, viewer->data->batUnitGroup4}) { viewerApi.unknownMethod(group, &viewer->data->unitId); } if (viewer->data2->normalAttack) updateForNormalAttack(viewer); viewerApi.unknownMethod6(viewer, false); bigFaceApi.setUnitId(bigFace2, &viewer->data->unitId); viewerApi.unknownMethod7(viewer); CMqPoint mousePosition; getMousePosition(&mousePosition); mousePosition.x -= viewer->data->dialogInterfArea.left; mousePosition.y -= viewer->data->dialogInterfArea.top; viewerApi.markAttackTargets(viewer, &mousePosition, false); viewerApi.updateCursor(viewer, &mousePosition); } void __fastcall battleViewerInterfUpdateBattleItemsHooked(game::CBattleViewerInterf* thisptr, int /*%edx*/, bool canUseItem) { using namespace game; const auto& battle = BattleMsgDataApi::get(); const auto& faderApi = CMusicFaderApi::get(); const auto& viewerApi = BattleViewerInterfApi::get(); auto fader = faderApi.get(); if (faderApi.hasEventId(fader)) faderApi.callback(fader); viewerApi.unknownMethod9(thisptr); if (!thisptr->data->targetData.attack.isBattleGoing || thisptr->data->unitId == emptyId) return; if (!isStackLeaderAndAllowedToUseBattleItems(thisptr->data->objectMap, &thisptr->data->unitId, &thisptr->data->battleMsgData)) return; CMidgardID itemIds[2]; battle.getLeaderEquippedBattleItemIds(thisptr->data->objectMap, &thisptr->data->unitId, &thisptr->data->battleMsgData, itemIds); for (int i = 0; i < 2; ++i) { if (faderApi.hasEventId(fader)) faderApi.callback(fader); if (itemIds[i] == emptyId) continue; viewerApi.unknownMethod10(thisptr, &itemIds[i], i, &thisptr->data2->list); if (canUseItem) { const auto& targetData = thisptr->data->targetData.items[i]; bool isUnitOnTheLeft = viewerApi.isUnitOnTheLeft(thisptr, targetData.isAttacker); viewerApi.unknownMethod11(thisptr, &itemIds[i], &targetData.groupId, &targetData.unitPositions, isUnitOnTheLeft ? &thisptr->data->groupAreas2 : &thisptr->data->groupAreas1, false, &thisptr->data2->list2); } } if (canUseItem) viewerApi.unknownMethod12(thisptr); } void batBigFaceCleanUnitData(game::CBatBigFace* thisptr, const game::UnitInfoList& unitInfos) { using namespace game; const auto& idApi = CMidgardIDApi::get(); const auto& battleApi = BattleMsgDataApi::get(); const auto& bigFaceApi = BatBigFaceApi::get(); for (auto it = thisptr->data->unitData.begin(); it != thisptr->data->unitData.end(); ++it) { bool unitFound = false; for (auto node = unitInfos.head->next; node != unitInfos.head; node = node->next) { CMidgardID unitId; idApi.validateId(&unitId, node->data.unitId1); if (battleApi.getUnitStatus(&thisptr->data->battleMsgData, &unitId, BattleStatus::Unsummoned) || battleApi.getUnitStatus(&thisptr->data->battleMsgData, &unitId, BattleStatus::Retreated) || battleApi.getUnitStatus(&thisptr->data->battleMsgData, &unitId, BattleStatus::Hidden)) { continue; } if (unitId == it->first) { unitFound = true; break; } } if (!unitFound) { if (thisptr->data->unitId == it->first) thisptr->data->unitId = emptyId; bigFaceApi.unitDataMapErase(&thisptr->data->unitData, it); } } } void batBigFaceUpdateUnitImplData(game::CBatBigFace* thisptr, game::CBatBigFaceUnitData* unitData) { using namespace game; const auto& bigFaceApi = BatBigFaceApi::get(); const auto& smartPtrApi = SmartPointerApi::get(); const auto& imagesLoaderApi = BatImagesLoaderApi::get(); auto unitImplData = bigFaceApi.unitImplDataMapAccess(&thisptr->data->unitImplData, &unitData->unitImplId); if (unitImplData->faceImage.data == nullptr) { auto faceImage = imagesLoaderApi.loadUnitFaceImage(thisptr->data->imagesLoader, &unitData->unitImplId, !thisptr->data->flippedBattle, true); smartPtrApi.createOrFree((SmartPointer*)&unitImplData->faceImage, faceImage); } } void batBigFaceUpdateItemData(game::CBatBigFace* thisptr, game::CBatBigFaceUnitData* unitData, const game::CMidgardID* unitId) { using namespace game; const auto& battleApi = BattleMsgDataApi::get(); const auto& bigFaceApi = BatBigFaceApi::get(); const auto& smartPtrApi = SmartPointerApi::get(); const auto& imagesLoaderApi = BatImagesLoaderApi::get(); unitData->showItems = isStackLeaderAndAllowedToUseBattleItems(thisptr->data->objectMap, unitId, &thisptr->data->battleMsgData); if (!unitData->showItems) { for (auto& itemId : unitData->itemIds) { itemId = emptyId; } return; } battleApi.getLeaderEquippedBattleItemIds(thisptr->data->objectMap, unitId, &thisptr->data->battleMsgData, unitData->itemIds); for (const auto& itemId : unitData->itemIds) { if (itemId == emptyId) continue; auto item = static_cast<CMidItem*>( thisptr->data->objectMap->vftable->findScenarioObjectById(thisptr->data->objectMap, &itemId)); auto itemImage = imagesLoaderApi.loadItemImage(thisptr->data->imagesLoader, &item->globalItemId, thisptr->data->flippedBattle); auto itemData = bigFaceApi.itemDataMapAccess(&thisptr->data->itemData, &itemId); smartPtrApi.createOrFree((SmartPointer*)&itemData->itemImage, itemImage); } } void batBigFaceUpdateUnitData(game::CBatBigFace* thisptr, const game::CMidgardID* unitId) { using namespace game; const auto& fn = gameFunctions(); const auto& battleApi = BattleMsgDataApi::get(); const auto& bigFaceApi = BatBigFaceApi::get(); const auto& image2TextApi = CImage2TextApi::get(); const auto& stringApi = StringApi::get(); const auto& smartPtrApi = SmartPointerApi::get(); auto unitData = bigFaceApi.unitDataMapAccess(&thisptr->data->unitData, unitId); if (unitData->textImage.data == nullptr) { auto textImage = (CImage2Text*)Memory::get().allocate(sizeof(CImage2Text)); const auto& textArea = thisptr->data->bigFaceTextArea; image2TextApi.constructor(textImage, textArea.right - textArea.left, textArea.bottom - textArea.top); smartPtrApi.createOrFree((SmartPointer*)&unitData->textImage, textImage); } String description{}; battleApi.generateBigFaceDescription(&description, thisptr->data->objectMap, unitId, &thisptr->data->battleMsgData); const auto desc = stringApi.cStr(&description); if (strcmp(desc, stringApi.cStr(&unitData->textImage.data->text)) != 0) image2TextApi.setText(unitData->textImage.data, desc); stringApi.free(&description); fn.getBaseUnitImplId(&unitData->unitImplId, thisptr->data->objectMap, unitId, false); batBigFaceUpdateUnitImplData(thisptr, unitData); batBigFaceUpdateItemData(thisptr, unitData, unitId); } void __fastcall batBigFaceUpdateHooked(game::CBatBigFace* thisptr, int /*%edx*/, const game::BattleMsgData* battleMsgData) { using namespace game; const auto& idApi = CMidgardIDApi::get(); const auto& battleApi = BattleMsgDataApi::get(); const auto& unitInfoListApi = UnitInfoListApi::get(); battleApi.copyAssignment(&thisptr->data->battleMsgData, battleMsgData); UnitInfoList unitInfos{}; unitInfoListApi.constructor(&unitInfos); battleApi.getUnitInfos(battleMsgData, &unitInfos, true); batBigFaceCleanUnitData(thisptr, unitInfos); for (const auto& unitInfo : unitInfos) { CMidgardID unitId; idApi.validateId(&unitId, unitInfo.unitId1); batBigFaceUpdateUnitData(thisptr, &unitId); } unitInfoListApi.destructor(&unitInfos); } } // namespace hooks
34,763
C++
.cpp
692
37.738439
100
0.623769
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,052
batimagesloader.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/batimagesloader.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "batimagesloader.h" #include "version.h" #include <array> namespace game::BatImagesLoaderApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::LoadMarkImage)0x648fff, (Api::LoadUnitFaceImage)0x649678, (Api::LoadItemImage)0x64955f, }, // Russobit Api{ (Api::LoadMarkImage)0x648fff, (Api::LoadUnitFaceImage)0x649678, (Api::LoadItemImage)0x64955f, }, // Gog Api{ (Api::LoadMarkImage)0x64787f, (Api::LoadUnitFaceImage)0x647ef8, (Api::LoadItemImage)0x647ddf, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::BatImagesLoaderApi
1,566
C++
.cpp
49
28.22449
72
0.710979
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,053
lordcat.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/lordcat.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "lordcat.h" #include "version.h" #include <array> namespace game::LordCategories { // clang-format off static std::array<Categories, 4> categories = {{ // Akella Categories{ (LLordCategory*)0x8397a8, (LLordCategory*)0x839798, (LLordCategory*)0x8397c0, }, // Russobit Categories{ (LLordCategory*)0x8397a8, (LLordCategory*)0x839798, (LLordCategory*)0x8397c0, }, // Gog Categories{ (LLordCategory*)0x837758, (LLordCategory*)0x837748, (LLordCategory*)0x837770, }, // Scenario Editor Categories{ (LLordCategory*)0x664fb8, (LLordCategory*)0x664fa8, (LLordCategory*)0x664fd0, }, }}; // clang-format on Categories& get() { return categories[static_cast<int>(hooks::gameVersion())]; } } // namespace game::LordCategories
1,686
C++
.cpp
55
26.563636
72
0.702952
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,054
version.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/version.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "version.h" namespace hooks { static GameVersion version{GameVersion::Unknown}; static bool lobbySupported{false}; GameVersion gameVersion() { return version; } bool executableIsGame() { return version != GameVersion::Unknown && version != GameVersion::ScenarioEditor; } bool isLobbySupported() { return lobbySupported; } std::error_code determineGameVersion(const std::filesystem::path& exeFilePath) { std::error_code errorCode; const auto exeFileSize = std::filesystem::file_size(exeFilePath, errorCode); if (errorCode) { return errorCode; } // Determine game version by executable file size switch (exeFileSize) { case 3907200: version = GameVersion::Akella; break; // Mortling's mod, exe with custom icon case 4214272: lobbySupported = true; [[fallthrough]]; case 4187648: version = GameVersion::Russobit; break; case 4474880: version = GameVersion::Gog; break; case 2895872: version = GameVersion::ScenarioEditor; break; default: version = GameVersion::Unknown; break; } return {}; } } // namespace hooks
2,021
C++
.cpp
66
26.484848
85
0.71355
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,055
umunit.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/umunit.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "umunit.h" #include "version.h" #include <array> namespace game::CUmUnitApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x5a49b0, (Api::CopyConstructor)0x5a4d0a, (Api::DataConstructor)0x5a4c3a, (Api::DataCopyConstructor)0x5a4d9f, (Api::ReadData)0x5a4a8a, }, // Russobit Api{ (Api::Constructor)0x5a49b0, (Api::CopyConstructor)0x5a4d0a, (Api::DataConstructor)0x5a4c3a, (Api::DataCopyConstructor)0x5a4d9f, (Api::ReadData)0x5a4a8a, }, // Gog Api{ (Api::Constructor)0x5a3c39, (Api::CopyConstructor)0x5a3f93, (Api::DataConstructor)0x5a3ec3, (Api::DataCopyConstructor)0x5a4028, (Api::ReadData)0x5a3d13, }, // Scenario Editor Api{ (Api::Constructor)0x54cc1b, (Api::CopyConstructor)0x54cf75, (Api::DataConstructor)0x54cea5, (Api::DataCopyConstructor)0x54d00a, (Api::ReadData)0x54ccf5, }, }}; static std::array<Vftable, 4> vftables = {{ // Akella Vftable{ (IUsUnitVftable*)0x6ece74, (IUsSoldierVftable*)0x6ecdfc, (CUmModifierVftable*)0x6ecdcc, }, // Russobit Vftable{ (IUsUnitVftable*)0x6ece74, (IUsSoldierVftable*)0x6ecdfc, (CUmModifierVftable*)0x6ecdcc, }, // Gog Vftable{ (IUsUnitVftable*)0x6eae14, (IUsSoldierVftable*)0x6ead9c, (CUmModifierVftable*)0x6ead6c, }, // Scenario Editor Vftable{ (IUsUnitVftable*)0x5e1034, (IUsSoldierVftable*)0x5e0fbc, (CUmModifierVftable*)0x5e0f8c, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } Vftable& vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CUmUnitApi
2,724
C++
.cpp
93
24.16129
72
0.674162
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,056
menuprotocol.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/menuprotocol.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "menuprotocol.h" #include "version.h" #include <array> namespace game::CMenuProtocolApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::Constructor)0x4ecd1e, (Api::DisplayCallback)0x4ecff4, (Api::ButtonHandler)0x4ecf2c, (Api::CreateMenu)0x4ec5bf, }, // Russobit Api{ (Api::Constructor)0x4ecd1e, (Api::DisplayCallback)0x4ecff4, (Api::ButtonHandler)0x4ecf2c, (Api::CreateMenu)0x4ec5bf, }, // Gog Api{ (Api::Constructor)0x4ec1dc, (Api::DisplayCallback)0x4ec4b2, (Api::ButtonHandler)0x4ec3ea, (Api::CreateMenu)0x4eba7f, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMenuProtocolApi
1,651
C++
.cpp
52
27.711538
72
0.70138
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,057
radiobuttoninterf.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/radiobuttoninterf.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "radiobuttoninterf.h" #include "version.h" #include <array> namespace game::CRadioButtonInterfApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::SetEnabled)0, (Api::SetButtonEnabled)0, (Api::SetCheckedButton)0, (Api::SetOnButtonPressed)0, }, // Russobit Api{ (Api::SetEnabled)0, (Api::SetButtonEnabled)0, (Api::SetCheckedButton)0, (Api::SetOnButtonPressed)0, }, // Gog Api{ (Api::SetEnabled)0, (Api::SetButtonEnabled)0, (Api::SetCheckedButton)0, (Api::SetOnButtonPressed)0, }, // Scenario Editor Api{ (Api::SetEnabled)0x48ee1e, (Api::SetButtonEnabled)0x48ee30, (Api::SetCheckedButton)0x48ede5, (Api::SetOnButtonPressed)0x4d102e, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CRadioButtonInterfApi
1,814
C++
.cpp
59
26.322034
72
0.687429
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,058
dynamiccast.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/dynamiccast.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "dynamiccast.h" #include "version.h" #include <array> namespace game::RttiApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api { (Api::DynamicCast)0x66d466, (Api::TypeInfoRawName*)0x6ce2cc, (Api::TypeInfoInequalityOperator*)0x6ce1a0, (Api::TypeIdOperator*)0x6ce2b4, }, // Russobit Api { (Api::DynamicCast)0x66d466, (Api::TypeInfoRawName*)0x6ce2cc, (Api::TypeInfoInequalityOperator*)0x6ce1a0, (Api::TypeIdOperator*)0x6ce2b4, }, // Gog Api { (Api::DynamicCast)0x66bda6, (Api::TypeInfoRawName*)0x6cc25c, (Api::TypeInfoInequalityOperator*)0x6cc1fc, (Api::TypeIdOperator*)0x6cc2c8, }, // Scenario Editor Api { (Api::DynamicCast)0x57109c, (Api::TypeInfoRawName*)0x5ca258, (Api::TypeInfoInequalityOperator*)0x5ca15c, (Api::TypeIdOperator*)0x5ca1f0, }, }}; static const std::array<Rtti, 4> types = {{ // Akella Rtti{ (TypeDescriptor*)0x78eda8, (TypeDescriptor*)0x78edd0, (TypeDescriptor*)0x79e868, (TypeDescriptor*)0x79e600, (TypeDescriptor*)0x79e620, (TypeDescriptor*)0x78ef80, (TypeDescriptor*)0x7b00e8, (TypeDescriptor*)0x7b0120, (TypeDescriptor*)0x78ee30, (TypeDescriptor*)0x78eee0, (TypeDescriptor*)0x7962b8, (TypeDescriptor*)0x78fd70, (TypeDescriptor*)0x7927b8, (TypeDescriptor*)0x7927e0, (TypeDescriptor*)0x792808, (TypeDescriptor*)0x78fd98, (TypeDescriptor*)0x793600, (TypeDescriptor*)0x793630, (TypeDescriptor*)0x792828, (TypeDescriptor*)0x7b28e8, (TypeDescriptor*)0x7aeea0, (TypeDescriptor*)0x7b0150, (TypeDescriptor*)0x7b01a0, (TypeDescriptor*)0x799da0, (TypeDescriptor*)0x799db8, (TypeDescriptor*)0x78f0f8, (TypeDescriptor*)0x7b0008, (TypeDescriptor*)0x7b4620, (TypeDescriptor*)0x7b51e8, (TypeDescriptor*)0x793c38, (TypeDescriptor*)0x7af710, (TypeDescriptor*)0x78f118, (TypeDescriptor*)0x7acdc8, (TypeDescriptor*)0x7a1178, (TypeDescriptor*)0x7ad348, (TypeDescriptor*)0x7b0138, (TypeDescriptor*)0x7ad2c8, (TypeDescriptor*)0x7a10f8, (TypeDescriptor*)0x7b52d0, (TypeDescriptor*)0x7b52f0, (TypeDescriptor*)0x7afb80, // CItemEquipmentType (TypeDescriptor*)0x7b0108, // CUmStackType (TypeDescriptor*)0x78ee68, // CFortificationType (TypeDescriptor*)0x799ec0, // IMidObjectType (TypeDescriptor*)0x793d90, // IUsNobleType (TypeDescriptor*)0x7974b8, // IUsSummonType (TypeDescriptor*)0x7afcf8, // IItemExPotionBoostType }, // Russobit Rtti{ (TypeDescriptor*)0x78eda8, (TypeDescriptor*)0x78edd0, (TypeDescriptor*)0x79e868, (TypeDescriptor*)0x79e600, (TypeDescriptor*)0x79e620, (TypeDescriptor*)0x78ef80, (TypeDescriptor*)0x7b00e8, (TypeDescriptor*)0x7b0120, (TypeDescriptor*)0x78ee30, (TypeDescriptor*)0x78eee0, (TypeDescriptor*)0x7962b8, (TypeDescriptor*)0x78fd70, (TypeDescriptor*)0x7927b8, (TypeDescriptor*)0x7927e0, (TypeDescriptor*)0x792808, (TypeDescriptor*)0x78fd98, (TypeDescriptor*)0x793600, (TypeDescriptor*)0x793630, (TypeDescriptor*)0x792828, (TypeDescriptor*)0x7b28e8, (TypeDescriptor*)0x7aeea0, (TypeDescriptor*)0x7b0150, (TypeDescriptor*)0x7b01a0, (TypeDescriptor*)0x799da0, (TypeDescriptor*)0x799db8, (TypeDescriptor*)0x78f0f8, (TypeDescriptor*)0x7b0008, (TypeDescriptor*)0x7b4620, (TypeDescriptor*)0x7b51e8, (TypeDescriptor*)0x793c38, (TypeDescriptor*)0x7af710, (TypeDescriptor*)0x78f118, (TypeDescriptor*)0x7acdc8, (TypeDescriptor*)0x7a1178, (TypeDescriptor*)0x7ad348, (TypeDescriptor*)0x7b0138, (TypeDescriptor*)0x7ad2c8, (TypeDescriptor*)0x7a10f8, (TypeDescriptor*)0x7b52d0, (TypeDescriptor*)0x7b52f0, (TypeDescriptor*)0x7afb80, // CItemEquipmentType (TypeDescriptor*)0x7b0108, // CUmStackType (TypeDescriptor*)0x78ee68, // CFortificationType (TypeDescriptor*)0x799ec0, // IMidObjectType (TypeDescriptor*)0x793d90, // IUsNobleType (TypeDescriptor*)0x7974b8, // IUsSummonType (TypeDescriptor*)0x7afcf8, // IItemExPotionBoostType }, // Gog Rtti{ (TypeDescriptor*)0x78cd50, (TypeDescriptor*)0x78cd78, (TypeDescriptor*)0x79c810, (TypeDescriptor*)0x79c5a8, (TypeDescriptor*)0x79c5c8, (TypeDescriptor*)0x78cf28, (TypeDescriptor*)0x7ae0a0, (TypeDescriptor*)0x7ae0d8, (TypeDescriptor*)0x78cdd8, (TypeDescriptor*)0x78ce88, (TypeDescriptor*)0x794260, (TypeDescriptor*)0x78dd18, (TypeDescriptor*)0x790760, (TypeDescriptor*)0x790788, (TypeDescriptor*)0x7907b0, (TypeDescriptor*)0x78dd40, (TypeDescriptor*)0x7915a8, (TypeDescriptor*)0x7915d8, (TypeDescriptor*)0x7907d0, (TypeDescriptor*)0x7b0898, (TypeDescriptor*)0x7ace58, (TypeDescriptor*)0x7ae108, (TypeDescriptor*)0x7ae158, (TypeDescriptor*)0x797d48, (TypeDescriptor*)0x797d60, (TypeDescriptor*)0x78d0a0, (TypeDescriptor*)0x7adfc0, (TypeDescriptor*)0x7b25d0, (TypeDescriptor*)0x7b3198, (TypeDescriptor*)0x791be0, (TypeDescriptor*)0x7ad6c8, (TypeDescriptor*)0x78d0c0, (TypeDescriptor*)0x7aad80, (TypeDescriptor*)0x79f118, (TypeDescriptor*)0x7ab300, (TypeDescriptor*)0x7ae0f0, (TypeDescriptor*)0x7ab280, (TypeDescriptor*)0x79f0a0, (TypeDescriptor*)0x7b3280, (TypeDescriptor*)0x7b32a0, (TypeDescriptor*)0x7adb38, // CItemEquipmentType (TypeDescriptor*)0x7ae0c0, // CUmStackType (TypeDescriptor*)0x78ce10, // CFortificationType (TypeDescriptor*)0x797e68, // IMidObjectType (TypeDescriptor*)0x791d38, // IUsNobleType (TypeDescriptor*)0x795460, // IUsSummonType (TypeDescriptor*)0x7adcb0, // IItemExPotionBoostType }, // Scenario Editor Rtti{ (TypeDescriptor*)0x648b48, (TypeDescriptor*)0x649788, (TypeDescriptor*)0x6561a8, // CPlayerBuildingsType (TypeDescriptor*)0x655d40, // TBuildingTypeType (TypeDescriptor*)0x6561e8, // TBuildingUnitUpgTypeType (TypeDescriptor*)0x648b90, (TypeDescriptor*)0x656e08, (TypeDescriptor*)0x65bd20, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)0x656310, (TypeDescriptor*)0x65a5a8, (TypeDescriptor*)0x65bd50, (TypeDescriptor*)0x65bd70, (TypeDescriptor*)0x655a90, (TypeDescriptor*)0x65b0d0, (TypeDescriptor*)0x648e98, (TypeDescriptor*)0x65bc28, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)0x649768, (TypeDescriptor*)nullptr, (TypeDescriptor*)0x649398, (TypeDescriptor*)0x655848, (TypeDescriptor*)0x655d80, (TypeDescriptor*)0x655e28, (TypeDescriptor*)0x65bd38, (TypeDescriptor*)0x655da8, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)nullptr, (TypeDescriptor*)0x65b820, // CItemEquipmentType (TypeDescriptor*)0x65bd08, // CUmStackType (TypeDescriptor*)0x648e20, // CFortificationType (TypeDescriptor*)0x649438, // IMidObjectType (TypeDescriptor*)0x64c3d0, // IUsNobleType (TypeDescriptor*)0x64f068, // IUsSummonType (TypeDescriptor*)0x656e28, // IItemExPotionBoostType }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } const Rtti& rtti() { return types[static_cast<int>(hooks::gameVersion())]; } } // namespace game::RttiApi
9,351
C++
.cpp
265
27.645283
72
0.663289
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,059
customattackutils.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/customattackutils.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "customattackutils.h" #include "attack.h" #include "attackclasscat.h" #include "attackimpl.h" #include "attackmodified.h" #include "attackutils.h" #include "batattack.h" #include "batattacktransformself.h" #include "batattackutils.h" #include "battlemsgdata.h" #include "battlemsgdataview.h" #include "custommodifier.h" #include "dbffile.h" #include "dynamiccast.h" #include "game.h" #include "gameutils.h" #include "idlistutils.h" #include "intset.h" #include "itemview.h" #include "log.h" #include "midgardobjectmap.h" #include "midplayer.h" #include "midunit.h" #include "midunitgroup.h" #include "scripts.h" #include "settings.h" #include "targetslistutils.h" #include "unitslotview.h" #include "unitutils.h" #include "ussoldier.h" #include "utils.h" #include <fmt/format.h> namespace hooks { void fillCustomAttackSources(const std::filesystem::path& dbfFilePath) { using namespace game; utils::DbfFile dbf; if (!dbf.open(dbfFilePath)) { logError("mssProxyError.log", fmt::format("Could not open {:s}", dbfFilePath.filename().string())); return; } static const std::uint32_t lastBaseSourceWardFlagPosition = 7; // 0-based bit flag index static const std::array<const char*, 8> baseSources = { {"L_WEAPON", "L_MIND", "L_LIFE", "L_DEATH", "L_FIRE", "L_WATER", "L_AIR", "L_EARTH"}}; auto& customSources = getCustomAttacks().sources; std::uint32_t wardFlagPosition = lastBaseSourceWardFlagPosition; const auto recordsTotal{dbf.recordsTotal()}; for (std::uint32_t i = 0; i < recordsTotal; ++i) { if (wardFlagPosition >= 31) { // UnitInfo::AttackSourceImmunityStatusesPatched can only contain 32 different bit flags showErrorMessageBox( "Total number of attack sources cannot exceed 32.\n" "The rest are ignored, this will likely result in game crash later."); break; } utils::DbfRecord record; if (!dbf.record(record, i)) { logError("mssProxyError.log", fmt::format("Could not read record {:d} from {:s}", i, dbfFilePath.filename().string())); return; } if (record.isDeleted()) { continue; } std::string text; record.value(text, "TEXT"); text = trimSpaces(text); if (std::none_of(std::begin(baseSources), std::end(baseSources), [&text](const char* baseText) { return text == baseText; })) { std::string nameId; record.value(nameId, "NAME_TXT"); int immunityAiRating = 5; // 5 is the default record.value(immunityAiRating, "IMMU_AI_R"); logDebug("customAttacks.log", fmt::format( "Found custom attack source {:s}, name id {:s}, immunity ai rating {:d}", text, nameId, immunityAiRating)); customSources.push_back({LAttackSource{AttackSourceCategories::vftable(), nullptr, (AttackSourceId)emptyCategoryId}, text, nameId, (double)immunityAiRating, ++wardFlagPosition}); } } } void fillCustomAttackReaches(const std::filesystem::path& dbfFilePath) { using namespace game; utils::DbfFile dbf; if (!dbf.open(dbfFilePath)) { logError("mssProxyError.log", fmt::format("Could not open {:s}", dbfFilePath.filename().string())); return; } static const std::array<const char*, 3> baseReaches = {{"L_ALL", "L_ANY", "L_ADJACENT"}}; auto& customReaches = getCustomAttacks().reaches; const auto recordsTotal{dbf.recordsTotal()}; for (std::uint32_t i = 0; i < recordsTotal; ++i) { utils::DbfRecord record; if (!dbf.record(record, i)) { logError("mssProxyError.log", fmt::format("Could not read record {:d} from {:s}", i, dbfFilePath.filename().string())); return; } if (record.isDeleted()) { continue; } std::string text; record.value(text, "TEXT"); text = trimSpaces(text); if (std::none_of(std::begin(baseReaches), std::end(baseReaches), [&text](const char* baseText) { return text == baseText; })) { std::string reachTxt; record.value(reachTxt, "REACH_TXT"); std::string targetsTxt; record.value(targetsTxt, "TARGET_TXT"); std::string selectionScript; record.value(selectionScript, "SEL_SCRIPT"); std::string attackScript; record.value(attackScript, "ATT_SCRIPT"); bool markAttackTargets = false; record.value(markAttackTargets, "MRK_TARGTS"); bool melee = false; record.value(melee, "MELEE"); int maxTargets = 1; // 1 is the default record.value(maxTargets, "MAX_TARGTS"); logDebug("customAttacks.log", fmt::format("Found custom attack reach {:s}", text)); customReaches.push_back({LAttackReach{AttackReachCategories::vftable(), nullptr, (AttackReachId)emptyCategoryId}, text, reachTxt, targetsTxt, trimSpaces(selectionScript), trimSpaces(attackScript), markAttackTargets, melee, (std::uint32_t)maxTargets}); } } } UnitSlots getTargetsToSelectOrAttack(const std::string& scriptFile, const bindings::UnitSlotView& attacker, const bindings::UnitSlotView& selected, const UnitSlots& allies, const UnitSlots& targets, bool targetsAreAllies, const std::optional<bindings::ItemView>& item, const bindings::BattleMsgDataView& battle, bool isMarking) { std::optional<sol::environment> env; const auto path{scriptsFolder() / scriptFile}; auto getTargets = getScriptFunction(path, "getTargets", env, true, true); if (!getTargets) { return UnitSlots(); } try { sol::table result = (*getTargets)(attacker, selected, allies, targets, targetsAreAllies, item ? &item.value() : nullptr, battle, isMarking); return result.as<UnitSlots>(); } catch (const std::exception& e) { showErrorMessageBox(fmt::format("Failed to run '{:s}' script.\n" "Reason: '{:s}'", path.string(), e.what())); return UnitSlots(); } } UnitSlots getTargets(const game::IMidgardObjectMap* objectMap, const game::BattleMsgData* battleMsgData, const game::IBatAttack* batAttack, const game::CMidgardID* targetGroupId, const game::CMidgardID* unitId, const game::CMidgardID* selectedUnitId) { using namespace game; const auto& fn = gameFunctions(); const auto& battle = BattleMsgDataApi::get(); const auto& rtti = RttiApi::rtti(); const auto dynamicCast = RttiApi::get().dynamicCast; void* tmp{}; auto targetGroup = fn.getStackFortRuinGroup(tmp, objectMap, targetGroupId); auto transformSelfAttack = (CBatAttackTransformSelf*) dynamicCast(batAttack, 0, rtti.IBatAttackType, rtti.CBatAttackTransformSelfType, 0); UnitSlots value; bool isSummonAttack = batAttack->vftable->method17(batAttack, battleMsgData); bool isAltAttack = transformSelfAttack != nullptr && *unitId != *selectedUnitId; for (size_t i = 0; i < std::size(targetGroup->positions); ++i) { CMidgardID targetUnitId = targetGroup->positions[i]; if (targetUnitId != emptyId) { auto targetUnit = fn.findUnitById(objectMap, &targetUnitId); if (i % 2 && !isUnitSmall(targetUnit)) continue; // Explicitly check if alt attack can be performed on self, because // canPerformAttackOnUnitWithStatusCheck always succeeds in case of transform-self // attack regardless of whether transform or alt-attack is going to be performed if (isAltAttack && targetUnitId == *unitId) { auto altAttack = transformSelfAttack->altAttack; if (altAttack != nullptr && !altAttack->vftable->canPerform(altAttack, objectMap, battleMsgData, &targetUnitId)) continue; } if (battle.canPerformAttackOnUnitWithStatusCheck(objectMap, battleMsgData, batAttack, &targetUnitId)) { value.emplace_back(bindings::UnitSlotView(targetUnit, i, targetGroupId)); } } else if (isSummonAttack) { value.emplace_back(bindings::UnitSlotView(nullptr, i, targetGroupId)); } } return value; } std::vector<bindings::UnitSlotView> getAllies(const game::IMidgardObjectMap* objectMap, const game::BattleMsgData* battleMsgData, const game::CMidgardID* unitGroupId, const game::CMidgardID* unitId) { using namespace game; const auto& fn = gameFunctions(); const auto& battle = BattleMsgDataApi::get(); void* tmp{}; auto unitGroup = fn.getStackFortRuinGroup(tmp, objectMap, unitGroupId); UnitSlots value; for (size_t i = 0; i < std::size(unitGroup->positions); ++i) { CMidgardID allyUnitId = unitGroup->positions[i]; if (allyUnitId == emptyId || allyUnitId == *unitId) continue; auto allyUnit = fn.findUnitById(objectMap, &allyUnitId); if (i % 2 && !isUnitSmall(allyUnit)) continue; if (battle.getUnitStatus(battleMsgData, &allyUnitId, BattleStatus::Dead) || battle.getUnitStatus(battleMsgData, &allyUnitId, BattleStatus::Retreated) || battle.getUnitStatus(battleMsgData, &allyUnitId, BattleStatus::Hidden)) { continue; } value.emplace_back(bindings::UnitSlotView(allyUnit, i, unitGroupId)); } return value; } void fillTargetsListForCustomAttackReach(const game::IMidgardObjectMap* objectMap, const game::BattleMsgData* battleMsgData, const game::IBatAttack* batAttack, const game::CMidgardID* targetGroupId, const game::CMidgardID* unitGroupId, const game::CMidgardID* unitId, const game::CMidgardID* attackUnitOrItemId, const CustomAttackReach& attackReach, game::TargetSet* value) { using namespace game; const auto& fn = gameFunctions(); const auto& intSetApi = IntSetApi::get(); const auto& groupApi = CMidUnitGroupApi::get(); const auto& idApi = CMidgardIDApi::get(); intSetApi.clear(value); void* tmp{}; auto unitGroup = fn.getStackFortRuinGroup(tmp, objectMap, unitGroupId); auto unit = fn.findUnitById(objectMap, unitId); int unitPosition = groupApi.getUnitPosition(unitGroup, unitId); bindings::UnitSlotView attacker(unit, unitPosition, unitGroupId); bindings::UnitSlotView selected(nullptr, -1, &emptyId); auto targets = getTargets(objectMap, battleMsgData, batAttack, targetGroupId, unitId, &emptyId); auto allies = getAllies(objectMap, battleMsgData, unitGroupId, unitId); std::optional<bindings::ItemView> item; if (idApi.getType(attackUnitOrItemId) == IdType::Item) { item = bindings::ItemView(attackUnitOrItemId, objectMap); } bindings::BattleMsgDataView battleView{battleMsgData, objectMap}; auto targetsToSelect = getTargetsToSelectOrAttack(attackReach.selectionScript, attacker, selected, allies, targets, *unitGroupId == *targetGroupId, item, battleView, false); bool isSummonAttack = batAttack->vftable->method17(batAttack, battleMsgData); for (const auto& target : targetsToSelect) { int position = target.getPosition(); Pair<TargetSetIterator, bool> tmp{}; intSetApi.insert(value, &tmp, &position); if (isSummonAttack && !(position % 2)) { auto unit = target.getUnit(); if (unit && !isUnitSmall(unit)) { int backPosition = position + 1; intSetApi.insert(value, &tmp, &backPosition); } } } } void getTargetsToAttackForAllAttackReach(const game::IMidgardObjectMap* objectMap, const game::BattleMsgData* battleMsgData, const game::IAttack* attack, const game::IBatAttack* batAttack, const game::CMidgardID* targetGroupId, const game::CMidgardID* targetUnitId, game::IdList* value) { using namespace game; const auto& fn = gameFunctions(); const auto& id = CMidgardIDApi::get(); const auto& listApi = IdListApi::get(); const auto& groupApi = CMidUnitGroupApi::get(); const auto& attackClasses = AttackClassCategories::get(); void* tmp{}; CMidUnitGroup* targetGroup = fn.getStackFortRuinGroup(tmp, objectMap, targetGroupId); CMidgardID summonUnitId{}; id.isSummonUnitId(&summonUnitId, targetUnitId); if (summonUnitId != emptyId || groupApi.getUnitPosition(targetGroup, targetUnitId) != -1) { if (attack != nullptr && attack->vftable->getAttackClass(attack)->id == attackClasses.summon->id) { groupApi.addUnitIdsAvailableForSummons(value, objectMap, targetGroup); } else { const auto& unitIds = targetGroup->units; for (const CMidgardID* unitId = unitIds.bgn; unitId != unitIds.end; ++unitId) { listApi.pushBack(value, unitId); } } } addUniqueIdToList(*value, targetUnitId); listApi.shuffle(value); } UnitSlots getTargetsToMarkOrAttackForCustomAttackReach(const game::IMidgardObjectMap* objectMap, const game::BattleMsgData* battleMsgData, const game::IBatAttack* batAttack, const game::CMidgardID* targetGroupId, const game::CMidgardID* targetUnitId, const game::CMidgardID* unitGroupId, const game::CMidgardID* unitId, const CustomAttackReach& attackReach, bool isMarking) { using namespace game; const auto& fn = gameFunctions(); const auto& id = CMidgardIDApi::get(); const auto& groupApi = CMidUnitGroupApi::get(); void* tmp{}; auto unitGroup = fn.getStackFortRuinGroup(tmp, objectMap, unitGroupId); auto targetGroup = fn.getStackFortRuinGroup(tmp, objectMap, targetGroupId); auto unit = fn.findUnitById(objectMap, unitId); int unitPosition = groupApi.getUnitPosition(unitGroup, unitId); bindings::UnitSlotView attacker(unit, unitPosition, unitGroupId); auto target = fn.findUnitById(objectMap, targetUnitId); int targetPosition = groupApi.getUnitPosition(targetGroup, targetUnitId); if (targetPosition == -1) { targetPosition = id.summonUnitIdToPosition(targetUnitId); } bindings::UnitSlotView selected(target, targetPosition, targetGroupId); auto targets = getTargets(objectMap, battleMsgData, batAttack, targetGroupId, unitId, targetUnitId); auto allies = getAllies(objectMap, battleMsgData, unitGroupId, unitId); std::optional<bindings::ItemView> item; auto itemId = getItemId(batAttack); if (*itemId != emptyId) { item = bindings::ItemView(itemId, objectMap); } bindings::BattleMsgDataView battleView{battleMsgData, objectMap}; return getTargetsToSelectOrAttack(attackReach.attackScript, attacker, selected, allies, targets, *unitGroupId == *targetGroupId, item, battleView, isMarking); } UnitSlots getTargetsToAttackForCustomAttackReach(const game::IMidgardObjectMap* objectMap, const game::BattleMsgData* battleMsgData, const game::IBatAttack* batAttack, const game::CMidgardID* targetGroupId, const game::CMidgardID* targetUnitId, const game::CMidgardID* unitGroupId, const game::CMidgardID* unitId, const CustomAttackReach& attackReach) { return getTargetsToMarkOrAttackForCustomAttackReach(objectMap, battleMsgData, batAttack, targetGroupId, targetUnitId, unitGroupId, unitId, attackReach, false); } UnitSlots getTargetsToMarkForCustomAttackReach(const game::IMidgardObjectMap* objectMap, const game::BattleMsgData* battleMsgData, const game::IAttack* attack, const game::CMidgardID* targetGroupId, const game::CMidgardID* targetUnitId, const game::CMidgardID* unitGroupId, const game::CMidgardID* unitId, const game::CMidgardID* attackUnitId, const CustomAttackReach& attackReach) { using namespace game; const auto& fn = gameFunctions(); const auto attackClass = attack->vftable->getAttackClass(attack); const auto batAttack = fn.createBatAttack(objectMap, battleMsgData, unitId, attackUnitId, 1, attackClass, false); auto result = getTargetsToMarkOrAttackForCustomAttackReach(objectMap, battleMsgData, batAttack, targetGroupId, targetUnitId, unitGroupId, unitId, attackReach, true); batAttack->vftable->destructor(batAttack, true); return result; } void getTargetsToAttackForCustomAttackReach(const game::IMidgardObjectMap* objectMap, const game::BattleMsgData* battleMsgData, const game::IBatAttack* batAttack, const game::CMidgardID* targetGroupId, const game::CMidgardID* targetUnitId, const game::CMidgardID* unitGroupId, const game::CMidgardID* unitId, const CustomAttackReach& attackReach, game::IdList* value) { using namespace game; const auto& id = CMidgardIDApi::get(); auto targets = getTargetsToAttackForCustomAttackReach(objectMap, battleMsgData, batAttack, targetGroupId, targetUnitId, unitGroupId, unitId, attackReach); for (const auto& target : targets) { CMidgardID targetUnitId = target.getUnitId(); if (targetUnitId == emptyId) { id.summonUnitIdFromPosition(&targetUnitId, target.getPosition()); } addUniqueIdToList(*value, &targetUnitId); } } bool shouldExcludeImmuneTargets(const game::IMidgardObjectMap* objectMap, const game::BattleMsgData* battleMsgData, const game::CMidgardID* unitId) { using namespace game; const auto& id = CMidgardIDApi::get(); const auto& battle = BattleMsgDataApi::get(); if (battle.isAutoBattle(battleMsgData)) return true; CMidgardID playerId{}; id.validateId(&playerId, battle.isUnitAttacker(battleMsgData, unitId) ? battleMsgData->attackerPlayerId : battleMsgData->defenderPlayerId); if (playerId == emptyId) return true; auto player = getPlayer(objectMap, &playerId); return !player || !player->isHuman; } void excludeImmuneTargets(const game::IMidgardObjectMap* objectMap, const game::BattleMsgData* battleMsgData, const game::IAttack* attack, const game::CMidgardID* unitGroupId, const game::CMidgardID* targetGroupId, game::TargetSet* value) { using namespace game; const auto& fn = gameFunctions(); const auto& intSetApi = IntSetApi::get(); void* tmp{}; auto unitGroup = fn.getStackFortRuinGroup(tmp, objectMap, unitGroupId); auto targetGroup = fn.getStackFortRuinGroup(tmp, objectMap, targetGroupId); for (auto it = value->begin(); it != value->end();) { int position = *it++; // Prevents iterator invalidation on erasing auto unitId = getTargetUnitId(position, targetGroup, unitGroup); if (unitId == emptyId) continue; if (fn.isUnitImmuneToAttack(objectMap, battleMsgData, &unitId, attack, true)) { intSetApi.erase(value, &position); } } } void fillCustomAttackTargets(const game::IdList* targets) { getCustomAttacks().damageRatios.clear(); auto& result = getCustomAttacks().targets; result.clear(); for (const auto& unitId : *targets) { result.push_back(unitId); } } const CustomAttackDamageRatios& getCustomDamageRatios(const game::IAttack* attack) { auto& damageRatios = getCustomAttacks().damageRatios; auto it = damageRatios.find(attack->id); if (it != damageRatios.end()) { return it->second; } auto& result = damageRatios[attack->id]; auto& targets = getCustomAttacks().targets; auto ratios = computeAttackDamageRatio(getCustomAttackData(attack), targets.size()); auto ratio = ratios.begin(); for (auto target : targets) { if (ratio == ratios.end()) { break; } result[target] = *ratio; ++ratio; } return result; } int applyAttackDamageRatio(int damage, double ratio) { if (damage == 0) return 0; int result = lround(ratio * damage); return result > 0 ? result : 1; } std::vector<double> computeAttackDamageRatio(const CustomAttackData& customData, int targetCount) { std::vector<double> result; if (customData.damageRatio == 100 && !customData.damageSplit) return result; const double ratio = (double)customData.damageRatio / 100; double currentRatio = ratio; double totalRatio = 1.0; result.push_back(1.0); for (int i = 1; i < targetCount; i++) { result.push_back(currentRatio); totalRatio += currentRatio; if (customData.damageRatioPerTarget) currentRatio *= ratio; } if (customData.damageSplit) { for (auto& value : result) { value /= totalRatio * userSettings().splitDamageMultiplier; } } return result; } double computeTotalDamageRatio(const game::IAttack* attack, int targetCount) { if (!getCustomAttacks().damageRatiosEnabled) return targetCount; auto customData = getCustomAttackData(attack); if (customData.damageSplit) { return 1.0 * userSettings().splitDamageMultiplier; } else if (customData.damageRatio != 100) { double ratio = (double)customData.damageRatio / 100; double value = 1.0; for (int i = 1; i < targetCount; i++) { value += customData.damageRatioPerTarget ? pow(ratio, i) : ratio; } return value; } return targetCount; } int computeAverageTotalDamage(const game::IAttack* attack, int damage) { int maxTargets = getAttackMaxTargets(attack->vftable->getAttackReach(attack)->id); int avgTargets = maxTargets % 2 + maxTargets / 2; return damage * avgTargets; } CustomAttackData getCustomAttackData(const game::IAttack* attack) { using namespace game; const auto& rtti = RttiApi::rtti(); const auto dynamicCast = RttiApi::get().dynamicCast; auto current = attack; while (current) { auto customModifier = castAttackToCustomModifier(current); if (customModifier) { return customModifier->getCustomAttackData(current); } auto attackImpl = (CAttackImpl*)dynamicCast(current, 0, rtti.IAttackType, rtti.CAttackImplType, 0); if (attackImpl) { const auto data = attackImpl->data; CustomAttackData result{}; result.damageRatio = data->damageRatio; result.damageRatioPerTarget = data->damageRatioPerTarget; result.damageSplit = data->damageSplit; result.critDamage = data->critDamage; result.critPower = data->critPower; return result; } auto attackModified = (CAttackModified*)dynamicCast(current, 0, rtti.IAttackType, rtti.CAttackModifiedType, 0); current = attackModified ? attackModified->data->prev : nullptr; } // Should never happen unless attack is null return {}; } } // namespace hooks
27,850
C++
.cpp
579
34.83247
100
0.588441
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,060
middragdropinterfhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/middragdropinterfhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "middragdropinterfhooks.h" #include "middragdropinterf.h" namespace hooks { void midDragDropInterfResetCurrentSource(game::CMidDragDropInterf* dragDropInterf) { using namespace game; auto data = dragDropInterf->dragAndDropInterfData; if (data->currentSource) { data->currentSource = nullptr; auto dropManager = &dragDropInterf->dropManager; dropManager->vftable->resetDropSource(dropManager); } } } // namespace hooks
1,286
C++
.cpp
32
37.21875
82
0.762019
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,061
buildingtype.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/buildingtype.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "buildingtype.h" #include "version.h" #include <array> namespace game { namespace TBuildingTypeApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x58ba1d, }, // Russobit Api{ (Api::Constructor)0x58ba1d, }, // Gog Api{ (Api::Constructor)0x58ab86, }, // Scenario Editor Api{ (Api::Constructor)0x538599, } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace TBuildingTypeApi namespace TBuildingUnitUpgTypeApi { // clang-format off static std::array<const void*, 4> vftables = {{ // Akella (const void*)0x6ea7cc, // Russobit (const void*)0x6ea7cc, // Gog (const void*)0x6e876c, // Scenario Editor (const void*)0x5df5f4 }}; // clang-format on const void* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace TBuildingUnitUpgTypeApi } // namespace game
1,840
C++
.cpp
67
24.268657
72
0.705048
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,062
batattackdrain.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/batattackdrain.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "batattackdrain.h" #include "version.h" #include <array> namespace game::CBatAttackDrainApi { // clang-format off static std::array<IBatAttackVftable*, 4> vftables = {{ // Akella (IBatAttackVftable*)0x6f4ebc, // Russobit (IBatAttackVftable*)0x6f4ebc, // Gog (IBatAttackVftable*)0x6f2e6c, // Scenario Editor (IBatAttackVftable*)nullptr, }}; // clang-format on IBatAttackVftable* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CBatAttackDrainApi
1,351
C++
.cpp
39
32.153846
72
0.749044
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,063
menulord.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/menulord.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "menulord.h" #include "version.h" #include <array> namespace game::CMenuLordApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::Constructor)0x4e6368, (Api::GetLordFacesByRace)0x4e694a, (Api::LoadLordFaceImages)0x4e69ce, (Api::GetLordAnimation)0x4e7568, (Api::LoadLordAnimation)0x4eb590, }, // Russobit Api{ (Api::Constructor)0x4e6368, (Api::GetLordFacesByRace)0x4e694a, (Api::LoadLordFaceImages)0x4e69ce, (Api::GetLordAnimation)0x4e7568, (Api::LoadLordAnimation)0x4eb590, }, // Gog Api{ (Api::Constructor)0x4e5899, (Api::GetLordFacesByRace)0x4e5e7b, (Api::LoadLordFaceImages)0x4e5eff, (Api::GetLordAnimation)0x4e6a67, (Api::LoadLordAnimation)0x4eaa42, } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMenuLordApi
1,806
C++
.cpp
55
28.527273
72
0.705613
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,064
mideventhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/mideventhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "mideventhooks.h" #include "eventconditioncathooks.h" #include "midcondgamemode.h" #include "midcondownresource.h" #include "midcondplayertype.h" #include "midevent.h" #include "originalfunctions.h" namespace hooks { void getConditionsOfType(const game::CMidEvent* event, const game::LEventCondCategory* category, std::vector<const game::CMidEvCondition*>& conditions) { const int conditionsTotal = event->conditions.end - event->conditions.bgn; for (int i = 0; i < conditionsTotal; ++i) { const auto condition = event->conditions.bgn[i]; if (condition->category.id == category->id) { conditions.push_back(condition); } } } bool __stdcall checkEventValidHooked(game::CDialogInterf* dialog, const game::IMidgardObjectMap* objectMap, const game::CMidgardID* eventId) { if (!getOriginalFunctions().checkEventValid(dialog, objectMap, eventId)) { return false; } return checkOwnResourceConditionsValid(dialog, objectMap, eventId) && checkGameModeConditionValid(dialog, objectMap, eventId) && checkPlayerTypeConditionValid(dialog, objectMap, eventId); } } // namespace hooks
2,112
C++
.cpp
50
36.46
79
0.703992
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,065
eventconditioncat.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/eventconditioncat.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "eventconditioncat.h" #include "version.h" #include <array> namespace game { namespace EventCondCategories { // clang-format off static std::array<Categories, 4> categories = {{ // Akella Categories{ (LEventCondCategory*)0x839e20, (LEventCondCategory*)0x839e50, (LEventCondCategory*)0x839d90, (LEventCondCategory*)0x839e10, (LEventCondCategory*)0x839df0, (LEventCondCategory*)0x839e60, (LEventCondCategory*)0x839da0, (LEventCondCategory*)0x839d70, (LEventCondCategory*)0x839dd0, (LEventCondCategory*)0x839e70, (LEventCondCategory*)0x839e40, (LEventCondCategory*)0x839de0, (LEventCondCategory*)0x839e30, (LEventCondCategory*)0x839e00, (LEventCondCategory*)0x839db0, (LEventCondCategory*)0x839d80, (LEventCondCategory*)0x839dc0, }, // Russobit Categories{ (LEventCondCategory*)0x839e20, (LEventCondCategory*)0x839e50, (LEventCondCategory*)0x839d90, (LEventCondCategory*)0x839e10, (LEventCondCategory*)0x839df0, (LEventCondCategory*)0x839e60, (LEventCondCategory*)0x839da0, (LEventCondCategory*)0x839d70, (LEventCondCategory*)0x839dd0, (LEventCondCategory*)0x839e70, (LEventCondCategory*)0x839e40, (LEventCondCategory*)0x839de0, (LEventCondCategory*)0x839e30, (LEventCondCategory*)0x839e00, (LEventCondCategory*)0x839db0, (LEventCondCategory*)0x839d80, (LEventCondCategory*)0x839dc0, }, // Gog Categories{ (LEventCondCategory*)0x837dd0, (LEventCondCategory*)0x837e00, (LEventCondCategory*)0x837d40, (LEventCondCategory*)0x837dc0, (LEventCondCategory*)0x837da0, (LEventCondCategory*)0x837e10, (LEventCondCategory*)0x837d50, (LEventCondCategory*)0x837d20, (LEventCondCategory*)0x837d80, (LEventCondCategory*)0x837e20, (LEventCondCategory*)0x837df0, (LEventCondCategory*)0x837d90, (LEventCondCategory*)0x837de0, (LEventCondCategory*)0x837db0, (LEventCondCategory*)0x837d60, (LEventCondCategory*)0x837d30, (LEventCondCategory*)0x837d70, }, // Scenario Editor Categories{ (LEventCondCategory*)0x6653d0, (LEventCondCategory*)0x665400, (LEventCondCategory*)0x665340, (LEventCondCategory*)0x6653c0, (LEventCondCategory*)0x6653a0, (LEventCondCategory*)0x665410, (LEventCondCategory*)0x665350, (LEventCondCategory*)0x665320, (LEventCondCategory*)0x665380, (LEventCondCategory*)0x665420, (LEventCondCategory*)0x6653f0, (LEventCondCategory*)0x665390, (LEventCondCategory*)0x6653e0, (LEventCondCategory*)0x6653b0, (LEventCondCategory*)0x665360, (LEventCondCategory*)0x665330, (LEventCondCategory*)0x665370, }, }}; static std::array<const void*, 4> vftables = {{ // Akella (const void*)0x6ead4c, // Russobit (const void*)0x6ead4c, // Gog (const void*)0x6e8cec, // Scenario Editor (const void*)0x5cd1c4, }}; // clang-format on Categories& get() { return categories[static_cast<int>(hooks::gameVersion())]; } const void* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace EventCondCategories namespace LEventCondCategoryTableApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x58ee9f, (Api::Init)0x58f131, (Api::ReadCategory)0x58f1a9, (Api::InitDone)0x58f0ec, (Api::FindCategoryById)nullptr, }, // Russobit Api{ (Api::Constructor)0x58ee9f, (Api::Init)0x58f131, (Api::ReadCategory)0x58f1a9, (Api::InitDone)0x58f0ec, (Api::FindCategoryById)nullptr, }, // Gog Api{ (Api::Constructor)0x58dfb4, (Api::Init)0x58e246, (Api::ReadCategory)0x58e2be, (Api::InitDone)0x58e201, (Api::FindCategoryById)nullptr, }, // Scenario Editor Api{ (Api::Constructor)0x5305c9, (Api::Init)0x53085b, (Api::ReadCategory)0x5308d3, (Api::InitDone)0x530816, (Api::FindCategoryById)nullptr, }, }}; static std::array<const void*, 4> vftables = {{ // Akella (const void*)0x6ead54, // Russobit (const void*)0x6ead54, // Gog (const void*)0x6e8cf4, // Scenario Editor (const void*)0x5de2ec, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } const void* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace LEventCondCategoryTableApi } // namespace game
5,677
C++
.cpp
183
25.038251
72
0.677861
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,066
midclientcore.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/midclientcore.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "midclientcore.h" #include "version.h" #include <array> namespace game::CMidClientCoreApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::GetObjectMap)0x40fa2c, }, // Russobit Api{ (Api::GetObjectMap)0x40fa2c, }, // Gog Api{ (Api::GetObjectMap)0x40f646, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMidClientCoreApi
1,319
C++
.cpp
43
27.674419
72
0.717545
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,067
listbox.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/listbox.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "listbox.h" #include "version.h" #include <array> namespace game::CListBoxInterfApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::AssignFunctor)0x5c9b66, (Api::AssignDisplayTextFunctor)0x5c9982, (Api::AssignDisplaySurfaceFunctor)0x5c9ab0, (Api::SetElementsTotal)0x536047, (Api::SelectedIndex)0x5838db, (Api::SetSelectedIndex)0x536026, }, // Russobit Api{ (Api::AssignFunctor)0x5c9b66, (Api::AssignDisplayTextFunctor)0x5c9982, (Api::AssignDisplaySurfaceFunctor)0x5c9ab0, (Api::SetElementsTotal)0x536047, (Api::SelectedIndex)0x5838db, (Api::SetSelectedIndex)0x536026, }, // Gog Api{ (Api::AssignFunctor)0x5c8b34, (Api::AssignDisplayTextFunctor)0x5c8950, (Api::AssignDisplaySurfaceFunctor)0x5c8a7e, (Api::SetElementsTotal)0x535665, (Api::SelectedIndex)0x535361, (Api::SetSelectedIndex)0x535644, }, // Scenario Editor Api{ (Api::AssignFunctor)0, (Api::AssignDisplayTextFunctor)0x4d1524, (Api::AssignDisplaySurfaceFunctor)0x4d1652, (Api::SetElementsTotal)0x48d410, (Api::SelectedIndex)0x48d127, (Api::SetSelectedIndex)0x48d3ef, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CListBoxInterfApi
2,269
C++
.cpp
67
28.895522
72
0.703687
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,068
effectinterfhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/effectinterfhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "effectinterfhooks.h" #include "eventeffectcathooks.h" #include "originalfunctions.h" namespace hooks { game::editor::CEffectInterf* __stdcall createEffectInterfFromCategoryHooked( game::ITask* task, void* unknown, const game::CMidgardID* eventId, const game::LEventEffectCategory* category) { const auto& effects = customEventEffects(); const auto id = category->id; return getOriginalFunctions().createEffectInterfFromCategory(task, unknown, eventId, category); } } // namespace hooks
1,341
C++
.cpp
33
38.121212
99
0.766692
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,069
subracecat.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/subracecat.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "subracecat.h" #include "version.h" #include <array> namespace game { namespace SubraceCategories { // clang-format off static std::array<Categories, 4> categories = {{ // Akella Categories{ (LSubRaceCategory*)0x839b38, (LSubRaceCategory*)0x839b18, (LSubRaceCategory*)0x839af8, (LSubRaceCategory*)0x839bc0, (LSubRaceCategory*)0x839b68, (LSubRaceCategory*)0x839b48, (LSubRaceCategory*)0x839bd0, (LSubRaceCategory*)0x839b58, (LSubRaceCategory*)0x839b08, (LSubRaceCategory*)0x839b28, (LSubRaceCategory*)0x839ba8, (LSubRaceCategory*)0x839b78, (LSubRaceCategory*)0x839ae8, (LSubRaceCategory*)0x839b88, (LSubRaceCategory*)0x839b98 }, // Russobit Categories{ (LSubRaceCategory*)0x839b38, (LSubRaceCategory*)0x839b18, (LSubRaceCategory*)0x839af8, (LSubRaceCategory*)0x839bc0, (LSubRaceCategory*)0x839b68, (LSubRaceCategory*)0x839b48, (LSubRaceCategory*)0x839bd0, (LSubRaceCategory*)0x839b58, (LSubRaceCategory*)0x839b08, (LSubRaceCategory*)0x839b28, (LSubRaceCategory*)0x839ba8, (LSubRaceCategory*)0x839b78, (LSubRaceCategory*)0x839ae8, (LSubRaceCategory*)0x839b88, (LSubRaceCategory*)0x839b98 }, // Gog Categories{ (LSubRaceCategory*)0x837ae8, (LSubRaceCategory*)0x837ac8, (LSubRaceCategory*)0x837aa8, (LSubRaceCategory*)0x837b70, (LSubRaceCategory*)0x837b18, (LSubRaceCategory*)0x837af8, (LSubRaceCategory*)0x837b80, (LSubRaceCategory*)0x837b08, (LSubRaceCategory*)0x837ab8, (LSubRaceCategory*)0x837ad8, (LSubRaceCategory*)0x837b58, (LSubRaceCategory*)0x837b28, (LSubRaceCategory*)0x837a98, (LSubRaceCategory*)0x837b38, (LSubRaceCategory*)0x837b48 }, // Scenario Editor Categories{ (LSubRaceCategory*)0x665268, (LSubRaceCategory*)0x665248, (LSubRaceCategory*)0x665228, (LSubRaceCategory*)0x6652f0, (LSubRaceCategory*)0x665298, (LSubRaceCategory*)0x665278, (LSubRaceCategory*)0x665300, (LSubRaceCategory*)0x665288, (LSubRaceCategory*)0x665238, (LSubRaceCategory*)0x665258, (LSubRaceCategory*)0x6652d8, (LSubRaceCategory*)0x6652a8, (LSubRaceCategory*)0x665218, (LSubRaceCategory*)0x6652b8, (LSubRaceCategory*)0x6652c8 } }}; static std::array<const void*, 4> vftables = {{ // Akella (const void*)0x6d3634, // Russobit (const void*)0x6d3634, // Gog (const void*)0x6d15d4, // Scenario Editor (const void*)0x5d300c }}; // clang-format on Categories& get() { return categories[static_cast<int>(hooks::gameVersion())]; } const void* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace SubraceCategories namespace LSubRaceCategoryTableApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x58dba4, (Api::Init)0x58de08, (Api::ReadCategory)0x58de80, (Api::InitDone)0x58ddc3, (Api::FindCategoryById)0x599025, }, // Russobit Api{ (Api::Constructor)0x58dba4, (Api::Init)0x58de08, (Api::ReadCategory)0x58de80, (Api::InitDone)0x58ddc3, (Api::FindCategoryById)0x599025, }, // Gog Api{ (Api::Constructor)0x58ccb9, (Api::Init)0x58cf1d, (Api::ReadCategory)0x58cf95, (Api::InitDone)0x58ced8, (Api::FindCategoryById)0x59819a, }, // Scenario Editor Api{ (Api::Constructor)0x52fd87, (Api::Init)0x52ffeb, (Api::ReadCategory)0x530063, (Api::InitDone)0x52ffa6, (Api::FindCategoryById)0x4fbf66, } }}; static std::array<const void*, 4> vftables = {{ // Akella (const void*)0x6eaaac, // Russobit (const void*)0x6eaaac, // Gog (const void*)0x6e8a4c, // Scenario Editor (const void*)0x5de1bc }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } const void* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace LSubRaceCategoryTableApi } // namespace game
5,225
C++
.cpp
175
24.017143
72
0.670175
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,070
waitgenerationinterf.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/waitgenerationinterf.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "waitgenerationinterf.h" #include "button.h" #include "mempool.h" #include "menubase.h" namespace hooks { static void __fastcall waitCancelButtonHandler(WaitGenerationInterf* thisptr, int /*%edx*/) { thisptr->onCanceled(thisptr->menu); } WaitGenerationInterf* createWaitGenerationInterf(CMenuRandomScenario* menu, OnGenerationCanceled onCanceled) { using namespace game; static const char waitDialogName[] = "DLG_WAIT_GENERATION"; const auto& allocateMem{game::Memory::get().allocate}; auto* interf = (WaitGenerationInterf*)allocateMem(sizeof(WaitGenerationInterf)); CPopupDialogInterfApi::get().constructor(interf, waitDialogName, nullptr); interf->onCanceled = onCanceled; interf->menu = menu; CDialogInterf* dialog{*interf->dialog}; SmartPointer functor; auto callback = (CMenuBaseApi::Api::ButtonCallback)waitCancelButtonHandler; CMenuBaseApi::get().createButtonFunctor(&functor, 0, (CMenuBase*)interf, &callback); CButtonInterfApi::get().assignFunctor(dialog, "BTN_CANCEL", waitDialogName, &functor, 0); SmartPointerApi::get().createOrFreeNoDtor(&functor, nullptr); return interf; } } // namespace hooks
2,051
C++
.cpp
46
40.586957
93
0.747617
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,071
eventconditioncathooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/eventconditioncathooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "eventconditioncathooks.h" #include "dbf/dbffile.h" #include "log.h" #include "midgardid.h" #include "utils.h" #include <algorithm> #include <array> #include <fmt/format.h> namespace hooks { static const char* ownResourceCategoryName{"L_OWN_RESOURCE"}; static const char* gameModeCategoryName{"L_GAME_MODE"}; static const char* playerTypeCategoryName{"L_PLAYER_TYPE"}; static const char* variableCmpCategoryName{"L_VARIABLE_CMP"}; static const char* scriptCategoryName{"L_SCRIPT"}; CustomEventConditions& customEventConditions() { static CustomEventConditions customConditions{}; return customConditions; } static void readCustomCondition(const utils::DbfRecord& record, CustomEventCondition& condition) { const auto& idApi = game::CMidgardIDApi::get(); std::string info; record.value(info, "INFO"); idApi.fromString(&condition.infoText, info.c_str()); std::string brief; record.value(brief, "BRIEF"); idApi.fromString(&condition.brief, brief.c_str()); std::string descr; record.value(descr, "DESCR"); idApi.fromString(&condition.description, descr.c_str()); } static bool readCustomConditions(const std::filesystem::path& dbfFilePath) { utils::DbfFile dbf; if (!dbf.open(dbfFilePath)) { logError("mssProxyError.log", fmt::format("Could not open {:s}", dbfFilePath.filename().string())); return false; } bool customConditions{false}; const auto recordsTotal{dbf.recordsTotal()}; for (std::uint32_t i = 0; i < recordsTotal; ++i) { utils::DbfRecord record; if (!dbf.record(record, i)) { logError("mssProxyError.log", fmt::format("Could not read record {:d} from {:s}", i, dbfFilePath.filename().string())); return false; } if (record.isDeleted()) { continue; } std::string categoryName; record.value(categoryName, "TEXT"); categoryName = trimSpaces(categoryName); if (ownResourceCategoryName == categoryName) { readCustomCondition(record, customEventConditions().ownResource); customConditions = true; } else if (gameModeCategoryName == categoryName) { readCustomCondition(record, customEventConditions().gameMode); customConditions = true; } else if (playerTypeCategoryName == categoryName) { readCustomCondition(record, customEventConditions().playerType); customConditions = true; } else if (variableCmpCategoryName == categoryName) { readCustomCondition(record, customEventConditions().variableCmp); customConditions = true; } else if (scriptCategoryName == categoryName) { readCustomCondition(record, customEventConditions().script); customConditions = true; } } return customConditions; } game::LEventCondCategoryTable* __fastcall eventCondCategoryTableCtorHooked( game::LEventCondCategoryTable* thisptr, int /*%edx*/, const char* globalsFolderPath, void* codeBaseEnvProxy) { using namespace game; static const char dbfFileName[] = "LEvCond.dbf"; const auto dbfFilePath{std::filesystem::path(globalsFolderPath) / dbfFileName}; const bool customConditionsExist{readCustomConditions(dbfFilePath)}; thisptr->bgn = nullptr; thisptr->end = nullptr; thisptr->allocatedMemEnd = nullptr; thisptr->allocator = nullptr; thisptr->vftable = LEventCondCategoryTableApi::vftable(); const auto& table = LEventCondCategoryTableApi::get(); const auto& conditions = EventCondCategories::get(); table.init(thisptr, codeBaseEnvProxy, globalsFolderPath, dbfFileName); table.readCategory(conditions.frequency, thisptr, "L_FREQUENCY", dbfFileName); table.readCategory(conditions.location, thisptr, "L_LOCATION", dbfFileName); table.readCategory(conditions.enterCity, thisptr, "L_ENTER_CITY", dbfFileName); table.readCategory(conditions.ownCity, thisptr, "L_OWN_CITY", dbfFileName); table.readCategory(conditions.killStack, thisptr, "L_KILL_STACK", dbfFileName); table.readCategory(conditions.ownItem, thisptr, "L_OWN_ITEM", dbfFileName); table.readCategory(conditions.leaderOwnItem, thisptr, "L_LEADER_OWN_ITEM", dbfFileName); table.readCategory(conditions.diplomacy, thisptr, "L_DIPLOMACY", dbfFileName); table.readCategory(conditions.alliance, thisptr, "L_ALLIANCE", dbfFileName); table.readCategory(conditions.lootRuin, thisptr, "L_LOOT_RUIN", dbfFileName); table.readCategory(conditions.transformLand, thisptr, "L_TRANSFORM_LAND", dbfFileName); table.readCategory(conditions.visitSite, thisptr, "L_VISIT_SITE", dbfFileName); table.readCategory(conditions.leaderToZone, thisptr, "L_LEADER_TO_ZONE", dbfFileName); table.readCategory(conditions.leaderToCity, thisptr, "L_LEADER_TO_CITY", dbfFileName); table.readCategory(conditions.itemToLocation, thisptr, "L_ITEM_TO_LOCATION", dbfFileName); table.readCategory(conditions.stackExists, thisptr, "L_STACK_EXISTS", dbfFileName); table.readCategory(conditions.varInRange, thisptr, "L_VAR_IN_RANGE", dbfFileName); if (customConditionsExist) { table.readCategory(&customEventConditions().ownResource.category, thisptr, ownResourceCategoryName, dbfFileName); table.readCategory(&customEventConditions().gameMode.category, thisptr, gameModeCategoryName, dbfFileName); table.readCategory(&customEventConditions().playerType.category, thisptr, playerTypeCategoryName, dbfFileName); table.readCategory(&customEventConditions().variableCmp.category, thisptr, variableCmpCategoryName, dbfFileName); table.readCategory(&customEventConditions().script.category, thisptr, scriptCategoryName, dbfFileName); } table.initDone(thisptr); return thisptr; } } // namespace hooks
6,893
C++
.cpp
143
41.608392
97
0.713903
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,072
intset.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/intset.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "intset.h" #include "version.h" #include <array> namespace game::IntSetApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::Constructor)0x42904e, (Api::Destructor)0x416331, (Api::Clear)0x668710, (Api::Insert)0x477d8a, (Api::Erase)0x6686f0, }, // Russobit Api{ (Api::Constructor)0x42904e, (Api::Destructor)0x416331, (Api::Clear)0x668710, (Api::Insert)0x477d8a, (Api::Erase)0x6686f0, }, // Gog Api{ (Api::Constructor)0x428ada, (Api::Destructor)0x415fdc, (Api::Clear)0x667190, (Api::Insert)0x477985, (Api::Erase)0x667170, } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::IntSetApi
1,669
C++
.cpp
55
26.036364
72
0.680547
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,073
uievent.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/uievent.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "uievent.h" #include "version.h" #include <array> namespace game::UiEventApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::CopyConstructor)0x562081, (Api::Destructor)0x562050, }, // Russobit Api{ (Api::CopyConstructor)0x562081, (Api::Destructor)0x562050, }, // Gog Api{ (Api::CopyConstructor)0x56181e, (Api::Destructor)0x5617ed, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::UiEventApi
1,412
C++
.cpp
46
27.304348
72
0.707568
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,074
attacksourcecat.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/attacksourcecat.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "attacksourcecat.h" #include "version.h" #include <array> namespace game::AttackSourceCategories { // clang-format off static std::array<Categories, 4> categories = {{ // Akella Categories{ (LAttackSource*)0x839420, (LAttackSource*)0x839440, (LAttackSource*)0x839458, (LAttackSource*)0x839430, (LAttackSource*)0x839410, (LAttackSource*)0x8393e0, (LAttackSource*)0x839400, (LAttackSource*)0x8393f0 }, // Russobit Categories{ (LAttackSource*)0x839420, (LAttackSource*)0x839440, (LAttackSource*)0x839458, (LAttackSource*)0x839430, (LAttackSource*)0x839410, (LAttackSource*)0x8393e0, (LAttackSource*)0x839400, (LAttackSource*)0x8393f0 }, // Gog Categories{ (LAttackSource*)0x8373d0, (LAttackSource*)0x8373f0, (LAttackSource*)0x837408, (LAttackSource*)0x8373e0, (LAttackSource*)0x8373c0, (LAttackSource*)0x837390, (LAttackSource*)0x8373b0, (LAttackSource*)0x8373a0 }, // Scenario Editor Categories{ (LAttackSource*)0x665ba8, (LAttackSource*)0x665bc8, (LAttackSource*)0x665be0, (LAttackSource*)0x665bb8, (LAttackSource*)0x665b98, (LAttackSource*)0x665b68, (LAttackSource*)0x665b88, (LAttackSource*)0x665b78, }, }}; static std::array<const void*, 4> vftables = {{ // Akella (const void*)0x6cead4, // Russobit (const void*)0x6cead4, // Gog (const void*)0x6cca74, // Scenario Editor (const void*)0x5da8cc, }}; // clang-format on Categories& get() { return categories[static_cast<int>(hooks::gameVersion())]; } const void* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::AttackSourceCategories namespace game::LAttackSourceTableApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x585143, (Api::Init)0x585306, (Api::ReadCategory)0x58537e, (Api::InitDone)0x5852c1, (Api::FindCategoryById)0x40ad09, }, // Russobit Api{ (Api::Constructor)0x585143, (Api::Init)0x585306, (Api::ReadCategory)0x58537e, (Api::InitDone)0x5852c1, (Api::FindCategoryById)0x40ad09, }, // Gog Api{ (Api::Constructor)0x5842f6, (Api::Init)0x5844b9, (Api::ReadCategory)0x584531, (Api::InitDone)0x584474, (Api::FindCategoryById)0x40a995, }, // Scenario Editor Api{ (Api::Constructor)0x53bf3a, (Api::Init)0x53c0fd, (Api::ReadCategory)0x53c175, (Api::InitDone)0x53c0b8, (Api::FindCategoryById)0x4f2414, }, }}; static std::array<const void*, 4> vftables = {{ // Akella (const void*)0x6e9d5c, // Russobit (const void*)0x6e9d5c, // Gog (const void*)0x6e7cfc, // Scenario Editor (const void*)0x5df7dc, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } const void* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::LAttackSourceTableApi
4,093
C++
.cpp
145
22.937931
72
0.662262
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,075
custommodifiers.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/custommodifiers.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "custommodifiers.h" #include "dbffile.h" #include "log.h" #include "unitutils.h" #include "utils.h" #include <fmt/format.h> namespace hooks { void fillNativeModifiers(CustomModifiers::NativeMap& value) { using namespace game; const auto& idApi = CMidgardIDApi::get(); utils::DbfFile dbf; const auto dbfFilePath{globalsFolder() / "GUmodif.dbf"}; if (!dbf.open(dbfFilePath)) return; const auto recordsTotal{dbf.recordsTotal()}; for (std::uint32_t i = 0; i < recordsTotal; ++i) { utils::DbfRecord record; if (!dbf.record(record, i)) { logError("mssProxyError.log", fmt::format("Could not read record {:d} from {:s}", i, dbfFilePath.filename().string())); return; } if (record.isDeleted()) continue; std::string tmp; record.value(tmp, "UNIT_ID"); CMidgardID unitId; if (*idApi.fromString(&unitId, tmp.c_str()) == invalidId) { logError("mssProxyError.log", fmt::format("Could not read unit id '{:s}' from {:s}", tmp.c_str(), dbfFilePath.filename().string())); continue; } auto& modifiers = value[unitId.value]; for (int j = 1;; ++j) { if (!record.value(tmp, fmt::format("MODIF_{:d}", j))) break; tmp = trimSpaces(tmp); if (!tmp.size()) break; CMidgardID modifierId; if (*idApi.fromString(&modifierId, tmp.c_str()) == invalidId) { logError("mssProxyError.log", fmt::format("Could not read modifier id '{:s}' from {:s}", tmp.c_str(), dbfFilePath.filename().string())); break; } modifiers.push_back(modifierId); } } } void initializeCustomModifiers() { using namespace game; auto& value = getCustomModifiers(); value.group.id = (ModifierSourceId)emptyCategoryId; value.group.table = nullptr; value.group.vftable = LModifGroupApi::vftable(); fillNativeModifiers(value.native); } CustomModifiers& getCustomModifiers() { static CustomModifiers value{}; return value; } NativeModifiers getNativeModifiers(const game::CMidgardID& unitImplId) { using namespace game; NativeModifiers result; const auto& native = getCustomModifiers().native; auto it = native.find(emptyId.value); if (it != native.end()) result = it->second; it = native.find(getGlobalUnitImplId(&unitImplId).value); if (it != native.end()) result.insert(result.end(), it->second.begin(), it->second.end()); return result; } } // namespace hooks
3,638
C++
.cpp
98
29.632653
96
0.624467
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,076
menuflashwait.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/menuflashwait.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "menuflashwait.h" #include "version.h" #include <array> namespace game::CMenuFlashWaitApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::Constructor)0x4dcda8, }, // Russobit Api{ (Api::Constructor)0x4dcda8, }, // Gog Api{ (Api::Constructor)0x4dc41c, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMenuFlashWaitApi
1,315
C++
.cpp
43
27.581395
72
0.716654
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,077
lobbycallbacks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/lobbycallbacks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "lobbycallbacks.h" #include "lobbyclient.h" #include "log.h" #include "menucustomlobby.h" #include "roomclientjoin.h" #include <fmt/format.h> namespace hooks { void LoggingCallbacks::ExecuteDefaultResult(SLNet::Lobby2Message* msg) { SLNet::RakString str; msg->DebugMsg(str); logDebug("lobbyCallbacks.log", str.C_String()); } void UiUpdateCallbacks::MessageResult(SLNet::Client_Login* message) { switch (message->resultCode) { case SLNet::L2RC_SUCCESS: customLobbyProcessLogin(menuLobby, message->userName.C_String()); break; case SLNet::L2RC_Client_Login_HANDLE_NOT_IN_USE_OR_BAD_SECRET_KEY: customLobbyShowError("Wrong account name or password"); break; case SLNet::L2RC_Client_Login_BANNED: customLobbyShowError("Banned from server"); break; default: { SLNet::RakString str; message->DebugMsg(str); customLobbyShowError(str.C_String()); break; } } } void UiUpdateCallbacks::MessageResult(SLNet::Client_Logoff* message) { if (message->resultCode == SLNet::L2RC_SUCCESS) { customLobbyProcessLogout(menuLobby); return; } SLNet::RakString str; message->DebugMsg(str); customLobbyShowError(str.C_String()); } void RoomsListCallbacks::JoinByFilter_Callback(const SLNet::SystemAddress&, SLNet::JoinByFilter_Func* callResult) { if (callResult->resultCode == SLNet::REC_SUCCESS) { auto& room = callResult->joinedRoomResult.roomDescriptor; auto roomName = room.GetProperty(DefaultRoomColumns::TC_ROOM_NAME)->c; logDebug("roomsCallbacks.log", fmt::format("{:s} joined room", callResult->joinedRoomResult.joiningMemberName.C_String())); const char* guidString{nullptr}; auto& table = room.roomProperties; auto index = table.ColumnIndex(serverGuidColumnName); if (index != std::numeric_limits<unsigned int>::max()) { auto row = table.GetRowByIndex(0, nullptr); if (row) { guidString = row->cells[index]->c; } } SLNet::RakNetGUID serverGuid{}; if (!serverGuid.FromString(guidString)) { customLobbyProcessJoinError(menuLobby, "Could not get player server GUID"); return; } customLobbyProcessJoin(menuLobby, roomName, serverGuid); return; } auto error = SLNet::RoomsErrorCodeDescription::ToEnglish(callResult->resultCode); customLobbyProcessJoinError(menuLobby, error); } void RoomsListCallbacks::SearchByFilter_Callback(const SLNet::SystemAddress&, SLNet::SearchByFilter_Func* callResult) { if (callResult->resultCode != SLNet::REC_SUCCESS) { customLobbyShowError(SLNet::RoomsErrorCodeDescription::ToEnglish(callResult->resultCode)); return; } auto& rooms = callResult->roomsOutput; const auto total{rooms.Size()}; std::vector<RoomInfo> roomsInfo; roomsInfo.reserve(total); for (std::uint32_t i = 0; i < total; ++i) { auto room = rooms[i]; auto name = room->GetProperty(DefaultRoomColumns::TC_ROOM_NAME)->c; const char* hostName{nullptr}; auto& members = room->roomMemberList; for (std::uint32_t j = 0; members.Size(); ++j) { auto& member = members[j]; if (member.roomMemberMode == RMM_MODERATOR) { hostName = member.name.C_String(); break; } } auto totalSlots = (int)room->GetProperty(DefaultRoomColumns::TC_TOTAL_PUBLIC_SLOTS)->i; auto usedSlots = (int)room->GetProperty(DefaultRoomColumns::TC_USED_PUBLIC_SLOTS)->i; const char* password{nullptr}; auto& table = room->roomProperties; auto index = table.ColumnIndex(passwordColumnName); if (index != std::numeric_limits<unsigned int>::max()) { auto row = table.GetRowByIndex(0, nullptr); if (row) { password = row->cells[index]->c; } } // Add 1 to used and total slots because they are not counting room moderator roomsInfo.push_back(RoomInfo{std::string(name), std::string{hostName ? hostName : "Unknown"}, password ? std::string{password} : std::string{}, totalSlots + 1, usedSlots + 1}); } customLobbySetRoomsInfo(menuLobby, std::move(roomsInfo)); } } // namespace hooks
5,460
C++
.cpp
133
32.954887
98
0.647914
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,078
mapgraphics.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/mapgraphics.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "mapgraphics.h" #include "version.h" #include <array> namespace game::MapGraphicsApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::GetMapGraphics)0x540e28, (Api::SetMapGraphics)0x407f37, (Api::GetTileIndex)0x541e15, (Api::SetOutOfBordersTileIndex)0x541e65, (Api::ShowImageOnMap)0x5adf66, (Api::HideLayerImages)0x5ae08a, }, // Russobit Api{ (Api::GetMapGraphics)0x540e28, (Api::SetMapGraphics)0x407f37, (Api::GetTileIndex)0x541e15, (Api::SetOutOfBordersTileIndex)0x541e65, (Api::ShowImageOnMap)0x5adf66, (Api::HideLayerImages)0x5ae08a, }, // Gog Api{ (Api::GetMapGraphics)0x5404d9, (Api::SetMapGraphics)0x407be5, (Api::GetTileIndex)0x5414c5, (Api::SetOutOfBordersTileIndex)0x541515, (Api::ShowImageOnMap)0x5ad1ee, (Api::HideLayerImages)0x5ad312, }, // Scenario Editor Api{ (Api::GetMapGraphics)0x49aac3, (Api::SetMapGraphics)0x4044be, (Api::GetTileIndex)0x49ba3f, (Api::SetOutOfBordersTileIndex)0x49ba8f, (Api::ShowImageOnMap)0x554042, (Api::HideLayerImages)0x55411d, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::MapGraphicsApi
2,210
C++
.cpp
67
28.014925
72
0.69551
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,079
midcondscript.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/midcondscript.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "midcondscript.h" #include "bindings/scenarioview.h" #include "button.h" #include "condinterf.h" #include "condinterfhandler.h" #include "d2string.h" #include "dialoginterf.h" #include "editboxinterf.h" #include "editor.h" #include "eventconditioncathooks.h" #include "game.h" #include "interfmanager.h" #include "listbox.h" #include "log.h" #include "mempool.h" #include "midbag.h" #include "midevcondition.h" #include "midevent.h" #include "midgardobjectmap.h" #include "midgardstream.h" #include "radiobuttoninterf.h" #include "scripts.h" #include "testcondition.h" #include "textboxinterf.h" #include "utils.h" #include <Windows.h> #include <fmt/format.h> #include <string> namespace hooks { static const std::string scriptSignature{"function checkEventCondition(scenario)"}; /** Custom event condition which logic is controlled entirely by lua script. */ struct CMidCondScript : public game::CMidEvCondition { std::string code; std::string description; }; void __fastcall condScriptDestructor(CMidCondScript* thisptr, int /*%edx*/, char flags) { // Manually call the destructors thisptr->code.~basic_string(); thisptr->description.~basic_string(); if (flags & 1) { game::Memory::get().freeNonZero(thisptr); } } bool __fastcall condScriptIsIdsEqual(const CMidCondScript*, int /*%edx*/, const game::CMidgardID*) { return false; } void __fastcall condScriptAddToList(const CMidCondScript*, int /*%edx*/, game::Set<game::CMidgardID>*) { } bool __fastcall condScriptIsValid(const CMidCondScript* thisptr, int /*%edx*/, const game::IMidgardObjectMap*) { return true; } bool __fastcall condScriptMethod4(const CMidCondScript*, int /*%edx*/, int) { return false; } void __fastcall condScriptStream(CMidCondScript* thisptr, int /*%edx*/, game::IMidgardStream** stream) { auto streamPtr = *stream; auto vftable = streamPtr->vftable; int codeLength = static_cast<int>(thisptr->code.size()); vftable->streamInt(streamPtr, "CODE_LEN", &codeLength); if (vftable->readMode(streamPtr)) { thisptr->code.resize(codeLength); } vftable->streamString(streamPtr, "CODE", thisptr->code.data()); int descrLength = static_cast<int>(thisptr->description.size()); vftable->streamInt(streamPtr, "DESCR_LEN", &descrLength); if (vftable->readMode(streamPtr)) { thisptr->description.resize(descrLength); } vftable->streamString(streamPtr, "DESCR", thisptr->description.data()); } // clang-format off static game::CMidEvConditionVftable condScriptVftable{ (game::CMidEvConditionVftable::Destructor)condScriptDestructor, (game::CMidEvConditionVftable::IsIdsEqual)condScriptIsIdsEqual, (game::CMidEvConditionVftable::AddToList)condScriptAddToList, (game::CMidEvConditionVftable::IsValid)condScriptIsValid, (game::CMidEvConditionVftable::Method4)condScriptMethod4, (game::CMidEvConditionVftable::Stream)condScriptStream, }; // clang-format on game::CMidEvCondition* createMidCondScript() { using namespace game; auto script = (CMidCondScript*)Memory::get().allocate(sizeof(CMidCondScript)); std::memset(script, 0, sizeof(CMidCondScript)); script->category.vftable = EventCondCategories::vftable(); script->category.id = customEventConditions().script.category.id; script->category.table = customEventConditions().script.category.table; std::string().swap(script->code); std::string().swap(script->description); script->vftable = &condScriptVftable; return script; } void __stdcall midCondScriptGetInfoString(game::String* info, const game::IMidgardObjectMap* objectMap, const game::CMidEvCondition* eventCondition) { const auto textInfoId = &customEventConditions().script.infoText; std::string str{game::gameFunctions().getInterfaceText(textInfoId)}; replace(str, "%DESC%", static_cast<const CMidCondScript*>(eventCondition)->description); game::StringApi::get().initFromStringN(info, str.c_str(), str.length()); } /** Toggle button indices, must match with RAD_FILTER in DLG_COND_SCRIPT in ScenEdit.dlg. */ enum class ObjectFilter : int { Stack, City, Ruin, Location, Bag, Other, }; using IdVector = std::vector<game::CMidgardID>; struct CCondScriptInterf : public game::editor::CCondInterf { void* unknown; CMidCondScript* condition; game::CMidgardID eventId; IdVector stacks; IdVector cities; IdVector ruins; IdVector locations; IdVector bags; }; void __fastcall condScriptInterfDestructor(CCondScriptInterf* thisptr, int /*%edx*/, char flags) { // Manually call destructors thisptr->stacks.~vector(); thisptr->cities.~vector(); thisptr->ruins.~vector(); thisptr->locations.~vector(); thisptr->bags.~vector(); if (flags & 1) { game::Memory::get().freeNonZero(thisptr); } } static game::CInterfaceVftable::OnVisibilityChanged onVisibilityChanged{}; void __fastcall condScriptInterfOnVisibilityChanged(CCondScriptInterf* thisptr, int /*%edx*/, int a2, int a3) { using namespace game; if (onVisibilityChanged) { onVisibilityChanged(thisptr, a2, a3); } if (!a2) { return; } if (!thisptr->condition) { return; } auto dialog = thisptr->popupData->dialog; const auto& dialogApi = CDialogInterfApi::get(); auto editBox = dialogApi.findEditBox(dialog, "EDIT_CODE"); if (editBox) { CEditBoxInterfApi::get().setString(editBox, thisptr->condition->code.c_str()); } auto editComment = dialogApi.findEditBox(dialog, "EDIT_COMMENT"); if (editComment) { CEditBoxInterfApi::get().setString(editComment, thisptr->condition->description.c_str()); } } bool __fastcall condScriptInterfSetEventCondition(CCondScriptInterf* thisptr, int /*%edx*/, game::CMidEvCondition* eventCondition) { if (eventCondition->category.id == customEventConditions().script.category.id) { thisptr->condition = static_cast<CMidCondScript*>(eventCondition); return true; } return false; } static game::editor::CCondInterfVftable condScriptInterfVftable{}; void __fastcall condScriptInterfCancelButtonHandler(CCondScriptInterf* thisptr, int /*%edx*/) { using namespace game; auto handler = thisptr->condData->interfHandler; if (handler) { handler->vftable->runCallback(handler, false); } InterfManagerImplPtr ptr; CInterfManagerImplApi::get().get(&ptr); ptr.data->CInterfManagerImpl::CInterfManager::vftable->hideInterface(ptr.data, thisptr); SmartPointerApi::get().createOrFree((SmartPointer*)&ptr, nullptr); if (thisptr) { thisptr->CInterface::vftable->destructor(thisptr, 1); } } void __fastcall condScriptInterfOkButtonHandler(CCondScriptInterf* thisptr, int /*%edx*/) { using namespace game; using namespace editor; auto dialog = thisptr->popupData->dialog; const auto& dialogApi = CDialogInterfApi::get(); auto editBox = dialogApi.findEditBox(dialog, "EDIT_CODE"); if (!editBox) { return; } const auto& code = editBox->data->editBoxData.inputString; if (!code.length) { return; } auto handler = thisptr->condData->interfHandler; if (handler) { handler->vftable->runCallback(handler, true); } auto objectMap = CCondInterfApi::get().getObjectMap(thisptr->unknown); { auto midEvent = (const CMidEvent*)objectMap->vftable ->findScenarioObjectById(objectMap, &thisptr->eventId); const int conditionsTotal = midEvent->conditions.end - midEvent->conditions.bgn; if (conditionsTotal >= 10) { // Could not create new condition showMessageBox(getInterfaceText("X100TA0631")); return; } } auto condition = static_cast<CMidCondScript*>(createMidCondScript()); condition->code = std::string(code.string); auto editComment = dialogApi.findEditBox(dialog, "EDIT_COMMENT"); if (editComment) { // Condition description is optional auto& comment = editComment->data->editBoxData.inputString; if (comment.length) { condition->description = std::string(comment.string); } } auto midEvent = (CMidEvent*)objectMap->vftable ->findScenarioObjectByIdForChange(objectMap, &thisptr->eventId); CMidEventApi::get().addCondition(midEvent, nullptr, condition); InterfManagerImplPtr ptr; CInterfManagerImplApi::get().get(&ptr); ptr.data->CInterfManagerImpl::CInterfManager::vftable->hideInterface(ptr.data, thisptr); SmartPointerApi::get().createOrFree((SmartPointer*)&ptr, nullptr); if (thisptr) { thisptr->CInterface::vftable->destructor(thisptr, 1); } } void __fastcall condScriptInterfLoadButtonHandler(CCondScriptInterf* thisptr, int /*%edx*/) { using namespace game; auto dialog = thisptr->popupData->dialog; const auto& dialogApi = CDialogInterfApi::get(); auto editBox = dialogApi.findEditBox(dialog, "EDIT_CODE"); if (!editBox) { return; } std::string script; if (readUserSelectedFile(script, "Lua scripts (*.lua)\0*.lua\0\0", scriptsFolder().string().c_str())) { CEditBoxInterfApi::get().setString(editBox, script.c_str()); } } static const IdVector* getObjectIds(const CCondScriptInterf* interf, ObjectFilter filter) { switch (filter) { case ObjectFilter::Stack: return &interf->stacks; case ObjectFilter::City: return &interf->cities; case ObjectFilter::Ruin: return &interf->ruins; case ObjectFilter::Location: return &interf->locations; case ObjectFilter::Bag: return &interf->bags; } return nullptr; } void __fastcall condScriptInterfPasteIdButtonHandler(CCondScriptInterf* thisptr, int /*%edx*/) { using namespace game; auto dialog = thisptr->popupData->dialog; const auto& dialogApi = CDialogInterfApi::get(); auto editBox = dialogApi.findEditBox(dialog, "EDIT_CODE"); if (!editBox) { return; } const auto& listApi = CListBoxInterfApi::get(); auto listBox = dialogApi.findListBox(dialog, "TLBOX_OBJECTS"); if (!listBox) { return; } auto radioButton = CDialogInterfApi::get().findRadioButton(dialog, "RAD_FILTER"); if (!radioButton) { return; } auto* ids = getObjectIds(thisptr, (ObjectFilter)radioButton->data->selectedButton); if (!ids) { return; } const auto selectedIndex = CListBoxInterfApi::get().selectedIndex(listBox); const auto total = static_cast<int>(ids->size()); if (selectedIndex < 0 || selectedIndex >= total) { return; } const CMidgardID* objectId = &(*ids)[selectedIndex]; const auto idString{fmt::format("'{:s}'", idToString(objectId))}; std::string code{editBox->data->editBoxData.inputString.string}; const auto cursor = editBox->data->editBoxData.editCursorPos; code.insert(cursor, idString); const auto& editBoxApi = CEditBoxInterfApi::get(); editBoxApi.setString(editBox, code.c_str()); // Set cursor position after inserted id string editBox->data->editBoxData.editCursorPos = cursor + idString.size(); editBoxApi.updateFocus(editBox->data->editBoxFocus.data); editBoxApi.update(editBox); } void __fastcall condScriptInterfDocsButtonHandler(CCondScriptInterf* thisptr, int /*%edx*/) { ShellExecute(nullptr, "open", "https://github.com/VladimirMakeev/D2ModdingToolset/blob/master/luaApi.md", nullptr, nullptr, SW_SHOWNORMAL); } void __fastcall condScriptInterfOnFilterChanged(CCondScriptInterf* thisptr, int /*%edx*/, int selectedButton) { using namespace game; auto dialog = thisptr->popupData->dialog; const auto& listApi = CListBoxInterfApi::get(); auto listBox = CDialogInterfApi::get().findListBox(dialog, "TLBOX_OBJECTS"); if (!listBox) { return; } auto* ids = getObjectIds(thisptr, (ObjectFilter)selectedButton); CListBoxInterfApi::get().setElementsTotal(listBox, ids ? static_cast<int>(ids->size()) : 0); } void __fastcall condScriptInterfStackListBoxDisplayHandler(CCondScriptInterf* thisptr, int /*%edx*/, game::String* string, bool a3, int selectedIndex) { using namespace game; using namespace editor; auto dialog = thisptr->popupData->dialog; auto radioButton = CDialogInterfApi::get().findRadioButton(dialog, "RAD_FILTER"); if (!radioButton) { return; } const auto filter = (ObjectFilter)radioButton->data->selectedButton; auto* ids = getObjectIds(thisptr, filter); if (!ids) { return; } const auto total = static_cast<int>(ids->size()); if (selectedIndex < 0 || selectedIndex >= total) { return; } auto objectMap = CCondInterfApi::get().getObjectMap(thisptr->unknown); const CMidgardID* objectId = &(*ids)[selectedIndex]; if (filter == ObjectFilter::Bag) { auto bag = (const CMidBag*)objectMap->vftable->findScenarioObjectById(objectMap, objectId); if (!bag) { // This should never happen return; } const auto& pos = bag->mapElement.position; const auto description{ fmt::format("{:s} ({:d}, {:d})", idToString(objectId), pos.x, pos.y)}; StringApi::get().initFromStringN(string, description.c_str(), description.size()); return; } String tmp{}; editorFunctions.getObjectNamePos(&tmp, objectMap, objectId); if (tmp.string != string->string) { StringApi::get().initFromStringN(string, tmp.string, tmp.length); } StringApi::get().free(&tmp); } game::editor::CCondInterf* createCondScriptInterf(game::ITask* task, void* a2, const game::CMidgardID* eventId) { using namespace game; using namespace editor; auto thisptr = (CCondScriptInterf*)Memory::get().allocate(sizeof(CCondScriptInterf)); std::memset(thisptr, 0, sizeof(CCondScriptInterf)); static const char dialogName[]{"DLG_COND_SCRIPT"}; CCondInterfApi::get().constructor(thisptr, dialogName, task); static bool initialized{false}; if (!initialized) { initialized = true; onVisibilityChanged = thisptr->CInterface::vftable->onVisibilityChanged; std::memcpy(&condScriptInterfVftable, thisptr->CInterface::vftable, sizeof(CInterfaceVftable)); // Change methods that are specific for our custom class condScriptInterfVftable .destructor = (CInterfaceVftable::Destructor)&condScriptInterfDestructor; condScriptInterfVftable .onVisibilityChanged = (CInterfaceVftable:: OnVisibilityChanged)&condScriptInterfOnVisibilityChanged; condScriptInterfVftable .setEventCondition = (CCondInterfVftable:: SetEventCondition)&condScriptInterfSetEventCondition; } thisptr->CInterface::vftable = &condScriptInterfVftable; thisptr->eventId = *eventId; thisptr->unknown = a2; thisptr->condition = nullptr; auto objectMap = CCondInterfApi::get().getObjectMap(thisptr->unknown); IdVector stacks; forEachScenarioObject(objectMap, IdType::Stack, [&stacks](const IMidScenarioObject* obj) { stacks.push_back(obj->id); }); stacks.swap(thisptr->stacks); IdVector cities; forEachScenarioObject(objectMap, IdType::Fortification, [&cities](const IMidScenarioObject* obj) { cities.push_back(obj->id); }); cities.swap(thisptr->cities); IdVector ruins; forEachScenarioObject(objectMap, IdType::Ruin, [&ruins](const IMidScenarioObject* obj) { ruins.push_back(obj->id); }); ruins.swap(thisptr->ruins); IdVector locations; forEachScenarioObject(objectMap, IdType::Location, [&locations](const IMidScenarioObject* obj) { locations.push_back(obj->id); }); locations.swap(thisptr->locations); IdVector bags; forEachScenarioObject(objectMap, IdType::Bag, [&bags](const IMidScenarioObject* obj) { bags.push_back(obj->id); }); bags.swap(thisptr->bags); auto dialog = thisptr->popupData->dialog; const auto& dialogApi = CDialogInterfApi::get(); if (dialogApi.findButton(dialog, "BTN_OK")) { using ButtonCallback = CCondInterfApi::Api::ButtonCallback; ButtonCallback callback{}; SmartPointer functor{}; callback.callback = (ButtonCallback::Callback)condScriptInterfOkButtonHandler; CCondInterfApi::get().createButtonFunctor(&functor, 0, thisptr, &callback); const auto& button = CButtonInterfApi::get(); button.assignFunctor(dialog, "BTN_OK", dialogName, &functor, 0); SmartPointerApi::get().createOrFreeNoDtor(&functor, nullptr); } if (dialogApi.findButton(dialog, "BTN_CANCEL")) { using ButtonCallback = CCondInterfApi::Api::ButtonCallback; ButtonCallback callback{}; SmartPointer functor{}; callback.callback = (ButtonCallback::Callback)condScriptInterfCancelButtonHandler; CCondInterfApi::get().createButtonFunctor(&functor, 0, thisptr, &callback); const auto& button = CButtonInterfApi::get(); button.assignFunctor(dialog, "BTN_CANCEL", dialogName, &functor, 0); SmartPointerApi::get().createOrFreeNoDtor(&functor, nullptr); } if (dialogApi.findButton(dialog, "BTN_LOAD")) { using ButtonCallback = CCondInterfApi::Api::ButtonCallback; ButtonCallback callback{}; SmartPointer functor{}; callback.callback = (ButtonCallback::Callback)condScriptInterfLoadButtonHandler; CCondInterfApi::get().createButtonFunctor(&functor, 0, thisptr, &callback); const auto& button = CButtonInterfApi::get(); button.assignFunctor(dialog, "BTN_LOAD", dialogName, &functor, 0); SmartPointerApi::get().createOrFreeNoDtor(&functor, nullptr); } if (dialogApi.findButton(dialog, "BTN_PASTE_ID")) { using ButtonCallback = CCondInterfApi::Api::ButtonCallback; ButtonCallback callback{}; SmartPointer functor{}; callback.callback = (ButtonCallback::Callback)condScriptInterfPasteIdButtonHandler; CCondInterfApi::get().createButtonFunctor(&functor, 0, thisptr, &callback); const auto& button = CButtonInterfApi::get(); button.assignFunctor(dialog, "BTN_PASTE_ID", dialogName, &functor, 0); SmartPointerApi::get().createOrFreeNoDtor(&functor, nullptr); } if (dialogApi.findButton(dialog, "BTN_DOCS")) { using ButtonCallback = CCondInterfApi::Api::ButtonCallback; ButtonCallback callback{}; SmartPointer functor{}; callback.callback = (ButtonCallback::Callback)condScriptInterfDocsButtonHandler; CCondInterfApi::get().createButtonFunctor(&functor, 0, thisptr, &callback); const auto& button = CButtonInterfApi::get(); button.assignFunctor(dialog, "BTN_DOCS", dialogName, &functor, 0); SmartPointerApi::get().createOrFreeNoDtor(&functor, nullptr); } const auto& radioApi = CRadioButtonInterfApi::get(); auto radioButton = dialogApi.findRadioButton(dialog, "RAD_FILTER"); if (radioButton) { radioApi.setCheckedButton(radioButton, (int)ObjectFilter::Stack); using Callback = CCondInterfApi::Api::RadioButtonCallback; Callback callback{}; SmartPointer functor{}; callback.callback = (Callback::Callback)condScriptInterfOnFilterChanged; CCondInterfApi::get().createRadioButtonFunctor(&functor, 0, thisptr, &callback); radioApi.setOnButtonPressed(dialog, "RAD_FILTER", dialogName, &functor); SmartPointerApi::get().createOrFreeNoDtor(&functor, nullptr); // Disable button since 'other' list is not implemented yet radioApi.setButtonEnabled(radioButton, (int)ObjectFilter::Other, false); } const auto& listApi = CListBoxInterfApi::get(); auto listBox = dialogApi.findListBox(dialog, "TLBOX_OBJECTS"); if (listBox) { using ListBoxCallback = CCondInterfApi::Api::ListBoxDisplayCallback; ListBoxCallback callback{}; SmartPointer functor{}; callback.callback = (ListBoxCallback::Callback)condScriptInterfStackListBoxDisplayHandler; CCondInterfApi::get().createListBoxDisplayFunctor(&functor, 0, thisptr, &callback); listApi.assignDisplayTextFunctor(dialog, "TLBOX_OBJECTS", dialogName, &functor, false); SmartPointerApi::get().createOrFreeNoDtor(&functor, nullptr); // Init with stacks, since its toggle button selected by default listApi.setElementsTotal(listBox, thisptr->stacks.size()); } auto signature = dialogApi.findTextBox(dialog, "TXT_SIGNATURE"); if (signature) { CTextBoxInterfApi::get().setString(signature, scriptSignature.c_str()); } CEditBoxInterfApi::get().setFilterAndLength(dialog, "EDIT_CODE", dialogName, EditFilter::NoFilter, 4096); // Disable buttons that are not implemented yet auto objectives = dialogApi.findButton(dialog, "BTN_OBJECTIVES"); if (objectives) { objectives->vftable->setEnabled(objectives, false); } auto buttonCheck = dialogApi.findButton(dialog, "BTN_CHECK"); if (buttonCheck) { buttonCheck->vftable->setEnabled(buttonCheck, false); } auto codeUp = dialogApi.findButton(dialog, "BTN_CODE_UP"); if (codeUp) { codeUp->vftable->setEnabled(codeUp, false); } auto codeDown = dialogApi.findButton(dialog, "BTN_CODE_DOWN"); if (codeDown) { codeDown->vftable->setEnabled(codeDown, false); } return thisptr; } struct CTestScript : public game::ITestCondition { CMidCondScript* condition; }; void __fastcall testScriptDestructor(CTestScript* thisptr, int /*%edx*/, char flags) { if (flags & 1) { game::Memory::get().freeNonZero(thisptr); } } bool __fastcall testScriptDoTest(const CTestScript* thisptr, int /*%edx*/, const game::IMidgardObjectMap* objectMap, const game::CMidgardID* playerId, const game::CMidgardID* eventId) { const auto& body = thisptr->condition->code; if (body.empty()) { return false; } const auto code{fmt::format("{:s}\n{:s}\nend\n", scriptSignature, body)}; sol::protected_function_result result; auto env = executeScript(code, result); if (!result.valid()) { const sol::error err = result; logError("mssProxyError.log", fmt::format("Failed to load scriptable event condition.\n" "Event id {:s}\n" "Description: '{:s}'\n" "Script:\n'{:s}'\n" "Reason: '{:s}'", idToString(eventId), thisptr->condition->description, code, err.what())); return false; } auto checkCondition = getProtectedScriptFunction(env, "checkEventCondition", true); if (!checkCondition) { // Sanity check, this should never happen return false; } const bindings::ScenarioView scenario{objectMap}; result = (*checkCondition)(scenario); if (!result.valid()) { const sol::error err = result; logError("mssProxyError.log", fmt::format("Failed to execute scriptable event condition.\n" "Event id {:s}\n" "Description: '{:s}'\n" "Script:\n'{:s}'\n" "Reason: '{:s}'", idToString(eventId), thisptr->condition->description, code, err.what())); return false; } return result; } static game::ITestConditionVftable testScriptVftable{ (game::ITestConditionVftable::Destructor)testScriptDestructor, (game::ITestConditionVftable::Test)testScriptDoTest, }; game::ITestCondition* createTestScript(game::CMidEvCondition* eventCondition) { auto thisptr = (CTestScript*)game::Memory::get().allocate(sizeof(CTestScript)); thisptr->condition = static_cast<CMidCondScript*>(eventCondition); thisptr->vftable = &testScriptVftable; return thisptr; } } // namespace hooks
26,459
C++
.cpp
625
34.3584
100
0.661254
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,080
encparambase.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/encparambase.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "encparambase.h" #include "version.h" #include <array> namespace game::CEncParamBaseApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::AddUnitBattleInfo)0x63b1a1, (Api::GetData)0x57437a, (Api::SetData)0x574342, }, // Russobit Api{ (Api::AddUnitBattleInfo)0x63b1a1, (Api::GetData)0x57437a, (Api::SetData)0x574342, }, // Gog Api{ (Api::AddUnitBattleInfo)0x639be1, (Api::GetData)0x5739cc, (Api::SetData)0x573994, }, // Scenario Editor Api{ (Api::AddUnitBattleInfo)nullptr, (Api::GetData)0x4c4ddb, (Api::SetData)nullptr, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CEncParamBaseApi
1,666
C++
.cpp
55
26.2
72
0.691781
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,081
enclayoutunithooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/enclayoutunithooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "enclayoutunithooks.h" #include "buildingtype.h" #include "categorylist.h" #include "custommodifier.h" #include "custommodifiers.h" #include "dialoginterf.h" #include "dynupgrade.h" #include "enclayoutunit.h" #include "encparambase.h" #include "encunitdescriptor.h" #include "gameimages.h" #include "gameutils.h" #include "imageptrvector.h" #include "interfaceutils.h" #include "intvector.h" #include "listbox.h" #include "mempool.h" #include "midplayer.h" #include "midunitdescriptor.h" #include "modifierutils.h" #include "mqimage2.h" #include "originalfunctions.h" #include "pictureinterf.h" #include "racetype.h" #include "restrictions.h" #include "settings.h" #include "stringarray.h" #include "textboxinterf.h" #include "textids.h" #include "unitmodifier.h" #include "unittypedescriptor.h" #include "unitutils.h" #include "usunitimpl.h" #include "utils.h" namespace hooks { static const char modifiersTextBoxName[] = "TXT_MODIFIERS"; static const char modifiersListBoxName[] = "LBOX_MODIFIERS"; struct CEncLayoutUnitDataPatched : game::CEncLayoutUnitData { game::Vector<game::SmartPtr<game::IMqImage2>> modifierIcons; game::Vector<game::String> modifierTexts; game::AttackSourceImmunityStatusesPatched attackSourceImmunityStatuses; std::uint32_t attackClassImmunityStatuses; }; game::IEncUnitDescriptor* createUnitDescriptor(const game::IMidgardObjectMap* objectMap, const game::CMidgardID* unitId, const game::CMidgardID* playerId) { using namespace game; const auto& memAlloc = Memory::get().allocate; switch (CMidgardIDApi::get().getType(unitId)) { case IdType::Unit: { auto descriptor = (CMidUnitDescriptor*)memAlloc(sizeof(CMidUnitDescriptor)); CMidUnitDescriptorApi::get().constructor(descriptor, objectMap, unitId, playerId); return descriptor; } case IdType::UnitGlobal: case IdType::UnitGenerated: { auto descriptor = (CUnitTypeDescriptor*)memAlloc(sizeof(CUnitTypeDescriptor)); descriptor->vftable = CUnitTypeDescriptorApi::vftable(); descriptor->unitImplId = *unitId; return descriptor; } } return nullptr; } game::CEncLayoutUnitData* createData(const game::IMidgardObjectMap* objectMap, const game::CMidgardID* unitId, game::IEncUnitDescriptor* descriptor) { using namespace game; const auto& memAlloc = Memory::get().allocate; auto data = (CEncLayoutUnitDataPatched*)memAlloc(sizeof(CEncLayoutUnitDataPatched)); CEncLayoutUnitApi::get().dataConstructor(data); data->unitId = *unitId; data->objectMap = objectMap; data->shatteredArmor = 0; data->fortificationArmor = 0; data->unitDescriptor = descriptor; return data; } void addModifierInfo(game::CEncLayoutUnit* layout, hooks::CCustomModifier* modifier, bool native) { using namespace game; const auto& stringApi = game::StringApi::get(); const auto& smartPtrApi = SmartPointerApi::get(); auto data = (CEncLayoutUnitDataPatched*)layout->data; IMqImage2* icon = nullptr; GameImagesApi::get().getIconImageByName(&icon, modifier->getIconName().c_str()); ImagePtr iconPtr{}; smartPtrApi.createOrFree((SmartPointer*)&iconPtr, icon); ImagePtrVectorApi::get().pushBack(&data->modifierIcons, &iconPtr); smartPtrApi.createOrFree((SmartPointer*)&iconPtr, nullptr); std::string format; if (native) { format = getInterfaceText(textIds().interf.nativeModifierDescription.c_str()); if (format.empty()) format = "\\vC;\\fMedBold;%DESC%\\fNormal;"; } else { format = getInterfaceText(textIds().interf.modifierDescription.c_str()); if (format.empty()) format = "\\vC;%DESC%"; } replace(format, "%DESC%", getGlobalText(modifier->getDescTxt())); String text{}; stringApi.initFromString(&text, format.c_str()); StringArrayApi::get().pushBack(&data->modifierTexts, &text); stringApi.free(&text); } void addModifiersInfo(game::CEncLayoutUnit* layout) { using namespace game; int count = 0; if (CMidgardIDApi::get().getType(&layout->data->unitId) == IdType::Unit) { const auto unit = gameFunctions().findUnitById(layout->data->objectMap, &layout->data->unitId); if (!unit) return; auto nativeModifiers = getNativeModifiers(unit->unitImpl->id); for (auto curr = getFirstUmModifier(unit->unitImpl); curr; curr = curr->data->next) { auto customModifier = castModifierToCustomModifier(curr); if (!customModifier || !customModifier->getDisplay()) { continue; } auto it = std::find(nativeModifiers.begin(), nativeModifiers.end(), curr->data->modifierId); addModifierInfo(layout, customModifier, it != nativeModifiers.end()); ++count; } } else { for (const auto& modifierId : getNativeModifiers(layout->data->unitId)) { const auto unitModifier = getUnitModifier(&modifierId); if (!unitModifier) { continue; } auto customModifier = castModifierToCustomModifier(unitModifier->data->modifier); if (!customModifier || !customModifier->getDisplay()) { continue; } addModifierInfo(layout, customModifier, true); ++count; } } if (count == 0) count = 1; // To display "None" text auto listBox = CDialogInterfApi::get().findListBox(layout->dialog, modifiersListBoxName); CListBoxInterfApi::get().setElementsTotal(listBox, count); } void __fastcall modifiersListBoxDisplayCallback(const game::CEncLayoutUnit* thisptr, int /*%edx*/, game::ImagePointList* contents, const game::CMqRect* lineArea, unsigned int index, bool selected) { using namespace game; const auto& imagePointListApi = ImagePointListApi::get(); if (index < 0) return; auto data = (CEncLayoutUnitDataPatched*)thisptr->data; CMqRect textClientArea = *lineArea; textClientArea.right -= textClientArea.left; textClientArea.bottom -= textClientArea.top; textClientArea.left = 31; // Width of modifier icon textClientArea.top = 0; auto length = data->modifierTexts.end - data->modifierTexts.bgn; if (length == 0 && index == 0) { auto text = getInterfaceText(textIds().interf.modifiersEmpty.c_str()); if (text.empty()) text = getInterfaceText("X005TA0676"); textClientArea.left = 0; imagePointListApi.addText(contents, lineArea, text.c_str(), &textClientArea, false, 0); return; } if ((int)index >= length) return; std::string text = data->modifierTexts.bgn[index].string; auto& icon = data->modifierIcons.bgn[index]; if (icon.data) { CMqPoint iconClientPos{0, 0}; imagePointListApi.addImageWithText(contents, lineArea, &icon, &iconClientPos, text.c_str(), &textClientArea, false, 0); } else { imagePointListApi.addText(contents, lineArea, text.c_str(), &textClientArea, false, 0); } } game::CEncLayoutUnit* __fastcall encLayoutUnitCtorHooked(game::CEncLayoutUnit* thisptr, int /*%edx*/, const game::IMidgardObjectMap* objectMap, game::CInterface* parent, const game::CMqRect* area, const game::CMidgardID* unitId, const game::CEncParamBase* encParam, const game::CMidgardID* playerId) { using namespace game; IEncLayoutApi::get().constructor(thisptr, parent, area); auto descriptor = createUnitDescriptor(objectMap, unitId, playerId); thisptr->vftable = CEncLayoutUnitApi::vftable(); thisptr->data = createData(objectMap, unitId, descriptor); parent->vftable->addChild(parent, (CInterface*)thisptr); CEncLayoutUnitApi::get().initialize(thisptr, encParam); return thisptr; } game::CEncLayoutUnit* __fastcall encLayoutUnitCtor2Hooked(game::CEncLayoutUnit* thisptr, int /*%edx*/, game::IEncUnitDescriptor* descriptor, game::CInterface* parent, const game::CMqRect* area, const game::CEncParamBase* encParam) { using namespace game; IEncLayoutApi::get().constructor(thisptr, parent, area); thisptr->vftable = CEncLayoutUnitApi::vftable(); thisptr->data = createData(nullptr, &emptyId, descriptor); parent->vftable->addChild(parent, (CInterface*)thisptr); CEncLayoutUnitApi::get().initialize(thisptr, encParam); return thisptr; } game::CEncLayoutUnitData* __fastcall encLayoutUnitDataCtorHooked(game::CEncLayoutUnitData* thisptr, int /*%edx*/) { using namespace game; const auto& imagePtrVectorApi = ImagePtrVectorApi::get(); const auto& stringArrayApi = StringArrayApi::get(); thisptr->unitId = invalidId; thisptr->leaderAbilityIcons = {}; imagePtrVectorApi.reserve(&thisptr->leaderAbilityIcons, 1); thisptr->leaderAbilityTexts = {}; stringArrayApi.reserve(&thisptr->leaderAbilityTexts, 1); thisptr->unitDescriptor = nullptr; auto patched = (CEncLayoutUnitDataPatched*)thisptr; patched->modifierIcons = {}; imagePtrVectorApi.reserve(&patched->modifierIcons, 1); patched->modifierTexts = {}; stringArrayApi.reserve(&patched->modifierTexts, 1); patched->attackSourceImmunityStatuses.patched = 0; patched->attackClassImmunityStatuses = 0; return thisptr; } void __fastcall encLayoutUnitDataDtorHooked(game::CEncLayoutUnitData* thisptr, int /*%edx*/) { using namespace game; const auto& imagePtrVectorApi = ImagePtrVectorApi::get(); const auto& stringArrayApi = StringArrayApi::get(); auto descriptor = thisptr->unitDescriptor; if (descriptor) { descriptor->vftable->destructor(descriptor, true); } stringArrayApi.destructor(&thisptr->leaderAbilityTexts); imagePtrVectorApi.destructor(&thisptr->leaderAbilityIcons); auto patched = (CEncLayoutUnitDataPatched*)thisptr; stringArrayApi.destructor(&patched->modifierTexts); imagePtrVectorApi.destructor(&patched->modifierIcons); } void __fastcall encLayoutUnitInitializeHooked(game::CEncLayoutUnit* thisptr, int /*%edx*/, const game::CEncParamBase* encParam) { using namespace game; const auto& dialogApi = CDialogInterfApi::get(); const auto& encParamBaseApi = CEncParamBaseApi::get(); auto data = (CEncLayoutUnitDataPatched*)thisptr->data; data->attackSourceImmunityStatuses .patched = encParamBaseApi.getData(encParam, CEncParamBaseDataKey::AttackSourceImmunityStatuses, 0); data->attackClassImmunityStatuses = encParamBaseApi.getData( encParam, CEncParamBaseDataKey::AttackClassImmunityStatuses, 0); getOriginalFunctions().encLayoutUnitInitialize(thisptr, encParam); if (!dialogApi.findControl(thisptr->dialog, modifiersListBoxName)) { return; } if (dialogApi.findControl(thisptr->dialog, modifiersTextBoxName)) { auto text = getInterfaceText(textIds().interf.modifiersCaption.c_str()); if (text.empty()) text = "\\fMedBold;Effects:\\fNormal;"; auto textBox = dialogApi.findTextBox(thisptr->dialog, modifiersTextBoxName); CTextBoxInterfApi::get().setString(textBox, text.c_str()); } SmartPointer functor{}; auto callback = (CEncLayoutUnitApi::Api::ListBoxDisplayCallback)modifiersListBoxDisplayCallback; CEncLayoutUnitApi::get().createListBoxDisplayFunctor(&functor, 0, thisptr, &callback); CListBoxInterfApi::get().assignDisplaySurfaceFunctor(thisptr->dialog, modifiersListBoxName, "DLG_R_C_UNIT", &functor); SmartPointerApi::get().createOrFreeNoDtor(&functor, nullptr); addModifiersInfo(thisptr); } static bool isModifiedImmunityToAttackSource(const game::IUsSoldier* soldierImpl, const game::LAttackSource* attackSource, const game::IdList& editorModifiers, game::ImmuneId immuneId) { using namespace game; auto immune = soldierImpl->vftable->getImmuneByAttackSource(soldierImpl, attackSource); if (immune->id == immuneId) { return false; } for (auto modifierId : editorModifiers) { if (isImmunityModifier(&modifierId, attackSource, immuneId)) { return false; } } return true; } static void addAttackSourceImmunityText(std::string& result, const game::IUsSoldier* soldierImpl, game::ImmuneId immuneId, const game::IdList& editorModifiers, const game::List<game::LAttackSource>& sources, game::AttackSourceImmunityStatusesPatched immunityStatuses) { using namespace game; for (const auto& source : sources) { auto text = getAttackSourceText(&source); if (immuneId == ImmuneId::Once && isUnitAttackSourceWardRemoved(immunityStatuses, &source)) { text = getRemovedAttackWardText(text); } else if (isModifiedImmunityToAttackSource(soldierImpl, &source, editorModifiers, immuneId)) { text = getModifiedStringText(text, true); } if (!result.empty() && !text.empty()) { result += ", "; } result += text; } } static bool isModifiedImmunityToAttackClass(const game::IUsSoldier* soldierImpl, const game::LAttackClass* attackClass, const game::IdList& editorModifiers, game::ImmuneId immuneId) { using namespace game; auto immune = soldierImpl->vftable->getImmuneByAttackClass(soldierImpl, attackClass); if (immune->id == immuneId) { return false; } for (auto modifierId : editorModifiers) { if (isImmunityclassModifier(&modifierId, attackClass, immuneId)) { return false; } } return true; } static void addAttackClassImmunityText(std::string& result, const game::IUsSoldier* soldierImpl, game::ImmuneId immuneId, const game::IdList& editorModifiers, const game::List<game::LAttackClass>& classes, std::uint32_t immunityStatuses) { using namespace game; for (const auto& class_ : classes) { auto text = getAttackClassText(class_.id); if (immuneId == ImmuneId::Once && isUnitAttackClassWardRemoved(immunityStatuses, &class_)) { text = getRemovedAttackWardText(text); } else if (isModifiedImmunityToAttackClass(soldierImpl, &class_, editorModifiers, immuneId)) { text = getModifiedStringText(text, true); } if (!result.empty() && !text.empty()) { result += ", "; } result += text; } } static std::string getImmuOrWardField(const game::CEncLayoutUnit* layout, const game::IUsSoldier* soldierImpl, game::IEncUnitDescriptorVftable::GetAttackSources getSources, game::IEncUnitDescriptorVftable::GetAttackClasses getClasses, game::ImmuneId immuneId, const game::IdList& editorModifiers) { using namespace game; const auto& categoryListApi = CategoryListApi::get(); auto data = (CEncLayoutUnitDataPatched*)layout->data; auto descriptor = data->unitDescriptor; List<LAttackSource> sources{}; categoryListApi.constructor((CategoryList*)&sources); getSources(descriptor, &sources); List<LAttackClass> classes{}; categoryListApi.constructor((CategoryList*)&classes); getClasses(descriptor, &classes); std::string result; addAttackSourceImmunityText(result, soldierImpl, immuneId, editorModifiers, sources, data->attackSourceImmunityStatuses); addAttackClassImmunityText(result, soldierImpl, immuneId, editorModifiers, classes, data->attackClassImmunityStatuses); if (result.empty()) { // "None" result = getInterfaceText("X005TA0469"); } categoryListApi.clear((CategoryList*)&sources); categoryListApi.freeNode((CategoryList*)&sources, (CategoryListNode*)sources.head); categoryListApi.clear((CategoryList*)&classes); categoryListApi.freeNode((CategoryList*)&classes, (CategoryListNode*)classes.head); return result; } static std::string getImmuField(const game::CEncLayoutUnit* layout, const game::IUsSoldier* soldierImpl, const game::IdList& editorModifiers) { auto data = layout->data; auto descriptor = data->unitDescriptor; return getImmuOrWardField(layout, soldierImpl, descriptor->vftable->getAttackSourcesUnitIsImmuneTo, descriptor->vftable->getAttackClassesUnitIsImmuneTo, game::ImmuneId::Always, editorModifiers); } static std::string getWardField(const game::CEncLayoutUnit* layout, const game::IUsSoldier* soldierImpl, const game::IdList& editorModifiers) { auto data = layout->data; auto descriptor = data->unitDescriptor; return getImmuOrWardField(layout, soldierImpl, descriptor->vftable->getAttackSourcesUnitIsResistantTo, descriptor->vftable->getAttackClassesUnitIsResistantTo, game::ImmuneId::Once, editorModifiers); } static int getUnitArmor(game::CEncLayoutUnit* layout) { using namespace game; const auto& restrictions = gameRestrictions(); auto data = layout->data; auto descriptor = data->unitDescriptor; auto objectMap = data->objectMap; int result = descriptor->vftable->getUnitArmor(descriptor); if (!data->unknown4 && objectMap && !descriptor->vftable->isUnitType(descriptor)) { result += getCityProtection(objectMap, &data->unitId); } result -= data->shatteredArmor; if (result < data->fortificationArmor) result = data->fortificationArmor; return std::clamp(result, restrictions.unitArmor->min, restrictions.unitArmor->max); } static std::string getHp2Field(game::IEncUnitDescriptor* descriptor, const game::IUsSoldier* soldierImpl, const game::IdList& editorModifiers) { using namespace game; const auto& fn = gameFunctions(); const auto& restrictions = gameRestrictions(); auto midUnitDescriptor = castToMidUnitDescriptor(descriptor); if (!midUnitDescriptor || !userSettings().unitEncyclopedia.displayBonusHp) { return getNumberText(descriptor->vftable->getHpMax(descriptor), false); } auto unit = midUnitDescriptor->unit; if (unit->transformed && unit->keepHp) { return getNumberText(unit->hpBefMax, false); } int implHpMax = soldierImpl->vftable->getHitPoints(soldierImpl); implHpMax = applyModifiers(implHpMax, editorModifiers, ModifierElementTypeFlag::Hp); implHpMax = std::clamp(implHpMax, restrictions.unitHp->min, restrictions.unitHp->max); auto soldier = fn.castUnitImplToSoldier(unit->unitImpl); auto actualHpMax = soldier->vftable->getHitPoints(soldier); return getModifiedNumberTextTotal(actualHpMax, implHpMax, false); } static std::string getXp2Field(game::IEncUnitDescriptor* descriptor, const game::IUsSoldier* soldierImpl) { using namespace game; const auto& fn = gameFunctions(); auto midUnitDescriptor = castToMidUnitDescriptor(descriptor); if (!midUnitDescriptor || !userSettings().unitEncyclopedia.displayBonusXp) { return getNumberText(descriptor->vftable->getUnitXpNext(descriptor), false); } int implXpNext = soldierImpl->vftable->getXpNext(soldierImpl); auto soldier = fn.castUnitImplToSoldier(midUnitDescriptor->unit->unitImpl); auto actualXpNext = soldier->vftable->getXpNext(soldier); return getModifiedNumberTextTotalReverseBonus(actualXpNext, implXpNext, false); } static std::string getArmorField(game::CEncLayoutUnit* layout, const game::IUsSoldier* soldierImpl, const game::IdList& editorModifiers) { using namespace game; const auto& restrictions = gameRestrictions(); int implArmor; soldierImpl->vftable->getArmor(soldierImpl, &implArmor); implArmor = applyModifiers(implArmor, editorModifiers, ModifierElementTypeFlag::Armor); implArmor = std::clamp(implArmor, restrictions.unitArmor->min, restrictions.unitArmor->max); int actualArmor = getUnitArmor(layout); return getModifiedNumberTextFull(actualArmor, implArmor, false); } static std::string getXpField(game::IEncUnitDescriptor* descriptor, const game::IUsSoldier* soldierImpl) { if (descriptor->vftable->isUnitAtMaxLevel(descriptor)) { // \c128;000;000;Max\c000;000;000; return getInterfaceText("X005TA0648"); } // %XP1% / %XP2% auto result = getInterfaceText("X005TA0649"); replace(result, "%XP1%", getNumberText(descriptor->vftable->getUnitCurrentXp(descriptor), false)); replace(result, "%XP2%", getXp2Field(descriptor, soldierImpl)); return result; } static std::string getEffhpField(game::CEncLayoutUnit* layout) { using namespace game; auto data{layout->data}; auto descriptor{data->unitDescriptor}; auto unitArmor{getUnitArmor(layout)}; auto unitHp{descriptor->vftable->getHp(descriptor)}; return getNumberText(computeUnitEffectiveHp(unitHp, unitArmor), false); } static std::string getRegenField(game::CEncLayoutUnit* layout, const game::IUsSoldier* soldierImpl) { using namespace game; const auto& fn = gameFunctions(); auto data = layout->data; auto descriptor = data->unitDescriptor; auto objectMap = data->objectMap; auto implRegen = *soldierImpl->vftable->getRegen(soldierImpl); auto midUnitDescriptor = castToMidUnitDescriptor(descriptor); if (!midUnitDescriptor) { return getNumberText(implRegen, true); } auto actualRegen = getUnitRegen(objectMap, &data->unitId); return getModifiedNumberText(actualRegen, implRegen, true); } static std::string getXpKillField(game::IEncUnitDescriptor* descriptor, const game::IUsSoldier* soldierImpl) { using namespace game; const auto& fn = gameFunctions(); auto implXpKilled = soldierImpl->vftable->getXpKilled(soldierImpl); auto midUnitDescriptor = castToMidUnitDescriptor(descriptor); if (!midUnitDescriptor) { return getNumberText(implXpKilled, false); } auto soldier = fn.castUnitImplToSoldier(midUnitDescriptor->unit->unitImpl); auto actualXpKilled = soldier->vftable->getXpKilled(soldier); return getModifiedNumberTextReverseBonus(actualXpKilled, implXpKilled, false); } static std::string getApField(game::IEncUnitDescriptor* descriptor) { if (!descriptor->vftable->isUnitType(descriptor)) { return ""; } // \fmedbold;Move points:\t\fnormal;%AP%\n auto result = getInterfaceText("X005TA0650"); replace(result, "%AP%", getNumberText(descriptor->vftable->getMovement(descriptor), false)); return result; } static std::string getLdrshpField(game::IEncUnitDescriptor* descriptor) { // \s110;\fmedbold;Leadership:\t\fnormal;%MAX%\n auto result = getInterfaceText("X005TA0583"); replace(result, "%MAX%", getNumberText(descriptor->vftable->getLeadership(descriptor) - 1, false)); return result; } static std::string getNbbatField(game::IEncUnitDescriptor* descriptor) { if (descriptor->vftable->isUnitType(descriptor)) { return ""; } // \s110;\fMedBold;Battles won:\t\fNormal;%VALUE%\n auto result = getInterfaceText("X005TA0737"); replace(result, "%VALUE%", getNumberText(descriptor->vftable->getNbBattle(descriptor), false)); return result; } static bool lordHasAnyRequiredBuilding(game::IEncUnitDescriptor* descriptor, const game::CMidgardID* lordId) { using namespace game; Vector<TBuildingType*> buildings{}; IntVectorApi::get().reserve((IntVector*)&buildings, 1); descriptor->vftable->getUnitRequiredBuildings(descriptor, &buildings); for (auto it = buildings.bgn; it != buildings.end; ++it) { auto buildingId = (*it)->id; if (lordHasBuilding(lordId, &buildingId)) { return true; } } return false; } static std::string getBuildingField(game::IEncUnitDescriptor* descriptor) { using namespace game; Vector<TBuildingType*> buildings{}; IntVectorApi::get().reserve((IntVector*)&buildings, 1); descriptor->vftable->getUnitRequiredBuildings(descriptor, &buildings); std::string result; for (auto it = buildings.bgn; it != buildings.end; ++it) { auto building = *it; auto namesAndId = building->data->name; auto name = GlobalDataApi::get().findTextById(namesAndId.texts, &namesAndId.id); if (!result.empty()) { // \fNormal;\c000;000;000; or \fNormal; result += getInterfaceText("X005TA0459"); } result += name; } return result; } static std::string getRaceField(game::IEncUnitDescriptor* descriptor, const game::IUsSoldier* soldier) { using namespace game; const auto& globalApi = GlobalDataApi::get(); auto raceId = soldier->vftable->getRaceId(soldier); auto races = (*globalApi.getGlobalData())->races; auto race = (TRaceType*)globalApi.findById(races, raceId); auto namesAndId = race->data->name; return globalApi.findTextById(namesAndId.texts, &namesAndId.id); } static void setImgUnitIcon(game::CEncLayoutUnit* layout) { using namespace game; const auto& pictureApi = CPictureInterfApi::get(); auto data = layout->data; auto descriptor = data->unitDescriptor; auto picture = CDialogInterfApi::get().findPicture(layout->dialog, "IMG_UNIT_ICON"); CMidgardID globalUnitImplId; descriptor->vftable->getGlobalUnitImplId(descriptor, &globalUnitImplId); auto image = GameImagesApi::get().getUnitIcon(&globalUnitImplId); if (!image) { CMqPoint offset{}; pictureApi.setImage(picture, nullptr, &offset); } else { setCenteredImage(picture, image); } } static void addStatsDynUpgradeText(std::string& text, game::IEncUnitDescriptor* descriptor, const game::IUsSoldier* soldierImpl) { using namespace game; const CDynUpgrade* upgrade1 = nullptr; const CDynUpgrade* upgrade2 = nullptr; if (!getDynUpgradesToDisplay(descriptor, &upgrade1, &upgrade2)) { return; } addDynUpgradeLevelToField(text, "%LEVEL%", soldierImpl->vftable->getDynUpgLvl(soldierImpl)); addDynUpgradeTextToField(text, "%HP2%", upgrade1->hp, upgrade2->hp); addDynUpgradeTextToField(text, "%ARMOR%", upgrade1->armor, upgrade2->armor); addDynUpgradeTextToField(text, "%XP%", upgrade1->xpNext, upgrade2->xpNext); } static void setTxtStats(game::CEncLayoutUnit* layout, const game::IUsSoldier* soldierImpl, const game::IdList& editorModifiers) { using namespace game; auto data = layout->data; auto descriptor = data->unitDescriptor; // \s110; // \fmedbold;Level:\t\fnormal;%LEVEL%\n // \fMedbold;XP:\t\fNormal;%XP%\n // \fMedbold;HP:\t\fnormal;%HP1% / %HP2%\n // \fMedbold;Armor:\t\fNormal;%ARMOR%\n // \fMedbold;Immunities:\t\fNormal;\p110;%IMMU%\mL0; // \fMedbold;Wards:\t\fNormal;\p110;%WARD% auto text = getInterfaceText("X005TA0423"); addStatsDynUpgradeText(text, descriptor, soldierImpl); replace(text, "%LEVEL%", getNumberText(descriptor->vftable->getUnitLevel(descriptor), false)); replace(text, "%HP1%", getNumberText(descriptor->vftable->getHp(descriptor), false)); replace(text, "%HP2%", getHp2Field(descriptor, soldierImpl, editorModifiers)); replace(text, "%ARMOR%", getArmorField(layout, soldierImpl, editorModifiers)); replace(text, "%XP%", getXpField(descriptor, soldierImpl)); replace(text, "%IMMU%", getImmuField(layout, soldierImpl, editorModifiers)); replace(text, "%WARD%", getWardField(layout, soldierImpl, editorModifiers)); auto textBox = CDialogInterfApi::get().findTextBox(layout->dialog, "TXT_STATS"); CTextBoxInterfApi::get().setString(textBox, text.c_str()); } static void addStats2DynUpgradeText(std::string& text, game::IEncUnitDescriptor* descriptor) { using namespace game; const CDynUpgrade* upgrade1 = nullptr; const CDynUpgrade* upgrade2 = nullptr; if (!getDynUpgradesToDisplay(descriptor, &upgrade1, &upgrade2)) { return; } addDynUpgradeTextToField(text, "%REGEN%", upgrade1->regen, upgrade2->regen); addDynUpgradeTextToField(text, "%XPKILL%", upgrade1->xpKilled, upgrade2->xpKilled); } static void setTxtStats2(game::CEncLayoutUnit* layout, const game::IUsSoldier* soldierImpl, const game::IdList& editorModifiers) { using namespace game; static const char controlName[]{"TXT_STATS_2"}; const auto& dialogApi{CDialogInterfApi::get()}; auto data{layout->data}; auto descriptor{data->unitDescriptor}; if (!dialogApi.findControl(layout->dialog, controlName)) { return; } auto textBox{dialogApi.findTextBox(layout->dialog, controlName)}; if (!textBox) { return; } std::string text{textBox->data->text.string}; addStats2DynUpgradeText(text, descriptor); replace(text, "%EFFHP%", getEffhpField(layout)); replace(text, "%REGEN%", getRegenField(layout, soldierImpl)); replace(text, "%XPKILL%", getXpKillField(descriptor, soldierImpl)); CTextBoxInterfApi::get().setString(textBox, text.c_str()); } static void setTxtUnitName(game::CEncLayoutUnit* layout) { using namespace game; auto data = layout->data; auto descriptor = data->unitDescriptor; // \fLarge;%NAME% auto text = getInterfaceText("X005TA0567"); replace(text, "%NAME%", descriptor->vftable->getUnitName(descriptor)); auto textBox = CDialogInterfApi::get().findTextBox(layout->dialog, "TXT_UNIT_NAME"); CTextBoxInterfApi::get().setString(textBox, text.c_str()); } static void setTxtUnitInfo(game::CEncLayoutUnit* layout) { using namespace game; auto data = layout->data; auto descriptor = data->unitDescriptor; // \fnormal;\hL;\vT;%DESC% auto text = getInterfaceText("X005TA0422"); replace(text, "%DESC%", descriptor->vftable->getUnitDescription(descriptor)); auto textBox = CDialogInterfApi::get().findTextBox(layout->dialog, "TXT_UNIT_INFO"); CTextBoxInterfApi::get().setString(textBox, text.c_str()); } static void setTxtLeaderInfo(game::CEncLayoutUnit* layout) { using namespace game; auto data = layout->data; auto descriptor = data->unitDescriptor; if (!descriptor->vftable->isUnitLeader(descriptor)) { return; } // \c000;000;000;%LDRSHP%%AP%%NBBAT% auto text = getInterfaceText("X005TA0809"); replace(text, "%AP%", getApField(descriptor)); replace(text, "%LDRSHP%", getLdrshpField(descriptor)); replace(text, "%NBBAT%", getNbbatField(descriptor)); auto textBox = CDialogInterfApi::get().findTextBox(layout->dialog, "TXT_LEADER_INFO"); CTextBoxInterfApi::get().setString(textBox, text.c_str()); } static void setTxtNeedUpgrade(game::CEncLayoutUnit* layout, bool* needUpgrade) { using namespace game; const auto& fn = gameFunctions(); auto data = layout->data; auto descriptor = data->unitDescriptor; auto objectMap = data->objectMap; *needUpgrade = false; std::string text; if (descriptor->vftable->isUnitUpgradePending(descriptor)) { auto unit = fn.findUnitById(objectMap, &data->unitId); auto soldier = fn.castUnitImplToSoldier(unit->unitImpl); auto player = getPlayerByUnitId(objectMap, &data->unitId); if (player && lordHasAnyRequiredBuilding(descriptor, &player->lordId)) { // You must build the %BUILDING% in your capital to upgrade this unit. text = getInterfaceText("X005TA0513"); replace(text, "%BUILDING%", getBuildingField(descriptor)); *needUpgrade = true; } else { // This unit is ready to upgrade but can not because it needs a building that is only // accessible to the %RACE% text = getInterfaceText("X005TA0822"); replace(text, "%RACE%", getRaceField(descriptor, soldier)); } } else if (descriptor->vftable->getUnitDynLevel(descriptor)) { // This unit's type has been locked. It does not need a new building to upgrade. text = getInterfaceText("X005TA0941"); } else { return; } auto textBox = CDialogInterfApi::get().findTextBox(layout->dialog, "TXT_NEED_UPGRADE"); CTextBoxInterfApi::get().setString(textBox, text.c_str()); } static void setImgUpgrade(game::CEncLayoutUnit* layout, bool needUpgrade) { using namespace game; if (!needUpgrade) { return; } const auto& imagesApi = GameImagesApi::get(); auto data = layout->data; auto descriptor = data->unitDescriptor; auto picture = CDialogInterfApi::get().findPicture(layout->dialog, "IMG_UPGRADE"); GameImagesPtr imagesPtr; imagesApi.getGameImages(&imagesPtr); auto images = *imagesPtr.data; auto image = imagesApi.getImage(images->battle, "FIUPGRADE", 0, false, images->log); CMqPoint offset{}; CPictureInterfApi::get().setImage(picture, image, &offset); imagesApi.createOrFreeGameImages(&imagesPtr, nullptr); } static void setTxtAttackInfo(game::CEncLayoutUnit* layout, const game::IdList& editorModifiers) { using namespace game; const auto& fn = gameFunctions(); auto data = layout->data; auto descriptor = data->unitDescriptor; CMidgardID globalUnitImplId; descriptor->vftable->getGlobalUnitImplId(descriptor, &globalUnitImplId); int damageMax = fn.getUnitImplDamageMax(&globalUnitImplId); fn.generateAttackDescription(descriptor, layout->dialog, data->boostDamageLevel, data->lowerDamageLevel, data->lowerInitiativeLevel, &editorModifiers, damageMax); } static void setTxtEffectiveHp(game::CEncLayoutUnit* layout) { using namespace game; static const char controlName[]{"TXT_EFFECTIVE_HP"}; const auto& dialogApi{CDialogInterfApi::get()}; if (!dialogApi.findControl(layout->dialog, controlName)) { return; } auto textBox{dialogApi.findTextBox(layout->dialog, controlName)}; if (!textBox) { return; } std::string text{textBox->data->text.string}; if (replace(text, "%HP%", getEffhpField(layout))) { CTextBoxInterfApi::get().setString(textBox, text.c_str()); } } void __fastcall encLayoutUnitUpdateHooked(game::CEncLayoutUnit* thisptr, int /*%edx*/) { if (!userSettings().unitEncyclopedia.detailedUnitDescription) { getOriginalFunctions().encLayoutUnitUpdate(thisptr); setTxtEffectiveHp(thisptr); return; } using namespace game; const auto& fn = gameFunctions(); const auto& idListApi = IdListApi::get(); auto data = thisptr->data; auto descriptor = data->unitDescriptor; auto objectMap = data->objectMap; auto unitImpl = getUnitImpl(descriptor); auto soldierImpl = gameFunctions().castUnitImplToSoldier(unitImpl); IdList editorModifiers = {}; idListApi.constructor(&editorModifiers); if (objectMap && !descriptor->vftable->isUnitType(descriptor)) { auto unit = fn.findUnitById(objectMap, &data->unitId); getEditorModifiers(unit, &editorModifiers); } bool needUpgrade; setImgUnitIcon(thisptr); setTxtUnitName(thisptr); setTxtUnitInfo(thisptr); setTxtStats(thisptr, soldierImpl, editorModifiers); setTxtStats2(thisptr, soldierImpl, editorModifiers); setTxtLeaderInfo(thisptr); setTxtNeedUpgrade(thisptr, &needUpgrade); setImgUpgrade(thisptr, needUpgrade); setTxtAttackInfo(thisptr, editorModifiers); setTxtEffectiveHp(thisptr); idListApi.destructor(&editorModifiers); } } // namespace hooks
39,286
C++
.cpp
874
36.187643
100
0.662554
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,082
drainlevelhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/drainlevelhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "drainlevelhooks.h" #include "attack.h" #include "batattackdrainlevel.h" #include "batattackutils.h" #include "battleattackinfo.h" #include "battlemsgdata.h" #include "battlemsgdataview.h" #include "game.h" #include "gameutils.h" #include "globaldata.h" #include "itemview.h" #include "log.h" #include "midgardobjectmap.h" #include "midunit.h" #include "scripts.h" #include "settings.h" #include "unitgenerator.h" #include "unitimplview.h" #include "unitutils.h" #include "unitview.h" #include "usleader.h" #include "usracialsoldier.h" #include "ussoldier.h" #include "usunitimpl.h" #include "utils.h" #include "visitors.h" #include <fmt/format.h> namespace hooks { static int getDrainLevel(const game::CMidUnit* unit, const game::CMidUnit* targetUnit, const game::IMidgardObjectMap* objectMap, const game::CMidgardID* unitOrItemId, const game::BattleMsgData* battleMsgData) { using namespace game; // The function is only accessed by the server thread - the single instance is enough. static std::optional<sol::environment> env; static std::optional<sol::function> getLevel; const auto path{scriptsFolder() / "drainLevel.lua"}; if (!env && !getLevel) { getLevel = getScriptFunction(path, "getLevel", env, true, true); } if (!getLevel) { return 0; } try { const bindings::UnitView attacker{unit}; const bindings::UnitView target{targetUnit}; const bindings::BattleMsgDataView battleView{battleMsgData, objectMap}; if (CMidgardIDApi::get().getType(unitOrItemId) == IdType::Item) { const bindings::ItemView itemView{unitOrItemId, objectMap}; return (*getLevel)(attacker, target, &itemView, battleView); } else return (*getLevel)(attacker, target, nullptr, battleView); } catch (const std::exception& e) { showErrorMessageBox(fmt::format("Failed to run '{:s}' script.\n" "Reason: '{:s}'", path.string(), e.what())); return 0; } } void __fastcall drainLevelAttackOnHitHooked(game::CBatAttackDrainLevel* thisptr, int /*%edx*/, game::IMidgardObjectMap* objectMap, game::BattleMsgData* battleMsgData, game::CMidgardID* targetUnitId, game::BattleAttackInfo** attackInfo) { using namespace game; const auto& fn = gameFunctions(); if (fn.isUnitImmuneToAttack(objectMap, battleMsgData, targetUnitId, thisptr->attack, false)) return; const CMidUnit* targetUnit = fn.findUnitById(objectMap, targetUnitId); const CMidgardID targetUnitImplId{targetUnit->unitImpl->id}; int targetLevel = 1; auto targetSoldier = fn.castUnitImplToSoldier(targetUnit->unitImpl); if (targetSoldier) targetLevel = targetSoldier->vftable->getLevel(targetSoldier); int drainLevel = targetLevel - 1; if (userSettings().leveledDrainLevelAttack) { const CMidUnit* unit = fn.findUnitById(objectMap, &thisptr->unitId); drainLevel = getDrainLevel(unit, targetUnit, objectMap, &thisptr->unitOrItemId, battleMsgData); } const auto& global = GlobalDataApi::get(); auto globalData = *global.getGlobalData(); CMidgardID transformImplId = emptyId; for (int i = targetLevel; i > drainLevel; i--) { auto unitImpl = targetUnit->unitImpl; if (transformImplId != emptyId) unitImpl = static_cast<TUsUnitImpl*>( global.findById(globalData->units, &transformImplId)); auto racialSoldier = fn.castUnitImplToRacialSoldier(unitImpl); if (racialSoldier) transformImplId = *racialSoldier->vftable->getPrevUnitImplId(racialSoldier); else { auto leader = fn.castUnitImplToLeader(unitImpl); if (leader) transformImplId = *leader->vftable->getPrevUnitImplId(leader); } if (transformImplId == emptyId) return; if (CMidgardIDApi::get().getType(&transformImplId) == IdType::UnitGenerated) { CUnitGenerator* unitGenerator = globalData->unitGenerator; unitGenerator->vftable->generateUnitImpl(unitGenerator, &transformImplId); } } bool prevAttackTwice = targetSoldier && targetSoldier->vftable->getAttackTwice(targetSoldier); const auto& visitors = VisitorApi::get(); visitors.transformUnit(targetUnitId, &transformImplId, false, objectMap, 1); updateAttackCountAfterTransformation(battleMsgData, targetUnit, prevAttackTwice); BattleAttackUnitInfo info{}; info.unitId = *targetUnitId; info.unitImplId = targetUnitImplId; BattleAttackInfoApi::get().addUnitInfo(&(*attackInfo)->unitsInfo, &info); const auto& battle = BattleMsgDataApi::get(); battle.removeTransformStatuses(targetUnitId, battleMsgData); battle.setUnitStatus(battleMsgData, targetUnitId, BattleStatus::TransformDrainLevel, true); battle.setUnitHp(battleMsgData, targetUnitId, targetUnit->currentHp); } } // namespace hooks
6,183
C++
.cpp
139
36.546763
98
0.672924
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,083
scenarioobjectstreams.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/scenarioobjectstreams.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2024 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "scenarioobjectstreams.h" #include "version.h" #include <array> namespace game::ScenarioObjectStreamsApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::AddStreamRegister)0x616064, }, // Russobit Api{ (Api::AddStreamRegister)0x616064, }, // Gog Api{ (Api::AddStreamRegister)0x614b6f, }, // Scenario Editor Api{ (Api::AddStreamRegister)0x501f39, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::ScenarioObjectStreamsApi
1,436
C++
.cpp
47
27.297872
72
0.717486
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,084
visitors.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/visitors.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "visitors.h" #include "version.h" #include <array> namespace game::VisitorApi { // clang-format off std::array<Api, 3> functions = {{ // Akella Api{ (Api::ChangeUnitHp)0x5e88f4, (Api::ChangeUnitXp)0x5e8942, (Api::UpgradeUnit)0x5e963d, (Api::ForceUnitMax)0x5e972a, (Api::AddUnitToGroup)0x5e8bf8, (Api::ExchangeItem)0x5e86cc, (Api::TransformUnit)0x5e968e, (Api::UndoTransformUnit)0x5e96df, (Api::ExtractUnitFromGroup)0x5e8d72, }, // Russobit Api{ (Api::ChangeUnitHp)0x5e88f4, (Api::ChangeUnitXp)0x5e8942, (Api::UpgradeUnit)0x5e963d, (Api::ForceUnitMax)0x5e972a, (Api::AddUnitToGroup)0x5e8bf8, (Api::ExchangeItem)0x5e86cc, (Api::TransformUnit)0x5e968e, (Api::UndoTransformUnit)0x5e96df, (Api::ExtractUnitFromGroup)0x5e8d72, }, // Gog Api{ (Api::ChangeUnitHp)0x5e75f3, (Api::ChangeUnitXp)0x5e7641, (Api::UpgradeUnit)0x5e833c, (Api::ForceUnitMax)0x5e8429, (Api::AddUnitToGroup)0x5e78f7, (Api::ExchangeItem)0x5e73cb, (Api::TransformUnit)0x5e838d, (Api::UndoTransformUnit)0x5e83de, (Api::ExtractUnitFromGroup)0x5e7a71, } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::VisitorApi
2,224
C++
.cpp
67
28.044776
72
0.689126
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,085
aigiveitemsactionhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/aigiveitemsactionhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "aigiveitemsactionhooks.h" #include "aigiveitemsaction.h" #include "aimovestackaction.h" #include "aistackgeneric.h" #include "dynamiccast.h" #include "idset.h" #include "midgardobjectmap.h" #include "midserverlogic.h" #include "midstack.h" namespace hooks { void __fastcall aiGiveItemsActionExecuteHooked(game::CAiGiveItemsAction* thisptr, int /*%edx*/, game::IMidgardObjectMap* objectMap, game::CMidServerLogicData* serverLogicData, game::IAiTacticInternal* tacticInternal) { using namespace game; const auto& idSetApi = IdSetApi::get(); const auto& serverLogicApi = CMidServerLogicApi::get(); const auto& rtti = RttiApi::rtti(); const auto dynamicCast = RttiApi::get().dynamicCast; CAiMoveStackActionApi::vftable().action->execute(thisptr, objectMap, serverLogicData, tacticInternal); // The stack can trigger battle/events during move action that might cause the stack to get // destroyed, causing AI logic to crash auto action = (IAiTacticAction*)thisptr; auto stackId = action->vftable->getStackId(action); auto stackObj = objectMap->vftable->findScenarioObjectById(objectMap, stackId); if (!stackObj) { return; } auto aiStack = thisptr->stack; auto targetPosition = action->vftable->getTargetPosition(action); if (aiStack->vftable->getDistance2(aiStack, targetPosition) != 1) { return; } IdSet itemIds{}; idSetApi.constructor(&itemIds); auto stack = static_cast<const CMidStack*>( dynamicCast(stackObj, 0, rtti.IMidScenarioObjectType, rtti.CMidStackType, 0)); const auto& items = stack->inventory.items; const auto count = items.end - items.bgn; for (const game::CMidgardID* it = items.bgn; it != items.end; it++) { Pair<IdSetIterator, bool> tmp{}; idSetApi.insert(&itemIds, &tmp, it); } serverLogicApi.stackExchangeItem(serverLogicData, &stack->ownerId, stackId, action->vftable->getTargetId(action), &itemIds); idSetApi.destructor(&itemIds); } } // namespace hooks
3,131
C++
.cpp
69
37.826087
95
0.675303
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,086
midserverlogic.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/midserverlogic.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "midserverlogic.h" #include "version.h" #include <array> namespace game::CMidServerLogicApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::GetObjectMap)0x4298aa, (Api::SendRefreshInfo)0x42972f, (Api::StackExchangeItem)0x41f5dc, }, // Russobit Api{ (Api::GetObjectMap)0x4298aa, (Api::SendRefreshInfo)0x42972f, (Api::StackExchangeItem)0x41f5dc, }, // Gog Api{ (Api::GetObjectMap)0x5a77e8, (Api::SendRefreshInfo)0x42915a, (Api::StackExchangeItem)0x41f0c4, }, }}; static std::array<Vftable, 3> vftables = {{ // Akella Vftable{ (void*)0x6d00ec, (IMidMsgSenderVftable*)0x6d00bc, }, // Russobit Vftable{ (void*)0x6d00ec, (IMidMsgSenderVftable*)0x6d00bc, }, // Gog Vftable{ (void*)0x6ce08c, (IMidMsgSenderVftable*)0x6ce05c, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } Vftable& vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMidServerLogicApi
2,001
C++
.cpp
70
24.385714
72
0.68711
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,087
d2string.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/d2string.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "d2string.h" #include "version.h" #include <array> namespace game::StringApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::InitFromString)0x403d80, (Api::InitFromStringN)0x403f62, (Api::Free)0x401418, (Api::Append)0x401453, (Api::AppendChar)0x4248a4, (Api::CStr)0x403dc6, }, // Russobit Api{ (Api::InitFromString)0x403d80, (Api::InitFromStringN)0x403f62, (Api::Free)0x401418, (Api::Append)0x401453, (Api::AppendChar)0x4248a4, (Api::CStr)0x403dc6, }, // Gog Api{ (Api::InitFromString)0x403ac6, (Api::InitFromStringN)0x403c8b, (Api::Free)0x40106a, (Api::Append)0x4010a5, (Api::AppendChar)0x4243a5, (Api::CStr)0x403b0c, }, // Scenario Editor Api{ (Api::InitFromString)0x402f6c, (Api::InitFromStringN)0x403079, (Api::Free)0x402fb2, (Api::Append)0x4043ac, (Api::AppendChar)0x472022, (Api::CStr)0x405141, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::StringApi
2,037
C++
.cpp
67
25.432836
72
0.668702
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,088
cmdbattleendmsg.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/cmdbattleendmsg.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "cmdbattleendmsg.h" #include "version.h" #include <array> namespace game::CCmdBattleEndMsgApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Destructor)0x41232e, }, // Russobit Api{ (Api::Destructor)0x41232e, }, // Gog Api{ (Api::Destructor)0x411f10, }, // Scenario Editor Api{ (Api::Destructor)nullptr, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } // clang-format off static std::array<CCommandMsgVftable*, 4> vftables = {{ // Akella (CCommandMsgVftable*)0x6d4a0c, // Russobit (CCommandMsgVftable*)0x6d4a0c, // Gog (CCommandMsgVftable*)0x6d29ac, // Scenario Editor (CCommandMsgVftable*)nullptr, }}; // clang-format on CCommandMsgVftable* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CCmdBattleEndMsgApi
1,791
C++
.cpp
63
25.142857
72
0.708309
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,089
stringintlist.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/stringintlist.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "stringintlist.h" #include "version.h" #include <array> namespace game::StringIntListApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x5b96f0, (Api::Destructor)0x5b9729, }, // Russobit Api{ (Api::Constructor)0x5b96f0, (Api::Destructor)0x5b9729, }, // Gog Api{ (Api::Constructor)0x5b868b, (Api::Destructor)0x5b86c4, }, // Scenario Editor Api{ (Api::Constructor)0x5551a7, (Api::Destructor)0x5551e0, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::StringIntListApi
1,528
C++
.cpp
51
26.254902
72
0.699049
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,090
batattacksummon.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/batattacksummon.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "batattacksummon.h" #include "version.h" #include <array> namespace game::CBatAttackSummonApi { // clang-format off static std::array<IBatAttackVftable*, 4> vftables = {{ // Akella (IBatAttackVftable*)0x6f55d4, // Russobit (IBatAttackVftable*)0x6f55d4, // Gog (IBatAttackVftable*)0x6f3584, // Scenario Editor (IBatAttackVftable*)nullptr, }}; // clang-format on IBatAttackVftable* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CBatAttackSummonApi
1,354
C++
.cpp
39
32.230769
72
0.749618
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,091
mempool.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/mempool.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "mempool.h" #include "version.h" #include <array> namespace game::Memory { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Allocate)0x509530, (Api::FreeNonZero)0x509550 }, // Russobit Api{ (Api::Allocate)0x509530, (Api::FreeNonZero)0x509550 }, // Gog Api{ (Api::Allocate)0x508820, (Api::FreeNonZero)0x508840 }, // Scenario Editor Api{ (Api::Allocate)0x4832a0, (Api::FreeNonZero)0x4832c0 } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::Memory
1,489
C++
.cpp
51
25.490196
72
0.694348
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,092
groundcat.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/groundcat.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "groundcat.h" #include "version.h" #include <array> namespace game::GroundCategories { // clang-format off static std::array<Categories, 4> categories = {{ // Akella Categories{ (LGroundCategory*)0x839360, (LGroundCategory*)0x839370, (LGroundCategory*)0x839380, (LGroundCategory*)0x839390, }, // Russobit Categories{ (LGroundCategory*)0x839360, (LGroundCategory*)0x839370, (LGroundCategory*)0x839380, (LGroundCategory*)0x839390, }, // Gog Categories{ (LGroundCategory*)0x837310, (LGroundCategory*)0x837320, (LGroundCategory*)0x837330, (LGroundCategory*)0x837340, }, // Scenario Editor Categories{ (LGroundCategory*)0x664e90, (LGroundCategory*)0x664ea0, (LGroundCategory*)0x664eb0, (LGroundCategory*)0x664ec0, }, }}; // clang-format on Categories& get() { return categories[static_cast<int>(hooks::gameVersion())]; } } // namespace game::GroundCategories
1,860
C++
.cpp
59
27.101695
72
0.704343
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,093
musichooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/musichooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "musichooks.h" #include "gamesettings.h" #include "midgard.h" #include "midmusic.h" #include "racecategory.h" #include "utils.h" #include <algorithm> #include <filesystem> #include <random> #include <string> #include <vector> namespace hooks { enum class CapitalsTracksIndex { Empire, Hordes, Clans, Legions, Elves }; using MusicTracksArray = std::vector<std::string>; static MusicTracksArray findBattleTrackNames() { namespace fs = std::filesystem; const auto settings = *game::CMidgardApi::get().instance()->data->settings; const fs::path dir{settings->musicFolder.string}; MusicTracksArray trackNames; for (const fs::directory_entry& file : fs::directory_iterator(dir)) { if (!file.is_regular_file()) { continue; } auto filename{file.path().stem().string()}; std::transform(filename.begin(), filename.end(), filename.begin(), [](unsigned char ch) { return std::tolower(ch); }); if (filename.find("battle") != filename.npos) { trackNames.push_back(filename); } } return trackNames; } static std::vector<MusicTracksArray> findCapitalsTracksNames() { namespace fs = std::filesystem; const auto settings = *game::CMidgardApi::get().instance()->data->settings; const fs::path dir{settings->musicFolder.string}; std::vector<MusicTracksArray> capitalsTracks(5); for (const fs::directory_entry& file : fs::directory_iterator(dir)) { if (!file.is_regular_file()) { continue; } auto filename{file.path().stem().string()}; std::transform(filename.begin(), filename.end(), filename.begin(), [](unsigned char ch) { return std::tolower(ch); }); if (filename.find("humntrk") != filename.npos) { capitalsTracks[(int)CapitalsTracksIndex::Empire].push_back(filename); } else if (filename.find("undetrk") != filename.npos) { capitalsTracks[(int)CapitalsTracksIndex::Hordes].push_back(filename); } else if (filename.find("dwrftrk") != filename.npos) { capitalsTracks[(int)CapitalsTracksIndex::Clans].push_back(filename); } else if (filename.find("heretrk") != filename.npos) { capitalsTracks[(int)CapitalsTracksIndex::Legions].push_back(filename); } else if (filename.find("elftrk") != filename.npos) { capitalsTracks[(int)CapitalsTracksIndex::Elves].push_back(filename); } } return capitalsTracks; } void __fastcall playBattleTrackHooked(game::CMidMusic* thisptr, int /*%edx*/) { using namespace game; static const MusicTracksArray battleTracks{findBattleTrackNames()}; if (battleTracks.empty()) { return; } const auto tracksTotal = battleTracks.size(); static size_t trackIndex{(size_t)getRandomNumber(0, tracksTotal)}; trackIndex++; if (trackIndex >= tracksTotal) { trackIndex = 0; } CMidMusicApi::get().playFile(thisptr, thisptr->data->musicFolder, battleTracks[trackIndex].c_str(), 0, false); } void __fastcall playCapitalTrackHooked(game::CMidMusic* thisptr, int /*%edx*/, const game::LRaceCategory* raceCategory) { using namespace game; static const std::vector<MusicTracksArray> capitalsTracks{findCapitalsTracksNames()}; const auto& music = CMidMusicApi::get(); music.freeStrings(thisptr); auto category = &thisptr->data->raceCategory; if (category != raceCategory) { category->table = raceCategory->table; category->id = raceCategory->id; } if (capitalsTracks.empty()) { return; } const auto& categories = RaceCategories::get(); const auto id = raceCategory->id; CapitalsTracksIndex capitalsIndex{CapitalsTracksIndex::Empire}; if (id == categories.human->id) { capitalsIndex = CapitalsTracksIndex::Empire; } else if (id == categories.dwarf->id) { capitalsIndex = CapitalsTracksIndex::Clans; } else if (id == categories.undead->id) { capitalsIndex = CapitalsTracksIndex::Hordes; } else if (id == categories.heretic->id) { capitalsIndex = CapitalsTracksIndex::Legions; } else if (id == categories.elf->id) { capitalsIndex = CapitalsTracksIndex::Elves; } const auto& tracks = capitalsTracks[(int)capitalsIndex]; if (tracks.empty()) { return; } static size_t trackIndex{0}; if (++trackIndex >= tracks.size()) { trackIndex = 0; } music.playFile(thisptr, thisptr->data->musicFolder, tracks[trackIndex].c_str(), 1, false); } } // namespace hooks
5,578
C++
.cpp
142
33.056338
94
0.667654
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,094
condinterf.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/condinterf.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "condinterf.h" namespace game::editor::CCondInterfApi { Api& get() { // clang-format off static Api api{ (Api::Constructor)0x41e73c, (Api::CreateFromCategory)0x45be8e, (Api::CreateButtonFunctor)0x41e6ac, (Api::CreateRadioButtonFunctor)0x425307, (Api::CreateListBoxDisplayFunctor)0x427199, (Api::GetObjectMap)0x403c23, }; // clang-format on return api; } } // namespace game::editor::CCondInterfApi
1,292
C++
.cpp
35
33.342857
72
0.734026
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,095
displayddraw.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/displayddraw.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "displayddraw.h" #include "version.h" #include <array> namespace game::CDisplayDDrawApi { // clang-format off static std::array<IMqRasterizerVftable*, 4> vftables = {{ // Akella (IMqRasterizerVftable*)0x6f5c7c, // Russobit (IMqRasterizerVftable*)0x6f5c7c, // Gog (IMqRasterizerVftable*)0x6f3c2c, // Scenario Editor (IMqRasterizerVftable*)0x5e5494, }}; // clang-format on const IMqRasterizerVftable* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CDisplayDDrawApi
1,370
C++
.cpp
39
32.641026
72
0.751885
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,096
battleutils.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/battleutils.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "battleutils.h" #include "battlemsgdata.h" #include "game.h" #include "midunit.h" #include "settings.h" #include "ussoldier.h" namespace hooks { int adjustUnitXpReceived(const game::BattleMsgData* battleMsgData, const game::CMidUnit* unit, int value) { using namespace game; const auto& fn = gameFunctions(); const auto& battleApi = BattleMsgDataApi::get(); auto result = value; if (result <= 0) { result = 1; } if (!userSettings().battle.allowRetreatedUnitsToUpgrade && battleApi.getUnitStatus(battleMsgData, &unit->id, BattleStatus::Retreated)) { auto soldier = fn.castUnitImplToSoldier(unit->unitImpl); auto xpNext = soldier->vftable->getXpNext(soldier); if (result + unit->currentXp >= xpNext) { result = xpNext - unit->currentXp - 1; } } return result; } } // namespace hooks
1,757
C++
.cpp
47
32.744681
88
0.699765
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,097
midgardmapblock.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/midgardmapblock.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "midgardmapblock.h" #include "version.h" #include <array> namespace game::CMidgardMapBlockApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Allocate)0x6851d3, (Api::Constructor)0x5f43c1, (Api::CountTerrainCoverage)0x5f46fc, (Api::SetTerrain)0x5f47dd, (Api::GetTerrain)0x5f444b, (Api::SetGround)0x5f484f, (Api::GetGround)0x5f44d9, }, // Russobit Api{ (Api::Allocate)0x6851d3, (Api::Constructor)0x5f43c1, (Api::CountTerrainCoverage)0x5f46fc, (Api::SetTerrain)0x5f47dd, (Api::GetTerrain)0x5f444b, (Api::SetGround)0x5f484f, (Api::GetGround)0x5f44d9, }, // Gog Api{ (Api::Allocate)0x683b5d, (Api::Constructor)0x5f308e, (Api::CountTerrainCoverage)0x5f33c9, (Api::SetTerrain)0x5f34aa, (Api::GetTerrain)0x5f3118, (Api::SetGround)0x5f351c, (Api::GetGround)0x5f31a6, }, // Scenario Editor Api{ (Api::Allocate)0x4da668, (Api::Constructor)0x5022ee, (Api::CountTerrainCoverage)0x502642, (Api::SetTerrain)0x502723, (Api::GetTerrain)0x502408, (Api::SetGround)0x502795, (Api::GetGround)0x502496, }, }}; static std::array<IMidScenarioObjectVftable*, 4> vftables = {{ // Akella (IMidScenarioObjectVftable*)0x6f0dbc, // Russobit (IMidScenarioObjectVftable*)0x6f0dbc, // Gog (IMidScenarioObjectVftable*)0x6eed5c, // Scenario Editor (IMidScenarioObjectVftable*)0x5db45c, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } IMidScenarioObjectVftable* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMidgardMapBlockApi
2,663
C++
.cpp
85
26.376471
72
0.687281
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,098
drainattackhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/drainattackhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "drainattackhooks.h" #include "attack.h" #include "batattackdrain.h" #include "batattackdrainoverflow.h" #include "battleattackinfo.h" #include "battlemsgdata.h" #include "game.h" #include "hooks.h" #include "log.h" #include "midgardobjectmap.h" #include "midunit.h" #include "midunitgroup.h" #include "settings.h" #include "usunitimpl.h" #include "utils.h" #include "visitors.h" #include <fmt/format.h> namespace hooks { static void addBattleAttackInfo(game::BattleAttackInfo* attackInfo, const game::CMidUnit* unit, int damage, int criticalHitDamage = 0) { using namespace game; BattleAttackUnitInfo info{}; info.unitId = unit->id; info.unitImplId = unit->unitImpl->id; info.damage = damage; info.criticalDamage = criticalHitDamage; BattleAttackInfoApi::get().addUnitInfo(&attackInfo->unitsInfo, &info); } static int drainAttack(game::IMidgardObjectMap* objectMap, game::BattleMsgData* battleMsgData, game::IAttack* attack, const game::CMidgardID* attackerUnitId, const game::CMidgardID* targetUnitId, game::BattleAttackInfo* attackInfo, int drainHealPercent) { using namespace game; const auto& fn = gameFunctions(); if (fn.isUnitImmuneToAttack(objectMap, battleMsgData, targetUnitId, attack, false)) { return 0; } int attackDamage{}; int criticalHitDamage{}; int fullDamage = fn.computeDamage(objectMap, battleMsgData, attack, attackerUnitId, targetUnitId, true, &attackDamage, &criticalHitDamage); auto targetUnit = static_cast<const CMidUnit*>( objectMap->vftable->findScenarioObjectById(objectMap, targetUnitId)); const auto targetInitialHp = targetUnit->currentHp; const auto& visitors = VisitorApi::get(); visitors.changeUnitHp(targetUnitId, -fullDamage, objectMap, 1); const auto targetResultingHp = targetUnit->currentHp; auto drainDamage = (targetInitialHp - targetResultingHp) * drainHealPercent / 100; drainDamage += attack->vftable->getDrain(attack, targetInitialHp - targetResultingHp); const auto& battle = BattleMsgDataApi::get(); battle.checkUnitDeath(objectMap, battleMsgData, targetUnitId); auto attackerUnit = static_cast<const CMidUnit*>( objectMap->vftable->findScenarioObjectById(objectMap, attackerUnitId)); const auto attackerInitialHp = attackerUnit->currentHp; visitors.changeUnitHp(attackerUnitId, drainDamage, objectMap, 1); const auto hpDiff = targetInitialHp - targetResultingHp; int damage{}; int criticalDamage{}; if (hpDiff < criticalHitDamage) { criticalDamage = hpDiff; } else { damage = hpDiff - criticalHitDamage; criticalDamage = criticalHitDamage; } addBattleAttackInfo(attackInfo, targetUnit, damage, criticalDamage); const auto attackerHpDiff = attackerUnit->currentHp - attackerInitialHp; addBattleAttackInfo(attackInfo, attackerUnit, attackerHpDiff); battle.setUnitHp(battleMsgData, targetUnitId, targetUnit->currentHp); battle.setUnitHp(battleMsgData, attackerUnitId, attackerUnit->currentHp); // drain overflow return drainDamage - attackerHpDiff; } static int countUnitsNeedHealing(const game::BattleMsgData* battleMsgData, const game::IMidgardObjectMap* objectMap, const game::CMidUnitGroup* group, const game::CMidgardID* attackerId, game::DrainOverflowHealData* healData) { using namespace game; const auto& groupApi = CMidUnitGroupApi::get(); int unitsNeedHealing = 0; const int unitsTotal = groupApi.getUnitsCount(group); for (int index = 0; index < unitsTotal; ++index) { const CMidgardID* unitId = groupApi.getUnitId(group, index); // Drain overflow does not apply to attacker itself if (*unitId == *attackerId) { continue; } // Don't count units that have already retreated from the battle if (BattleMsgDataApi::get().getUnitStatus(battleMsgData, unitId, BattleStatus::Retreated)) { continue; } const auto& attack = CBatAttackDrainOverflowApi::get(); if (attack.isUnitNotAtFullHp(objectMap, unitId, healData)) { ++unitsNeedHealing; } } return unitsNeedHealing; } static void computeDrainOverflowGroupHeal(game::DrainOverflowHealData* healData, const game::BattleMsgData* battleMsgData, const game::IMidgardObjectMap* objectMap, const game::CMidgardID* groupId, const game::CMidgardID* attackerId, int drainOverflow) { using namespace game; const auto& fn = gameFunctions(); void* tmp = nullptr; const CMidUnitGroup* group = fn.getStackFortRuinGroup(tmp, objectMap, groupId); const int unitsNeedHealing = countUnitsNeedHealing(battleMsgData, objectMap, group, attackerId, healData); if (!unitsNeedHealing) { return; } int remainingDrainOverflow = drainOverflow; int singleUnitHeal = drainOverflow / unitsNeedHealing; if (!singleUnitHeal && drainOverflow > 0) { singleUnitHeal = 1; } const auto& groupApi = CMidUnitGroupApi::get(); const auto& attackApi = CBatAttackDrainOverflowApi::get(); const int unitsCount = groupApi.getUnitsCount(group); for (int index = 0; index < unitsCount && remainingDrainOverflow > 0; ++index) { const CMidgardID* unitId = groupApi.getUnitId(group, index); // Drain overflow does not apply to attacker itself if (*unitId == *attackerId) { continue; } // Don't count units that have already retreated from the battle if (BattleMsgDataApi::get().getUnitStatus(battleMsgData, unitId, BattleStatus::Retreated)) { continue; } if (!attackApi.isUnitNotAtFullHp(objectMap, unitId, healData)) { continue; } const CMidUnit* unit = static_cast<const CMidUnit*>( objectMap->vftable->findScenarioObjectById(objectMap, unitId)); remainingDrainOverflow -= attackApi.updateUnitHealFromDrainOverflow(healData, unit, singleUnitHeal); } if (remainingDrainOverflow > 0) { computeDrainOverflowGroupHeal(healData, battleMsgData, objectMap, groupId, attackerId, remainingDrainOverflow); } } void __fastcall drainAttackOnHitHooked(game::CBatAttackDrain* thisptr, int /*%edx*/, game::IMidgardObjectMap* objectMap, game::BattleMsgData* battleMsgData, game::CMidgardID* unitId, game::BattleAttackInfo** attackInfo) { drainAttack(objectMap, battleMsgData, thisptr->attack, &thisptr->unitId, unitId, *attackInfo, userSettings().drainAttackHeal); } void __fastcall drainOverflowAttackOnHitHooked(game::CBatAttackDrainOverflow* thisptr, int /*%edx*/, game::IMidgardObjectMap* objectMap, game::BattleMsgData* battleMsgData, game::CMidgardID* unitId, game::BattleAttackInfo** attackInfo) { using namespace game; const auto& fn = gameFunctions(); const auto drainOverflow = drainAttack(objectMap, battleMsgData, thisptr->attack, &thisptr->unitId, unitId, *attackInfo, userSettings().drainOverflowHeal); if (!drainOverflow) { return; } CMidgardID unitGroupId{}; fn.getAllyOrEnemyGroupId(&unitGroupId, battleMsgData, &thisptr->unitId, true); const auto& attack = CBatAttackDrainOverflowApi::get(); DrainOverflowHealData healData{}; attack.healDataCtor(&healData); computeDrainOverflowGroupHeal(&healData, battleMsgData, objectMap, &unitGroupId, &thisptr->unitId, drainOverflow); const auto& visitors = VisitorApi::get(); const auto& battle = BattleMsgDataApi::get(); DrainOverflowHealIterator tmp{}; for (const auto& data : healData) { auto unit = static_cast<const CMidUnit*>( objectMap->vftable->findScenarioObjectById(objectMap, &data.first)); const auto unitInitialHp = unit->currentHp; visitors.changeUnitHp(&data.first, data.second, objectMap, 1); const auto unitResultingHp = unit->currentHp; addBattleAttackInfo(*attackInfo, unit, unitResultingHp - unitInitialHp); battle.setUnitHp(battleMsgData, &data.first, unitResultingHp); } attack.healDataDtor(&healData); } } // namespace hooks
10,291
C++
.cpp
218
36.366972
100
0.641801
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,099
managestkinterf.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/managestkinterf.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "managestkinterf.h" #include "version.h" #include <array> namespace game::CManageStkInterfApi { // clang-format off static std::array<Vftable, 4> vftables = {{ // Akella Vftable{ (CMidDataCache2::INotifyVftable*)0x6d751c, (IResetStackExtVftable*)0x6d74fc, (CInterfaceVftable*)0x6d746c, (ITaskManagerHolderVftable*)0x6d745c, (IMidDropManagerVftable*)0x6d741c, }, // Russobit Vftable{ (CMidDataCache2::INotifyVftable*)0x6d751c, (IResetStackExtVftable*)0x6d74fc, (CInterfaceVftable*)0x6d746c, (ITaskManagerHolderVftable*)0x6d745c, (IMidDropManagerVftable*)0x6d741c, }, // Gog Vftable{ (CMidDataCache2::INotifyVftable*)0x6d54bc, (IResetStackExtVftable*)0x6d549c, (CInterfaceVftable*)0x6d540c, (ITaskManagerHolderVftable*)0x6d53fc, (IMidDropManagerVftable*)0x6d53bc, }, // Scenario Editor Vftable{}, }}; // clang-format on Vftable& vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CManageStkInterfApi
1,934
C++
.cpp
57
29.596491
72
0.721688
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,100
displayd3d.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/displayd3d.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "displayd3d.h" #include "version.h" #include <array> namespace game::CDisplayD3DApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::DrawPrimitive)0x6776d0, (Api::SwapBuffers)0x676a40, (Api::AlphaBlend)0x6775f0, }, // Russobit Api{ (Api::DrawPrimitive)0x6776d0, (Api::SwapBuffers)0x676a40, (Api::AlphaBlend)0x6775f0, }, // Gog Api{ (Api::DrawPrimitive)0x675fb0, (Api::SwapBuffers)0x675320, (Api::AlphaBlend)0x675ed0, }, // Scenario Editor Api{ (Api::DrawPrimitive)0x58eaa0, (Api::SwapBuffers)0x58de10, (Api::AlphaBlend)0x58e9c0, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CDisplayD3DApi
1,673
C++
.cpp
55
26.327273
72
0.693118
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,101
borderedimg.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/borderedimg.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "borderedimg.h" #include "version.h" #include <array> namespace game::CBorderedImgApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Constructor)0x5b7353, (Api::AddImage)0x5b74c2, }, // Russobit Api{ (Api::Constructor)0x5b7353, (Api::AddImage)0x5b74c2, }, // Gog Api{ (Api::Constructor)0x5b6559, (Api::AddImage)0x5b66c8, }, // Scenario Editor Api{ (Api::Constructor)0x55a699, (Api::AddImage)0x55a808, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CBorderedImgApi
1,517
C++
.cpp
51
26.039216
72
0.696783
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,102
isoenginegroundhooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/isoenginegroundhooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "isoenginegroundhooks.h" #include "2dengine.h" #include "bordertile.h" #include "isostillbackground.h" #include "midisogroundindexer.h" #include "mqimage2.h" #include "mqrenderer2.h" #include "surfacedecompressdata.h" #include "terraintile.h" #include "utils.h" #include <algorithm> #include <array> #include <cassert> #include <fmt/format.h> #include <vector> namespace hooks { static constexpr game::Color black{0}; static constexpr game::Color magenta{0xff00ffu}; static constexpr game::Color white{0xffffffffu}; /** Array with info about what (and how) needs to be drawn inside of each CGroundTexture. */ static std::vector<game::TileBordersDrawInfo> drawInfoArray; void updateTileBordersDrawInfo(game::CIsoEngineGround::CGroundTexture* groundTexture); static std::uint32_t getTileVariantsCount(const game::IsoEngineGroundArrayElement& element) { auto variants{element.tileVariants.data}; if (!variants) { return 0; } return variants->end - variants->bgn; } static game::CTerrainTile* groundArrayElementGetTile(game::IsoEngineGroundArrayElement& element, std::uint32_t tileVariant) { const auto variantsTotal{getTileVariantsCount(element)}; if (!variantsTotal) { return nullptr; } return element.tileVariants.data->bgn[tileVariant % variantsTotal].data; } static game::CTerrainTile* getFirstTerrainTile(game::IsoEngineGroundArray& groundArray) { for (auto element = groundArray.bgn; element != groundArray.end; ++element) { if (element->water) { continue; } const auto variantsTotal{getTileVariantsCount(*element)}; for (std::uint32_t i = 0; i < variantsTotal; ++i) { auto tile{groundArrayElementGetTile(*element, i)}; if (tile) { return tile; } } } return nullptr; } static game::CTerrainTile* getTerrainTile(game::CIsoEngineGround* engineGround, const game::CMqPoint* position, game::TileArrayIndex tileArrayIndex) { const auto idx{static_cast<int>(tileArrayIndex)}; auto& element{engineGround->data->terrainTiles.bgn[idx]}; if (element.water) { return nullptr; } auto groundIndexer{engineGround->data->isoGroundIndexer}; auto variant{groundIndexer->vftable->getData(groundIndexer, position)}; return groundArrayElementGetTile(element, variant); } static std::uint32_t getBorderTileIndex(std::uint32_t borderIndex, game::TileArrayIndex tileArrayIndex) { return borderIndex + 32 * static_cast<int>(tileArrayIndex); } static game::CBorderTile* getBorderTile(game::Vector<game::BorderTilePtr>* borderTiles, std::uint32_t borderIndex, int borderVariation, game::TileArrayIndex tileArrayIndex) { if (borderIndex && borderIndex != 16) { const auto idx{getBorderTileIndex(borderIndex, tileArrayIndex)}; assert(idx < 320); auto begin{borderTiles[idx].bgn}; auto end{borderTiles[idx].end}; auto total{end - begin}; assert(total > 0); return begin[borderVariation % total].data; } return nullptr; } static game::CBorderTile* getMainBorderTile(game::Vector<game::BorderTilePtr>* borderTiles, const game::TileBorders& borders, game::TileArrayIndex tileArrayIndex) { return getBorderTile(borderTiles, borders.mainIndex, borders.mainVariation, tileArrayIndex); } static game::CBorderTile* getAdditionalBorderTile(game::Vector<game::BorderTilePtr>* borderTiles, const game::TileBorders& borders, game::TileArrayIndex tileArrayIndex) { return getBorderTile(borderTiles, borders.additionalIndex, borders.additionalVariation, tileArrayIndex); } static void drawTerrainTiles(game::CIsoEngineGround* engineGround, game::SurfaceDecompressData* surfaceData, game::TileBordersDrawInfo& drawInfo, const std::uint32_t* blendMask, const std::uint32_t* alphaMask, game::TileArrayIndex tileArrayIndex) { auto& position{drawInfo.pos3}; auto srcPos{&drawInfo.srcPos}; auto dstPos{&drawInfo.dstPos}; using namespace game; auto terrainTile2{getTerrainTile(engineGround, &position, tileArrayIndex)}; if (terrainTile2) { terrainTile2->vftable->draw(terrainTile2, surfaceData, srcPos, dstPos, &surfaceData->textureArea, blendMask, alphaMask); } if (srcPos->y + tileHeight > 192) { const CMqPoint pos{position.x, position.y + tileHeight}; auto terrainTile3{getTerrainTile(engineGround, &pos, tileArrayIndex)}; if (terrainTile3) { CMqPoint src{srcPos->x, srcPos->y - 192}; terrainTile3->vftable->draw(terrainTile3, surfaceData, &src, dstPos, &surfaceData->textureArea, blendMask, alphaMask); } } if (srcPos->x + tileWidth > 192) { const CMqPoint pos{position.x + tileWidth, position.y}; auto terrainTile4{getTerrainTile(engineGround, &pos, tileArrayIndex)}; if (terrainTile4) { CMqPoint src{srcPos->x - 192, srcPos->y}; terrainTile4->vftable->draw(terrainTile4, surfaceData, &src, dstPos, &surfaceData->textureArea, blendMask, alphaMask); } } if (srcPos->x + tileWidth > 192 && srcPos->y + tileHeight > 192) { const CMqPoint pos{position.x + tileHalfWidth, position.y + tileHalfHeight}; auto terrainTile5{getTerrainTile(engineGround, &pos, tileArrayIndex)}; if (terrainTile5) { CMqPoint src{srcPos->x - 192, srcPos->y - 192}; terrainTile5->vftable->draw(terrainTile5, surfaceData, &src, dstPos, &surfaceData->textureArea, blendMask, alphaMask); } } } static void getMasks(game::SurfaceDecompressData* surfaceData, game::CBorderTile* mainBorder, game::CBorderTile* additionalBorder, const std::uint32_t** blendMask, const std::uint32_t** alphaMask) { const auto& surfaceApi{game::SurfaceDecompressDataApi::get()}; if (mainBorder && additionalBorder) { auto maskBuffer{game::CGroundTextureApi::borderMaskBuffer()}; if (mainBorder->vftable->is8BppImage(mainBorder)) { auto buffer = reinterpret_cast<std::uint8_t*>(maskBuffer); auto additionalBorderPixel{additionalBorder->vftable->getByteData(additionalBorder)}; auto mainBorderPixel{mainBorder->vftable->getByteData(mainBorder)}; int pixelCount{game::tilePixelCount}; do { std::uint8_t pixel = *mainBorderPixel; if (!pixel) { pixel = *additionalBorderPixel; } *buffer++ = pixel; ++mainBorderPixel; ++additionalBorderPixel; --pixelCount; } while (pixelCount); *blendMask = reinterpret_cast<const std::uint32_t*>(maskBuffer); *alphaMask = nullptr; } else { auto buffer = reinterpret_cast<std::uint16_t*>(maskBuffer); auto additionalBorderPixel{additionalBorder->vftable->getWordData(additionalBorder)}; auto mainBorderPixel{mainBorder->vftable->getWordData(mainBorder)}; const auto magentaConverted{surfaceApi.convertColor(surfaceData, &magenta)}; int pixelCount{game::tilePixelCount}; do { std::uint16_t pixel = *mainBorderPixel; if (pixel == magentaConverted) { pixel = *additionalBorderPixel; } *buffer++ = pixel; ++mainBorderPixel; ++additionalBorderPixel; --pixelCount; } while (pixelCount); *blendMask = nullptr; *alphaMask = reinterpret_cast<const std::uint32_t*>(maskBuffer); } return; } if (mainBorder) { if (mainBorder->vftable->is8BppImage(mainBorder)) { *blendMask = (const std::uint32_t*)mainBorder->vftable->getByteData(mainBorder); *alphaMask = nullptr; } else { *blendMask = nullptr; *alphaMask = (const std::uint32_t*)mainBorder->vftable->getWordData(mainBorder); } return; } if (additionalBorder) { if (additionalBorder->vftable->is8BppImage(additionalBorder)) { *blendMask = (const std::uint32_t*)additionalBorder->vftable->getByteData( additionalBorder); *alphaMask = nullptr; } else { *blendMask = nullptr; *alphaMask = (const std::uint32_t*)additionalBorder->vftable->getWordData( additionalBorder); } } } void __stdcall groundTextureDrawHooked(game::CIsoEngineGround::CGroundTexture* thisptr, game::SurfaceDecompressData* surfaceData) { using namespace game; auto engineGround{thisptr->isoEngineGround}; auto& borderTiles{engineGround->data->borderTiles}; auto groundIndexer{engineGround->data->isoGroundIndexer}; groundIndexer->vftable->updateData(groundIndexer); updateTileBordersDrawInfo(thisptr); if (thisptr->hidden) { return; } const auto& surfaceApi{SurfaceDecompressDataApi::get()}; if (thisptr->hasWaterTiles) { if (engineGround->data->animatedIso) { // Fill entire area with transparent (magenta) color and remember it const auto magentaConverted{surfaceApi.convertColor(surfaceData, &magenta)}; surfaceApi.fillArea(surfaceData, magentaConverted, &surfaceData->textureArea); surfaceApi.setColor(surfaceData, magentaConverted); } else { auto stillBackground{engineGround->data->isoStillBackground}; if (stillBackground) { // Draw still background if we have it stillBackground->vftable->draw(stillBackground, surfaceData); } else { // Otherwise fill area with black color const auto blackConverted{surfaceApi.convertColor(surfaceData, &black)}; surfaceApi.fillArea(surfaceData, blackConverted, &surfaceData->textureArea); } } } if (!engineGround->data->animatedIso) { surfaceApi.setColor(surfaceData, white); } auto& terrainTiles{engineGround->data->terrainTiles}; auto terrainTile{getFirstTerrainTile(terrainTiles)}; assert(terrainTile != nullptr); for (auto& drawInfo : drawInfoArray) { const std::uint32_t* blendMask{}; const std::uint32_t* alphaMask{}; if (drawInfo.hidden) { // Draw under the fog of war? terrainTile->vftable->method2(terrainTile, surfaceData, &drawInfo.dstPos, &surfaceData->textureArea); continue; } auto tileInfo{drawInfo.tileInfo}; if (tileInfo->bordersTotal < 0) { // No borders, nothing to do here continue; } const auto tileType{tileInfo->tileArrayIndex}; if (!terrainTiles.bgn[static_cast<int>(tileType)].water) { // Ground tile, draw terrain tiles drawTerrainTiles(engineGround, surfaceData, drawInfo, blendMask, alphaMask, tileType); } else { // Water tile, check for coast borders and draw if present if (tileInfo->hasWaterBorders) { const auto& waterBorders{tileInfo->waterBorders}; auto main{getMainBorderTile(borderTiles, waterBorders, tileType)}; if (main) { main->vftable->draw(main, surfaceData, &drawInfo.dstPos, &surfaceData->textureArea); } auto additional{getAdditionalBorderTile(borderTiles, waterBorders, tileType)}; if (additional) { additional->vftable->draw(additional, surfaceData, &drawInfo.dstPos, &surfaceData->textureArea); } } } // Draw border tiles for (int border = 0; border < tileInfo->bordersTotal; ++border) { auto& borders{tileInfo->borders[border]}; const auto bordersType{borders.tileArrayIndex}; auto mainBorder{getMainBorderTile(borderTiles, borders, bordersType)}; auto additionalBorder{getAdditionalBorderTile(borderTiles, borders, bordersType)}; getMasks(surfaceData, mainBorder, additionalBorder, &blendMask, &alphaMask); drawTerrainTiles(engineGround, surfaceData, drawInfo, blendMask, alphaMask, bordersType); } } thisptr->dirty = false; return; } static std::uint32_t getTileMainBorder(int positionX, int positionY, int mapSize, game::TileBordersInfo* bordersInfo, game::TileArrayIndex tileType, const game::TileArrayIndex* expectedAdjacent = nullptr) { using namespace game; // clang-format off static const std::array<CMqPoint, 4> offsets = {{ CMqPoint{-1, 0}, CMqPoint{ 0, -1}, CMqPoint{ 1, 0}, CMqPoint{ 0, 1} }}; // clang-format on // Assume there are no borders by default std::uint32_t mainBorder{}; for (std::uint32_t i = 0; i < offsets.size(); ++i) { const int x = positionX + offsets[i].x; const int y = positionY + offsets[i].y; if (x < 0 || y < 0 || x >= mapSize || y >= mapSize) { // Skip tiles outside of the map. // With assumption above it means // we do not draw tile borders on map edges. continue; } auto& adjacentTile{bordersInfo[x + y * mapSize]}; if (adjacentTile.tileArrayIndex == tileType) { continue; } if (expectedAdjacent && adjacentTile.tileArrayIndex != *expectedAdjacent) { continue; } mainBorder |= 1 << i; } return mainBorder; } static std::uint32_t getTileAdditionalBorder(std::uint32_t mainBorder, int positionX, int positionY, int mapSize, game::TileBordersInfo* bordersInfo, game::TileArrayIndex tileType, const game::TileArrayIndex* expectedAdjacent = nullptr) { using namespace game; // Assume there are no additional borders by default std::uint32_t additionalBorder{}; // Check 4 triplets of adjacent tiles for (std::uint32_t triplet = 0; triplet < 4; ++triplet) { // Skip triplet check if main border index contains set bit at triplet position. // We don't want to draw additional borders above main. if (mainBorder & (1 << triplet)) { continue; } // clang-format off static const std::array<std::array<CMqPoint, 3>, 4> triplets = {{ {{ CMqPoint{-1, 0}, CMqPoint{-1, -1}, CMqPoint{ 0, -1} }}, {{ CMqPoint{ 0, -1}, CMqPoint{ 1, -1}, CMqPoint{ 1, 0} }}, {{ CMqPoint{ 1, 0}, CMqPoint{ 1, 1}, CMqPoint{ 0, 1} }}, {{ CMqPoint{ 0, 1}, CMqPoint{-1, 1}, CMqPoint{-1, 0} }} }}; // clang-format on const auto& offsets{triplets[triplet]}; std::uint32_t tmpBorder{}; for (std::uint32_t i = 0; i < offsets.size(); ++i) { const int x = positionX + offsets[i].x; const int y = positionY + offsets[i].y; if (x < 0 || y < 0 || x >= mapSize || y >= mapSize) { // Skip tiles outside of the map. // With additionalBorder being zero by default it means // we do not draw additional tile borders on map edges. continue; } auto& adjacentTile{bordersInfo[x + y * mapSize]}; if (adjacentTile.tileArrayIndex == tileType) { continue; } if (expectedAdjacent && adjacentTile.tileArrayIndex != *expectedAdjacent) { continue; } tmpBorder |= 1 << i; } // Middle tile from triplet had ground, it is an additional border additionalBorder |= static_cast<std::uint32_t>(tmpBorder == 2) << triplet; } if (additionalBorder) { // Adjust border index to 17 - 31 // 16 is an invalid border index just as 0 additionalBorder += 16; } return additionalBorder; } static void updateTileBorders(game::CIsoEngineGround* thisptr) { using namespace game; if (!thisptr->data->dirty) { return; } thisptr->data->dirty = false; auto& tileBorders{thisptr->data->tileBorders}; const auto mapSize{static_cast<int>(thisptr->data->mapSize)}; for (int indexY = 0; indexY < mapSize; ++indexY) { for (int indexX = 0; indexX < mapSize; ++indexX) { auto& tile{tileBorders.bgn[indexX + indexY * mapSize]}; const auto tileType{tile.tileArrayIndex}; tile.hasWaterBorders = false; tile.bordersTotal = 0; // +1 to get borders that can be drawn above current tile, not below for (int i = static_cast<int>(tileType) + 1; i < 8; ++i) { const auto expected = static_cast<TileArrayIndex>(i); const auto mainIndex{getTileMainBorder(indexX, indexY, mapSize, tileBorders.bgn, tileType, &expected)}; const auto additionalIndex{getTileAdditionalBorder(mainIndex, indexX, indexY, mapSize, tileBorders.bgn, tileType, &expected)}; if (mainIndex || additionalIndex) { auto& border = tile.borders[tile.bordersTotal]; border.tileArrayIndex = expected; border.mainIndex = mainIndex; border.additionalIndex = additionalIndex; ++tile.bordersTotal; } } if (tile.bordersTotal) { // Sort in such a way that borders with lesser types are (drawn) first std::sort(&tile.borders[0], &tile.borders[tile.bordersTotal], [](const TileBorders& a, const TileBorders& b) { return a.tileArrayIndex < b.tileArrayIndex; }); // Water tiles that have borders with ground (coastal tiles) // should also have water borders if (tileType == TileArrayIndex::Water) { const auto mainIndex{getTileMainBorder(indexX, indexY, mapSize, tileBorders.bgn, TileArrayIndex::Water)}; const auto additionalIndex{getTileAdditionalBorder(mainIndex, indexX, indexY, mapSize, tileBorders.bgn, TileArrayIndex::Water)}; if (mainIndex || additionalIndex) { auto& waterBorders{tile.waterBorders}; waterBorders.tileArrayIndex = TileArrayIndex::Water; waterBorders.mainIndex = mainIndex; waterBorders.additionalIndex = additionalIndex; tile.hasWaterBorders = true; } } } } } } /** Projects tile coordinate to the screen coordinate in isometric view. */ static game::CMqPoint tilePositionToScreen(const game::CMqPoint& p) { using namespace game; return CMqPoint{p.x * tileHalfWidth - p.y * tileHalfWidth, p.x * tileHalfHeight + p.y * tileHalfHeight}; } static game::CMqPoint textureCoordToTileCoord(const game::CMqPoint& textureCoordinate) { using namespace game; // clang-format off static const std::array<char, tilePixelCount> tileIndices = {{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2, 1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2, 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4, 3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4, 3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4, 3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 }}; // clang-format on const auto x{textureCoordinate.x}; const auto y{textureCoordinate.y}; const int adjX{x <= 0 ? x - tileWidth + 1 : x}; const int adjY{y <= 0 ? y - tileHeight + 1 : y}; const int tileIndexX{adjX / tileWidth}; const int tileIndexY{adjY / tileHeight}; int coordX{tileIndexX + tileIndexY}; int coordY{tileIndexY - tileIndexX}; const auto index{65 * std::abs(y - tileHeight * tileIndexY) + std::abs(x - tileIndexX * tileWidth)}; const int tileIndex{tileIndices[index]}; switch (tileIndex) { case 0: default: break; case 1: --coordX; break; case 2: --coordY; break; case 3: ++coordY; break; case 4: ++coordX; break; } return game::CMqPoint{coordX, coordY}; } void __fastcall isoEngineGroundRenderHooked(game::CIsoEngineGround* thisptr, int /*%edx*/, game::IMqRenderer2* renderer, const game::CMqPoint* position, const game::CMqRect* area) { using namespace game; auto& groundTextures{thisptr->data->groundTextures}; for (auto textureData = groundTextures.bgn; textureData != groundTextures.end; ++textureData) { auto groundTexture{textureData->texture}; if (groundTexture->vftable->isDirty(groundTexture)) { updateTileBordersDrawInfo(groundTexture); } if (groundTexture->hidden) { continue; } const auto& textureOffset{textureData->textureOffset}; CMqPoint start{textureOffset.x + position->x, textureOffset.y + position->y}; CMqPoint offset{}; CMqPoint* size{&textureData->textureHandle.textureSize}; if (thisptr->data->animatedIso && groundTexture->hasWaterTiles) { auto waterBgnd{thisptr->data->waterBackground}; if (waterBgnd) { waterBgnd->vftable->render(waterBgnd, renderer, &start, &offset, size, area); } } renderer->vftable->drawTexture(renderer, &textureData->textureHandle, &start, &offset, size, area); } } static void splitTextureOffset(const game::CMqPoint& textureOffset, game::CMqPoint& tileCoordinate, game::CMqPoint& dst) { tileCoordinate = textureCoordToTileCoord(textureOffset); const auto screenPos{tilePositionToScreen(tileCoordinate)}; dst = screenPos - textureOffset; } static game::TileBordersInfo* getTileBordersInfo(game::CIsoEngineGround& engineGround, const game::CMqPoint& mapPosition) { const auto mapSize{static_cast<int>(engineGround.data->mapSize)}; const auto x{mapPosition.x}; const auto y{mapPosition.y}; if (x >= 0 && x < mapSize && y >= 0 && y < mapSize) { return &engineGround.data->tileBorders.bgn[x + y * mapSize]; } return &engineGround.data->outOfMapBorders; } /** Returns true if specified map position is completely hidden by fog of war. */ static bool isPositionFullyHidden(game::CIsoEngineGround& engineGround, const game::CMqPoint& mapPosition) { using namespace game; if (!getTileBordersInfo(engineGround, mapPosition)->hidden) { return false; } // clang-format off static const std::array<CMqPoint, 8> offsets = {{ CMqPoint{-1, 1}, CMqPoint{ 0, 1}, CMqPoint{ 1, 1}, CMqPoint{ 1, 0}, CMqPoint{ 1, -1}, CMqPoint{ 0, -1}, CMqPoint{-1, -1}, CMqPoint{-1, 0} }}; // clang-format on const auto mapSize{static_cast<int>(engineGround.data->mapSize)}; // Check if adjacent tiles are hidden too for (const auto& offset : offsets) { const CMqPoint position{mapPosition.x + offset.x, mapPosition.y + offset.y}; if (position.x >= 0 && position.x < mapSize && position.y >= 0 && position.y < mapSize) { if (!getTileBordersInfo(engineGround, position)->hidden) { return false; } } } return true; } static void fillBordersDrawInfo(game::CIsoEngineGround::CGroundTexture* groundTexture, const game::CMqPoint& mapPosition, const game::CMqPoint& dstPos, game::TileBordersDrawInfo& drawInfo) { using namespace game; auto& engineGround{*groundTexture->isoEngineGround}; auto tileBorders{getTileBordersInfo(engineGround, mapPosition)}; drawInfo.tileInfo = tileBorders; drawInfo.dstPos = dstPos; if (isPositionFullyHidden(engineGround, mapPosition)) { drawInfo.hidden = true; return; } const auto mapSize{engineGround.data->mapSize}; drawInfo.srcPos = groundTexture->textureOffset; drawInfo.srcPos += dstPos; drawInfo.srcPos.x += mapSize * tileWidth; drawInfo.srcPos.y += mapSize * tileHeight; drawInfo.pos3 = drawInfo.srcPos; drawInfo.srcPos.x %= 192; drawInfo.srcPos.y %= 192; if (engineGround.data->terrainTiles.bgn[static_cast<int>(tileBorders->tileArrayIndex)].water) { groundTexture->hasWaterTiles = true; } drawInfo.hidden = false; groundTexture->hidden = false; } void updateTileBordersDrawInfo(game::CIsoEngineGround::CGroundTexture* groundTexture) { using namespace game; auto engineGround{groundTexture->isoEngineGround}; updateTileBorders(engineGround); drawInfoArray.clear(); groundTexture->hasWaterTiles = false; groundTexture->hidden = true; CMqPoint tileCoordinate{}; CMqPoint dst{}; splitTextureOffset(groundTexture->textureOffset, tileCoordinate, dst); --tileCoordinate.x; for (int y = dst.y - tileHalfHeight; y < 128; y += tileHeight, ++tileCoordinate.x, ++tileCoordinate.y) { CMqPoint mapPos{tileCoordinate}; for (int x = dst.x - tileHalfWidth; x < 128; x += tileWidth, --mapPos.y) { const CMqPoint dstPos{x, y}; TileBordersDrawInfo drawInfo{}; fillBordersDrawInfo(groundTexture, mapPos, dstPos, drawInfo); drawInfoArray.push_back(drawInfo); ++mapPos.x; const CMqPoint dstPos2{x + tileHalfWidth, y + tileHalfHeight}; TileBordersDrawInfo drawInfo2{}; fillBordersDrawInfo(groundTexture, mapPos, dstPos2, drawInfo2); drawInfoArray.push_back(drawInfo2); } } if (groundTexture->hidden) { groundTexture->dirty = false; } } } // namespace hooks
33,279
C++
.cpp
686
37.075802
136
0.579809
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,103
scenariodata.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/scenariodata.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "scenariodata.h" #include "version.h" #include <array> namespace game::ScenarioDataApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::Constructor)0x605bf2, (Api::Destructor)0x605c8c, (Api::CopyConstructor)0x60624b }, // Russobit Api{ (Api::Constructor)0x605bf2, (Api::Destructor)0x605c8c, (Api::CopyConstructor)0x60624b }, // Gog Api{ (Api::Constructor)0x6046ff, (Api::Destructor)0x604799, (Api::CopyConstructor)0x604d58 } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::ScenarioDataApi
1,531
C++
.cpp
49
27.510204
72
0.706838
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,104
button.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/button.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2020 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "button.h" #include "version.h" #include <array> namespace game::CButtonInterfApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::AssignFunctor)0x5c93d6, }, // Russobit Api{ (Api::AssignFunctor)0x5c93d6, }, // Gog Api{ (Api::AssignFunctor)0x5c83a4, }, // Scenario Editor Api{ (Api::AssignFunctor)0x4d0ee8, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CButtonInterfApi
1,389
C++
.cpp
47
26.297872
72
0.707554
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,105
ddcarryoveritems.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/ddcarryoveritems.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "ddcarryoveritems.h" #include "version.h" #include <array> namespace game::CDDCarryOverItemsApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::Constructor)0x4f9ce5 }, // Russobit Api{ (Api::Constructor)0x4f9ce5 }, // Gog Api{ (Api::Constructor)0x4f90a9 } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CDDCarryOverItemsApi
1,320
C++
.cpp
43
27.697674
72
0.720912
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,106
unitpickerinterf.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/unitpickerinterf.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "unitpickerinterf.h" #include "version.h" #include <array> namespace game::editor::CUnitPickerInterfApi { Api& get() { // clang-format off static Api api{ (Api::DataConstructor)0x44183e, (Api::UpdateRadioButton)0x441a71, (Api::UpdateEnabledButtons)0x441c86, (Api::UpdateEditLevel)0x44240e, (Api::FilterUnits)0x442680, (Api::SortUnits)0x442705, (Api::OnTogglePressed)0x442520, (UnitPickerSubrace*)0x663650, (UnitPickerSortMethod*)0x64ea08, }; // clang-format on return api; } } // namespace game::editor::CUnitPickerInterfApi
1,443
C++
.cpp
40
32.225
72
0.728898
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,107
unitutils.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/unitutils.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "unitutils.h" #include "attack.h" #include "attacksourcecat.h" #include "attacksourcelist.h" #include "attackutils.h" #include "battlemsgdata.h" #include "customattacks.h" #include "dynamiccast.h" #include "fortcategory.h" #include "fortification.h" #include "game.h" #include "gameutils.h" #include "globaldata.h" #include "globalvariables.h" #include "immunecat.h" #include "leaderabilitycat.h" #include "log.h" #include "lordtype.h" #include "midgardid.h" #include "midgardmap.h" #include "midgardmapblock.h" #include "midgardobjectmap.h" #include "midplayer.h" #include "midstack.h" #include "midunit.h" #include "midvillage.h" #include "modifierutils.h" #include "racetype.h" #include "scenarioinfo.h" #include "settings.h" #include "ummodifier.h" #include "unitgenerator.h" #include "unitmodifier.h" #include "usleader.h" #include "usracialsoldier.h" #include "ussoldier.h" #include "ussoldierimpl.h" #include "usstackleader.h" #include "usunitimpl.h" #include "utils.h" #include "visitors.h" #include <fmt/format.h> namespace hooks { void generateUnitImplByAttackId(const game::CMidgardID* attackId) { using namespace game; const auto& id = CMidgardIDApi::get(); int typeIndex = id.getTypeIndex(attackId); int categoryIndex = id.getCategoryIndex(attackId); IdCategory category = id.getCategory(attackId); CMidgardID unitImplId{}; id.fromParts(&unitImplId, category, categoryIndex, IdType::UnitGenerated, typeIndex); CUnitGenerator* unitGenerator = (*(GlobalDataApi::get().getGlobalData()))->unitGenerator; unitGenerator->vftable->generateUnitImpl(unitGenerator, &unitImplId); } game::IUsSoldier* castUnitImplToSoldierWithLogging(const game::IUsUnit* unitImpl) { using namespace game; auto soldier = gameFunctions().castUnitImplToSoldier(unitImpl); if (!soldier) { hooks::logError("mssProxyError.log", fmt::format("Failed to cast unit impl {:s} to soldier", hooks::idToString(&unitImpl->id))); } return soldier; } void getSoldierAttackSourceImmunities(const game::LImmuneCat* immuneCat, const game::IUsSoldier* soldier, game::List<game::LAttackSource>* value) { using namespace game; const auto& sources = AttackSourceCategories::get(); const auto& sourceListApi = AttackSourceListApi::get(); if (immuneCat->id == soldier->vftable->getImmuneByAttackSource(soldier, sources.weapon)->id) sourceListApi.add(value, sources.weapon); if (immuneCat->id == soldier->vftable->getImmuneByAttackSource(soldier, sources.mind)->id) sourceListApi.add(value, sources.mind); if (immuneCat->id == soldier->vftable->getImmuneByAttackSource(soldier, sources.life)->id) sourceListApi.add(value, sources.life); if (immuneCat->id == soldier->vftable->getImmuneByAttackSource(soldier, sources.death)->id) sourceListApi.add(value, sources.death); if (immuneCat->id == soldier->vftable->getImmuneByAttackSource(soldier, sources.fire)->id) sourceListApi.add(value, sources.fire); if (immuneCat->id == soldier->vftable->getImmuneByAttackSource(soldier, sources.water)->id) sourceListApi.add(value, sources.water); if (immuneCat->id == soldier->vftable->getImmuneByAttackSource(soldier, sources.air)->id) sourceListApi.add(value, sources.air); if (immuneCat->id == soldier->vftable->getImmuneByAttackSource(soldier, sources.earth)->id) sourceListApi.add(value, sources.earth); for (const auto& custom : getCustomAttacks().sources) { if (immuneCat->id == soldier->vftable->getImmuneByAttackSource(soldier, &custom.source)->id) sourceListApi.add(value, &custom.source); } } bool isUnitSmall(const game::CMidUnit* unit) { using namespace game; const auto& fn = gameFunctions(); auto soldier = fn.castUnitImplToSoldier(unit->unitImpl); return soldier->vftable->getSizeSmall(soldier); } game::CMidgardID getGlobalUnitImplId(const game::CMidgardID* unitImplId) { using namespace game; CMidgardID globalImplId{}; CUnitGenerator* unitGenerator = (*(GlobalDataApi::get().getGlobalData()))->unitGenerator; unitGenerator->vftable->getGlobalUnitImplId(unitGenerator, &globalImplId, unitImplId); return globalImplId; } game::TUsUnitImpl* getGlobalUnitImpl(const game::CMidgardID* unitImplId) { const game::CMidgardID globalImplId{getGlobalUnitImplId(unitImplId)}; return getUnitImpl(&globalImplId); } game::TUsUnitImpl* generateUnitImpl(const game::CMidgardID* unitImplId, int level) { using namespace game; CMidgardID generatedId; CUnitGenerator* unitGenerator = (*(GlobalDataApi::get().getGlobalData()))->unitGenerator; unitGenerator->vftable->generateUnitImplId(unitGenerator, &generatedId, unitImplId, level); if (unitGenerator->vftable->isUnitGenerated(unitGenerator, &generatedId)) { unitGenerator->vftable->generateUnitImpl(unitGenerator, &generatedId); } return getUnitImpl(&generatedId); } game::TUsUnitImpl* getUnitImpl(const game::CMidgardID* unitImplId) { using namespace game; const auto& global = GlobalDataApi::get(); auto globalData = *global.getGlobalData(); auto result = (TUsUnitImpl*)global.findById(globalData->units, unitImplId); if (!result) { logError("mssProxyError.log", fmt::format("Could not find unit impl {:s}", idToString(unitImplId))); } return result; } game::TUsUnitImpl* getUnitImpl(const game::IUsUnit* unit) { using namespace game; const auto& rtti = RttiApi::rtti(); const auto dynamicCast = RttiApi::get().dynamicCast; CUmModifier* modifier = nullptr; for (auto curr = unit; curr; curr = modifier->data->prev) { modifier = (CUmModifier*)dynamicCast(curr, 0, rtti.IUsUnitType, rtti.CUmModifierType, 0); if (!modifier) return (TUsUnitImpl*)curr; } return nullptr; } game::TUsSoldierImpl* getSoldierImpl(const game::IUsUnit* unit) { using namespace game; const auto& rtti = RttiApi::rtti(); const auto dynamicCast = RttiApi::get().dynamicCast; return (TUsSoldierImpl*)dynamicCast(getUnitImpl(unit), 0, rtti.IUsUnitType, rtti.TUsSoldierImplType, 0); } game::TUsSoldierImpl* getSoldierImpl(const game::IUsSoldier* soldier) { using namespace game; const auto& rtti = RttiApi::rtti(); const auto dynamicCast = RttiApi::get().dynamicCast; auto unit = (IUsUnit*)dynamicCast(soldier, 0, rtti.IUsSoldierType, rtti.IUsUnitType, 0); return getSoldierImpl(unit); } game::IAttack* getAttack(const game::IUsUnit* unit, bool primary, bool checkAltAttack) { using namespace game; auto soldier = gameFunctions().castUnitImplToSoldier(unit); if (!soldier) return nullptr; auto attack = primary ? soldier->vftable->getAttackById(soldier) : soldier->vftable->getSecondAttackById(soldier); if (attack && checkAltAttack) { auto altAttack = getGlobalAttack(attack->vftable->getAltAttackId(attack)); if (altAttack) return wrapAltAttack(unit, altAttack); } return attack; } game::IAttack* getAltAttack(const game::IUsUnit* unit, bool primary) { auto attack = getAttack(unit, primary, false); auto altAttack = getGlobalAttack(attack->vftable->getAltAttackId(attack)); if (!altAttack) { return nullptr; } return wrapAltAttack(unit, altAttack); } int getArmor(const game::CMidgardID* unitId, const game::IUsSoldier* soldier, const game::BattleMsgData* battleMsgData, bool includeShattered, bool includeFortification) { using namespace game; const auto& battle = BattleMsgDataApi::get(); int armor; soldier->vftable->getArmor(soldier, &armor); if (!includeShattered) armor -= battle.getUnitShatteredArmor(battleMsgData, unitId); if (!includeFortification) armor -= battle.getUnitFortificationArmor(battleMsgData, unitId); return armor > 0 ? armor : 0; } const game::CDynUpgrade* getDynUpgrade(const game::IUsUnit* unit, int upgradeNumber) { using namespace game; if (upgradeNumber != 1 && upgradeNumber != 2) { return nullptr; } auto soldier = hooks::castUnitImplToSoldierWithLogging(unit); if (!soldier) { return nullptr; } auto id = upgradeNumber == 1 ? soldier->vftable->getDynUpg1(soldier) : soldier->vftable->getDynUpg2(soldier); if (!id) { hooks::logError("mssProxyError.log", fmt::format("Dyn upgrade {:d} id is null, unit impl {:s}", upgradeNumber, hooks::idToString(&unit->id))); return nullptr; } const auto& globalApi = GlobalDataApi::get(); auto globalData = *globalApi.getGlobalData(); auto upgrade = globalApi.findDynUpgradeById(globalData->dynUpgrade, id); if (!upgrade) { hooks::logError("mssProxyError.log", fmt::format("Could not find dyn upgrade {:d} {:s}", upgradeNumber, hooks::idToString(id))); return nullptr; } return upgrade; } int getCityProtection(const game::IMidgardObjectMap* objectMap, const game::CMidgardID* unitId) { using namespace game; const auto& fn{gameFunctions()}; const auto dynamicCast = RttiApi::get().dynamicCast; const auto& rtti = RttiApi::rtti(); auto findObject{objectMap->vftable->findScenarioObjectById}; auto objectId{fn.getStackFortRuinId(unitId, objectMap)}; const auto objectType{CMidgardIDApi::get().getType(objectId)}; CMidgardID fortificationId{emptyId}; if (objectType == IdType::Fortification) { fortificationId = *objectId; } else if (objectType == IdType::Stack) { auto stackObject{findObject(objectMap, objectId)}; auto stack{(const CMidStack*)dynamicCast(stackObject, 0, rtti.IMidScenarioObjectType, rtti.CMidStackType, 0)}; if (stack && stack->insideId != emptyId) { fortificationId = stack->insideId; } } if (fortificationId != emptyId) { auto fortification{(CFortification*)findObject(objectMap, &fortificationId)}; if (fortification) { auto vftable{(const CFortificationVftable*)fortification->vftable}; const auto& list{IdListApi::get()}; IdList modifiers; list.constructor(&modifiers); vftable->getProtection(fortification, objectMap, &modifiers); const auto protection{applyModifiers(0, modifiers, ModifierElementTypeFlag::Armor)}; list.destructor(&modifiers); return protection; } } // Only fortifications (cities) grant protection return 0; } static int getLordRegenBonus(const game::CMidPlayer* player) { using namespace game; const auto& fn = gameFunctions(); const auto& globalApi = GlobalDataApi::get(); const auto globalData = *globalApi.getGlobalData(); const auto vars = *globalData->globalVariables; if (!player || player->capturedById != emptyId) { return 0; } if (fn.isRaceCategoryUnplayable(&player->raceType->data->raceType)) { return 0; } const auto lords = globalData->lords; const auto lordType = (const TLordType*)globalApi.findById(lords, &player->lordId); if (lordType->data->lordCategory.id == LordCategories::get().warrior->id) { return vars->fighterLeaderRegen; } return 0; } static int getFortRegen(int base, const game::IMidgardObjectMap* objectMap, const game::CFortification* fort) { using namespace game; auto vftable{static_cast<const CFortificationVftable*>(fort->vftable)}; auto category{vftable->getCategory(fort)}; if (category->id == FortCategories::get().village->id) { auto village{static_cast<const CMidVillage*>(fort)}; if (village->riotTurn > 0) { return 0; // Units in rioting villages take damage instead of regeneration } } int regen; return base + *vftable->getRegen(fort, &regen, objectMap); } static int getTerrainRegenBonus(const game::IMidgardObjectMap* objectMap, const game::CMidPlayer* player, const game::CMidStack* stack) { using namespace game; auto map = getMidgardMap(objectMap); auto block = getMidgardMapBlock(objectMap, &map->id, map->mapSize, stack->position.x, stack->position.y); LTerrainCategory terrain{}; if (!CMidgardMapBlockApi::get().getTerrain(block, &terrain, &stack->position)) { return 0; } auto raceTerrain = getTerrainCategory(&player->raceType->data->raceType); if (terrain.id == raceTerrain->id) { return 10; // Strictly hard-coded in game, not even const data } return 0; } // See CEffectRegenUnitsApply, CEffectRegenRuinsApply int getUnitRegen(const game::IMidgardObjectMap* objectMap, const game::CMidgardID* unitId) { using namespace game; const auto& fn = gameFunctions(); const auto& globalApi = GlobalDataApi::get(); const auto globalData = *globalApi.getGlobalData(); const auto vars = *globalData->globalVariables; const CMidPlayer* player = nullptr; const CFortification* fort = nullptr; const CMidRuin* ruin = nullptr; const CMidStack* stack = getStackByUnitId(objectMap, unitId); if (stack) { player = getPlayer(objectMap, &stack->ownerId); if (stack->insideId != emptyId) { fort = getFort(objectMap, &stack->insideId); } } else { fort = getFortByUnitId(objectMap, unitId); if (fort) { player = getPlayer(objectMap, &fort->ownerId); } else { ruin = getRuinByUnitId(objectMap, unitId); } } auto unit = fn.findUnitById(objectMap, unitId); auto soldier = fn.castUnitImplToSoldier(unit->unitImpl); int result = *soldier->vftable->getRegen(soldier); result += getLordRegenBonus(player); if (fort) { // Total regen in fort can be zero in case of riot result = getFortRegen(result, objectMap, fort); } else if (ruin) { // Units in ruins have fixed regen value, no other factors apply result = vars->regenRuin; } else { // Terrain bonus apply only outside result += getTerrainRegenBonus(objectMap, player, stack); } return std::clamp(result, 0, 100); } int getUnitHpMax(const game::CMidUnit* unit) { using namespace game; if (unit->transformed && unit->keepHp) return unit->hpBefMax; auto soldier = gameFunctions().castUnitImplToSoldier(unit->unitImpl); return soldier->vftable->getHitPoints(soldier); } const char* getUnitName(const game::CMidUnit* unit) { using namespace game; const auto& rtti = RttiApi::rtti(); auto impl = unit->unitImpl; if (castUnitImpl(impl, rtti.IUsStackLeaderType) && !castUnitImpl(impl, rtti.IUsNobleType) && !castUnitImpl(impl, rtti.IUsSummonType)) { return unit->name.string ? unit->name.string : ""; } auto soldier = (IUsSoldier*)castUnitImpl(impl, rtti.IUsSoldierType); return soldier->vftable->getName(soldier); } game::IUsUnitExtension* castUnitImpl(const game::IUsUnit* unitImpl, const game::TypeDescriptor* type) { using namespace game; auto& typeInfoRawName = *RttiApi::get().typeInfoRawName; return unitImpl ? unitImpl->vftable->cast(unitImpl, typeInfoRawName(type)) : nullptr; } int computeUnitEffectiveHpForAi(int hp, int armor) { if (userSettings().fixEffectiveHpFormula) { return computeUnitEffectiveHp(hp, armor); } if (hp < 0) { return 0; } return hp * armor / 100 + hp; } int computeUnitEffectiveHp(int hp, int armor) { if (hp <= 0) { return 0; } int factor = 100 - armor; if (factor <= 0) return std::numeric_limits<int>::max(); return hp * 100 / factor; } int computeShatterDamage(const game::CMidgardID* unitId, const game::IUsSoldier* soldier, const game::BattleMsgData* battleMsgData, const game::IAttack* attack) { using namespace game; const auto& battle = BattleMsgDataApi::get(); int armor = getArmor(unitId, soldier, battleMsgData, false, false); int limit = userSettings().shatteredArmorMax - battle.getUnitShatteredArmor(battleMsgData, unitId); int result = attack->vftable->getQtyDamage(attack); if (result > armor) result = armor; if (result > limit) result = limit; if (result > userSettings().shatterDamageMax) result = userSettings().shatterDamageMax; return result; } void updateAttackCountAfterTransformation(game::BattleMsgData* battleMsgData, const game::CMidUnit* unit, bool prevAttackTwice) { using namespace game; for (auto& turn : battleMsgData->turnsOrder) { if (turn.unitId == unit->id) { const auto soldier = gameFunctions().castUnitImplToSoldier(unit->unitImpl); bool attackTwice = soldier && soldier->vftable->getAttackTwice(soldier); if (!prevAttackTwice && attackTwice) turn.attackCount++; else if (prevAttackTwice && !attackTwice && turn.attackCount > 1) turn.attackCount--; break; } } } bool isStackLeaderAndAllowedToUseBattleItems(const game::IMidgardObjectMap* objectMap, const game::CMidgardID* unitId, const game::BattleMsgData* battleMsgData) { using namespace game; const auto& battleApi = BattleMsgDataApi::get(); auto stack = getStack(objectMap, battleMsgData, unitId); if (!stack || stack->leaderId != *unitId) return false; if (battleApi.getUnitStatus(battleMsgData, unitId, BattleStatus::Transform)) return userSettings().allowBattleItems.onTransformOther; else if (battleApi.getUnitStatus(battleMsgData, unitId, BattleStatus::TransformSelf)) return userSettings().allowBattleItems.onTransformSelf; else if (battleApi.getUnitStatus(battleMsgData, unitId, BattleStatus::TransformDrainLevel)) return userSettings().allowBattleItems.onDrainLevel; else if (battleApi.getUnitStatus(battleMsgData, unitId, BattleStatus::TransformDoppelganger)) return userSettings().allowBattleItems.onDoppelganger; return true; } bool hasLeaderAbility(const game::IUsUnit* unitImpl, const game::LLeaderAbility* ability) { using namespace game; auto stackLeader{gameFunctions().castUnitImplToStackLeader(unitImpl)}; if (!stackLeader) { return false; } return stackLeader->vftable->hasAbility(stackLeader, ability); } bool hasCriticalHitLeaderAbility(const game::IUsUnit* unitImpl) { using namespace game; return hasLeaderAbility(unitImpl, LeaderAbilityCategories::get().criticalHit); } bool validateUnit(game::CMidUnit* unit) { using namespace game; const auto& fn = gameFunctions(); IUsUnit* origImpl = unit->transformed ? hooks::getUnitImpl(&unit->origTypeId) : unit->unitImpl; auto soldier = fn.castUnitImplToSoldier(origImpl); bool result = false; auto validXp = std::clamp(unit->currentXp, 0, soldier->vftable->getXpNext(soldier) - 1); if (unit->currentXp != validXp) { unit->currentXp = validXp; result = true; } auto validHp = std::clamp(unit->currentHp, 0, getUnitHpMax(unit)); if (unit->currentHp != validHp) { unit->currentHp = validHp; result = true; } return result; } bool canUnitGainXp(const game::IUsUnit* unitImpl) { using namespace game; auto unitCategory = unitImpl->vftable->getCategory(unitImpl); return unitCategory->id != UnitId::Noble && unitCategory->id != UnitId::Summon && unitCategory->id != UnitId::Illusion && unitCategory->id != UnitId::Guardian; } bool isNextUnitImpl(const game::IUsUnit* unitImpl, const game::IUsUnit* currImpl) { using namespace game; const auto& fn = gameFunctions(); if (fn.castUnitImplToLeader(currImpl)) { auto leader = fn.castUnitImplToLeader(unitImpl); if (leader) { return *leader->vftable->getPrevUnitImplId(leader) == currImpl->id; } } else { auto racialSoldier = fn.castUnitImplToRacialSoldier(unitImpl); if (racialSoldier) { return *racialSoldier->vftable->getPrevUnitImplId(racialSoldier) == currImpl->id; } } return false; } bool isNextTierUnitImpl(const game::IUsUnit* unitImpl, const game::IUsUnit* currImpl) { using namespace game; const auto& idApi = CMidgardIDApi::get(); if (idApi.getType(&unitImpl->id) == IdType::UnitGenerated) { return false; } return isNextUnitImpl(unitImpl, currImpl); } bool hasNextTierUnitImpl(const game::IUsUnit* unitImpl) { using namespace game; const auto& globalApi = GlobalDataApi::get(); const auto globalData = *globalApi.getGlobalData(); const auto& units = globalData->units->map->data; for (auto it = units.bgn; it != units.end; ++it) { if (isNextTierUnitImpl(it->second, unitImpl)) { return true; } } return false; } bool hasMaxTierUpgradeBuilding(const game::IMidgardObjectMap* objectMap, const game::IUsUnit* unitImpl) { using namespace game; const auto& fn = gameFunctions(); auto racialSoldier = fn.castUnitImplToRacialSoldier(unitImpl); if (!racialSoldier) { return false; } auto upgradeBuildingId = racialSoldier->vftable->getUpgradeBuildingId(racialSoldier); if (*upgradeBuildingId == emptyId) { return false; } auto scenarioInfo = getScenarioInfo(objectMap); return getBuildingLevel(upgradeBuildingId) >= scenarioInfo->unitMaxTier; } const game::TUsUnitImpl* getUpgradeUnitImpl(const game::IMidgardObjectMap* objectMap, const game::CMidPlayer* player, const game::CMidUnit* unit) { using namespace game; const auto& fn = gameFunctions(); const auto& globalApi = GlobalDataApi::get(); const auto& idApi = CMidgardIDApi::get(); if (!unit->dynLevel && idApi.getType(&unit->unitImpl->id) != IdType::UnitGenerated) { bool hasBuildableNextTier = false; const auto globalData = *globalApi.getGlobalData(); const auto& units = globalData->units->map->data; for (auto it = units.bgn; it != units.end; ++it) { if (isNextTierUnitImpl(it->second, unit->unitImpl)) { auto upgradeBuildingId = getUpgradeBuildingId(it->second); if (upgradeBuildingId == emptyId) { return it->second; } // capturedById explicit check is required because captured players still have their // CPlayerBuildings untouched, allowing their units to use upgrade buildings from // captured capital if (player && player->capturedById == emptyId) { if (playerHasBuilding(objectMap, player, &upgradeBuildingId)) { return it->second; } if (isBuildingBuildable(objectMap, &player->id, &upgradeBuildingId)) { hasBuildableNextTier = true; } } } } if (hasBuildableNextTier) { return nullptr; } } auto soldier = fn.castUnitImplToSoldier(unit->unitImpl); return generateUnitImpl(&unit->unitImpl->id, soldier->vftable->getLevel(soldier) + 1); } game::CMidgardID getUpgradeBuildingId(const game::IUsUnit* unitImpl) { using namespace game; const auto& fn = gameFunctions(); auto racialSoldier = fn.castUnitImplToRacialSoldier(unitImpl); return racialSoldier ? *racialSoldier->vftable->getUpgradeBuildingId(racialSoldier) : emptyId; } int getGeneratedUnitImplLevelMax() { using namespace game; const auto& globalApi = GlobalDataApi::get(); const auto globalData = *globalApi.getGlobalData(); const auto units = globalData->units; return 0xffff / units->baseCount; } int addUnitXpNoUpgrade(game::IMidgardObjectMap* objectMap, game::CMidUnit* unit, int value) { using namespace game; auto soldier = gameFunctions().castUnitImplToSoldier(unit->unitImpl); auto xpNext = soldier->vftable->getXpNext(soldier); int xpAmount = value; if (xpAmount >= xpNext - unit->currentXp) { xpAmount = xpNext - unit->currentXp - 1; } if (!VisitorApi::get().changeUnitXp(&unit->id, xpAmount, objectMap, 1)) { return 0; } return xpAmount; } } // namespace hooks
26,197
C++
.cpp
647
33.608964
100
0.677503
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,108
midunitgroup.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/midunitgroup.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "midunitgroup.h" #include "version.h" #include <array> namespace game::CMidUnitGroupApi { // clang-format off std::array<Api, 4> functions = {{ // Akella Api{ (Api::GetUnitId)0x5f57f1, (Api::GetUnitPosition)0x5f5897, (Api::GetUnitIdByPosition)0x5f586f, (Api::AddUnitIdsAvailableForSummons)0x628a02, (Api::UnknownFunction)0x631c50, (Api::GetUnitsCount)0x5f5779, }, // Russobit Api{ (Api::GetUnitId)0x5f57f1, (Api::GetUnitPosition)0x5f5897, (Api::GetUnitIdByPosition)0x5f586f, (Api::AddUnitIdsAvailableForSummons)0x628a02, (Api::UnknownFunction)0x631c50, (Api::GetUnitsCount)0x5f5779, }, // Gog Api{ (Api::GetUnitId)0x5f44b9, (Api::GetUnitPosition)0x5f455f, (Api::GetUnitIdByPosition)0x5f4537, (Api::AddUnitIdsAvailableForSummons)0x627542, (Api::UnknownFunction)0x630690, (Api::GetUnitsCount)0x5f4441, }, // Scenario Editor Api{ (Api::GetUnitId)0x4f03e8, (Api::GetUnitPosition)0x4f0444, (Api::GetUnitIdByPosition)0x4f041c, (Api::AddUnitIdsAvailableForSummons)nullptr, (Api::UnknownFunction)nullptr, (Api::GetUnitsCount)0x4f0370, }, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMidUnitGroupApi
2,234
C++
.cpp
67
28.373134
72
0.699352
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,109
commandmsghooks.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/commandmsghooks.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "commandmsghooks.h" #include "cmdbattlechooseactionmsg.h" #include "cmdbattleendmsg.h" #include "cmdbattleresultmsg.h" #include "cmdbattlestartmsg.h" #include "dynamiccast.h" #include "netmsgutils.h" #include "originalfunctions.h" namespace hooks { void __fastcall cmdBattleStartMsgSerializeHooked(game::CCmdBattleStartMsg* thisptr, int /*%edx*/, game::CMqStream* stream) { serializeMsgWithBattleMsgData((game::CNetMsg*)thisptr, &thisptr->battleMsgData, getOriginalFunctions().cmdBattleStartMsgSerialize, stream); } void __fastcall cmdBattleChooseActionMsgSerializeHooked(game::CCmdBattleChooseActionMsg* thisptr, int /*%edx*/, game::CMqStream* stream) { serializeMsgWithBattleMsgData((game::CNetMsg*)thisptr, &thisptr->battleMsgData, getOriginalFunctions().cmdBattleChooseActionMsgSerialize, stream); } void __fastcall cmdBattleResultMsgSerializeHooked(game::CCmdBattleResultMsg* thisptr, int /*%edx*/, game::CMqStream* stream) { serializeMsgWithBattleMsgData((game::CNetMsg*)thisptr, &thisptr->battleMsgData, getOriginalFunctions().cmdBattleResultMsgSerialize, stream); } void __fastcall cmdBattleEndMsgSerializeHooked(game::CCmdBattleEndMsg* thisptr, int /*%edx*/, game::CMqStream* stream) { serializeMsgWithBattleMsgData((game::CNetMsg*)thisptr, &thisptr->battleMsgData, getOriginalFunctions().cmdBattleEndMsgSerialize, stream); } /* * Had to patch it here since direct class destructors are not called in some places because they * are transformed to inline. CCommandMsg dtor is always called as function by derived classes. */ void __fastcall commandMsgDtorHooked(game::CCommandMsg* thisptr, int /*%edx*/) { using namespace game; const auto& rtti = RttiApi::rtti(); const auto& battle = BattleMsgDataApi::get(); const auto dynamicCast = RttiApi::get().dynamicCast; auto battleResultMsg = (CCmdBattleResultMsg*)dynamicCast(thisptr, 0, rtti.CNetMsgType, rtti.CCommandMsgTempl_10_0_Type, 0); if (battleResultMsg != nullptr) { battle.destructor(&battleResultMsg->battleMsgData); getOriginalFunctions().commandMsgDtor(thisptr); return; } auto battleChooseActionMsg = (CCmdBattleChooseActionMsg*) dynamicCast(thisptr, 0, rtti.CNetMsgType, rtti.CCommandMsgTempl_9_0_Type, 0); if (battleChooseActionMsg != nullptr) { battle.destructor(&battleChooseActionMsg->battleMsgData); getOriginalFunctions().commandMsgDtor(thisptr); return; } auto battleStartMsg = (CCmdBattleStartMsg*)dynamicCast(thisptr, 0, rtti.CNetMsgType, rtti.CCommandMsgTempl_8_1_Type, 0); if (battleStartMsg != nullptr) { battle.destructor(&battleStartMsg->battleMsgData); getOriginalFunctions().commandMsgDtor(thisptr); return; } auto battleEndMsg = (CCmdBattleEndMsg*)dynamicCast(thisptr, 0, rtti.CNetMsgType, rtti.CCommandMsgTempl_11_2_Type, 0); if (battleEndMsg != nullptr) { battle.destructor(&battleEndMsg->battleMsgData); getOriginalFunctions().commandMsgDtor(thisptr); return; } getOriginalFunctions().commandMsgDtor(thisptr); } } // namespace hooks
4,663
C++
.cpp
96
37.8125
100
0.647924
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,110
batattackdrainoverflow.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/batattackdrainoverflow.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "batattackdrainoverflow.h" #include "version.h" #include <array> namespace game::CBatAttackDrainOverflowApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::HealDataConstructor)0x668910, (Api::HealDataDestructor)0x668990, (Api::ComputeDrainOverflowGroupHeal)0x661138, (Api::IsUnitNotAtFullHp)0x66137a, (Api::UpdateUnitHealFromDrainOverflow)0x661255, }, // Russobit Api{ (Api::HealDataConstructor)0x668910, (Api::HealDataDestructor)0x668990, (Api::ComputeDrainOverflowGroupHeal)0x661138, (Api::IsUnitNotAtFullHp)0x66137a, (Api::UpdateUnitHealFromDrainOverflow)0x661255, }, // Gog Api{ (Api::HealDataConstructor)0x667360, (Api::HealDataDestructor)0x6673e0, (Api::ComputeDrainOverflowGroupHeal)0x65fbb8, (Api::IsUnitNotAtFullHp)0x65fdfa, (Api::UpdateUnitHealFromDrainOverflow)0x65fcd5, }, }}; static std::array<IBatAttackVftable*, 4> vftables = {{ // Akella (IBatAttackVftable*)0x6f536c, // Russobit (IBatAttackVftable*)0x6f536c, // Gog (IBatAttackVftable*)0x6f331c, // Scenario Editor (IBatAttackVftable*)nullptr, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } IBatAttackVftable* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CBatAttackDrainOverflowApi
2,305
C++
.cpp
69
29.217391
72
0.723643
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,111
enclayoutruin.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/enclayoutruin.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2022 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "enclayoutruin.h" #include "version.h" #include <array> namespace game::CEncLayoutRuinApi { // clang-format off static std::array<Api, 4> functions = {{ // Akella Api{ (Api::Update)0x57a003, }, // Russobit Api{ (Api::Update)0x57a003, }, // Gog Api{ (Api::Update)0x5796be, }, // Scenario Editor Api{ (Api::Update)0x4cb3c7, }, }}; static std::array<IEncLayoutVftable*, 4> vftables = {{ // Akella (IEncLayoutVftable*)0x6e8b34, // Russobit (IEncLayoutVftable*)0x6e8b34, // Gog (IEncLayoutVftable*)0x6e6ad4, // Scenario Editor (IEncLayoutVftable*)0x5d7efc, }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } IEncLayoutVftable* vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CEncLayoutRuinApi
1,726
C++
.cpp
61
24.934426
72
0.703257
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,112
miditem.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/miditem.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2021 Vladimir Makeev. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "miditem.h" #include "version.h" #include <array> namespace game::CMidItemApi { // clang-format off static std::array<Api, 3> functions = {{ // Akella Api{ (Api::GetSellingPrice)0x5e0f98 }, // Russobit Api{ (Api::GetSellingPrice)0x5e0f98 }, // Gog Api{ (Api::GetSellingPrice)0x5dfccd } }}; // clang-format on Api& get() { return functions[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CMidItemApi
1,305
C++
.cpp
43
27.348837
72
0.717582
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,542,113
umstack.cpp
VladimirMakeev_D2ModdingToolset/mss32/src/umstack.cpp
/* * This file is part of the modding toolset for Disciples 2. * (https://github.com/VladimirMakeev/D2ModdingToolset) * Copyright (C) 2023 Stanislav Egorov. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "umstack.h" #include "version.h" #include <array> namespace game::CUmStackApi { // clang-format off static std::array<Vftable, 4> vftables = {{ // Akella Vftable{ (IUsUnitVftable*)0x6ecd84, (IUsStackLeaderVftable*)0x6ecd54, (CUmModifierVftable*)0x6ecd24, }, // Russobit Vftable{ (IUsUnitVftable*)0x6ecd84, (IUsStackLeaderVftable*)0x6ecd54, (CUmModifierVftable*)0x6ecd24, }, // Gog Vftable{ (IUsUnitVftable*)0x6ead24, (IUsStackLeaderVftable*)0x6eacf4, (CUmModifierVftable*)0x6eacc4, }, // Scenario Editor Vftable{ (IUsUnitVftable*)0x5e0f4c, (IUsStackLeaderVftable*)0x5e0f1c, (CUmModifierVftable*)0x5e0eec, }, }}; // clang-format on Vftable& vftable() { return vftables[static_cast<int>(hooks::gameVersion())]; } } // namespace game::CUmStackApi
1,719
C++
.cpp
55
27.163636
72
0.708861
VladimirMakeev/D2ModdingToolset
32
13
15
GPL-3.0
9/20/2024, 10:45:25 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false