82 lines
5.8 KiB
C++
82 lines
5.8 KiB
C++
#include "optional_test_codec.hpp"
|
|
#include "world_translation.hpp"
|
|
#include "gateway/taxi.hpp"
|
|
#include "gateway/object_updates.hpp"
|
|
#include <iostream>
|
|
#include <bit>
|
|
#include <dlfcn.h>
|
|
#include <cstdlib>
|
|
using namespace gateway;
|
|
int main(){try{
|
|
const uint64_t npc=(uint64_t(0xf130)<<48)|(uint64_t(3310)<<24)|1;
|
|
auto modern=forever_creature_guid(npc,3310,70,1);
|
|
Bytes source;le(source,1,4);le(source,npc,8);le(source,23,4);
|
|
Bytes mask(32);mask[2]=0x40;mask[9]=0x40;append(source,mask);
|
|
auto menu=turtle_taxi_menu(source);auto out=forever_taxi_menu(menu,modern);
|
|
Reader r(out);if(r.le(1)!=0x80||r.le(4)!=4||r.le(4)!=4||unpack_guid(r,16)!=Bytes(modern.begin(),modern.end())||r.le(4)!=23||r.take(32)!=mask||r.take(32)!=mask)return 1;r.end();
|
|
if(forever_taxi_status(modern,0).back()!=0x80||forever_taxi_status(modern,1).back()!=0x40)return 2;
|
|
for(unsigned result=0;result<=9;++result){Bytes b;le(b,result,4);if(forever_taxi_reply(b)!=Bytes{uint8_t(result<<4)})return 3;}
|
|
NativeWorldTranslation world{};world.self_created=true;world.selected.guid=4518;world.realm=70;world.location=WorldLocation{1,{0,0,0,0}};
|
|
NativeEntityTranslation::Actor actor;actor.kind=3;actor.sent=true;actor.modern=modern;actor.generation=1;world.entities.actors[npc]=actor;
|
|
auto request=pack_guid(modern);
|
|
for(auto op:{0x3f0040u,0x3f0041u,0x3f0042u}){auto p=world.gameplay(op,request);Reader q(p.body);if(p.opcode!=(op==0x3f0040?0x1aa:0x1ac)||q.le(8)!=npc)return 4;q.end();}
|
|
auto bundle=world.translate({0x1a9,source},0x46010046,0,nullptr);Reader b(bundle);
|
|
if(b.le(4)!=1||b.le(4)!=0x47017a)return 5;
|
|
auto n=b.le(4);if(b.take(n)!=out)return 7;b.end();
|
|
// Repeated genuine replies may refresh the map but never reopen the NPC
|
|
// interaction and generate another available-nodes request.
|
|
auto repeated=world.translate({0x1a9,source},0x46010046,0,nullptr);Reader again(repeated);
|
|
if(again.le(4)!=1||again.le(4)!=0x47017a)return 6;
|
|
for(size_t i=0;i<source.size();++i){try{turtle_taxi_menu(std::span(source).first(i));return 8;}catch(const Error&) {}}
|
|
auto bad=source;bad.push_back(0);try{turtle_taxi_menu(bad);return 9;}catch(const Error&) {}
|
|
// Real source graph is used for multi-hop routing, never the target DB2 graph.
|
|
auto complete=menu;complete.known=Bytes(32);
|
|
for(unsigned node:{23u,40u,79u,73u})complete.known[(node-1)/8]|=1u<<((node-1)%8);
|
|
auto activation=turtle_taxi_activation(complete,73);
|
|
Reader route(activation);if(route.le(8)!=npc||route.le(4)!=2590||route.le(4)!=4)return 13;
|
|
for(unsigned node:{23u,40u,79u,73u})if(route.le(4)!=node)return 14;route.end();
|
|
auto absent=complete;absent.known[9]&=~1u;
|
|
try{turtle_taxi_activation(absent,73);return 15;}catch(const Error&) {}
|
|
try{turtle_taxi_activation(complete,23);return 16;}catch(const Error&) {}
|
|
// A newly defined node still requires actual Source discovery. The
|
|
// current Source82->2 edge costs50; target DB2 path IDs never select it.
|
|
TaxiMenu added{npc,82,Bytes(32)};
|
|
for(unsigned node:{82u,2u})added.known[(node-1)/8]|=1u<<((node-1)%8);
|
|
auto new_activation=turtle_taxi_activation(added,2);Reader new_route(new_activation);
|
|
if(new_route.le(8)!=npc||new_route.le(4)!=50||new_route.le(4)!=2||new_route.le(4)!=82||new_route.le(4)!=2)return 27;new_route.end();
|
|
added.known[(82-1)/8]&=~(1u<<((82-1)%8));
|
|
try{turtle_taxi_activation(added,2);return 28;}catch(const Error&) {}
|
|
// A self flight uses source Flying+Runmode0x300 and uncompressed points;
|
|
// its player GUID must remain the authenticated self, not a fake creature.
|
|
Bytes flight;le(flight,4518,8);flight=pack_guid(flight);
|
|
auto float32=[](Bytes& bytes,float value){le(bytes,std::bit_cast<uint32_t>(value),4);};
|
|
for(float value:{1.f,2.f,3.f})float32(flight,value);
|
|
le(flight,19,4);le(flight,0,1);le(flight,0x300,4);le(flight,4000,4);le(flight,2,4);
|
|
for(float value:{4.f,5.f,6.f,7.f,8.f,9.f})float32(flight,value);
|
|
auto spline=turtle_monster_spline(flight);
|
|
if(!spline.flying||spline.guid!=4518||spline.points.size()!=2||spline.points.back()[2]!=9)return 17;
|
|
auto self=forever_player_guid(4518,70);auto translated=forever_monster_spline(spline,self);
|
|
Reader v(translated);if(unpack_guid(v,16)!=Bytes(self.begin(),self.end())||v.le(4)!=19||v.le(4)!=0x400a00)return 18;
|
|
if(const char* path=std::getenv("GW_TEST_CODEC_PATH")){
|
|
if (test_fixture::optional_codec_missing(path)) return 77;
|
|
void* library=dlopen(path,RTLD_NOW|RTLD_LOCAL);if(!library)return 23;
|
|
auto codec=reinterpret_cast<decltype(&gw_codec_serialize)>(dlsym(library,"gw_codec_serialize"));if(!codec)return 24;
|
|
Bytes payload;le(payload,70,2);le(payload,1,4);append(payload,flight);Bytes original(65536);uint32_t written=0;
|
|
if(codec(GW_CODEC_MONSTER_MOVE,payload.data(),payload.size(),0,original.data(),original.size(),&written))return 25;
|
|
original.resize(written);if(original!=translated)return 26;dlclose(library);
|
|
std::cout<<"Self-flight bytes match original70334 MonsterMove writer.\n";
|
|
}
|
|
world.entities.self_presentation_ready=true;
|
|
auto emitted=world.translate({0xdd,flight},0x46010046,0,nullptr);Reader framed(emitted);
|
|
if(framed.le(4)!=1||framed.le(4)!=0x600002)return 19;
|
|
auto length=framed.le(4);if(framed.take(length)!=translated)return 20;framed.end();
|
|
for(size_t size=0;size<flight.size();++size){try{turtle_monster_spline(std::span(flight).first(size));return 21;}catch(const Error&) {}}
|
|
auto foreign=flight;foreign[1]^=1;world.entities.motion_unknown=0;
|
|
emitted=world.translate({0xdd,foreign},0x46010046,0,nullptr);Reader no_foreign(emitted);
|
|
if(no_foreign.le(4)!=0||!world.entities.motion_unknown)return 22;
|
|
world.entities.actors[npc].sent=false;
|
|
try{world.gameplay(0x3f0042,request);return 10;}catch(const Error&) {}
|
|
try{world.translate({0x1a9,source},0x46010046,0,nullptr);return 11;}catch(const Error&) {}
|
|
std::cout<<"Source taxi window/status/reply layouts and visible GUID ownership pass; offline only.\n";return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 12;}}
|