Files
ForeverCore/tests/common/ClassicWireSpecReader.h
Karrz1 ff699fb5cf Sync with WoW Forever 0.1.34: Blizzlike core
Brings forever up to date with our 0.1.34 code for the WoW Forever client 1.60.1.70862.
Blizzlike only: fixes from real game data (packet captures, live hotfixes, player caches, Wowhead and Questie data,
VMaNGOS for the vanilla world) and server fixes. No custom items or custom content; every rate and option defaults
to Blizzard's behaviour.

What is new since 2ae1313e, in short:
- Clients 70790, 70840 and 70862: message numbers, mail, guild window, charters, contact list, add-on whispers.
- Crash and exploit fixes: guild ranks, loot of emptied veins, quest lookups, taxi mask, battleground templates,
  vendor free buys, item sell price, auction house, falling out of the world, bnetserver request limit.
- Classes, talents, pets and buffs from the live game data and Blizzard's hotfixes of November.
- Quests, NPCs, spawns, trainers, loot, fishing, events, Merchant's Favor crates and writs, sealed crate turn-ins.
- Dungeon and raid scripts (Molten Core, Blackwing Lair, Zul'Gurub, Ahn'Qiraj, Shadowfang Keep, Deadmines ...).
- Pathing fixes that help pets and NPCs.
- Russian creature names, quest titles and quest texts.
- README: Blizzlike stance, branches, repack.
2026-11-09 17:27:57 +00:00

85 lines
2.3 KiB
C++

#ifndef TRINITYCORE_TESTS_CLASSIC_WIRE_SPEC_READER_H
#define TRINITYCORE_TESTS_CLASSIC_WIRE_SPEC_READER_H
#include "Define.h"
#include <bit>
#include <sstream>
#include <string>
#include <string_view>
// The 70291 client's own reader specs (see tests/game/ClassicWireSpec.cpp for the grammar) and a reader that checks a packet payload against one.
// Shared by the golden byte tests and the headless client.
namespace ClassicWireSpec
{
struct SpecEntry
{
uint32 Index;
char const* Spec;
};
inline constexpr SpecEntry MainGroupSpecs[] =
{
#include "Classic70291MainGroupSpecs.inc"
};
inline constexpr uint32 MainGroup70291 = 0x47;
inline SpecEntry const* FindSpec(uint32 wireOpcode)
{
if ((wireOpcode >> 16) != MainGroup70291)
return nullptr;
for (SpecEntry const& entry : MainGroupSpecs)
if (entry.Index == (wireOpcode & 0xFFFF))
return &entry;
return nullptr;
}
// Reads `spec` from `data`; returns an empty string if the data is consumed exactly, else what went wrong.
inline std::string ReadSpec(std::string_view spec, uint8 const* data, size_t size)
{
size_t pos = 0;
std::istringstream tokens{ std::string(spec) };
std::string token;
std::ostringstream trace;
while (tokens >> token)
{
size_t need = 0;
if (token == "u8")
need = 1;
else if (token == "u16")
need = 2;
else if (token == "u32")
need = 4;
else if (token == "u64")
need = 8;
else if (token == "GUID")
{
if (pos + 2 > size)
{
trace << "GUID mask at " << pos << " is past the end (" << size << " bytes)";
return trace.str();
}
need = 2 + size_t(std::popcount(uint32(data[pos])) + std::popcount(uint32(data[pos + 1])));
}
else
return "spec token not readable: " + token;
if (pos + need > size)
{
trace << "client reads " << token << " at byte " << pos << " but the packet has " << size << " bytes";
return trace.str();
}
pos += need;
}
if (pos != size)
{
trace << "client stops at byte " << pos << ", the packet has " << size << " (" << (size - pos) << " bytes the client never reads)";
return trace.str();
}
return { };
}
}
#endif