175 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
66 lines
3.6 KiB
C++
66 lines
3.6 KiB
C++
#include "world_translation.hpp"
|
|
#include "gateway/emote_profile.hpp"
|
|
#include <algorithm>
|
|
using namespace gateway;
|
|
|
|
LegacyPacket NativeWorldTranslation::emote_request(uint32_t opcode,std::span<const uint8_t> body) const {
|
|
Reader r(body);
|
|
if(opcode==0x2d0024){
|
|
auto bits=(r.le(1)<<8)|r.le(1);auto size=bits>>5;
|
|
if((bits&31) || !size || size>255)throw Error("custom emote text bound/padding");
|
|
auto text=r.take(size);r.end();
|
|
if(std::find(text.begin(),text.end(),0)!=text.end())throw Error("custom emote embedded terminator");
|
|
Bytes out;le(out,8,4);le(out,0,4);append(out,text);le(out,0,1);return {0x95,std::move(out)};
|
|
}
|
|
if(opcode==0x3f00e6){
|
|
// Original EmoteClient::Read has no fields; source zero clears state.
|
|
r.end();Bytes out;le(out,0,4);return {0x102,std::move(out)};
|
|
}
|
|
auto target=unpack_guid(r,16);auto text=uint32_t(r.le(4));auto sound=uint32_t(r.le(4));
|
|
auto count=r.le(4);auto variation=r.le(4);
|
|
// Legacy has no client-selected visual kits/sequence variations.
|
|
if(count || variation)throw Error("unrepresented client emote visual selection");
|
|
r.end();auto source=emote_profile::source_text(text);
|
|
if(!source)throw Error("unmapped text emote identity");
|
|
uint64_t legacy=0;
|
|
if(target!=Bytes(16)){
|
|
bool found=false;
|
|
for(const auto& [guid,modern]:bindings())if(std::equal(target.begin(),target.end(),modern.begin())){legacy=guid;found=true;break;}
|
|
if(!found)throw Error("emote target without current source binding");
|
|
}
|
|
Bytes out;le(out,source,4);le(out,sound,4);le(out,legacy,8);return {0x104,std::move(out)};
|
|
}
|
|
|
|
std::vector<LegacyPacket> NativeWorldTranslation::emote_event(const LegacyPacket& packet) const {
|
|
Reader r(packet.body);std::vector<LegacyPacket> out;auto known=bindings();
|
|
if(packet.opcode==0x103){
|
|
auto id=uint32_t(r.le(4));auto source=r.le(8);r.end();
|
|
if(!known.contains(source) || !emote_profile::has_animation(id))return out;
|
|
Bytes body=pack_guid(known.at(source));le(body,emote_profile::animation(id),4);
|
|
le(body,0,4);le(body,0,4); // No fabricated kits or sequence variation.
|
|
out.push_back({0x470274,std::move(body)});return out;
|
|
}
|
|
auto source=r.le(8);auto text=uint32_t(r.le(4));auto sound=r.le(4);auto size=r.le(4);
|
|
if(!size || size>256)throw Error("source emote target name bound");
|
|
auto bytes=r.take(size);r.end();
|
|
if(bytes.back() || std::find(bytes.begin(),bytes.end()-1,0)!=bytes.end()-1)throw Error("source emote target terminator");
|
|
auto native=emote_profile::native_text(text);
|
|
if(!known.contains(source) || !native)return out;
|
|
Guid128 target{};
|
|
if(size>1){
|
|
std::string name(bytes.begin(),bytes.end()-1);std::set<uint64_t> matches;
|
|
if(selected.name==name)matches.insert(selected.guid);
|
|
for(const auto& [id,player]:chat_players)if(player.name==name && known.contains(id))matches.insert(id);
|
|
for(const auto& [id,actor]:entities.actors)if(actor.sent && known.contains(id)){
|
|
auto t=entities.templates.find(actor.entry);
|
|
if(t!=entities.templates.end() && std::find(t->second.names.begin(),t->second.names.end(),name)!=t->second.names.end())matches.insert(id);
|
|
}
|
|
// Source carries only a name. Never invent/guess a directed target.
|
|
if(matches.size()!=1)return out;
|
|
target=known.at(*matches.begin());
|
|
}
|
|
Bytes body=pack_guid(known.at(source));append(body,pack_guid(Guid128{}));
|
|
le(body,native,4);le(body,sound,4);append(body,pack_guid(target));
|
|
out.push_back({0x470127,std::move(body)});return out;
|
|
}
|