mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
* feat(pvp): add IsActiveBattlefieldArena Stock 1.12 has no arenas, so it answers nil there. Turtle-lineage clients add arena matches, run in instances IsInInstance reports as "pvp": in a "pvp" instance their scoreboard asks for arena scores over the hidden TW_ARENA channel, only an arena answers, and the scoreboard keeps the reply in WorldStateScoreFrame.arenaData until the world states update outside an instance. isArena follows that state, as the scoreboard's own arena view does (Octo's FrameXML, patch-4.mpq: WorldStateFrame.lua and Turtle_ArenaUI.lua). isRegistered is always nil: the reply has no rated flag, and the client's queue window only joins skirmishes. Zygor Guides Viewer 2.0 calls it, unguarded, to decide whether to set its corpse arrow when the player is dead outside a battleground. Verified in-game (OctoWoW 1.12.1 client via VanillaFixes): outside an instance it returns nil, nil. The arena branch has not been exercised in a match yet. * refactor(pvp): answer IsActiveBattlefieldArena from DBC data in C The Lua version read Turtle's scoreboard state (WorldStateScoreFrame.arenaData), which is nil until the server's TW_ARENA reply lands and depends on Turtle's FrameXML. The client's own data already marks an arena: a pvp-type map (Map.dbc instanceType 3) whose area carries AreaTable flag 0x80, the flag Script_GetZonePVPInfo reports as isArena. Check the zone as well as the subzone, since the arena maps' areas are top-level zones. The type-3 gate keeps the open-world rings (Gurubashi, The Maul) out. Returns booleans, as retail does; isRegistered is always false. Offsets.h: add OFF_AREATABLE_FLAGS, AREA_FLAG_ARENA and VAR_PLAYER_SUBZONE_AREA_ID, and correct the zone-change handler's second argument (the subzone ID, not the parent area ID). * docs(pvp): note the server only ever creates arena map 26 tortoise-wow's GetBattleGrounMapIdByTypeId sends its one arena type, BATTLEGROUND_BR, to map 26 (Blood Ring); map 28 (Lordaeron Arena) is client data only. --------- Co-authored-by: Brues <5278969+brues-code@users.noreply.github.com>
111 lines
4.5 KiB
C++
111 lines
4.5 KiB
C++
// This file is part of ClassicAPI.
|
|
//
|
|
// ClassicAPI 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.
|
|
//
|
|
// ClassicAPI 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
|
|
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#include "Game.h"
|
|
#include "Offsets.h"
|
|
|
|
#include <cstdint>
|
|
|
|
// `IsActiveBattlefieldArena()` -> isArena, isRegistered.
|
|
//
|
|
// The client has no arena battlefield state of its own; what marks an arena is
|
|
// its DBC data. An arena match is a pvp-type map (Map.dbc instanceType 3, the
|
|
// same type battlegrounds use) whose area carries AreaTable flag 0x80 — the
|
|
// flag `Script_GetZonePVPInfo` reports as its isArena return. Verified against
|
|
// the extracted DBCs: Turtle's arena maps 26 (Blood Ring) and 28 (Lordaeron
|
|
// Arena) are type 3 with areas 4014 / 4013 flagged 0x80, and no battleground
|
|
// area has the flag. Server side (tortoise-wow SharedDefines.h,
|
|
// GetBattleGrounMapIdByTypeId) the one arena type, BATTLEGROUND_BR, always
|
|
// creates map 26; map 28 is client data only. The type-3 gate excludes the
|
|
// open-world free-for-all rings (Gurubashi, The Maul, Rumble Cage), which are
|
|
// flagged but sit on type-0 continents.
|
|
//
|
|
// Both the zone and the subzone are checked. `Script_GetZonePVPInfo` reads
|
|
// only the subzone, which is 0 on the arena maps: their areas are top-level
|
|
// zones with no children, so the engine files them as the zone.
|
|
//
|
|
// 3.3.5 answers from the battlefield status array (an active arena
|
|
// battlefield). Being on an arena map is the same condition for every caller
|
|
// that can observe it, and is true from the moment the map loads.
|
|
//
|
|
// isRegistered (a rated match) is always false: nothing client-side carries a
|
|
// rated flag.
|
|
namespace PvP::Arena {
|
|
|
|
namespace {
|
|
|
|
constexpr uint32_t MAP_INSTANCE_TYPE_PVP = 3;
|
|
|
|
const uint8_t *DbcRecord(uintptr_t recordsVar, uintptr_t countVar, uint32_t id) {
|
|
const int count = *reinterpret_cast<const int *>(countVar);
|
|
if (id == 0 || static_cast<int>(id) > count)
|
|
return nullptr;
|
|
const uint8_t *const *records =
|
|
*reinterpret_cast<const uint8_t *const *const *>(recordsVar);
|
|
return records != nullptr ? records[id] : nullptr;
|
|
}
|
|
|
|
bool IsArenaArea(uint32_t areaID) {
|
|
const uint8_t *rec = DbcRecord(Offsets::VAR_AREATABLE_RECORDS,
|
|
Offsets::VAR_AREATABLE_COUNT, areaID);
|
|
if (rec == nullptr)
|
|
return false;
|
|
const uint32_t flags =
|
|
*reinterpret_cast<const uint32_t *>(rec + Offsets::OFF_AREATABLE_FLAGS);
|
|
return (flags & Offsets::AREA_FLAG_ARENA) != 0;
|
|
}
|
|
|
|
bool InArena() {
|
|
const uint32_t mapID = *reinterpret_cast<const uint32_t *>(
|
|
static_cast<uintptr_t>(Offsets::VAR_CURRENT_MAP_ID));
|
|
const uint8_t *map =
|
|
DbcRecord(Offsets::VAR_MAP_RECORDS, Offsets::VAR_MAP_COUNT, mapID);
|
|
if (map == nullptr)
|
|
return false;
|
|
const uint32_t type =
|
|
*reinterpret_cast<const uint32_t *>(map + Offsets::OFF_MAP_INSTANCE_TYPE);
|
|
if (type != MAP_INSTANCE_TYPE_PVP)
|
|
return false;
|
|
|
|
const uint32_t zone = *reinterpret_cast<const uint32_t *>(
|
|
static_cast<uintptr_t>(Offsets::VAR_PLAYER_AREA_ID));
|
|
const uint32_t subzone = *reinterpret_cast<const uint32_t *>(
|
|
static_cast<uintptr_t>(Offsets::VAR_PLAYER_SUBZONE_AREA_ID));
|
|
return IsArenaArea(subzone) || IsArenaArea(zone);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
static int __fastcall Script_IsActiveBattlefieldArena(void *L) {
|
|
Game::Lua::PushBool(L, InArena());
|
|
Game::Lua::PushBool(L, false);
|
|
return 2;
|
|
}
|
|
|
|
static const Game::Doc::Field kRets[] = {
|
|
Game::Doc::Req("isArena", "bool", "True while the player is in an arena match."),
|
|
Game::Doc::Req("isRegistered", "bool", "True for a rated match; always false here."),
|
|
};
|
|
static const Game::Doc::Function kDoc = {
|
|
"Returns whether the player is in an arena match, and whether it is rated.",
|
|
{}, kRets, "PvPGlobals"};
|
|
|
|
static void RegisterLuaFunctions() {
|
|
Game::Lua::RegisterGlobalFunction("IsActiveBattlefieldArena",
|
|
&Script_IsActiveBattlefieldArena, &kDoc);
|
|
}
|
|
|
|
static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};
|
|
|
|
} // namespace PvP::Arena
|