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

273 lines
28 KiB
C++

#include "gateway/object_updates.hpp"
#include "gateway/gameobject_queries.hpp"
#include "gateway/gameobject_type_references.hpp"
#include "fixtures/gameobject_types42.hpp"
#include "gateway/wmo_game_object_displays.hpp"
// 70334 needs GO_FLAG_MAP_OBJECT for WMO displays (ship 3015, zeppelin 3031, Naxxramas 6637); M2 ones never get it.
static_assert(gateway::turtle_wmo_game_object_display(3015) && gateway::turtle_wmo_game_object_display(3031) && gateway::turtle_wmo_game_object_display(6637));
static_assert(!gateway::turtle_wmo_game_object_display(1947) && !gateway::turtle_wmo_game_object_display(0));
#include "gateway/shop_forge_focus_authority.hpp"
#include <algorithm>
#include <bit>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <tuple>
using namespace gateway;
static void expect(bool ok,const char* why){if(!ok)throw Error(why);}
template<class F>static void rejected(F f){bool no=false;try{f();}catch(const Error&){no=true;}expect(no,"malformed game-object input accepted");}
static Bytes source_wire(const GameObjectTemplateReply& v){
Bytes b;le(b,v.entry|(v.found?0u:0x80000000u),4);if(!v.found)return b;
le(b,v.type,4);le(b,v.display,4);for(const auto& n:v.names)cstring(b,n);cstring(b,v.extra_name);for(auto x:v.data)le(b,x,4);return b;
}
static bool has(const GameObjectTemplateProjection& p,GameObjectTemplateHold reason,int field=-1){
for(auto x:p.held)if(x.reason==reason && x.source_field==field)return true;
return false;
}
static std::array<uint32_t,35> native_data(const GameObjectTemplateProjection& projected,float expected_size=1.5f){
expect(projected.packet.has_value(),"stationary template was held");Reader r(projected.packet->body);
r.le(4);unpack_guid(r,16);expect(r.le(1)==0x80,"stationary Allow bit");auto raw=r.take(r.le(4));r.end();
Reader s(raw);s.le(4);s.le(4);for(unsigned i=0;i<7;++i)s.cstring(255);
std::array<uint32_t,35> out{};for(auto& word:out)word=uint32_t(s.le(4));
expect(s.le(4)==std::bit_cast<uint32_t>(expected_size),"stationary base Size changed");
expect(s.le(1)==0 && s.le(4)==0 && s.le(4)==0,"invented stationary quest/level context");s.end();return out;
}
static void stationary_family(const GameObjectTemplateBinding& original){
auto binding=original;binding.references=[](GameObjectTemplateReference kind,uint32_t value)->std::optional<uint32_t>{
return value+1000+uint32_t(kind)*100;
};
GameObjectTemplateReply door;door.entry=binding.entry;door.found=true;door.type=0;door.display=310;door.names[0]="Door";
door.data[0]=1;door.data[1]=12;door.data[2]=3*0x10000u+65535;door.data[3]=1;door.data[4]=13;door.data[5]=14;
auto d=native_data(forever_gameobject_template(door,binding));
expect(d[0]==1 && d[1]==1012 && d[2]==3000 && d[3]==1 && d[4]==1513 && d[5]==1514,"door typed fields/timer conversion");
auto b=binding;b.references={};expect(has(forever_gameobject_template(door,b),GameObjectTemplateHold::ReferenceClosure,1),"door raw Lock fallback");
auto changed=door;changed.data[0]=2;expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::ScalarRange,0),"invalid startOpen admitted");
changed=door;changed.data[6]=1;expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::UnmappedTypeField,6),"door unknown field copied");
auto button=door;button.type=1;button.data={};button.data[0]=1;button.data[1]=12;button.data[2]=65535;button.data[3]=15;button.data[4]=1;
d=native_data(forever_gameobject_template(button,binding));expect(d[2]==0 && d[3]==1315,"button linked trap or truncated Source timer");
for(auto field:{5u,8u,9u,23u}){changed=button;changed.data[field]=1;expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::UnmappedTypeField,int(field)),"button large/LOS/deactivate meaning guessed");}
auto goober=door;goober.type=10;goober.data={};goober.data[0]=12;goober.data[1]=13;goober.data[2]=14;goober.data[3]=2*65536;goober.data[4]=4;goober.data[5]=1;goober.data[6]=9;
goober.data[7]=15;goober.data[8]=16;goober.data[9]=17;goober.data[10]=18;goober.data[11]=1;goober.data[12]=19;goober.data[14]=20;goober.data[15]=21;goober.data[17]=1;goober.data[18]=1;goober.data[19]=22;
d=native_data(forever_gameobject_template(goober,binding));expect(d[0]==1012 && d[1]==1413 && d[2]==1214 && d[3]==2000 && d[6]==9 && d[10]==1918,"goober typed references/scalars");
for(auto field:{13u,16u,20u}){changed=goober;changed.data[field]=1;expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::UnmappedTypeField,int(field)),"goober large/LOS/unknown field copied");}
auto fish=door;fish.type=25;fish.data={};fish.data[0]=20;fish.data[1]=8;fish.data[2]=2;fish.data[3]=5;fish.data[4]=7;
d=native_data(forever_gameobject_template(fish,binding));expect(d[0]==20 && d[1]==8 && d[2]==2 && d[3]==5 && d[4]==1007,"fishing-hole typed loot/count/lock");
changed=fish;changed.data[0]=51;expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::ScalarRange,0),"fishing radius overflow");
// Goblin Brainwashing Device (Turtle 1000333): QUESTGIVER lock0, pageMaterial 2, allowMounted 1.
auto giver=door;giver.type=2;giver.data={};giver.data[1]=7;giver.data[2]=2;giver.data[3]=90350;giver.data[8]=1;
d=native_data(forever_gameobject_template(giver,binding));
expect(d[0]==0 && d[1]==0 && d[2]==2 && d[3]==0 && d[8]==1,"questgiver template: server-owned list/gossip, page material, mounted");
for(auto field:{10u,11u,23u}){changed=giver;changed.data[field]=1;expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::UnmappedTypeField,int(field)),"questgiver unknown field copied");}
changed=giver;changed.data[2]=6;expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::ScalarRange,2),"unknown page material");
auto lift=door;lift.type=11;lift.data={};
expect(forever_gameobject_template(lift,binding).held.empty(),"elevator template projected");
lift.data[0]=1;expect(has(forever_gameobject_template(lift,binding),GameObjectTemplateHold::UnmappedTypeField,0),"elevator stop frame held");
static_assert(gateway::turtle_presentable_game_object(11,20649,455,1) && gateway::turtle_presentable_game_object(11,176080,3831,0),"Undercity lift + tram presented");
static_assert(!gateway::turtle_presentable_game_object(11,32056,561,1),"no client animation -> not presented");
static_assert(gateway::turtle_presentable_game_object(15,20808,3015,1),"Ratchet-Booty Bay ship presented on its 12000+P client path (0f453283)");
static_assert(gateway::turtle_presentable_game_object(15,164871,3031,1),"Orgrimmar-Undercity zeppelin presented");
{auto ship=door;ship.type=15;ship.data={};ship.data[0]=121;ship.data[1]=30;ship.data[2]=1;d=native_data(forever_gameobject_template(ship,binding));
expect(d[0]==302 && d[1]==30 && d[2]==1,"MO transport path mapped to the client TaxiPath");
ship.data[0]=72;d=native_data(forever_gameobject_template(ship,binding));expect(d[0]==12072,"Turtle-only MO route mapped to its 12000+P client path");
ship.data[0]=9999;expect(has(forever_gameobject_template(ship,binding),GameObjectTemplateHold::ReferenceClosure,0),"unmapped MO route held");}
{auto g=gateway::forever_game_object_guid(0x1FC0000000000007ull,164871,1,1);uint64_t lo=0,hi=0;
for(int i=0;i<8;++i){lo|=uint64_t(g[i])<<(8*i);hi|=uint64_t(g[8+i])<<(8*i);}
expect(lo==0 && (hi>>58)==6 && ((hi>>38)&0xFFFFF)==((1u<<19)|7),"MO transport uses a Transport GUID apart from lifts");}
{auto g=gateway::forever_game_object_guid(0xF110000000000000ull|(uint64_t(20649)<<24)|44892,20649,1,0);uint64_t lo=0,hi=0;
for(int i=0;i<8;++i){lo|=uint64_t(g[i])<<(8*i);hi|=uint64_t(g[8+i])<<(8*i);}
expect(lo==0 && (hi>>58)==6 && ((hi>>38)&0xFFFFF)==44892,"elevator uses a Transport GUID");}
static_assert(gateway::turtle_transport_period(20650)==16667 && gateway::turtle_transport_period(176080)==143333,"client periods");
auto stone=door;stone.type=23;stone.data={};stone.data[2]=42;d=native_data(forever_gameobject_template(stone,binding));expect(d[2]==2142,"meeting-stone Area relationship");
changed=stone;changed.data[0]=1;expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::UnmappedTypeField,0),"source minLevel became modern Unused");
GameObjectTemplateAuthority authority;authority.entry=door.entry;authority.type=door.type;authority.source_display=door.display;authority.source_data=door.data;authority.source_name=door.names[0];authority.provenance="fixture immutable local source";
expect(gameobject_template_authority_matches(door,authority),"exact local body failed authority match");
for(unsigned invalid=0;invalid<6;++invalid){auto a=authority;if(invalid==0)++a.entry;if(invalid==1)++a.type;if(invalid==2)++a.source_display;if(invalid==3)++a.source_data[23];if(invalid==4)a.source_name="Other";if(invalid==5)a.provenance.clear();expect(!gameobject_template_authority_matches(door,a),"changed Source template borrowed Size authority");}
for(uint32_t type:{3u,25u}){ // #95: live loot template id (data[1]) differs from the local server's
auto src=door;src.type=type;auto a=authority;a.type=type;a.source_data=src.data;a.source_data[1]=src.data[1]+4999999;
expect(gameobject_template_authority_matches(src,a),"chest/fishing-hole loot id held the template");
a.source_data[0]^=1;expect(!gameobject_template_authority_matches(src,a),"chest/fishing-hole data[0] change matched");
}
{auto a=authority;a.source_data[1]^=1;expect(!gameobject_template_authority_matches(door,a),"door data[1] change matched");}
{auto bobber=door;bobber.type=17;bobber.data={};expect(forever_gameobject_template(bobber,binding).packet.has_value(),"#99 fishing bobber template held");
bobber.data[0]=1;expect(has(forever_gameobject_template(bobber,binding),GameObjectTemplateHold::UnmappedTypeField,0),"bobber unknown word admitted");}
for(auto type:{14u,22u,24u,26u}){changed=door;changed.type=type;expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::UnsupportedType),"dynamic/unreviewed template category admitted");}
}
static void real_local_types42(){
for(const auto& row:go_types42_fixture::Rows){
GameObjectTemplateReply src;src.entry=row.entry;src.type=row.type;src.display=row.display;src.names[0]=row.name;src.found=true;src.data=row.data;
GameObjectTemplateBinding b;b.entry=row.entry;b.realm=70;b.map=0;b.source_guid=(uint64_t(0xf110)<<48)|(uint64_t(row.entry)<<24)|26243u;
b.request_generation=b.current_generation=1;b.native_guid=forever_game_object_guid(b.source_guid,row.entry,70,0);
b.template_size=row.size;b.native_display_id=row.display;
b.references=[type=row.type](GameObjectTemplateReference kind,uint32_t value){return gameobject_type_references::reference(type,kind,value);};
auto d=native_data(forever_gameobject_template(src,b),row.size);
if(row.type==5){expect(d[0]==1&&d[1]==1,"real generic sign tooltip/highlight");
auto changed=src;changed.data[5]=99999999;expect(has(forever_gameobject_template(changed,b),GameObjectTemplateHold::ReferenceClosure,5),"generic quest closure bypass");
changed=src;changed.data[3]=1;expect(forever_gameobject_template(changed,b).packet.has_value(),"Source-owned generic large incorrectly held");}
if(row.type==6){expect(d[0]==0&&d[1]==0&&d[2]==1&&d[3]==7897&&d[4]==0&&d[5]==3,"real invisible campfire trap");
auto changed=src;changed.data[6]=3u*65536u+65535u;expect(native_data(forever_gameobject_template(changed,b),row.size)[6]==3000,"trap fixed16 seconds to ms");
changed.data[6]=uint32_t(-1);expect(native_data(forever_gameobject_template(changed,b),row.size)[6]==65535000,"source unsigned fixed16 getter");
changed=src;changed.data[4]=2;expect(has(forever_gameobject_template(changed,b),GameObjectTemplateHold::ScalarRange,4),"Source count2 became native bomb");
changed=src;changed.data[3]=99999999;expect(has(forever_gameobject_template(changed,b),GameObjectTemplateHold::ReferenceClosure,3),"trap unknown spell admitted");
changed=src;changed.data[0]=99999999;expect(has(forever_gameobject_template(changed,b),GameObjectTemplateHold::ReferenceClosure,0),"trap unknown lock admitted");
auto no=b;no.references={};expect(has(forever_gameobject_template(src,no),GameObjectTemplateHold::ReferenceClosure,3),"trap raw spell fallback");
no=b;no.native_display_id=1;expect(has(forever_gameobject_template(src,no),GameObjectTemplateHold::DisplayClosure),"invisible trap became visible");}
if(row.type==7){expect(d[0]==1&&d[1]==1&&d[2]==0,"Goldshire chair slots/height");
for(auto slots:{0u,6u}){auto changed=src;changed.data[0]=slots;expect(has(forever_gameobject_template(changed,b),GameObjectTemplateHold::ScalarRange,0),"invalid chair slots");}}
if(row.type==9){expect(d[0]==731&&d[1]==7&&d[2]==2&&d[3]==0,"real tombstone page/language/material");
for(unsigned field=0;field<3;++field){auto changed=src;changed.data[field]=99999999;expect(has(forever_gameobject_template(changed,b),GameObjectTemplateHold::ReferenceClosure,field),"unclosed text reference admitted");}
auto changed=src;changed.data[0]=2050507;expect(has(forever_gameobject_template(changed,b),GameObjectTemplateHold::ReferenceClosure,0),"missing LOCAL page admitted");}
auto unknown=src;unknown.data[23]=1;expect(has(forever_gameobject_template(unknown,b),GameObjectTemplateHold::UnmappedTypeField,23),"unreviewed type tail admitted");
}
expect(!gameobject_type_references::reference(6,GameObjectTemplateReference::PageText,731),"reference namespace/type isolation");
}
int main(){try{
real_local_types42();
{ // Gitea #8: Octo sends type-11 lifts/doors with vmangos HIGHGUID_TRANSPORT 0xF120 (Undercity 152614 family).
constexpr uint32_t lift=152614;
const uint64_t octo=(uint64_t(0xf120)<<48)|(uint64_t(lift)<<24)|0x244a,local=(uint64_t(0xf110)<<48)|(uint64_t(lift)<<24)|0x244a;
expect(forever_game_object_guid(octo,lift,1,0)==forever_game_object_guid(local,lift,1,0),"F120 lift maps like F110");
expect(turtle_gameobject_query(lift,octo).size()==12,"F120 lift query");
bool refused=false;try{(void)forever_game_object_guid((uint64_t(0xf120)<<48)|(uint64_t(1734)<<24)|1,1734,1,0);}catch(const std::exception&){refused=true;}
expect(refused,"F120 only for transport entries");
}
constexpr uint32_t entry=1734;constexpr uint64_t source=(uint64_t(0xf110)<<48)|(uint64_t(entry)<<24)|41;
GameObjectTemplateReply input;input.entry=entry;input.found=true;input.type=3;input.display=310;input.names={"Gold Vein","Alternate","", ""};
input.data[0]=10;input.data[1]=20;input.data[2]=30;input.data[6]=40;input.data[7]=50;input.data[8]=60;
auto wire=source_wire(input);auto parsed=turtle_gameobject_template(wire);
expect(parsed.found && parsed.entry==entry && parsed.names==input.names && parsed.data==input.data,"source fields lost");
auto query=turtle_gameobject_query(entry,source);Reader source_q(query);
expect(source_q.le(4)==entry && source_q.le(8)==source,"source query framing");source_q.end();
GameObjectTemplateBinding binding;binding.source_guid=source;binding.entry=entry;binding.realm=70;binding.map=0;
binding.request_generation=9;binding.current_generation=9;binding.native_guid=forever_game_object_guid(source,entry,70,0);
binding.template_size=1.5f;binding.native_display_id=674;
Bytes native_q;le(native_q,entry,4);append(native_q,pack_guid(binding.native_guid));auto request=forever_gameobject_query(native_q);
expect(request.entry==entry && request.guid==binding.native_guid,"native query framing");
for(size_t n=0;n<native_q.size();++n)rejected([&]{forever_gameobject_query(std::span(native_q).first(n));});
auto tail=native_q;tail.push_back(0);rejected([&]{forever_gameobject_query(tail);});
rejected([&]{turtle_gameobject_query(entry,source+0x1000000);});
auto hold=forever_gameobject_template(parsed,binding);
expect(!hold.packet && hold.held.size()==3 && has(hold,GameObjectTemplateHold::ReferenceClosure,0) &&
!has(hold,GameObjectTemplateHold::ReferenceClosure,7),"same-number fallback only for game-object entries");
unsigned resolutions=0;
binding.references=[&](GameObjectTemplateReference kind,uint32_t value)->std::optional<uint32_t>{
++resolutions;switch(kind){
case GameObjectTemplateReference::Lock:expect(value==10,"wrong lock source");return 110;
case GameObjectTemplateReference::ChestLoot:throw Error("server loot ID requested as client definition");
case GameObjectTemplateReference::GameEvent:expect(value==40,"wrong event source");return 440;
case GameObjectTemplateReference::GameObject:expect(value==50,"wrong linked trap source");return 550;
case GameObjectTemplateReference::Quest:expect(value==60,"wrong quest source");return 660;
default:return {};
}
};
auto accepted=forever_gameobject_template(parsed,binding);expect(accepted.packet && accepted.held.empty() && resolutions==4,"closed chest not emitted");
expect(accepted.packet->opcode==0x4b0007,"reference opcode emitted without70334 normalization");
Reader header(accepted.packet->body);expect(header.le(4)==entry,"native entry lost");
auto guid=unpack_guid(header,16);expect(std::equal(guid.begin(),guid.end(),binding.native_guid.begin()),"native GUID mismatch");
expect(header.le(1)==0x80,"Allow must be nativeMSBbit");auto length=header.le(4);auto stats=header.take(length);header.end();
Reader s(stats);expect(s.le(4)==3 && s.le(4)==674,"type/display closure lost");
for(const auto& name:input.names)expect(s.cstring(255)==name,"native name lost");
for(unsigned i=0;i<3;++i)expect(s.cstring(255).empty(),"invented icon/caption");
for(unsigned i=0;i<35;++i){uint32_t expected=0;switch(i){case 0:expected=110;break;case 1:expected=20;break;case 2:expected=30;break;case 6:expected=440;break;case 7:expected=550;break;case 8:expected=660;break;}
expect(s.le(4)==expected,"typed nativeData field mismatch");}
expect(s.le(4)==std::bit_cast<uint32_t>(1.5f),"authoritative template size lost");
expect(s.le(1)==0 && s.le(4)==0 && s.le(4)==0,"invented quest/tuning/requiredlevel");s.end();
// Preserve all24 source words while refusing changed semantics. In
// particular source level9 must never become a native radius/level guess.
// Gathering-node words3/4/5 are accepted and projected as0 (server-owned).
{auto node=input;node.data[3]=1;node.data[4]=2;node.data[5]=4;auto exact=turtle_gameobject_template(source_wire(node));
auto p=forever_gameobject_template(exact,binding);expect(p.packet.has_value(),"gathering node template withheld");
Reader nh(p.packet->body);nh.le(4);unpack_guid(nh,16);nh.le(1);auto nl=nh.le(4);auto nb=nh.take(nl);Reader ns(nb);ns.le(4);ns.le(4);
for(unsigned i=0;i<4+3;++i)ns.cstring(255);
for(unsigned i=0;i<35;++i){auto w=ns.le(4);if(i>=3&&i<=5)expect(w==0,"server-owned open count copied into native restock");}}
// Source level9/losOK10/leaveLoot11/notInCombat12/logLoot13/groupLootRules15
// are Source-server rules: accepted and projected as0 (native9 is
// InteractRadiusOverride, 10-13/15 Unused). Water Barrel 3658 sets 15=1.
for(unsigned field:{9u,10u,11u,12u,13u,15u}){
auto modified=input;modified.data[field]=1000+field;auto p=forever_gameobject_template(turtle_gameobject_template(source_wire(modified)),binding);
expect(p.packet.has_value(),"server-only chest rule withheld template");
Reader h(p.packet->body);h.le(4);unpack_guid(h,16);h.le(1);auto l=h.le(4);auto b=h.take(l);Reader t(b);t.le(4);t.le(4);
for(unsigned i=0;i<4+3;++i)t.cstring(255);
for(unsigned i=0;i<35;++i){auto w=t.le(4);if(i==field)expect(w==0,"server-only chest rule copied into native field");}
}
for(unsigned field:{16u,23u}){
auto modified=input;modified.data[field]=1000+field;auto exact=turtle_gameobject_template(source_wire(modified));
expect(exact.data[field]==1000+field,"held source word discarded");auto p=forever_gameobject_template(exact,binding);
expect(!p.packet && has(p,GameObjectTemplateHold::UnmappedChestField,int(field)),"unproved chest field projected");
}
{auto excessive=input;excessive.data[1]=0x80000000u;
expect(has(forever_gameobject_template(excessive,binding),GameObjectTemplateHold::ScalarRange,1),"opaque server loot range ignored");}
auto changed=input;changed.type=4;expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::UnsupportedType),"unproved category projected");
changed=input;changed.extra_name="Unproven";expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::ExtraString),"extra source string guessed");
changed=input;changed.data[2]=1800001;expect(has(forever_gameobject_template(changed,binding),GameObjectTemplateHold::RestockRange,2),"native restock bound ignored");
auto b=binding;b.request_generation=8;expect(has(forever_gameobject_template(input,b),GameObjectTemplateHold::Binding),"stale generation accepted");
b=binding;b.map=1;expect(has(forever_gameobject_template(input,b),GameObjectTemplateHold::Binding),"oldmapGUID accepted");
b=binding;b.native_display_id.reset();expect(has(forever_gameobject_template(input,b),GameObjectTemplateHold::DisplayClosure),"raw display identity assumed");
for(auto size:{0.f,-1.f,std::numeric_limits<float>::infinity(),std::numeric_limits<float>::quiet_NaN()}){
b=binding;b.template_size=size;expect(has(forever_gameobject_template(input,b),GameObjectTemplateHold::TemplateSize),"bad template size accepted");
}
b=binding;b.template_size.reset();expect(has(forever_gameobject_template(input,b),GameObjectTemplateHold::TemplateSize),"invented missing template size");
b=binding;b.references=[](GameObjectTemplateReference,uint32_t)->std::optional<uint32_t>{return 0;};
expect(!forever_gameobject_template(input,b).packet,"reference silently dropped");
GameObjectTemplateReply missing;missing.entry=entry;auto absent=turtle_gameobject_template(source_wire(missing));
b=binding;b.template_size.reset();b.native_display_id.reset();b.references={};auto deny=forever_gameobject_template(absent,b);
expect(deny.packet && deny.packet->opcode==0x4b0007,"genuine notfound reply held");Reader negative(deny.packet->body);
expect(negative.le(4)==entry,"notfound entry");unpack_guid(negative,16);expect(negative.le(1)==0 && negative.le(4)==0,"notfound container grammar");negative.end();
for(size_t n=0;n<wire.size();++n)rejected([&]{turtle_gameobject_template(std::span(wire).first(n));});
tail=wire;tail.push_back(0);rejected([&]{turtle_gameobject_template(tail);});
stationary_family(binding);
for(const auto& [shop_entry,display,focus,name]:{
std::tuple<uint32_t,uint32_t,uint32_t,const char*>{3000684,197,3,"Blazing Forge Kit: Forge"},
std::tuple<uint32_t,uint32_t,uint32_t,const char*>{3000685,273,1,"Blazing Forge Kit: Anvil"}}){
GameObjectTemplateReply shop;shop.found=true;shop.entry=shop_entry;
shop.type=8;shop.display=display;shop.names[0]=name;
shop.data[0]=focus;shop.data[1]=10;
auto authority=shop_forge_focus_authority::lookup(shop);
expect(authority && gameobject_template_authority_matches(shop,*authority),"exact shop forge authority not matched");
unsigned local_calls=0;
auto remote=shop_forge_focus_authority::select(shop,false,[&](const auto&)->std::optional<GameObjectTemplateAuthority>{
++local_calls;return std::nullopt;});
expect(remote && local_calls==0 && gameobject_template_authority_matches(shop,*remote),
"public shop forge used local-only authority or failed exact fallback");
auto local_override=*authority;local_override.provenance="local fixture precedence";
auto local=shop_forge_focus_authority::select(shop,true,[&](const auto&)->std::optional<GameObjectTemplateAuthority>{
++local_calls;return local_override;});
expect(local && local_calls==1 && local->provenance==local_override.provenance,
"local general authority lost precedence");
GameObjectTemplateBinding b;b.entry=shop_entry;b.source_guid=(uint64_t(0xf110)<<48)|(uint64_t(shop_entry)<<24)|1;
b.realm=70;b.map=1;b.request_generation=b.current_generation=1;
b.native_guid=forever_game_object_guid(b.source_guid,b.entry,b.realm,b.map);
b.native_display_id=authority->native_display;b.template_size=authority->template_size;b.references=authority->references;
auto p=forever_gameobject_template(turtle_gameobject_template(source_wire(shop)),b);
expect(p.packet && p.held.empty(),"shop forge type8 template held");
Reader envelope(p.packet->body);expect(envelope.le(4)==shop_entry,"shop forge query entry");
unpack_guid(envelope,16);expect(envelope.le(1)==0x80,"shop forge query allow bit");
auto stats=envelope.take(envelope.le(4));envelope.end();Reader decoded(stats);
expect(decoded.le(4)==8 && decoded.le(4)==display,"shop forge type/display");
expect(decoded.cstring(255)==name,"shop forge name");
for(unsigned i=0;i<6;++i)expect(decoded.cstring(255).empty(),"shop forge invented label");
for(unsigned i=0;i<35;++i){auto value=decoded.le(4);expect(value==(i==0?focus:i==1?10:0),"shop forge focus/radius or zero tail");}
expect(decoded.le(4)==std::bit_cast<uint32_t>(0.5f),"shop forge local Source template size");
expect(decoded.le(1)==0 && decoded.le(4)==0 && decoded.le(4)==0,"shop forge invented context");decoded.end();
auto changed=shop;changed.display++;expect(!shop_forge_focus_authority::lookup(changed),"stale shop display accepted");
expect(!shop_forge_focus_authority::select(changed,false,[&](const auto&)->std::optional<GameObjectTemplateAuthority>{
++local_calls;return local_override;}) && local_calls==1,"stale public shop borrowed local-only authority");
changed=shop;changed.data[2]=1;expect(!shop_forge_focus_authority::lookup(changed),"unproved shop linked trap accepted");
auto no_ref=b;no_ref.references={};expect(has(forever_gameobject_template(shop,no_ref),GameObjectTemplateHold::ReferenceClosure,0),"shop focus ID raw fallback");
changed=shop;changed.data[1]=51;expect(has(forever_gameobject_template(changed,b),GameObjectTemplateHold::ScalarRange,1),"shop focus radius >50 accepted");
changed=shop;changed.data[5]=1;expect(has(forever_gameobject_template(changed,b),GameObjectTemplateHold::UnmappedTypeField,5),"source large misread as GiganticAOI");
changed=shop;changed.display=0;auto no_model=b;no_model.native_display_id=0;
expect(forever_gameobject_template(changed,no_model).packet.has_value(),"displayless spell focus rejected");
}
{ // #96: Turtle hardcore grave (live OCTO reply 7101359): exact shape only.
GameObjectTemplateReply g;g.found=true;g.entry=7101359;g.type=2;g.display=19;g.names[0]="Grave of Orangewhale (level 43)";
auto a=turtle_hardcore_grave_authority(g,true);if(!a || !gameobject_template_authority_matches(g,*a) || a->native_display!=19)return EXIT_FAILURE;
if(turtle_hardcore_grave_authority(g,false))return EXIT_FAILURE; // unknown display
auto d=g;d.data[0]=1;if(turtle_hardcore_grave_authority(d,true))return EXIT_FAILURE; // any data word
auto t=g;t.type=3;if(turtle_hardcore_grave_authority(t,true))return EXIT_FAILURE; // other type
for(auto bad:{"Grave of (level 43)","Grave of Orange whale (level 43)","Grave of Orangewhale (level 4x)","Grave of Orangewhale (level 43","Tomb of Orangewhale (level 43)"}){
auto n=g;n.names[0]=bad;if(turtle_hardcore_grave_authority(n,true))return EXIT_FAILURE;}
}
std::cout<<"Typed stationary game-object query/container, timers and explicit closure holds PASS\n";return EXIT_SUCCESS;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return EXIT_FAILURE;}}