79 lines
4.6 KiB
C++
79 lines
4.6 KiB
C++
// Source despawn animation is an event for an existing presentation, not a
|
|
// CREATE or DESTROY. Totems and dynamic objects also use this Source opcode.
|
|
#include "world_translation.hpp"
|
|
#include "gateway/object_updates.hpp"
|
|
#include "gateway/persistent_ground.hpp"
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
static int checks=0,failures=0;
|
|
static void check(bool ok,const char* label){++checks;if(!ok){++failures;std::cerr<<"FAIL "<<label<<'\n';}}
|
|
static constexpr uint64_t object=0xf110000002000124ull,totem=0xf130000001000123ull,ground=0xf100000000000125ull;
|
|
static NativeWorldTranslation world(){
|
|
NativeWorldTranslation w{};w.realm=70;w.selected.guid=4509;w.selected.race=1;w.selected.cls=1;
|
|
w.selected.name="Fixture";w.self_created=true;w.location=WorldLocation{0,{0,0,0,0}};
|
|
for(auto [id,kind]:{std::pair{object,5},std::pair{totem,3},std::pair{ground,6}}){
|
|
NativeEntityTranslation::Actor a{};a.kind=kind;a.sent=true;a.eligible=true;a.generation=1;
|
|
a.presentation_realm=70;a.presentation_map=0;a.entry=kind==5?2:kind==3?1:25;
|
|
a.modern=kind==5?forever_game_object_guid(id,a.entry,70,0):
|
|
kind==3?forever_creature_guid(id,a.entry,70,0):forever_persistent_ground_guid(id,a.entry,70,0);
|
|
w.entities.actors[id]=a;
|
|
}
|
|
return w;
|
|
}
|
|
static Bytes request(uint64_t id){Bytes b;le(b,id,8);return b;}
|
|
static std::vector<Bytes> animations(NativeWorldTranslation& w,const Bytes& body){
|
|
auto wire=w.translate({0x215,body},0x10046,0,nullptr);std::vector<Bytes> out;
|
|
if(wire.empty())return out;
|
|
Reader r(wire);auto count=r.le(4);
|
|
while(count--){auto op=r.le(4),size=r.le(4);auto raw=r.take(size);if(op==0x470069)out.emplace_back(raw.begin(),raw.end());}
|
|
r.end();return out;
|
|
}
|
|
int main(){try{
|
|
auto w=world();
|
|
for(auto id:{object,totem,ground}){
|
|
const auto before=w.entities.actors.at(id);
|
|
check(animations(w,request(id))==std::vector<Bytes>{pack_guid(before.modern)},"loaded source emitter exact packed GUID");
|
|
check(w.entities.actors.at(id).sent && w.entities.actors.at(id).generation==before.generation,"animation does not destroy binding");
|
|
}
|
|
check(animations(w,request(0)).empty(),"zero source rejected");
|
|
check(animations(w,request(88)).empty(),"unknown player cannot synthesize a presentation");
|
|
check(animations(w,request(object+1)).empty(),"unknown gameobject suppressed");
|
|
for(int state=0;state<5;++state){auto x=world();
|
|
if(state==0)x.self_created=false;
|
|
if(state==1)x.location.reset();
|
|
if(state==2)x.logout_complete=true;
|
|
if(state==3)x.pending_teleport=NearTeleport{};
|
|
if(state==4)x.far_transfer=NativeWorldTranslation::FarTransfer{};
|
|
check(animations(x,request(object)).empty(),"inactive world suppresses despawn animation");
|
|
}
|
|
for(int state=0;state<9;++state){auto x=world();auto& a=x.entities.actors.at(object);
|
|
if(state==0)a.sent=false;
|
|
if(state==1)a.eligible=false;
|
|
if(state==2)a.generation=0;
|
|
if(state==3)a.presentation_realm=71;
|
|
if(state==4)a.presentation_map=1;
|
|
if(state==5)a.modern={};
|
|
if(state==6)a.kind=1;
|
|
if(state==7)a.kind=2;
|
|
if(state==8)a.kind=0;
|
|
check(animations(x,request(object)).empty(),"unloaded stale or nonworld actor suppressed");
|
|
}
|
|
// Source sends the animation before removal. A late animation after the
|
|
// genuine destroy must not revive the previous presentation.
|
|
(void)w.translate({0xaa,request(object)},0x10046,0,nullptr);
|
|
check(!w.entities.actors.contains(object),"source destroy retires object");
|
|
check(animations(w,request(object)).empty(),"late animation suppressed after destroy");
|
|
auto fresh=world().entities.actors.at(object);fresh.generation=2;fresh.presentation_map=1;fresh.modern=forever_game_object_guid(object,2,70,1);
|
|
w.location->map=1;
|
|
w.entities.actors[object]=fresh;
|
|
check(animations(w,request(object))==std::vector<Bytes>{pack_guid(fresh.modern)},"new presentation uses replacement GUID only");
|
|
(void)w.translate({0x4d,{}},0x10046,0,nullptr);
|
|
check(animations(w,request(object)).empty(),"source logout retires object route");
|
|
check(animations(w,request(w.selected.guid)).empty(),"source logout cannot use self fallback");
|
|
for(int size=0;size<=9;++size){if(size==8)continue;auto x=world();auto bad=request(object);bad.resize(size);bool rejected=false;
|
|
try{(void)animations(x,bad);}catch(const Error&){rejected=true;}
|
|
check(rejected,"truncated or oversized framing rejected");
|
|
}
|
|
std::cout<<checks<<" despawn-animation lifecycle checks; failures="<<failures<<'\n';return failures?1:0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|