From 7aba6250f6d244b5fa19c4803bb407fab2d9be25 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 31 Oct 2016 15:02:32 +0100 Subject: [PATCH] Load team zones. --- src/Components/Modules/ArenaLength.cpp | 23 +++++++------- src/Components/Modules/Maps.cpp | 42 ++++++++++++++++++++++++++ src/Components/Modules/Maps.hpp | 2 ++ src/Game/Structs.hpp | 12 ++++++-- 4 files changed, 65 insertions(+), 14 deletions(-) diff --git a/src/Components/Modules/ArenaLength.cpp b/src/Components/Modules/ArenaLength.cpp index b3a25922..8ae1d3d0 100644 --- a/src/Components/Modules/ArenaLength.cpp +++ b/src/Components/Modules/ArenaLength.cpp @@ -68,22 +68,21 @@ namespace Components Utils::Hook::Set(0x630B2E, &ArenaLength::NewArenas[0]); Utils::Hook::Set(0x632782, &ArenaLength::NewArenas[0]); - Utils::Hook::Set(0x4A967A, &ArenaLength::NewArenas[0].other[0]); - - Utils::Hook::Set(0x4A96AD, &ArenaLength::NewArenas[0].other[0x20]); - - Utils::Hook::Set(0x42F214, &ArenaLength::NewArenas[0].other[0xA40]); - - Utils::Hook::Set(0x4A96ED, &ArenaLength::NewArenas[0].other[0xA48]); - Utils::Hook::Set(0x4A9769, &ArenaLength::NewArenas[0].other[0xA48]); - Utils::Hook::Set(0x4A97A5, &ArenaLength::NewArenas[0].other[0xA48]); - - Utils::Hook::Set(0x631E92, &ArenaLength::NewArenas[0].other[0xACC]); + Utils::Hook::Set(0x4A967A, ArenaLength::NewArenas[0].description); + Utils::Hook::Set(0x4A96AD, ArenaLength::NewArenas[0].mapimage); Utils::Hook::Set(0x4A9616, ArenaLength::NewArenas[0].mapName); Utils::Hook::Set(0x4A9703, ArenaLength::NewArenas[0].mapName); Utils::Hook::Set(0x4064A8, ArenaLength::NewArenas[0].mapName); + Utils::Hook::Set(0x42F214, &ArenaLength::NewArenas[0].other[0]); + + Utils::Hook::Set(0x4A96ED, &ArenaLength::NewArenas[0].other[0x8]); + Utils::Hook::Set(0x4A9769, &ArenaLength::NewArenas[0].other[0x8]); + Utils::Hook::Set(0x4A97A5, &ArenaLength::NewArenas[0].other[0x8]); + + Utils::Hook::Set(0x631E92, &ArenaLength::NewArenas[0].other[0x8C]); + // Resize the array Utils::Hook::Set(0x4064DE, sizeof(Game::newMapArena_t)); Utils::Hook::Set(0x417802, sizeof(Game::newMapArena_t)); @@ -112,6 +111,6 @@ namespace Components Utils::Hook::Set(0x4A95F8, 32); - Utils::Hook::Set(0x42F22B, offsetof(Game::newMapArena_t, mapName) - offsetof(Game::newMapArena_t, other[0xA40])); + Utils::Hook::Set(0x42F22B, offsetof(Game::newMapArena_t, mapName) - offsetof(Game::newMapArena_t, other)); } } diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index a10e4266..37db0ecc 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -29,9 +29,22 @@ namespace Components } } + Utils::Memory::Allocator allocator; + auto teams = Maps::GetTeamsForMap(Maps::CurrentMainZone); + std::vector data; Utils::Merge(&data, zoneInfo, zoneCount); + Game::XZoneInfo team; + team.allocFlags = zoneInfo->allocFlags; + team.freeFlags = zoneInfo->freeFlags; + + team.name = allocator.DuplicateString(fmt::sprintf("iw4x_team_%s", teams.first.data())); + data.push_back(team); + + team.name = allocator.DuplicateString(fmt::sprintf("iw4x_team_%s", teams.second.data())); + data.push_back(team); + for (unsigned int i = 0; i < Maps::CurrentDependencies.size(); ++i) { Game::XZoneInfo info; @@ -198,6 +211,35 @@ namespace Components return (Utils::String::StartsWith(entity, "dyn_") || Utils::String::StartsWith(entity, "node_") || Utils::String::StartsWith(entity, "actor_")); } + std::pair Maps::GetTeamsForMap(std::string map) + { + std::string team_axis = "opforce_composite"; + std::string team_allies = "us_army"; + + for (int i = 0; i < *Game::arenaCount; ++i) + { + Game::newMapArena_t* arena = &ArenaLength::NewArenas[i]; + if (arena->mapName == map) + { + for (int j = 0; j < ARRAY_SIZE(arena->keys); ++j) + { + if (arena->keys[j] == "allieschar"s) + { + team_allies = arena->values[j]; + } + else if (arena->keys[j] == "axischar"s) + { + team_axis = arena->values[j]; + } + } + + break; + } + } + + return { team_axis, team_allies }; + } + #if defined(DEBUG) && defined(ENABLE_DXSDK) // Credit to SE2Dev, as we shouldn't share the code, keep that in debug mode! void Maps::ExportMap(Game::GfxWorld* world) diff --git a/src/Components/Modules/Maps.hpp b/src/Components/Modules/Maps.hpp index ae4153c5..27ec5fa0 100644 --- a/src/Components/Modules/Maps.hpp +++ b/src/Components/Modules/Maps.hpp @@ -13,6 +13,8 @@ namespace Components static void HandleAsSPMap() { IsSPMap = true; } static void AddDependency(std::string expression, std::string zone); + static std::pair GetTeamsForMap(std::string map); + private: class DLC { diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 93a1a672..72069472 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -3009,14 +3009,22 @@ namespace Game { char uiName[32]; char mapName[16]; - char pad[2768]; + char description[32]; + char mapimage[32]; + char keys[32][16]; + char values[32][64]; + char pad[144]; }; struct newMapArena_t { char uiName[32]; char oldMapName[16]; - char other[2768]; + char description[32]; + char mapimage[32]; + char keys[32][16]; + char values[32][64]; + char other[144]; char mapName[32]; };