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

610 lines
47 KiB
C++

#include "world_translation.hpp"
#include "gateway/mount_action_spells.hpp"
#include "session.h"
#include "gateway/object_updates.hpp"
#include "gateway/corpse.hpp"
#include "gateway/turtle_entity_profile.hpp"
#include "gateway/pet_presentation.hpp"
#include "gateway/source_faction_profile.hpp"
#include "gateway/spell_damage.hpp"
#include <bit>
#include <algorithm>
#include <cstdlib>
#include <iostream>
using namespace gateway;
static void check(bool condition){if(!condition)throw Error("native gameplay fixture assertion");}
template<class F> static void rejects(F operation){try{operation();}catch(const Error&){return;}throw Error("expected gameplay rejection");}
static void verify_selected_player_create(){
// The requested character is visible as a peer in the other character's world.
Bytes body;
le(body,2,4);
le(body,0,1);
auto add_player=[&](uint64_t guid,uint8_t flags){
Bytes identity;
le(identity,guid,8);
le(body,3,1);
append(body,pack_guid(identity));
append(body,Bytes{4,flags,0}); // player type, update flags, empty update mask
};
add_player(4514,0);
add_player(4528,1);
auto records=turtle_object_updates(0xa9,body);
check(records.size()==2);
check(!records[0].is_self_player_create(4514));
check(!records[1].is_self_player_create(4514));
check(records[1].is_self_player_create(4528));
}
static void verify_character_bank_transfers(){
namespace F=gateway::turtle_entity_fields;
NativeWorldTranslation world{};
world.realm=70;
world.selected.guid=42;
world.self_created=true;
world.location=WorldLocation{};
constexpr uint64_t banker=(0xf130ULL<<48)|(2455ULL<<24)|1;
auto& actor=world.entities.actors[banker];
actor.entry=2455;
actor.kind=3;
actor.sent=true;
actor.eligible=true;actor.presentation_realm=70;actor.presentation_map=0;
actor.generation=3;
actor.modern=forever_creature_guid(banker,2455,world.realm,0);
Bytes show;le(show,banker,8);
auto open=[&](){world.translate({0x1b8,show},0x46010046,0,nullptr);};
auto& inventory=world.inventory;
uint32_t next=10;
auto root_item=[&](uint16_t root){
const auto id=++next;
inventory.player_fields[root]=id;
auto& item=inventory.items[id];
item.type=1;
item.fields[F::ITEM_FIELD_OWNER]=world.selected.guid;
item.fields[F::ITEM_FIELD_CONTAINED]=world.selected.guid;
return id;
};
const Bytes deposit{0,0,255,35};
auto check_request=[&](uint32_t opcode,const Bytes& input,uint32_t output,const Bytes& position){
auto packet=world.gameplay(opcode,input);
check(packet.opcode==output && packet.body==position);
};
for(unsigned offset : {0u,15u})root_item(F::PLAYER_FIELD_PACK_SLOT_1+2*offset);
for(unsigned offset : {0u,23u})root_item(F::PLAYER_FIELD_BANK_SLOT_1+2*offset);
// BuyBankTab (bank type 0) buys a Turtle bank bag slot from the open banker only.
auto buy=[&](uint8_t type){auto b=pack_guid(actor.modern);b.push_back(type);return b;};
rejects([&]{world.gameplay(0x3f012c,buy(0));});
rejects([&]{world.gameplay(0x410003,deposit);});
open();
{auto p=world.gameplay(0x3f012c,buy(0));check(p.opcode==0x1b9 && p.body==show);}
rejects([&]{world.gameplay(0x3f012c,buy(1));});
check_request(0x410003,deposit,0x283,{255,23});
check_request(0x410003,{0x40,255,50,0,255,50},0x283,{255,38});
check_request(0x410002,{0,63,0},0x282,{255,39});
check_request(0x410002,{0x40,63,23,63,23},0x282,{255,62});
{ // GM .bank: Tortoise names the player itself as the banker.
world.character_bank.reset();rejects([&]{world.gameplay(0x410003,deposit);});
Bytes self_show;le(self_show,world.selected.guid,8);
check(!world.translate({0x1b8,self_show},0x46010046,0,nullptr).empty());
check(world.equipment_bank_open());check_request(0x410003,deposit,0x283,{255,23});
world.character_bank.reset();open();
}
// Both original servers also allow AutoStoreBankItem from a carried slot.
check_request(0x410002,{0,255,35},0x282,{255,23});
for(unsigned i=0;i<10;++i){
const bool bank=i>=4;
const auto index=bank?i-4:i;
const uint8_t native_bag=(bank?64:30)+index;
const uint8_t source_bag=(bank?63:19)+index;
const uint16_t root=bank?F::PLAYER_FIELD_BANKBAG_SLOT_1:F::PLAYER_FIELD_INV_SLOT_HEAD+2*19;
const auto bag=root_item(root+2*index);
auto& container=inventory.items[bag];
container.type=2;
container.fields[F::CONTAINER_FIELD_NUM_SLOTS]=6;
const auto child=++next;
inventory.items[child].type=1;
inventory.items[child].fields[F::ITEM_FIELD_CONTAINED]=bag;
inventory.items[child].fields[F::ITEM_FIELD_OWNER]=world.selected.guid;
container.fields[F::CONTAINER_FIELD_SLOT_1+2*5]=child;
if(bank)check_request(0x410002,{0,native_bag,5},0x282,{source_bag,5});
else check_request(0x410003,{0,0,native_bag,5},0x283,{source_bag,5});
}
++actor.generation;
rejects([&]{world.gameplay(0x410003,deposit);});
open();
world.close_interaction(pack_guid(actor.modern));
rejects([&]{world.gameplay(0x410002,Bytes{0,63,0});});
rejects([&]{world.gameplay(0x3f012c,buy(0));});
open();
world.gameplay_sent(0x3f0029,pack_guid(actor.modern));
rejects([&]{world.gameplay(0x410003,deposit);});
// Source alone changes the inventory after its normal storage checks.
check(inventory.position(63,0).item && inventory.position(255,35).item);
}
static void verify_binder_current_presentation(){
unsigned checks=0;auto expect=[&](bool ok){++checks;if(!ok)throw Error("binder lifecycle assertion");};
const uint64_t id=(0xf130ull<<48)|(123ull<<24)|7;
const auto modern=forever_creature_guid(id,123,70,1);const auto target=pack_guid(modern);
Bytes source;le(source,id,8);Bytes native=target;le(native,20,4);native.push_back(0x80);
Bytes expected;le(expected,1,4);le(expected,0x47031b,4);le(expected,native.size(),4);append(expected,native);
auto fresh=[&]{NativeWorldTranslation q;q.selected.guid=4509;q.realm=70;q.self_created=true;q.location=WorldLocation{1,{}};
auto& a=q.entities.actors[id];a.kind=3;a.sent=true;a.eligible=true;a.generation=7;
a.presentation_realm=70;a.presentation_map=1;a.modern=modern;return q;};
auto offer=[&](NativeWorldTranslation& q){expect(q.translate({0x2eb,source},1,0,nullptr)==expected);
expect(q.binder_offer && q.binder_offer->guid==id && q.binder_offer->generation==7);};
auto reject=[&](auto action){bool threw=false;try{action();}catch(const Error&){threw=true;}
++checks;if(!threw)throw Error("stale binder presentation was admitted");};
auto mutate=[&](NativeWorldTranslation& q,int field){auto& a=q.entities.actors.at(id);
if(field==0)a.presentation_map=2;
if(field==1)a.presentation_realm=71;
if(field==2)a.eligible=false;
if(field==3)a.generation=0;
if(field==4)a.sent=false;
if(field==5)a.kind=4;
if(field==6)q.entities.actors.erase(id);
if(field==7)q.self_created=false;
if(field==8)q.location.reset();
if(field==9)q.logout_complete=true;
if(field==10)q.pending_teleport=NearTeleport{};
if(field==11)q.far_transfer=NativeWorldTranslation::FarTransfer{};
};
for(int field=0;field<12;++field){auto q=fresh();mutate(q,field);
reject([&]{q.translate({0x2eb,source},1,0,nullptr);});expect(!q.binder_offer);}
for(int field=0;field<12;++field){auto q=fresh();offer(q);mutate(q,field);
reject([&]{q.gameplay(0x3f004a,target);});}
{auto q=fresh();offer(q);q.entities.actors.at(id).generation++;
reject([&]{q.gameplay(0x3f004a,target);});}
{auto q=fresh();offer(q);auto p=q.gameplay(0x3f004a,target);
expect(p.opcode==0x1b5 && p.body==source);expect(q.gameplay(0x3f004a,target).body==source);
q.gameplay_sent(0x3f004a,target);expect(!q.binder_offer);reject([&]{q.gameplay(0x3f004a,target);});}
for(size_t n=0;n<=9;++n){if(n==8)continue;auto q=fresh();offer(q);auto bad=source;bad.resize(n);
reject([&]{q.translate({0x2eb,bad},1,0,nullptr);});
expect(q.binder_offer && q.binder_offer->guid==id && q.binder_offer->generation==7);}
std::cout<<"binder current presentation: "<<checks<<" checks PASS\n";
}
int main(){
verify_binder_current_presentation();
verify_character_bank_transfers();
verify_selected_player_create();
NativeWorldTranslation world{};world.selected.guid=4509;world.selected.race=1;world.selected.cls=1;world.realm=70;
auto self=pack_guid(forever_player_guid(4509,70));
rejects([&]{world.gameplay(0x3f00cd,self);});
rejects([&]{world.gameplay(0x3f001f,Bytes{1,0,0,0,0x80});});
rejects([&]{world.gameplay(0x3f00cb,Bytes{0});});world.self_created=true;
for(auto bits:{0u,0x80u}){
auto release=world.gameplay(0x3f00cb,Bytes{uint8_t(bits)});
check(release.opcode==0x15a && release.body.empty() && world.self_created && !world.pending_teleport);
}
for(auto bad:{Bytes{},Bytes{1},Bytes{0x7f},Bytes{0x81},Bytes{0,0}})
rejects([&]{world.gameplay(0x3f00cb,bad);});
{
auto query=world.gameplay(0x44008c,self);check(query.opcode==0x216 && query.body.empty());
rejects([&]{world.gameplay(0x44008c,pack_guid(forever_player_guid(4510,70)));});
rejects([&]{world.gameplay(0x44008c,Bytes{});});
auto corpse_guid=(0xf101ULL<<48)|17;
auto corpse=forever_corpse_guid(corpse_guid,70,1);auto corpse_request=pack_guid(corpse);
rejects([&]{world.gameplay(0x3f0078,corpse_request);});
auto& actor=world.entities.actors[corpse_guid];actor.kind=7;actor.sent=true;actor.modern=corpse;actor.corpse_owner=4509;actor.generation=1;
auto reclaim=world.gameplay(0x3f0078,corpse_request);Bytes source_reclaim;le(source_reclaim,corpse_guid,8);
check(reclaim.opcode==0x1d2 && reclaim.body==source_reclaim && actor.sent); // No optimistic resurrection/removal.
actor.corpse_owner=4510;rejects([&]{world.gameplay(0x3f0078,corpse_request);});actor.corpse_owner=4509;
for(size_t n=0;n<corpse_request.size();++n)rejects([&]{world.gameplay(0x3f0078,std::span(corpse_request).first(n));});
auto tail=corpse_request;tail.push_back(0);rejects([&]{world.gameplay(0x3f0078,tail);});
world.entities.actors.erase(corpse_guid);rejects([&]{world.gameplay(0x3f0078,corpse_request);});
rejects([&]{forever_corpse_guid((0xf130ULL<<48)|17,70,1);});
rejects([&]{forever_corpse_guid(0xf101ULL<<48,70,1);});
for(auto b:{Bytes{},Bytes{2},Bytes{0,0},Bytes{1}})rejects([&]{turtle_corpse_location(b);});
check(!turtle_corpse_location(Bytes{0}).valid);
}
{
NativeWorldTranslation lifecycle;lifecycle.selected.guid=4509;
LegacyObjectUpdate flags;flags.kind=0;flags.guid=4510;flags.fields={{190,16}};
check(!lifecycle.observe_death_updates({flags}));check(lifecycle.requests.empty());
flags.guid=4509;check(!lifecycle.observe_death_updates({flags}));
check(lifecycle.requests.size()==1 && lifecycle.requests.front().opcode==0x216 && lifecycle.requests.front().body.empty());
check(!lifecycle.observe_death_updates({flags}));check(lifecycle.requests.size()==1);
flags.fields={{22,1}};lifecycle.observe_death_updates({flags});check(lifecycle.source_ghost==true && lifecycle.requests.size()==1);
flags.fields={{190,0}};lifecycle.observe_death_updates({flags});check(lifecycle.source_ghost==false);
flags.fields={{190,16}};check(lifecycle.observe_death_updates({flags}));check(lifecycle.requests.size()==2);
check(!lifecycle.observe_death_updates({flags}));check(lifecycle.requests.size()==2);
}
auto action=[&](uint64_t value,uint16_t index){Bytes body;le(body,value,8);le(body,index,2);return body;};
auto bound=world.gameplay(0x440062,action(772,1));check(bound.opcode==0x128 && bound.body==Bytes({1,4,3,0,0}));
check(world.gameplay(0x440062,action((uint64_t(0x80)<<56)|159,119)).body==Bytes({119,159,0,0,128}));
check(world.gameplay(0x440062,action(0,119)).body==Bytes({119,0,0,0,0}));
for(auto index:{120,255,256,359,65535})rejects([&]{world.gameplay(0x440062,action(772,uint16_t(index)));});
for(auto value:{uint64_t(1)<<24,uint64_t(0x40)<<56|1,uint64_t(0x80)<<56})rejects([&]{world.gameplay(0x440062,action(value,1));});
// Journal IDs are accepted only when they resolve to a learned riding spell.
const auto journal_mount = uint64_t(0x60) << 56;
rejects([&]{world.gameplay(0x440062,action(journal_mount|71,24));});
for(const auto& binding : mount_action_spells::Bindings) {
world.spells.insert(binding.spell);
for(uint16_t index : {24,47}) {
const auto saved=world.gameplay(0x440062,action(journal_mount|binding.mount,index));
Bytes expected; le(expected,index,1); le(expected,binding.spell,4);
check(saved.opcode==0x128 && saved.body==expected);
Bytes source(120*4);
std::copy(saved.body.begin()+1,saved.body.end(),source.begin()+4*index);
const auto restored=forever_action_buttons(source);
Reader read(restored);
for(unsigned i=0;i<360;++i)check(read.le(8)==(i==index ? binding.spell : 0));
check(read.le(1)==0);read.end();
}
world.spells.erase(binding.spell);
}
rejects([&]{world.gameplay(0x440062,action(journal_mount|0xffffffff,47));});
rejects([&]{world.gameplay(0x440062,action((uint64_t(0x50)<<56)|71,47));});
auto valid_action=action(772,1);for(size_t n=0;n<valid_action.size();++n)rejects([&]{world.gameplay(0x440062,Bytes(valid_action.begin(),valid_action.begin()+n));});
valid_action.push_back(0);rejects([&]{world.gameplay(0x440062,valid_action);});
auto sit=world.gameplay(0x3e0036,Bytes{1});check(sit.opcode==0x101 && sit.body==Bytes({1,0,0,0}));
for(auto bad:{Bytes{},Bytes{2},Bytes{9},Bytes{1,0}})rejects([&]{world.gameplay(0x3e0036,bad);});
rejects([&]{world.gameplay(0x3e0155,Bytes{});});
auto& rider=world.auras.units[4509];
rider.spells[0]=36651;
rejects([&]{world.gameplay(0x3e0155,Bytes{});}); // Holder alone is not a mounted unit.
rider.mount_display=1;
rider.spells[1]=433; // Unrelated visible aura.
for(uint32_t spell:{30174u,36651u,46210u}){
rider.spells[0]=spell;
auto dismount=world.gameplay(0x3e0155,Bytes{});
Bytes expected;le(expected,spell,4);
check(dismount.opcode==0x136 && dismount.body==expected && rider.spells[0]==spell);
}
rejects([&]{world.gameplay(0x3e0155,Bytes{0});});
rider.spells[1]=36651;
rejects([&]{world.gameplay(0x3e0155,Bytes{});}); // Two distinct source mount holders.
rider.spells[0]=46499; // Collection item learning spell.
rider.spells[1]=433;
rejects([&]{world.gameplay(0x3e0155,Bytes{});});
world.auras.units.clear();
// Generic source-backed self aura cancellation, not a mount-ID exception.
for(uint32_t spell:{30174u,433u,11551u}){
Bytes request;le(request,spell,4);append(request,pack_guid(Guid128{}));
rejects([&]{world.gameplay(0x3e0061,request);});
world.auras.units[4509].spells[0]=spell;
auto cancel=world.gameplay(0x3e0061,request);Bytes expected;le(expected,spell,4);
check(cancel.opcode==0x136 && cancel.body==expected && world.auras.units[4509].spells[0]==spell);
for(size_t n=0;n<request.size();++n)rejects([&]{world.gameplay(0x3e0061,std::span(request).first(n));});
request.push_back(0);rejects([&]{world.gameplay(0x3e0061,request);});
Bytes self_cast;le(self_cast,spell,4);append(self_cast,self);
check(world.gameplay(0x3e0061,self_cast).body==expected);
Bytes foreign;le(foreign,spell,4);append(foreign,pack_guid(forever_player_guid(4510,70)));
rejects([&]{world.gameplay(0x3e0061,foreign);});
world.auras.units.clear();
}
// AuctionRemove is a distinct native opcode and cannot cancel an aura.
{Bytes request;le(request,433,4);append(request,pack_guid(Guid128{}));
rejects([&]{world.gameplay(0x3e0061,request);});}
// Genuine native sheath request preserves all Turtle states and ignores
// only the native Animate bit, as the original server handler does.
// Request serialization must never invent an incoming state change.
for(unsigned state=0;state<3;++state)for(auto animate:{0u,0x80u}){
Bytes request;le(request,state,4);le(request,animate,1);
auto sheath=world.gameplay(0x3f001f,request);Bytes expected;le(expected,state,4);
check(sheath.opcode==0x1e0 && sheath.body==expected && !world.pending_cast && world.auras.units.empty());
}
const Bytes sheath_request{1,0,0,0,0x80};
world.gameplay_sent(0x3f001f,sheath_request);
check(!world.pending_cast && world.auras.units.empty());
for(size_t n=0;n<sheath_request.size();++n)rejects([&]{world.gameplay(0x3f001f,Bytes(sheath_request.begin(),sheath_request.begin()+n));});
auto sheath_tail=sheath_request;sheath_tail.push_back(0);rejects([&]{world.gameplay(0x3f001f,sheath_tail);});
for(auto state:{3u,255u,0x80000000u,0xffffffffu}){
Bytes invalid;le(invalid,state,4);le(invalid,0x80,1);rejects([&]{world.gameplay(0x3f001f,invalid);});
}
for(auto animate:{1u,0x7fu,0x81u,0xffu}){
auto invalid=sheath_request;invalid.back()=uint8_t(animate);rejects([&]{world.gameplay(0x3f001f,invalid);});
}
auto stand_ack=world.translate({0x29d,Bytes{1}},0x46010046,0,nullptr);Reader stance(stand_ack);
check(stance.le(4)==1 && stance.le(4)==0x4701c9 && stance.le(4)==5 && stance.take(5)==Bytes({1,0,0,0,0}));stance.end();
constexpr uint64_t guid=(0xf130ULL<<48)|(9010ULL<<24)|99;
auto modern=forever_creature_guid(guid,9010,70,0);auto target=pack_guid(modern);
NativeEntityTranslation::Actor actor;actor.entry=9010;actor.kind=3;actor.modern=modern;actor.sent=true;
world.entities.actors[guid]=actor;
Bytes raw;le(raw,guid,8);
for(auto [opcode,legacy]:{std::pair{0x3f00cdu,0x13du},{0x3f0029u,0x17bu},{0x3f0038u,0x19eu},{0x3e011eu,0x141u}}){
auto out=world.gameplay(opcode,target);check(out.opcode==legacy && out.body==raw);
}
check(world.gameplay(0x3e011f,{}).opcode==0x142);
// Turtle shop helpers (Field Repair Bot 75B, Mechanical Auctioneer, portable bank) are Source mini-pets (0xF140).
{
constexpr uint64_t helper=(0xf140ULL<<48)|(50041ULL<<24)|32;
const auto helper_modern=forever_pet_guid(helper,50041,70,0);
NativeEntityTranslation::Actor pet;pet.entry=50041;pet.kind=3;pet.modern=helper_modern;pet.sent=true;
world.entities.actors[helper]=pet;
Bytes helper_raw;le(helper_raw,helper,8);
for(auto [opcode,legacy]:{std::pair{0x3f0029u,0x17bu},{0x3f0038u,0x19eu},{0x3f0061u,0x255u}}){
auto out=world.gameplay(opcode,pack_guid(helper_modern));check(out.opcode==legacy && out.body==helper_raw);
}
Bytes bank=pack_guid(helper_modern);le(bank,67,4);
auto opened=world.gameplay(0x3f004b,bank);check(opened.opcode==0x1b7 && opened.body==helper_raw);
world.entities.actors.erase(helper);
}
auto single=[&](uint16_t opcode,const Bytes& packet,uint32_t modern_opcode,const Bytes& expected){
auto bundle=world.translate({opcode,packet},0x46010046,0,nullptr);Reader r(bundle);
check(r.le(4)==1 && r.le(4)==modern_opcode);auto n=r.le(4);check(r.take(n)==expected);r.end();
};
// Raid Info: empty request; known classic raid locks with native difficulty, custom maps not shown.
{
auto request=world.gameplay(0x4400f9,{});check(request.opcode==0x2cd && request.body.empty());
Bytes locks;le(locks,3,4);for(auto [map,reset,id]:{std::tuple{409u,3600u,77u},std::tuple{807u,100u,78u},std::tuple{309u,7200u,79u}}){le(locks,map,4);le(locks,reset,4);le(locks,id,4);}
Bytes expected;le(expected,2,4);
for(auto [map,diff,id,reset]:{std::tuple{409u,9u,77u,3600u},std::tuple{309u,148u,79u,7200u}}){le(expected,map,4);le(expected,diff,2);le(expected,id,8);le(expected,reset,4);le(expected,0,4);le(expected,0x80,1);}
single(0x2cc,locks,0x4700de,expected);
Bytes none;le(none,0,4);Bytes empty;le(empty,0,4);single(0x2cc,none,0x4700de,empty);
}
// /played: native trigger bit is held and echoed; Source request is empty.
{
auto request=world.gameplay(0x3e014e,Bytes{0x80});check(request.opcode==0x1cc && request.body.empty());
Bytes played;le(played,93784,4);le(played,3600,4);auto expected=played;expected.push_back(0x80);
single(0x1cd,played,0x470181,expected);
check(world.gameplay(0x3e014e,Bytes{0}).opcode==0x1cc);expected.back()=0;single(0x1cd,played,0x470181,expected);
rejects([&]{world.gameplay(0x3e014e,Bytes{0x01});});rejects([&]{world.gameplay(0x3e014e,Bytes{});});
}
// QueryTime and ServerTimeOffsetRequest share Source 0x1ce; replies return in request order.
{
check(world.gameplay(0x4400ca,{}).opcode==0x1ce && world.gameplay(0x3f0073,{}).opcode==0x1ce);
Bytes now;le(now,1763700000,4);Bytes expected;le(expected,1763700000,8);
single(0x1cf,now,0x4701c0,expected);single(0x1cf,now,0x47018f,expected);single(0x1cf,now,0x47018f,expected);
rejects([&]{world.gameplay(0x4400ca,Bytes{0});});
// CMSG_TUTORIAL (TC TutorialSetFlag): update bit 29 -> Source 0xFE, clear -> 0xFF, reset -> 0x100.
{auto f=world.gameplay(0x44010c,Bytes{0,29,0,0,0});check(f.opcode==0xfe && f.body==Bytes({29,0,0,0}));
check(world.gameplay(0x44010c,Bytes{0x40}).opcode==0xff && world.gameplay(0x44010c,Bytes{0x80}).opcode==0x100);
rejects([&]{world.gameplay(0x44010c,Bytes{0,0,1,0,0});});rejects([&]{world.gameplay(0x44010c,Bytes{0xc0});});
rejects([&]{world.gameplay(0x44010c,Bytes{0x41});});rejects([&]{world.gameplay(0x44010c,Bytes{0x40,0});});}
}
// Real faction IDs survive source-index to native-index translation.
FactionMappings faction_map;for(auto row:source_factions::Mappings)faction_map.emplace(row.source_index,FactionMapping{row.id,row.index,0,0});
auto wardens=std::find_if(faction_map.begin(),faction_map.end(),[](auto& r){return r.second.id==1007;});check(wardens!=faction_map.end());
Bytes reputation;le(reputation,64,4);for(unsigned i=0;i<69;++i){le(reputation,i==wardens->first?17:0,1);le(reputation,i==wardens->first?42000:0,4);}
auto initial_states=turtle_initial_reputation(reputation);
single(0x122,reputation,0x4701cf,forever_initial_reputation(initial_states,faction_map));
check(world.reputation_values.at(wardens->first)==42000);
Bytes standing;le(standing,1,4);le(standing,wardens->first,4);le(standing,42100,4);
Bytes standing_expected;le(standing_expected,0,4);le(standing_expected,1,4);le(standing_expected,wardens->second.index,4);le(standing_expected,100,4);le(standing_expected,42100,4);le(standing_expected,0,4);standing_expected.push_back(0);
single(0x124,standing,0x4701d7,standing_expected);check(world.reputation_values.at(wardens->first)==42100);
Bytes visible;le(visible,wardens->first,4);Bytes visible_expected;le(visible_expected,wardens->second.index,4);
single(0x123,visible,0x4701d5,visible_expected);
// SET_FACTION_ATWAR: u32 repListID + u8 flag -> native u32 index + u16 flags (bit 0x2 = at war).
for(uint8_t flag:{uint8_t(2),uint8_t(0)}){Bytes atwar;le(atwar,wardens->first,4);atwar.push_back(flag);
Bytes atwar_expected;le(atwar_expected,wardens->second.index,4);le(atwar_expected,flag,2);single(0x313,atwar,0x4701ab,atwar_expected);}
{Bytes odd;le(odd,wardens->first,4);odd.push_back(1);{auto b=world.translate({0x313,odd},0x46010046,0,nullptr);check(b.empty()||(b.size()==4&&Reader(b).le(4)==0));}
Bytes unknown;le(unknown,999,4);unknown.push_back(2);{auto b=world.translate({0x313,unknown},0x46010046,0,nullptr);check(b.empty()||(b.size()==4&&Reader(b).le(4)==0));}
Bytes trailing;le(trailing,wardens->first,4);trailing.push_back(2);trailing.push_back(0);rejects([&]{world.translate({0x313,trailing},0x46010046,0,nullptr);});
Bytes truncated;le(truncated,wardens->first,4);rejects([&]{world.translate({0x313,truncated},0x46010046,0,nullptr);});}
auto bad_standing=standing;bad_standing.push_back(0);auto previous=world.reputation_values;
rejects([&]{world.translate({0x124,bad_standing},0x46010046,0,nullptr);});check(world.reputation_values==previous);
auto bad_initial=reputation;bad_initial.pop_back();rejects([&]{world.translate({0x122,bad_initial},0x46010046,0,nullptr);});check(world.reputation_values==previous);
for(auto interaction:{8u,67u}){auto bank=target;le(bank,interaction,4);auto request=world.gameplay(0x3f004b,bank);check(request.opcode==0x1b7 && request.body==raw);}
auto account_bank=target;le(account_bank,68,4);rejects([&]{world.gameplay(0x3f004b,account_bank);});
rejects([&]{world.gameplay(0x3f004b,target);});
auto trailing_bank=target;le(trailing_bank,67,4);trailing_bank.push_back(0);rejects([&]{world.gameplay(0x3f004b,trailing_bank);});
world.location=WorldLocation{0,{}};
world.entities.actors.at(guid).eligible=true;world.entities.actors.at(guid).generation=1;
world.entities.actors.at(guid).presentation_realm=world.realm;world.entities.actors.at(guid).presentation_map=0;
single(0x1b8,raw,0x47031b,forever_interaction_open(modern,67));
rejects([&]{world.gameplay(0x3f0047,target);});
single(0x222,raw,0x47031b,forever_interaction_open(modern,18));
auto heal=world.gameplay(0x3f0047,target);check(heal.opcode==0x21c && heal.body==raw);
check(world.gameplay(0x3f0047,target).body==raw); // Capacity retries are pure.
for(size_t n=0;n<target.size();++n)rejects([&]{world.gameplay(0x3f0047,std::span(target).first(n));});
auto healer_tail=target;healer_tail.push_back(0);rejects([&]{world.gameplay(0x3f0047,healer_tail);});
++world.entities.actors.at(guid).generation;
rejects([&]{world.gameplay(0x3f0047,target);});
single(0x222,raw,0x47031b,forever_interaction_open(modern,18));
world.gameplay_sent(0x3f0047,target);rejects([&]{world.gameplay(0x3f0047,target);});
// Innkeeper: Source SMSG_BINDER_CONFIRM opens native Binder (20); only that offer activates 0x1B5.
world.location=WorldLocation{0,{}};world.entities.actors.at(guid).eligible=true;
world.entities.actors.at(guid).presentation_realm=world.realm;world.entities.actors.at(guid).presentation_map=0;
rejects([&]{world.gameplay(0x3f004a,target);});
single(0x2eb,raw,0x47031b,forever_interaction_open(modern,20));
{auto bind=world.gameplay(0x3f004a,target);check(bind.opcode==0x1b5 && bind.body==raw);}
{auto tail=target;tail.push_back(0);rejects([&]{world.gameplay(0x3f004a,tail);});}
world.gameplay_sent(0x3f004a,target);rejects([&]{world.gameplay(0x3f004a,target);});
single(0x2b4,{},0x4701ef,{});
// Guild tabard vendor: Source activate opens GuildTabardVendor(14); requests carry the bound GUID.
single(0x1f2,raw,0x47031b,forever_interaction_open(modern,14));
{auto act=target;le(act,0,4);auto r=world.gameplay(0x3e0188,act);check(r.opcode==0x1f2 && r.body==raw);}
{auto personal=target;le(personal,1,4);rejects([&]{world.gameplay(0x3e0188,personal);});}
{auto save=target;for(uint32_t v:{1u,2u,3u,4u,5u})le(save,v,4);auto r=world.gameplay(0x3e0186,save);
auto expected=raw;for(uint32_t v:{1u,2u,3u,4u,5u})le(expected,v,4);check(r.opcode==0x1f1 && r.body==expected);}
single(0x1f1,Bytes{3,0,0,0},0x530040,Bytes{3,0,0,0});
{auto silent=world.translate({0x1f1,Bytes{5,0,0,0}},0x46010046,0,nullptr);Reader s(silent);check(s.le(4)==0);}
auto unknown_banker=raw;unknown_banker[0]^=0x80;rejects([&]{world.translate({0x1b8,unknown_banker},0x46010046,0,nullptr);});
Bytes periodic;append(periodic,pack_guid(raw));Bytes tickCaster;le(tickCaster,4509,8);append(periodic,pack_guid(tickCaster));le(periodic,772,4);le(periodic,1,4);le(periodic,3,4);le(periodic,46,4);le(periodic,0,4);le(periodic,0,4);le(periodic,0,4);
single(0x24e,periodic,0x690008,forever_periodic_aura_log(*turtle_periodic_aura_log(periodic),world.bindings()));
auto unknownPeriodic=periodic;unknownPeriodic[1]^=1;check(world.translate({0x24e,unknownPeriodic},0x46010046,0,nullptr)==Bytes(4));
Bytes spell_damage;append(spell_damage,pack_guid(raw));Bytes spell_caster;le(spell_caster,4509,8);append(spell_damage,pack_guid(spell_caster));
le(spell_damage,23894,4);le(spell_damage,120,4);le(spell_damage,0,1);le(spell_damage,5,4);le(spell_damage,2,4);
le(spell_damage,0,1);le(spell_damage,0,1);le(spell_damage,3,4);le(spell_damage,2,4);le(spell_damage,0,1);
auto spell_event=turtle_spell_damage_log(spell_damage);check(spell_event && spell_event->original==130);
single(0x250,spell_damage,0x690020,forever_spell_damage_log(*spell_event,world.bindings()));
auto unknown_spell_damage=spell_damage;unknown_spell_damage[1]^=1;
check(world.translate({0x250,unknown_spell_damage},0x46010046,0,nullptr)==Bytes(4));
world.self_created=false;check(world.translate({0x250,spell_damage},0x46010046,0,nullptr)==Bytes(4));world.self_created=true;
{ // #91: damage shield + dispel logs recover their spell from gateway state.
uint64_t npc;{Reader rr(raw);npc=rr.le(8);}
auto known=world.bindings();Bytes shield;le(shield,4509,8);le(shield,npc,8);le(shield,10,4);le(shield,3,4);
check(world.translate({0x24f,shield},0x46010046,0,nullptr)==Bytes(4)); // no shield aura known: dropped
world.auras.units[4509].spells[0]=467; // Thorns (nature, aura 15)
Bytes want=pack_guid(known.at(4509));append(want,pack_guid(known.at(npc)));
for(uint32_t v:{467u,10u,10u,0u,8u,0u})le(want,v,4);le(want,0,1);
single(0x24f,shield,0x69001f,want);
Bytes dlog;append(dlog,pack_guid(raw));append(dlog,[]{Bytes x;le(x,4509,8);return pack_guid(x);}());le(dlog,1,4);le(dlog,8936,4);
check(world.translate({0x27b,dlog},0x46010046,0,nullptr)==Bytes(4)); // no dispel cast seen: dropped
world.dispel_go[4509]={527,std::chrono::steady_clock::now()+std::chrono::seconds(2)};
Bytes dwant;le(dwant,0,1);append(dwant,pack_guid(known.at(npc)));append(dwant,pack_guid(known.at(4509)));
le(dwant,527,4);le(dwant,1,4);le(dwant,8936,4);le(dwant,0,1);
single(0x27b,dlog,0x690007,dwant);
Bytes fail;le(fail,4509,8);le(fail,npc,8);le(fail,8936,4);
Bytes fwant=pack_guid(known.at(4509));append(fwant,pack_guid(known.at(npc)));le(fwant,527,4);le(fwant,1,4);le(fwant,8936,4);
single(0x262,fail,0x69001e,fwant);
}
Bytes attack;le(attack,4509,8);append(attack,raw);
single(0x143,attack,0x4d0017,forever_attack_event(0x143,attack,world.bindings()));
Bytes stop;Bytes self_raw;le(self_raw,4509,8);append(stop,pack_guid(self_raw));append(stop,pack_guid(raw));le(stop,0,4);
single(0x144,stop,0x4d0018,forever_attack_event(0x144,stop,world.bindings()));
Bytes no_victim=pack_guid(self_raw);le(no_victim,0,1);le(no_victim,1,4);
single(0x144,no_victim,0x4d0018,forever_attack_event(0x144,no_victim,world.bindings()));
for(auto opcode:{0x145,0x146,0x148,0x149})single(opcode,{},0x4d0026,forever_attack_error(opcode,{}));
auto melee=[&](uint64_t attacker,uint64_t victim){
Bytes b;le(b,2,4);Bytes id;le(id,attacker,8);append(b,pack_guid(id));id.clear();le(id,victim,8);append(b,pack_guid(id));
le(b,12,4);le(b,0,1);le(b,1,4);append(b,Bytes(12));return b;
};
auto melee_packets=[&](const Bytes& packet,bool player_involved){
const auto basic=forever_melee_damage(turtle_melee_damage(packet),world.bindings());
auto bundle=world.translate({0x14a,packet},0x46010046,0,nullptr);Reader r(bundle);
check(r.le(4)==(player_involved?2u:1u));check(r.le(4)==0x4d002c);auto size=r.le(4);check(r.take(size)==basic);
if(player_involved){Bytes landed;le(landed,0,4);append(landed,basic);check(r.le(4)==0x4d0027);size=r.le(4);check(r.take(size)==landed);}
r.end();check(world.translate({0,{}},0x46010046,0,nullptr)==Bytes(4)); // No cached replay.
};
auto damage=melee(4509,guid);melee_packets(damage,true);melee_packets(melee(guid,4509),true);
constexpr uint64_t other_guid=(0xf130ULL<<48)|(9010ULL<<24)|100;
auto other_actor=actor;other_actor.modern=forever_creature_guid(other_guid,9010,70,0);world.entities.actors[other_guid]=other_actor;
melee_packets(melee(guid,other_guid),false);
world.entities.actors.at(other_guid).sent=false;
check(world.translate({0x14a,melee(4509,other_guid)},0x46010046,0,nullptr)==Bytes(4));
check(world.translate({0x14a,melee(other_guid,4509)},0x46010046,0,nullptr)==Bytes(4));
world.entities.actors.erase(other_guid);
world.self_created=false;check(world.translate({0x14a,damage},0x46010046,0,nullptr)==Bytes(4));world.self_created=true;
for(size_t n=0;n<damage.size();++n)rejects([&]{world.translate({0x14a,Bytes(damage.begin(),damage.begin()+n)},0x46010046,0,nullptr);});
// Tortoise helper plus a two-band weapon: one populated school and one
// default physical component. No item/GUID-specific compatibility rule.
auto two_schools=[&](uint32_t primary,uint32_t secondary,uint32_t absorbed){
Bytes b;le(b,2,4);append(b,pack_guid(self_raw));append(b,pack_guid(raw));le(b,primary+secondary,4);le(b,2,1);
auto total=primary+secondary;
le(b,3,4);le(b,std::bit_cast<uint32_t>(total?float(primary)/float(total):0.0f),4);le(b,primary,4);le(b,absorbed,4);le(b,0,4);
le(b,0,4);le(b,std::bit_cast<uint32_t>(total?float(secondary)/float(total):0.0f),4);le(b,secondary,4);append(b,Bytes(8));
le(b,1,4);append(b,Bytes(12));return turtle_melee_damage(b);
};
check(two_schools(500,0,0).school==8); // Nature only; zero physical omitted.
check(two_schools(500,20,0).school==9); // Real Nature +physical preserved.
check(two_schools(0,0,500).school==8); // Fully absorbed Nature preserved.
check(two_schools(0,0,0).school==9); // No active components: preserve wire identity.
Bytes five;le(five,2,4);append(five,pack_guid(self_raw));append(five,pack_guid(raw));le(five,50,4);le(five,5,1);
for(unsigned school=0;school<5;++school){le(five,school,4);le(five,std::bit_cast<uint32_t>(.2f),4);le(five,10,4);append(five,Bytes(8));}
le(five,1,4);append(five,Bytes(12));check(turtle_melee_damage(five).school==31);
auto oversized=five;oversized[4+pack_guid(self_raw).size()+pack_guid(raw).size()+4]=6;
rejects([&]{turtle_melee_damage(oversized);});
auto bad_stop=stop;bad_stop.back()=1;rejects([&]{world.translate({0x144,bad_stop},0x46010046,0,nullptr);});
rejects([&]{world.translate({0x143,{}},0x46010046,0,nullptr);});
rejects([&]{world.translate({0x14a,Bytes{0}},0x46010046,0,nullptr);});
check(world.gameplay(0x3f00cd,Bytes{0,0}).body==Bytes(8));
rejects([&]{world.gameplay(0x3f0038,self);});rejects([&]{world.gameplay(0x3f0038,Bytes{0,0});});
rejects([&]{world.gameplay(0x3f002b,{});});
auto bad=target;bad.push_back(0);rejects([&]{world.gameplay(0x3f0029,bad);});
world.location=WorldLocation{0,{}};
Bytes menu=raw;le(menu,123,4);le(menu,1,4);le(menu,7,4);le(menu,0,2);cstring(menu,"Real service option");le(menu,0,4);
check(world.translate({0x17d,menu},0x46010046,0,nullptr)==Bytes(4));
auto query=world.requests.back(); check(query.opcode==0x17f && query.body.size()==12);
// No valid greeting in this truncated synthetic response; the selectable service survives.
Bytes no_greeting; le(no_greeting,123,4);
auto gossip=world.translate({0x180,no_greeting},0x46010046,0,nullptr);Reader g(gossip);check(g.le(4)==1 && g.le(4)==0x670018);
auto option=target;le(option,123,4);le(option,7,4);le(option,0,1);
auto selected=world.gameplay(0x3f002b,option);Bytes expected=raw;le(expected,7,4);check(selected.opcode==0x17c && selected.body==expected);
auto stale=option;stale[target.size()]^=1;rejects([&]{world.gameplay(0x3f002b,stale);});
// Shop mini-pet (Field Repair Bot 75B) gossip reply: same menu path as a creature (owner disconnect 2026-11-22).
{
constexpr uint64_t helper=(0xf140ULL<<48)|(50041ULL<<24)|33;
const auto helper_modern=forever_pet_guid(helper,50041,70,0);
NativeEntityTranslation::Actor pet;pet.entry=50041;pet.kind=3;pet.modern=helper_modern;pet.sent=true;
world.entities.actors[helper]=pet;
Bytes helper_raw;le(helper_raw,helper,8);
check(world.gameplay(0x3f0029,pack_guid(helper_modern)).opcode==0x17b);
Bytes pet_menu=helper_raw;le(pet_menu,124,4);le(pet_menu,1,4);le(pet_menu,0,4);le(pet_menu,1,1);le(pet_menu,0,1);cstring(pet_menu,"Repair my gear");le(pet_menu,0,4);
check(world.translate({0x17d,pet_menu},0x46010046,0,nullptr)==Bytes(4) && world.requests.back().opcode==0x17f);
Bytes pet_greeting;le(pet_greeting,124,4);auto shown=world.translate({0x180,pet_greeting},0x46010046,0,nullptr);Reader sg(shown);check(sg.le(4)==1 && sg.le(4)==0x670018);
auto pet_option=pack_guid(helper_modern);le(pet_option,124,4);le(pet_option,0,4);le(pet_option,0,1);
Bytes pet_pick=helper_raw;le(pet_pick,0,4);auto pick=world.gameplay(0x3f002b,pet_option);check(pick.opcode==0x17c && pick.body==pet_pick);
// Its shop window (vendor list + repair) comes from the same mini-pet GUID.
Bytes pet_vendor=helper_raw;le(pet_vendor,0,1);le(pet_vendor,0,1);
check(!world.translate({0x19f,pet_vendor},0x46010046,0,nullptr).empty());
// Mechanical Auctioneer / bank carrier replies from mini-pets.
Bytes pet_house=helper_raw;le(pet_house,7,4);
check(!world.translate({0x255,pet_house},0x46010046,0,nullptr).empty());
auto& bank_pet=world.entities.actors.at(helper);bank_pet.eligible=true;bank_pet.generation=1;
bank_pet.presentation_realm=world.realm;bank_pet.presentation_map=world.location->map;
check(!world.translate({0x1b8,helper_raw},0x46010046,0,nullptr).empty());
world.entities.actors.erase(helper);
}
// Genuine class trainer services retain service/wrapper IDs, source price,
// requirements and internal native context1; server decides actual learning.
Bytes trainer=raw;le(trainer,0,4);le(trainer,1,4);le(trainer,1234,4);le(trainer,0,1);le(trainer,71,4);le(trainer,0,8);le(trainer,14,1);le(trainer,26,4);le(trainer,5,4);le(trainer,78,4);le(trainer,0,8);cstring(trainer,"Real trainer greeting");
auto offers=turtle_trainer_list(trainer);check(offers.spells.size()==1 && offers.spells[0].cost==71 && offers.spells[0].requirements[0]==78);
auto training=world.translate({0x1b1,trainer},0x46010046,0,nullptr);Reader tr(training);check(tr.le(4)==2 && tr.le(4)==0x47031b);auto trn=tr.le(4);check(tr.take(trn)==forever_interaction_open(modern,7));check(tr.le(4)==0x47018a);trn=tr.le(4);check(tr.take(trn)==forever_trainer_list(offers,modern));tr.end();
auto refreshed=world.translate({0x1b1,trainer},0x46010046,0,nullptr);Reader refresh(refreshed);check(refresh.le(4)==1 && refresh.le(4)==0x47018a); // No repeated interaction-open/request loop.
auto train=target;le(train,1,4);le(train,1234,4);auto teach=world.gameplay(0x3f0046,train);auto lesson=raw;le(lesson,1234,4);check(teach.opcode==0x1b2 && teach.body==lesson);
check(world.gameplay(0x3f0045,target).opcode==0x1b0);
auto badtrain=train;badtrain.back()=1;rejects([&]{world.gameplay(0x3f0046,badtrain);});badtrain=train;badtrain[target.size()]=2;rejects([&]{world.gameplay(0x3f0046,badtrain);});
for(size_t n=0;n<train.size();++n)rejects([&]{world.gameplay(0x3f0046,Bytes(train.begin(),train.begin()+n));});
auto failure_wire=lesson;le(failure_wire,1,4);auto failure_body=target;le(failure_body,1234,4);le(failure_body,1,4);single(0x1b4,failure_wire,0x47018b,failure_body);
Bytes learned;le(learned,1234,4);single(0x12b,learned,0x690040,forever_spell_learning(0x12b,learned));check(world.spells.contains(1234));
Bytes replaced;le(replaced,1234,2);le(replaced,1235,2);single(0x12c,replaced,0x69003f,forever_spell_learning(0x12c,replaced));check(!world.spells.contains(1234) && world.spells.contains(1235));
Bytes removed;le(removed,1235,2);single(0x203,removed,0x690041,forever_spell_learning(0x203,removed));check(!world.spells.contains(1235));
for(size_t n=0;n<trainer.size();++n)rejects([&]{turtle_trainer_list(std::span(trainer).first(n));});
auto mount_trainer=trainer;mount_trainer[8]=1;check(world.translate({0x1b1,mount_trainer},0x46010046,0,nullptr)==Bytes(4) && !world.trainer);rejects([&]{world.gameplay(0x3f0046,train);});
Bytes inventory=raw;le(inventory,1,1);for(auto v:{1u,25u,1542u,0xffffffffu,20u,0u,1u})le(inventory,v,4);
auto vendor=world.translate({0x19f,inventory},0x46010046,0,nullptr);Reader v(vendor);
check(v.le(4)==2 && v.le(4)==0x47031b);auto n=v.le(4);check(v.take(n)==forever_interaction_open(modern,5));
check(v.le(4)==0x47005c);n=v.le(4);check(v.take(n)==forever_vendor_inventory(turtle_vendor_inventory(inventory),modern));v.end();
auto repeated=world.translate({0x19f,inventory},0x46010046,0,nullptr);Reader repeat(repeated);check(repeat.le(4)==1 && repeat.le(4)==0x47005c);
// Bundle quantities are genuinely different: native units vs Turtle
// vendor purchase bundles. Validate against authenticated offer ID + slot.
world.vendor_inventory->items[0].stack=5;
auto buy_request=[&](uint32_t quantity,uint32_t slot,const Bytes& container){auto b=target;append(b,container);le(b,25,4);append(b,Bytes{0,0});le(b,quantity,4);le(b,1,4);le(b,slot,4);le(b,1,4);return b;};
auto purchase=world.gameplay(0x3f003b,buy_request(5,0,Bytes{0,0}));auto purchase_wire=raw;le(purchase_wire,25,4);append(purchase_wire,Bytes{1,0});check(purchase.opcode==0x1a2 && purchase.body==purchase_wire);
auto stored=world.gameplay(0x3f003b,buy_request(10,35,self));auto stored_wire=raw;le(stored_wire,25,4);le(stored_wire,4509,8);append(stored_wire,Bytes{23,2});check(stored.opcode==0x1a3 && stored.body==stored_wire);
for(auto quantity:{0u,1u,4u,6u,1280u,0xffffffffu})rejects([&]{world.gameplay(0x3f003b,buy_request(quantity,0,Bytes{0,0}));});
auto buy=buy_request(5,0,Bytes{0,0});for(size_t n=0;n<buy.size();++n)rejects([&]{world.gameplay(0x3f003b,Bytes(buy.begin(),buy.begin()+n));});
auto badbuy=buy;badbuy.push_back(0);rejects([&]{world.gameplay(0x3f003b,badbuy);});
badbuy=buy;badbuy.back()=1;rejects([&]{world.gameplay(0x3f003b,badbuy);});
auto entry_offset=target.size()+2;
for(auto offset:{entry_offset,entry_offset+4,entry_offset+5,entry_offset+10}){auto modified=buy;modified[offset]^=1;rejects([&]{world.gameplay(0x3f003b,modified);});}
rejects([&]{world.gameplay(0x3f003b,buy_request(5,29,self));});
rejects([&]{world.gameplay(0x3f003b,buy_request(5,256,self));});
constexpr uint64_t vendor_bag=(0x4000ULL<<48)|22345;
LegacyObjectUpdate bag_record;bag_record.guid=vendor_bag;bag_record.type=2;bag_record.fields[48]=6;world.inventory.items[vendor_bag]=bag_record;
world.inventory.player_fields[524]=uint32_t(vendor_bag);world.inventory.player_fields[525]=uint32_t(vendor_bag>>32);
auto vendor_bag_guid=pack_guid(world.inventory.owned_bindings().at(vendor_bag));
auto bag_buy=world.gameplay(0x3f003b,buy_request(10,2,vendor_bag_guid));auto bag_wire=raw;le(bag_wire,25,4);le(bag_wire,vendor_bag,8);append(bag_wire,Bytes{2,2});check(bag_buy.opcode==0x1a3 && bag_buy.body==bag_wire);
rejects([&]{world.gameplay(0x3f003b,buy_request(5,6,vendor_bag_guid));});
world.inventory.player_fields[524]=0;world.inventory.player_fields[525]=0;rejects([&]{world.gameplay(0x3f003b,buy_request(5,2,vendor_bag_guid));});world.inventory.items.erase(vendor_bag);
auto buy_context=world.merchant;world.merchant.reset();rejects([&]{world.gameplay(0x3f003b,buy);});world.merchant=buy_context;
auto duplicate=world.vendor_inventory->items[0];duplicate.slot=2;world.vendor_inventory->items.push_back(duplicate);rejects([&]{world.gameplay(0x3f003b,buy);});world.vendor_inventory->items.pop_back();
Bytes buy_success=raw;le(buy_success,1,4);le(buy_success,0xffffffff,4);le(buy_success,3,4);
auto success_body=target;le(success_body,1,4);le(success_body,0xffffffff,4);le(success_body,15,4);single(0x1a4,buy_success,0x470172,success_body);
for(auto reason:{0u,1u,2u,4u,5u,7u,8u,11u,12u}){auto source=raw;le(source,25,4);le(source,reason,1);auto dest=target;le(dest,25,4);le(dest,reason,4);single(0x1a5,source,0x470173,dest);}
auto badreason=raw;le(badreason,25,4);le(badreason,3,1);rejects([&]{world.translate({0x1a5,badreason},0x46010046,0,nullptr);});
constexpr uint64_t owned_id=(0x4000ULL<<48)|12345;
LegacyObjectUpdate owned_item;owned_item.guid=owned_id;owned_item.type=1;world.inventory.items[owned_id]=owned_item;
auto owned_modern=world.inventory.owned_bindings().at(owned_id);
auto sell=target;append(sell,pack_guid(owned_modern));le(sell,1,4);
auto sale=world.gameplay(0x3f0039,sell);Bytes sale_wire=raw;le(sale_wire,owned_id,8);le(sale_wire,1,1);check(sale.opcode==0x1a0 && sale.body==sale_wire);
auto sell_all=sell;std::fill(sell_all.end()-4,sell_all.end(),0);check(world.gameplay(0x3f0039,sell_all).body.back()==0);
auto overflow=sell;overflow[overflow.size()-4]=0;overflow[overflow.size()-3]=1;rejects([&]{world.gameplay(0x3f0039,overflow);});
auto trailing=sell;trailing.push_back(0);rejects([&]{world.gameplay(0x3f0039,trailing);});
auto context=world.merchant;world.merchant.reset();rejects([&]{world.gameplay(0x3f0039,sell);});world.merchant=context;
// Slot identity comes from genuine player buyback fields + owned objects,
// not a trusted UI index. Native72..83 maps to Turtle69..80.
world.inventory.player_fields[624]=uint32_t(owned_id);world.inventory.player_fields[625]=uint32_t(owned_id>>32);
auto buyback=target;le(buyback,72,4);Bytes bought=raw;le(bought,69,4);
auto repurchase=world.gameplay(0x3f003c,buyback);check(repurchase.opcode==0x290 && repurchase.body==bought);
for(auto slot:{69u,71u,73u,84u,0xffffffffu}){auto bad=target;le(bad,slot,4);rejects([&]{world.gameplay(0x3f003c,bad);});}
auto extra=buyback;extra.push_back(0);rejects([&]{world.gameplay(0x3f003c,extra);});
for(size_t n=0;n<buyback.size();++n)rejects([&]{world.gameplay(0x3f003c,Bytes(buyback.begin(),buyback.begin()+n));});
world.merchant.reset();rejects([&]{world.gameplay(0x3f003c,buyback);});world.merchant=context;
world.inventory.player_fields[624]=0;world.inventory.player_fields[625]=0;rejects([&]{world.gameplay(0x3f003c,buyback);});
Bytes sell_error=raw;le(sell_error,owned_id,8);le(sell_error,2,1);
auto response=target;le(response,1,4);le(response,2,4);append(response,pack_guid(owned_modern));single(0x1a1,sell_error,0x470171,response);
auto unknown_error=sell_error;unknown_error.back()=7;rejects([&]{world.translate({0x1a1,unknown_error},0x46010046,0,nullptr);});
world.inventory.items.erase(owned_id);rejects([&]{world.gameplay(0x3f0039,sell);});check(world.translate({0x1a1,sell_error},0x46010046,0,nullptr)==Bytes(4));
world.entities.actors.erase(guid);
check(world.translate({0x250,spell_damage},0x46010046,0,nullptr)==Bytes(4));
check(world.translate({0x143,attack},0x46010046,0,nullptr)==Bytes(4));
check(world.translate({0x144,stop},0x46010046,0,nullptr)==Bytes(4));
check(world.translate({0x14a,damage},0x46010046,0,nullptr)==Bytes(4));
rejects([&]{world.gameplay(0x3f0038,target);});rejects([&]{world.gameplay(0x3f002b,option);});
rejects([&]{world.translate({0x19f,inventory},0x46010046,0,nullptr);});
world.translate({0x17e,{}},0x46010046,0,nullptr);check(!world.gossip);
uint32_t required=99;check(gw_native_transport_gameplay(nullptr,0x3f00cd,nullptr,0,nullptr,0,&required)==-1 && !required);
return EXIT_SUCCESS;
}