Files
WoW-Hybrid-gateway/tests/native_talent_far_transfer_test.cpp

72 lines
4.6 KiB
C++

// Same authenticated character's learned spells outlive a map's self actor.
// This tests bridge lifecycle, not native UI/runtime acceptance.
#include "world_translation.hpp"
#include <bit>
#include <iostream>
using namespace gateway;
static void check(bool ok){if(!ok)throw Error("talent far-transfer lifecycle assertion");}
static NativeWorldTranslation character(uint64_t guid=4509){
NativeWorldTranslation w{};w.selected.guid=guid;w.selected.race=1;w.selected.cls=1;
w.realm=70;w.self_created=true;w.location=WorldLocation{1,{5,6,7,0.5f}};
return w;
}
static uint32_t initial(NativeWorldTranslation& w,std::initializer_list<uint16_t> spells){
Bytes b{0};le(b,spells.size(),2);for(auto s:spells){le(b,s,2);le(b,0,2);}le(b,0,2);
auto bundle=w.translate({0x12a,std::move(b)},0x46010046,0,nullptr);
Reader reader(bundle);check(reader.le(4)>=4);return uint32_t(reader.le(4));
}
static void create(NativeWorldTranslation& w){
LegacyObjectUpdate u;u.kind=3;u.type=4;u.guid=w.selected.guid;
u.fields={{34,60},{36,257}};w.observe_talent_updates({u});
}
static bool contains(const std::vector<LegacyPacket>& packets,const std::string& text){
for(const auto& p:packets){std::string body(p.body.begin(),p.body.end());if(body.find(text)!=std::string::npos)return true;}
return false;
}
int main(){try{
auto w=character();check(initial(w,{78,12285})==0x47007a);create(w);
check(w.talent_ready() && w.talent_points==0);
w.talent_snapshot_pending=true;w.take_talent_presentation(0x46010046);
const auto previous_sequence=w.talent_sequence;
w.entities.self_presentation_ready=true;w.entities.self_position_generation=9;
w.entities.generation=9;w.entities.position_realm=70;w.entities.position_map=1;
Bytes pending;le(pending,35,4);Bytes destination=pending;
for(float f:{-0.91f,40.57f,-24.23f,0.5f})le(destination,std::bit_cast<uint32_t>(f),4);
// Writer grammar is already verified by the original far-transfer fixture.
// This distinct check needs only a serializer token to drive the real helper.
NativeEntityTranslation::Codec codec=[](uint32_t,const Bytes& b){return b;};
w.receive_far_transfer(0x3f,pending,codec);check(w.receive_far_transfer(0x3e,destination,codec).size()==2);
Bytes token(4);w.suspend_transfer_response(token);w.local_presentation(0x46010046);
check(w.gameplay(0x440025,{}).opcode==0xdc);w.gameplay_sent(0x440025,{});
check(w.worldport_send_completed());w.local_presentation(0x46010046);
// Source HandleMoveWorldportAck sends initial spells BEFORE Map::Add's
// full self create. Both that ordering and removal/recreate must work.
LegacyObjectUpdate removal;removal.kind=4;removal.removed={4509};
w.observe_talent_updates({removal});check(!w.talent_ready());
check(initial(w,{78,12664})==0x47007a);
check(initial(w,{78,12664})==0x690019);
check(w.talent_spells_ready && !w.talent_ready());
create(w);check(!w.talent_ready());w.self_created=true;
check(w.talent_ready() && w.talent_points==0 && !w.spells.contains(12285));
std::optional<LegacyPacket> outgoing;check(w.talent_control(".gwtalent state",outgoing) && !outgoing);
auto shown=w.take_talent_presentation(0x46010046);
check(contains(shown,"GWTURTLE1 BEGIN "+std::to_string(previous_sequence+1)+" 4509 1 60 0 2"));
check(contains(shown,"78,12664") && w.talent_sequence==previous_sequence+1);
// The known-spell proof survives another full generation even without a
// redundant snapshot, but unit metadata must be repopulated before use.
w.observe_talent_updates({removal});check(w.talent_spells_ready && !w.talent_ready());
create(w);check(w.talent_ready());
Bytes removed;le(removed,12664,2);w.translate({0x203,removed},0x46010046,0,nullptr);
check(!w.spells.contains(12664) && w.talent_spells_ready);
Bytes learned;le(learned,12285,4);w.translate({0x12b,learned},0x46010046,0,nullptr);
check(w.spells.contains(12285));
// Session character entry constructs a fresh translator, including when
// selecting the same character again. No old snapshot may authorize it.
for(uint64_t guid:{4509u,4510u}){
auto fresh=character(guid);create(fresh);check(!fresh.talent_spells_ready && !fresh.talent_ready() && fresh.spells.empty());
check(fresh.talent_control(".gwtalent state",outgoing) && fresh.talent_notice=="GWTURTLE1 ERROR state-not-ready");
}
std::cout<<"PASS same-session far transfer, source initial-before-create, removal/recreate, fresh points, known-spell deltas and fresh-session refusal\n";
return 0;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}