883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
67 lines
4.4 KiB
C++
67 lines
4.4 KiB
C++
#include "world_translation.hpp"
|
|
#include "gateway/emote_profile.hpp"
|
|
#include <cstdlib>
|
|
using namespace gateway;
|
|
namespace {
|
|
void check(bool ok){if(!ok)throw Error("emote fixture assertion");}
|
|
template<class F>void rejects(F run){try{run();}catch(const Error&){return;}throw Error("malformed emote accepted");}
|
|
Bytes request(uint32_t text,const Guid128& target={}){
|
|
auto body=pack_guid(target);le(body,text,4);le(body,0xffffffffu,4);le(body,0,4);le(body,0,4);return body;
|
|
}
|
|
Bytes text_event(uint32_t text,const char* target=""){
|
|
Bytes body;le(body,4520,8);le(body,text,4);le(body,0xffffffffu,4);
|
|
std::string name(target);le(body,name.size()+1,4);cstring(body,name);return body;
|
|
}
|
|
}
|
|
int main(){try{
|
|
NativeWorldTranslation world{};world.selected.guid=4520;world.selected.name="Praxis";
|
|
world.realm=70;auto self=forever_player_guid(4520,70);
|
|
rejects([&]{world.gameplay(0x3f001e,request(77));});world.self_created=true;
|
|
for(auto mapping:emote_profile::Texts){
|
|
auto input=request(mapping.native);auto output=world.gameplay(0x3f001e,input);
|
|
check(output.opcode==0x104);Reader r(output.body);
|
|
check(r.le(4)==mapping.source && r.le(4)==0xffffffffu && r.le(8)==0);r.end();
|
|
}
|
|
auto input=request(77,self);auto source=world.gameplay(0x3f001e,input);
|
|
Reader r(source.body);check(r.le(4)==77 && r.le(4)==0xffffffffu && r.le(8)==4520);r.end();
|
|
for(size_t n=0;n<input.size();++n)rejects([&]{world.gameplay(0x3f001e,std::span(input).first(n));});
|
|
auto tail=input;tail.push_back(0);rejects([&]{world.gameplay(0x3f001e,tail);});
|
|
auto kit=input;kit[kit.size()-8]=1;rejects([&]{world.gameplay(0x3f001e,kit);});
|
|
auto variation=input;variation.back()=1;rejects([&]{world.gameplay(0x3f001e,variation);});
|
|
rejects([&]{world.gameplay(0x3f001e,request(0xffffffffu));});
|
|
rejects([&]{world.gameplay(0x3f001e,request(77,forever_player_guid(4521,70)));});
|
|
auto cancel=world.gameplay(0x3f00e6,{});check(cancel.opcode==0x102 && cancel.body==Bytes(4));
|
|
rejects([&]{world.gameplay(0x3f00e6,Bytes{0});});
|
|
{
|
|
std::string text="tests a custom emote";auto bits=text.size()<<5;
|
|
Bytes custom{uint8_t(bits>>8),uint8_t(bits)};custom.insert(custom.end(),text.begin(),text.end());
|
|
auto output=world.gameplay(0x2d0024,custom);check(output.opcode==0x95);Reader q(output.body);
|
|
check(q.le(4)==8 && q.le(4)==0 && q.cstring(255)==text);q.end();
|
|
rejects([&]{world.gameplay(0x2d0024,Bytes{});});
|
|
auto bad=custom;bad[1]|=1;rejects([&]{world.gameplay(0x2d0024,bad);});
|
|
bad=custom;bad.back()=0;rejects([&]{world.gameplay(0x2d0024,bad);});
|
|
}
|
|
for(auto mapping:emote_profile::Animations){
|
|
Bytes body;le(body,mapping.source,4);le(body,4520,8);auto output=world.emote_event({0x103,body});
|
|
check(output.size()==1 && output[0].opcode==0x470274);Reader q(output[0].body);
|
|
check(unpack_guid(q,16)==Bytes(self.begin(),self.end()));
|
|
check(q.le(4)==mapping.native && q.le(4)==0 && q.le(4)==0);q.end();
|
|
for(size_t n=0;n<body.size();++n)rejects([&]{world.emote_event({0x103,Bytes(body.begin(),body.begin()+n)});});
|
|
}
|
|
for(auto name:{"","Praxis"})for(auto id:{77u,89u}){
|
|
auto output=world.emote_event({0x105,text_event(id,name)});check(output.size()==1 && output[0].opcode==0x470127);
|
|
Reader q(output[0].body);check(unpack_guid(q,16)==Bytes(self.begin(),self.end()));check(unpack_guid(q,16)==Bytes(16));
|
|
check(q.le(4)==id && q.le(4)==0xffffffffu);auto target=unpack_guid(q,16);
|
|
check(target==(std::string(name).empty()?Bytes(16):Bytes(self.begin(),self.end())));q.end();
|
|
}
|
|
auto event=text_event(77);for(size_t n=0;n<event.size();++n)rejects([&]{world.emote_event({0x105,Bytes(event.begin(),event.begin()+n)});});
|
|
event.push_back(0);rejects([&]{world.emote_event({0x105,event});});
|
|
check(world.emote_event({0x105,text_event(77,"Unknown")}).empty());
|
|
Bytes unknown;le(unknown,14,4);le(unknown,9999,8);check(world.emote_event({0x103,unknown}).empty());
|
|
Bytes unsupported;le(unsupported,0xffffffffu,4);le(unsupported,4520,8);check(world.emote_event({0x103,unsupported}).empty());
|
|
auto bundle=world.translate({0x105,text_event(77)},0x46010046,0,nullptr);Reader b(bundle);
|
|
check(b.le(4)==1 && b.le(4)==0x470127);b.take(b.le(4));b.end();
|
|
world.self_created=false;check(world.translate({0x105,text_event(77)},0x46010046,0,nullptr)==Bytes(4));
|
|
return EXIT_SUCCESS;
|
|
}catch(...){return EXIT_FAILURE;}}
|