65 lines
7.2 KiB
C++
65 lines
7.2 KiB
C++
#include "gateway/quest_packets.hpp"
|
|
#include "../native/quest_translation.hpp"
|
|
#include <cassert>
|
|
#include <set>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
Bytes query(const std::string& details, const std::string& area){Bytes b;for(auto x:{7,1,3,12,0,0,0,0,0,0,125,0,0,0,8})le(b,x,4);for(int i=0;i<20;++i)le(b,0,4);le(b,0,4);le(b,0,4);le(b,0,4);le(b,0,4);cstring(b,"Wolf quest");cstring(b,"Kill8wolves");cstring(b,details);cstring(b,area);for(int i=0;i<4;++i){le(b,i==1?69:0,4);le(b,i==1?8:0,4);le(b,i==2?789:0,4);le(b,i==2?2:0,4);}for(auto s:{"","Source wolf objective","",""})cstring(b,s);return b;}
|
|
Bytes dialogue(uint16_t op,uint64_t giver, const std::string& text){Bytes b;le(b,giver,8);le(b,7,4);cstring(b,"Wolf quest");cstring(b,text);if(op==0x188)cstring(b,"Kill8wolves");le(b,0,4);if(op==0x18d)le(b,0,4);le(b,2,4);for(auto id:{31,32}){le(b,id,4);le(b,1,4);le(b,0,4);}le(b,0,4);le(b,125,4);if(op==0x18d)le(b,0,4);le(b,0,4);if(op==0x188)le(b,0,4);return b;}
|
|
Bytes query() { return query("Actual Source details", ""); }
|
|
Bytes dialogue(uint16_t op, uint64_t giver) { return dialogue(op, giver, "Source dialogue"); }
|
|
|
|
void localized_quest_text() {
|
|
const auto ordinary = std::string(1100, 'a');
|
|
const auto max_text = std::string(4095, 'b');
|
|
const std::string area(510, 'c');
|
|
auto definition = source_quest_definition(query(ordinary, area + "éclair"));
|
|
assert(definition.details == ordinary);
|
|
assert(definition.end == area);
|
|
assert(!definition.objectives.empty() && definition.objectives.front().object == 69);
|
|
|
|
auto exact = source_quest_dialogue(0x188, dialogue(0x188, 45, max_text));
|
|
assert(exact.text == max_text);
|
|
const std::string prefix(4092, 'x');
|
|
auto longer = source_quest_dialogue(0x188, dialogue(0x188, 45, prefix + "🌍 fin"));
|
|
assert(longer.text == prefix && longer.log == "Kill8wolves" && longer.money == 125);
|
|
|
|
Bytes unfinished{'a', 'b'};
|
|
Reader reader(unfinished);
|
|
bool rejected = false;
|
|
try { reader.utf8_cstring_prefix(1); }
|
|
catch (const Error&) { rejected = true; }
|
|
assert(rejected);
|
|
}
|
|
|
|
int main(){
|
|
localized_quest_text();
|
|
// The receive path includes two dialogue closers and an item-progress event
|
|
// in addition to its mapped native packets. Neighbouring opcodes stay outside.
|
|
const std::set<uint16_t> handled{0x05d,0x17d,0x17e,0x183,0x185,0x188,0x18b,
|
|
0x18d,0x18f,0x191,0x192,0x195,0x196,0x197,0x198,0x199,0x19a,0x19c,0x276};
|
|
for(unsigned op=0;op<=UINT16_MAX;++op)
|
|
assert(NativeQuestTranslation::handles_source(uint16_t(op))==handled.contains(uint16_t(op)));
|
|
auto q=source_quest_definition(query());assert(q.id==7&&q.objectives.size()==2&&q.objectives[0].object==69&&q.objectives[0].storage==1&&q.objectives[0].count==8&&q.objectives[1].type==1&&q.objectives[1].storage==6);auto bad=query();bad.pop_back();bool rejected=false;try{source_quest_definition(bad);}catch(const Error&){rejected=true;}assert(rejected);
|
|
// All three emitted stored objective families have distinct valid native
|
|
// slots; Source's original four creature/GO counter positions remain0..3.
|
|
auto all=query();Reader cursor(all);cursor.take(156);for(unsigned i=0;i<4;++i)cursor.cstring();
|
|
auto objective_start=all.size()-cursor.left();
|
|
auto put=[&](size_t p,uint32_t value){for(unsigned j=0;j<4;++j)all[p+j]=uint8_t(value>>(j*8));};
|
|
for(unsigned i=0;i<4;++i){put(objective_start+16*i,(i&1?0x80000000u:0u)|(100+i));put(objective_start+16*i+4,2);put(objective_start+16*i+8,200+i);put(objective_start+16*i+12,3);}
|
|
auto eight=source_quest_definition(all);assert(eight.objectives.size()==8);
|
|
for(unsigned i=0;i<8;++i){assert(eight.objectives[i].storage==int(i));assert(eight.objectives[i].type==(i<4?(i&1?2:0):1));}
|
|
put(objective_start+12,32768);rejected=false;try{source_quest_definition(all);}catch(const Error&){rejected=true;}assert(rejected);
|
|
assert(native_quest_giver_status(2)==0x40&&native_quest_giver_status(3)==0x2000&&native_quest_giver_status(7)==0x200000000ULL&&native_quest_giver_status(4)==0x800000000ULL);
|
|
constexpr uint64_t giver=0xf13000007b000001ULL;Guid128 modern{};modern[0]=11;modern[8]=0x30;NativeQuestTranslation::Bindings bindings{{giver,{modern,10,3,true}}};NativeQuestTranslation state;
|
|
auto codec=[](uint32_t mode,const Bytes& b){assert(mode==52);Reader r(b);assert(r.le(2)==1&&r.le(4)==0);r.take(16);auto op=r.le(2);auto n=r.le(4);if(n)assert(source_quest_definition(r.take(n)).id==7);return Bytes{uint8_t(op)};};
|
|
auto details=dialogue(0x188,giver);auto first=state.receive(0x188,details,bindings,1,0,codec);assert(first&&first->empty()&&state.requests.size()==1&&state.requests.front().opcode==0x05c&&!state.detail_offer);auto answer=query();auto ready=state.receive(0x05d,answer,bindings,1,0,codec);assert(ready&&ready->size()==2&&(*ready)[0].opcode==0x670016&&(*ready)[1].opcode==0x670012&&state.detail_offer);
|
|
Bytes accept=pack_guid(modern);le(accept,7,4);le(accept,0,1);auto accepted=state.client(0x3f002f,accept,bindings);assert(accepted.packets.size()==1&&accepted.packets[0].opcode==0x189&&accepted.packets[0].body.size()==12);
|
|
Bytes cheat=accept;cheat.back()=0x80;auto unsupported=state.client(0x3f002f,cheat,bindings);assert(unsupported.held&&unsupported.packets.empty());cheat.back()=1;rejected=false;try{state.client(0x3f002f,cheat,bindings);}catch(const Error&){rejected=true;}assert(rejected);
|
|
NativeQuestTranslation closed;closed.receive(0x188,details,bindings,1,0,codec);assert(!closed.awaiting_definition.empty());closed.receive(0x17e,{},bindings,1,0,codec);assert(closed.awaiting_definition.empty());auto after_close=closed.receive(0x05d,answer,bindings,1,0,codec);assert(after_close&&after_close->size()==1&&!closed.detail_offer);
|
|
auto offer=dialogue(0x18d,giver);state.receive(0x18d,offer,bindings,1,0,codec);Bytes choose=pack_guid(modern);le(choose,7,4);le(choose,0,1);le(choose,32,4);le(choose,0,1);le(choose,0,1);le(choose,1,4);auto picked=state.client(0x3f0031,choose,bindings);Reader source(picked.packets[0].body);assert(source.le(8)==giver&&source.le(4)==7&&source.le(4)==1);source.end();
|
|
bindings.at(giver).generation=11;auto stale=state.client(0x3f0031,choose,bindings);assert(stale.held&&stale.packets.empty());bindings.at(giver).generation=10;
|
|
auto multi=state.client(0x3f0034,{},bindings);assert(multi.packets.size()==1&&state.multiple.empty());state.sent(multi);Bytes status;le(status,giver,8);le(status,7,4);auto batch=state.receive(0x183,status,bindings,1,0,codec);assert(batch&&batch->size()==1&&batch->front().opcode==0x670011);Reader br(batch->front().body);assert(br.le(4)==1);assert(unpack_guid(br,16)==Bytes(modern.begin(),modern.end()));assert(br.le(8)==0x200000000ULL);br.end();
|
|
Bytes abandon{20};auto extended=state.client(0x3f00d3,abandon,bindings);assert(!extended.held&&extended.packets.size()==1&&extended.packets[0].opcode==0x194&&extended.packets[0].body==Bytes{20});abandon[0]=25;auto outside_source=state.client(0x3f00d3,abandon,bindings);assert(outside_source.held&&outside_source.packets.empty());abandon[0]=175;rejected=false;try{state.client(0x3f00d3,abandon,bindings);}catch(const Error&){rejected=true;}assert(rejected);Bytes poi(704,0);auto held_poi=state.client(0x4400de,poi,bindings);assert(held_poi.held&&held_poi.packets.empty());std::cout<<"Quest Source protocol,definition closure,offer identity,reward index andstatus fanout PASS\n";
|
|
}
|