883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
47 lines
5.6 KiB
C++
47 lines
5.6 KiB
C++
// Offline replay consumes a separately supplied private genuine Source trace.
|
|
// No client, socket, database, loot collection or item mutation occurs.
|
|
#include "world_translation.hpp"
|
|
#include "gateway/object_updates.hpp"
|
|
#include <algorithm>
|
|
#include <dlfcn.h>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
using namespace gateway;
|
|
static void check(bool x){if(!x)throw Error("gameobject loot assertion");}
|
|
static Bytes last_loot;
|
|
static int codec(uint32_t mode,const uint8_t* src,uint32_t size,uint32_t,uint8_t* out,uint32_t cap,uint32_t* written){
|
|
*written=1;if(cap<1)return GW_CODEC_CAPACITY;
|
|
if(mode==GW_CODEC_LOOT_EVENT)last_loot.assign(src,src+size);
|
|
out[0]=0;return GW_CODEC_OK;
|
|
}
|
|
static Bytes cast(const Guid128& target){Bytes b;Guid128 id{};id[0]=1;append(b,pack_guid(id));le(b,0,1);for(int i=0;i<3;++i)le(b,0,4);le(b,2575,4);le(b,0,4);le(b,0,4);le(b,0x800,4);append(b,pack_guid(target));Guid128 z{};append(b,pack_guid(z));append(b,pack_guid(z));le(b,0,2);le(b,0,4);le(b,0,4);append(b,pack_guid(z));for(int i=0;i<3;++i)le(b,0,4);le(b,0,1);le(b,0,1);return b;}
|
|
int main(int argc,char** argv){try{
|
|
if(argc!=2 && argc!=3)throw Error("actual private Source frames and optional matching codec required");
|
|
auto codecfn=&codec;void* lib=nullptr;
|
|
if(argc==3){lib=dlopen(argv[2],RTLD_NOW|RTLD_LOCAL);if(!lib)throw Error("matching codec unavailable");
|
|
codecfn=reinterpret_cast<decltype(&gw_codec_serialize)>(dlsym(lib,"gw_codec_serialize"));if(!codecfn)throw Error("codec ABI missing");}
|
|
std::ifstream f(argv[1],std::ios::binary);if(!f)throw Error("private Source frames unavailable");Bytes b((std::istreambuf_iterator<char>(f)),{});Reader frames(b);std::vector<LegacyPacket> packets;
|
|
while(frames.left()){auto op=frames.le(2);auto size=frames.le(4);packets.push_back({uint32_t(op),frames.take(size)});}check(packets.size()==3 && packets[0].opcode==0x131 && packets[1].opcode==0x132 && packets[2].opcode==0x160);
|
|
auto go=turtle_spell_cast(0x132,packets[1].body);auto loot=turtle_loot_response(packets[2].body);check(go && go->spell==2575 && go->unit==4509 && go->targets==0x800 && go->target_unit==loot.owner && loot.type==2 && loot.items.size()==2 && std::find(go->hits.begin(),go->hits.end(),loot.owner)!=go->hits.end());
|
|
auto make_world=[&](){NativeWorldTranslation w{};w.selected.guid=4509;w.realm=70;w.location=WorldLocation{0,{0,0,0,0}};w.self_created=true;w.spells.insert(2575);auto& a=w.entities.actors[loot.owner];a.kind=5;a.entry=1731;a.gameobject_type=3;a.generation=7;a.presentation_realm=70;a.presentation_map=0;a.sent=true;a.eligible=true;a.modern=forever_game_object_guid(loot.owner,1731,70,0);return w;};
|
|
auto open=[&](NativeWorldTranslation& w){auto native=cast(w.entities.actors.at(loot.owner).modern);check(w.gameplay(0x3e0176,native).opcode==0x12e);w.gameplay_sent(0x3e0176,native);(void)w.translate(packets[0],0x10046,0,codecfn);check(!w.loot.opening);(void)w.translate(packets[1],0x10046,0,codecfn);};
|
|
auto w=make_world();open(w);check(w.loot.opening && w.loot.opening->source==loot.owner && w.loot.opening->kind==5);
|
|
auto bundle=w.translate(packets[2],0x10046,0,codecfn);Reader outer(bundle);check(outer.le(4)==1 && outer.le(4)==0x4700bf);auto output=outer.take(outer.le(4));outer.end();check(w.loot.window && !w.loot.opening);
|
|
if(!lib)check(!last_loot.empty() && last_loot[0]==10);
|
|
else{Reader n(output);check(unpack_guid(n,16)==Bytes(w.loot.window->owner.modern.begin(),w.loot.window->owner.modern.end()));
|
|
check(unpack_guid(n,16)==Bytes(w.loot.window->object.begin(),w.loot.window->object.end()));
|
|
check(n.le(1)==17 && n.le(1)==9 && n.le(1)==0 && n.le(1)==2);check(n.le(4)==loot.money && n.le(4)==loot.items.size() && n.le(4)==0);check(output.back()==0x80);}
|
|
Bytes item;le(item,1,4);append(item,pack_guid(w.loot.window->object));le(item,loot.items[0].slot,1);le(item,0,1);auto take=w.loot.items(item,w.entities);check(take.size()==1 && take[0].opcode==0x108 && take[0].body==Bytes{loot.items[0].slot});
|
|
auto release=w.loot.gameplay(0x3e00d2,pack_guid(w.loot.window->owner.modern),w.entities);check(release.opcode==0x15f);
|
|
{auto x=make_world();open(x);x.entities.actors.at(loot.owner).generation++;auto response=x.translate(packets[2],0x10046,0,codecfn);check(response==Bytes(4,0) && !x.loot.window);}
|
|
{auto x=make_world();open(x);x.entities.actors.at(loot.owner).gameobject_type=2;check(x.translate(packets[2],0x10046,0,codecfn)==Bytes(4,0) && !x.loot.window);}
|
|
{auto x=make_world();auto request=cast(x.entities.actors.at(loot.owner).modern);x.gameplay_sent(0x3e0176,request);(void)x.translate(packets[0],0x10046,0,codecfn);auto bad=packets[1];bad.body.back()^=1;(void)x.translate(bad,0x10046,0,codecfn);check(!x.loot.opening);}
|
|
|
|
{auto x=make_world();x.entities.actors.at(loot.owner).gameobject_type=2;open(x);check(!x.loot.opening);check(x.translate(packets[2],0x10046,0,codecfn)==Bytes(4,0));}
|
|
{auto x=make_world();open(x);x.loot.opening_deadline=std::chrono::steady_clock::now()-std::chrono::seconds(1);check(x.translate(packets[2],0x10046,0,codecfn)==Bytes(4,0) && !x.loot.opening);}
|
|
{auto x=make_world();open(x);TurtleGroupList g;g.explicit_solo=false;g.leader=4509;x.loot.group=g;check(x.translate(packets[2],0x10046,0,codecfn)==Bytes(4,0) && !x.loot.window && !x.loot.requests.empty());}
|
|
{auto x=make_world();open(x);auto wrong=packets[2];wrong.body[0]^=1;check(x.translate(wrong,0x10046,0,codecfn)==Bytes(4,0) && !x.loot.window);}
|
|
std::cout<<"PASS genuine Source GO chest and loot replay, same generation, slot/release guards and grouped/stale/expiry/owner holds\n";return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|