60 lines
4.6 KiB
C++
60 lines
4.6 KiB
C++
// Synthetic: Source 0x26F for a visible stablemaster queries real creature templates, publishes
|
|
// one mode-76 K1 snapshot, routes SetPetSlot to Source, refreshes after success, and closes with K2.
|
|
#include "world_translation.hpp"
|
|
#include <algorithm>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
static void expect(bool ok,const char* what){if(!ok)throw Error(what);}
|
|
static int fake_codec(uint32_t mode,const uint8_t* in,uint32_t size,uint32_t,uint8_t* out,uint32_t capacity,uint32_t* written){
|
|
if(mode!=GW_CODEC_PET_STABLE)return GW_CODEC_PACKET;
|
|
*written=size;if(capacity<size)return GW_CODEC_CAPACITY;std::copy(in,in+size,out);return GW_CODEC_OK;
|
|
}
|
|
static std::vector<std::pair<uint32_t,Bytes>> unbundle(const Bytes& bundle){
|
|
std::vector<std::pair<uint32_t,Bytes>> out;Reader r(bundle);auto n=r.le(4);
|
|
for(uint64_t i=0;i<n;++i){auto op=uint32_t(r.le(4));auto size=r.le(4);auto body=r.take(size);out.emplace_back(op,Bytes(body.begin(),body.end()));}
|
|
return out;
|
|
}
|
|
int main(){try{
|
|
NativeWorldTranslation w{};w.realm=70;w.selected.guid=4509;w.selected.race=1;w.selected.name="Hunter";
|
|
w.self_created=true;w.location=WorldLocation{0,{0,0,0,0}};w.virtual_realm_address=0x10046;
|
|
const uint64_t npc=(0xf130ULL<<48)|(9010ULL<<24)|0x77;
|
|
auto modern=forever_creature_guid(npc,9010,70,0);
|
|
NativeEntityTranslation::Actor actor;actor.entry=9010;actor.kind=3;actor.modern=modern;actor.sent=true;w.entities.actors[npc]=actor;
|
|
// Open request: native RequestStabledPets -> Source 0x26F {npc}.
|
|
auto open=w.gameplay(0x3f0028,pack_guid(modern));
|
|
expect(open.opcode==0x26f,"stable list request");{Reader r(open.body);expect(r.le(8)==npc,"npc");r.end();}
|
|
// Source list: one current + one stabled pet, templates unknown -> queries, nothing published.
|
|
Bytes list;le(list,npc,8);le(list,2,1);le(list,2,1);
|
|
for(auto [n,e,k]:{std::tuple{11u,3000u,1u},std::tuple{12u,3001u,2u}}){le(list,n,4);le(list,e,4);le(list,10,4);list.push_back('P');list.push_back(0);le(list,3,4);le(list,k,1);}
|
|
auto first=unbundle(w.translate({0x26f,list},0x10046,0,fake_codec));
|
|
expect(std::none_of(first.begin(),first.end(),[](auto& p){return p.first==0x5e0000;}),"wait for displays");
|
|
expect(w.entities.queries.contains(3000) && w.entities.queries.contains(3001),"real creature queries");
|
|
for(uint32_t e:{3000u,3001u}){CreatureTemplateReply t;t.entry=e;t.found=true;t.display=e+7;w.entities.templates[e]=t;w.entities.queries.erase(e);}
|
|
auto second=unbundle(w.translate({0x1d1,Bytes(8,0)},0x10046,0,fake_codec));
|
|
auto k1=std::find_if(second.begin(),second.end(),[](auto& p){return p.first==0x5e0000;});
|
|
expect(k1!=second.end(),"K1 published");
|
|
auto dto=pet_stable_from_input(k1->second);
|
|
expect(dto.kind==1 && dto.list.npc==npc && dto.displays[0]==3007 && dto.displays[1]==3008 && dto.list.pets[1].number==12,"K1 contents");
|
|
auto third=unbundle(w.translate({0x1d1,Bytes(8,0)},0x10046,0,fake_codec));
|
|
expect(std::none_of(third.begin(),third.end(),[](auto& p){return p.first==0x5e0000;}),"published once");
|
|
// SetPetSlot(12 -> 0) with a current pet = Source SWAP 0x275 {npc, 12}.
|
|
Bytes set;le(set,12,4);le(set,0,1);append(set,pack_guid(modern));
|
|
auto swap=w.gameplay(0x3e0012,set);expect(swap.opcode==0x275,"swap");
|
|
{Reader r(swap.body);expect(r.le(8)==npc && r.le(4)==12,"swap body");r.end();}
|
|
// A stable-to-stable move or a foreign stablemaster is refused.
|
|
{Bytes bad;le(bad,12,4);le(bad,2,1);append(bad,pack_guid(modern));bool r=false;try{w.gameplay(0x3e0012,bad);}catch(const Error&){r=true;}expect(r,"stable-to-stable refused");}
|
|
// Source success 9 -> native result and a fresh 0x26F request.
|
|
w.requests.clear();
|
|
w.translate({0x273,Bytes{9}},0x10046,0,fake_codec);
|
|
expect(std::any_of(w.requests.begin(),w.requests.end(),[](auto& p){return p.opcode==0x26f;}),"roster refresh after success");
|
|
// Close interaction on the stablemaster -> K2.
|
|
auto closed=w.close_interaction(pack_guid(modern));
|
|
expect(closed && pet_stable_from_input(*closed).kind==2 && !w.stable,"K2 on close");
|
|
expect(!w.close_interaction(pack_guid(modern)),"nothing to close twice");
|
|
// Inconsistent Source list (over capacity) holds, publishes nothing.
|
|
NativeWorldTranslation h=w;Bytes over;le(over,npc,8);le(over,2,1);le(over,0,1);
|
|
for(uint32_t n:{21u,22u}){le(over,n,4);le(over,3000,4);le(over,10,4);over.push_back(0);le(over,3,4);le(over,2,1);}
|
|
h.translate({0x26f,over},0x10046,0,fake_codec);expect(!h.stable && h.stable_holds==1,"over capacity held");
|
|
std::cout<<"PASS pet stable pipeline (open, displays, K1 once, swap, refresh, K2, holds)\n";return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|