Files
WoW-Hybrid-gateway/tests/appearance_presentation_test.cpp

176 lines
10 KiB
C++

// Forward-only presentation of existing Source appearances; offline relation
// check against the default profile. No client, no rendering claim.
#include "gateway/character_creation.hpp"
#include "gateway/character_creation_profile.hpp"
#include <algorithm>
#include <cstdio>
#include <map>
#include <set>
#include <stdexcept>
#include <tuple>
using namespace gateway::character_creation;
namespace {
using Pairs=std::vector<std::array<uint32_t,2>>;
void check(bool good,const char* what){if(!good)throw std::runtime_error(what);}
void check_source_face_dependencies() {
struct Face {
uint8_t race, sex, first_skin, last_skin, face;
uint32_t option, choice;
};
// Both face overlays in every listed skin resolve to the original BLPs.
const Face faces[] = {
{3,0,9,13,0,31,551}, {3,0,9,13,1,31,552}, {3,0,9,13,9,31,560},
{3,1,9,10,0,36,634}, {3,1,9,10,5,36,639}, {3,1,9,10,6,36,640},
{6,1,1,1,0,379,1135},
{8,0,6,11,0,91,1315}, {8,0,6,11,1,91,1316}, {8,0,6,11,3,91,1318},
{8,1,6,11,0,96,1382}, {8,1,6,11,3,96,1385}, {8,1,6,11,5,96,1387}
};
for (const auto& face : faces) {
for (uint8_t skin = face.first_skin; skin <= face.last_skin; ++skin) {
const std::array<uint8_t,5> appearance{skin,face.face,0,0,0};
NativeCreate request;
request.race = face.race;
request.sex = face.sex;
request.customizations = source_presentation_choices(face.race, face.sex, appearance);
const auto choice = std::array<uint32_t,2>{face.option, face.choice};
check(std::ranges::find(request.customizations, choice) != request.customizations.end(),
"selected skin needs its matched face choice");
check(resolve_appearance(request) == appearance, "selected skin and face roundtrip");
}
}
NativeCreate mismatched;
mismatched.race = 3;
mismatched.sex = 0;
mismatched.customizations = source_presentation_choices(3, 0, {9,0,0,0,0});
// Dwarf face 561 belongs to a different skin group in the conversion table.
for (auto& pair : mismatched.customizations) if (pair[0] == 31) pair[1] = 561;
try { resolve_appearance(mismatched); }
catch (const Unsupported&) { return; }
throw std::runtime_error("unrelated face dependency accepted");
}
}
int main(){
check_source_face_dependencies();
// Human male: the original beards (choice option 9494) give each
// facial-hair value its own relation, so the strict projection resolves.
const std::array<SourceAppearance,2> human{{{1,0,{0,0,0,0,0}},{1,0,{3,2,5,4,1}}}};
const auto strict_human=project_source_appearances(human);
check(strict_human[0].resolved && strict_human[1].resolved,"strict projection resolves Human male");
check(source_presentation_choices(1,0,{0,0,0,0,0})==Pairs{{9,1},{10,20},{11,44},{12,61},{463,4138},{525,5056},{890,9925},{9494,78934}},
"Human male default tuple forward relations");
check(source_presentation_choices(1,0,{3,2,5,4,1})==Pairs{{9,4},{10,22},{11,49},{12,65},{463,4133},{525,5056},{890,9925},{9494,78935}},
"Human male second tuple forward relations");
check(source_presentation_choices(0,0,{0,0,0,0,0}).empty() && source_presentation_choices(1,2,{0,0,0,0,0}).empty(),
"identity bounds give no pairs");
check(source_presentation_choices(200,0,{0,0,0,0,0}).empty(),"unknown race gives no pairs");
check(source_presentation_choices(1,0,{255,255,255,255,255}).empty() &&
source_presentation_choices(1,0,{209,202,211,207,200}).empty(),
"a wholly unrecognized saved appearance has no native presentation");
// An Octo-only option must not erase the other four appearance fields.
// The server tuple remains strict; only the native roster presentation
// substitutes the nearest retained value for an unsupported option.
auto find_choice=[](const Pairs& pairs,uint32_t option){
for(const auto& pair:pairs)if(pair[0]==option)return pair[1];
return uint32_t(0);
};
for(uint8_t style=0;style<=13;++style){
const std::array<uint8_t,5> source{1,0,style,0,0};
const auto projected=source_presentation_choices(9,0,source);
check(find_choice(projected,102)==(style==0?1474u:1456u),
"Goblin male bald, topknot and saved missing-style presentation");
if(style==0||style==12){
NativeCreate request;
request.race=9;request.sex=0;request.customizations=projected;
check(resolve_appearance(request)==source,"Goblin male exact new-character inverse");
}
}
for(uint8_t style=0;style<=16;++style){
const auto projected=source_presentation_choices(9,1,{0,0,style,0,0});
const auto choice=style==0?1544u:style==16?1545u:1545u+style;
check(find_choice(projected,107)==choice,"Goblin female saved style selects source geoset");
}
const auto control=source_presentation_choices(1,0,{3,2,5,4,1});
for(size_t field=0;field<5;++field){
std::array<uint8_t,5> octo_only{3,2,5,4,1};octo_only[field]=200;
const auto forward=source_presentation_choices(1,0,octo_only);
check(!forward.empty() && forward==source_presentation_choices(1,0,octo_only),
"unsupported field retains deterministic native presentation");
if(field==0)check(find_choice(forward,11)==find_choice(control,11),"skin fallback retains hair style");
if(field==1)check(find_choice(forward,9)==find_choice(control,9),"face fallback retains skin");
if(field==2)check(find_choice(forward,9)==find_choice(control,9),"hair fallback retains skin");
if(field==3)check(find_choice(forward,11)==find_choice(control,11),"hair-colour fallback retains style");
if(field==4)check(find_choice(forward,9)==find_choice(control,9),"facial fallback retains skin");
const std::array<SourceAppearance,1> strict_row{{{1,0,octo_only}}};
check(!project_source_appearances(strict_row)[0].resolved,
"strict Source projection does not rewrite unsupported option");
}
// The owner-reported Octo Tauren horn variation 8 is outside the
// retained native profile; the other four fields remain present while
// the nearest known variation 7 is used for presentation.
const auto known_horn=source_presentation_choices(6,0,{0,0,0,0,7});
const auto extra_horn=source_presentation_choices(6,0,{0,0,0,0,8});
check(!known_horn.empty() && extra_horn==known_horn,
"Octo Tauren horn retains the other customization fields");
// Sweep the profile's own Source domain per race/sex: every value of each
// field around the zero tuple, plus the skin x face x hair-style grid.
std::map<std::pair<int,int>,std::array<std::set<int>,5>> domain;
using SectionKey=std::tuple<int,int,int,int,int>;
using SectionGroup=std::tuple<int,int,int,int>;
std::set<SectionKey> sections;
std::set<std::tuple<int,int,int>> facial,hair;
std::map<SectionGroup,int> clear_count;
for(const auto& s:profile::Sections)if(!(s.flags&1u))++clear_count[{s.race,s.sex,s.section,s.variation}];
for(const auto& s:profile::Sections){
// Source player bytes use appended indices for flagged section rows.
// Do not report the old raw-color union as a valid tuple denominator.
const auto colour=int(s.color)+((s.flags&1u)?clear_count[{s.race,s.sex,s.section,s.variation}]:0);
if(colour>255)continue;
sections.emplace(s.race,s.sex,s.section,s.variation,colour);
auto& d=domain[{s.race,s.sex}];
if(s.section==0&&s.variation==0)d[0].insert(colour);
if(s.section==1)d[1].insert(s.variation);
if(s.section==3){d[2].insert(s.variation);d[3].insert(colour);}
}
for(const auto& f:profile::FacialHair){domain[{f.race,f.sex}][4].insert(f.variation);facial.emplace(f.race,f.sex,f.variation);}
for(const auto& h:profile::HairGeosets)hair.emplace(h.race,h.sex,h.variation);
auto source_valid=[&](const SourceAppearance& row){
const auto& a=row.values;const auto race=row.race,sex=row.sex;
return sections.contains({race,sex,0,0,a[0]})&&sections.contains({race,sex,1,a[1],a[0]})&&
sections.contains({race,sex,3,a[2],a[3]})&&hair.contains({race,sex,a[2]})&&facial.contains({race,sex,a[4]});
};
unsigned long total=0,valid_total=0,strict_total=0,forward_total=0,fallback_total=0;
for(auto& [key,d]:domain){
if(key.first>10)continue;
for(auto& values:d)if(values.empty())values.insert(0);
std::vector<SourceAppearance> rows;
for(int field=0;field<5;++field)for(int value:d[field]){
SourceAppearance row{uint8_t(key.first),uint8_t(key.second),{}};row.values[field]=uint8_t(value);rows.push_back(row);}
for(int skin:d[0])for(int face:d[1])for(int style:d[2])
rows.push_back({uint8_t(key.first),uint8_t(key.second),{uint8_t(skin),uint8_t(face),uint8_t(style),0,0}});
const auto strict=project_source_appearances(rows);
unsigned long valid=0,strict_ok=0,forward_ok=0;
for(size_t i=0;i<rows.size();++i){
const auto forward=source_presentation_choices(rows[i].race,rows[i].sex,rows[i].values);
uint32_t previous=0;
for(const auto& pair:forward){check(pair[0]>previous && pair[1],"pairs ordered by unique option");previous=pair[0];}
if(source_valid(rows[i]))++valid;
else if(!forward.empty())++fallback_total;
if(!forward.empty())++forward_ok;
if(strict[i].resolved){++strict_ok;check(forward==strict[i].choices,"forward equals the strict projection wherever that resolves");}
}
std::printf("race %2d sex %d: valid Source %lu/%zu; strict %lu/%lu; forward %lu/%lu\n",
key.first,key.second,valid,rows.size(),strict_ok,valid,forward_ok,valid);
total+=rows.size();valid_total+=valid;strict_total+=strict_ok;forward_total+=forward_ok;
check(forward_ok>=strict_ok,"forward never covers less than strict");
}
check(total && forward_total>strict_total && fallback_total>0,
"forward presentation retains fields for out-of-profile Source values");
std::printf("Sampled tuples %lu; Source-valid %lu: strict resolves %lu, forward gives pairs for %lu.\n"
"This per-axis plus skin/face/style grid is bounded coverage, not the complete Source Cartesian domain.\n"
"Appearance presentation relations PASS; offline only, no rendering claim.\n",
total,valid_total,strict_total,forward_total);
return 0;
}