939 lines
69 KiB
C++
939 lines
69 KiB
C++
#include "optional_test_codec.hpp"
|
|
#include "entity_translation.hpp"
|
|
#include "fixtures/character_creation_tauren_70334.hpp"
|
|
#include "gateway/character_creation.hpp"
|
|
#include "serializer.h"
|
|
#include "gateway/turtle_entity_profile.hpp"
|
|
#include "gateway/gameplay.hpp"
|
|
#include "gateway/unit_presentation.hpp"
|
|
#include "gateway/object_updates.hpp"
|
|
#include "gateway/corpse.hpp"
|
|
#include "world_translation.hpp"
|
|
#include "gateway/exploration.hpp"
|
|
#include <algorithm>
|
|
#include <bit>
|
|
#include <dlfcn.h>
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <iterator>
|
|
#include <source_location>
|
|
#include <tuple>
|
|
#include <zlib.h>
|
|
using namespace gateway;
|
|
static void expect(bool condition,const std::source_location& at=std::source_location::current()){
|
|
if(!condition)throw Error("native entity fixture assertion at line "+std::to_string(at.line()));
|
|
}
|
|
static Bytes packed(uint64_t guid){Bytes b;le(b,guid,8);return pack_guid(b);}
|
|
static LegacyPacket npc(uint32_t entry,uint64_t guid,uint8_t cls=1,uint8_t kind=3,const std::map<uint16_t,uint32_t>& extra={},std::optional<uint64_t> melee={},float walk=2.5f,bool spline=false){
|
|
std::map<uint16_t,uint32_t> f{{3,entry},{4,std::bit_cast<uint32_t>(1.f)},{22,80},{28,80},{34,1},{35,1},{36,uint32_t(cls)<<8|1},{131,19723},{132,19723}};
|
|
if(kind==5)f[21]=11; // Unsupported transport: must remain visible in diagnostics, not be serialized as a static GO.
|
|
for(auto [index,value]:extra)f[index]=value;
|
|
Bytes b;le(b,1,4);le(b,0,1);le(b,3,1);append(b,packed(guid));le(b,kind,1);le(b,melee?0x24:0x20,1);le(b,spline?0x400000:0,4);le(b,100,4);
|
|
for(float v:{1.f,2.f,3.f,0.f})le(b,std::bit_cast<uint32_t>(v),4);le(b,0,4);
|
|
for(float v:{walk,7.f,4.5f,4.72f,2.5f,3.14f})le(b,std::bit_cast<uint32_t>(v),4);
|
|
if(spline){le(b,0,4);for(auto v:{111,222,333,1})le(b,v,4);for(float v:{1.25f,2.5f,3.75f,4.f,5.f,6.f})le(b,std::bit_cast<uint32_t>(v),4);}
|
|
if(melee)append(b,packed(*melee));
|
|
std::vector<uint32_t> mask(f.rbegin()->first/32+1);for(auto [index,value]:f){(void)value;mask[index/32]|=uint32_t(1)<<(index%32);}
|
|
le(b,mask.size(),1);for(auto word:mask)le(b,word,4);for(auto [index,value]:f){(void)index;le(b,value,4);}return {0xa9,b};
|
|
}
|
|
static LegacyPacket attack(uint64_t attacker,uint64_t victim,bool stopped=false){
|
|
Bytes b;
|
|
if(stopped){append(b,packed(attacker));append(b,packed(victim));le(b,0,4);}
|
|
else{le(b,attacker,8);le(b,victim,8);}
|
|
return {stopped?0x144u:0x143u,std::move(b)};
|
|
}
|
|
static LegacyPacket combat_movement(uint64_t owner,uint64_t victim){
|
|
Bytes b;le(b,1,4);le(b,0,1);le(b,1,1);le(b,owner,8);le(b,4,1);append(b,packed(victim));return {0xa9,std::move(b)};
|
|
}
|
|
static LegacyPacket gameobject(uint64_t guid,uint32_t type,uint32_t display){
|
|
std::map<uint16_t,uint32_t> fields{{3,9010},{4,std::bit_cast<uint32_t>(1.f)},{8,display},{13,std::bit_cast<uint32_t>(1.f)},{14,1},{21,type}};
|
|
Bytes b;le(b,1,4);le(b,0,1);le(b,3,1);append(b,packed(guid));le(b,5,1);le(b,0x40,1);
|
|
for(float v:{1.f,2.f,3.f,0.f})le(b,std::bit_cast<uint32_t>(v),4);
|
|
le(b,1,1);uint32_t mask=0;for(auto [i,v]:fields){(void)v;mask|=1u<<i;}le(b,mask,4);for(auto [i,v]:fields){(void)i;le(b,v,4);}return {0xa9,std::move(b)};
|
|
}
|
|
static LegacyPacket corpse(uint64_t guid,uint64_t owner){
|
|
std::map<uint16_t,uint32_t> fields{{4,std::bit_cast<uint32_t>(1.f)},{6,uint32_t(owner)},{7,uint32_t(owner>>32)},{12,20585},{32,6u<<8},{35,4}};
|
|
Bytes b;le(b,1,4);le(b,0,1);le(b,3,1);append(b,packed(guid));le(b,7,1);le(b,0x40,1);
|
|
for(float v:{1.f,2.f,3.f,0.f})le(b,std::bit_cast<uint32_t>(v),4);
|
|
std::array<uint32_t,2> masks{};for(auto [i,v]:fields){(void)v;masks[i/32]|=1u<<(i%32);}
|
|
le(b,2,1);for(auto m:masks)le(b,m,4);for(auto [i,v]:fields){(void)i;le(b,v,4);}return {0xa9,b};
|
|
}
|
|
static LegacyPacket spline(uint64_t guid){
|
|
auto b=packed(guid);for(float v:{1.f,2.f,3.f})le(b,std::bit_cast<uint32_t>(v),4);
|
|
le(b,42,4);le(b,0,1);le(b,0x100,4);le(b,5000,4);le(b,1,4);
|
|
for(float v:{5.f,6.f,3.f})le(b,std::bit_cast<uint32_t>(v),4);return {0xdd,b};
|
|
}
|
|
static LegacyPacket spline_stop(uint64_t guid){
|
|
auto b=packed(guid);for(float v:{4.f,5.f,3.f})le(b,std::bit_cast<uint32_t>(v),4);
|
|
le(b,43,4);le(b,1,1);return {0xdd,b};
|
|
}
|
|
static LegacyPacket compressed(const LegacyPacket& packet){
|
|
Bytes records;le(records,packet.body.size()+2,1);le(records,packet.opcode,2);append(records,packet.body);
|
|
uLongf length=compressBound(records.size());Bytes z(length);
|
|
expect(compress2(z.data(),&length,records.data(),records.size(),Z_DEFAULT_COMPRESSION)==Z_OK);z.resize(length);
|
|
Bytes b;le(b,records.size(),4);append(b,z);return {0x2fb,b};
|
|
}
|
|
static LegacyPacket metadata(uint32_t entry,uint32_t type=7,uint32_t display=19723,const char* name="Source trainer"){
|
|
Bytes b;le(b,entry,4);cstring(b,name);for(unsigned i=0;i<3;++i)cstring(b,"");cstring(b,"Trainer");
|
|
for(auto value:{0u,type,0u,0u,0u,0u,display})le(b,value,4);le(b,0,1);le(b,0,1);return {0x61,b};
|
|
}
|
|
static LegacyPacket values(uint64_t guid,const std::map<uint16_t,uint32_t>& fields){
|
|
Bytes b;le(b,1,4);le(b,0,1);le(b,0,1);append(b,packed(guid));
|
|
auto n=fields.rbegin()->first/32+1;le(b,n,1);std::vector<uint32_t> mask(n);
|
|
for(auto [index,value]:fields){(void)value;mask[index/32]|=1u<<(index%32);}
|
|
for(auto word:mask)le(b,word,4);for(auto [index,value]:fields){(void)index;le(b,value,4);}return {0xa9,b};
|
|
}
|
|
static void rest_state(const Character& self, decltype(&gw_codec_serialize) encode) {
|
|
NativeWorldTranslation world;
|
|
world.selected = self;
|
|
world.realm = 70;
|
|
uint64_t clock = 0;
|
|
auto dispatch = [&](const LegacyPacket& packet) {
|
|
return world.translate(packet, 0x46010046, ++clock, encode);
|
|
};
|
|
|
|
// Tortoise sends a zero rest timestamp before the player enters the map.
|
|
const LegacyPacket login_rest{0x21e, Bytes(4, 0)};
|
|
expect(dispatch(login_rest) == Bytes(4, 0));
|
|
world.location = WorldLocation{0, {0, 0, 0, 0}};
|
|
world.self_created = true;
|
|
world.entities.self_presentation_ready = true;
|
|
|
|
// One UpdateObject for the selected player's PlayerFlags field. Keep the
|
|
// AFK bit while entering/leaving rest, then explicitly clear all flags.
|
|
const Bytes update_header = unhex(
|
|
"000001000000801d0000000003e09d111801081100000001000340000000002000080020");
|
|
for (uint32_t flags : {0x02u, 0x22u, 0x02u, 0x00u}) {
|
|
Bytes expected = update_header;
|
|
le(expected, flags, 4);
|
|
auto batch = dispatch(values(self.guid, {{turtle_entity_fields::PLAYER_FLAGS, flags}}));
|
|
Reader reader(batch);
|
|
unsigned matches = 0;
|
|
for (auto left = reader.le(4); left; --left) {
|
|
auto opcode = reader.le(4);
|
|
auto body = reader.take(reader.le(4));
|
|
if (opcode == 0x5e0000) {
|
|
expect(body == expected);
|
|
++matches;
|
|
}
|
|
}
|
|
reader.end();
|
|
expect(matches == 1);
|
|
}
|
|
std::cout << "PASS login rest timestamp consumed; PlayerFlags set, preserve and clear through world dispatch\n";
|
|
}
|
|
|
|
int main(int argc,char** argv){
|
|
const bool appearance_only=argc>1 && std::string_view(argv[1])=="--appearance-only";
|
|
const bool profession_only=argc>1 && std::string_view(argv[1])=="--profession-only";
|
|
const bool exploration_only=argc>1 && std::string_view(argv[1])=="--exploration-only";
|
|
const bool creature_walk_only=argc>1 && std::string_view(argv[1])=="--creature-walk-only";
|
|
const bool creature_type_only=argc>1 && std::string_view(argv[1])=="--creature-type-only";
|
|
const bool rest_only=argc>1 && std::string_view(argv[1])=="--rest-only";
|
|
const char* codec_path=(appearance_only || profession_only || exploration_only || creature_walk_only || creature_type_only || rest_only) && argc>2?argv[2]:GW_ENTITY_CODEC;
|
|
if (test_fixture::optional_codec_missing(codec_path)) return 77;
|
|
void* library = dlopen(codec_path, RTLD_NOW | RTLD_LOCAL);
|
|
if (!library) {
|
|
std::cerr << dlerror() << '\n';
|
|
return 1;
|
|
}
|
|
auto encode=reinterpret_cast<decltype(&gw_codec_serialize)>(dlsym(library,"gw_codec_serialize"));
|
|
if(!encode)return EXIT_FAILURE;
|
|
std::vector<std::pair<uint32_t,Bytes>> npc_inputs;
|
|
NativeEntityTranslation::Codec codec=[&](uint32_t mode,const Bytes& in){
|
|
if(creature_walk_only && (mode==GW_CODEC_NPCS_TYPES || mode==GW_CODEC_NPCS_COMBAT))npc_inputs.emplace_back(mode,in);
|
|
uint32_t n=0;expect(encode(mode,in.data(),uint32_t(in.size()),0,nullptr,0,&n)==GW_CODEC_CAPACITY);
|
|
Bytes out(n);expect(encode(mode,in.data(),uint32_t(in.size()),0,out.data(),n,&n)==GW_CODEC_OK);return out;
|
|
};
|
|
Character self{};self.guid=4509;self.name="Fixture";self.race=1;self.cls=1;self.gender=0;self.zone=12;
|
|
if (rest_only || argc == 1) {
|
|
rest_state(self, encode);
|
|
if (rest_only) return EXIT_SUCCESS;
|
|
}
|
|
auto run=[&](NativeEntityTranslation& state,const LegacyPacket& p){return state.translate(p,self,70,0x46010046,0,codec);};
|
|
if (creature_type_only || argc == 1) {
|
|
// Public Tortoise creature_template 90990 (Cherry) is type 0, display 15396.
|
|
// A mixed batch must keep both actors when the last genuine template arrives.
|
|
constexpr uint32_t generic_entry=90990, typed_entry=9;
|
|
const uint64_t generic_guid=(0xf130ULL<<48)|(uint64_t(generic_entry)<<24)|101;
|
|
const uint64_t typed_guid=(0xf130ULL<<48)|(uint64_t(typed_entry)<<24)|102;
|
|
auto batch=npc(generic_entry,generic_guid,1,3,{{35,35},{131,15396},{132,15396}});
|
|
auto other=npc(typed_entry,typed_guid);
|
|
batch.body[0]=2;
|
|
append(batch.body,std::span(other.body).subspan(5));
|
|
NativeEntityTranslation state;
|
|
expect(run(state,batch).empty() && state.queries.size()==2);
|
|
expect(run(state,metadata(typed_entry)).size()==1);
|
|
Bytes profile;
|
|
NativeEntityTranslation::Codec capture=[&](uint32_t mode,const Bytes& input){
|
|
if(mode==GW_CODEC_NPCS_TYPES)profile=input;
|
|
return codec(mode,input);
|
|
};
|
|
auto ready=state.translate(metadata(generic_entry,0,15396,"Cherry"),self,70,0x46010046,0,capture);
|
|
expect(ready.size()==2 && ready[0].opcode==0x4b0006 && ready[1].opcode==0x5e0000);
|
|
expect(state.actors.at(generic_guid).sent && state.actors.at(typed_guid).sent);
|
|
expect(state.templates.at(generic_entry).type==0 && state.templates.at(typed_entry).type==7);
|
|
Reader created(ready[1].body);expect(created.le(2)==0 && created.le(4)==2);
|
|
Reader header(profile);header.take(30);header.cstring();header.take(3);
|
|
expect(header.le(4)==2);
|
|
const size_t entries_offset=profile.size()-header.left();
|
|
expect(header.le(4)==typed_entry && header.le(1)==7);
|
|
expect(header.le(4)==generic_entry && header.le(1)==0);
|
|
const size_t generic_type=profile.size()-header.left()-1;
|
|
auto upper=profile;upper[generic_type]=15;
|
|
auto upper_create=codec(GW_CODEC_NPCS_TYPES,upper);
|
|
expect(upper_create.size()==ready[1].body.size());
|
|
size_t changed=0;
|
|
for(size_t i=0;i<upper_create.size();++i)if(upper_create[i]!=ready[1].body[i]){
|
|
expect(upper_create[i]==15 && ready[1].body[i]==0);
|
|
++changed;
|
|
}
|
|
expect(changed==1);
|
|
auto reject=[&](const Bytes& input){
|
|
uint32_t size=0;
|
|
expect(encode(GW_CODEC_NPCS_TYPES,input.data(),uint32_t(input.size()),0,nullptr,0,&size)==GW_CODEC_PACKET);
|
|
};
|
|
auto bad=profile;bad[generic_type]=16;reject(bad);
|
|
for (uint32_t entry : {0u,0x800000u,typed_entry}) {
|
|
bad=profile;
|
|
for(unsigned i=0;i<4;++i)bad[entries_offset+5+i]=uint8_t(entry>>(8*i));
|
|
reject(bad);
|
|
}
|
|
if(creature_type_only){
|
|
dlclose(library);
|
|
std::cout<<"Mixed creature metadata type 0/7, exact zero/15 create field and entry/type bounds passed\n";
|
|
return 0;
|
|
}
|
|
}
|
|
if (appearance_only || argc == 1) {
|
|
using namespace gateway::turtle_entity_fields;
|
|
// The captured native create requests independently identify the
|
|
// sorted option/choice words that the player-values writer must send.
|
|
auto expected = [](size_t i) {
|
|
auto body = unhex(std::string(CreationFixtures[i].native_hex));
|
|
auto request = character_creation::parse_request(character_creation::NativeCreateOpcode, body);
|
|
Bytes pairs;
|
|
for (const auto& [option, choice] : request.customizations) {
|
|
le(pairs, option, 4);
|
|
le(pairs, choice, 4);
|
|
}
|
|
return pairs;
|
|
};
|
|
const auto first = expected(0), second = expected(1);
|
|
auto tauren = self;
|
|
tauren.race = 6;
|
|
tauren.cls = 5;
|
|
NativeEntityTranslation state;
|
|
auto view = [&](const LegacyPacket& p) { return state.translate(p, tauren, 70, 0x46010046, 0, codec); };
|
|
auto update = [&](uint16_t field, uint32_t value, const Bytes& tail) {
|
|
const auto packets = view(values(self.guid, {{field, value}}));
|
|
expect(packets.size() == 1 && packets.front().opcode == 0x5e0000);
|
|
const auto& bytes = packets.front().body;
|
|
expect(bytes.size() > tail.size() && std::equal(tail.rbegin(), tail.rend(), bytes.rbegin()));
|
|
};
|
|
view(npc(1, self.guid, 5, 4, {{UNIT_FIELD_BYTES_0, 0x506}, {PLAYER_BYTES_2, 1}}));
|
|
// An omitted body word is zero on a create. Sparse updates then
|
|
// move between two known appearances one Source word at a time.
|
|
view(values(self.guid, {{PLAYER_BYTES, 0x01030201}}));
|
|
update(PLAYER_BYTES_2, 2, second);
|
|
view(values(self.guid, {{PLAYER_BYTES_2, 1}}));
|
|
update(PLAYER_BYTES, 0, first);
|
|
// Bytes 2/3 of 0x02040001 are the purchased bank-bag count (4) and the XP rest state
|
|
// (2): both are real ActivePlayerData changes, so this update is no longer silent.
|
|
expect(!view(values(self.guid, {{PLAYER_BYTES_2, 0x02040001}})).empty());
|
|
Bytes removed;
|
|
le(removed, self.guid, 8);
|
|
view({0xaa, removed});
|
|
expect(view(values(self.guid, {{PLAYER_BYTES_2, 2}})).empty());
|
|
const auto before_create = view(values(self.guid, {{UNIT_FIELD_BYTES_0, 0x506},
|
|
{PLAYER_BYTES, 0x01030201}, {PLAYER_BYTES_2, 2}}));
|
|
for (const auto& packet : before_create) {
|
|
expect(std::search(packet.body.begin(), packet.body.end(), second.begin(), second.end()) == packet.body.end());
|
|
}
|
|
// Source spell 64945 changes PLAYER_BYTES while display 15435 is
|
|
// active, then restores the native display in a later self delta.
|
|
// The restore must carry the current customization again.
|
|
NativeEntityTranslation morph;
|
|
auto shown=[&](const LegacyPacket& p){return morph.translate(p,tauren,70,0x46010046,0,codec);};
|
|
auto pairs=[](uint8_t skin){
|
|
Bytes out;
|
|
for(const auto& pair:character_creation::source_presentation_choices(6,0,
|
|
std::array<uint8_t,5>{skin,0,0,0,1})){
|
|
le(out,pair[0],4);le(out,pair[1],4);
|
|
}
|
|
return out;
|
|
};
|
|
auto has_tail=[](const std::vector<LegacyPacket>& packets,const Bytes& tail){
|
|
return std::any_of(packets.begin(),packets.end(),[&](const auto& packet){
|
|
return packet.opcode==0x5e0000 && packet.body.size()>=tail.size() &&
|
|
std::equal(tail.rbegin(),tail.rend(),packet.body.rbegin());
|
|
});
|
|
};
|
|
shown(npc(1,self.guid,5,4,{{UNIT_FIELD_BYTES_0,0x506},{PLAYER_BYTES,21},
|
|
{PLAYER_BYTES_2,1},{SourceUnitDisplayIdField,59},{SourceUnitNativeDisplayIdField,59}}));
|
|
expect(has_tail(shown(values(self.guid,{{SourceUnitDisplayIdField,15435},{PLAYER_BYTES,0}})),pairs(0)));
|
|
expect(has_tail(shown(values(self.guid,{{SourceUnitDisplayIdField,59}})),pairs(0)));
|
|
expect(has_tail(shown(values(self.guid,{{SourceUnitDisplayIdField,15435},{PLAYER_BYTES,21}})),pairs(21)));
|
|
expect(has_tail(shown(values(self.guid,{{SourceUnitDisplayIdField,59}})),pairs(21)));
|
|
if (appearance_only) return EXIT_SUCCESS;
|
|
}
|
|
if(profession_only){
|
|
NativeWorldTranslation world;
|
|
world.selected = self; world.realm = 70; world.self_created = true;
|
|
auto& state = world.entities;
|
|
std::vector<Bytes> requests;
|
|
NativeEntityTranslation::Codec capture=[&](uint32_t mode,const Bytes& input){
|
|
if(mode==GW_CODEC_PROFESSION_VALUES)requests.push_back(input);
|
|
return codec(mode,input);
|
|
};
|
|
auto view=[&](const LegacyPacket& p){return state.translate(p,self,70,0x46010046,0,capture);};
|
|
constexpr uint64_t mallory = (0xf130ULL << 48) | (1215ULL << 24) | 99;
|
|
const auto npc_guid = forever_creature_guid(mallory, 1215, 70, 0);
|
|
NativeEntityTranslation::Actor trainer;
|
|
trainer.entry = 1215; trainer.kind = 3; trainer.sent = true; trainer.modern = npc_guid;
|
|
state.actors[mallory] = trainer;
|
|
Bytes offers; le(offers, mallory, 8); le(offers, 2, 4); le(offers, 1, 4);
|
|
le(offers, 2275, 4); le(offers, 0, 1); le(offers, 10, 4); le(offers, 1, 4);
|
|
le(offers, 1, 4); le(offers, 5, 1);
|
|
for (unsigned i = 0; i != 5; ++i) le(offers, 0, 4);
|
|
cstring(offers, "Alchemy");
|
|
auto check_menu = [&](uint32_t expected_type) {
|
|
const auto frames = world.translate({0x1b1, offers}, 0x46010046, 0, encode);
|
|
Reader r(frames);
|
|
const auto count = r.le(4); expect(count == 1 || count == 2);
|
|
if (count == 2) { expect(r.le(4) == 0x47031b); r.take(r.le(4)); }
|
|
expect(r.le(4) == 0x47018a);
|
|
const auto payload = r.take(r.le(4)); r.end();
|
|
Reader list(payload);
|
|
expect(list.take(pack_guid(npc_guid).size()) == pack_guid(npc_guid));
|
|
expect(list.le(1) == expected_type && list.le(4) == 1001215 && list.le(4) == 1 && list.le(4) == 2275);
|
|
};
|
|
expect(view(npc(1,self.guid,1,4)).empty());expect(state.self_profession_skills.initialized());
|
|
check_menu(0); // A genuine full SELF create omitted all profession slots.
|
|
auto out=view(values(self.guid,{{SourceSkillFirst+30,186},{SourceSkillFirst+31,1u|(75u<<16)}}));
|
|
expect(out.size()==1 && out[0].opcode==0x5e0000 && requests.size()==1);
|
|
Reader r(requests.back());expect(r.le(2)==70 && r.le(4)==0 && r.le(8)==self.guid);
|
|
expect(r.le(1)==1 && r.le(4)==186 && r.le(2)==2);
|
|
expect(r.le(2)==10 && r.le(2)==186 && r.le(2)==1 && r.le(2)==1 && r.le(2)==1 && r.le(2)==75);
|
|
expect(r.le(2)==0 && r.le(2)==0);expect(r.le(2)==134 && r.le(2)==2946);
|
|
expect(r.le(2)==1 && r.le(2)==1 && r.le(2)==1 && r.le(2)==75 && r.le(2)==0 && r.le(2)==0);r.end();
|
|
check_menu(0); // Mining on the same player cannot qualify an Alchemy trainer.
|
|
view(values(self.guid,{{SourceSkillFirst+32,0x0003fff9}}));expect(requests.size()==2);
|
|
Reader bonus(requests.back());bonus.take(14);expect(bonus.le(1)==0 && bonus.le(2)==2);
|
|
expect(bonus.le(2)==10 && bonus.le(2)==186 && bonus.le(2)==1 && bonus.le(2)==1);
|
|
bonus.take(4);expect(bonus.le(2)==65529 && bonus.le(2)==3);
|
|
view(values(self.guid,{{SourceSkillFirst+30,0},{SourceSkillFirst+31,0},{SourceSkillFirst+32,0}}));
|
|
expect(requests.size()==3);Reader removed(requests.back());removed.take(14);
|
|
expect(removed.le(1)==1 && removed.le(4)==0 && removed.le(2)==2);
|
|
// Unrelated weapon skill words continue through the established writer.
|
|
auto weapon=view(values(self.guid,{{SourceSkillFirst,43},{SourceSkillFirst+1,300u|(300u<<16)}}));
|
|
expect(weapon.size()==1 && requests.size()==3);
|
|
view(values(self.guid,{{SourceSkillFirst+30,171},{SourceSkillFirst+31,1u|(75u<<16)}}));
|
|
expect(state.self_profession_skills.has_learned_skill(self.guid,171));
|
|
expect(!state.self_profession_skills.has_learned_skill(self.guid+1,171));
|
|
check_menu(2);
|
|
view(values(self.guid,{{SourceSkillFirst+32,3}})); // A sparse bonus preserves the real rank.
|
|
check_menu(2);
|
|
view(values(self.guid,{{SourceSkillFirst+31,75u<<16}})); // A maximum alone is not a positive current rank.
|
|
check_menu(0);
|
|
view(values(self.guid,{{SourceSkillFirst+31,12u|(75u<<16)}}));
|
|
check_menu(2);
|
|
view(values(self.guid,{{SourceSkillFirst+30,0}})); // Clear only the ID: no stale rank may qualify.
|
|
check_menu(0);
|
|
view(values(self.guid,{{SourceSkillFirst+30,171},{SourceSkillFirst+31,1u|(75u<<16)}}));
|
|
check_menu(2);
|
|
Bytes self_remove;le(self_remove,self.guid,8);view({0xaa,self_remove});
|
|
expect(!state.self_profession_skills.initialized());
|
|
expect(!state.self_profession_skills.has_learned_skill(self.guid,171));
|
|
// A newly selected character gets a fresh full SELF create with no Alchemy.
|
|
self.guid += 1;
|
|
world.selected = self;
|
|
Bytes old_purchase = pack_guid(npc_guid);
|
|
le(old_purchase, 1001215, 4); le(old_purchase, 2275, 4);
|
|
bool rejected = false;
|
|
try { world.gameplay(0x3f0046, old_purchase); } catch (const Error&) { rejected = true; }
|
|
expect(rejected);
|
|
view(npc(1,self.guid,1,4));
|
|
check_menu(0);
|
|
view(values(self.guid,{{SourceSkillFirst+30,171},{SourceSkillFirst+31,1u|(75u<<16)}}));
|
|
check_menu(2);
|
|
world.translate({0x4d,{}},0x46010046,0,encode);
|
|
expect(!world.trainer && !state.self_profession_skills.has_learned_skill(self.guid,171));
|
|
expect(world.translate({0x1b1,offers},0x46010046,0,encode) == Bytes(4));
|
|
std::cout<<"Source create and sparse profession updates passed through native entity and writer\n";return 0;
|
|
}
|
|
if(creature_walk_only){
|
|
const uint64_t actor=0xf13000000600002aULL;
|
|
auto zero=npc(6,actor,1,3,{}, {},0);auto original=zero.body;
|
|
auto shown=turtle_creature_create_presentation(zero,self.guid);
|
|
auto before=turtle_object_updates(zero.opcode,zero.body).at(0);
|
|
auto after=turtle_object_updates(shown.opcode,shown.body).at(0);
|
|
expect(zero.body==original && before.speeds[0]==0 && after.speeds[0]==2.5f);
|
|
expect(before.fields==after.fields && before.update_flags==after.update_flags);
|
|
expect(before.movement->flags==after.movement->flags && before.movement->time==after.movement->time && before.movement->position==after.movement->position);
|
|
for(unsigned i=1;i<6;++i)expect(std::bit_cast<uint32_t>(before.speeds[i])==std::bit_cast<uint32_t>(after.speeds[i]));
|
|
auto spline_zero=npc(6,actor,1,3,{}, {},0,true);auto spline_shown=turtle_creature_create_presentation(spline_zero,self.guid);
|
|
expect(spline_zero.body.size()==spline_shown.body.size());unsigned changed_bytes=0;
|
|
for(unsigned i=0;i<spline_zero.body.size();++i)changed_bytes+=spline_zero.body[i]!=spline_shown.body[i];
|
|
expect(changed_bytes==2); // Only 00000000 -> 00002040; the entire spline tail stays exact.
|
|
for(auto packet:{npc(6,actor),npc(6,actor,1,4,{}, {},0),npc(6,self.guid,1,3,{}, {},0)}){
|
|
auto result=turtle_creature_create_presentation(packet,self.guid);expect(result.opcode==packet.opcode && result.body==packet.body);
|
|
}
|
|
bool rejected=false;try{(void)turtle_creature_create_presentation(npc(6,actor,1,3,{}, {},-1),self.guid);}catch(const Error&){rejected=true;}expect(rejected);
|
|
NativeEntityTranslation state;run(state,zero);run(state,metadata(6));expect(npc_inputs.size()==1);
|
|
unsigned specimen_creates=0;
|
|
if(argc>3){
|
|
self.guid=4510;NativeEntityTranslation specimen;
|
|
std::ifstream stream(argv[3],std::ios::binary);Bytes bytes((std::istreambuf_iterator<char>(stream)),{});expect(!bytes.empty());
|
|
Reader packets(bytes);auto count=packets.le(4);expect(count<=4096);
|
|
for(unsigned i=0;i<count;++i){auto opcode=uint32_t(packets.le(4));auto size=packets.le(4);run(specimen,{opcode,packets.take(size)});}packets.end();
|
|
}
|
|
for(const auto& [mode,input]:npc_inputs){
|
|
Reader r(input);r.take(30);r.cstring(63);r.take(3);auto count=r.le(4);r.take(count*5);count=r.le(4);r.take(count*8);
|
|
if(mode==GW_CODEC_NPCS_COMBAT){count=r.le(4);r.take(count*24);}auto opcode=r.le(4);
|
|
for(const auto& u:turtle_object_updates(opcode,r.take(r.left())))if(u.type==3 && (u.kind==2 || u.kind==3) && (u.fields.at(3)==6 || u.fields.at(3)==91814)){
|
|
expect(u.speeds[0]==2.5f);
|
|
if(u.fields.at(3)==91814){expect(u.update_flags==0x70 && u.fields.size()==39 && u.fields.rbegin()->first==172);++specimen_creates;}
|
|
}
|
|
}
|
|
if(argc>3)expect(specimen_creates==2);
|
|
std::cout<<"Creature zero-walk presentation: positive/player/self/negative guards, native codec argument and "<<specimen_creates<<" actual Source91814 creates passed\n";return 0;
|
|
}
|
|
if(exploration_only){
|
|
constexpr auto first=turtle_entity_fields::PLAYER_EXPLORED_ZONES_1;
|
|
expect(first==1111 && turtle_entity_fields::PLAYER_EXPLORED_ZONES_END==1174);
|
|
NativeEntityTranslation state;std::map<uint16_t,uint32_t> projected;
|
|
NativeEntityTranslation::Codec capture=[&](uint32_t mode,const Bytes& input){
|
|
if(mode==GW_CODEC_UNIT_VALUES_PROFILE){
|
|
Reader r(input);r.take(15);auto n=r.le(2);r.take(n*9);auto op=uint32_t(r.le(4));
|
|
auto rows=turtle_object_updates(op,r.take(r.left()));expect(rows.size()==1 && rows[0].guid==self.guid);projected=rows[0].fields;
|
|
}
|
|
return codec(mode,input);
|
|
};
|
|
auto view=[&](const LegacyPacket& packet){projected.clear();return state.translate(packet,self,70,0x46010046,0,capture);};
|
|
expect(view(npc(1,self.guid,1,4,{{first,0x80000000u},{first+1,0x80000001u},{first+2,1},{first+49,1u<<14},{first+63,0x80000000u}})).empty());
|
|
auto check=[&](){
|
|
for(unsigned i=0;i<64;++i)expect(projected.at(first+i)==state.self_explored_zone_words[i]);
|
|
expect(projected.size()==64);
|
|
};
|
|
expect(view(values(self.guid,{{first,0}})).size()==1);check();
|
|
expect(state.self_explored_zone_words[1]==0x80000001u && state.self_explored_zone_words[49]==1u<<14);
|
|
view(values(self.guid,{{first,0x12345678u}}));check();
|
|
view(values(self.guid,{{first+1,0}}));check();expect(state.self_explored_zone_words[0]==0x12345678u);
|
|
auto pairs=source_explored_zone_pairs(projected,false);
|
|
expect(pairs[0]==0x12345678u && pairs[1]==1 && pairs[24]==uint64_t(1u<<14)<<32 && pairs[31]==uint64_t(1)<<63);
|
|
view(values(self.guid,{{first+63,0}}));check();expect(source_explored_zone_pairs(projected,false)[31]==0);
|
|
view(npc(1,self.guid,1,4));view(values(self.guid,{{first+63,1}}));check();
|
|
for(unsigned i=0;i<63;++i)expect(state.self_explored_zone_words[i]==0);
|
|
Bytes self_remove;le(self_remove,self.guid,8);view({0xaa,self_remove});
|
|
expect(!state.self_presentation_ready);view(values(self.guid,{{first,1}}));expect(!projected.contains(first));
|
|
NativeWorldTranslation world;Bytes experience;le(experience,2040,4);le(experience,123,4);
|
|
auto out=world.translate({0x1f8,experience},0x46010046,0,nullptr);Reader frame(out);
|
|
expect(frame.le(4)==1 && frame.le(4)==0x47020a && frame.le(4)==8);
|
|
expect(frame.take(8)==Bytes({0xf8,7,0,0,123,0,0,0}));frame.end();
|
|
for(unsigned size=0;size<11;++size)if(size!=8){bool refused=false;try{forever_exploration_experience(Bytes(size));}catch(const Error&) {refused=true;}expect(refused);}
|
|
dlclose(library);std::cout<<"Exploration full/sparse DWORD cache, pair boundaries, reset, private-self isolation and Source notification pass.\n";return 0;
|
|
}
|
|
{ // Real-cohort actual entries differ from GUID middle PetNumbers.
|
|
NativeEntityTranslation pets;
|
|
const uint64_t first=(0xf140ULL<<48)|(uint64_t(25719)<<24)|17;
|
|
const uint64_t second=(0xf140ULL<<48)|(uint64_t(174273)<<24)|18;
|
|
auto query=[&](uint32_t entry){
|
|
bool found=false;
|
|
for(const auto& request:pets.requests){
|
|
expect(request.opcode==0x60);Reader r(request.body);auto actual=r.le(4);
|
|
expect(r.le(8)==0);r.end();found|=actual==entry;
|
|
}
|
|
expect(found);
|
|
};
|
|
expect(run(pets,npc(2511023,first,1,3,{{12,uint32_t(self.guid)},{13,0},{14,4321},{15,0}})).empty());
|
|
expect(run(pets,npc(830,second)).empty());query(2511023);query(830);expect(pets.classes.empty());
|
|
for(auto guid:{first,second}){
|
|
const auto& a=pets.actors.at(guid);
|
|
expect(a.kind==3 && a.unit_class==1 && !a.eligible && !a.sent && a.modern==Guid128{});
|
|
}
|
|
expect(!pets.queries.contains(25719) && !pets.queries.contains(174273) && pets.pending.empty());
|
|
auto generation=pets.actors.at(first).generation;
|
|
run(pets,values(first,{{13,7}}));
|
|
expect(pets.actors.at(first).generation==generation && pets.requests.size()==2 &&
|
|
pets.actors.at(first).pending_values.at(12)==self.guid &&
|
|
pets.actors.at(first).pending_values.at(13)==7 && pets.actors.at(first).pending_values.at(14)==4321);
|
|
run(pets,values(first,{{3,831}}));query(831);expect(pets.actors.at(first).entry==831);
|
|
run(pets,values(first,{{3,832},{36,3u<<8}}));expect(pets.requests.size()==3 && !pets.classes.contains(832));
|
|
run(pets,values(first,{{36,1u<<8}}));query(832);
|
|
// Creature and Pet collection share one actual-entry query cache.
|
|
auto creature=(0xf130ULL<<48)|(uint64_t(830)<<24)|19;
|
|
run(pets,npc(830,creature));expect(pets.requests.size()==4 && pets.actors.at(creature).eligible);
|
|
Bytes removed;le(removed,first,8);expect(run(pets,{0xaa,removed}).empty());
|
|
expect(!pets.actors.contains(first) && pets.pending_value_fields==0 &&
|
|
pets.pet_source_value_fields==pets.actors.at(second).pending_values.size());
|
|
run(pets,npc(2511023,first));expect(pets.actors.at(first).generation>generation && pets.requests.size()==4 &&
|
|
!pets.actors.at(first).pending_values.contains(12));
|
|
NativeEntityTranslation bounded;bounded.pet_source_value_fields=65536;
|
|
expect(run(bounded,npc(830,first)).empty() && bounded.requests.empty());
|
|
NativeEntityTranslation primary_full;primary_full.pending_value_fields=65536;
|
|
expect(run(primary_full,npc(830,first)).empty() && primary_full.requests.size()==1 &&
|
|
primary_full.pending_value_fields==65536 && primary_full.pet_source_value_fields>0);
|
|
NativeEntityTranslation full;full.requests.resize(4096);
|
|
expect(run(full,npc(830,first)).empty() && full.requests.size()==4096 && full.queries.empty() && full.classes.empty());
|
|
NativeEntityTranslation conflict;conflict.classes[830]=2;
|
|
expect(run(conflict,npc(830,first)).empty() && conflict.requests.size()==1 && conflict.classes.at(830)==2);
|
|
NativeEntityTranslation unknown;unknown.actors[first].kind=3;
|
|
expect(run(unknown,values(first,{{3,830}})).empty() && unknown.requests.empty());
|
|
// Pet discovery never assigns a native template's Creature class.
|
|
NativeEntityTranslation late;
|
|
run(late,npc(830,first));expect(run(late,metadata(830)).empty());
|
|
expect(late.templates.contains(830) && late.classes.empty());
|
|
auto promoted=run(late,npc(830,creature,0));
|
|
expect(promoted.size()==2 && promoted[0].opcode==0x4b0006 && promoted[1].opcode==0x5e0000 &&
|
|
late.classes.at(830)==0 && !late.actors.at(first).eligible);
|
|
NativeEntityTranslation saturated;
|
|
for(uint32_t entry=1;entry<=4096;++entry)saturated.queries.insert(entry);
|
|
expect(run(saturated,npc(2511023,first)).empty() && saturated.requests.empty() && saturated.classes.empty());
|
|
auto fresh_creature=(0xf130ULL<<48)|(uint64_t(2511023)<<24)|20;
|
|
expect(run(saturated,npc(2511023,fresh_creature,0)).empty() && saturated.requests.size()==1 &&
|
|
saturated.classes.at(2511023)==0 && saturated.actors.at(fresh_creature).eligible);
|
|
}
|
|
if(argc==2 && std::string_view(argv[1])=="--pet-queries-only"){
|
|
dlclose(library);std::cout<<"Pet actual-entry collection, shared dedupe, sparse fields and held bounds passed. No Pet rendered.\n";return EXIT_SUCCESS;
|
|
}
|
|
{ // Own corpse identity survives create/removal; no class guessed for strangers.
|
|
NativeEntityTranslation ghosts;auto source=(0xf101ULL<<48)|17;
|
|
run(ghosts,npc(1,self.guid,1,4,{{35,35}}));expect(ghosts.self_faction==35);
|
|
run(ghosts,values(self.guid+1,{{35,99}}));expect(ghosts.self_faction==35);
|
|
auto created=run(ghosts,corpse(source,self.guid));expect(created.size()==1 && created[0].opcode==0x5e0000);
|
|
expect(ghosts.actors.at(source).sent && ghosts.actors.at(source).kind==7 && ghosts.actors.at(source).corpse_owner==self.guid);
|
|
expect(ghosts.actors.at(source).modern==forever_corpse_guid(source,70,0));
|
|
Bytes removed;le(removed,source,8);auto dead=run(ghosts,{0xaa,removed});expect(dead.size()==1 && !ghosts.actors.contains(source));
|
|
expect(run(ghosts,corpse(source,self.guid+1)).empty());expect(!ghosts.actors.at(source).sent && ghosts.unsupported==1);
|
|
}
|
|
// Player invisibility comes from the source aura presentation byte, never
|
|
// legacy ALWAYS_STAND or the account's GM permissions. Preserve other
|
|
// visual flags across updates containing only one of the two source words.
|
|
constexpr auto visual_unit=turtle_entity_fields::UNIT_FIELD_BYTES_1;
|
|
constexpr auto visual_player=turtle_entity_fields::PLAYER_FIELD_BYTES2;
|
|
expect(visual_unit==138 && visual_player==1260);
|
|
for(uint32_t bits=0;bits<8;++bits)for(uint32_t vision:{0u,0x20u,0x40u,0x60u}){
|
|
expect(forever_unit_vis_flags(bits<<24,vision<<8)==((bits&6)|((vision&0x40)?1:0)));
|
|
expect(forever_aura_vision((vision<<8)|0xab0000cdu)==vision);
|
|
}
|
|
NativeEntityTranslation visual;std::map<uint16_t,uint32_t> projected;
|
|
NativeEntityTranslation::Codec capture=[&](uint32_t mode,const Bytes& input){
|
|
if(mode==GW_CODEC_UNIT_VALUES_PROFILE){
|
|
Reader r(input);r.take(15);auto n=r.le(2);r.take(n*9);auto op=uint32_t(r.le(4));
|
|
auto rows=turtle_object_updates(op,r.take(r.left()));expect(rows.size()==1 && rows[0].guid==self.guid);projected=rows[0].fields;
|
|
}
|
|
return codec(mode,input);
|
|
};
|
|
auto view=[&](const LegacyPacket& packet){projected.clear();return visual.translate(packet,self,70,0x46010046,0,capture);};
|
|
expect(view(npc(1,self.guid,1,4,{{visual_unit,6u<<24},{visual_player,0x4000}})).empty());
|
|
auto visual_out=view(values(self.guid,{{visual_player,0x6000}}));expect(visual_out.size()==1);
|
|
expect(projected.at(visual_unit)==6u<<24 && projected.at(visual_player)==0x6000);
|
|
expect(forever_unit_vis_flags(projected.at(visual_unit),projected.at(visual_player))==7);
|
|
view(values(self.guid,{{visual_unit,0}}));expect(projected.at(visual_player)==0x6000 && projected.at(visual_unit)==0);
|
|
view(values(self.guid,{{visual_player,0}}));expect(projected.at(visual_unit)==0 && projected.at(visual_player)==0);
|
|
view(values(self.guid,{{visual_unit,4u<<24},{visual_player,0x4000}}));expect(projected.at(visual_unit)==4u<<24 && projected.at(visual_player)==0x4000);
|
|
view(values(self.guid,{{22,50}}));expect(projected.size()==1 && projected.at(22)==50);
|
|
// A new full create resets omitted words to zero; an old glow must not leak.
|
|
view(npc(1,self.guid,1,4));view(values(self.guid,{{visual_unit,2u<<24}}));expect(projected.at(visual_player)==0);
|
|
Bytes self_remove;le(self_remove,self.guid,8);view({0xaa,self_remove});
|
|
expect(!visual.self_presentation_ready);view(values(self.guid,{{visual_player,0x4000}}));expect(!projected.contains(visual_unit));
|
|
{ // A real source sit/stand field changes the native self update on wire.
|
|
NativeEntityTranslation posture;
|
|
expect(run(posture,npc(1,self.guid,1,4,{{visual_unit,1175040}})).empty());
|
|
auto seated=run(posture,values(self.guid,{{visual_unit,1175041}}));
|
|
auto standing=run(posture,values(self.guid,{{visual_unit,1175040}}));
|
|
expect(seated.size()==1 && seated[0].opcode==0x5e0000);
|
|
expect(standing.size()==1 && standing[0].opcode==0x5e0000);
|
|
auto self_guid=pack_guid(forever_player_guid(self.guid,70));
|
|
Reader wire(seated[0].body);
|
|
expect(wire.le(2)==0 && wire.le(4)==1 && wire.le(1)==0x80);
|
|
auto block=wire.take(wire.le(4));wire.end();
|
|
Reader update(block);expect(update.le(1)==0);
|
|
auto encoded_guid=update.take(self_guid.size());
|
|
expect(std::equal(encoded_guid.begin(),encoded_guid.end(),self_guid.begin()));
|
|
expect(seated[0].body.size()==standing[0].body.size());
|
|
unsigned differences=0;
|
|
for(size_t i=0;i<seated[0].body.size();++i)if(seated[0].body[i]!=standing[0].body[i]){
|
|
expect(seated[0].body[i]==1 && standing[0].body[i]==0);++differences;
|
|
}
|
|
expect(differences==1);
|
|
}
|
|
constexpr uint32_t entry=9010;constexpr uint64_t guid=(0xf130ULL<<48)|(uint64_t(entry)<<24)|9;
|
|
NativeEntityTranslation state;
|
|
expect(run(state,npc(entry,guid)).empty());expect(state.requests.size()==1 && state.pending.size()==1 && !state.actors.at(guid).sent);
|
|
expect(state.requests[0].opcode==0x60 && state.requests[0].body==turtle_creature_query(entry));state.requests.clear();
|
|
auto created=run(state,metadata(entry));expect(created.size()==2 && created[0].opcode==0x4b0006 && created[1].opcode==0x5e0000);
|
|
Reader count(created[1].body);count.le(2);expect(count.le(4)==1 && state.actors.at(guid).sent && state.pending.empty());
|
|
// Tortoise Creature::InitEntry changes the live template without changing
|
|
// its spawn GUID. A real local packet had encoded1563/current1564. Query
|
|
// the CURRENT template while every create/value/move/removal keeps the
|
|
// immutable identity; do not relax the low-level GUID profile validator.
|
|
for(const auto& [original,current,low]:std::vector<std::tuple<uint32_t,uint32_t,uint32_t>>{{1563,1564,2195},{entry,entry+1,12}}){
|
|
const uint64_t changed_guid=(0xf130ULL<<48)|(uint64_t(original)<<24)|low;
|
|
const auto identity=forever_creature_guid(changed_guid,original,70,0);
|
|
NativeEntityTranslation changed_template;
|
|
expect(run(changed_template,npc(current,changed_guid,8)).empty());
|
|
expect(changed_template.actors.at(changed_guid).entry==current && changed_template.actors.at(changed_guid).modern==identity);
|
|
expect(changed_template.requests.size()==1 && changed_template.requests.front().body==turtle_creature_query(current));
|
|
auto ready=run(changed_template,metadata(current));expect(ready.size()==2 && changed_template.actors.at(changed_guid).sent);
|
|
Reader create(ready[1].body);create.le(2);expect(create.le(4)==1);create.le(1);create.le(4);expect(create.le(1)==2);
|
|
auto packed_identity=pack_guid(identity);auto on_wire=create.take(packed_identity.size());
|
|
expect(std::equal(on_wire.begin(),on_wire.end(),packed_identity.begin()));
|
|
expect(run(changed_template,values(changed_guid,{{22,59}})).size()==1);
|
|
auto move=run(changed_template,spline(changed_guid));expect(move.size()==1 && move.front().body==forever_monster_spline(turtle_monster_spline(spline(changed_guid).body),identity));
|
|
Bytes removed;le(removed,changed_guid,8);auto gone=run(changed_template,{0xaa,removed});
|
|
std::array<Guid128,1> ids{identity};expect(gone.size()==1 && gone.front().body==forever_object_removal(0,ids,{}));
|
|
}
|
|
auto moving=run(state,spline(guid));expect(moving.size()==1 && moving[0].opcode==0x600002);
|
|
auto health=run(state,values(guid,{{22,60}}));expect(health.size()==1 && health[0].opcode==0x5e0000);
|
|
Reader health_count(health[0].body);health_count.le(2);expect(health_count.le(4)==1);
|
|
auto power=run(state,values(guid,{{23,30}}));expect(power.size()==2 && power[0].opcode==0x5e0000 && power[1].opcode==0x47017e);
|
|
expect(power[1].body==forever_power_update(state.actors.at(guid).modern,0,30));
|
|
expect(run(state,values(guid+50,{{22,30}})).empty());
|
|
expect(moving[0].body==forever_monster_spline(turtle_monster_spline(spline(guid).body),state.actors.at(guid).modern));
|
|
auto zipped=run(state,compressed(spline(guid)));expect(zipped.size()==1 && zipped[0].body==moving[0].body);
|
|
auto broken=spline(guid);broken.body.push_back(0);expect(run(state,broken).empty() && state.motion_rejected==1);
|
|
expect(state.motion_sent==2 && state.motion.size()==2 && state.motion_snapshot().size()==2208);
|
|
auto stopped=run(state,spline_stop(guid));expect(stopped.size()==1 && stopped[0].opcode==0x600002);
|
|
expect(stopped[0].body==forever_monster_spline(turtle_monster_spline(spline_stop(guid).body),state.actors.at(guid).modern));
|
|
auto compressed_stop=run(state,compressed(spline_stop(guid)));expect(compressed_stop.size()==1 && compressed_stop[0].body==stopped[0].body);
|
|
expect(state.motion_sent==4 && state.motion.size()==4);
|
|
auto stopped_snapshot=state.motion_snapshot();expect(stopped_snapshot.size()==2208);
|
|
Reader last_stop(std::span<const uint8_t>(stopped_snapshot).subspan(32+3*64,64));
|
|
expect(last_stop.le(8)==guid);last_stop.take(16);expect(last_stop.le(4)==43 && last_stop.le(4)==0);
|
|
for(unsigned repeat=0;repeat<2;++repeat)for(float coordinate:{4.f,5.f,3.f})expect(last_stop.f32()==coordinate);
|
|
expect(last_stop.le(4)==0 && last_stop.le(4)==1);last_stop.end();
|
|
auto snapshot=state.snapshot();Reader stats(snapshot);expect(stats.le(4)==3 && stats.le(4)==43088 && stats.le(4)==1 && stats.le(4)==1);
|
|
Bytes remove;le(remove,guid,8);auto removed=run(state,{0xaa,remove});expect(removed.size()==1 && state.actors.empty());
|
|
expect(run(state,spline(guid)).empty() && state.motion_unknown==1 && state.motion_sent==4);
|
|
expect(run(state,spline_stop(guid)).empty() && state.motion_unknown==2 && state.motion_sent==4);
|
|
expect(run(state,values(guid,{{22,30}})).empty());
|
|
NativeEntityTranslation pending_values;run(pending_values,npc(entry,guid));
|
|
expect(run(pending_values,values(guid,{{22,59}})).empty() && pending_values.pending_value_fields==1);
|
|
expect(run(pending_values,values(guid,{{22,58}})).empty() && pending_values.pending_value_fields==1);
|
|
auto pending_ready=run(pending_values,metadata(entry));
|
|
expect(pending_ready.size()==3 && pending_ready[0].opcode==0x4b0006 && pending_ready[1].opcode==0x5e0000 && pending_ready[2].body!=pending_ready[1].body);
|
|
expect(pending_values.pending_value_fields==0 && pending_values.actors.at(guid).pending_values.empty());
|
|
NativeEntityTranslation lost_values;run(lost_values,npc(entry,guid));run(lost_values,values(guid,{{22,59}}));run(lost_values,{0xaa,remove});
|
|
expect(lost_values.pending_value_fields==0 && run(lost_values,metadata(entry)).size()==1);
|
|
// Delayed genuine metadata may populate the cache, but cannot resurrect an
|
|
// actor removed before the response or an older create generation.
|
|
NativeEntityTranslation delayed;run(delayed,npc(entry,guid));
|
|
expect(run(delayed,spline(guid)).empty() && delayed.motion_unknown==1);
|
|
expect(run(delayed,spline_stop(guid)).empty() && delayed.motion_unknown==2);run(delayed,{0xaa,remove});
|
|
auto late=run(delayed,metadata(entry));expect(late.size()==1 && late[0].opcode==0x4b0006 && delayed.actors.empty() && delayed.pending.empty());
|
|
NativeEntityTranslation replaced;run(replaced,npc(entry,guid));run(replaced,npc(entry,guid));
|
|
auto newest=run(replaced,metadata(entry));expect(newest.size()==2 && replaced.actors.size()==1 && replaced.actors.at(guid).sent);
|
|
// Class0 is genuine unspecified creature metadata, not a playable class.
|
|
// Exercise unrelated entries as well as the observed dummy: no NPC allowlist.
|
|
for(uint32_t zero_entry:{9011u,50516u}){
|
|
const uint64_t zero_guid=(0xf130ULL<<48)|(uint64_t(zero_entry)<<24)|17;
|
|
NativeEntityTranslation unspecified;
|
|
expect(run(unspecified,npc(zero_entry,zero_guid,0)).empty());
|
|
expect(unspecified.unsupported==0 && unspecified.requests.size()==1);
|
|
expect(unspecified.classes.at(zero_entry)==0 && unspecified.actors.at(zero_guid).unit_class==0);
|
|
auto ready=run(unspecified,metadata(zero_entry));
|
|
expect(ready.size()==2 && ready[0].opcode==0x4b0006 && unspecified.actors.at(zero_guid).sent);
|
|
const auto reply=turtle_creature_template(metadata(zero_entry).body);
|
|
auto zero=forever_creature_template(reply,0),one=forever_creature_template(reply,1);
|
|
const size_t class_offset=zero.size()-(reply.title.size()+1)-16;
|
|
expect(zero.size()==one.size() && zero.at(class_offset)==0 && one.at(class_offset)==1);
|
|
one[class_offset]=0;expect(zero==one && ready[0].body==zero);
|
|
expect(run(unspecified,values(zero_guid,{{22,59}})).size()==1);
|
|
Bytes removed;le(removed,zero_guid,8);
|
|
expect(run(unspecified,{0xaa,removed}).size()==1 && unspecified.actors.empty());
|
|
}
|
|
for(uint8_t bad_class:{3,5,6,7,9,11,255}){
|
|
NativeEntityTranslation invalid;
|
|
expect(run(invalid,npc(entry,guid,bad_class)).empty());
|
|
expect(invalid.unsupported==1 && invalid.requests.empty() && !invalid.actors.at(guid).sent);
|
|
bool rejected=false;
|
|
try{forever_creature_template(turtle_creature_template(metadata(entry).body),bad_class);}
|
|
catch(const Error&){rejected=true;}
|
|
expect(rejected);
|
|
}
|
|
// Unsupported unit classes remain in authoritative create accounting, and
|
|
// an unrelated GO sharing a numeric template entry cannot acquire its type.
|
|
constexpr uint64_t other=guid+1,go=(0xf110ULL<<48)|(uint64_t(entry)<<24)|2;
|
|
expect(run(replaced,npc(entry,other,3)).empty());
|
|
expect(run(replaced,npc(entry,go,1,5)).empty());
|
|
auto all=replaced.snapshot();Reader totals(all);totals.le(8);
|
|
expect(totals.le(4)==2 && totals.le(4)==1 && totals.le(4)==0);
|
|
expect(replaced.actors.size()==3 && !replaced.actors.at(other).sent && !replaced.actors.at(go).sent);
|
|
Reader identities(std::span<const uint8_t>(all).subspan(48));
|
|
for(unsigned i=0;i<3;++i){auto id=identities.le(8);identities.take(16);identities.le(4);auto kind=identities.le(4);identities.le(4);auto type=identities.le(4);if(id==go)expect(kind==5 && type==0);}
|
|
Bytes remove_other;le(remove_other,other,8);expect(run(replaced,{0xaa,remove_other}).empty());
|
|
expect(!replaced.actors.contains(other));
|
|
expect(turtle_entity_fields::GAMEOBJECT_TYPE_ID==21);
|
|
NativeEntityTranslation nonvisual;constexpr auto trap=(0xf110ULL<<48)|(9010ULL<<24)|30;
|
|
expect(run(nonvisual,gameobject(trap,6,0)).empty());expect(nonvisual.actors.size()==1 && !nonvisual.actors.at(trap).eligible && !nonvisual.actors.at(trap).sent && nonvisual.unsupported==1);
|
|
Bytes trap_remove;le(trap_remove,trap,8);expect(run(nonvisual,{0xaa,trap_remove}).empty() && nonvisual.actors.empty());
|
|
auto visible=run(nonvisual,gameobject(trap,6,1907));expect(visible.size()==1 && nonvisual.actors.at(trap).sent);
|
|
NativeEntityTranslation focus;auto focus_create=run(focus,gameobject(trap,8,0));expect(focus_create.size()==1 && focus.actors.at(trap).sent);
|
|
// Stationary questgivers use the same identity/create path for every
|
|
// entry; the nonvisual guard still applies, not a Wind-Stone ID exception.
|
|
for(auto display:{6425u,6426u,6427u,1907u}){
|
|
NativeEntityTranslation questgiver;auto created=run(questgiver,gameobject(trap,2,display));
|
|
expect(created.size()==1 && questgiver.actors.at(trap).eligible && questgiver.actors.at(trap).sent);
|
|
expect(created.front().opcode==0x5e0000);
|
|
}
|
|
NativeEntityTranslation null_questgiver;
|
|
expect(run(null_questgiver,gameobject(trap,2,0)).empty() && !null_questgiver.actors.at(trap).eligible);
|
|
expect(turtle_entity_fields::GAMEOBJECT_DISPLAYID==8);
|
|
// Target identity is a source GUID pair, not a forced facing operation.
|
|
// The original target writer may run only after both real unit bindings.
|
|
constexpr auto target_field=turtle_entity_fields::UNIT_FIELD_TARGET;
|
|
expect(target_field==16);
|
|
std::vector<Bytes> target_calls;
|
|
NativeEntityTranslation::Codec target_codec=[&](uint32_t mode,const Bytes& input){
|
|
if(mode==GW_CODEC_UNIT_TARGET)target_calls.push_back(input);
|
|
return codec(mode,input);
|
|
};
|
|
auto target_run=[&](NativeEntityTranslation& s,const LegacyPacket& p){target_calls.clear();return s.translate(p,self,70,0x46010046,0,target_codec);};
|
|
auto target_input=[&](const Guid128& owner,const Guid128& target){Bytes b;le(b,0,2);append(b,owner);append(b,target);return b;};
|
|
auto target_fields=[&](uint64_t target){return std::map<uint16_t,uint32_t>{{target_field,uint32_t(target)},{target_field+1,uint32_t(target>>32)}};};
|
|
auto check_target=[&](const std::vector<LegacyPacket>& output,const Guid128& owner,const Guid128& target){
|
|
auto input=target_input(owner,target);expect(target_calls==std::vector<Bytes>{input});
|
|
expect(!output.empty() && output.back().opcode==0x5e0000 && output.back().body==codec(GW_CODEC_UNIT_TARGET,input));
|
|
for(const auto& p:output)expect(p.opcode!=0x600002); // No invented facing spline.
|
|
};
|
|
NativeEntityTranslation targeted;
|
|
expect(target_run(targeted,npc(1,self.guid,1,4)).empty());
|
|
expect(target_run(targeted,npc(entry,guid,1,3,target_fields(self.guid))).empty());
|
|
auto target_created=target_run(targeted,metadata(entry));expect(target_created.size()==3);
|
|
const auto player_guid=forever_player_guid(self.guid,70),owner_guid=targeted.actors.at(guid).modern;
|
|
check_target(target_created,owner_guid,player_guid);
|
|
expect(target_run(targeted,values(guid,target_fields(self.guid))).empty() && target_calls.empty());
|
|
auto target_clear=target_run(targeted,values(guid,{{target_field,0}}));check_target(target_clear,owner_guid,{});
|
|
expect(targeted.targets.at(guid).words==std::array<uint32_t,2>{0,0});
|
|
const uint64_t referenced=guid+70,referenced2=guid+71;
|
|
expect(target_run(targeted,npc(entry,referenced)).size()==1 && target_calls.empty());
|
|
expect(target_run(targeted,npc(entry,referenced2)).size()==1 && target_calls.empty());
|
|
// High then low, and later low-only, retain the genuine other half.
|
|
expect(target_run(targeted,values(guid,{{target_field+1,uint32_t(referenced>>32)}})).empty());
|
|
auto split=target_run(targeted,values(guid,{{target_field,uint32_t(referenced)}}));
|
|
check_target(split,owner_guid,targeted.actors.at(referenced).modern);
|
|
auto low_only=target_run(targeted,values(guid,{{target_field,uint32_t(referenced2)}}));
|
|
check_target(low_only,owner_guid,targeted.actors.at(referenced2).modern);
|
|
// A source transition to player target cannot reuse an invented zero high word.
|
|
expect(target_run(targeted,values(guid,{{target_field,uint32_t(self.guid)}})).empty() && target_calls.empty());
|
|
expect(targeted.targets.at(guid).words[1]==uint32_t(referenced>>32));
|
|
auto high_clear=target_run(targeted,values(guid,{{target_field+1,0}}));check_target(high_clear,owner_guid,player_guid);
|
|
const uint64_t waiting=(0xf130ULL<<48)|(uint64_t(entry+1)<<24)|28;
|
|
expect(target_run(targeted,values(guid,target_fields(waiting))).empty() && target_calls.empty());
|
|
expect(target_run(targeted,npc(entry+1,waiting)).empty() && target_calls.empty());
|
|
auto reference_ready=target_run(targeted,metadata(entry+1));expect(reference_ready.size()==3);
|
|
check_target(reference_ready,owner_guid,targeted.actors.at(waiting).modern);
|
|
Bytes waiting_remove;le(waiting_remove,waiting,8);auto reference_removed=target_run(targeted,{0xaa,waiting_remove});
|
|
expect(reference_removed.size()==1 && target_calls.empty() && targeted.target_dirty.contains(guid));
|
|
auto rebound=target_run(targeted,npc(entry+1,waiting));expect(rebound.size()==2);
|
|
check_target(rebound,owner_guid,targeted.actors.at(waiting).modern);
|
|
auto self_target=target_run(targeted,values(self.guid,target_fields(referenced)));check_target(self_target,player_guid,targeted.actors.at(referenced).modern);
|
|
auto self_recreated=target_run(targeted,npc(1,self.guid,1,4));check_target(self_recreated,player_guid,{});
|
|
{ // Self combo target (Tortoise PLAYER_FIELD_COMBO_TARGET 714/715) -> UnitData.ClassicComboTarget.
|
|
std::vector<Bytes> combo_calls;
|
|
NativeEntityTranslation::Codec combo_codec=[&](uint32_t mode,const Bytes& input){
|
|
// The writer is covered by the codec ABI suite; this checks the native input only.
|
|
if(mode==GW_CODEC_COMBO_TARGET){combo_calls.push_back(input);return input;}return codec(mode,input);};
|
|
Character rogue_self=self;rogue_self.cls=4; // the shared fixture is a Warrior
|
|
auto combo_as=[&](NativeEntityTranslation& s,const LegacyPacket& p,const Character& c){combo_calls.clear();return s.translate(p,c,70,0x46010046,0,combo_codec);};
|
|
auto combo_run=[&](NativeEntityTranslation& s,const LegacyPacket& p){return combo_as(s,p,rogue_self);};
|
|
auto combo_fields=[&](uint64_t id){return std::map<uint16_t,uint32_t>{{714,uint32_t(id)},{715,uint32_t(id>>32)}};};
|
|
NativeEntityTranslation rogue;
|
|
combo_run(rogue,npc(1,self.guid,1,4));expect(combo_calls.empty()); // native default empty: nothing to send
|
|
combo_run(rogue,npc(entry,guid,1,3));combo_run(rogue,metadata(entry));combo_run(rogue,npc(entry,referenced));
|
|
expect(rogue.actors.at(guid).sent && rogue.actors.at(referenced).sent);
|
|
const auto a=rogue.actors.at(guid).modern,b=rogue.actors.at(referenced).modern;
|
|
auto on_a=combo_run(rogue,values(self.guid,combo_fields(guid)));
|
|
expect(combo_calls==std::vector<Bytes>{target_input(player_guid,a)} && !on_a.empty() && on_a.back().opcode==0x5e0000 && on_a.back().body==target_input(player_guid,a));
|
|
combo_run(rogue,values(self.guid,combo_fields(guid)));expect(combo_calls.empty()); // unchanged
|
|
combo_run(rogue,values(self.guid,combo_fields(referenced)));expect(combo_calls==std::vector<Bytes>{target_input(player_guid,b)}); // GUID-only transfer
|
|
combo_run(rogue,values(self.guid,{{714,0},{715,0}}));expect(combo_calls==std::vector<Bytes>{target_input(player_guid,{})}); // spent/cleared
|
|
combo_run(rogue,values(self.guid,combo_fields(waiting)));expect(combo_calls.empty()); // unpresented unit: stays empty
|
|
combo_run(rogue,values(self.guid,combo_fields(guid)));expect(combo_calls.size()==1);
|
|
// Repeated self create (no native self re-emit) with omitted 714/715: one clear of the old native GUID.
|
|
combo_run(rogue,npc(1,self.guid,1,4));expect(combo_calls==std::vector<Bytes>{target_input(player_guid,{})});
|
|
combo_run(rogue,npc(1,self.guid,1,4));expect(combo_calls.empty());
|
|
NativeEntityTranslation warrior;combo_as(warrior,npc(1,self.guid,1,4),self);combo_as(warrior,npc(entry,guid,1,3),self);combo_as(warrior,metadata(entry),self);
|
|
combo_as(warrior,values(self.guid,combo_fields(guid)),self);expect(combo_calls.empty()); // other classes never capture/emit
|
|
}
|
|
{ // Self farsight (Tortoise PLAYER_FARSIGHT 712/713: Mind Vision / possess camera) -> ActivePlayerData.FarsightObject.
|
|
std::vector<Bytes> calls;
|
|
NativeEntityTranslation::Codec fs_codec=[&](uint32_t mode,const Bytes& input){
|
|
if(mode==GW_CODEC_FARSIGHT){calls.push_back(input);return input;}return codec(mode,input);};
|
|
auto run=[&](NativeEntityTranslation& s,const LegacyPacket& p){calls.clear();return s.translate(p,self,70,0x46010046,0,fs_codec);};
|
|
auto fields=[&](uint64_t id){return std::map<uint16_t,uint32_t>{{712,uint32_t(id)},{713,uint32_t(id>>32)}};};
|
|
NativeEntityTranslation priest;
|
|
run(priest,npc(1,self.guid,1,4));expect(calls.empty());
|
|
run(priest,npc(entry,guid,1,3));run(priest,metadata(entry));
|
|
expect(priest.actors.at(guid).sent);const auto a=priest.actors.at(guid).modern;
|
|
auto on=run(priest,values(self.guid,fields(guid)));
|
|
expect(calls==std::vector<Bytes>{target_input(player_guid,a)} && !on.empty() && on.back().opcode==0x5e0000);
|
|
run(priest,values(self.guid,fields(guid)));expect(calls.empty());
|
|
// Current camera projection tolerates a brief source clear while a
|
|
// viewpoint is changing. Exercise both grace and expiry without sleep.
|
|
run(priest,values(self.guid,{{712,0},{713,0}}));
|
|
expect(calls.empty() && priest.self_farsight_clear_since.has_value());
|
|
expect(priest.self_farsight.presented==a);
|
|
run(priest,values(self.guid,fields(guid)));
|
|
expect(calls.empty() && !priest.self_farsight_clear_since); // rebound cancels pending clear
|
|
run(priest,values(self.guid,{{712,0},{713,0}}));expect(calls.empty());
|
|
priest.self_farsight_clear_since=std::chrono::steady_clock::now()-std::chrono::milliseconds(1501);
|
|
run(priest,values(self.guid,{{712,0},{713,0}}));
|
|
expect(calls==std::vector<Bytes>{target_input(player_guid,{})} && !priest.self_farsight_clear_since);
|
|
run(priest,values(self.guid,fields(waiting)));expect(calls.empty()); // unpresented unit: camera stays on self
|
|
}
|
|
expect(targeted.targets.at(self.guid).words==std::array<uint32_t,2>{0,0});
|
|
expect(target_run(targeted,values(self.guid,target_fields(0))).empty() && target_calls.empty());
|
|
expect(target_run(targeted,values(guid+999,target_fields(self.guid))).empty() && !targeted.targets.contains(guid+999));
|
|
target_run(targeted,{0xaa,remove});expect(!targeted.targets.contains(guid) && !targeted.target_dirty.contains(guid));
|
|
expect(target_run(targeted,values(guid,target_fields(self.guid))).empty());
|
|
auto owner_recreated=target_run(targeted,npc(entry,guid));expect(owner_recreated.size()==1 && target_calls.empty());
|
|
expect(targeted.targets.at(guid).known==3 && targeted.targets.at(guid).words==std::array<uint32_t,2>{0,0});
|
|
// A bound owner without initialized pair state must wait for both actual
|
|
// words; zero is not inferred from the absent half of a sparse packet.
|
|
NativeEntityTranslation partial_target;
|
|
expect(target_run(partial_target,npc(1,self.guid,1,4)).empty());
|
|
partial_target.actors[guid]=targeted.actors.at(guid);
|
|
expect(target_run(partial_target,values(guid,{{target_field,uint32_t(self.guid)}})).empty());
|
|
expect(partial_target.targets.at(guid).known==1 && target_calls.empty());
|
|
auto completed_pair=target_run(partial_target,values(guid,{{target_field+1,0}}));check_target(completed_pair,owner_guid,player_guid);
|
|
target_run(targeted,{0xaa,self_remove});expect(!targeted.targets.contains(self.guid));
|
|
target_run(targeted,values(self.guid,{{target_field,uint32_t(referenced)}}));expect(target_calls.empty());
|
|
expect(target_run(targeted,npc(1,self.guid,1,4)).empty() && target_calls.empty());
|
|
expect(targeted.targets.at(self.guid).words==std::array<uint32_t,2>{0,0});
|
|
// Initial melee state comes from the source movement combat-victim flag,
|
|
// not Target. Original native visibility sends AttackStart after create.
|
|
std::vector<std::pair<uint64_t,Guid128>> combat_rows;
|
|
unsigned combat_calls=0;
|
|
NativeEntityTranslation::Codec combat_codec=[&](uint32_t mode,const Bytes& input){
|
|
if(mode==GW_CODEC_NPCS_COMBAT){
|
|
++combat_calls;Reader r(input);r.take(30);r.cstring(63);r.take(3);
|
|
auto types=r.le(4);r.take(types*5);auto owners=r.le(4);r.take(owners*8);
|
|
auto n=r.le(4);for(unsigned i=0;i<n;++i){auto owner=r.le(8);Guid128 victim{};auto raw=r.take(16);std::copy(raw.begin(),raw.end(),victim.begin());combat_rows.emplace_back(owner,victim);}
|
|
}
|
|
return codec(mode,input);
|
|
};
|
|
auto combat_run=[&](NativeEntityTranslation& s,const LegacyPacket& p){combat_rows.clear();combat_calls=0;return s.translate(p,self,70,0x46010046,0,combat_codec);};
|
|
auto prepare_self=[&](NativeEntityTranslation& s){expect(combat_run(s,npc(1,self.guid,1,4)).empty());};
|
|
auto check_attack=[&](const std::vector<LegacyPacket>& output,const NativeEntityTranslation& s,uint64_t owner,uint64_t victim){
|
|
std::map<uint64_t,Guid128> known{{owner,s.actors.at(owner).modern}};
|
|
known[victim]=victim==self.guid?player_guid:s.actors.at(victim).modern;
|
|
expect(!output.empty() && output.back().opcode==0x4d0017);
|
|
expect(output.back().body==forever_attack_event(TurtleAttackEvent{owner,victim,false,false},known));
|
|
for(const auto& p:output)expect(p.opcode!=0x600002); // No forced angle or spline.
|
|
};
|
|
NativeEntityTranslation combat_initial;prepare_self(combat_initial);
|
|
expect(combat_run(combat_initial,npc(entry,guid,1,3,{},self.guid)).empty());
|
|
auto melee_created=combat_run(combat_initial,metadata(entry));
|
|
expect(melee_created.size()==3 && melee_created[0].opcode==0x4b0006 && melee_created[1].opcode==0x5e0000);
|
|
expect(combat_calls==1 && combat_rows==std::vector<std::pair<uint64_t,Guid128>>{{guid,player_guid}});
|
|
check_attack(melee_created,combat_initial,guid,self.guid);
|
|
expect(!combat_initial.actors.at(guid).melee_pending);
|
|
// The original create carries CombatVictim separately, immediately after
|
|
// the complete movement data and before the original values section.
|
|
Reader combat_create(melee_created[1].body);combat_create.take(11);expect(combat_create.le(1)==2);
|
|
unpack_guid(combat_create,16);expect(combat_create.le(1)==5);
|
|
expect(combat_create.take(3)==Bytes({0x84,0x80,0}));combat_create.take(4);unpack_guid(combat_create,16);
|
|
combat_create.take(48+2+36+8+68+1);
|
|
expect(unpack_guid(combat_create,16)==Bytes(player_guid.begin(),player_guid.end()));
|
|
auto values_size=combat_create.le(4);expect(values_size==combat_create.left());
|
|
expect(combat_run(combat_initial,{0, {}}).empty());
|
|
// Known-actor source events are delivered by NativeWorldTranslation and
|
|
// must not be duplicated by the entity initialization path.
|
|
expect(combat_run(combat_initial,attack(guid,self.guid)).empty());
|
|
expect(combat_run(combat_initial,attack(guid,self.guid,true)).empty());
|
|
expect(combat_initial.actors.at(guid).melee_victim==0 && !combat_initial.actors.at(guid).melee_pending);
|
|
// Source movement-kind1 has no native object-update-kind1 equivalent;
|
|
// only its genuine changed combat state uses the dedicated attack event.
|
|
auto movement_melee=combat_run(combat_initial,combat_movement(guid,self.guid));
|
|
expect(movement_melee.size()==1);check_attack(movement_melee,combat_initial,guid,self.guid);
|
|
expect(combat_run(combat_initial,combat_movement(guid,self.guid)).empty());
|
|
auto explicit_clear=combat_run(combat_initial,combat_movement(guid,0));
|
|
expect(explicit_clear.size()==1 && explicit_clear[0].opcode==0x4d0018);
|
|
expect(explicit_clear[0].body==forever_attack_event(TurtleAttackEvent{guid,0,true,false},{{guid,combat_initial.actors.at(guid).modern}}));
|
|
expect(combat_run(combat_initial,combat_movement(guid,0)).empty());
|
|
expect(combat_initial.actors.at(guid).melee_victim==0);
|
|
// A genuine stop while templates are pending cancels the original
|
|
// attacking create's victim and its supplementary initial AttackStart.
|
|
NativeEntityTranslation combat_cancel;prepare_self(combat_cancel);
|
|
combat_run(combat_cancel,npc(entry,guid,1,3,{},self.guid));
|
|
expect(combat_run(combat_cancel,attack(guid,self.guid,true)).empty());
|
|
auto cancelled=combat_run(combat_cancel,metadata(entry));
|
|
expect(cancelled.size()==2 && !combat_calls && combat_rows.empty());
|
|
NativeEntityTranslation combat_plain;prepare_self(combat_plain);
|
|
combat_run(combat_plain,npc(entry,guid));auto plain=combat_run(combat_plain,metadata(entry));
|
|
expect(plain.size()==2 && plain[1].body==cancelled[1].body);
|
|
// Later real attack-start may replace a pending create's inactive state.
|
|
NativeEntityTranslation combat_later;prepare_self(combat_later);
|
|
combat_run(combat_later,npc(entry,guid));combat_run(combat_later,attack(guid,self.guid));
|
|
auto later_created=combat_run(combat_later,metadata(entry));expect(later_created.size()==3 && combat_calls==1);
|
|
check_attack(later_created,combat_later,guid,self.guid);
|
|
// An unresolved source victim stays pending until its real eligible create
|
|
// and metadata bind it. Arbitrary source high bits are never translated.
|
|
NativeEntityTranslation combat_wait;prepare_self(combat_wait);
|
|
combat_run(combat_wait,npc(entry,guid,1,3,{},waiting));
|
|
auto waiting_created=combat_run(combat_wait,metadata(entry));expect(waiting_created.size()==2 && !combat_calls);
|
|
expect(combat_wait.actors.at(guid).melee_pending);
|
|
expect(combat_run(combat_wait,npc(entry+1,waiting)).empty());
|
|
auto combat_bound=combat_run(combat_wait,metadata(entry+1));expect(combat_bound.size()==3);
|
|
check_attack(combat_bound,combat_wait,guid,waiting);
|
|
expect(combat_run(combat_wait,{0,{}}).empty());
|
|
combat_run(combat_wait,{0xaa,waiting_remove});expect(combat_wait.actors.at(guid).melee_victim==0);
|
|
expect(combat_run(combat_wait,npc(entry+1,waiting)).size()==1);
|
|
// Removal and owner recreation cannot resurrect an older generation's
|
|
// pending state; neither can an event for an unknown owner.
|
|
NativeEntityTranslation combat_recreate;prepare_self(combat_recreate);
|
|
expect(combat_run(combat_recreate,attack(guid,self.guid)).empty() && combat_recreate.actors.empty());
|
|
combat_run(combat_recreate,npc(entry,guid,1,3,{},self.guid));combat_run(combat_recreate,{0xaa,remove});
|
|
combat_run(combat_recreate,npc(entry,guid));auto recreated_plain=combat_run(combat_recreate,metadata(entry));
|
|
expect(recreated_plain.size()==2 && !combat_calls && combat_rows.empty());
|
|
NativeEntityTranslation combat_unseen_stop;prepare_self(combat_unseen_stop);
|
|
combat_run(combat_unseen_stop,npc(entry,guid,1,3,{},waiting));combat_run(combat_unseen_stop,metadata(entry));
|
|
expect(combat_run(combat_unseen_stop,attack(guid,waiting,true)).empty());
|
|
combat_run(combat_unseen_stop,npc(entry+1,waiting));auto stopped_before_binding=combat_run(combat_unseen_stop,metadata(entry+1));
|
|
expect(stopped_before_binding.size()==2 && !combat_unseen_stop.actors.at(guid).melee_pending);
|
|
// Source-only diagnostics preserve actual sparse words and never inspect
|
|
// item fields, unknown sparse identities, aura data or absent create words.
|
|
NativeEntityTranslation observed_fields;
|
|
LegacyObjectUpdate own;own.kind=0;own.guid=self.guid;own.fields={{16,4509},{17,0},{22,4000},{27,3},{33,10},{46,0x80000},{47,21991},{138,0},{164,10241},{200,0x1234}};
|
|
LegacyObjectUpdate unseen=own;unseen.guid=guid;
|
|
LegacyObjectUpdate item=own;item.guid=999;item.kind=3;item.type=1;
|
|
observed_fields.observe_source_fields({own},self.guid,0xa9);expect(observed_fields.source_fields.empty());
|
|
observed_fields.source_packets=1;observed_fields.observe_source_fields({own,unseen,item},self.guid,0x1f6);
|
|
expect(observed_fields.source_fields.size()==8 && observed_fields.source_field_count==8);
|
|
expect(observed_fields.source_fields.back().index==164 && observed_fields.source_fields.back().value==10241);
|
|
for(const auto& field:observed_fields.source_fields)expect(field.legacy==self.guid && field.source_packet==1 && field.opcode==0x1f6 && field.kind==0);
|
|
LegacyObjectUpdate typed;typed.guid=guid;typed.kind=3;typed.type=3;typed.fields={{46,0x400000},{164,0}};
|
|
observed_fields.source_packets=2;observed_fields.observe_source_fields({typed},self.guid,0xa9);
|
|
expect(observed_fields.source_field_count==10 && observed_fields.source_fields.back().value==0);
|
|
observed_fields.observe_source_fields({own},self.guid,0x96);expect(observed_fields.source_field_count==10);
|
|
observed_fields.actors[guid].kind=3;unseen.fields={{164,1}};
|
|
observed_fields.source_packets=3;observed_fields.observe_source_fields({unseen},self.guid,0xa9);
|
|
expect(observed_fields.source_field_count==11 && observed_fields.source_fields.back().legacy==guid);
|
|
for(uint32_t i=0;i<70;++i){observed_fields.source_packets=4+i;own.fields={{22,5000-i}};observed_fields.observe_source_fields({own},self.guid,0xa9);}
|
|
expect(observed_fields.source_fields.size()==64 && observed_fields.source_field_count==81);
|
|
expect(observed_fields.source_fields.front().sequence==18 && observed_fields.source_fields.back().sequence==81);
|
|
auto field_snapshot=observed_fields.snapshot();expect(field_snapshot==observed_fields.snapshot() && observed_fields.source_field_count==81);
|
|
Reader field_header(std::span<const uint8_t>(field_snapshot).subspan(41008));
|
|
expect(field_header.le(4)==1 && field_header.le(4)==2080 && field_header.le(4)==73 && field_header.le(4)==81);
|
|
expect(field_header.le(4)==64 && field_header.le(4)==17 && field_header.le(4)==0 && field_header.le(4)==0);
|
|
expect(field_header.le(8)==self.guid && field_header.le(4)==18);
|
|
// Packet counting is independent of whether a packet yields fields/output.
|
|
NativeWorldTranslation counted;counted.selected=self;counted.realm=70;
|
|
expect(counted.translate({0,{}},0x46010046,0,nullptr)==Bytes(4));
|
|
expect(counted.translate({0,{}},0x46010046,0,nullptr)==Bytes(4));
|
|
expect(counted.entities.source_packets==2 && counted.entities.source_fields.empty());
|
|
expect(counted.translate(values(self.guid,{{164,10240}}),0x46010046,0,encode)==Bytes(4));
|
|
expect(counted.entities.source_packets==3 && counted.entities.source_field_count==1 && counted.entities.source_fields[0].source_packet==3);
|
|
dlclose(library);std::cout<<"Real source codec: arbitrary-entry NPC query/create, inclusive identity counts, GO type isolation, removal and stale-generation rejection passed. No client/server used.\n";
|
|
// More than the former256-row diagnostic cap must remain observable.
|
|
NativeEntityTranslation crowded;
|
|
for(uint64_t n=1;n<=300;++n){NativeEntityTranslation::Actor a;a.kind=3;a.entry=unsigned(n);crowded.actors[(0xf130ULL<<48)|(n<<24)|n]=a;}
|
|
auto public_rows=crowded.snapshot();Reader page(public_rows);expect(page.le(4)==3 && page.le(4)==43088);page.take(32);expect(page.le(4)==300 && page.le(4)==0);
|
|
for(uint64_t n=301;n<=1025;++n){NativeEntityTranslation::Actor a;a.kind=3;a.entry=unsigned(n);crowded.actors[(0xf130ULL<<48)|(n<<24)|n]=a;}
|
|
public_rows=crowded.snapshot();Reader bounded(public_rows);bounded.take(40);expect(bounded.le(4)==1024 && bounded.le(4)==1);
|
|
}
|