153 lines
11 KiB
C++
153 lines
11 KiB
C++
#include "world_translation.hpp"
|
|
#include "serializer.h"
|
|
#include "gateway/object_updates.hpp"
|
|
#include <algorithm>
|
|
#include <bit>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
namespace {
|
|
constexpr uint64_t owner=45;
|
|
constexpr uint16_t realm=70;
|
|
const Bytes self_marker{'T','h','i','s','I','s','Y','o','u'};
|
|
Bytes codec_result,codec_input;
|
|
uint32_t codec_mode=0,self_calls=0;
|
|
void check(bool ok,const char* what){if(!ok)throw Error(what);}
|
|
template<class F>void rejects(F action){try{action();}catch(const Error&){return;}throw Error("malformed source accepted");}
|
|
int codec(uint32_t mode,const uint8_t* input,uint32_t size,uint32_t flags,uint8_t* output,uint32_t capacity,uint32_t* written){
|
|
check(written && !flags,"codec ABI arguments");Bytes request(input,input+size);
|
|
if(!output){
|
|
codec_mode=mode;codec_input=request;
|
|
if(mode==GW_CODEC_SELF){
|
|
Reader r(request);check(r.le(8)==owner && r.le(2)==realm,"self codec authenticated identity");
|
|
r.le(4);check(r.le(4)==0,"self map");r.le(4);check(r.le(4)==0 && r.le(4)==0,"no invented modern account identity");
|
|
r.cstring();r.le(1);r.le(1);r.le(1);auto op=uint16_t(r.le(4));
|
|
auto updates=turtle_object_updates(op,r.take(r.left()));
|
|
check(std::any_of(updates.begin(),updates.end(),[](const auto& u){return u.guid==owner && u.type==4 && (u.update_flags&1);}),"self codec requires genuine selected ThisIsYou source create");
|
|
++self_calls;codec_result=self_marker;
|
|
}else if(mode==GW_CODEC_INVENTORY){codec_result.clear();le(codec_result,0,2);le(codec_result,0,4);}
|
|
else throw Error("unexpected codec mode in empty self fixture");
|
|
*written=uint32_t(codec_result.size());return GW_CODEC_CAPACITY;
|
|
}
|
|
check(mode==codec_mode && request==codec_input,"codec sizing/write input changed");
|
|
*written=uint32_t(codec_result.size());if(capacity<*written)return GW_CODEC_CAPACITY;
|
|
std::copy(codec_result.begin(),codec_result.end(),output);return GW_CODEC_OK;
|
|
}
|
|
NativeWorldTranslation world(uint8_t cls=1){
|
|
NativeWorldTranslation w{};w.realm=realm;w.selected.guid=owner;w.selected.name="Fixture";
|
|
w.selected.race=1;w.selected.cls=cls;w.location=WorldLocation{0,{1,2,3,.5f}};return w;
|
|
}
|
|
LegacyPacket modifier(uint8_t bit,int32_t amount,uint32_t opcode=0x266,uint8_t operation=11){
|
|
Bytes b{bit,operation};le(b,std::bit_cast<uint32_t>(amount),4);return {opcode,std::move(b)};
|
|
}
|
|
LegacyPacket self_create(bool this_is_you=true){
|
|
// Actual source UPDATE_OBJECT/CreateObject2 Player, LIVING MovementInfo
|
|
// plus genuine SELF flag; only the independent native schema writer is spied.
|
|
Bytes b;le(b,1,4);le(b,0,1);le(b,3,1);Bytes id;le(id,owner,8);append(b,pack_guid(id));le(b,4,1);
|
|
le(b,this_is_you?0x21:0x20,1);le(b,0,4);le(b,100,4);
|
|
for(float f:{1.f,2.f,3.f,.5f}){le(b,std::bit_cast<uint32_t>(f),4);}
|
|
le(b,0,4);
|
|
for(float f:{2.5f,7.f,4.5f,4.7f,2.5f,3.14f})le(b,std::bit_cast<uint32_t>(f),4);
|
|
le(b,0,1);return {0xa9,std::move(b)};
|
|
}
|
|
std::vector<LegacyPacket> dispatch(NativeWorldTranslation& w,const LegacyPacket& p){
|
|
auto bundle=w.translate(p,0x46010046,100,&codec);Reader r(bundle);auto n=r.le(4);check(n<=1024,"bounded world packet count");std::vector<LegacyPacket> result;
|
|
while(n--){auto op=uint32_t(r.le(4));auto count=r.le(4);result.push_back({op,r.take(count)});}r.end();return result;
|
|
}
|
|
}
|
|
int main(){try{
|
|
// Frozen source/paired-private-membership cases. These exercise the real
|
|
// World lifecycle; the independent profile producer proves membership.
|
|
struct Case {uint8_t cls,source_bit,operation,native_operation,native_bit;bool percent;};
|
|
const Case cases[]{
|
|
{1,2,14,14,126,false}, // spell 72
|
|
{1,11,0,0,126,true}, // spell 72
|
|
{2,3,6,6,126,false}, // spell 465
|
|
{2,6,8,8,126,true}, // spell 465
|
|
{3,0,5,5,127,false}, // spell 75
|
|
{3,0,15,15,127,true}, // spell 75
|
|
{4,2,7,7,127,false}, // spell 53
|
|
{4,2,0,0,127,true}, // spell 53
|
|
{5,0,16,16,127,false}, // spell 17
|
|
{5,6,2,2,123,true}, // spell 139
|
|
{7,28,1,1,125,false}, // spell 315
|
|
{7,0,15,15,125,true}, // spell 315
|
|
{8,0,16,16,127,false}, // spell 10
|
|
{8,19,1,1,127,true}, // spell 10
|
|
{9,1,16,16,124,false}, // spell 172
|
|
{9,17,8,8,125,true}, // spell 128
|
|
{11,1,10,10,127,false}, // spell 99
|
|
{11,3,8,8,127,true}, // spell 99
|
|
};
|
|
for(const auto& c:cases){
|
|
auto w=world(c.cls);const auto source_opcode=c.percent?0x267u:0x266u;
|
|
dispatch(w,modifier(c.source_bit,10,source_opcode,c.operation));
|
|
dispatch(w,modifier(c.source_bit,c.percent?30:17,source_opcode,c.operation));
|
|
auto packets=dispatch(w,self_create());unsigned matched=0;
|
|
for(const auto& p:packets)if(p.opcode==(c.percent?0x690028u:0x690027u) &&
|
|
p.body.size()==14 && p.body[4]==c.native_operation && p.body.back()==c.native_bit){
|
|
Reader r(p.body);check(r.le(4)==1 && r.le(1)==c.native_operation && r.le(4)==1,"group framing");
|
|
check(r.f32()==(c.percent?1.3f:17.f) && r.le(1)==c.native_bit,"group absolute replacement");r.end();++matched;
|
|
}
|
|
check(matched==1,"per-class group replay missing or duplicated");
|
|
}
|
|
// Qualified Renew family: source bit6 -> paired private bit123.
|
|
// Inner Fire mixed-kind scope remains explicitly held in this profile.
|
|
auto priest=world(5);
|
|
auto percentages=[](const std::vector<LegacyPacket>& packets){std::vector<LegacyPacket> out;for(const auto& p:packets)if(p.opcode==0x690028 && p.body.size()==14 && p.body[4]==8 && p.body.back()==123)out.push_back(p);return out;};
|
|
auto points=[](const LegacyPacket& packet,float factor){Reader r(packet.body);check(packet.opcode==0x690028 && r.le(4)==1 && r.le(1)==8 && r.le(4)==1 && r.f32()==factor && r.le(1)==123,"Q106 exact factor/operation/family framing");r.end();};
|
|
check(percentages(dispatch(priest,modifier(6,10,0x267,8))).empty(),"Q106 pre-self emitted");
|
|
check(percentages(dispatch(priest,modifier(6,30,0x267,8))).empty(),"Q106 replacement pre-self emitted");
|
|
check(percentages(dispatch(priest,self_create(false))).empty() && !priest.self_created,"Q106 non-self create admitted replay");
|
|
auto initialized=dispatch(priest,self_create());auto replay=percentages(initialized);
|
|
check(replay.size()==1,"Q106 genuine source effect-percent missing after self create");points(replay[0],1.3f);
|
|
auto self_at=std::find_if(initialized.begin(),initialized.end(),[](const auto& p){return p.opcode==0x5e0000;});
|
|
auto percent_at=std::find_if(initialized.begin(),initialized.end(),[](const auto& p){return p.opcode==0x690028;});
|
|
check(self_at<percent_at,"Q106 replay before native self");
|
|
check(percentages(dispatch(priest,self_create())).empty(),"Q106 duplicate self replay");
|
|
auto repeated=percentages(dispatch(priest,modifier(6,30,0x267,8)));check(repeated.size()==1,"Q106 immediate aggregate missing");points(repeated[0],1.3f);
|
|
auto removed=percentages(dispatch(priest,modifier(6,0,0x267,8)));check(removed.size()==1,"Q106 zero removal missing");points(removed[0],1.f);
|
|
auto reduced=percentages(dispatch(priest,modifier(6,-20,0x267,8)));check(reduced.size()==1,"Q106 negative percentage missing");points(reduced[0],.8f);
|
|
for(auto p:{modifier(2,30,0x267,8),modifier(6,30,0x267,3),modifier(6,30,0x267,26)})check(percentages(dispatch(priest,p)).empty(),"Q106 unqualified operation/family escaped");
|
|
auto bad=modifier(6,30,0x267,8);bad.body.push_back(0);rejects([&]{dispatch(priest,bad);});
|
|
auto malformed=world(5);dispatch(malformed,modifier(6,30,0x267,8));
|
|
auto valid=modifier(6,30,0x267,8);
|
|
for(size_t n=0;n<valid.body.size();++n)rejects([&]{dispatch(malformed,{0x267,Bytes(valid.body.begin(),valid.body.begin()+n)});});
|
|
rejects([&]{dispatch(malformed,modifier(64,30,0x267,8));});
|
|
auto kept=percentages(dispatch(malformed,self_create()));check(kept.size()==1,"Q106 malformed input retired previous source aggregate");points(kept[0],1.3f);
|
|
auto neutral=world(5);dispatch(neutral,modifier(6,0,0x267,8));
|
|
auto zero_replay=percentages(dispatch(neutral,self_create()));check(zero_replay.size()==1,"Q106 initial source zero lost");points(zero_replay[0],1.f);
|
|
auto foreign=world(6);dispatch(foreign,modifier(6,30,0x267,8));check(percentages(dispatch(foreign,self_create())).empty(),"Q106 foreign class");
|
|
// Use the actual far-transfer state machine. The serializer token is
|
|
// independent of this lifetime check; its grammar has a separate fixture.
|
|
for(bool late_update:{false,true}){
|
|
auto moving=world(5);dispatch(moving,modifier(6,30,0x267,8));
|
|
dispatch(moving,self_create());
|
|
moving.entities.self_presentation_ready=true;
|
|
moving.entities.self_position_generation=9;moving.entities.generation=9;
|
|
moving.entities.position_realm=realm;moving.entities.position_map=0;
|
|
Bytes pending;le(pending,0,4);Bytes destination=pending;
|
|
for(float f:{5.f,6.f,7.f,.5f})le(destination,std::bit_cast<uint32_t>(f),4);
|
|
NativeEntityTranslation::Codec token_codec=[](uint32_t,const Bytes& b){return b;};
|
|
moving.receive_far_transfer(0x3f,pending,token_codec);
|
|
check(moving.receive_far_transfer(0x3e,destination,token_codec).size()==2,"modifier transfer refused");
|
|
Bytes token(4);moving.suspend_transfer_response(token);
|
|
moving.local_presentation(0x46010046);
|
|
check(!moving.self_created,"old native self survived NewWorld");
|
|
if(late_update)check(percentages(dispatch(moving,modifier(6,-20,0x267,8))).empty(),"modifier emitted during transfer");
|
|
check(moving.gameplay(0x440025,{}).opcode==0xdc,"worldport acknowledgement");
|
|
moving.gameplay_sent(0x440025,{});
|
|
check(moving.worldport_send_completed(),"worldport send completion");
|
|
moving.local_presentation(0x46010046);
|
|
auto destination_packets=dispatch(moving,self_create());
|
|
auto destination_modifiers=percentages(destination_packets);
|
|
check(destination_modifiers.size()==1,"modifier missing or duplicated after transfer");
|
|
points(destination_modifiers[0],late_update?.8f:1.3f);
|
|
auto self_pos=std::find_if(destination_packets.begin(),destination_packets.end(),[](const auto& p){return p.opcode==0x5e0000;});
|
|
auto modifier_pos=std::find_if(destination_packets.begin(),destination_packets.end(),[](const auto& p){return p.opcode==0x690028;});
|
|
check(self_pos!=destination_packets.end() && self_pos<modifier_pos,"destination modifier precedes self");
|
|
}
|
|
dispatch(priest,{0x4d,{}});check(percentages(dispatch(priest,self_create())).empty(),"Q106 logout leaked source aggregate");
|
|
|
|
std::cout<<"Q106 effect-percent lifecycle PASS\n";return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|