218 lines
13 KiB
C++
218 lines
13 KiB
C++
#include "gateway/roster_translation.hpp"
|
|
#include <iostream>
|
|
#include <source_location>
|
|
using namespace gateway;
|
|
namespace {
|
|
void check(bool good,std::source_location at=std::source_location::current()){if(!good)throw Error("roster visual fixture assertion at line "+std::to_string(at.line()));}
|
|
template<class F>void rejects(F f){try{f();}catch(const Error&){return;}throw Error("expected roster preview rejection");}
|
|
Bytes source_roster(uint8_t race=1,uint8_t gender=0,std::array<uint8_t,5> appearance={},uint32_t flags=0){
|
|
// Independent Player::BuildEnumData source field order. The source has20
|
|
// display/type pairs and deliberately NO item IDs or enchant identifiers.
|
|
Bytes out{1};le(out,4509,8);cstring(out,"Preview");
|
|
append(out,Bytes{race,1,gender});for(auto value:appearance)le(out,value,1);le(out,60,1);le(out,12,4);le(out,0,4);
|
|
for(unsigned i=0;i<3;++i)le(out,0,4); // XYZ floats0.
|
|
le(out,0,4);le(out,flags,4);le(out,0,1);
|
|
for(unsigned i=0;i<3;++i)le(out,0,4); // Pet metadata.
|
|
for(unsigned i=0;i<20;++i){le(out,1000+11*i,4);le(out,i,1);}
|
|
return out;
|
|
}
|
|
std::array<Bytes,19> visual_records(const Bytes& packet,bool realmless,uint32_t expected_flags=0){
|
|
Reader r(packet);check(r.le(1)==(realmless?0xc0:0x80));check(r.le(1)==0x80);
|
|
check(r.le(4)==(realmless?0:1));check(r.le(4)==(realmless?1:0));
|
|
r.take(24); // Max level, unlock counts and optional ClassDisableMask.
|
|
auto guid=unpack_guid(r,16);auto expected=forever_player_guid(4509,70);check(guid==Bytes(expected.begin(),expected.end()));
|
|
r.take(4+2+3+2);check(r.le(4)<=250); // Virtual/list/race/sex/class/spec/customization count.
|
|
r.take(1+4+4+12); // Level/map/zone/XYZ.
|
|
check(r.le(8)==(4509u|(uint64_t(70)<<48)));
|
|
check(unpack_guid(r,16)==Bytes(16));
|
|
check(r.le(4)==expected_flags);r.take(13+12); // Unrelated flags/restriction byte and pet fields.
|
|
std::array<Bytes,19> out{};for(auto& row:out)row=r.take(23);
|
|
return out;
|
|
}
|
|
struct NativeAppearanceRow {
|
|
uint8_t race,gender,cls;
|
|
uint16_t position;
|
|
uint64_t member_id;
|
|
Bytes guild_guid;
|
|
std::vector<std::array<uint32_t,2>> choices;
|
|
std::string name;
|
|
};
|
|
std::vector<NativeAppearanceRow> appearance_rows(const Bytes& packet,bool realmless){
|
|
// Independent CharacterInfoBasic reader: count near SpecID, pairs only
|
|
// after the entire fixed row including SuperDistrict, then name bits.
|
|
Reader r(packet);check(r.le(1)==(realmless?0xc0:0x80));check(r.le(1)==0x80);
|
|
const auto normal=r.le(4),without_realm=r.le(4);
|
|
check((realmless?normal:without_realm)==0);
|
|
const auto count=normal+without_realm;check(count<=10);
|
|
r.take(4);const auto races=r.le(4);r.take(16);
|
|
std::vector<NativeAppearanceRow> out;
|
|
for(size_t i=0;i<count;++i){
|
|
unpack_guid(r,16);check(r.le(4)==0x01010046);
|
|
NativeAppearanceRow row{};row.position=r.le(2);row.race=r.le(1);row.gender=r.le(1);row.cls=r.le(1);
|
|
check(r.le(2)==0);const auto choices=r.le(4);check(choices<=250);
|
|
r.take(1+4+4+12);row.member_id=r.le(8);row.guild_guid=unpack_guid(r,16);
|
|
r.take(4*4+1+3*4+19*23); // Flags, cantLogin, pet and visuals.
|
|
r.take(4+8+8+4+5*4+5*4);check(r.le(4)==2); // Save/time/version/tabard/professions/season/screen/queue + district.
|
|
for(size_t choice=0;choice<choices;++choice)
|
|
row.choices.push_back({uint32_t(r.le(4)),uint32_t(r.le(4))});
|
|
const auto first=r.le(1),second=r.le(1);const auto bits=(first<<8)|second;
|
|
const auto size=(bits>>10)&63;check(((bits>>4)&63)==0);
|
|
auto name=r.take(size);row.name.assign(name.begin(),name.end());
|
|
r.take(realmless?23:17);out.push_back(std::move(row));
|
|
}
|
|
for(size_t i=0;i<races;++i){
|
|
r.take(1);const auto classes=r.le(4);check(classes<=64);
|
|
r.take(classes*6+1);
|
|
}
|
|
r.end();return out;
|
|
}
|
|
void source_appearance_goldens(){
|
|
auto male=characters(source_roster(9,0,{1,0,0,0,0})).front();
|
|
auto female=characters(source_roster(9,1,{0,0,0,0,0})).front();
|
|
auto held=male;held.appearance={0,0,0,0,0};
|
|
auto high_elf=characters(source_roster(10,0,{0,0,0,0,0})).front();
|
|
male.guid=4509;female.guid=4510;held.guid=4511;high_elf.guid=4512;
|
|
male.name="Male";female.name="Female";held.name="Partial";high_elf.name="HighElf";
|
|
const std::vector<std::array<uint32_t,2>> expected_male{
|
|
{100,1427},{101,1446},{102,1474},{103,1475},{104,1488},{552,5666},
|
|
{806,9071},{807,9083},{815,9153},{817,9169},{819,9179}};
|
|
const std::vector<std::array<uint32_t,2>> expected_female{
|
|
{105,1513},{106,1526},{107,1544},{108,1561},{109,1574},{553,5677},
|
|
{808,9093},{809,9104},{811,9118},{813,9144},{821,9195}};
|
|
const std::vector<std::array<uint32_t,2>> expected_high_elf{
|
|
{110,1599},{111,1626},{112,1649},{113,1666},{114,1680}};
|
|
female.guild=41;
|
|
const std::vector<Character> source{male,female,held,high_elf};
|
|
for(bool realmless:{false,true}){
|
|
const auto rows=appearance_rows(forever_roster_preview(source,{},realmless),realmless);
|
|
check(rows.size()==4&&rows[0].choices==expected_male&&rows[1].choices==expected_female);
|
|
auto expected_partial=expected_male;expected_partial.front()={100,1430};
|
|
check(rows[2].choices==expected_partial); // Skin catalogue (#122, ee92): Source skin0 now has its own native choice.
|
|
check(rows[3].choices==expected_high_elf); // Existing High Elf relation; no race substitution.
|
|
for(size_t i=0;i<rows.size();++i){
|
|
check(rows[i].position==i&&rows[i].name==source[i].name);
|
|
check(rows[i].member_id==(source[i].guid|(uint64_t(70)<<48)));
|
|
const auto guild=forever_guild_guid(source[i].guild,70);
|
|
check(rows[i].guild_guid==Bytes(guild.begin(),guild.end()));
|
|
check(rows[i].race==source[i].race&&rows[i].gender==source[i].gender&&rows[i].cls==source[i].cls);
|
|
}
|
|
// Multiple nonempty vectors with differing pair counts must not shift names,
|
|
// restrictions, realmless metadata or race-unlock records.
|
|
auto original=characters(source_roster(1,0,{255,255,255,255,255}));
|
|
check(appearance_rows(forever_roster(original,{},realmless),realmless).front().choices.empty());
|
|
for(uint8_t facial:{0,7}){
|
|
auto tauren=characters(source_roster(6,0,{0,0,0,0,facial}));
|
|
const std::vector<std::array<uint32_t,2>> expected_tauren{
|
|
{68,1045},{71,1084},{72,1100},{73,1107},{378,1074},
|
|
{646,7279},{661,7343},{671,7408},{672,7425},{803,9017}};
|
|
check(appearance_rows(forever_roster(tauren,{},realmless),realmless).front().choices==expected_tauren);
|
|
// Showing shared native choices does not choose a canonical
|
|
// Source value or make this ambiguous inverse safe for creation.
|
|
check(tauren.front().appearance[4]==facial);
|
|
}
|
|
original.front().appearance={3,2,5,4,1};
|
|
const std::vector<std::array<uint32_t,2>> expected_human{
|
|
{9,4},{10,22},{11,49},{12,65},{463,4133},{525,5056},{890,9925},{9494,78935}};
|
|
check(appearance_rows(forever_roster(original,{},realmless),realmless).front().choices==expected_human);
|
|
original.front().race=5;original.front().appearance={0,0,0,0,0};
|
|
const std::vector<std::array<uint32_t,2>> expected_undead{
|
|
{58,913},{59,920},{60,940},{61,956},{62,967},{534,5330},{563,6287},{567,6527}};
|
|
check(appearance_rows(forever_roster(original,{},realmless),realmless).front().choices==expected_undead);
|
|
check(appearance_rows(forever_roster({}, {},realmless),realmless).empty());
|
|
}
|
|
check(male.appearance==std::array<uint8_t,5>{1,0,0,0,0});
|
|
check(held.appearance==std::array<uint8_t,5>{0,0,0,0,0});
|
|
}
|
|
}
|
|
int main(){
|
|
source_appearance_goldens();
|
|
auto characters_from_server=characters(source_roster());check(characters_from_server.size()==1);
|
|
for(bool realmless:{false,true}){
|
|
auto rows=visual_records(forever_roster(characters_from_server,{},realmless),realmless);
|
|
for(unsigned i=0;i<19;++i){
|
|
// CharacterPackets.cpp VisualItemInfo writer: ItemID32, transmog32,
|
|
// subclass8, invType8, display32, enchant32, secondary32, sheath8.
|
|
Reader r(rows[i]);check(r.le(4)==0 && r.le(4)==0 && r.le(1)==0);
|
|
check(r.le(1)==i && r.le(4)==1000+11*i);
|
|
check(r.le(4)==0 && r.le(4)==0 && r.le(1)==0);r.end();
|
|
}
|
|
check(rows.back()[10]==uint8_t(1198)); // Last visible slot18, not bag19.
|
|
}
|
|
// Named source/native flags preserve forced rename, ghost and cosmetic settings;
|
|
// unrelated restrictions are never copied. All supported source races and
|
|
// both genders use the same semantic mapping, including preview aliases.
|
|
for(uint8_t race:{1,2,3,4,5,6,7,8,9,10})for(uint8_t gender:{0,1})
|
|
for(bool realmless:{false,true})for(auto source_flags:{0u,0x2000u,0x400u,0x800u,0xc00u,0x2c00u,0x4000u,0x6c00u,0x10000u,0xffffffffu}){
|
|
characters_from_server[0].race=race;characters_from_server[0].gender=gender;
|
|
characters_from_server[0].flags=source_flags;
|
|
if(forever_roster_row_reason(characters_from_server[0])==RosterValidationReason::Ok)
|
|
(void)visual_records(forever_roster(characters_from_server,{},realmless),realmless,source_flags&0x6c00u);
|
|
(void)visual_records(forever_roster_preview(characters_from_server,{},realmless),realmless,source_flags&0x6c00u);
|
|
}
|
|
// A Tauren roster can carry both the hide flag and an equipped display.
|
|
// Decode the original flags, then compare every emitted slot with a shown
|
|
// control. Returning to a shown preference must restore its equipped visual.
|
|
for(bool realmless:{false,true})for(auto encode:{forever_roster,forever_roster_preview}){
|
|
auto roster=characters(source_roster(6,0));
|
|
roster[0].cls=5;
|
|
roster[0].visuals[0]={35049,1};
|
|
roster[0].visuals[14]={14421,16};
|
|
const auto shown=visual_records(encode(roster,{},realmless),realmless);
|
|
check(shown[0]!=Bytes(23) && shown[14]!=Bytes(23));
|
|
for(uint32_t flags:{0x400u,0x800u,0xc00u,0x2400u,0u}){
|
|
roster[0].flags=characters(source_roster(6,0,{},flags))[0].flags;
|
|
const auto slots=visual_records(encode(roster,{},realmless),realmless,flags);
|
|
for(unsigned slot=0;slot<slots.size();++slot){
|
|
const bool hidden=(slot==0 && (flags&0x400)) || (slot==14 && (flags&0x800));
|
|
check(slots[slot]==(hidden?Bytes(23):shown[slot]));
|
|
}
|
|
}
|
|
}
|
|
// A Tauren roster can carry both the hide flag and an equipped display.
|
|
// Decode the original flags, then compare every emitted slot with a shown
|
|
// control. Returning to a shown preference must restore its equipped visual.
|
|
for(bool realmless:{false,true})for(auto encode:{forever_roster,forever_roster_preview}){
|
|
auto roster=characters(source_roster(6,0));
|
|
roster[0].cls=5;
|
|
roster[0].visuals[0]={35049,1};
|
|
roster[0].visuals[14]={14421,16};
|
|
const auto shown=visual_records(encode(roster,{},realmless),realmless);
|
|
check(shown[0]!=Bytes(23) && shown[14]!=Bytes(23));
|
|
for(uint32_t flags:{0x400u,0x800u,0xc00u,0x2400u,0u}){
|
|
roster[0].flags=characters(source_roster(6,0,{},flags))[0].flags;
|
|
const auto slots=visual_records(encode(roster,{},realmless),realmless,flags);
|
|
for(unsigned slot=0;slot<slots.size();++slot){
|
|
const bool hidden=(slot==0 && (flags&0x400)) || (slot==14 && (flags&0x800));
|
|
check(slots[slot]==(hidden?Bytes(23):shown[slot]));
|
|
}
|
|
}
|
|
}
|
|
characters_from_server[0].flags=0;characters_from_server[0].race=1;characters_from_server[0].gender=0;
|
|
// Literal golden from the reviewed destination source field sequence:
|
|
// invType21 and DisplayID0x01020304; all absent source metadata stays0.
|
|
auto& visual=characters_from_server[0].visuals[15];visual.display=0x01020304;visual.type=21;
|
|
auto rows=visual_records(forever_roster(characters_from_server,{},false),false);
|
|
check(rows[15]==unhex("0000000000000000001504030201000000000000000000"));
|
|
// Real source Thunderfury display30606 is a display, not item19019.
|
|
visual.display=30606;visual.type=21;
|
|
rows=visual_records(forever_roster(characters_from_server,{},false),false);
|
|
Reader sword(rows[15]);check(sword.le(4)==0 && sword.le(4)==0 && sword.le(1)==0 && sword.le(1)==21 && sword.le(4)==30606);
|
|
// Source Modrag'zan display68720 is not its converted native display755482.
|
|
// The enum contains no item identity: adapt only the display field.
|
|
visual.display=68720;visual.type=13;
|
|
rows=visual_records(forever_roster(characters_from_server,{},false),false);
|
|
Reader converted(rows[15]);check(converted.le(4)==0 && converted.le(4)==0 && converted.le(1)==0 && converted.le(1)==13 && converted.le(4)==755482);
|
|
for(auto& item:characters_from_server[0].visuals)item={0,0};
|
|
rows=visual_records(forever_roster(characters_from_server,{},false),false);
|
|
for(const auto& row:rows)check(row==Bytes(23)); // Existing empty appearance preserved.
|
|
for(unsigned type=0;type<=28;++type){
|
|
characters_from_server[0].visuals[0]={35049,uint8_t(type)};
|
|
rows=visual_records(forever_roster(characters_from_server,{},false),false);check(rows[0][9]==type);
|
|
}
|
|
for(unsigned type:{29u,255u}){
|
|
characters_from_server[0].visuals[0]={35049,uint8_t(type)};
|
|
rejects([&]{forever_roster(characters_from_server,{},false);});
|
|
}
|
|
std::cout<<"Source roster appearance goldens and held rows PASS;19-slot equipment/flags preserved in both roster layouts. Model rendering remains actual-client acceptance work.\n";
|
|
}
|