From ce2cf1b56bca91f5c9fc9c22fb8d729b2d64b918 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Tue, 26 Jul 2022 19:59:31 -0700 Subject: [PATCH] fix quest menu bug --- src/CommandFormats.hh | 3 +++ src/ReceiveCommands.cc | 58 ++++++++++-------------------------------- 2 files changed, 17 insertions(+), 44 deletions(-) diff --git a/src/CommandFormats.hh b/src/CommandFormats.hh index ce8f98a3..f22c3875 100644 --- a/src/CommandFormats.hh +++ b/src/CommandFormats.hh @@ -502,6 +502,9 @@ struct S_Unknown_GC_0E { // specifies... something else. These two bits directly correspond to the two // lowest bits in the flags field of the game menu: 02 specifies that the game // is locked, but the function of 01 is unknown. +// Annoyingly, the no-arguments form of the command can have any flag value, so +// it doesn't suffice to check the flag value to know which format is being +// used! struct C_MenuSelection_10_Flag00 { le_uint32_t menu_id; diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index d6550806..adf03ad9 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -766,59 +766,29 @@ void process_menu_item_info_request(shared_ptr s, shared_ptr s, shared_ptr c, - uint16_t, uint32_t flags, const string& data) { // 10 + uint16_t, uint32_t, const string& data) { // 10 bool uses_unicode = ((c->version == GameVersion::PC) || (c->version == GameVersion::BB)); uint32_t menu_id; uint32_t item_id; u16string password; - u16string unknown_a1; - uint8_t type_flags = flags & 3; - if (type_flags == 0) { + if (data.size() > sizeof(C_MenuSelection_10_Flag00)) { + if (uses_unicode) { + const auto& cmd = check_size_t(data); + password = cmd.password; + menu_id = cmd.menu_id; + item_id = cmd.item_id; + } else { + const auto& cmd = check_size_t(data); + password = decode_sjis(cmd.password); + menu_id = cmd.menu_id; + item_id = cmd.item_id; + } + } else { const auto& cmd = check_size_t(data); menu_id = cmd.menu_id; item_id = cmd.item_id; - } else if (type_flags == 1) { - if (uses_unicode) { - const auto& cmd = check_size_t(data); - menu_id = cmd.menu_id; - item_id = cmd.item_id; - unknown_a1 = cmd.unknown_a1; - } else { - const auto& cmd = check_size_t(data); - menu_id = cmd.menu_id; - item_id = cmd.item_id; - unknown_a1 = decode_sjis(cmd.unknown_a1); - } - } else if (type_flags == 2) { - if (uses_unicode) { - const auto& cmd = check_size_t(data); - menu_id = cmd.menu_id; - item_id = cmd.item_id; - password = cmd.password; - } else { - const auto& cmd = check_size_t(data); - menu_id = cmd.menu_id; - item_id = cmd.item_id; - password = decode_sjis(cmd.password); - } - } else if (type_flags == 3) { - if (uses_unicode) { - const auto& cmd = check_size_t(data); - menu_id = cmd.menu_id; - item_id = cmd.item_id; - unknown_a1 = cmd.unknown_a1; - password = cmd.password; - } else { - const auto& cmd = check_size_t(data); - menu_id = cmd.menu_id; - item_id = cmd.item_id; - unknown_a1 = decode_sjis(cmd.unknown_a1); - password = decode_sjis(cmd.password); - } - } else { - throw logic_error("invalid type flag"); } switch (menu_id) {