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

84 lines
5.1 KiB
C++

// #87 (owner 2026-11-26): Crusader/Holy Strike were dropped while the right mouse button turned the player, because
// the native CastSpell then carries a MoveUpdate (SpellCastRequest bit 0x40) the parser refused. The cast must
// translate and its MovementInfo must reach Turtle as MSG_MOVE_SET_FACING (0xda) with the same source bytes as an
// ordinary facing packet.
#include "world_translation.hpp"
#include <bit>
#include <iostream>
using namespace gateway;
static void check(bool ok,const char* what){if(!ok)throw Error(what);}
template<class F> static void rejects(F fn){try{fn();}catch(const Error&){return;}throw Error("expected rejection");}
static void number(Bytes& b,float f){le(b,std::bit_cast<uint32_t>(f),4);}
static Bytes movement(uint64_t flags){
auto b=pack_guid(forever_player_guid(4509,70));le(b,flags,8);le(b,100,4);
for(float f:{1.f,2.f,3.f,.5f,.25f,0.f})number(b,f);
le(b,0,4);le(b,0,4);number(b,1);le(b,0,1);le(b,0,1);return b;
}
static Bytes cast(uint8_t tail,const Bytes& move,uint8_t send_flags=0,uint32_t spell=35395){
Guid128 id{};id[0]=7;Bytes out=pack_guid(id);le(out,send_flags,1);
for(unsigned i=0;i<3;++i)le(out,0,4);
le(out,spell,4);le(out,0,4);le(out,0,4);le(out,0,4);
append(out,pack_guid(Guid128{}));append(out,pack_guid(Guid128{}));append(out,pack_guid(Guid128{}));
le(out,0,2);le(out,0,4);le(out,0,4);append(out,pack_guid(Guid128{}));
for(unsigned i=0;i<3;++i)le(out,0,4);
le(out,0,1);le(out,tail,1);if(tail&0x80)le(out,123456,4);append(out,move);return out;
}
// Spell.dbc selects the implicit-self target shape. SendCastFlags is an
// independent client request byte; each spell must keep its Turtle payload.
static void check_channelled_self_casts(NativeWorldTranslation& world){
constexpr uint32_t spells[] = {
#include "fixtures/octo_channelled_self_cast_ids.inc"
};
for (uint32_t spell : spells) {
const auto [known, inserted] = world.spells.insert(spell);
Bytes expected;
le(expected,spell,4);
le(expected,0,2); // Turtle SpellCastTargets with no explicit target.
for (uint8_t send_flags : {0, 1, 2, 0x80}) {
const auto request = cast(0x80,{},send_flags,spell);
try {
const auto result = world.gameplay(0x3e0176,request);
check(result.opcode==0x12e && result.body==expected,
"channelled self-cast produced the wrong Turtle packet");
} catch (const std::exception& error) {
throw Error("channelled self-cast spell "+std::to_string(spell)+
", SendCastFlags "+std::to_string(send_flags)+": "+error.what());
}
}
if (inserted) world.spells.erase(known);
}
std::cout << std::size(spells) << " channelled self-cast spells, four SendCastFlags values each PASS\n";
}
int main(){try{
NativeWorldTranslation w{};w.realm=70;w.selected.guid=4509;w.self_created=true;w.mover_confirmed=true;w.spells.insert(35395);
w.location=WorldLocation{0,{1,2,3,0}};
check_channelled_self_casts(w);
const std::vector<Character> owned{w.selected};
for(uint64_t flags:{0ull,1ull,4ull}){ // standing turn, running forward, turning while running
const auto move=movement(flags);
for(uint8_t tail:{uint8_t(0xc0),uint8_t(0x40)}){
const auto body=cast(tail,move);
const auto request=forever_spell_request(body);
check(request.spell==35395 && request.move_update==move,"MoveUpdate not kept raw");
check(w.gameplay(0x3e0176,body).opcode==0x12e,"cast with MoveUpdate not translated");
const auto facing=w.cast_move_update(0x3e0176,body,owned);
const auto plain=w.player_movement(0x420027,move,owned);
check(facing.size()==1 && facing[0].opcode==0xda && facing[0].body==plain[0].body,"facing differs from ordinary SET_FACING");
}
}
const auto still=cast(0x80,{});
check(forever_spell_request(still).move_update.empty() && w.cast_move_update(0x3e0176,still,owned).empty(),"cast without MoveUpdate gained facing");
// Gitea #6 (Heroic Strike): next-melee casts carry a non-zero SendCastFlags byte. TrinityCore reads it and never
// uses it (SpellPackets.cpp CastSpell), and Turtle CMSG_CAST_SPELL has no such field: the cast must still translate.
for(uint8_t send:{uint8_t(1),uint8_t(2),uint8_t(0x80)}){
const auto queued=cast(0x80,{},send);
check(forever_spell_request(queued).spell==35395 && w.gameplay(0x3e0176,queued).opcode==0x12e,"cast with SendCastFlags refused");
}
rejects([&]{forever_spell_request(cast(0x10,{}));}); // weights still unsupported
rejects([&]{forever_spell_request(cast(0x08,{}));}); // crafting order still unsupported
rejects([&]{forever_spell_request(cast(0x40,{}));}); // MoveUpdate flagged but absent
auto other=movement(0);other[1]^=1;
rejects([&]{w.cast_move_update(0x3e0176,cast(0x40,other),owned);}); // another mover's MovementInfo
std::cout<<"cast MoveUpdate: kept raw, cast translated, facing = SET_FACING bytes, weights/order/foreign mover refused PASS\n";return 0;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}