883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
100 lines
6.9 KiB
C++
100 lines
6.9 KiB
C++
#include "world_translation.hpp"
|
|
#include "inventory_translation.hpp"
|
|
#include "gateway/turtle_entity_profile.hpp"
|
|
#include "gateway/talents.hpp"
|
|
#include "serializer.h"
|
|
#include <iostream>
|
|
#include <source_location>
|
|
#include <cstdlib>
|
|
using namespace gateway;
|
|
static void check(bool ok,std::source_location at=std::source_location::current()){if(!ok)throw Error("equipment visibility assertion line "+std::to_string(at.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 std::map<uint16_t,uint32_t> inventory_fields(const Bytes& input,uint64_t self){
|
|
Reader r(input);check(r.le(8)==self);r.le(2);r.le(4);auto count=r.le(4);
|
|
std::map<uint16_t,uint32_t> out;
|
|
for(unsigned n=0;n<count;++n){
|
|
auto id=r.le(8);r.le(1);r.le(1);auto fields=r.le(2);
|
|
for(unsigned i=0;i<fields;++i){auto key=uint16_t(r.le(2));auto value=uint32_t(r.le(4));if(id==self)out[key]=value;}
|
|
}
|
|
r.end();return out;
|
|
}
|
|
int main(){
|
|
constexpr uint64_t self=42,item=(0x4000ULL<<48)|75,cloak=item+1;
|
|
constexpr uint16_t flags=190,head=260,back=428;
|
|
if(!std::getenv("GW_VISIBILITY_INVENTORY_ONLY")){
|
|
for(auto slot:{0u,14u})for(auto mask:{0u,SourceHideHelm,SourceHideCloak,SourceHideHelm|SourceHideCloak}){
|
|
auto id=forever_visible_item_id(mask,slot,19019);check(id==((mask&visibility_mask(slot))?0u:19019u));
|
|
check(forever_visible_item_id(mask,5,19019)==19019);
|
|
}
|
|
// Reserved grammar preserves existing state/learn/reset and refuses extra data.
|
|
check(turtle_talent_control(".gwtalent state")->visibility==0);
|
|
check(turtle_talent_control(".gwtalent learn 12285 1")->talent==12285);
|
|
check(turtle_talent_control(".gwtalent reset 99")->reset_guid==99);
|
|
for(auto part:{"helm","cloak"})for(auto action:{"on","off","toggle","status"})
|
|
check(turtle_talent_control(std::string(".gwtalent visibility ")+part+" "+action)->visibility!=0);
|
|
for(auto text:{".gwtalent visibility gloves off",".gwtalent visibility helm off trailing",".gwtalent visibility helm"}){
|
|
bool rejected=false;try{turtle_talent_control(text);}catch(const Error&){rejected=true;}check(rejected);
|
|
}
|
|
NativeWorldTranslation world{};world.selected.guid=self;world.realm=70;world.self_created=true;
|
|
world.location=WorldLocation{0,0,0,0,0};
|
|
std::optional<LegacyPacket> outgoing;
|
|
check(world.talent_control(".gwtalent visibility helm off",outgoing) && !outgoing);
|
|
LegacyObjectUpdate create{};create.guid=self;create.kind=3;create.type=4;create.fields={{flags,0}};
|
|
world.entities.observe_equipment_visibility(create,self,70,0);
|
|
auto& state=world.entities.equipment_visibility;
|
|
check(state.bound(self,70,0) && !state.hidden(0));
|
|
check(world.talent_control(".gwtalent visibility helm off",outgoing) && outgoing && outgoing->opcode==0x2b9 && outgoing->body.empty());
|
|
check(!state.pending[0] && !state.hidden(0)); // Preparing/capacity retry is not send.
|
|
world.talent_control_sent(*outgoing);check(state.pending[0] && *state.pending[0] && !state.hidden(0));
|
|
for(auto action:{"off","on","toggle"}){
|
|
check(world.talent_control(std::string(".gwtalent visibility helm ")+action,outgoing) && !outgoing);
|
|
check(state.pending[0] && !state.hidden(0));
|
|
}
|
|
LegacyObjectUpdate ack{};ack.guid=self;ack.kind=0;ack.fields={{flags,1}};
|
|
world.entities.observe_equipment_visibility(ack,self,70,0);check(state.pending[0] && !state.hidden(0));
|
|
ack.fields[flags]=SourceHideHelm|1;world.entities.observe_equipment_visibility(ack,self,70,0);
|
|
check(!state.pending[0] && state.hidden(0));
|
|
check(world.talent_control(".gwtalent visibility helm off",outgoing) && !outgoing);
|
|
check(world.talent_control(".gwtalent visibility helm on",outgoing) && outgoing && outgoing->opcode==0x2b9);
|
|
world.talent_control_sent(*outgoing);ack.fields[flags]=1;world.entities.observe_equipment_visibility(ack,self,70,0);
|
|
check(!state.pending[0] && !state.hidden(0));
|
|
check(world.talent_control(".gwtalent visibility cloak toggle",outgoing) && outgoing && outgoing->opcode==0x2ba && outgoing->body.empty());
|
|
world.talent_control_sent(*outgoing);auto old=state.generation;world.entities.invalidate_self_display();
|
|
check(!state.known && !state.pending[1] && state.generation!=old);
|
|
world.entities.observe_equipment_visibility(create,self,70,0);
|
|
check(!state.bound(self,71,0) && !state.bound(self,70,1) && !state.bound(self+1,70,0));
|
|
}
|
|
// Real inventory state projects a copy. Actual item instances and source
|
|
// visible words stay intact through hide/replace/unhide, including enchant-only deltas.
|
|
NativeInventoryTranslation inventory;Bytes last;
|
|
auto codec=[&](uint32_t mode,const Bytes& input){
|
|
check(mode==GW_CODEC_INVENTORY);last=input;Bytes out;le(out,0,2);le(out,0,4);return out;
|
|
};
|
|
auto receive=[&](const LegacyPacket& p,bool initial=false){last.clear();inventory.translate(p,self,70,0,initial,codec);};
|
|
receive(update(item,1,2,{{3,19019},{6,self},{7,0},{8,self},{9,0}}));
|
|
receive(update(cloak,1,2,{{3,25},{6,self},{7,0},{8,self},{9,0}}));
|
|
receive(update(self,4,3,{{flags,0},{head,19019},{head+1,0},{back,25},{486,75},{487,0x40000000},{514,76},{515,0x40000000}}),true);
|
|
auto raw_head=inventory.player_fields.at(head);
|
|
receive(update(self,0,0,{{flags,SourceHideHelm|SourceHideCloak}}));
|
|
auto hidden=inventory_fields(last,self);
|
|
check(hidden.at(head)==19019 && hidden.at(back)==25 && hidden.at(flags)==(SourceHideHelm|SourceHideCloak));
|
|
check(forever_visible_item_id(hidden.at(flags),0,hidden.at(head))==0);
|
|
check(inventory.player_fields.at(head)==raw_head && inventory.items.at(item).fields.at(3)==19019);
|
|
receive(update(self,0,0,{{uint16_t(head+1),5}}));auto enchant=inventory_fields(last,self);
|
|
check(enchant.at(head)==19019 && enchant.at(head+1)==5 && enchant.at(flags)==(SourceHideHelm|SourceHideCloak));
|
|
receive(update(self,0,0,{{flags,0}}));auto restored=inventory_fields(last,self);
|
|
check(forever_visible_item_id(restored.at(flags),0,restored.at(head))==19019 && restored.at(head+1)==5);
|
|
receive(update(self,0,0,{{head,0},{486,0},{487,0}}));auto empty=inventory_fields(last,self);
|
|
check(empty.at(head)==0 && inventory.items.at(item).fields.at(3)==19019);
|
|
// A new full source generation has implicit zeros, no old hidden flag.
|
|
receive(update(self,4,3,{{486,0}}),true);
|
|
check(inventory.player_fields.at(flags)==0 && inventory.player_fields.at(head)==0 && inventory.player_fields.at(back)==0);
|
|
std::cout<<"PASS source toggles/ACK/coalescing; typed visual projection; raw inventory restore/lifecycle\n";
|
|
}
|