fix v1-encoded item descriptions
This commit is contained in:
+4
-20
@@ -1047,44 +1047,28 @@ void Client::use_character_bank(int8_t index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Client::print_inventory(FILE* stream) const {
|
void Client::print_inventory(FILE* stream) const {
|
||||||
|
auto s = this->require_server_state();
|
||||||
auto p = this->character();
|
auto p = this->character();
|
||||||
shared_ptr<const ItemNameIndex> name_index;
|
|
||||||
try {
|
|
||||||
name_index = this->require_server_state()->item_name_index(this->version());
|
|
||||||
} catch (const runtime_error&) {
|
|
||||||
}
|
|
||||||
fprintf(stream, "[PlayerInventory] Meseta: %" PRIu32 "\n", p->disp.stats.meseta.load());
|
fprintf(stream, "[PlayerInventory] Meseta: %" PRIu32 "\n", p->disp.stats.meseta.load());
|
||||||
fprintf(stream, "[PlayerInventory] %hhu items\n", p->inventory.num_items);
|
fprintf(stream, "[PlayerInventory] %hhu items\n", p->inventory.num_items);
|
||||||
for (size_t x = 0; x < p->inventory.num_items; x++) {
|
for (size_t x = 0; x < p->inventory.num_items; x++) {
|
||||||
const auto& item = p->inventory.items[x];
|
const auto& item = p->inventory.items[x];
|
||||||
auto hex = item.data.hex();
|
auto hex = item.data.hex();
|
||||||
if (name_index) {
|
auto name = s->describe_item(this->version(), item.data, false);
|
||||||
auto name = name_index->describe_item(item.data);
|
|
||||||
fprintf(stream, "[PlayerInventory] %2zu: [+%08" PRIX32 "] %s (%s)\n", x, item.flags.load(), hex.c_str(), name.c_str());
|
fprintf(stream, "[PlayerInventory] %2zu: [+%08" PRIX32 "] %s (%s)\n", x, item.flags.load(), hex.c_str(), name.c_str());
|
||||||
} else {
|
|
||||||
fprintf(stream, "[PlayerInventory] %2zu: [+%08" PRIX32 "] %s\n", x, item.flags.load(), hex.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::print_bank(FILE* stream) const {
|
void Client::print_bank(FILE* stream) const {
|
||||||
|
auto s = this->require_server_state();
|
||||||
auto p = this->character();
|
auto p = this->character();
|
||||||
shared_ptr<const ItemNameIndex> name_index;
|
|
||||||
try {
|
|
||||||
name_index = this->require_server_state()->item_name_index(this->version());
|
|
||||||
} catch (const runtime_error&) {
|
|
||||||
}
|
|
||||||
fprintf(stream, "[PlayerBank] Meseta: %" PRIu32 "\n", p->bank.meseta.load());
|
fprintf(stream, "[PlayerBank] Meseta: %" PRIu32 "\n", p->bank.meseta.load());
|
||||||
fprintf(stream, "[PlayerBank] %" PRIu32 " items\n", p->bank.num_items.load());
|
fprintf(stream, "[PlayerBank] %" PRIu32 " items\n", p->bank.num_items.load());
|
||||||
for (size_t x = 0; x < p->bank.num_items; x++) {
|
for (size_t x = 0; x < p->bank.num_items; x++) {
|
||||||
const auto& item = p->bank.items[x];
|
const auto& item = p->bank.items[x];
|
||||||
const char* present_token = item.present ? "" : " (missing present flag)";
|
const char* present_token = item.present ? "" : " (missing present flag)";
|
||||||
auto hex = item.data.hex();
|
auto hex = item.data.hex();
|
||||||
if (name_index) {
|
auto name = s->describe_item(this->version(), item.data, false);
|
||||||
auto name = name_index->describe_item(item.data);
|
|
||||||
fprintf(stream, "[PlayerBank] %3zu: %s (%s) (x%hu)%s\n", x, hex.c_str(), name.c_str(), item.amount.load(), present_token);
|
fprintf(stream, "[PlayerBank] %3zu: %s (%s) (x%hu)%s\n", x, hex.c_str(), name.c_str(), item.amount.load(), present_token);
|
||||||
} else {
|
|
||||||
fprintf(stream, "[PlayerBank] %3zu: %s (x%hu)%s\n", x, hex.c_str(), item.amount.load(), present_token);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,9 +97,7 @@ const array<const char*, 0x11> name_for_s_rank_special = {
|
|||||||
"King\'s",
|
"King\'s",
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string ItemNameIndex::describe_item(
|
std::string ItemNameIndex::describe_item(const ItemData& item, bool include_color_escapes) const {
|
||||||
const ItemData& item,
|
|
||||||
bool include_color_escapes) const {
|
|
||||||
if (item.data1[0] == 0x04) {
|
if (item.data1[0] == 0x04) {
|
||||||
return string_printf("%s%" PRIu32 " Meseta", include_color_escapes ? "$C7" : "", item.data2d.load());
|
return string_printf("%s%" PRIu32 " Meseta", include_color_escapes ? "$C7" : "", item.data2d.load());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -406,8 +406,14 @@ shared_ptr<const ItemNameIndex> ServerState::item_name_index(Version version) co
|
|||||||
}
|
}
|
||||||
|
|
||||||
string ServerState::describe_item(Version version, const ItemData& item, bool include_color_codes) const {
|
string ServerState::describe_item(Version version, const ItemData& item, bool include_color_codes) const {
|
||||||
|
if (is_v1(version)) {
|
||||||
|
ItemData encoded = item;
|
||||||
|
encoded.encode_for_version(version, this->item_parameter_table(version));
|
||||||
|
return this->item_name_index(version)->describe_item(encoded, include_color_codes);
|
||||||
|
} else {
|
||||||
return this->item_name_index(version)->describe_item(item, include_color_codes);
|
return this->item_name_index(version)->describe_item(item, include_color_codes);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ItemData ServerState::parse_item_description(Version version, const string& description) const {
|
ItemData ServerState::parse_item_description(Version version, const string& description) const {
|
||||||
return this->item_name_index(version)->parse_item_description(description);
|
return this->item_name_index(version)->parse_item_description(description);
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user