883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
51 lines
4.3 KiB
C++
51 lines
4.3 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#include "world_translation.hpp"
|
|
#include "gateway/turtle_entity_profile.hpp"
|
|
#include <iostream>
|
|
#include <source_location>
|
|
using namespace gateway;
|
|
namespace F=gateway::turtle_entity_fields;
|
|
static void check(bool ok,const std::source_location where=std::source_location::current()){
|
|
if(!ok)throw Error("starter inventory fixture 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);}
|
|
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);}
|
|
int main(){try{
|
|
constexpr uint64_t self=4528,item=0x40000000000f4353ULL,bag=0x40000000000f4354ULL;
|
|
NativeWorldTranslation w;w.selected.guid=self;w.realm=70;w.location=WorldLocation{};w.self_created=true;
|
|
auto codec=[](uint32_t,const Bytes&){return Bytes(6);};
|
|
auto send=[&](LegacyPacket packet){(void)w.inventory.translate(packet,self,70,0,false,codec);};
|
|
std::map<uint16_t,uint32_t> fields{{F::OBJECT_FIELD_ENTRY,6775},{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(w.inventory.item_generations.contains(item));
|
|
const auto first=w.inventory.item_generations.at(item);
|
|
std::map<uint16_t,uint32_t> slot;pair(slot,F::PLAYER_FIELD_PACK_SLOT_1,item);send(update(self,4,0,slot));
|
|
check(!w.quest_bindings().contains(item)); // Genuine Source template still required.
|
|
ItemTemplateReply meta;meta.entry=6775;meta.found=true;meta.start_quest=1642;w.inventory.templates[6775]=meta;
|
|
auto live=w.quest_bindings();check(live.contains(item)&&live.at(item).kind==1&&!live.at(item).questgiver&&live.at(item).start_quest==1642&&live.at(item).generation==first);
|
|
auto query=pack_guid(live.at(item).modern);le(query,1642,4);le(query,0,1);
|
|
auto request=w.quests.client(0x3f002e,query,live);check(request.packets.size()==1&&request.packets[0].opcode==0x186);
|
|
// A cached owned item in the bank is not a usable quest giver.
|
|
pair(slot,F::PLAYER_FIELD_PACK_SLOT_1,0);pair(slot,F::PLAYER_FIELD_BANK_SLOT_1,item);send(update(self,4,0,slot));check(!w.quest_bindings().contains(item));
|
|
// An actual equipped carried bag plus its matching contained pointer works.
|
|
auto container=fields;container[F::OBJECT_FIELD_ENTRY]=4496;container[F::CONTAINER_FIELD_NUM_SLOTS]=4;pair(container,F::CONTAINER_FIELD_SLOT_1,item);
|
|
send(update(bag,2,2,container));pair(slot,F::PLAYER_FIELD_BANK_SLOT_1,0);pair(slot,F::PLAYER_FIELD_INV_SLOT_HEAD+2*19,bag);send(update(self,4,0,slot));
|
|
auto contained=fields;pair(contained,F::ITEM_FIELD_CONTAINED,bag);send(update(item,1,0,contained));
|
|
live=w.quest_bindings();check(live.contains(item)&&live.at(item).generation==first&&!live.contains(bag));
|
|
auto wrong=contained;pair(wrong,F::ITEM_FIELD_CONTAINED,self);send(update(item,1,0,wrong));check(!w.quest_bindings().contains(item));
|
|
send(update(item,1,0,contained));check(w.quest_bindings().contains(item));
|
|
// Removal, same-GUID recreation and foreign replacement retire old offers.
|
|
w.quests.detail_offer=NativeQuestTranslation::Offer{item,first,1642,{}};
|
|
Bytes remove;le(remove,item,8);send({0xaa,remove});check(!w.inventory.item_generations.contains(item)&&!w.quest_bindings().contains(item));
|
|
send(update(item,1,2,contained));live=w.quest_bindings();check(live.contains(item)&&live.at(item).generation>first);
|
|
auto stale=w.quests.client(0x3f002f,query,live);check(stale.held&&stale.packets.empty());
|
|
auto foreign=contained;pair(foreign,F::ITEM_FIELD_OWNER,999);send(update(item,1,2,foreign));check(!w.quest_bindings().contains(item));
|
|
w.logout_complete=true;check(w.quest_bindings().empty());
|
|
std::cout<<"Quest starter live Source ownership, bag admission, template and lifecycle integration passed\n";return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|