98 lines
5.8 KiB
C++
98 lines
5.8 KiB
C++
#include "world_translation.hpp"
|
|
#include "gateway/turtle_combat_logs.hpp"
|
|
#include <iostream>
|
|
#include <source_location>
|
|
using namespace gateway;
|
|
namespace {
|
|
void check(bool ok,const std::source_location at=std::source_location::current()) {
|
|
if(!ok)throw Error("combat route fixture line "+std::to_string(at.line()));
|
|
}
|
|
Bytes full(uint64_t guid){Bytes b;le(b,guid,8);return b;}
|
|
Bytes packed(uint64_t guid){return pack_guid(full(guid));}
|
|
NativeWorldTranslation world(){
|
|
NativeWorldTranslation w{};w.selected.guid=4514;w.selected.race=1;w.selected.cls=1;w.realm=70;
|
|
w.self_created=true;w.location=WorldLocation{0,{0,0,0,0}};
|
|
return w;
|
|
}
|
|
Bytes output(NativeWorldTranslation& w,uint32_t source,const Bytes& body) {
|
|
return w.translate({source,body},0x46010046,0,nullptr);
|
|
}
|
|
void single(NativeWorldTranslation& w,uint32_t source,const Bytes& body,uint32_t opcode,const Bytes& expected){
|
|
auto bundle=output(w,source,body);Reader r(bundle);check(r.le(4)==1);check(r.le(4)==opcode);
|
|
auto size=r.le(4);check(r.take(size)==expected);r.end();
|
|
}
|
|
}
|
|
int main(){try{
|
|
constexpr uint64_t actor=(0xf130ULL<<48)|(9010ULL<<24)|99;
|
|
constexpr uint64_t unknown=(0xf130ULL<<48)|(9010ULL<<24)|100;
|
|
auto w=world();NativeEntityTranslation::Actor a;
|
|
a.kind=3;a.entry=9010;a.modern=forever_creature_guid(actor,9010,w.realm,0);a.sent=true;a.generation=1;
|
|
w.entities.actors[actor]=a;
|
|
const auto initial_bindings=w.bindings();const auto actor_guid=pack_guid(a.modern);
|
|
const auto self_guid=pack_guid(forever_player_guid(w.selected.guid,w.realm));
|
|
// Source spell IDs above65535 remain32-bit throughout both qualified routes.
|
|
Bytes heal=packed(actor);append(heal,packed(w.selected.guid));le(heal,65536,4);le(heal,777,4);le(heal,1,1);
|
|
Bytes heal_expected=actor_guid;append(heal_expected,self_guid);le(heal_expected,65536,4);le(heal_expected,777,4);le(heal_expected,777,4);
|
|
le(heal_expected,0xffffffffu,4);le(heal_expected,0,4);le(heal_expected,0,4);le(heal_expected,0x80,1);
|
|
single(w,0x150,heal,0x69000a,heal_expected);
|
|
// Source victim is FULL64; native GUID is the authenticated typed binding.
|
|
Bytes env=full(actor);le(env,2,1);le(env,100,4);le(env,7,4);le(env,uint32_t(-3),4);
|
|
Bytes env_expected=actor_guid;le(env_expected,2,1);le(env_expected,100,4);le(env_expected,uint32_t(-3),4);le(env_expected,7,4);le(env_expected,0,1);
|
|
single(w,0x1fc,env,0x69000e,env_expected);
|
|
Bytes immune=full(w.selected.guid);append(immune,full(actor));le(immune,65537,4);le(immune,0,1);
|
|
Bytes immune_expected=self_guid;append(immune_expected,actor_guid);le(immune_expected,65537,4);le(immune_expected,0,1);
|
|
single(w,0x263,immune,0x69001d,immune_expected);
|
|
// No Source-derived actor/health/spell state is invented by log delivery.
|
|
check(w.bindings()==initial_bindings&&!w.source_health&&w.spells.empty());
|
|
for(auto source:{0x150u,0x1fcu,0x263u}) {
|
|
const auto& body=source==0x150?heal:source==0x1fc?env:immune;
|
|
w.self_created=false;check(output(w,source,body)==Bytes(4));w.self_created=true;
|
|
w.entities.actors.at(actor).sent=false;check(output(w,source,body)==Bytes(4));w.entities.actors.at(actor).sent=true;
|
|
}
|
|
auto foreign_heal=packed(unknown);append(foreign_heal,packed(w.selected.guid));le(foreign_heal,65536,4);le(foreign_heal,777,4);le(foreign_heal,0,1);
|
|
check(output(w,0x150,foreign_heal)==Bytes(4));
|
|
auto foreign_env=full(unknown);append(foreign_env,std::span(env).subspan(8));check(output(w,0x1fc,foreign_env)==Bytes(4));
|
|
auto foreign_immune=full(unknown);append(foreign_immune,std::span(immune).subspan(8));check(output(w,0x263,foreign_immune)==Bytes(4));
|
|
auto unsupported_heal=heal;unsupported_heal.back()=2;check(output(w,0x150,unsupported_heal)==Bytes(4));
|
|
auto oversized_heal=packed(actor);append(oversized_heal,packed(w.selected.guid));le(oversized_heal,65536,4);le(oversized_heal,0x80000000u,4);le(oversized_heal,0,1);
|
|
check(output(w,0x150,oversized_heal)==Bytes(4));
|
|
auto oversized_env=env;oversized_env[12]=0x80;check(output(w,0x1fc,oversized_env)==Bytes(4));
|
|
oversized_env=env;oversized_env[16]=0x80;check(output(w,0x1fc,oversized_env)==Bytes(4));
|
|
auto unsupported_env=env;unsupported_env[8]=6;check(output(w,0x1fc,unsupported_env)==Bytes(4));
|
|
auto unsupported_immune=immune;unsupported_immune.back()=1;check(output(w,0x263,unsupported_immune)==Bytes(4));
|
|
single(w,0x29c,{},0x470189,self_guid);
|
|
check(output(w,0x29c,{1})==Bytes(4));
|
|
auto delay=full(w.selected.guid);
|
|
le(delay,300,4);
|
|
auto expected_delay=self_guid;
|
|
le(expected_delay,300,4);
|
|
single(w,0x1e2,delay,0x690032,expected_delay);
|
|
auto foreign_delay=full(unknown);
|
|
le(foreign_delay,300,4);
|
|
check(output(w,0x1e2,foreign_delay)==Bytes(4));
|
|
auto kill=full(w.selected.guid);
|
|
append(kill,full(actor));
|
|
auto expected_kill=self_guid;
|
|
append(expected_kill,actor_guid);
|
|
single(w,0x1f5,kill,0x470205,expected_kill);
|
|
auto remote=full(4515);
|
|
append(remote,full(4516));
|
|
auto remote_expected=pack_guid(forever_player_guid(4515,w.realm));
|
|
append(remote_expected,pack_guid(forever_player_guid(4516,w.realm)));
|
|
single(w,0x1f5,remote,0x470205,remote_expected);
|
|
w.entities.actors.at(actor).sent=false;
|
|
check(output(w,0x1f5,kill)==Bytes(4));
|
|
w.entities.actors.at(actor).sent=true;
|
|
w.self_created=false;
|
|
check(output(w,0x29c,{})==Bytes(4));
|
|
check(output(w,0x1e2,delay)==Bytes(4));
|
|
check(output(w,0x1f5,kill)==Bytes(4));
|
|
w.self_created=true;
|
|
check(output(w,0x1e2,{1})==Bytes(4));
|
|
check(output(w,0x1f5,{1})==Bytes(4));
|
|
for(auto source:{0x151u,0x24bu,0x1f5u,0x27bu})check(output(w,source,{})==Bytes(4));
|
|
check(w.bindings()==initial_bindings&&!w.source_health&&w.spells.empty());
|
|
std::cout<<"Combat log, party kill, spell pushback and auto-repeat cancellation routes PASS\n";
|
|
return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|