Files
WoW-Hybrid-gateway/tests/tauren_boots_projection_test.cpp
2026-11-19 02:25:06 +02:00

89 lines
6.0 KiB
C++

// SPDX-License-Identifier: GPL-2.0-or-later
#include "gateway/roster_translation.hpp"
#include "gateway/unit_presentation.hpp"
#include "gateway/turtle_entity_profile.hpp"
#include "inventory_translation.hpp"
#include "serializer.h"
#include <iostream>
#include <source_location>
using namespace gateway;
namespace F=gateway::turtle_entity_fields;
namespace {
void check(bool ok,std::source_location at=std::source_location::current()){
if(!ok)throw Error("Tauren feet projection assertion line "+std::to_string(at.line()));
}
uint32_t roster_feet(uint8_t race,uint8_t gender,uint32_t display){
Character c{};c.guid=4509;c.name="Fixture";c.race=race;c.gender=gender;c.cls=1;c.level=60;c.visuals[7]={display,8};
auto bytes=forever_roster({c},{},false);Reader r(bytes);
check(r.le(1)==0x80&&r.le(1)==0x80);check(r.le(4)==1&&r.le(4)==0);r.take(24);unpack_guid(r,16);
r.take(4+2+3+2);check(r.le(4)<=250);r.take(1+4+4+12+8);unpack_guid(r,16);r.take(4+13+12);
for(unsigned i=0;i<7;++i)r.take(23);
r.take(10);return uint32_t(r.le(4));
}
LegacyPacket update(uint64_t guid,uint8_t type,uint8_t kind,const std::map<uint16_t,uint32_t>& fields){
Bytes b;le(b,1,4);le(b,0,1);le(b,kind,1);Bytes raw;le(raw,guid,8);append(b,pack_guid(raw));
if(kind==2||kind==3){le(b,type,1);le(b,0,1);}
unsigned count=fields.rbegin()->first/32+1;le(b,count,1);std::vector<uint32_t> mask(count);
for(auto [i,v]:fields){(void)v;mask[i/32]|=1u<<(i%32);}for(auto m:mask)le(b,m,4);for(auto [i,v]:fields){(void)i;le(b,v,4);}return {0xa9,b};
}
std::map<uint16_t,uint32_t> projected(const Bytes& input,uint64_t self){
Reader r(input);check(r.le(8)==self);r.le(2);r.le(4);auto count=r.le(4);std::map<uint16_t,uint32_t> out;
for(unsigned n=0;n<count;++n){auto id=r.le(8);r.le(1);r.le(1);auto fields=r.le(2);
for(unsigned i=0;i<fields;++i){auto key=uint16_t(r.le(2));auto value=uint32_t(r.le(4));if(id==self)out[key]=value;}}
r.end();return out;
}
ItemTemplateReply item(uint32_t entry,uint32_t display){ItemTemplateReply x{};x.found=true;x.entry=entry;x.display=display;x.cls=4;x.inventory_type=8;return x;}
void owned_case(uint8_t race,uint8_t gender,uint32_t real_entry,uint32_t visible_entry,uint32_t display,bool hidden,bool initial=false){
constexpr uint64_t self=4509,owned=(uint64_t(0x4000)<<48)|75;
constexpr auto foot=F::PLAYER_VISIBLE_ITEM_1_0+12*7,root=F::PLAYER_FIELD_INV_SLOT_HEAD+2*7;
NativeInventoryTranslation state;state.templates[real_entry]=item(real_entry,real_entry==4137?4835:31025);
state.templates[visible_entry]=item(visible_entry,display);
std::map<uint16_t,uint32_t> last;
auto codec=[&](uint32_t mode,const Bytes& input){
if(mode==GW_CODEC_INVENTORY){auto p=projected(input,self);if(p.contains(foot))last=p;}
else check(mode==GW_CODEC_ITEM_APPEARANCE);
return Bytes(6,0);
};
std::map<uint16_t,uint32_t> player{{F::UNIT_FIELD_BYTES_0,uint32_t(race)|(1u<<8)|(uint32_t(gender)<<16)},
{root,uint32_t(owned)},{root+1,uint32_t(owned>>32)},{foot,visible_entry}};
std::map<uint16_t,uint32_t> object{{F::OBJECT_FIELD_ENTRY,real_entry},{F::ITEM_FIELD_OWNER,uint32_t(self)},
{F::ITEM_FIELD_OWNER+1,0},{F::ITEM_FIELD_CONTAINED,uint32_t(self)},{F::ITEM_FIELD_CONTAINED+1,0},
{F::ITEM_FIELD_STACK_COUNT,1},{F::ITEM_FIELD_DURABILITY,75}};
if(initial){
auto a=update(self,4,3,player),b=update(owned,1,3,object);Bytes body;le(body,2,4);le(body,0,1);
append(body,std::span(a.body).subspan(5));append(body,std::span(b.body).subspan(5));
state.translate({0xa9,body},self,70,0,true,codec);
}else{
state.translate(update(self,4,3,player),self,70,0,false,codec);
state.translate(update(owned,1,3,object),self,70,0,false,codec);
}
check(last.contains(foot));check(hidden?last.at(foot)==0:last.at(foot)!=0);
check(state.player_fields.at(foot)==visible_entry);check(state.items.at(owned).fields==object);
auto position=state.position(255,7);check(position.item==owned&&position.slot==7);
if(visible_entry!=real_entry){check(state.applied_appearances.contains(owned));check(state.applied_appearances.at(owned)!=0);}
// A Source race change alone re-evaluates the cached feet look, while
// leaving the real equipment/Source transmog and item fields untouched.
state.translate(update(self,4,0,{{F::UNIT_FIELD_BYTES_0,1u|(1u<<8)|(uint32_t(gender)<<16)}}),self,70,0,false,codec);
check(last.at(foot)!=0&&state.player_fields.at(foot)==visible_entry&&state.items.at(owned).fields==object);
}
}
int main(){
check(std::size(race_slot_hide_profile::Displays)==55&&std::size(race_slot_hide_profile::Items)==79);
for(auto display:race_slot_hide_profile::Displays)for(uint8_t race=1;race<=10;++race)for(uint8_t gender:{0,1})for(unsigned slot=0;slot<19;++slot)
check((forever_visible_item_id(0,slot,4137,race,gender,display)==0)==(race==6&&slot==7));
for(const auto& row:race_slot_hide_profile::Items)check(race_slot_hide_profile::source_display(row.item)==row.display);
check(!race_slot_hide_profile::hidden(6,2,7,4835));check(!race_slot_hide_profile::hidden(6,0,7,0));
check(forever_visible_item_id(SourceHideHelm,0,19019)==0&&forever_visible_item_id(SourceHideCloak,14,19019)==0);
for(uint8_t gender:{0,1}){
for(auto display:race_slot_hide_profile::Displays){check(roster_feet(6,gender,display)==0);check(roster_feet(1,gender,display)!=0);}
check(roster_feet(6,gender,31025)!=0); // Sabatons of Might is explicitly normal.
owned_case(6,gender,16862,16862,31025,false);
owned_case(6,gender,16862,113266,4835,true); // Ordinary base, hidden post-transmog display.
owned_case(6,gender,16862,113266,4835,true,true); // Cached template on initial SELF.
owned_case(6,gender,4137,113267,31025,false); // Hidden base, ordinary post-transmog display.
owned_case(1,gender,16862,113266,4835,false);
owned_case(6,gender,4137,4137,4835,true);
}
std::cout<<"55-display/79-item Source rule, char-select and real owned-item transmog/restore projections PASS; inventory identity/stats retained\n";
}