154 lines
11 KiB
C++
154 lines
11 KiB
C++
#include "world_translation.hpp"
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
|
|
int main() {
|
|
NativeWorldTranslation world{};
|
|
world.selected.guid=4509;world.realm=70;
|
|
if(world.authorizes_movement(4509))return EXIT_FAILURE;
|
|
if(world.authorizes_movement(4510))return EXIT_FAILURE;
|
|
auto input=gateway::forever_ground_movement(gateway::GroundMovement{4509,1,100,{1,2,3,0}},70);
|
|
const std::vector<gateway::Character> owned{world.selected};
|
|
try{world.player_movement(0x420000,input,owned);return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
world.self_created=true;
|
|
if(!world.authorizes_movement(4509))return EXIT_FAILURE;
|
|
if(world.authorizes_movement(4510))return EXIT_FAILURE;
|
|
auto first=world.player_movement(0x420000,input,owned);
|
|
gateway::Bytes mover;gateway::le(mover,4509,8);
|
|
if(first.size()!=2 || first[0].opcode!=0x26a || first[0].body!=mover || first[1].opcode!=0xb5)return EXIT_FAILURE;
|
|
if(first[1].body!=gateway::turtle_ground_movement(gateway::GroundMovement{4509,1,100,{1,2,3,0}}))return EXIT_FAILURE;
|
|
if(world.mover_confirmed)return EXIT_FAILURE; // Preparing/sizing is side-effect free.
|
|
world.mover_confirmed=true;
|
|
// User mounted-walking disconnect: actual metadata57bytes/flags82000001,
|
|
// no optional blocks.70334 stores elevation in the fixed float after pitch;
|
|
// Turtle requires a distinct flag and a float after fallTime. This must not
|
|
// become ONTRANSPORT and consume a nonexistent transport GUID.
|
|
auto elevated=input;
|
|
auto elevated_flags=gateway::pack_guid(gateway::forever_player_guid(4509,70)).size();
|
|
elevated[elevated_flags+3]=0x82;
|
|
auto elevation_offset=elevated_flags+8+4+16+4;
|
|
elevated[elevation_offset+2]=0xa0;elevated[elevation_offset+3]=0x3f; //1.25
|
|
auto elevation_move=world.player_movement(0x42002e,elevated,owned);
|
|
if(elevation_move.size()!=1 || elevation_move[0].opcode!=0xee ||
|
|
elevation_move[0].body!=gateway::unhex("01000004640000000000803f000000400000404000000000000000000000a03f"))return EXIT_FAILURE;
|
|
for(size_t n=0;n<elevated.size();++n){
|
|
try{world.player_movement(0x42002e,std::span(elevated).first(n),owned);return EXIT_FAILURE;}
|
|
catch(const gateway::Error&){}
|
|
}
|
|
auto bad_elevation=elevated;bad_elevation[elevation_offset+2]=0x80;bad_elevation[elevation_offset+3]=0x7f;
|
|
try{world.player_movement(0x42002e,bad_elevation,owned);return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
auto swimming=input;
|
|
auto swim_flags=gateway::pack_guid(gateway::forever_player_guid(4509,70)).size();
|
|
swimming[swim_flags+2]=0x10; // Actual57-byte START_FORWARD flags0x100001.
|
|
auto swim_pitch=swim_flags+8+4+16;
|
|
swimming[swim_pitch+2]=0x80;swimming[swim_pitch+3]=0x3e; // .25 radians.
|
|
auto swim=world.player_movement(0x420000,swimming,owned);
|
|
if(swim.size()!=1 || swim[0].opcode!=0xb5)return EXIT_FAILURE;
|
|
// Independent source Read layout: flags/time/position/pitch/fallTime.
|
|
if(swim[0].body!=gateway::unhex("01002000640000000000803f0000004000004040000000000000803e00000000"))return EXIT_FAILURE;
|
|
auto stop_swim=swimming;stop_swim[swim_flags]=0;
|
|
auto swim_stop=world.player_movement(0x420002,stop_swim,owned);
|
|
if(swim_stop[0].body[0]!=0 || swim_stop[0].body[2]!=0x20 || swim_stop[0].body.size()!=32)return EXIT_FAILURE;
|
|
for(size_t n=0;n<swimming.size();++n){
|
|
try{world.player_movement(0x420000,std::span<const uint8_t>(swimming).first(n),owned);return EXIT_FAILURE;}
|
|
catch(const gateway::Error&){}
|
|
}
|
|
auto invalid_swim=swimming;invalid_swim[swim_pitch+2]=0x80;invalid_swim[swim_pitch+3]=0x7f;
|
|
try{world.player_movement(0x420000,invalid_swim,owned);return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
auto next=world.player_movement(0x420000,input,owned);
|
|
if(next.size()!=1 || next[0].opcode!=0xb5 || next[0].body!=first[1].body)return EXIT_FAILURE;
|
|
auto pending=input;auto flag_offset=gateway::pack_guid(gateway::forever_player_guid(4509,70)).size();
|
|
pending[flag_offset+1]=0x28;pending[pending.size()-2]=0x20;
|
|
gateway::le(pending,100,4);gateway::append(pending,gateway::unhex("0000c040809a99193fcdcc4c3f0000e040"));
|
|
auto stopped=world.player_movement(0x420002,pending,owned);
|
|
if(stopped.size()!=1 || stopped[0].opcode!=0xb7 || stopped[0].body[0]!=1 || stopped[0].body[1]!=0x20)return EXIT_FAILURE;
|
|
auto strafe=pending;strafe[flag_offset]=8;strafe[flag_offset+1]=0x48;
|
|
auto strafe_stop=world.player_movement(0x420005,strafe,owned);
|
|
if(strafe_stop.size()!=1 || strafe_stop[0].opcode!=0xba || strafe_stop[0].body[0]!=8 || strafe_stop[0].body[1]!=0x20)return EXIT_FAILURE;
|
|
for(uint32_t intent=0x2000;intent<=0x40000;intent<<=1){
|
|
auto deferred=input;auto flags=uint64_t(1|intent);
|
|
for(unsigned i=0;i<8;++i)deferred[flag_offset+i]=uint8_t(flags>>(8*i));
|
|
if(world.player_movement(0x420000,deferred,owned)[0].body!=first[1].body)return EXIT_FAILURE;
|
|
}
|
|
// Original70334 writer: optional standing surface GUID precedes fall data.
|
|
// Surface metadata must not be mistaken for a fall direction byte or a
|
|
// transport attachment, and has no field in the Turtle world-space packet.
|
|
auto surface=gateway::pack_guid(gateway::unhex("0102030405000000000000000000003c"));
|
|
auto standing=input;standing[standing.size()-2]=0x80;
|
|
gateway::append(standing,surface);
|
|
if(world.player_movement(0x420000,standing,owned)[0].body!=first[1].body)return EXIT_FAILURE;
|
|
auto surface_fall=pending;
|
|
auto options_at=input.size()-2;
|
|
surface_fall[options_at]|=0x80;
|
|
surface_fall.insert(surface_fall.begin()+input.size(),surface.begin(),surface.end());
|
|
if(world.player_movement(0x420002,surface_fall,owned)[0].body!=stopped[0].body)return EXIT_FAILURE;
|
|
// Actual failed packet had TOUCHING_GROUND, forward and options0xa0.
|
|
auto contact=input;contact[flag_offset+3]=0x80;contact[options_at]=0xa0;
|
|
gateway::append(contact,surface);gateway::le(contact,25,4);
|
|
gateway::append(contact,gateway::unhex("0000000000"));
|
|
auto contact_move=world.player_movement(0x420017,contact,owned);
|
|
if(contact_move.size()!=1 || contact_move[0].body.size()!=28 || contact_move[0].body[24]!=25)return EXIT_FAILURE;
|
|
for(size_t n=input.size();n<contact.size();++n){
|
|
try{world.player_movement(0x420017,std::span(contact).first(n),owned);return EXIT_FAILURE;}
|
|
catch(const gateway::Error&){}
|
|
}
|
|
auto transport=standing;transport[options_at]|=0x40;
|
|
try{world.player_movement(0x420000,transport,owned);return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
try{world.player_movement(0x440014,input,owned);return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
auto foreign=world.selected;foreign.guid=4510;
|
|
auto other=gateway::forever_ground_movement(gateway::GroundMovement{4510,1,100,{1,2,3,0}},70);
|
|
try{world.player_movement(0x420000,other,{world.selected,foreign});return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
// Real server near-teleport state owns the ACK's identity/sequence. Preparing
|
|
// an outgoing packet must not consume it (transport capacity retries).
|
|
auto near=gateway::pack_guid(gateway::unhex("9d11000000000000"));
|
|
gateway::le(near,42,4);gateway::append(near,gateway::turtle_ground_movement(gateway::GroundMovement{4509,0,100,{1,-2,3.5,0}}));
|
|
auto ack=gateway::pack_guid(gateway::forever_player_guid(4509,70));gateway::le(ack,42,4);gateway::le(ack,5678,4);
|
|
try{world.player_movement(0x420016,ack,owned);return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
auto bundle=world.translate({0xc7,near},0x46010046,0,nullptr);
|
|
gateway::Reader teleported(bundle);
|
|
if(teleported.le(4)!=1 || teleported.le(4)!=0x600034)return EXIT_FAILURE;
|
|
auto count=teleported.le(4);auto body=teleported.take(count);teleported.end();
|
|
if(body!=gateway::forever_near_teleport(*world.pending_teleport,70))return EXIT_FAILURE;
|
|
for(auto flags:{0x1000u,0x10000000u,0x20000000u,0x40000000u,0x70001000u}){
|
|
NativeWorldTranslation ghost;ghost.selected=world.selected;ghost.realm=70;ghost.self_created=true;
|
|
auto update=near;auto offset=gateway::pack_guid(gateway::unhex("9d11000000000000")).size()+4;
|
|
for(unsigned i=0;i<4;++i)update[offset+i]=uint8_t(flags>>(8*i));
|
|
if(ghost.translate({0xc7,update},0x46010046,0,nullptr)!=bundle || !ghost.pending_teleport)return EXIT_FAILURE;
|
|
for(size_t n=0;n<update.size();++n){
|
|
try{gateway::turtle_near_teleport(std::span(update).first(n),4509);return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
}
|
|
}
|
|
auto acknowledged=world.player_movement(0x420016,ack,owned);
|
|
if(acknowledged.size()!=1 || acknowledged[0].opcode!=0xc7 || acknowledged[0].body!=gateway::unhex("9d110000000000002a0000002e160000"))return EXIT_FAILURE;
|
|
if(!world.pending_teleport || world.pending_teleport->sequence!=42)return EXIT_FAILURE;
|
|
if(world.player_movement(0x420016,ack,owned)[0].body!=acknowledged[0].body)return EXIT_FAILURE;
|
|
for(size_t size=0;size<ack.size();++size){
|
|
try{world.player_movement(0x420016,std::span(ack).first(size),owned);return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
}
|
|
auto wrong=ack;wrong[gateway::pack_guid(gateway::forever_player_guid(4509,70)).size()]^=1;
|
|
try{world.player_movement(0x420016,wrong,owned);return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
try{world.translate({0xc7,near},0x46010046,0,nullptr);return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
if(!world.pending_teleport || world.pending_teleport->sequence!=42)return EXIT_FAILURE;
|
|
// A post-send observation with no matching serialized ACK must not consume
|
|
// the real source teleport. Actual transport supplies the exact packet batch.
|
|
world.mover_confirmed=false;
|
|
for(unsigned variant=0;variant<5;++variant){
|
|
auto submitted=acknowledged;auto intent=ack;
|
|
if(variant==0)submitted.clear();
|
|
if(variant==1)submitted[0].opcode^=1;
|
|
if(variant==2)submitted[0].body.back()^=1;
|
|
if(variant==3)submitted.push_back(submitted[0]);
|
|
if(variant==4)intent.pop_back();
|
|
world.movement_sent(0x420016,intent,submitted);
|
|
if(!world.pending_teleport || world.pending_teleport->sequence!=42 || world.mover_confirmed){
|
|
std::cerr<<"invalid serialized teleport ACK retired source state\n";return EXIT_FAILURE;
|
|
}
|
|
}
|
|
world.movement_sent(0x420016,ack,acknowledged);
|
|
if(world.pending_teleport || world.mover_confirmed)return EXIT_FAILURE;
|
|
std::cout<<"Teleport retirement requires exact serialized ACK; rejected hooks preserve retry state\n";
|
|
NativeWorldTranslation before{};before.selected=world.selected;before.realm=70;
|
|
try{before.translate({0xc7,near},0x46010046,0,nullptr);return EXIT_FAILURE;}catch(const gateway::Error&){}
|
|
return EXIT_SUCCESS;
|
|
}
|