From 24be0d8195cb4e38022c5c1fcade4bb0ebae8c55 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Tue, 6 Aug 2024 22:36:01 -0700 Subject: [PATCH] move default keyboard and joystick config into files --- src/Client.cc | 7 +++ src/ServerState.cc | 54 +++++++++++++------ src/ServerState.hh | 3 ++ system/blueburst/default-joystick-config.bin | Bin 0 -> 56 bytes system/blueburst/default-keyboard-config.bin | Bin 0 -> 364 bytes 5 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 system/blueburst/default-joystick-config.bin create mode 100644 system/blueburst/default-keyboard-config.bin diff --git a/src/Client.cc b/src/Client.cc index 7183424b..93b6df27 100644 --- a/src/Client.cc +++ b/src/Client.cc @@ -828,6 +828,13 @@ void Client::load_all_files() { if (!this->system_data) { this->system_data = make_shared(); + auto s = this->require_server_state(); + if (s->bb_default_keyboard_config) { + this->system_data->key_config = *s->bb_default_keyboard_config; + } + if (s->bb_default_joystick_config) { + this->system_data->joystick_config = *s->bb_default_joystick_config; + } files_manager->set_system(sys_filename, this->system_data); player_data_log.info("Created new system data"); } diff --git a/src/ServerState.cc b/src/ServerState.cc index 57886039..d84b3ad0 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -19,7 +19,7 @@ using namespace std; -ServerState::QuestF960Result::QuestF960Result(const phosg::JSON& json, std::shared_ptr name_index) { +ServerState::QuestF960Result::QuestF960Result(const phosg::JSON& json, shared_ptr name_index) { static const array day_names = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; this->meseta_cost = json.get_int("MesetaCost", 0); this->base_probability = json.get_int("BaseProbability", 0); @@ -754,8 +754,8 @@ void ServerState::load_config_early() { throw runtime_error("CLIENT drop mode cannot be allowed in V4"); } - auto parse_quest_flag_rewrites = [&json = this->config_json](const char* key) -> std::unordered_map { - std::unordered_map ret; + auto parse_quest_flag_rewrites = [&json = this->config_json](const char* key) -> unordered_map { + unordered_map ret; try { for (const auto& it : json->get_dict(key)) { if (!phosg::starts_with(it.first, "F_")) { @@ -967,7 +967,7 @@ void ServerState::load_config_early() { if (colors_json.size() != NUM_NON_PATCH_VERSIONS) { throw runtime_error("VersionNameColors list length is incorrect"); } - auto new_colors = make_unique>(); + auto new_colors = make_unique>(); for (size_t z = 0; z < NUM_NON_PATCH_VERSIONS; z++) { new_colors->at(z) = colors_json.at(z)->as_int(); } @@ -1296,8 +1296,8 @@ void ServerState::load_config_late() { } catch (const out_of_range&) { } - auto parse_primary_identifier_list = [&](const char* key, Version base_version) -> std::unordered_set { - std::unordered_set ret; + auto parse_primary_identifier_list = [&](const char* key, Version base_version) -> unordered_set { + unordered_set ret; try { for (const auto& pi_json : this->config_json->get_list(key)) { if (pi_json->is_int()) { @@ -1334,7 +1334,7 @@ void ServerState::load_config_late() { } void ServerState::load_bb_private_keys(bool from_non_event_thread) { - std::vector> new_keys; + vector> new_keys; for (const string& filename : phosg::list_directory("system/blueburst/keys")) { if (!phosg::ends_with(filename, ".nsk")) { continue; @@ -1343,7 +1343,6 @@ void ServerState::load_bb_private_keys(bool from_non_event_thread) { phosg::load_object_file("system/blueburst/keys/" + filename))); config_log.info("Loaded Blue Burst key file: %s", filename.c_str()); } - config_log.info("%zu Blue Burst key file(s) loaded", this->bb_private_keys.size()); auto set = [s = this->shared_from_this(), new_keys = std::move(new_keys)]() { s->bb_private_keys = std::move(new_keys); @@ -1351,6 +1350,28 @@ void ServerState::load_bb_private_keys(bool from_non_event_thread) { this->forward_or_call(from_non_event_thread, std::move(set)); } +void ServerState::load_bb_system_defaults(bool from_non_event_thread) { + shared_ptr> new_key_config; + shared_ptr> new_joystick_config; + + try { + new_key_config = make_shared>(phosg::load_object_file>("system/blueburst/default-keyboard-config.bin")); + config_log.info("Default Blue Burst keyboard config is present"); + } catch (const phosg::cannot_open_file&) { + } + try { + new_joystick_config = make_shared>(phosg::load_object_file>("system/blueburst/default-joystick-config.bin")); + config_log.info("Default Blue Burst joystick config is present"); + } catch (const phosg::cannot_open_file&) { + } + + auto set = [s = this->shared_from_this(), new_key_config = std::move(new_key_config), new_joystick_config = std::move(new_joystick_config)]() { + s->bb_default_keyboard_config = std::move(new_key_config); + s->bb_default_joystick_config = std::move(new_joystick_config); + }; + this->forward_or_call(from_non_event_thread, std::move(set)); +} + void ServerState::load_accounts(bool from_non_event_thread) { config_log.info("Indexing accounts"); shared_ptr new_index = make_shared(this->is_replay); @@ -1419,10 +1440,10 @@ void ServerState::clear_map_file_caches() { void ServerState::load_set_data_tables(bool from_non_event_thread) { config_log.info("Loading set data tables"); - std::array, NUM_VERSIONS> new_tables; - std::array, NUM_VERSIONS> new_tables_ep1_ult; - std::shared_ptr new_table_bb_solo; - std::shared_ptr new_table_bb_solo_ep1_ult; + array, NUM_VERSIONS> new_tables; + array, NUM_VERSIONS> new_tables_ep1_ult; + shared_ptr new_table_bb_solo; + shared_ptr new_table_bb_solo_ep1_ult; auto load_table = [&](Version version) -> void { auto data = this->load_map_file(version, "SetDataTableOn.rel"); @@ -1609,7 +1630,7 @@ shared_ptr ServerState::create_item_name_index_for_version( } void ServerState::load_item_name_indexes(bool from_non_event_thread) { - std::array, NUM_VERSIONS> new_indexes; + array, NUM_VERSIONS> new_indexes; for (size_t v_s = NUM_PATCH_VERSIONS; v_s < NUM_VERSIONS; v_s++) { Version v = static_cast(v_s); @@ -1690,7 +1711,7 @@ void ServerState::load_drop_tables(bool from_non_event_thread) { auto new_tool_random_set = make_shared(tool_data); config_log.info("Loading weapon tables"); - std::array, 4> new_weapon_random_sets; + array, 4> new_weapon_random_sets; const char* filenames[4] = { "system/item-tables/WeaponRandomNormal-gc-v3.rel", "system/item-tables/WeaponRandomHard-gc-v3.rel", @@ -1719,7 +1740,7 @@ void ServerState::load_drop_tables(bool from_non_event_thread) { it.second->multiply_all_rates(s->server_global_drop_rate_multiplier); } } - // We can't just move() new_rare_item_sets into place because its values are + // We can't just std::move() new_rare_item_sets into place because its values are // not const :( s->rare_item_sets.clear(); for (auto& it : new_rare_item_sets) { @@ -1736,7 +1757,7 @@ void ServerState::load_drop_tables(bool from_non_event_thread) { } void ServerState::load_item_definitions(bool from_non_event_thread) { - std::array, NUM_VERSIONS> new_item_parameter_tables; + array, NUM_VERSIONS> new_item_parameter_tables; for (size_t v_s = NUM_PATCH_VERSIONS; v_s < NUM_VERSIONS; v_s++) { Version v = static_cast(v_s); string path = phosg::string_printf("system/item-tables/ItemPMT-%s.prs", file_path_token_for_version(v)); @@ -1898,6 +1919,7 @@ void ServerState::load_all() { this->collect_network_addresses(); this->load_config_early(); this->load_bb_private_keys(false); + this->load_bb_system_defaults(false); this->load_accounts(false); this->clear_map_file_caches(); this->load_patch_indexes(false); diff --git a/src/ServerState.hh b/src/ServerState.hh index d56afc24..12e23c28 100644 --- a/src/ServerState.hh +++ b/src/ServerState.hh @@ -145,6 +145,8 @@ struct ServerState : public std::enable_shared_from_this { std::unordered_set notify_server_for_item_primary_identifiers_v4; bool notify_server_for_max_level_achieved = false; std::vector> bb_private_keys; + std::shared_ptr> bb_default_keyboard_config; + std::shared_ptr> bb_default_joystick_config; std::shared_ptr function_code_index; std::shared_ptr pc_patch_file_index; std::shared_ptr bb_patch_file_index; @@ -379,6 +381,7 @@ struct ServerState : public std::enable_shared_from_this { void load_config_early(); void load_config_late(); void load_bb_private_keys(bool from_non_event_thread); + void load_bb_system_defaults(bool from_non_event_thread); void load_accounts(bool from_non_event_thread); void load_teams(bool from_non_event_thread); void load_patch_indexes(bool from_non_event_thread); diff --git a/system/blueburst/default-joystick-config.bin b/system/blueburst/default-joystick-config.bin new file mode 100644 index 0000000000000000000000000000000000000000..043ec4e845e8119b744d5d4a39dab26f56b25145 GIT binary patch literal 56 qcmZQz{QsYUfsuiMfeDCNfS3c!1F=9N96$_WC;+JjAO=Z-R09BaHv+-{ literal 0 HcmV?d00001 diff --git a/system/blueburst/default-keyboard-config.bin b/system/blueburst/default-keyboard-config.bin new file mode 100644 index 0000000000000000000000000000000000000000..918fa244e86491e401ed26ec2edb7ff991ebac17 GIT binary patch literal 364 zcmajXISPbO5Jk~4(Nu5;1_sW<1{~W~6C**;7Wco2{^B(e#Dd46>OqN!I4Z~3Ct{+7 zcXkdV>Nw*MS6pyI