wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
client_version.cpp
Go to the documentation of this file.
2
3#include <array>
4#include <ostream>
5#include <utility>
6
8
9namespace wowlib {
10 std::ostream& operator<<(std::ostream& out, const ClientVersion& version) {
11 out << version.major << '.' << version.minor << '.' << version.patch << '.' << version.build;
12 if (version.isClassic()) out << " (" << enumName(version.flavor) << ')';
13 return out;
14 }
15
16 namespace {
17 // CASC_LOCALE_* values from CascLib (CascPort.h); kept here so the public header
18 // does not include CascLib.
19 constexpr std::array<std::pair<std::string_view, std::uint32_t>, 12> LocaleTable{
20 {
21 {"enUS", 0x00000002},
22 {"koKR", 0x00000004},
23 {"frFR", 0x00000010},
24 {"deDE", 0x00000020},
25 {"zhCN", 0x00000040},
26 {"esES", 0x00000080},
27 {"zhTW", 0x00000100},
28 {"enGB", 0x00000200},
29 {"esMX", 0x00001000},
30 {"ruRU", 0x00002000},
31 {"ptBR", 0x00004000},
32 {"itIT", 0x00008000},
33 }
34 };
35
36 constexpr std::size_t localeIndex(Locale locale) {
37 switch (locale) {
38 case Locale::enUS: return 0;
39 case Locale::koKR: return 1;
40 case Locale::frFR: return 2;
41 case Locale::deDE: return 3;
42 case Locale::zhCN: return 4;
43 case Locale::esES: return 5;
44 case Locale::zhTW: return 6;
45 case Locale::enGB: return 7;
46 case Locale::esMX: return 8;
47 case Locale::ruRU: return 9;
48 case Locale::ptBR: return 10;
49 case Locale::itIT: return 11;
50 }
51 std::unreachable();
52 }
53 }
54
55 std::string_view localeCode(Locale locale) {
56 return LocaleTable[localeIndex(locale)].first;
57 }
58
59 std::optional<Locale> localeFromCode(std::string_view code) {
60 constexpr std::array locales{
73 };
74 for (std::size_t i = 0; i < LocaleTable.size(); ++i)
75 if (LocaleTable[i].first == code) return locales[i];
76 return std::nullopt;
77 }
78
79 std::uint32_t cascLocaleFlag(Locale locale) {
80 return LocaleTable[localeIndex(locale)].second;
81 }
82}
Client version identity, the flavor axis that separates a client's CONTENT version from the engine ge...
std::string_view localeCode(Locale locale)
The four-letter code of locale ("enUS", ...) as used in MPQ locale directory and archive names.
std::optional< Locale > localeFromCode(std::string_view code)
Parse a four-letter locale code.
std::uint32_t cascLocaleFlag(Locale locale)
The CASC_LOCALE_* bit of locale for CascOpenStorage/CascOpenFile locale masks.
std::ostream & operator<<(std::ostream &out, const ClientVersion &version)
render version as "major.minor.patch.build", with the flavor appended when it is not Retail ("1....
constexpr std::string_view enumName(E value)
The enumerator name of value, straight from reflection — no handwritten stringification tables anywhe...
Definition reflect.hpp:19
Internal C++26 reflection utilities (<meta> based).
std::uint16_t patch
Patch version within the minor release.
std::uint32_t build
Exact client build number, e.g.
std::uint16_t major
Expansion number, e.g.
std::uint16_t minor
Minor version within the expansion.