Files
WoW-Hybrid-gateway/tests/native_inventory_test.cpp

790 lines
72 KiB
C++

#include "optional_test_codec.hpp"
#include "inventory_translation.hpp"
#include "world_translation.hpp"
#include "serializer.h"
#include "gateway/gameplay.hpp"
#include "gateway/turtle_entity_profile.hpp"
#include "gateway/item_render_profile.hpp"
#include <dlfcn.h>
#include <array>
#include <bit>
#include <cstdlib>
#include <iostream>
#include <source_location>
using namespace gateway;
static void check(bool value,std::source_location where=std::source_location::current()){if(!value)throw Error("inventory pipeline assertion at line "+std::to_string(where.line()));}
static LegacyPacket update(uint64_t guid,uint8_t type,uint8_t kind,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);}
auto n=fields.rbegin()->first/32+1;le(b,n,1);std::vector<uint32_t> mask(n);
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};
}
static uint32_t count(const std::vector<LegacyPacket>& packets){uint32_t n=0;for(auto& p:packets){check(p.opcode==0x5e0000);Reader r(p.body);r.le(2);n+=r.le(4);}return n;}
static decltype(&gw_codec_serialize) actual_codec=nullptr;
static std::vector<Bytes> world_inventory_inputs;
static std::vector<Bytes> real_self_outputs,real_inventory_inputs,real_inventory_outputs;
static int tracking_real_codec(uint32_t mode,const uint8_t* input,uint32_t size,uint32_t flags,uint8_t* output,uint32_t capacity,uint32_t* written){
int result=actual_codec(mode,input,size,flags,output,capacity,written);
if(result==GW_CODEC_OK && output){
if(mode==GW_CODEC_SELF)real_self_outputs.emplace_back(output,output+*written);
if(mode==GW_CODEC_INVENTORY){real_inventory_inputs.emplace_back(input,input+size);real_inventory_outputs.emplace_back(output,output+*written);}
}
return result;
}
static LegacyPacket real_self_fixture(uint64_t self,uint64_t item,bool same_packet,bool equipped=true,uint32_t visible_item=25,unsigned equipment_slot=0,bool omit_zero=false){
namespace F=gateway::turtle_entity_fields;
std::map<uint16_t,uint32_t> fields{{22,80},{28,80},{34,60},{35,1},{36,0x01000101},
{uint16_t(F::PLAYER_VISIBLE_ITEM_1_0+12*equipment_slot),equipped?visible_item:0u},
{uint16_t(F::PLAYER_FIELD_INV_SLOT_HEAD+2*equipment_slot),equipped?uint32_t(item):0u},
{uint16_t(F::PLAYER_FIELD_INV_SLOT_HEAD+2*equipment_slot+1),equipped?uint32_t(item>>32):0u},
{718,98},{719,0x012c012c}};
// The pinned Source SELF create writer omits zero-valued update fields.
if(omit_zero)for(auto it=fields.begin();it!=fields.end();){if(!it->second)it=fields.erase(it);else ++it;}
Bytes body;le(body,same_packet?2:1,4);le(body,0,1);
if(same_packet){auto item_create=update(item,1,2,{{3,25},{6,uint32_t(self)},{8,uint32_t(self)},{14,1}});append(body,std::span(item_create.body).subspan(5));}
le(body,3,1);Bytes id;le(id,self,8);append(body,pack_guid(id));le(body,4,1);le(body,0x21,1);
le(body,0,4);le(body,100,4);
for(float v:{1.f,2.f,3.f,0.f})le(body,std::bit_cast<uint32_t>(v),4);
le(body,0,4);for(float v:{2.5f,7.f,4.5f,4.72f,2.5f,3.14f})le(body,std::bit_cast<uint32_t>(v),4);
std::vector<uint32_t> masks(23);for(auto [i,v]:fields){(void)v;masks[i/32]|=1u<<(i%32);}
le(body,masks.size(),1);for(auto m:masks)le(body,m,4);for(auto [i,v]:fields){(void)i;le(body,v,4);}
return {0xa9,std::move(body)};
}
static uint32_t real_self_visible_item(const Bytes& packet,unsigned slot){
// Pinned original full-SELF writer layout for this exact fixture.
check(slot<19);
check(packet.size()>11);uint32_t count=uint32_t(packet[2])|(uint32_t(packet[3])<<8)|(uint32_t(packet[4])<<16)|(uint32_t(packet[5])<<24);
size_t at=11;
for(uint32_t i=1;i<count;++i){check(at+3<=packet.size() && packet[at]==2);unsigned mask=packet[at+1]|(unsigned(packet[at+2])<<8);at+=3+std::popcount(mask)+1+3+4;check(at+4<=packet.size());uint32_t size=packet[at]|(uint32_t(packet[at+1])<<8)|(uint32_t(packet[at+2])<<16)|(uint32_t(packet[at+3])<<24);at+=4+size;}
// The retained VisibleItem::WriteCreate writes 27 bytes per slot.
constexpr size_t offset=13464,stride=27;at+=offset+stride*slot;check(at+4<=packet.size());
return packet[at]|(uint32_t(packet[at+1])<<8)|(uint32_t(packet[at+2])<<16)|(uint32_t(packet[at+3])<<24);
}
// Decode the original active-player change mask, rather than assuming the
// bank count is the penultimate byte. New writers also emit purchased tab count.
static void bank_counts(const Bytes& packet,unsigned purchased){
Reader outer(packet);outer.le(2);check(outer.le(4)==1 && outer.le(1)==0x80);
auto block=outer.take(outer.le(4));outer.end();Reader update(block);
check(update.le(1)==0);unpack_guid(update,16);
auto body=update.take(update.le(4));update.end();Reader values(body);
check(values.le(1)==1 && values.le(1)==0 && values.le(1)==3);
check(values.le(4)==(1u<<7)); // ActivePlayer only, not Unit/Player projection.
auto mask=values.take(values.left());size_t bit=0;
auto bits=[&](unsigned n){
check(bit+n<=mask.size()*8);uint32_t result=0;
while(n--){result=(result<<1)|((mask[bit/8]>>(7-bit%8))&1);++bit;}
return result;
};
const auto blocks=bits(14);std::array<uint32_t,14> fields{};
for(unsigned i=0;i<fields.size();++i)if(blocks&(1u<<i))fields[i]=bits(32);
auto present=[&](unsigned field){return (fields[field/32]&(1u<<(field%32)))!=0;};
check(present(134) && present(135)); // Original group and NumBankSlots.
const bool tabs=present(136); // NumCharacterBankTabs is independently masked.
const size_t tail=tabs?3:2;check(body.size()>=tail);
check(body[body.size()-tail]==purchased && body.back()==0);
if(tabs){
check(present(32) && present(48)); // Full CharacterBankTabSettings accompanies it.
check(body[body.size()-2]==purchased+1); // Fixed bank plus purchased bags.
}
}
static uint32_t real_self_head_item(const Bytes& packet){return real_self_visible_item(packet,0);}
static int self_fixture_codec(uint32_t mode,const uint8_t* input,uint32_t size,uint32_t flags,uint8_t* output,uint32_t capacity,uint32_t* written){
if(mode!=GW_CODEC_SELF){
if(mode==GW_CODEC_INVENTORY && output)world_inventory_inputs.emplace_back(input,input+size);
return actual_codec(mode,input,size,flags,output,capacity,written);
}
*written=1;if(!output || capacity<1)return GW_CODEC_CAPACITY;output[0]=0;return GW_CODEC_OK;
}
int main(){
if (test_fixture::optional_codec_missing(GW_ENTITY_CODEC)) return 77;
void* library = dlopen(GW_ENTITY_CODEC, RTLD_NOW | RTLD_LOCAL);
if (!library) {
std::cerr << dlerror() << '\n';
return 1;
}
auto encode=reinterpret_cast<decltype(&gw_codec_serialize)>(dlsym(library,"gw_codec_serialize"));check(encode);
actual_codec=encode;
Bytes last,last_appearance;unsigned appearance_calls=0;
NativeEntityTranslation::Codec codec=[&](uint32_t mode,const Bytes& input){
check(mode==GW_CODEC_INVENTORY || mode==GW_CODEC_ITEM_APPEARANCE);
if(mode==GW_CODEC_INVENTORY)last=input;else{last_appearance=input;++appearance_calls;}uint32_t n=0;
check(encode(mode,input.data(),input.size(),0,nullptr,0,&n)==GW_CODEC_CAPACITY);
Bytes output(n);check(encode(mode,input.data(),input.size(),0,output.data(),n,&n)==GW_CODEC_OK);return output;
};
NativeInventoryTranslation state;constexpr uint64_t self=42,item=(0x4000ULL<<48)|75;
auto run=[&](const LegacyPacket& p,bool initial=false){return state.translate(p,self,70,0,initial,codec);};
auto create=update(item,1,2,{{3,25},{6,42},{8,42},{14,2},{46,19},{47,20}});
// The normal owned-create path takes over an outstanding peer query without sending a second request.
{
NativeInventoryTranslation pending;
pending.request_peer_template(25);
pending.translate(create,self,70,0,true,codec);
check(pending.queries.contains(25) && !pending.peer_template_queries.contains(25) && pending.requests.size()==1);
Bytes negative;le(negative,0x80000000u|25u,4);
check(pending.cache_pending_template_reply(negative) && pending.templates.contains(25) && !pending.templates.at(25).found);
NativeInventoryTranslation cached;
cached.request_peer_template(25);check(cached.cache_pending_template_reply(negative));
check(cached.templates.empty() && cached.peer_template(25) && !cached.peer_template(25)->found);
cached.translate(create,self,70,0,true,codec);
check(cached.requests.size()==1 && cached.templates.contains(25) && cached.peer_templates.empty());
}
// A full Source object packet may precede the separate SELF packet.
// No item, query or native object is published before genuine ThisIsYou.
auto self_create=update(self,4,2,{{3,0}});
Bytes self_guid;le(self_guid,self,8);self_create.body[6+pack_guid(self_guid).size()+1]=1;
NativeWorldTranslation before;before.selected.guid=self;before.realm=70;before.location=WorldLocation{};
world_inventory_inputs.clear();
auto waiting_bytes=before.translate(create,0x46010046,0,self_fixture_codec);Reader waiting(waiting_bytes);
check(waiting.le(4)==0 && before.inventory.items.empty() && before.inventory.requests.empty() && before.pre_self_items.contains(item));
auto foreign=update((0x4000ULL<<48)|76,1,2,{{3,26},{6,43},{8,43}});
before.translate(foreign,0x46010046,0,self_fixture_codec);check(before.pre_self_items.size()==1);
before.translate(self_create,0x46010046,0,self_fixture_codec);
check(before.self_created && before.pre_self_items.empty() && before.inventory.items.contains(item));
check(before.inventory.requests.size()==1 && before.inventory.queries.contains(25));
check(world_inventory_inputs.size()==1);Reader pre_emission(world_inventory_inputs.front());
check(pre_emission.le(8)==self && pre_emission.le(2)==70 && pre_emission.le(4)==0 && pre_emission.le(4)==1);
check(pre_emission.le(8)==item && pre_emission.le(1)==1 && pre_emission.le(1)==2);
NativeWorldTranslation after;after.selected.guid=self;after.realm=70;after.location=WorldLocation{};
after.translate(self_create,0x46010046,0,self_fixture_codec);after.translate(create,0x46010046,0,self_fixture_codec);
check(after.self_created && after.inventory.items.contains(item) && after.inventory.requests.size()==1);
// An ownership change before SELF must not emit or query a foreign item.
NativeWorldTranslation changed_owner;changed_owner.selected.guid=self;changed_owner.realm=70;changed_owner.location=WorldLocation{};
changed_owner.translate(create,0x46010046,0,self_fixture_codec);
changed_owner.translate(update(item,0,0,{{6,43}}),0x46010046,0,self_fixture_codec);
changed_owner.translate(self_create,0x46010046,0,self_fixture_codec);
check(changed_owner.inventory.items.empty() && changed_owner.inventory.requests.empty());
// Source may bundle the ownership delta with SELF rather than sending it
// in an earlier packet. It must be applied before replaying staged items.
NativeWorldTranslation owner_at_self;owner_at_self.selected.guid=self;owner_at_self.realm=70;owner_at_self.location=WorldLocation{};
owner_at_self.translate(create,0x46010046,0,self_fixture_codec);
auto owner_delta=update(item,0,0,{{6,43}});Bytes owner_packet;le(owner_packet,2,4);le(owner_packet,0,1);
append(owner_packet,std::span(owner_delta.body).subspan(5));append(owner_packet,std::span(self_create.body).subspan(5));
world_inventory_inputs.clear();owner_at_self.translate({0xa9,owner_packet},0x46010046,0,self_fixture_codec);
check(owner_at_self.self_created && owner_at_self.pre_self_items.empty() && owner_at_self.inventory.items.empty());
check(owner_at_self.inventory.requests.empty() && world_inventory_inputs.empty());
NativeWorldTranslation owner_after_self;owner_after_self.selected.guid=self;owner_after_self.realm=70;owner_after_self.location=WorldLocation{};
owner_after_self.translate(create,0x46010046,0,self_fixture_codec);
Bytes owner_after_packet;le(owner_after_packet,2,4);le(owner_after_packet,0,1);
append(owner_after_packet,std::span(self_create.body).subspan(5));append(owner_after_packet,std::span(owner_delta.body).subspan(5));
world_inventory_inputs.clear();owner_after_self.translate({0xa9,owner_after_packet},0x46010046,0,self_fixture_codec);
check(owner_after_self.self_created && owner_after_self.inventory.items.empty());
check(owner_after_self.inventory.requests.empty() && world_inventory_inputs.empty());
// A same-packet out-of-range removal must likewise prevent a staged
// create from being published before the real SELF create.
NativeWorldTranslation removed_at_self;removed_at_self.selected.guid=self;removed_at_self.realm=70;removed_at_self.location=WorldLocation{};
removed_at_self.translate(create,0x46010046,0,self_fixture_codec);
Bytes item_guid;le(item_guid,item,8);Bytes removal_packet;le(removal_packet,2,4);le(removal_packet,0,1);
le(removal_packet,4,1);le(removal_packet,1,4);append(removal_packet,pack_guid(item_guid));append(removal_packet,std::span(self_create.body).subspan(5));
world_inventory_inputs.clear();removed_at_self.translate({0xa9,removal_packet},0x46010046,0,self_fixture_codec);
check(removed_at_self.self_created && removed_at_self.pre_self_items.empty() && removed_at_self.inventory.items.empty());
check(removed_at_self.inventory.requests.empty() && world_inventory_inputs.empty());
NativeWorldTranslation removed_after_self;removed_after_self.selected.guid=self;removed_after_self.realm=70;removed_after_self.location=WorldLocation{};
removed_after_self.translate(create,0x46010046,0,self_fixture_codec);
Bytes removal_after;le(removal_after,2,4);le(removal_after,0,1);append(removal_after,std::span(self_create.body).subspan(5));
le(removal_after,4,1);le(removal_after,1,4);append(removal_after,pack_guid(item_guid));
world_inventory_inputs.clear();removed_after_self.translate({0xa9,removal_after},0x46010046,0,self_fixture_codec);
check(removed_after_self.self_created && removed_after_self.inventory.items.empty());
check(removed_after_self.inventory.requests.empty() && world_inventory_inputs.empty());
NativeWorldTranslation removed;removed.selected.guid=self;removed.realm=70;removed.location=WorldLocation{};
removed.translate(create,0x46010046,0,self_fixture_codec);Bytes gone;le(gone,item,8);
removed.translate({0xaa,gone},0x46010046,0,self_fixture_codec);removed.translate(self_create,0x46010046,0,self_fixture_codec);
check(removed.inventory.items.empty() && removed.inventory.requests.empty());
NativeWorldTranslation changed_map;changed_map.selected.guid=self;changed_map.realm=70;changed_map.location=WorldLocation{};
changed_map.translate(create,0x46010046,0,self_fixture_codec);changed_map.location->map=1;
changed_map.translate(self_create,0x46010046,0,self_fixture_codec);
check(changed_map.inventory.items.empty() && changed_map.pre_self_items.empty());
NativeWorldTranslation logout_staging;logout_staging.selected.guid=self;logout_staging.realm=70;logout_staging.location=WorldLocation{};
logout_staging.translate(create,0x46010046,0,self_fixture_codec);logout_staging.translate({0x4d,{}},0x46010046,0,self_fixture_codec);
check(logout_staging.pre_self_items.empty() && !logout_staging.pre_self_item_map);
NativeWorldTranslation transferring;transferring.selected.guid=self;transferring.realm=70;transferring.location=WorldLocation{};
transferring.translate(create,0x46010046,0,self_fixture_codec);transferring.far_transfer.emplace();
transferring.translate(foreign,0x46010046,0,self_fixture_codec);
check(transferring.pre_self_items.empty() && !transferring.pre_self_item_map);
// Only the selected owner, realm and completed destination transfer can
// carry item blocks until destination SELF. Other contexts drop them.
for(unsigned mismatch=0;mismatch<4;++mismatch){
NativeWorldTranslation held;held.selected.guid=self;held.realm=70;held.location=WorldLocation{};
held.far_transfer.emplace();held.far_transfer->owner=self;held.far_transfer->realm=70;held.far_transfer->phase=4;
if(mismatch==0)held.far_transfer->owner=self+1;
if(mismatch==1)held.far_transfer->realm=71;
if(mismatch==2)held.far_transfer->phase=3;
if(mismatch==3)held.far_transfer->destination.map=1;
held.translate(create,0x46010046,0,self_fixture_codec);
check(held.pre_self_items.empty() && held.inventory.requests.empty());
}
NativeWorldTranslation invalidated;invalidated.selected.guid=self;invalidated.realm=70;invalidated.location=WorldLocation{};
invalidated.far_transfer.emplace();invalidated.far_transfer->owner=self;invalidated.far_transfer->realm=70;invalidated.far_transfer->phase=4;
invalidated.translate(create,0x46010046,0,self_fixture_codec);check(invalidated.pre_self_items.contains(item));
invalidated.far_transfer->realm=71;world_inventory_inputs.clear();
invalidated.translate(self_create,0x46010046,0,self_fixture_codec);
check(invalidated.pre_self_items.empty() && invalidated.inventory.items.empty() && world_inventory_inputs.empty());
NativeWorldTranslation malformed;malformed.selected.guid=self;malformed.realm=70;malformed.location=WorldLocation{};
bool pre_rejected=false;try{malformed.translate(update(item,1,2,{{3,25},{6,42},{122,1}}),0x46010046,0,self_fixture_codec);}catch(const Error&){pre_rejected=true;}
check(pre_rejected && malformed.pre_self_items.empty());
NativeWorldTranslation bounded;bounded.selected.guid=self;bounded.realm=70;bounded.location=WorldLocation{};
for(uint64_t i=0;i<4096;++i)bounded.pre_self_items.emplace((0x4000ULL<<48)|(1000+i),LegacyObjectUpdate{});
pre_rejected=false;try{bounded.translate(create,0x46010046,0,self_fixture_codec);}catch(const Error&){pre_rejected=true;}
check(pre_rejected && bounded.pre_self_items.size()==4096);
NativeWorldTranslation duplicate;duplicate.selected.guid=self;duplicate.realm=70;duplicate.location=WorldLocation{};
duplicate.translate(create,0x46010046,0,self_fixture_codec);
Bytes combined;le(combined,2,4);le(combined,0,1);append(combined,std::span(create.body).subspan(5));append(combined,std::span(self_create.body).subspan(5));
world_inventory_inputs.clear();
duplicate.translate({0xa9,combined},0x46010046,0,self_fixture_codec);
check(duplicate.pre_self_items.empty() && duplicate.inventory.items.size()==1 && duplicate.inventory.requests.size()==1);
check(world_inventory_inputs.size()==1);Reader duplicate_emission(world_inventory_inputs.front());
duplicate_emission.le(8);duplicate_emission.le(2);duplicate_emission.le(4);check(duplicate_emission.le(4)==1);
check(duplicate_emission.le(8)==item && duplicate_emission.le(1)==1 && duplicate_emission.le(1)==0);
{
// Exercise the actual pinned SELF and inventory codecs at the world
// ingress: an equipped create in an earlier packet is invisible to
// GW_CODEC_SELF, so a post-SELF player projection is required.
constexpr uint64_t real_self=4509,real_item=(0x4000ULL<<48)|75;
auto make_world=[&](){NativeWorldTranslation w;w.selected.guid=real_self;w.selected.name="Gatewaytest";w.selected.race=1;w.selected.cls=1;w.selected.gender=0;w.selected.zone=12;w.realm=70;w.location=WorldLocation{};ItemTemplateReply t;t.entry=25;t.found=true;t.cls=4;t.inventory_type=5;w.inventory.templates[25]=t;return w;};
auto created=update(real_item,1,2,{{3,25},{6,uint32_t(real_self)},{8,uint32_t(real_self)},{14,1}});
auto projected_visible=[&](uint16_t wanted){
std::vector<uint32_t> values;
for(const auto& input:real_inventory_inputs){
Reader r(input);r.le(8);r.le(2);r.le(4);auto records=r.le(4);
for(unsigned k=0;k<records;++k){auto id=r.le(8);auto type=r.le(1);r.le(1);auto n=r.le(2);
for(unsigned j=0;j<n;++j){auto field=r.le(2);auto value=uint32_t(r.le(4));
if(id==real_self && type==4 && field==wanted)values.push_back(value);
}
}
r.end();
}
return values;
};
auto player_projection=[&]()->std::optional<size_t>{
for(size_t i=0;i<real_inventory_inputs.size();++i){Reader r(real_inventory_inputs[i]);r.le(8);r.le(2);r.le(4);auto records=r.le(4);for(unsigned k=0;k<records;++k){auto id=r.le(8);auto type=r.le(1);r.le(1);auto n=r.le(2);for(unsigned j=0;j<n;++j){auto field=r.le(2);auto value=r.le(4);if(id==real_self && type==4 && field==gateway::turtle_entity_fields::PLAYER_VISIBLE_ITEM_1_0){check(value==25);return i;}}}}return std::nullopt;
};
real_self_outputs.clear();real_inventory_inputs.clear();real_inventory_outputs.clear();
auto staged=make_world();staged.translate(created,0x46010046,0,tracking_real_codec);staged.translate(real_self_fixture(real_self,real_item,false),0x46010046,0,tracking_real_codec);
check(real_self_outputs.size()==1 && real_self_head_item(real_self_outputs[0])==0);
auto projection=player_projection();check(projection && *projection<real_inventory_outputs.size());
check(staged.inventory.items.contains(real_item) && staged.inventory.requests.empty());
// Decode the source-visible field in the emitted update, then compare
// the real native serializer with the identical projection set to 0.
auto assert_native_projection=[&](size_t index){
Bytes zero=real_inventory_inputs[index];Reader zr(zero);zr.le(8);zr.le(2);zr.le(4);auto records=zr.le(4);bool zeroed=false;
for(unsigned k=0;k<records;++k){auto id=zr.le(8);auto type=zr.le(1);zr.le(1);auto zn=zr.le(2);for(unsigned j=0;j<zn;++j){auto field=zr.le(2);size_t pos=zero.size()-zr.left();zr.le(4);if(id==real_self && type==4 && field==gateway::turtle_entity_fields::PLAYER_VISIBLE_ITEM_1_0){check(pos+4<=zero.size());std::fill(zero.begin()+pos,zero.begin()+pos+4,0);zeroed=true;}}}
check(zeroed);uint32_t n=0;check(encode(GW_CODEC_INVENTORY,zero.data(),zero.size(),0,nullptr,0,&n)==GW_CODEC_CAPACITY);Bytes zero_native(n);check(encode(GW_CODEC_INVENTORY,zero.data(),zero.size(),0,zero_native.data(),n,&n)==GW_CODEC_OK);
const auto& projected=real_inventory_outputs[index];check(projected.size()==zero_native.size());bool native_item_25=false;
for(size_t i=0;i+4<=projected.size();++i)if(projected[i]==25 && !zero_native[i] && projected[i+1]==0 && projected[i+2]==0 && projected[i+3]==0 && zero_native[i+1]==0 && zero_native[i+2]==0 && zero_native[i+3]==0)native_item_25=true;
check(native_item_25);
};
assert_native_projection(*projection);
// Baseline: SELF itself contains the create, and already supplies
// the decoded native head item; don't emit a redundant projection.
real_self_outputs.clear();real_inventory_inputs.clear();real_inventory_outputs.clear();auto same=make_world();same.translate(real_self_fixture(real_self,real_item,true),0x46010046,0,tracking_real_codec);
check(real_self_outputs.size()==1 && real_self_head_item(real_self_outputs[0])==25);check(!player_projection());
check(same.inventory.items.contains(real_item) && same.inventory.requests.empty());
// A staged item outside equipment needs no extra player projection.
real_self_outputs.clear();real_inventory_inputs.clear();real_inventory_outputs.clear();auto unequipped=make_world();unequipped.translate(created,0x46010046,0,tracking_real_codec);unequipped.translate(real_self_fixture(real_self,real_item,false,false),0x46010046,0,tracking_real_codec);
check(real_self_outputs.size()==1 && real_self_head_item(real_self_outputs[0])==0);check(!player_projection());
// The reverse order also needs exactly one projection once the real
// owned create arrives, even with the base item already cached.
real_self_outputs.clear();real_inventory_inputs.clear();real_inventory_outputs.clear();auto delayed=make_world();delayed.translate(real_self_fixture(real_self,real_item,false),0x46010046,0,tracking_real_codec);
check(real_self_outputs.size()==1 && real_self_head_item(real_self_outputs[0])==0);check(!player_projection());
real_inventory_inputs.clear();real_inventory_outputs.clear();delayed.translate(update(real_item,1,2,{{3,25},{6,uint32_t(real_self+1)},{8,uint32_t(real_self+1)},{14,1}}),0x46010046,0,tracking_real_codec);check(!player_projection() && !delayed.inventory.items.contains(real_item));
real_inventory_inputs.clear();real_inventory_outputs.clear();delayed.translate(created,0x46010046,0,tracking_real_codec);projection=player_projection();check(projection && *projection<real_inventory_outputs.size());assert_native_projection(*projection);check(delayed.inventory.items.contains(real_item) && delayed.inventory.requests.empty());
real_inventory_inputs.clear();real_inventory_outputs.clear();delayed.translate(created,0x46010046,0,tracking_real_codec);check(!player_projection() && delayed.inventory.requests.empty());
// A genuine player update in the item packet already supplies the
// projection; do not append a duplicate player update.
for(bool item_first:{false,true}){
real_self_outputs.clear();real_inventory_inputs.clear();real_inventory_outputs.clear();auto concurrent=make_world();concurrent.translate(real_self_fixture(real_self,real_item,false),0x46010046,0,tracking_real_codec);
auto player_delta=update(real_self,0,0,{{gateway::turtle_entity_fields::PLAYER_VISIBLE_ITEM_1_0,25}});Bytes together;le(together,2,4);le(together,0,1);
const auto& first=item_first?created:player_delta;const auto& second=item_first?player_delta:created;append(together,std::span(first.body).subspan(5));append(together,std::span(second.body).subspan(5));
real_inventory_inputs.clear();real_inventory_outputs.clear();concurrent.translate({0xa9,together},0x46010046,0,tracking_real_codec);unsigned projections=0;
for(const auto& input:real_inventory_inputs){Reader r(input);r.le(8);r.le(2);r.le(4);auto records=r.le(4);for(unsigned k=0;k<records;++k){auto id=r.le(8);auto type=r.le(1);r.le(1);auto n=r.le(2);if(id==real_self && type==4)++projections;for(unsigned j=0;j<n;++j){r.le(2);r.le(4);}}}check(projections==1 && concurrent.inventory.requests.empty());
}
// An item outside the cached equipment slots does not reproject SELF.
real_self_outputs.clear();real_inventory_inputs.clear();real_inventory_outputs.clear();auto late_unequipped=make_world();late_unequipped.translate(real_self_fixture(real_self,real_item,false,false),0x46010046,0,tracking_real_codec);late_unequipped.translate(created,0x46010046,0,tracking_real_codec);check(!player_projection());
// Validate every original equipment slot, including the previously
// reported gloves, legs and boots, through both real-codec orders.
for(unsigned slot=0;slot<19;++slot){
const auto wanted=uint16_t(gateway::turtle_entity_fields::PLAYER_VISIBLE_ITEM_1_0+12*slot);
// Independently decode the real SELF baseline at every target slot.
real_self_outputs.clear();real_inventory_inputs.clear();real_inventory_outputs.clear();
auto baseline=make_world();baseline.translate(real_self_fixture(real_self,real_item,true,true,25,slot),0x46010046,0,tracking_real_codec);
check(real_self_outputs.size()==1);
for(unsigned native_slot=0;native_slot<19;++native_slot)
check(real_self_visible_item(real_self_outputs[0],native_slot)==(native_slot==slot?25u:0u));
auto verify_slot_projection=[&](){
unsigned matching=0;
for(size_t i=0;i<real_inventory_inputs.size();++i){
Bytes zero=real_inventory_inputs[i];Reader r(zero);
r.le(8);r.le(2);r.le(4);auto records=r.le(4);bool zeroed=false;
for(unsigned k=0;k<records;++k){auto id=r.le(8);auto type=r.le(1);r.le(1);auto n=r.le(2);
for(unsigned j=0;j<n;++j){auto field=r.le(2);auto pos=zero.size()-r.left();auto value=r.le(4);
if(id==real_self && type==4 && field==wanted){check(value==25);std::fill(zero.begin()+pos,zero.begin()+pos+4,0);zeroed=true;}
}
}
if(!zeroed)continue;
++matching;check(i<real_inventory_outputs.size());uint32_t n=0;
check(encode(GW_CODEC_INVENTORY,zero.data(),zero.size(),0,nullptr,0,&n)==GW_CODEC_CAPACITY);
Bytes zero_native(n);check(encode(GW_CODEC_INVENTORY,zero.data(),zero.size(),0,zero_native.data(),n,&n)==GW_CODEC_OK);
const auto& emitted=real_inventory_outputs[i];check(emitted.size()==zero_native.size());bool changed_item=false;
for(size_t j=0;j+4<=emitted.size();++j)if(emitted[j]==25 && !zero_native[j] && !emitted[j+1] && !emitted[j+2] && !emitted[j+3] && !zero_native[j+1] && !zero_native[j+2] && !zero_native[j+3])changed_item=true;
check(changed_item);
}
check(matching==1);
};
real_self_outputs.clear();real_inventory_inputs.clear();real_inventory_outputs.clear();
auto before=make_world();before.translate(created,0x46010046,0,tracking_real_codec);
before.translate(real_self_fixture(real_self,real_item,false,true,25,slot),0x46010046,0,tracking_real_codec);
check(before.inventory.requests.empty());verify_slot_projection();
real_self_outputs.clear();real_inventory_inputs.clear();real_inventory_outputs.clear();
auto after=make_world();after.translate(real_self_fixture(real_self,real_item,false,true,25,slot),0x46010046,0,tracking_real_codec);
real_inventory_inputs.clear();real_inventory_outputs.clear();after.translate(created,0x46010046,0,tracking_real_codec);
check(after.inventory.requests.empty());verify_slot_projection();
// An explicit Source clear must not revive a cached equipped item.
real_inventory_inputs.clear();real_inventory_outputs.clear();
after.translate(update(real_self,4,0,{{wanted,0}}),0x46010046,0,tracking_real_codec);
check(projected_visible(wanted)==std::vector<uint32_t>{0});
check(!real_inventory_outputs.empty() && after.inventory.requests.empty());
}
{
namespace F=gateway::turtle_entity_fields;
// A full owned SELF create replaces cached player fields. Source
// omits zero-valued visibility, inventory and buyback words.
auto refreshed=make_world();
refreshed.translate(real_self_fixture(real_self,real_item,true),0x46010046,0,tracking_real_codec);
std::map<uint16_t,uint32_t> old_visibility;
for(unsigned index=F::PLAYER_VISIBLE_ITEM_1_CREATOR;index<F::PLAYER_FIELD_INV_SLOT_HEAD;++index)
old_visibility[uint16_t(index)]=25;
constexpr auto outside=uint16_t(F::PLAYER_FIELD_INV_SLOT_HEAD+2);
old_visibility[outside]=55;
const std::array<uint16_t,8> stale_fields={outside,uint16_t(F::PLAYER_FIELD_PACK_SLOT_1),
uint16_t(F::PLAYER_FIELD_BANK_SLOT_1),uint16_t(F::PLAYER_FIELD_BANKBAG_SLOT_1),
uint16_t(F::PLAYER_FIELD_VENDORBUYBACK_SLOT_1),uint16_t(F::PLAYER_FIELD_BUYBACK_PRICE_1),
uint16_t(F::PLAYER_FIELD_BUYBACK_TIMESTAMP_1),uint16_t(F::PLAYER_AMMO_ID)};
for(auto index:stale_fields)old_visibility[index]=55;
old_visibility[uint16_t(F::PLAYER_BYTES_2)]=55;
// Initial SELF is authoritative even if a caller already has
// cached player data; no stale bag slot can survive omitted zero.
auto initial=make_world();
initial.inventory.player_fields[F::PLAYER_FIELD_PACK_SLOT_1]=55;
initial.translate(real_self_fixture(real_self,real_item,false,false,25,0,true),0x46010046,0,tracking_real_codec);
{auto field=initial.inventory.player_fields.find(F::PLAYER_FIELD_PACK_SLOT_1);check(field==initial.inventory.player_fields.end() || field->second==0);}
refreshed.translate(update(real_self,4,0,old_visibility),0x46010046,0,tracking_real_codec);
for(unsigned index=F::PLAYER_VISIBLE_ITEM_1_CREATOR;index<F::PLAYER_FIELD_INV_SLOT_HEAD;++index)
check(refreshed.inventory.player_fields.at(index)==25);
refreshed.translate(real_self_fixture(real_self+1,real_item,false,false),0x46010046,0,tracking_real_codec);
check(refreshed.inventory.player_fields.at(F::PLAYER_VISIBLE_ITEM_1_0+12*10)==25);
for(auto index:stale_fields)check(refreshed.inventory.player_fields.at(index)==55);
// Ordinary updates, including updates for other players, must not
// clear omitted fields from this authenticated player's cache.
refreshed.translate(update(real_self,4,0,{{uint16_t(F::PLAYER_VISIBLE_ITEM_1_0),0}}),0x46010046,0,tracking_real_codec);
check(refreshed.inventory.player_fields.at(F::PLAYER_VISIBLE_ITEM_1_0)==0);
check(refreshed.inventory.player_fields.at(F::PLAYER_VISIBLE_ITEM_1_0+12*10)==25);
for(auto index:stale_fields)check(refreshed.inventory.player_fields.at(index)==55);
refreshed.translate(update(real_self+1,4,0,{{uint16_t(F::PLAYER_VISIBLE_ITEM_1_0+12*10),0}}),0x46010046,0,tracking_real_codec);
check(refreshed.inventory.player_fields.at(F::PLAYER_VISIBLE_ITEM_1_0+12*10)==25);
refreshed.far_transfer.emplace();refreshed.far_transfer->owner=real_self;
refreshed.far_transfer->realm=70;refreshed.far_transfer->phase=4;refreshed.self_created=false;
real_self_outputs.clear();
refreshed.translate(real_self_fixture(real_self,real_item,false,false,25,0,true),0x46010046,0,tracking_real_codec);
check(real_self_outputs.size()==1);
for(unsigned slot=0;slot<19;++slot)check(real_self_visible_item(real_self_outputs[0],slot)==0);
for(unsigned index=F::PLAYER_VISIBLE_ITEM_1_CREATOR;index<F::PLAYER_FIELD_INV_SLOT_HEAD;++index){
auto field=refreshed.inventory.player_fields.find(index);
check(field==refreshed.inventory.player_fields.end() || field->second==0);
}
for(auto index:stale_fields){auto field=refreshed.inventory.player_fields.find(index);check(field==refreshed.inventory.player_fields.end() || field->second==0);}
{auto field=refreshed.inventory.player_fields.find(F::PLAYER_BYTES_2);check(field==refreshed.inventory.player_fields.end() || field->second==0);}
// A later unrelated player update must not replay old gear through
// the real inventory serializer after the new SELF was created.
real_inventory_inputs.clear();real_inventory_outputs.clear();
refreshed.translate(update(real_self,4,0,{{uint16_t(F::PLAYER_AMMO_ID),77}}),0x46010046,0,tracking_real_codec);
check(!real_inventory_outputs.empty());
for(unsigned slot=0;slot<19;++slot)
for(auto value:projected_visible(uint16_t(F::PLAYER_VISIBLE_ITEM_1_0+12*slot)))check(value==0);
}
{
namespace F=gateway::turtle_entity_fields;
constexpr auto visible=uint16_t(F::PLAYER_VISIBLE_ITEM_1_0);
// An absent visible field keeps the cached appearance.
auto unchanged=make_world();unchanged.translate(real_self_fixture(real_self,real_item,true),0x46010046,0,tracking_real_codec);
real_inventory_inputs.clear();real_inventory_outputs.clear();
unchanged.translate(update(real_self,4,0,{{uint16_t(F::PLAYER_AMMO_ID),0}}),0x46010046,0,tracking_real_codec);
check(projected_visible(visible)==std::vector<uint32_t>{25});
// A foreign item cannot turn a clear into an unknown appearance.
auto foreign=make_world();foreign.translate(real_self_fixture(real_self,real_item,false),0x46010046,0,tracking_real_codec);
foreign.translate(update(real_item,1,2,{{3,25},{6,4508},{8,4508},{14,1}}),0x46010046,0,tracking_real_codec);
check(!foreign.inventory.items.contains(real_item));
real_inventory_inputs.clear();real_inventory_outputs.clear();
foreign.translate(update(real_self,4,0,{{visible,0}}),0x46010046,0,tracking_real_codec);
check(projected_visible(visible)==std::vector<uint32_t>{0});
}
}
check(count(run(create))==1 && state.items.size()==1);
check(state.queries.contains(25) && state.requests.size()==1 && state.requests.front().opcode==0x56);
Bytes missingItem;le(missingItem,0x80000019,4);check(run({0x58,missingItem}).empty() && !state.queries.contains(25) && state.profile_missing==1 && !state.templates.at(25).found);
auto delta=run(update(item,0,0,{{14,1},{25,9},{26,600000}}));
check(count(delta)==1 && state.items.at(item).fields.at(3)==25 && state.items.at(item).fields.at(25)==9);
Bytes timer;le(timer,item,8);le(timer,1,4);le(timer,600,4);le(timer,self,8);
auto timed=run({0x1eb,timer});check(timed.size()==1 && timed[0].opcode==0x470200);
Guid128 timerItem{};timerItem[0]=75;timerItem[15]=12;
auto expectedTimer=pack_guid(timerItem);le(expectedTimer,600,4);le(expectedTimer,1,4);append(expectedTimer,pack_guid(forever_player_guid(self,70)));
check(timed[0].body==expectedTimer);
for(size_t n=0;n<timer.size();++n){bool rejected=false;try{run({0x1eb,Bytes(timer.begin(),timer.begin()+n)});}catch(const Error&){rejected=true;}check(rejected);}
auto invalidTimer=timer;invalidTimer.push_back(0);bool invalid=false;try{run({0x1eb,invalidTimer});}catch(const Error&){invalid=true;}check(invalid);
auto foreignTimer=timer;foreignTimer[16]=43;check(run({0x1eb,foreignTimer}).empty());
auto unknownTimer=timer;unknownTimer[0]=76;check(run({0x1eb,unknownTimer}).empty());
auto badSlot=timer;badSlot[8]=7;invalid=false;try{run({0x1eb,badSlot});}catch(const Error&){invalid=true;}check(invalid);
auto snapshot=state.snapshot();Reader summary(snapshot);check(summary.le(4)==2 && summary.le(4)==1344 && summary.le(4)==1 && summary.le(4)==1);summary.take(16);check(summary.le(8)==item);summary.le(8);check(summary.le(4)==25 && summary.le(4)==1);
check(run(update(item+1,0,0,{{14,1}})).empty());
auto wrong=update(item+2,1,2,{{3,25},{6,43},{14,1}});check(run(wrong).empty());
// Real Turtle buyback is persisted and sent on login. Source fields are
// separate from carried slots; both belong to the same full SELF create,
// and timestamps retain their full uint32 range.
auto buyback=run(update(self,4,3,{{532,75},{533,0x40000000},{624,75},{625,0x40000000},{1226,7},{1238,0xffffffff}}),true);
check(count(buyback)==1 && state.buyback_slot(72)==69);
// A mask alone is insufficient: the bounded source extractor must also
// retain the reviewed array writer (group311), in original interleaved
// price32/time64 order. This catches a disabled branch with a valid mask.
Bytes buyback_tail;le(buyback_tail,7,4);le(buyback_tail,0xffffffff,8);
check(buyback[0].body.size()>=buyback_tail.size() && std::equal(buyback_tail.begin(),buyback_tail.end(),buyback[0].body.end()-buyback_tail.size()));
check(state.player_fields.at(1226)==7 && state.player_fields.at(1238)==0xffffffff);
check(count(run(update(self,0,0,{{646,75},{647,0x40000000},{1237,9},{1249,108001}})))==1 && state.buyback_slot(83)==80);
for(auto slot:{0u,69u,71u,73u,84u,0xffffffffu}){bool rejected=false;try{state.buyback_slot(slot);}catch(const Error&){rejected=true;}check(rejected);}
check(count(run(update(self,0,0,{{624,0},{625,0},{1226,0},{1238,0}})))==1);
bool emptyBuyback=false;try{state.buyback_slot(72);}catch(const Error&){emptyBuyback=true;}check(emptyBuyback);
check(state.player_fields.at(1226)==0 && state.player_fields.at(1238)==0);
auto swap=state.gameplay(0x410007,Bytes{0x80,255,35,255,15,15,35});
check(swap.opcode==0x10d && swap.body==Bytes({23,15}));
auto equip=state.gameplay(0x410004,Bytes{0x40,255,35,255,35});check(equip.opcode==0x10a && equip.body==Bytes({255,23}));
// Ammo selection names an owned entry and never moves/deletes its stack.
Bytes ammo;le(ammo,25,4);auto selectedAmmo=state.gameplay(0x3f0105,ammo);
check(selectedAmmo.opcode==0x268 && selectedAmmo.body==ammo && state.items.at(item).fields.at(14)==1);
check(state.gameplay(0x3f0105,Bytes(4)).body==Bytes(4));
for(auto invalid:{Bytes{},Bytes{25},Bytes{25,0,0},Bytes{25,0,0,0,0},Bytes{26,0,0,0}}){
bool rejected=false;try{state.gameplay(0x3f0105,invalid);}catch(const Error&){rejected=true;}check(rejected);
}
// Source-confirmed selection and clearing must carry a real native scalar,
// not just set an update-mask bit with its writer filtered out.
NativeInventoryTranslation ammoState;
auto ammoUpdate=ammoState.translate(update(self,0,0,{{turtle_entity_fields::PLAYER_AMMO_ID,13377}}),self,70,0,false,codec);
check(count(ammoUpdate)==1 && ammoState.player_fields.at(turtle_entity_fields::PLAYER_AMMO_ID)==13377);
Bytes ammoTail;le(ammoTail,13377,4);
check(ammoUpdate[0].body.size()>=4 && std::equal(ammoTail.begin(),ammoTail.end(),ammoUpdate[0].body.end()-4));
auto clearAmmo=ammoState.translate(update(self,0,0,{{turtle_entity_fields::PLAYER_AMMO_ID,0}}),self,70,0,false,codec);
check(count(clearAmmo)==1 && ammoState.player_fields.at(turtle_entity_fields::PLAYER_AMMO_ID)==0);
check(clearAmmo[0].body.size()>=4 && std::all_of(clearAmmo[0].body.end()-4,clearAmmo[0].body.end(),[](uint8_t b){return b==0;}));
Bytes bagError{29};le(bagError,item,8);le(bagError,0,8);le(bagError,0,1);
auto failed=run({0x112,bagError});check(failed.size()==1 && failed[0].opcode==0x6a0005);
Reader bagFailure(failed[0].body);check(bagFailure.le(4)==30 && unpack_guid(bagFailure,16)==Bytes(timerItem.begin(),timerItem.end()));check(unpack_guid(bagFailure,16)==Bytes(16) && bagFailure.le(1)==0);bagFailure.end();
Bytes levelError{1};le(levelError,60,4);le(levelError,item,8);le(levelError,0,8);levelError.push_back(0);
auto levelPacket=run({0x112,levelError});Reader level(levelPacket.at(0).body);check(level.le(4)==1);unpack_guid(level,16);unpack_guid(level,16);level.le(1);check(level.le(4)==60);level.end();
for(size_t n=0;n<levelError.size();++n){bool rejected=false;try{run({0x112,Bytes(levelError.begin(),levelError.begin()+n)});}catch(const Error&){rejected=true;}check(rejected);}
auto unknownError=bagError;unknownError[1]=76;check(run({0x112,unknownError}).empty());
const Bytes splitRequest{0x80,255,35,255,36,255,35,255,36,1,0,0,0};
auto split=state.gameplay(0x410008,splitRequest);check(split.opcode==0x10e && split.body==Bytes({255,23,255,24,1}));
// Real client emitted9bytes (empty advisory InvUpdate), source-generated
// body for the verified API positions; no captured payload claim.
auto compactSplit=state.gameplay(0x410008,Bytes{0,255,35,255,37,1,0,0,0});check(compactSplit.body==Bytes({255,23,255,25,1}));
auto splitReject=[&](const Bytes& bytes){bool rejected=false;try{state.gameplay(0x410008,bytes);}catch(const Error&){rejected=true;}check(rejected);};
for(size_t n=0;n<splitRequest.size();++n)splitReject(Bytes(splitRequest.begin(),splitRequest.begin()+n));
auto badSplit=splitRequest;badSplit.push_back(0);splitReject(badSplit);
for(auto quantity:{0u,256u,0xffffffffu}){badSplit=splitRequest;for(unsigned i=0;i<4;++i)badSplit[9+i]=quantity>>(8*i);splitReject(badSplit);}
badSplit=splitRequest;badSplit[5]=30;splitReject(badSplit); // Unbound equipped bag.
badSplit=splitRequest;badSplit[6]=37;splitReject(badSplit); // Unknown source.
// Cast item/slot must match the authenticated inventory cache. Merely
// presenting a well-formed arbitrary modern item GUID cannot authorize use.
Guid128 modern{};modern[0]=75;modern[15]=12;
auto use=Bytes{255,35};append(use,pack_guid(modern));append(use,Bytes{0,0});le(use,0,1);le(use,0,8);le(use,0,4);le(use,433,4);le(use,0,8);le(use,0,4);
append(use,Bytes(8)); // empty unit/item/housing GUIDs and target option bits
append(use,Bytes(8));append(use,Bytes(2));append(use,Bytes(12));append(use,Bytes(2));
auto used=state.use_item(use,{});check(used.opcode==0xab && used.body==Bytes({255,23,0,0,0}));
auto wrong_source=use;wrong_source[1]=36;bool denied=false;try{state.use_item(wrong_source,{});}catch(const Error&){denied=true;}check(denied);
for(auto invalid:{Bytes{0x80,255,35,255,15,15,34},Bytes{0x80,255,35,255,15,15,35,0},Bytes{0,29,35}}){
bool rejected=false;try{state.gameplay(0x410007,invalid);}catch(const Error&){rejected=true;}check(rejected);
}
check(count(run(update(self,0,0,{{532,0}})))==1 && state.player_fields.at(533)==0x40000000);
// A sparse low-word delta preserves its actual cached high word. A clear
// must carry the server's high-word clear as well, never a guessed GUID.
check(count(run(update(self,0,0,{{533,0},{440,25}})))==1 && state.player_fields.at(533)==0);
auto bag=update(item+3,2,2,{{3,4496},{6,42},{8,42},{14,1},{48,6},{50,75},{51,0x40000000}});
check(count(run(bag))==1 && state.items.at(item+3).type==2);
run(update(self,0,0,{{524,78},{525,0x40000000}})); // Equipped bag19 -> modern30.
run(update(item,0,0,{{8,78},{9,0x40000000}})); // Genuine contained GUID changes.
auto nested=state.position(30,0);check(nested.bag==19 && nested.slot==0 && nested.item==item);
auto moved=state.gameplay(0x410006,Bytes{0,255,30,37,0});check(moved.opcode==0x10c && moved.body==Bytes({255,25,19,0}));
auto bagUse=use;bagUse[0]=30;bagUse[1]=0;check(state.use_item(bagUse,{}).body==Bytes({19,0,0,0,0}));
check(state.gameplay(0x410004,Bytes{0,30,0}).body==Bytes({19,0}));
for(auto pos:std::vector<std::pair<uint8_t,uint8_t>>{{30,6},{31,0},{34,0},{255,29}}){bool rejected=false;try{state.position(pos.first,pos.second);}catch(const Error&){rejected=true;}check(rejected);}
state.items.at(item).fields[8]=42;state.items.at(item).fields[9]=0;
bool badChild=false;try{state.position(30,0);}catch(const Error&){badChild=true;}check(badChild);
Bytes remove;le(remove,item,8);check(run({0xaa,remove}).size()==1 && !state.items.contains(item));
check(run(update(item,0,0,{{14,0}})).empty());
check(count(run(create,true))==1);Reader typed(last);typed.take(18);check(typed.le(8)==item && typed.le(1)==1 && typed.le(1)==0);
check(run(update(item,0,0,{{6,43}})).size()==1 && !state.items.contains(item));
// Source codec + authenticated presentation-state fixture: never emit a
// prepare/start/go for an unrelated spell, and retire correlation on GO.
NativeWorldTranslation world{};world.selected.guid=4509;world.realm=70;world.self_created=true;world.location=WorldLocation{};
constexpr uint64_t stone=(0x4000ULL<<48)|36230,sword=(0x4000ULL<<48)|36198;
world.inventory.items[stone].fields[3]=12404;world.inventory.items[sword].fields[3]=25;
auto request=unhex("ff250380868d0c01870282c20fbc000000000000000000000000000a3f0000dfbf0300000000001000000000000380668d0c00000000000000000000000000000000000000000000000000000000");world.gameplay_sent(0x3e0171,request);
Bytes start,rawId;le(rawId,stone,8);append(start,pack_guid(rawId));rawId.clear();le(rawId,4509,8);append(start,pack_guid(rawId));le(start,16138,4);auto prefix=start;le(start,2,2);le(start,3000,4);le(start,16,2);rawId.clear();le(rawId,sword,8);append(start,pack_guid(rawId));
auto started=world.translate({0x131,start},0x46010046,0,encode);Reader prepared(started);check(prepared.le(4)==2 && prepared.le(4)==0x69002b);auto size=prepared.le(4);prepared.take(size);check(prepared.le(4)==0x69002d);size=prepared.le(4);check(size>40);prepared.take(size);prepared.end();
auto repeatedStart=world.translate({0x131,start},0x46010046,0,encode);Reader repeated(repeatedStart);check(repeated.le(4)==1 && repeated.le(4)==0x69002d);
auto go=prefix;le(go,0x100,2);le(go,0,2);le(go,16,2);append(go,pack_guid(rawId));auto completed=world.translate({0x132,go},0x46010046,0,encode);Reader ended(completed);check(ended.le(4)==1 && ended.le(4)==0x69002c && !world.pending_cast);
check(world.translate({0x132,go},0x46010046,0,encode)==Bytes({0,0,0,0}));
world.gameplay_sent(0x3e0171,request);auto castId=pack_guid(forever_item_use(request).spell.cast);auto cancel=castId;le(cancel,16138,4);auto canceled=world.gameplay(0x3e0179,cancel);check(canceled.opcode==0x12f && canceled.body==Bytes({0x0a,0x3f,0,0}));
auto foreignCancel=cancel;foreignCancel.back()=1;bool cancelRejected=false;try{world.gameplay(0x3e0179,foreignCancel);}catch(const Error&){cancelRejected=true;}check(cancelRejected);
Bytes rejected;le(rejected,16138,4);le(rejected,2,1);le(rejected,1,1);auto rejectedResult=world.translate({0x130,rejected},0x46010046,0,encode);Reader failure(rejectedResult);check(failure.le(4)==1 && failure.le(4)==0x69004a && !world.pending_cast);
world.gameplay_sent(0x3e0171,request);world.cast_prepared=true;rejected[5]=35;auto interrupted=world.translate({0x130,rejected},0x46010046,0,encode);Reader interruptions(interrupted);check(interruptions.le(4)==2 && interruptions.le(4)==0x69004a);auto failedBytes=interruptions.le(4);interruptions.take(failedBytes);check(interruptions.le(4)==0x690046 && !world.pending_cast);
world.gameplay_sent(0x3e0171,request);world.cast_prepared=true;Bytes notify;le(notify,4509,8);le(notify,16138,4);
auto notified=world.translate({0x2a6,notify},0x46010046,0,encode);Reader notice(notified);check(notice.le(4)==1 && notice.le(4)==0x690046 && world.pending_cast && !world.cast_prepared);
auto finalFailure=world.translate({0x130,rejected},0x46010046,0,encode);Reader finalResult(finalFailure);check(finalResult.le(4)==1 && finalResult.le(4)==0x69004a && !world.pending_cast);
// Same source-backed cast lifecycle for a normal player-cast spell,
// using the genuine693840 request, not an item-shaped cast workaround.
auto normal_request=unhex("018701426602bc0000000000000000000000000099090000c6a2030000000000000000000000000000000000000000000000000000000000000000000000000000000000");
bool unknown_spell_rejected=false;try{world.gameplay(0x3e0176,normal_request);}catch(const Error&){unknown_spell_rejected=true;}check(unknown_spell_rejected && !world.pending_cast);
world.spells.insert(2457);auto normal_wire=world.gameplay(0x3e0176,normal_request);check(normal_wire.opcode==0x12e && normal_wire.body==Bytes({0x99,9,0,0,0,0}));
world.gameplay_sent(0x3e0176,normal_request);check(world.pending_cast && !world.pending_item_entry);
Bytes normal_prefix;Bytes normal_self;le(normal_self,4509,8);append(normal_prefix,pack_guid(normal_self));append(normal_prefix,pack_guid(normal_self));le(normal_prefix,2457,4);
auto normal_start=normal_prefix;le(normal_start,2,2);le(normal_start,0,4);le(normal_start,0,2);
auto normal_started=world.translate({0x131,normal_start},0x46010046,0,encode);Reader normal_begin(normal_started);check(normal_begin.le(4)==2 && normal_begin.le(4)==0x69002b);
auto normal_go=normal_prefix;le(normal_go,0x100,2);le(normal_go,0,2);le(normal_go,0,2);
auto normal_ended=world.translate({0x132,normal_go},0x46010046,0,encode);Reader normal_end(normal_ended);check(normal_end.le(4)==1 && normal_end.le(4)==0x69002c && !world.pending_cast);
world.gameplay_sent(0x3e0176,normal_request);Bytes normal_failure;le(normal_failure,2457,4);append(normal_failure,Bytes{2,35});
auto normal_rejected=world.translate({0x130,normal_failure},0x46010046,0,encode);Reader normal_fail(normal_rejected);check(normal_fail.le(4)==1 && normal_fail.le(4)==0x69004a && !world.pending_cast);
// Deliberate test-server prototype override, not a claim about installed
// stone cooldowns. The generic adapter must honor wire metadata by entry.
ItemTemplateReply profile;profile.entry=12404;profile.found=true;profile.spells[0]={16138,0,4,0,120000,120000};world.inventory.templates[12404]=profile;
world.gameplay_sent(0x3e0171,request);auto cooled=world.translate({0x132,go},0x46010046,0,encode);Reader cooldown(cooled);check(cooldown.le(4)==3);check(world.inventory.cooldown_packets==1);
Bytes modifier{0,11};le(modifier,0xffffec78,4);world.translate({0x266,modifier},0x46010046,0,encode);
world.gameplay_sent(0x3e0171,request);auto guarded=world.translate({0x132,go},0x46010046,0,encode);Reader guard(guarded);check(guard.le(4)==2 && world.inventory.cooldown_packets==1 && world.inventory.cooldown_modifier_blocks==1);
Bytes clear;le(clear,16138,4);le(clear,4509,8);auto cleared=world.translate({0x1de,clear},0x46010046,0,encode);Reader clearResult(cleared);check(clearResult.le(4)==1 && clearResult.le(4)==0x470167 && world.item_cooldown_until.empty());
Bytes forced;le(forced,4509,8);le(forced,6612,4);le(forced,120000,4);auto forcedResult=world.translate({0x134,forced},0x46010046,0,encode);Reader forcedBundle(forcedResult);check(forcedBundle.le(4)==1 && forcedBundle.le(4)==0x690005);auto forcedSize=forcedBundle.le(4);auto forcedBody=forcedBundle.take(forcedSize);Reader forcedFields(forcedBody);auto forcedOwner=forever_player_guid(4509,70);check(unpack_guid(forcedFields,16)==Bytes(forcedOwner.begin(),forcedOwner.end()));check(forcedFields.le(1)==0 && forcedFields.le(4)==1 && forcedFields.le(4)==6612 && forcedFields.le(4)==120000 && forcedFields.f32()==1.0f);forcedFields.end();
Bytes owner;le(owner,4509,8);world.spells.insert(433);auto reset=world.translate({0x1e1,owner},0x46010046,0,encode);Reader resetBundle(reset);check(resetBundle.le(4)==1 && resetBundle.le(4)==0x690015 && world.item_cooldown_until.empty());
// Ordinary source bank: fixed24 slots + six independently owned bags.
// The virtual native root container is presentation only and cannot be moved.
namespace F=gateway::turtle_entity_fields;
NativeInventoryTranslation banks;
auto bankrun=[&](const LegacyPacket& p){return banks.translate(p,self,70,0,false,codec);};
bankrun(create);
// An advertised bank-count mask must include its actual byte. The old
// bounded writer stripped this nested branch and misaligned following
// inventory GUIDs in the original engine despite packet-count tests passing.
for(unsigned purchased: {6u,5u,0u}){
auto counted=bankrun(update(self,0,0,{{F::PLAYER_BYTES_2,purchased<<16}}));
check(count(counted)==1 && counted.size()==1 && counted[0].body.size()>=2);
// Original group134 ends with four optional-presence bits, after
// whichever separately masked bank/tab counts were actually emitted.
bank_counts(counted[0].body,purchased);
}
constexpr uint64_t bankbag=item+20;
check(count(bankrun(update(bankbag,2,2,{{3,4496},{6,42},{8,42},{14,1},{48,6}})))==1);
auto bankstate=update(self,0,0,{{F::PLAYER_BYTES_2,6u<<16},{F::PLAYER_FIELD_BANK_SLOT_1,75},
{F::PLAYER_FIELD_BANK_SLOT_1+1,0x40000000},{F::PLAYER_FIELD_BANKBAG_SLOT_1,95},
{F::PLAYER_FIELD_BANKBAG_SLOT_1+1,0x40000000}});
check(count(bankrun(bankstate))==2 && banks.player_fields.at(F::PLAYER_BYTES_2)==6u<<16);
auto rootbank=banks.position(63,0);check(rootbank.bag==255 && rootbank.slot==39 && rootbank.item==item);
auto bankbagslot=banks.position(255,64);check(bankbagslot.bag==255 && bankbagslot.slot==63 && bankbagslot.item==bankbag);
auto emptybank=banks.position(64,5);check(emptybank.bag==63 && emptybank.slot==5 && !emptybank.item);
auto closed = equipment_sets::accessible(banks, false);
auto opened = equipment_sets::accessible(banks, true);
const auto mapped = banks.owned_bindings().at(item);
check(std::none_of(closed.begin(), closed.end(), [](const auto& pos) { return pos.bank; }));
check(std::any_of(opened.begin(), opened.end(), [&](const auto& pos) {
return pos.bank && pos.bag == 255 && pos.slot == 39 && pos.item == mapped;
}));
check(std::any_of(opened.begin(), opened.end(), [](const auto& pos) {
return pos.bank && pos.bag == 63 && pos.slot == 5 && pos.item == Guid128{};
}));
auto withdrawal=banks.gameplay(0x410006,Bytes{0,255,63,35,0});check(withdrawal.opcode==0x10c && withdrawal.body==Bytes({255,23,255,39}));
for(auto pos:std::vector<std::pair<uint8_t,uint8_t>>{{63,24},{64,6},{70,0},{255,63}}){bool rejected=false;try{banks.position(pos.first,pos.second);}catch(const Error&){rejected=true;}check(rejected);}
check(count(bankrun(update(self,0,0,{{F::PLAYER_FIELD_BANK_SLOT_1,0},{F::PLAYER_FIELD_BANK_SLOT_1+1,0}})))==2);
check(!banks.position(63,0).item);
// Generated source transmog entries must never become native ItemIDs.
// Preserve the source cache and derive presentation identity from ownership.
NativeInventoryTranslation appearances;
auto appearance_run=[&](const LegacyPacket& p){return appearances.translate(p,self,70,0,false,codec);};
appearance_run(create);
constexpr unsigned visible=F::PLAYER_VISIBLE_ITEM_1_0+12*15;
constexpr unsigned equipped=F::PLAYER_FIELD_INV_SLOT_HEAD+2*15;
appearance_run(update(self,0,0,{{visible,138687},{equipped,75},{equipped+1,0x40000000}}));
check(appearances.player_fields.at(visible)==138687);
auto serialized_field=[&](unsigned wanted){Reader r(last);r.take(14);auto records=r.le(4);check(records==1);r.le(8);check(r.le(1)==4);r.le(1);auto n=r.le(2);std::map<unsigned,unsigned> f;for(unsigned i=0;i<n;++i){auto index=r.le(2);auto value=r.le(4);f[index]=value;}r.end();return f.at(wanted);};
check(serialized_field(visible)==25);
check(appearances.queries.contains(138687));
// Real template reply semantics: generated transmog appearance is separate
// from base owned item. Delayed metadata must refresh the existing player.
ItemTemplateReply base;base.entry=25;base.found=true;base.cls=4;base.inventory_type=5;
appearances.templates[25]=base;
// Initial SELF may follow an item whose base template was already cached.
// There is then no later base-query reply to trigger a player projection.
// Resolve the real Source appearance once, without changing owned ItemID.
for(bool self_first:{false,true}){
NativeInventoryTranslation initial_appearance;initial_appearance.templates[25]=base;
auto initial_run=[&](const LegacyPacket& p){return initial_appearance.translate(p,self,70,0,true,codec);};
auto initial_self=update(self,4,2,{{visible,138687},{equipped,75},{equipped+1,0x40000000}});
if(self_first){initial_run(initial_self);initial_run(create);}else{initial_run(create);initial_run(initial_self);}
check(initial_appearance.queries.contains(138687) && initial_appearance.requests.size()==1);
check(initial_appearance.requests.front().opcode==0x56 && initial_appearance.items.at(item).fields.at(3)==25);
initial_run(update(self,0,0,{{visible,138687}}));
check(initial_appearance.requests.size()==1);
ItemTemplateReply absent;absent.entry=138687;absent.found=false;
initial_appearance.queries.erase(138687);initial_appearance.templates[138687]=absent;
initial_run(update(self,0,0,{{visible,138687}}));
check(initial_appearance.requests.size()==1);
}
Bytes transmog;le(transmog,138687,4);le(transmog,4,4);le(transmog,4,4);
cstring(transmog,"appearance query fixture");for(unsigned i=0;i<3;++i)cstring(transmog,"");
for(unsigned i=0;i<20;++i)le(transmog,i==0?21898:i==5?5:0,4);
for(unsigned i=0;i<20+15+7+3+30;++i)le(transmog,0,4);
le(transmog,0,4);cstring(transmog,"");for(unsigned i=0;i<14;++i)le(transmog,0,4);
// A genuine outstanding item reply may arrive while the same owned far
// transfer has removed SELF. Cache only that reply, publish nothing
// before SELF, then use the actual codecs to restore its appearance once.
for(bool item_in_self:{false,true}){
constexpr uint64_t transfer_self=4509,transfer_item=(0x4000ULL<<48)|75;
NativeWorldTranslation transfer;transfer.selected.guid=transfer_self;transfer.selected.name="Gatewaytest";
transfer.selected.race=1;transfer.selected.cls=1;transfer.selected.gender=0;transfer.selected.zone=12;
transfer.realm=70;transfer.location=WorldLocation{};transfer.inventory.templates[25]=base;
auto transfer_create=update(transfer_item,1,2,{{3,25},{6,uint32_t(transfer_self)},{8,uint32_t(transfer_self)},{14,1}});
transfer.translate(transfer_create,0x46010046,0,tracking_real_codec);
transfer.translate(real_self_fixture(transfer_self,transfer_item,false,true,138687),0x46010046,0,tracking_real_codec);
check(transfer.inventory.queries.contains(138687));
transfer.far_transfer.emplace();transfer.far_transfer->owner=transfer_self;
transfer.far_transfer->realm=70;transfer.far_transfer->phase=2;transfer.self_created=false;
auto reply_world=[&](const Bytes& body){auto out=transfer.translate({0x58,body},0x46010046,0,tracking_real_codec);Reader r(out);check(r.le(4)==0);r.end();};
auto foreign=transmog;foreign[0]^=1;reply_world(foreign);
check(transfer.inventory.queries.contains(138687) && !transfer.inventory.templates.contains(138687));
transfer.far_transfer->owner=transfer_self+1;reply_world(transmog);
check(transfer.inventory.queries.contains(138687) && !transfer.inventory.deferred_template_projection);
transfer.far_transfer->owner=transfer_self;transfer.far_transfer->realm=71;reply_world(transmog);
check(transfer.inventory.queries.contains(138687) && !transfer.inventory.deferred_template_projection);
transfer.far_transfer->realm=70;transfer.far_transfer->phase=1;reply_world(transmog);
check(transfer.inventory.queries.contains(138687) && !transfer.inventory.deferred_template_projection);
transfer.far_transfer->phase=2;auto requests=transfer.inventory.requests.size();reply_world(transmog);
check(!transfer.inventory.queries.contains(138687) && transfer.inventory.templates.at(138687).found && transfer.inventory.deferred_template_projection);
auto replies=transfer.inventory.profile_replies;reply_world(transmog);check(transfer.inventory.profile_replies==replies && transfer.inventory.requests.size()==requests);
transfer.inventory.queries.insert(138688);Bytes missing;le(missing,0x80000000u|138688u,4);reply_world(missing);
check(!transfer.inventory.queries.contains(138688) && !transfer.inventory.templates.at(138688).found && transfer.inventory.profile_missing==1);
transfer.far_transfer->owner_generation=7;transfer.entities.self_position_generation=7;
transfer.worldport_prepared();check(transfer.worldport_send_completed());
check(transfer.inventory.deferred_template_projection);
if(!item_in_self){
auto out=transfer.translate(transfer_create,0x46010046,0,tracking_real_codec);
Reader r(out);check(r.le(4)==0);r.end();
check(transfer.pre_self_items.contains(transfer_item) && transfer.inventory.requests.empty());
}
real_inventory_inputs.clear();real_inventory_outputs.clear();
transfer.translate(real_self_fixture(transfer_self,transfer_item,item_in_self,true,138687),0x46010046,0,tracking_real_codec);
check(!transfer.inventory.deferred_template_projection && !real_inventory_outputs.empty());
unsigned player_updates=0;bool mapped=false;
for(const auto& input:real_inventory_inputs){Reader r(input);r.le(8);r.le(2);r.le(4);auto records=r.le(4);
for(unsigned i=0;i<records;++i){auto guid=r.le(8),type=r.le(1);r.le(1);auto fields=r.le(2);
for(unsigned j=0;j<fields;++j){auto index=r.le(2),value=r.le(4);
if(guid==transfer_self && type==4 && index==F::PLAYER_VISIBLE_ITEM_1_0){++player_updates;mapped|=value==11633;}
}
}r.end();
}
check(player_updates==1 && mapped);
}
{
// WorldPort completion resets world instances, but authenticated
// Source item queries and replies remain valid on this transport.
NativeWorldTranslation ack;ack.selected.guid=self;ack.realm=70;ack.location=WorldLocation{};
ack.far_transfer.emplace();ack.far_transfer->owner=self;ack.far_transfer->realm=70;
ack.far_transfer->phase=3;ack.far_transfer->owner_generation=7;ack.entities.self_position_generation=7;
ack.inventory.queries.insert(138689);ack.inventory.templates[138687]=base;
ack.inventory.deferred_template_projection=true;ack.inventory.items[item]=LegacyObjectUpdate{};
ack.inventory.request_peer_template(191919);ack.inventory.requests.clear(); // already sent
check(ack.worldport_send_completed());
ack.inventory.deferred_template_projection=false;
Bytes peer_missing;le(peer_missing,0x80000000u|191919u,4);
auto peer_out=ack.translate({0x58,peer_missing},0x46010046,0,tracking_real_codec);
Reader peer_result(peer_out);check(peer_result.le(4)==0);peer_result.end();
check(ack.inventory.peer_template(191919) && !ack.inventory.templates.contains(191919)
&& !ack.inventory.deferred_template_projection);
ack.inventory.deferred_template_projection=true;
check(ack.inventory.items.empty() && ack.inventory.templates.contains(138687));
check(ack.inventory.queries.contains(138689) && ack.inventory.deferred_template_projection);
Bytes missing;le(missing,0x80000000u|138689u,4);
auto out=ack.translate({0x58,missing},0x46010046,0,tracking_real_codec);Reader r(out);check(r.le(4)==0);r.end();
check(!ack.inventory.queries.contains(138689) && !ack.inventory.templates.at(138689).found);
}
{
// Only sent queries remain pending when the transfer discards its
// queued, unsent requests.
NativeWorldTranslation start;start.selected.guid=self;start.realm=70;start.self_created=true;
start.location=WorldLocation{};start.entities.self_presentation_ready=true;
start.entities.self_position_generation=9;start.entities.position_realm=70;start.entities.position_map=0;
start.inventory.request_peer_template(199999);
start.inventory.queries.insert({138687,138689});start.inventory.requests.push_back({0x56,turtle_item_query(138689)});
Bytes pending;le(pending,1,4);Bytes next;le(next,1,4);for(unsigned i=0;i<4;++i)le(next,0,4);
NativeEntityTranslation::Codec codec=[](uint32_t,const Bytes& b){return b;};
check(start.receive_far_transfer(0x3f,pending,codec).empty());
check(start.receive_far_transfer(0x3e,next,codec).size()==2);
check(start.inventory.requests.empty() && start.inventory.queries.contains(138687) && !start.inventory.queries.contains(138689));
check(!start.inventory.queries.contains(199999) && !start.inventory.peer_template_queries.contains(199999));
}
{
NativeWorldTranslation stale;stale.selected.guid=self;stale.realm=70;stale.location=WorldLocation{};
stale.far_transfer.emplace();stale.far_transfer->owner=self;stale.far_transfer->realm=70;stale.far_transfer->phase=2;
stale.inventory.queries.insert(138687);stale.inventory.deferred_template_projection=true;
stale.translate({0x4d,{}},0x46010046,0,tracking_real_codec);
check(!stale.inventory.deferred_template_projection && stale.logout_complete);
auto out=stale.translate({0x58,transmog},0x46010046,0,tracking_real_codec);Reader r(out);check(r.le(4)==0);r.end();
check(stale.inventory.queries.contains(138687) && !stale.inventory.templates.contains(138687));
}
check(count(appearance_run({0x58,transmog}))==3);
check(appearance_calls==1 && appearances.applied_appearances.at(item)==160297);
Reader appearance_delta(last_appearance);check(appearance_delta.le(2)==0 && appearance_delta.le(2)==70 && appearance_delta.le(8)==self && appearance_delta.le(2)==1 && appearance_delta.le(8)==item && appearance_delta.le(4)==160297);check(appearance_delta.le(1)==1 && appearance_delta.le(1)==15 && appearance_delta.le(1)==1);appearance_delta.end();
check(serialized_field(visible)==11633 && appearances.items.at(item).fields.at(3)==25);
check(appearance_run({0x58,transmog}).empty()); // Unsolicited/duplicate reply never replays.
auto before_appearance_calls=appearance_calls;
check(count(appearance_run(update(self,0,0,{{visible,138687}})))==1 && appearance_calls==before_appearance_calls);
appearances.templates[138687].inventory_type=17;
appearance_run(update(self,0,0,{{visible,138687}}));
check(serialized_field(visible)==25);
check(appearances.applied_appearances.empty() && appearance_calls==before_appearance_calls+1);
Reader appearance_clear(last_appearance);appearance_clear.le(2);check(appearance_clear.le(2)==70 && appearance_clear.le(8)==self && appearance_clear.le(2)==1 && appearance_clear.le(8)==item && appearance_clear.le(4)==0);check(appearance_clear.le(1)==1 && appearance_clear.le(1)==15 && appearance_clear.le(1)==0);appearance_clear.end();
appearance_run(update(self,0,0,{{visible,0},{equipped,0},{equipped+1,0}}));
check(serialized_field(visible)==0 && appearances.player_fields.at(visible)==0);
// Reapply a validated source appearance, then real slot/GUID unequip must
// clear item metadata without changing the owned item's actual identity.
appearances.templates[138687].inventory_type=5;
check(count(appearance_run(update(self,0,0,{{visible,138687},{equipped,75},{equipped+1,0x40000000}})))==3);
check(appearances.applied_appearances.at(item)==160297);
check(count(appearance_run(update(self,0,0,{{visible,0},{equipped,0},{equipped+1,0}})))==3);
check(appearances.applied_appearances.empty() && appearances.items.at(item).fields.at(3)==25);
Reader unequip_clear(last_appearance);unequip_clear.le(2);check(unequip_clear.le(2)==70 && unequip_clear.le(8)==self && unequip_clear.le(2)==1 && unequip_clear.le(8)==item && unequip_clear.le(4)==0);check(unequip_clear.le(1)==1 && unequip_clear.le(1)==15 && unequip_clear.le(1)==0);unequip_clear.end();
// Live 2026-11-23: Spaulders transmogged to Withered Bark Pauldrons 33210 read "Transmogrified to:
// Dark Iron Shoulders" (same-display donor). A source with its own client appearance uses it.
check(gateway::item_render_profile::modified_appearance(33210)==318460);
appearances.templates[33210]=appearances.templates.at(138687);
appearance_run(update(self,0,0,{{visible,33210},{equipped,75},{equipped+1,0x40000000}}));
check(appearances.applied_appearances.at(item)==318460);
appearance_run(update(self,0,0,{{visible,0},{equipped,0},{equipped+1,0}}));
check(appearances.applied_appearances.empty());
appearance_run(update(self,0,0,{{visible,138687},{equipped,75},{equipped+1,0x40000000}}));
Bytes destroy_item;le(destroy_item,item,8);auto destroyed_appearance=appearance_run({0xaa,destroy_item});
check(destroyed_appearance.size()==2 && !appearances.items.contains(item) && appearances.applied_transmog_slots.empty());
Reader destroyed_flag(last_appearance);check(destroyed_flag.le(2)==0 && destroyed_flag.le(2)==70 && destroyed_flag.le(8)==self && destroyed_flag.le(2)==0);
check(destroyed_flag.le(1)==1 && destroyed_flag.le(1)==15 && destroyed_flag.le(1)==0);destroyed_flag.end();
{// Live 2026-11-22 (MC rune, Aqual Quintessence 17333 -> 21358 on GO 176956): the item cast on a game object
// must present its prepare/start/go like any item cast (cast bar, animation, item cooldown).
NativeWorldTranslation w{};w.selected.guid=4509;w.realm=70;w.self_created=true;w.location=WorldLocation{409,{0,0,0,0}};
const uint64_t rune=0xf11002b33c00000aULL;auto& a=w.entities.actors[rune];a.kind=5;a.sent=true;a.eligible=true;a.entry=176956;a.generation=3;
a.presentation_realm=70;a.presentation_map=409;a.modern=forever_game_object_guid(rune,176956,70,409);
constexpr uint64_t quint=(0x4000ULL<<48)|36300;w.inventory.items[quint].fields[3]=17333;
Guid128 itemId{};for(unsigned i=0;i<4;++i)itemId[i]=uint8_t(quint>>(8*i));itemId[15]=3u<<2;
Bytes use{255,23};append(use,pack_guid(itemId));
Guid128 castId{};castId[0]=7;castId[15]=0x30;append(use,pack_guid(castId));le(use,0,1);for(int i=0;i<3;++i)le(use,0,4);
le(use,21358,4);le(use,0,4);le(use,0,4);le(use,0x800,4);append(use,pack_guid(a.modern));
Guid128 zero{};append(use,pack_guid(zero));append(use,pack_guid(zero));le(use,0,2);le(use,0,4);le(use,0,4);append(use,pack_guid(zero));
for(int i=0;i<3;++i)le(use,0,4);le(use,0,1);le(use,0,1);
w.gameplay_sent(0x3e0171,use);check(w.pending_cast.has_value());
Bytes start,raw;le(raw,quint,8);append(start,pack_guid(raw));raw.clear();le(raw,4509,8);append(start,pack_guid(raw));le(start,21358,4);
auto prefix=start;le(start,2,2);le(start,5000,4);le(start,0x800,2);raw.clear();le(raw,rune,8);append(start,pack_guid(raw));
auto started=w.translate({0x131,start},0x46010046,0,encode);Reader sr(started);auto n=sr.le(4);
std::cerr<<"GO item cast start packets="<<n<<"\n";check(n==2);}
dlclose(library);std::cout<<"Owned inventory, mapped bank containers and source spell lifecycle correlation fixtures passed; no real gameplay asserted.\n";
}