193 lines
14 KiB
C++
193 lines
14 KiB
C++
// Exercise the actual Windows world dispatcher and matching public codec in an offline fixture.
|
|
#include "world_translation.hpp"
|
|
#include "gateway/peer_item_appearances.hpp"
|
|
#include "gateway/roster_translation.hpp"
|
|
#include "gateway/turtle_entity_profile.hpp"
|
|
#include <algorithm>
|
|
#include <bit>
|
|
#include <iostream>
|
|
#include <source_location>
|
|
using namespace gateway;
|
|
|
|
static void check(bool ok,std::source_location where=std::source_location::current()){
|
|
if(!ok)throw Error("peer item fixture line "+std::to_string(where.line()));
|
|
}
|
|
static Bytes packed(uint64_t guid){Bytes bytes;le(bytes,guid,8);return pack_guid(bytes);}
|
|
using Fields=std::map<uint16_t,uint32_t>;
|
|
static constexpr uint16_t slot(unsigned i){return turtle_entity_fields::PLAYER_VISIBLE_ITEM_1_0+12*i;}
|
|
static LegacyPacket update(uint64_t guid,Fields fields,bool create=false){
|
|
Bytes b;le(b,1,4);le(b,0,1);le(b,create?3:0,1);append(b,packed(guid));
|
|
if(create){
|
|
fields.insert({{0,uint32_t(guid)},{2,0x19},{4,std::bit_cast<uint32_t>(1.f)},{22,80},{28,80},{34,60},{35,35},{36,0x10706},{131,60},{132,60}});
|
|
le(b,4,1);le(b,0x20,1);le(b,0,4);le(b,100,4);
|
|
for(float v:{1.f,2.f,3.f,0.f})le(b,std::bit_cast<uint32_t>(v),4);
|
|
le(b,0,4);for(float v:{2.5f,7.f,4.5f,4.72f,2.5f,3.14f})le(b,std::bit_cast<uint32_t>(v),4);
|
|
}
|
|
std::vector<uint32_t> mask(fields.rbegin()->first/32+1);
|
|
for(auto [key,v]:fields){(void)v;mask[key/32]|=1u<<(key%32);}
|
|
le(b,mask.size(),1);for(auto word:mask)le(b,word,4);for(auto [k,v]:fields){(void)k;le(b,v,4);}
|
|
return {0xa9,std::move(b)};
|
|
}
|
|
static LegacyPacket name(uint64_t guid){
|
|
Bytes b;le(b,guid,8);cstring(b,"PeerFixture");cstring(b,"");le(b,6,4);le(b,1,4);le(b,7,4);return {0x51,std::move(b)};
|
|
}
|
|
static LegacyPacket definition(uint32_t entry,uint32_t display=0,uint32_t type=0){
|
|
Bytes b;le(b,display?entry:entry|0x80000000,4);if(!display)return {0x58,std::move(b)};
|
|
le(b,4,4);le(b,0,4);cstring(b,"EquipmentFixture");for(unsigned i=0;i<3;i++)cstring(b,"");
|
|
for(unsigned i=0;i<20;i++)le(b,i==0?display:i==5?type:i==18?1:0,4);
|
|
for(unsigned i=0;i<20+15+7+3+30;i++)le(b,0,4);
|
|
le(b,0,4);cstring(b,"");for(unsigned i=0;i<14;i++)le(b,0,4);
|
|
return {0x58,std::move(b)};
|
|
}
|
|
static size_t occurrences(const Bytes& data,uint32_t id){
|
|
Bytes word;le(word,id,4);size_t count=0;auto p=data.begin();
|
|
while((p=std::search(p,data.end(),word.begin(),word.end()))!=data.end()){++count;p+=word.size();}
|
|
return count;
|
|
}
|
|
static void scenario(){
|
|
NativeWorldTranslation w{};w.selected.guid=4509;w.selected.name="Fixture";w.selected.race=1;w.selected.cls=1;
|
|
w.realm=70;w.location=WorldLocation{1,{0,0,0,0}};w.self_created=true;uint64_t clock=100;
|
|
auto send=[&](const LegacyPacket& p){auto buf=w.translate(p,0x46010046,clock++,&gw_codec_serialize);Reader r(buf);Bytes blocks;
|
|
auto n=r.le(4);for(unsigned i=0;i<n;i++){auto op=r.le(4);auto data=r.take(r.le(4));if(op==0x5e0000)append(blocks,data);}
|
|
r.end();return blocks;};
|
|
constexpr uint64_t guid=9191;
|
|
constexpr uint32_t unknown_shoulder=1002236,unknown_chest=1012258,weapon=18000001,unknown_ring=18000002,change=18000003;
|
|
const uint32_t sh=peer_item_appearances::render_item(68476,3),ch=peer_item_appearances::render_item(68472,5);
|
|
check(sh==58147 && ch==58177 && peer_item_appearances::has_native_look(10004));
|
|
send(update(guid,{{slot(2),unknown_shoulder},{slot(4),unknown_chest},{slot(10),unknown_ring},{slot(15),weapon},{slot(16),weapon}},true));
|
|
check(w.inventory.requests.size()==3 && w.inventory.queries==std::set<uint32_t>{unknown_shoulder,unknown_chest,weapon});
|
|
for(const auto& p:w.inventory.requests){check(p.opcode==0x56 && p.body.size()==12);}
|
|
check(send(definition(unknown_shoulder,68476,3)).empty()); // Source reply arrives before the name/create gate.
|
|
auto created=send(name(guid));check(occurrences(created,sh)==1 && occurrences(created,56316)>=1);
|
|
check(w.entities.peer_players.at(guid).fields.at(slot(2))==unknown_shoulder);
|
|
auto chest=send(definition(unknown_chest,68472,5));check(occurrences(chest,ch)==1);
|
|
check(send(definition(unknown_chest,68472,5)).empty());
|
|
check(w.entities.peer_players.at(guid).fields.at(slot(4))==unknown_chest);
|
|
auto weapons=send(definition(weapon,1550,13));
|
|
// Two visible slots, each with PlayerData.VisibleItems and UnitData.VirtualItems.
|
|
check(occurrences(weapons,41111)==4 && occurrences(weapons,317860)==4);
|
|
send(update(guid,{{slot(4),change}}));send(update(guid,{{slot(4),10004}}));
|
|
check(!w.inventory.queries.contains(10004) && send(definition(change,68472,5)).empty());
|
|
// Cached query when an already-presented peer equips the generated entry.
|
|
auto restored=send(update(guid,{{slot(4),unknown_chest}}));check(occurrences(restored,ch)==1);
|
|
constexpr uint32_t mismatch=18000004,absent=18000005,held=18000006;
|
|
send(update(guid,{{slot(2),mismatch},{slot(9),absent},{slot(14),held}}));
|
|
check(send(definition(mismatch,68472,5)).empty());
|
|
check(send(definition(absent)).empty());
|
|
check(send(definition(held,128282,16)).empty());
|
|
constexpr uint32_t stale=18000007;send(update(guid,{{slot(2),stale}}));
|
|
Bytes g;le(g,guid,8);send({0xaa,g});check(send(definition(stale,68476,3)).empty());
|
|
check(!w.entities.peer_players.contains(guid));
|
|
send(update(guid,{{slot(2),unknown_shoulder},{slot(4),unknown_chest}},true));
|
|
auto rebuilt=send(name(guid));check(occurrences(rebuilt,sh)==1 && occurrences(rebuilt,ch)==1);
|
|
constexpr auto flags=turtle_entity_fields::PLAYER_FLAGS;
|
|
constexpr uint32_t cloak=18000008,head=18000009;
|
|
send(update(guid,{{flags,SourceHideCloak|SourceHideHelm},{slot(14),cloak},{slot(0),head}}));
|
|
check(!w.inventory.queries.contains(cloak) && !w.inventory.queries.contains(head));
|
|
send(update(guid,{{flags,0}}));check(w.inventory.queries.contains(cloak) && w.inventory.queries.contains(head));
|
|
send(update(guid,{{flags,SourceHideCloak|SourceHideHelm}}));
|
|
check(send(definition(cloak,13984,16)).empty());
|
|
auto unhidden=send(update(guid,{{flags,0}}));
|
|
check(occurrences(unhidden,8286)==1);
|
|
constexpr uint32_t boot=18000010;
|
|
send(update(guid,{{slot(7),boot}}));check(w.inventory.queries.contains(boot));
|
|
auto hidden_boot=send(definition(boot,2083,8));check(!hidden_boot.empty() && occurrences(hidden_boot,boot)==0);
|
|
// Retain only the active actor's current appearance while unrelated full templates turn over.
|
|
for(uint32_t entry=20000000;entry<20000000+NativeInventoryTranslation::PeerTemplateCapacity+10;++entry){
|
|
w.inventory.request_peer_template(entry);
|
|
check(w.inventory.queries.contains(entry));
|
|
w.inventory.requests.clear(); // Simulate successful transport dispatch.
|
|
check(w.inventory.cache_pending_template_reply(definition(entry).body));
|
|
}
|
|
check(w.inventory.peer_templates.size()==NativeInventoryTranslation::PeerTemplateCapacity && !w.inventory.peer_template(unknown_shoulder));
|
|
auto preserve=send(update(guid,{{slot(2),unknown_shoulder}}));
|
|
check(occurrences(preserve,sh)==1 && !w.inventory.queries.contains(unknown_shoulder));
|
|
send(update(guid,{{slot(2),10004}}));send(update(guid,{{slot(2),unknown_shoulder}}));
|
|
check(w.inventory.queries.contains(unknown_shoulder));
|
|
NativeInventoryTranslation budget;
|
|
for(uint32_t item=100000;item<100200;++item)budget.request_peer_template(item);
|
|
check(budget.queries.size()==64 && budget.requests.size()==64 && budget.peer_queries_deferred);
|
|
budget.request_peer_template(100000);check(budget.requests.size()==64);
|
|
check(budget.cache_pending_template_reply(definition(100000).body));
|
|
budget.request_peer_template(100064);check(budget.queries.size()==64 && budget.requests.size()==65);
|
|
NativeInventoryTranslation crowded;
|
|
for(uint32_t entry=1;entry<=64;++entry)crowded.request_peer_template(entry);
|
|
for(uint32_t entry=65;entry<=4096;++entry)crowded.request_owned_template(entry);
|
|
crowded.request_owned_template(4097);
|
|
check(crowded.requests.size()==4096 && crowded.queries.contains(4097) &&
|
|
!crowded.queries.contains(1) && !crowded.peer_template_queries.contains(1) && crowded.peer_queries_deferred);
|
|
check(!crowded.cache_pending_template_reply(definition(1).body));
|
|
NativeInventoryTranslation shared;
|
|
for(uint32_t i=1;i<=3072;++i)shared.templates.emplace(i,ItemTemplateReply{});
|
|
constexpr uint32_t first=21000000,capacity=NativeInventoryTranslation::PeerTemplateCapacity;
|
|
for(uint32_t id=first;id<first+capacity+1000;++id){
|
|
shared.request_peer_template(id);shared.request_peer_template(id);
|
|
check(shared.requests.size()==1 && shared.queries.size()==1);
|
|
shared.requests.clear();
|
|
auto packet=definition(id,68476,3);
|
|
bool only_peer=false;check(shared.cache_pending_template_reply(packet.body,&only_peer) && only_peer);
|
|
check(!shared.cache_pending_template_reply(packet.body));
|
|
}
|
|
check(shared.templates.size()==3072 && shared.templates.contains(1) && shared.templates.contains(3072));
|
|
check(shared.peer_templates.size()==capacity && !shared.peer_template(first));
|
|
const auto latest=first+capacity+999;
|
|
check(shared.peer_template(latest)->display==68476);
|
|
shared.request_owned_template(latest);shared.request_owned_template(latest);
|
|
check(shared.requests.empty() && shared.templates.at(latest).display==68476 && !shared.peer_templates.contains(latest));
|
|
const auto missing=latest+1;
|
|
shared.request_peer_template(missing);shared.requests.clear();
|
|
check(shared.cache_pending_template_reply(definition(missing).body));
|
|
shared.request_peer_template(missing);check(shared.requests.empty() && !shared.peer_template(missing)->found);
|
|
shared.request_owned_template(missing);check(shared.requests.empty() && !shared.templates.at(missing).found);
|
|
const auto pending=missing+1;
|
|
shared.request_peer_template(pending);shared.request_owned_template(pending);shared.request_peer_template(pending);
|
|
check(shared.requests.size()==1 && !shared.peer_template_queries.contains(pending));
|
|
check(shared.cache_pending_template_reply(definition(pending,68472,5).body) && shared.templates.at(pending).display==68472);
|
|
shared.request_peer_template(pending);check(shared.requests.size()==1);
|
|
const auto owned=pending+1;
|
|
shared.requests.clear();shared.request_owned_template(owned);shared.request_peer_template(owned);
|
|
check(shared.requests.size()==1 && !shared.peer_template_queries.contains(owned));
|
|
check(shared.cache_pending_template_reply(definition(owned).body) && !shared.templates.at(owned).found);
|
|
}
|
|
// The player's own transmogged slot: Source shows a generated per-transmog
|
|
// entry (live Octo: Helm of Wrath -> Eye of Rend = 1011974, display 22794).
|
|
// It has no native Item row, so it must resolve through the queried template
|
|
// exactly as a peer's does, or the equipped helm renders as nothing.
|
|
static void self_transmog(){
|
|
NativeWorldTranslation w{};w.selected.guid=4509;w.selected.name="Fixture";w.selected.race=6;w.selected.cls=1;
|
|
w.realm=70;w.location=WorldLocation{1,{0,0,0,0}};w.self_created=true;uint64_t clock=100;
|
|
auto send=[&](const LegacyPacket& p){auto buf=w.translate(p,0x46010046,clock++,&gw_codec_serialize);Reader r(buf);Bytes blocks;
|
|
auto n=r.le(4);for(unsigned i=0;i<n;i++){auto op=r.le(4);auto data=r.take(r.le(4));if(op==0x5e0000)append(blocks,data);}
|
|
r.end();return blocks;};
|
|
// Live Octo case: head 1011974 (Helm of Wrath shown as Eye of Rend, display 22794).
|
|
// The same generated-entry path is exercised on a slot whose donor this
|
|
// isolated codec and the header agree on (chest display 68472).
|
|
constexpr uint64_t self=4509;constexpr uint32_t generated=1011974,look=68472,type=5;constexpr unsigned s=4;
|
|
const uint32_t donor=peer_item_appearances::render_item(look,type);
|
|
check(donor==58177 && !peer_item_appearances::has_native_look(generated));
|
|
send(update(self,{{slot(s),generated},{36,0x10106}},true));
|
|
check(w.inventory.queries.contains(generated));
|
|
auto first=send(definition(generated,look,type));
|
|
check(occurrences(first,donor)==1 && occurrences(first,generated)==0);
|
|
// The active player applies VisibleItems only from its owner-form values
|
|
// update (live Octo: 152 public-form corrections were all ignored).
|
|
{const auto id=pack_guid(forever_player_guid(self,70));
|
|
auto at=std::search(first.begin(),first.end(),id.begin(),id.end());
|
|
check(at!=first.end() && first.end()-at>long(id.size()+5) && *(at+id.size()+4)==1);}
|
|
// Cached template: re-equipping the same generated entry resolves at once.
|
|
send(update(self,{{slot(s),10004}}));
|
|
auto again=send(update(self,{{slot(s),generated}}));
|
|
// The raw self update may carry the generated entry; the template
|
|
// correction must follow it so the client's final value is the donor.
|
|
auto at=[&](uint32_t id){Bytes w;le(w,id,4);auto p=std::find_end(again.begin(),again.end(),w.begin(),w.end());return p==again.end()?-1L:long(p-again.begin());};
|
|
check(occurrences(again,donor)==1 && at(donor)>at(generated));
|
|
// Self re-create (teleport, instance, death/resurrect transitions) rebuilds
|
|
// visible slots; the cached transmog look must be re-applied at once, not
|
|
// left on the base/generated entry until some later slot update.
|
|
auto recreated=send(update(self,{{slot(s),generated},{36,0x10106}},true));
|
|
check(occurrences(recreated,donor)==1);
|
|
check(!w.inventory.queries.contains(generated) || w.inventory.requests.empty());
|
|
}
|
|
int main(int argc,char**){try{if(argc>1){self_transmog();std::cout<<"PASS self transmog\n";return 0;}scenario();self_transmog();std::cout<<"PASS peer template render projections\n";return 0;}
|
|
catch(const std::exception& e){std::cerr<<e.what()<<"\n";return 1;}}
|