116 lines
5.7 KiB
C++
116 lines
5.7 KiB
C++
#include "gateway/character_creation.hpp"
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
namespace cc = gateway::character_creation;
|
|
using Appearance = std::array<uint8_t,5>;
|
|
|
|
void require(bool ok, const char* why) {
|
|
if (!ok) throw std::runtime_error(why);
|
|
}
|
|
|
|
std::vector<std::array<uint32_t,2>> roundtrip(Appearance source) {
|
|
auto choices = cc::source_presentation_choices(1,0,source);
|
|
cc::NativeCreate request{};
|
|
request.race=1;
|
|
request.sex=0;
|
|
request.customizations=choices;
|
|
require(cc::resolve_appearance(request)==source, "saved inverse differs");
|
|
const std::array<cc::SourceAppearance,1> rows{{{1,0,source}}};
|
|
const auto strict = cc::project_source_appearances(rows);
|
|
require(strict.front().resolved && strict.front().choices==choices, "strict batch differs");
|
|
return choices;
|
|
}
|
|
|
|
bool option(const auto& choices, uint32_t parent, uint32_t child) {
|
|
return std::ranges::find(choices,std::array<uint32_t,2>{parent,child})!=choices.end();
|
|
}
|
|
|
|
auto creation(const std::vector<std::array<uint32_t,2>>& choices) {
|
|
const std::string name="Appearance";
|
|
gateway::Bytes packet(18,0);
|
|
packet[0]=static_cast<uint8_t>(name.size()<<2);
|
|
packet[3]=1;
|
|
packet[4]=1;
|
|
packet[6]=static_cast<uint8_t>(choices.size());
|
|
std::fill(packet.begin()+10,packet.begin()+14,255);
|
|
packet.insert(packet.end(),name.begin(),name.end());
|
|
for(const auto& pair:choices) {
|
|
gateway::le(packet,pair[0],4);
|
|
gateway::le(packet,pair[1],4);
|
|
}
|
|
const std::array<std::array<uint8_t,2>,1> pairs{{{1,1}}};
|
|
return cc::translate_request(cc::NativeCreateOpcode,packet,pairs);
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
try {
|
|
const bool baseline=argc>1 && std::string(argv[1])=="baseline";
|
|
const Appearance normal{0,0,0,0,0};
|
|
require(option(roundtrip(normal),9,1),"ordinary skin changed");
|
|
require(creation(roundtrip(normal)).appearance==normal,"ordinary character creation changed");
|
|
for(uint8_t sex: {0,1}) {
|
|
const uint8_t skin = sex==0 ? 21 : 13;
|
|
const uint32_t hd = sex==0 ? 1066 : 1127;
|
|
const Appearance stored{skin,0,0,0,1};
|
|
cc::NativeCreate request{};
|
|
request.race=6;request.sex=sex;
|
|
request.customizations=cc::source_presentation_choices(6,sex,stored);
|
|
const std::array<cc::SourceAppearance,1> stored_rows{{{6,sex,stored}}};
|
|
const auto strict=cc::project_source_appearances(stored_rows);
|
|
auto found=std::ranges::find_if(request.customizations,[=](const auto& pair){return pair[1]==hd;});
|
|
require((found!=request.customizations.end())!=baseline,"Grimtotem must use exact stored skin only on candidate");
|
|
require(strict.front().resolved!=baseline,"Grimtotem strict stored source acceptance differs");
|
|
std::cout<<"Grimtotem sex="<<unsigned(sex)<<" original="<<unsigned(skin)<<",0,0,0,1 pairs=";
|
|
for(const auto& pair:request.customizations)std::cout<<pair[0]<<"/"<<pair[1]<<",";
|
|
std::cout<<" strict="<<strict.front().resolved<<" inverse=";
|
|
try {
|
|
const auto inverse=cc::resolve_appearance(request);
|
|
for(const auto x:inverse)std::cout<<unsigned(x)<<",";
|
|
require(baseline || inverse==stored,"Grimtotem saved reverse did not retain all source bytes");
|
|
} catch(const cc::Unsupported& e) {
|
|
require(baseline,"Grimtotem reverse threw on candidate");
|
|
std::cout<<"held ("<<e.what()<<")";
|
|
}
|
|
std::cout<<"\n";
|
|
}
|
|
if(baseline){
|
|
const std::array<cc::SourceAppearance,1> rows{{{1,0,Appearance{15,0,0,0,0}}}};
|
|
const auto old=cc::project_source_appearances(rows);
|
|
require(!old.front().resolved && !option(cc::source_presentation_choices(1,0,rows[0].values),9,101000),"baseline contains new choice");
|
|
std::cout<<"baseline ordinary roundtrip passed, unrepresented token held\n";
|
|
return 0;
|
|
}
|
|
unsigned total=0;
|
|
for(uint8_t face=0;face<12;++face){
|
|
for(uint8_t style: {0,1,2}){
|
|
for(uint8_t color: {0,1}){
|
|
for(uint8_t facial: {0,1}){
|
|
auto choices=roundtrip({15,face,style,color,facial});
|
|
require(option(choices,9,101000),"token choice missing");
|
|
require(option(choices,10,20+face),"retained face byte mapped to a different HD face");
|
|
++total;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
require(option(roundtrip({14,0,0,0,0}),9,15),"existing neighboring token lost");
|
|
bool rejected=false;
|
|
try { (void)creation(roundtrip({15,0,0,0,0})); }
|
|
catch(const cc::Unsupported&) { rejected=true; }
|
|
require(rejected,"creator can use a stored-only skin");
|
|
const std::array<cc::SourceAppearance,3> invalid{{{1,0,{17,0,0,0,0}}, {1,0,{15,250,0,0,0}}, {1,0,{15,0,250,0,0}}}};
|
|
for(const auto& row:cc::project_source_appearances(invalid))require(!row.resolved,"undeclared tuple accepted");
|
|
cc::NativeCreate invalid_sex{};
|
|
invalid_sex.race=1;invalid_sex.sex=1;
|
|
invalid_sex.customizations=cc::source_presentation_choices(1,0,{15,0,0,0,0});
|
|
try { (void)cc::resolve_appearance(invalid_sex); } catch(const std::exception&){invalid_sex.race=0;}
|
|
require(!invalid_sex.race,"cross-sex choice admitted");
|
|
std::cout<<"Human male: "<<total<<" stored Arcane Binder tuples roundtrip; ordinary, sibling, unmapped, invalid face/hair, restricted creator and wrong-sex controls pass\n";
|
|
return 0;
|
|
} catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}
|
|
}
|