111 lines
8.8 KiB
C++
111 lines
8.8 KiB
C++
#include "world_translation.hpp"
|
|
#include "serializer.h"
|
|
#include "gateway/warrior_cooldown_modifiers.hpp"
|
|
#include "gateway/spell_modifiers.hpp"
|
|
#include <map>
|
|
#include <optional>
|
|
#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;
|
|
}
|
|
std::vector<LegacyPacket> flat(const std::vector<LegacyPacket>& packets){
|
|
std::vector<LegacyPacket> result;for(const auto& p:packets)if(p.opcode==0x690027)result.push_back(p);return result;
|
|
}
|
|
}
|
|
int main(){try{
|
|
auto queued=world();
|
|
check(flat(dispatch(queued,modifier(9,-750))).empty(),"early modifier emitted before native self");
|
|
check(flat(dispatch(queued,modifier(9,-1500))).empty(),"early replacement emitted before native self");
|
|
check(queued.cooldown_flat[9]==-1500 && queued.cooldown_flat_received==(uint64_t(1)<<9),"real aggregate not retained");
|
|
check(flat(dispatch(queued,self_create(false))).empty() && !queued.self_created,"source create without SELF triggered replay");
|
|
const auto calls_before=self_calls;auto created=dispatch(queued,self_create());
|
|
check(queued.self_created && self_calls==calls_before+1,"genuine source self did not invoke native self codec once");
|
|
auto self=std::find_if(created.begin(),created.end(),[](const auto& p){return p.opcode==0x5e0000 && p.body==self_marker;});
|
|
auto mod=std::find_if(created.begin(),created.end(),[](const auto& p){return p.opcode==0x690027;});
|
|
check(self!=created.end() && mod!=created.end() && self<mod,"modifier replay preceded native ThisIsYou initialization");
|
|
// Q106 group runtime: the native projection is the paired group profile's snapshot.
|
|
auto oracle=[](uint8_t cls,uint16_t opcode,uint8_t op,const std::map<uint8_t,int32_t>& vals,std::optional<uint8_t> changed){
|
|
std::array<int32_t,64> v{};for(auto [bit,val]:vals)v[bit]=val;
|
|
auto all=spell_modifier::translate_group_snapshot(cls,op,opcode==0x267?spell_modifier::Kind::Percent:spell_modifier::Kind::Flat,v,~uint64_t(0),changed);
|
|
std::vector<LegacyPacket> out;for(auto& p:all)if(p.opcode==0x690027)out.push_back(p);return out;};
|
|
auto same=[](const std::vector<LegacyPacket>& a,const std::vector<LegacyPacket>& b){
|
|
return a.size()==b.size() && std::equal(a.begin(),a.end(),b.begin(),[](auto& x,auto& y){return x.opcode==y.opcode && x.body==y.body;});};
|
|
check(!oracle(1,0x266,11,{{9,-1500}},std::nullopt).empty(),"warrior flat11 bit 9 has no paired group route");
|
|
check(same(flat(created),oracle(1,0x266,11,{{9,-1500}},std::nullopt)),"queued replacement replay differs from latest group snapshot");
|
|
check(flat(dispatch(queued,self_create())).empty() && self_calls==calls_before+1,"later source create duplicated initial replay");
|
|
auto immediate=flat(dispatch(queued,modifier(9,-2000)));check(!immediate.empty() && same(immediate,oracle(1,0x266,11,{{9,-2000}},9)),"supported source immediate modifier missing");
|
|
auto repeated=flat(dispatch(queued,modifier(9,-2000)));check(same(repeated,immediate),"repeat aggregate became additive or disappeared");
|
|
auto zero=flat(dispatch(queued,modifier(9,0)));check(!zero.empty() && same(zero,oracle(1,0x266,11,{{9,0}},9)),"real zero removal dropped");
|
|
auto other=flat(dispatch(queued,modifier(10,-500)));check(!other.empty() && same(other,oracle(1,0x266,11,{{10,-500}},10)),"matching Revenge family not translated");
|
|
check(flat(dispatch(queued,modifier(9,20,0x267))).empty() && queued.cooldown_percent[9]==20,"percent cooldown retained, never emitted as flat");
|
|
check(queued.cooldown_flat[10]==-500,"flat aggregate not retained");
|
|
const auto received=queued.cooldown_flat_received;
|
|
check(flat(dispatch(queued,modifier(9,-250,0x266,21))).empty() && queued.cooldown_flat_received==received,"source OLD_CAST_TIME aliased to cooldown");
|
|
auto neutral=world();dispatch(neutral,modifier(9,0));auto initial_zero=flat(dispatch(neutral,self_create()));
|
|
check(same(initial_zero,oracle(1,0x266,11,{{9,0}},std::nullopt)),"first genuine pre-self zero not replayed");
|
|
for(uint8_t cls:{uint8_t(6),uint8_t(10)}){
|
|
auto foreign=world(cls);dispatch(foreign,modifier(9,-1000));
|
|
check(same(flat(dispatch(foreign,self_create())),oracle(cls,0x266,11,{{9,-1000}},std::nullopt)),"foreign-class replay differs from its own group routes");
|
|
check(same(flat(dispatch(foreign,modifier(9,-1500))),oracle(cls,0x266,11,{{9,-1500}},9)) && foreign.cooldown_flat[9]==-1500,"foreign-class immediate projection changed");
|
|
}
|
|
auto invalid=world();auto valid=modifier(9,-1500);
|
|
for(size_t n=0;n<valid.body.size();++n)rejects([&]{dispatch(invalid,{0x266,Bytes(valid.body.begin(),valid.body.begin()+n)});});
|
|
auto tail=valid;tail.body.push_back(0);rejects([&]{dispatch(invalid,tail);});rejects([&]{dispatch(invalid,modifier(64,-1500));});
|
|
check(!invalid.cooldown_flat_received,"malformed packet contaminated replay state");
|
|
auto logout=dispatch(queued,{0x4d,{}});check(!queued.self_created && queued.logout_complete && !queued.cooldown_flat_received,"logout retains modifier lifecycle");
|
|
check(std::all_of(queued.cooldown_flat.begin(),queued.cooldown_flat.end(),[](auto v){return v==0;}) &&
|
|
std::all_of(queued.cooldown_percent.begin(),queued.cooldown_percent.end(),[](auto v){return v==0;}),"logout aggregate arrays not cleared");
|
|
auto clean=world();check(flat(dispatch(clean,self_create())).empty(),"new session inherited prior modifier values");
|
|
std::cout<<"Native Warrior flat11 pipeline: genuine source self ordered replay, immediate/absolute/zero, percent+held+class guards, malformed and logout isolation PASS\n";
|
|
return 0;
|
|
}catch(const std::exception& e){std::cerr<<"Native Warrior cooldown pipeline: "<<e.what()<<'\n';return 1;}}
|