fix v1-encoded item descriptions

This commit is contained in:
Martin Michelsen
2024-03-01 23:19:18 -08:00
parent a2e3f4882d
commit d93e6405c3
4 changed files with 14 additions and 26 deletions
+6 -22
View File
@@ -1047,44 +1047,28 @@ void Client::use_character_bank(int8_t index) {
}
void Client::print_inventory(FILE* stream) const {
auto s = this->require_server_state();
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] %hhu items\n", p->inventory.num_items);
for (size_t x = 0; x < p->inventory.num_items; x++) {
const auto& item = p->inventory.items[x];
auto hex = item.data.hex();
if (name_index) {
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());
} else {
fprintf(stream, "[PlayerInventory] %2zu: [+%08" PRIX32 "] %s\n", x, item.flags.load(), hex.c_str());
}
auto name = s->describe_item(this->version(), item.data, false);
fprintf(stream, "[PlayerInventory] %2zu: [+%08" PRIX32 "] %s (%s)\n", x, item.flags.load(), hex.c_str(), name.c_str());
}
}
void Client::print_bank(FILE* stream) const {
auto s = this->require_server_state();
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] %" PRIu32 " items\n", p->bank.num_items.load());
for (size_t x = 0; x < p->bank.num_items; x++) {
const auto& item = p->bank.items[x];
const char* present_token = item.present ? "" : " (missing present flag)";
auto hex = item.data.hex();
if (name_index) {
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);
} else {
fprintf(stream, "[PlayerBank] %3zu: %s (x%hu)%s\n", x, hex.c_str(), item.amount.load(), present_token);
}
auto name = s->describe_item(this->version(), item.data, false);
fprintf(stream, "[PlayerBank] %3zu: %s (%s) (x%hu)%s\n", x, hex.c_str(), name.c_str(), item.amount.load(), present_token);
}
}
+1 -3
View File
@@ -97,9 +97,7 @@ const array<const char*, 0x11> name_for_s_rank_special = {
"King\'s",
};
std::string ItemNameIndex::describe_item(
const ItemData& item,
bool include_color_escapes) const {
std::string ItemNameIndex::describe_item(const ItemData& item, bool include_color_escapes) const {
if (item.data1[0] == 0x04) {
return string_printf("%s%" PRIu32 " Meseta", include_color_escapes ? "$C7" : "", item.data2d.load());
}
+7 -1
View File
@@ -406,7 +406,13 @@ 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 {
return this->item_name_index(version)->describe_item(item, include_color_codes);
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);
}
}
ItemData ServerState::parse_item_description(Version version, const string& description) const {