883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
123 lines
8.4 KiB
C++
123 lines
8.4 KiB
C++
#include "gateway/world.hpp"
|
|
#include "gateway/roster_translation.hpp"
|
|
#include <array>
|
|
#include <bit>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
|
|
using namespace gateway;
|
|
namespace {
|
|
size_t passed=0,rejected=0;
|
|
void check(bool ok,const char* message){if(!ok)throw std::runtime_error(message);}
|
|
template<class F>void reject(F action){try{action();}catch(const Error&){++rejected;return;}throw std::runtime_error("unsupported matrix state accepted");}
|
|
void number(Bytes& b,float f){le(b,std::bit_cast<uint32_t>(f),4);}
|
|
Bytes frame(uint64_t flags,bool fall=false,bool surface=false){
|
|
auto b=pack_guid(forever_player_guid(4509,70));le(b,flags,8);le(b,1234,4);
|
|
for(float f:{1.f,2.f,3.f,.5f,.25f,1.25f})number(b,f);
|
|
le(b,0,4);le(b,17,4);number(b,1);le(b,(fall?0x20:0)|(surface?0x80:0),1);le(b,0,1);
|
|
if(surface){Bytes id(16);id[0]=7;append(b,pack_guid(id));}
|
|
if(fall){le(b,50,4);number(b,4);le(b,0x80,1);for(float f:{0.f,1.f,3.f})number(b,f);}
|
|
return b;
|
|
}
|
|
// Independent source MovementInfo::Read layout: flags/time/XYZ/O, optional
|
|
// swimPitch, fallTime, optional zSpeed/cos/sin/xySpeed, optional elevation.
|
|
Bytes source(uint32_t flags,bool fall){
|
|
Bytes b;le(b,flags,4);le(b,1234,4);for(float f:{1.f,2.f,3.f,.5f})number(b,f);
|
|
if(flags&0x200000)number(b,.25f);
|
|
le(b,fall?50:0,4);
|
|
if(flags&0x2000)for(float f:{4.f,1.f,0.f,3.f})number(b,f);
|
|
if(flags&0x4000000)number(b,1.25f);
|
|
return b;
|
|
}
|
|
void read_source(std::span<const uint8_t> wire,uint32_t flags,bool fall){
|
|
Reader r(wire);check(r.le(4)==flags,"flags mismatch");check(r.le(4)==1234,"time mismatch");
|
|
for(float f:{1.f,2.f,3.f,.5f})check(r.f32()==f,"position mismatch");
|
|
if(flags&0x200000)check(r.f32()==.25f,"pitch mismatch");
|
|
check(r.le(4)==(fall?50:0),"fallTime mismatch");
|
|
if(flags&0x2000)for(float f:{4.f,1.f,0.f,3.f})check(r.f32()==f,"jump scalar/order mismatch");
|
|
if(flags&0x4000000)check(r.f32()==1.25f,"elevation mismatch");
|
|
r.end();
|
|
}
|
|
}
|
|
int main(){try{
|
|
Character c{};c.guid=4509;const std::vector<Character> owned{c};
|
|
constexpr std::array<std::pair<uint64_t,uint32_t>,4> modes{{{0x400,0x1000},{0x4000000,0x10000000},{0x8000000,0x20000000},{0x800000000000000,0x40000000}}};
|
|
// Every noncontradictory direction combination, walk/run, contact bit,
|
|
// reviewed server mode combination, swim, jump/far-fall, elevation.
|
|
for(unsigned direction=0;direction<81;++direction){
|
|
uint64_t active=0;unsigned choice=direction;
|
|
for(unsigned pair=0;pair<4;++pair){unsigned state=choice%3;choice/=3;if(state)active|=uint64_t(1)<<(2*pair+state-1);}
|
|
for(unsigned mode=0;mode<16;++mode)for(unsigned walk=0;walk<2;++walk)
|
|
for(unsigned contact=0;contact<2;++contact)for(unsigned swim=0;swim<2;++swim)
|
|
for(unsigned fall=0;fall<3;++fall)for(unsigned elevated=0;elevated<2;++elevated){
|
|
uint64_t flags=active|(walk?0x100:0)|(contact?0x80000000:0)|(swim?0x100000:0)|(fall?0x800:0)|(fall==2?0x1000:0)|(elevated?0x2000000:0);
|
|
uint32_t legacy=uint32_t(active)|(walk?0x100:0)|(swim?0x200000:0)|(fall?0x2000:0)|(fall==2?0x4000:0)|(elevated?0x4000000:0);
|
|
for(unsigned i=0;i<4;++i)if(mode&(1u<<i)){flags|=modes[i].first;legacy|=modes[i].second;}
|
|
auto packet=frame(flags,fall!=0);
|
|
if((mode&1) && ((active&0xcf)||fall||elevated)){reject([&]{forever_basic_movement(packet,70,owned);});continue;}
|
|
auto encoded=turtle_basic_movement(forever_basic_movement(packet,70,owned));
|
|
check(encoded==source(legacy,fall!=0),"matrix complete source wire differs");read_source(encoded,legacy,fall!=0);++passed;
|
|
}
|
|
}
|
|
for(uint64_t vertical:{0x200000ULL,0x400000ULL})for(uint64_t direction:{0ULL,1ULL,2ULL,4ULL,8ULL,0x10ULL,0x20ULL,0x40ULL,0x80ULL}){
|
|
auto encoded=turtle_basic_movement(forever_basic_movement(frame(0x100000|vertical|direction),70,owned));
|
|
check(encoded==source(0x200000|uint32_t(direction),false),"vertical swim direction changed");++passed;
|
|
}
|
|
// Every native flag position is exercised once in a supported context or
|
|
// explicitly rejected. Falling and up/down have required companion bits.
|
|
constexpr uint64_t opaque=(1ULL<<43)|(1ULL<<47)|(1ULL<<48)|(1ULL<<50)|(1ULL<<55)|(1ULL<<56)|(1ULL<<57)|(1ULL<<58);
|
|
constexpr uint64_t supported=0x800001ffULL|0x400|0x1800|0x7e000|0x700000|0x2000000|0x4000000|0x8000000|0x800000000000000ULL|opaque;
|
|
for(unsigned bit=0;bit<64;++bit){
|
|
uint64_t flag=uint64_t(1)<<bit;bool falling=bool(flag&0x1800);
|
|
if(!(supported&flag)){reject([&]{forever_basic_movement(frame(flag),70,owned);});continue;}
|
|
if(flag&0x600000)flag|=0x100000;
|
|
if(flag&0x1000)flag|=0x800;
|
|
auto parsed=forever_basic_movement(frame(flag,falling),70,owned);
|
|
check(parsed.native_opaque_extensions==(flag&opaque),"opaque extension metadata lost");++passed;
|
|
}
|
|
// Deferred intent combinations remain distinct from legacy jump flags.
|
|
for(unsigned combination=0;combination<64;++combination){
|
|
auto move=forever_basic_movement(frame(4|(uint64_t(combination)<<13)),70,owned);
|
|
check(turtle_basic_movement(move)==source(4,false),"pending intent became movement mode");++passed;
|
|
}
|
|
auto surface=turtle_basic_movement(forever_basic_movement(frame(0x300004,false,true),70,owned));
|
|
check(surface==source(0x200004,false),"contact surface changed world position");++passed;
|
|
auto surface_fall=turtle_basic_movement(forever_basic_movement(frame(0x800,true,true),70,owned));
|
|
check(surface_fall==source(0x2000,true),"combined contact/fall option layout differs");++passed;
|
|
for(unsigned bit=0;bit<8;++bit){
|
|
if(bit==5 || bit==7)continue; // Supported fall and surface fixtures above.
|
|
auto packet=frame(4);packet[packet.size()-2]=uint8_t(1u<<bit);
|
|
reject([&]{forever_basic_movement(packet,70,owned);});
|
|
}
|
|
for(unsigned bit=0;bit<8;++bit){auto packet=frame(4);packet.back()=uint8_t(1u<<bit);reject([&]{forever_basic_movement(packet,70,owned);});}
|
|
for(const auto& packet:{frame(0x800,true),frame(4,false,true),frame(0x1800,true,true)})
|
|
for(size_t n=0;n<packet.size();++n)reject([&]{forever_basic_movement(std::span(packet).first(n),70,owned);});
|
|
for(unsigned bit=0;bit<7;++bit){
|
|
auto packet=frame(0x800,true);packet[frame(0x800).size()+8]|=uint8_t(1u<<bit);
|
|
reject([&]{forever_basic_movement(packet,70,owned);});
|
|
}
|
|
for(uint64_t flags:{3ULL,12ULL,48ULL,0xc0ULL,0x700000ULL,0x200000ULL,0x400000ULL,0x1000ULL,0x300400ULL,0x300800ULL,0x2300000ULL})
|
|
reject([&]{forever_basic_movement(frame(flags),70,owned);});
|
|
// Source-grounded pitch plus root semantics roundtrip independently.
|
|
for(uint32_t flags:{0x40u,0x80u,0x50u,0xa0u,0x1010u,0x1020u}){
|
|
auto wire=forever_ground_movement(GroundMovement{4509,flags,1234,{1,2,3,.5f}},70);
|
|
check(forever_ground_movement(wire,70,owned).flags==flags,"grounded pitch/root turn lost");++passed;
|
|
}
|
|
for(uint32_t flags:{0xc0u,0x1040u,0x1080u,0x1001u})reject([&]{forever_ground_movement(GroundMovement{4509,flags,1234,{1,2,3,.5f}},70);});
|
|
// Near teleport uses authoritative source coordinates; mode fields do not
|
|
// silently become transport/swim optional payloads or ACK identities.
|
|
for(uint32_t flags:{0u,0x40u,0x80u,0x1000u,0x10000000u,0x20000000u,0x40000000u,0x70001000u}){
|
|
Bytes id;le(id,4509,8);auto input=pack_guid(id);le(input,9,4);le(input,flags,4);le(input,1234,4);
|
|
for(float f:{1.f,2.f,3.f,.5f})number(input,f);
|
|
le(input,0,4);
|
|
auto move=turtle_near_teleport(input,4509);auto modern=forever_near_teleport(move,70);Reader r(modern);
|
|
auto expected_guid=forever_player_guid(4509,70);
|
|
check(unpack_guid(r,16)==Bytes(expected_guid.begin(),expected_guid.end()),"teleport identity differs");
|
|
check(r.le(4)==9,"teleport sequence differs");for(float f:{1.f,2.f,3.f,.5f})check(r.f32()==f,"teleport position differs");check(r.le(1)==0,"teleport optional data invented");r.end();
|
|
auto ack=pack_guid(forever_player_guid(4509,70));le(ack,9,4);le(ack,222,4);
|
|
Bytes expected;le(expected,4509,8);le(expected,9,4);le(expected,222,4);check(turtle_near_teleport_ack(ack,move,70)==expected,"teleport ACK differs");++passed;
|
|
ack[ack.size()-8]=10;reject([&]{turtle_near_teleport_ack(ack,move,70);});
|
|
}
|
|
std::cout<<"Movement matrix PASS: "<<passed<<" accepted full-wire/state cases, "<<rejected<<" guarded rejects; all64flag positions classified\n";return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|