94 lines
7.8 KiB
C++
94 lines
7.8 KiB
C++
#include "gateway/gameobject_queries.hpp"
|
|
#include GW_GAMEOBJECT_AUTHORITY_PROFILE_HEADER
|
|
#include <algorithm>
|
|
#include <iostream>
|
|
#include <source_location>
|
|
#include <vector>
|
|
using namespace gateway;
|
|
using namespace gateway::gameobject_authority_profile;
|
|
static void expect(bool ok,const std::source_location& at=std::source_location::current()){
|
|
if(!ok)throw Error("typed GO Lock definition assertion line "+std::to_string(at.line()));
|
|
}
|
|
using Record=item_sparse_compat::Record;
|
|
static std::vector<Record> without(std::vector<Record> rows,uint32_t table,uint32_t id){
|
|
std::erase_if(rows,[&](const auto& row){return row.table==table&&row.id==id;});return rows;
|
|
}
|
|
int main(){try{
|
|
constexpr uint32_t lock_table=0xe9becb23;std::vector<Record> records(std::begin(item_sparse_compat::Records),std::end(item_sparse_compat::Records));
|
|
auto resolved=[&](uint32_t id,const auto& rows){return reference_from(GameObjectTemplateReference::Lock,id,rows);};
|
|
const auto target=std::find_if(std::begin(Locks),std::end(Locks),[](const auto& row){return row.id==1656;});
|
|
expect(target!=std::end(Locks)&&target->overlay&&target->native==1656&&target->items[0]==41913);
|
|
// A prepared JSON row is not a loaded definition (the compat Records now also carry 1656, so test without it).
|
|
expect(!resolved(1656,without(records,lock_table,1656)));
|
|
unsigned overlays=0;
|
|
for(const auto& row:Locks)if(row.overlay){records.push_back({lock_table,row.native,row.wire});++overlays;}
|
|
expect(overlays==15 && resolved(1656,records)==1656);
|
|
unsigned links=0;for(const auto& row:Locks){expect(resolved(row.id,records)==row.native);++links;}
|
|
const auto baked=resolved(4582,records);
|
|
expect(links==(baked?213u:212u)); // #109: every Lock any profiled template references (was the 164 of the 2627 world rows)
|
|
// W14: unchanged native key alternatives, one loaded Source-rank override.
|
|
for(auto id:{39u,40u,41u})expect(resolved(id,without(records,lock_table,id))==id);
|
|
expect(resolved(38,records)==38 && !resolved(38,without(records,lock_table,38)));
|
|
auto copper=std::find_if(std::begin(Locks),std::end(Locks),[](const auto& row){return row.id==38;});
|
|
expect(copper!=std::end(Locks)&&copper->overlay);
|
|
Reader copper_body(copper->wire);expect(copper_body.le(4)==0);
|
|
expect(copper_body.le(4)==3&&copper_body.le(4)==872); // Mining + native key.
|
|
copper_body.take(6*4);expect(copper_body.le(2)==0); // Exact Source rank0.
|
|
|
|
expect(!resolved(777777,records)); // No same-integer/default fallback.
|
|
// Content dece93a3 baked Source Survival LockType 20 and tree Locks 1660-1665 into the native client tables.
|
|
for(auto id:{1660u,1661u,1662u,1663u,1664u,1665u})expect(resolved(id,records)==id);
|
|
expect(!reference_from(GameObjectTemplateReference::Quest,1656,records));
|
|
expect(!resolved(1656,without(records,lock_table,1656)));
|
|
expect(!resolved(1656,without(records,0x50238ec2,41913)));
|
|
expect(!resolved(1656,without(records,0x919be54e,41913)));
|
|
auto changed=records;auto found=std::find_if(changed.begin(),changed.end(),[](const auto& r){return r.table==lock_table&&r.id==1656;});expect(found!=changed.end());
|
|
found->status=3;expect(!resolved(1656,changed)); // Removed definition is not active.
|
|
auto wrong=target->wire;wrong[0]^=1;found->status=1;found->data=wrong;expect(!resolved(1656,changed));
|
|
wrong=target->wire;wrong[40]^=1;found->data=wrong;expect(!resolved(1656,changed)); // Wrong rank/action/body cannot satisfy closure.
|
|
auto gate=std::find_if(std::begin(Rows),std::end(Rows),[](const auto& row){return row.entry==2020233;});expect(gate!=std::end(Rows));
|
|
GameObjectTemplateReply source;source.found=true;source.entry=gate->entry;source.type=gate->type;source.display=gate->display;source.names[0]=gate->name;source.data=gate->data;
|
|
auto authority=lookup(source);expect(authority&&gameobject_template_authority_matches(source,*authority));
|
|
GameObjectTemplateBinding b;b.entry=source.entry;b.source_guid=(uint64_t(0xf110)<<48)|(uint64_t(source.entry)<<24)|1;b.realm=70;b.request_generation=b.current_generation=1;b.native_guid=forever_game_object_guid(b.source_guid,b.entry,70,0);b.template_size=authority->template_size;b.native_display_id=authority->native_display;
|
|
b.references=[&](auto kind,uint32_t value){return reference_from(kind,value,records);};
|
|
auto projection=forever_gameobject_template(source,b);expect(projection.packet&&projection.held.empty());
|
|
Reader r(projection.packet->body);expect(r.le(4)==2020233);unpack_guid(r,16);expect(r.le(1)==0x80);auto stats=r.take(r.le(4));r.end();Reader s(stats);expect(s.le(4)==0&&s.le(4)==27506);for(unsigned i=0;i<7;++i)s.cstring(255);
|
|
expect(s.le(4)==0&&s.le(4)==1656&&s.le(4)==3000); // Exact named Door fields: lock + fixed16 timer.
|
|
// Actual cached gathering templates must publish with typed Lock closure
|
|
// and opaque Source loot IDs, without a client loot-definition resolver.
|
|
// Eight known herb chests share the source lock with two carcasses and a dormant tuber.
|
|
// Exercise the per-template resolver after the normal authority and reference checks.
|
|
#ifdef GW_TEST_GATHERING_LOCK
|
|
expect(baked==4582);
|
|
auto herb_lock=std::find_if(std::begin(Locks),std::end(Locks),[](const auto& row){return row.id==4582;});
|
|
expect(herb_lock!=std::end(Locks)&&!herb_lock->overlay);
|
|
std::array<uint8_t,68> herb_wire{};
|
|
herb_wire[4]=2;herb_wire[8]=13;herb_wire[52]=2;herb_wire[53]=2;
|
|
expect(herb_lock->wire==herb_wire);
|
|
#endif
|
|
for(auto entry:{1731u,1617u,1618u,142142u,13891u,17282u,141853u,164958u,175566u,175928u,176753u,2020023u,
|
|
175207u,176189u,184691u}){
|
|
auto row=std::find_if(std::begin(Rows),std::end(Rows),[&](const auto& r){return r.entry==entry;});expect(row!=std::end(Rows));
|
|
GameObjectTemplateReply node;node.found=true;node.entry=entry;node.type=row->type;node.display=row->display;node.names[0]=row->name;node.data=row->data;
|
|
auto authority=lookup(node);
|
|
expect(authority&&authority->native_display&&gameobject_template_authority_matches(node,*authority));
|
|
const bool tracked_herb=node.data[0]==259 && entry!=175207 && entry!=176189 && entry!=184691;
|
|
const auto expected_lock=tracked_herb && baked?4582u:node.data[0];
|
|
expect(authority->references(GameObjectTemplateReference::Lock,node.data[0])==expected_lock);
|
|
auto binding=b;binding.references=authority->references;binding.entry=entry;binding.source_guid=(uint64_t(0xf110)<<48)|(uint64_t(entry)<<24)|1;
|
|
binding.native_guid=forever_game_object_guid(binding.source_guid,entry,70,0);binding.native_display_id=authority->native_display;binding.template_size=authority->template_size;
|
|
auto projected=forever_gameobject_template(node,binding);
|
|
if(node.data[8] && !baked){
|
|
expect(!projected.packet && projected.held.size()==1 &&
|
|
projected.held.front().reason==GameObjectTemplateHold::ReferenceClosure && projected.held.front().source_field==8);
|
|
continue;
|
|
}
|
|
if(!projected.packet || !projected.held.empty())throw Error("Unexpected template hold for entry "+std::to_string(entry));
|
|
expect(!authority->references(GameObjectTemplateReference::Quest,999999));
|
|
Reader outer(projected.packet->body);expect(outer.le(4)==entry);unpack_guid(outer,16);expect(outer.le(1)==0x80);auto raw_stats=outer.take(outer.le(4));outer.end();Reader stats(raw_stats);
|
|
expect(stats.le(4)==3&&stats.le(4)==authority->native_display);for(unsigned i=0;i<7;++i)stats.cstring(255);
|
|
for(unsigned i=0;i<35;++i){auto value=stats.le(4);if(i==0)expect(value==expected_lock);if(i==1)expect(value==node.data[1]);if(i>=3&&i<=5)expect(value==0);if(i==7||i==8)expect(value==node.data[i]);}
|
|
}
|
|
std::cout<<"Typed Lock boundary passed for gathering, stock shared locks, missing/wrong/removed references and the Stormwrought gate\n";return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|