79 lines
4.5 KiB
C++
79 lines
4.5 KiB
C++
#include "world_translation.hpp"
|
|
#include <functional>
|
|
#include <iostream>
|
|
#include <vector>
|
|
using namespace gateway;
|
|
namespace {
|
|
unsigned checks=0,failures=0;
|
|
void check(bool ok,const char* why){++checks;if(!ok){++failures;std::cerr<<"FAIL "<<why<<'\n';}}
|
|
constexpr uint64_t banker=(0xf130ULL<<48)|(2455ULL<<24)|1;
|
|
void prepare(NativeWorldTranslation& w){
|
|
w.realm=70;w.selected.guid=42;w.self_created=true;w.location=WorldLocation{1,{0,0,0,0}};
|
|
auto& a=w.entities.actors[banker];a.entry=2455;a.kind=3;a.sent=a.eligible=true;a.generation=3;
|
|
a.presentation_realm=70;a.presentation_map=1;a.modern=forever_creature_guid(banker,2455,70,1);
|
|
}
|
|
Bytes request(uint64_t guid){Bytes b;le(b,guid,8);return b;}
|
|
Bytes golden(const Guid128& guid){
|
|
auto body=pack_guid(guid);le(body,67,4);le(body,0x80,1);
|
|
Bytes b;le(b,1,4);le(b,0x47031b,4);le(b,body.size(),4);append(b,body);return b;
|
|
}
|
|
Bytes show(NativeWorldTranslation& w,const Bytes& b){return w.translate({0x1b8,b},0x46010046,0,nullptr);}
|
|
bool held(NativeWorldTranslation& w,const Bytes& b){try{return show(w,b)==Bytes(4);}catch(const Error&){return true;}}
|
|
Bytes buy(NativeWorldTranslation& w){auto b=pack_guid(w.entities.actors.at(banker).modern);b.push_back(0);return b;}
|
|
}
|
|
int main(){
|
|
using Change=std::function<void(NativeWorldTranslation&)>;
|
|
const std::vector<Change> world_changes={
|
|
[](auto& w){w.self_created=false;},[](auto& w){w.location.reset();},
|
|
[](auto& w){w.logout_complete=true;},[](auto& w){w.pending_teleport.emplace();},
|
|
[](auto& w){w.far_transfer.emplace();},[](auto& w){w.realm=0;},[](auto& w){w.selected.guid=0;}};
|
|
auto changes=world_changes;
|
|
changes.insert(changes.end(),{
|
|
[](auto& w){w.entities.actors.at(banker).eligible=false;},
|
|
[](auto& w){w.entities.actors.at(banker).sent=false;},
|
|
[](auto& w){w.entities.actors.at(banker).generation=0;},
|
|
[](auto& w){w.entities.actors.at(banker).presentation_realm=71;},
|
|
[](auto& w){w.entities.actors.at(banker).presentation_map=2;},
|
|
[](auto& w){w.realm=71;},[](auto& w){w.location->map=2;},
|
|
[](auto& w){w.entities.actors.at(banker).kind=4;},
|
|
[](auto& w){w.entities.actors.erase(banker);}});
|
|
for(const auto& change:changes){
|
|
NativeWorldTranslation w;prepare(w);change(w);
|
|
check(held(w,request(banker)),"invalid current banker must not open native interaction");
|
|
check(!w.equipment_bank_open(),"invalid bank context not usable");
|
|
}
|
|
for(const auto& change:changes){
|
|
NativeWorldTranslation w;prepare(w);
|
|
check(show(w,request(banker))==golden(w.entities.actors.at(banker).modern),"exact genuine bank-open packet");
|
|
check(w.equipment_bank_open(),"fresh banker usable");
|
|
auto action=buy(w);auto sent=w.gameplay(0x3f012c,action);
|
|
check(sent.opcode==0x1b9 && sent.body==request(banker),"bank bag purchase names genuine source banker");
|
|
change(w);
|
|
check(!w.equipment_bank_open(),"retired bank scope loses access");
|
|
bool refused=false;try{(void)w.gameplay(0x3f012c,action);}catch(const Error&){refused=true;}
|
|
check(refused,"bank purchase cannot use retired presentation");
|
|
}
|
|
for(size_t size=0;size<8;++size){
|
|
NativeWorldTranslation w;prepare(w);auto b=request(banker);b.resize(size);
|
|
check(held(w,b) && !w.character_bank,"truncated bank response does not open");
|
|
check(show(w,request(banker))==golden(w.entities.actors.at(banker).modern),"valid response after truncated input");
|
|
}
|
|
{
|
|
NativeWorldTranslation w;prepare(w);auto b=request(banker);b.push_back(0);
|
|
check(held(w,b) && !w.character_bank,"trailing bank response does not open");
|
|
show(w,request(banker));++w.entities.actors.at(banker).generation;
|
|
check(!w.equipment_bank_open(),"old offer cannot bind recreated generation");
|
|
check(show(w,request(banker))==golden(w.entities.actors.at(banker).modern) && w.equipment_bank_open(),"fresh source offer binds recreated generation");
|
|
}
|
|
{
|
|
NativeWorldTranslation w;prepare(w);
|
|
check(show(w,request(42))==golden(forever_player_guid(42,70)) && w.equipment_bank_open(),"genuine GM self-bank preserved");
|
|
}
|
|
for(const auto& change:world_changes){
|
|
NativeWorldTranslation w;prepare(w);change(w);
|
|
check(held(w,request(w.selected.guid)) && !w.equipment_bank_open(),"GM bank still requires active owner context");
|
|
}
|
|
std::cout<<checks<<" character-bank checks, "<<failures<<" failures\n";
|
|
return failures?1:0;
|
|
}
|