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

77 lines
5.3 KiB
C++

// SPDX-License-Identifier: GPL-2.0-or-later
#include "world_translation.hpp"
#include "gateway/turtle_entity_profile.hpp"
#include "gateway/quest_log.hpp"
#include <iostream>
using namespace gateway;
namespace F=gateway::turtle_entity_fields;
static void check(bool ok,const char* why){if(!ok)throw Error(why);}
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);}
const auto n=fields.rbegin()->first/32+1;le(b,n,1);std::vector<uint32_t> masks(n);
for(auto [i,v]:fields){(void)v;masks[i/32]|=1u<<(i%32);}for(auto mask:masks)le(b,mask,4);for(auto [i,v]:fields){(void)i;le(b,v,4);}return {0xa9,b};
}
static void pair(std::map<uint16_t,uint32_t>& fields,unsigned index,uint64_t value){fields[index]=uint32_t(value);fields[index+1]=uint32_t(value>>32);}
static Bytes definition(uint32_t id,uint32_t object=0,int storage=-1){
Bytes b;le(b,id,4);for(auto n:{2,9,12,0,0,0,0,0,0,0,0,0,0,0})le(b,n,4);
for(unsigned i=0;i<24;++i)le(b,0,4);
for(auto s:{"Fixture","Objectives","Details",""})cstring(b,s);
for(int i=0;i<4;++i){le(b,storage==i?object:0,4);le(b,storage==i?8:0,4);le(b,storage==i+4?object:0,4);le(b,storage==i+4?8:0,4);}
for(unsigned i=0;i<4;++i)cstring(b,"");return b;
}
static std::vector<QuestLogWireUpdate> updates;
static int codec(uint32_t mode,const uint8_t* input,uint32_t size,uint32_t,uint8_t* out,uint32_t cap,uint32_t* needed){
*needed=6;if(cap<6)return GW_CODEC_CAPACITY;
if(mode==GW_CODEC_QUEST_LOG_VALUES)updates.push_back(parse_quest_log_update_input(std::span(input,size)));
std::fill(out,out+6,0);return GW_CODEC_OK;
}
int main(){try{
constexpr uint64_t self=4528,item=0x40000000000f4353ULL;
for(int storage=4;storage<8;++storage){
NativeWorldTranslation w;w.selected.guid=self;w.realm=70;w.location=WorldLocation{};w.self_created=true;
w.entities.self_presentation_ready=true;
(void)w.entities.self_quest_log.observe({{198,7}},true);
auto send=[&](const LegacyPacket& p){updates.clear();w.translate(p,0x46010046,0,codec);};
// Native client cache may suppress QUERY_QUEST_INFO; the gateway still
// needs genuine source metadata to map item entries to objective storage.
send(update(self,4,0,{{198,7}}));
auto queries=[&](){return std::count_if(w.requests.begin(),w.requests.end(),[](const auto& p){return p.opcode==0x05c;});};
check(queries()==1,"active quest missing source definition was not queried");
send(update(self,4,0,{{198,7}}));
check(queries()==1,"pending active quest definition query duplicated");
auto malformed=definition(7,789,storage);malformed.pop_back();
send({0x05d,malformed});
check(!w.quests.definitions.contains(7)&&queries()==1,"malformed definition accepted or retried");
std::map<uint16_t,uint32_t> fields{{F::OBJECT_FIELD_ENTRY,789},{F::ITEM_FIELD_STACK_COUNT,1}};
pair(fields,F::ITEM_FIELD_OWNER,self);pair(fields,F::ITEM_FIELD_CONTAINED,self);
send(update(item,1,2,fields));check(updates.empty(),"unreferenced item counted");
std::map<uint16_t,uint32_t> slot;pair(slot,F::PLAYER_FIELD_PACK_SLOT_1,item);
send(update(self,4,0,slot));
check(updates.empty(),"missing definition invented item objective");
send({0x05d,definition(7,789,storage)});
check(!updates.empty()&&updates.back().projection.slots.at(0).item_counters[storage-4]==1,"late definition did not reconcile pickup");
check(w.quest_item_waiting_definitions.empty(),"valid definition did not retire pending query");
send(update(item,1,0,{{F::ITEM_FIELD_STACK_COUNT,8}}));
check(!updates.empty()&&updates.back().projection.slots.at(0).item_counters[storage-4]==8,"stack increase did not complete objective");
send(update(item,1,0,{{F::ITEM_FIELD_STACK_COUNT,99}}));
check(updates.empty(),"excess inventory changed already capped objective");
Bytes notice;le(notice,789,4);le(notice,1000,4);send({0x19a,notice});
check(updates.empty(),"item-credit notice invented inventory progress");
send(update(item,1,0,{{F::ITEM_FIELD_STACK_COUNT,0}}));
check(!updates.empty()&&updates.back().projection.slots.at(0).item_counters[storage-4]==0,"empty stack did not clear objective");
// A different active quest is queried once and abandoned work is retired.
send(update(self,4,0,{{201,9}}));check(queries()==2,"new active quest not queried");
send(update(self,4,0,{{201,0}}));check(!w.quest_item_waiting_definitions.contains(9),"abandoned quest retained pending marker");
send(update(self,4,0,{{201,9}}));check(queries()==3,"reaccepted missing quest not queried");
w.requests.clear();w.requests.resize(4096,{0x05c,Bytes{1,0,0,0}});
send(update(self,4,0,{{204,11}}));
check(w.requests.size()==4096&&!w.quest_item_waiting_definitions.contains(11),"full queue admitted or marked unsent query");
w.requests.clear();send(update(self,4,0,{{204,11}}));
check(queries()==1&&w.quest_item_waiting_definitions.contains(11),"available queue did not retry unsent query");
send({0x4d,{}});check(w.quest_item_waiting_definitions.empty(),"logout retained pending marker");
}
std::cout<<"Quest item world progress PASS\n";
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}