From 956e890ad6e77473079de7c456c9b65ea618b4bb Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Thu, 30 Nov 2023 10:24:27 -0800 Subject: [PATCH] use make_shared where appropriate --- src/ARCodeTranslator.cc | 2 +- src/CatSession.cc | 12 ++-- src/ChatCommands.cc | 5 +- src/CommonItemSet.cc | 8 +-- src/Episode3/DataIndexes.cc | 16 ++--- src/Episode3/PlayerState.cc | 31 +++------- src/Episode3/Server.cc | 16 ++--- src/Episode3/Tournament.cc | 10 ++-- src/FileContentsCache.cc | 4 +- src/FunctionCompiler.cc | 8 +-- src/IPStackSimulator.cc | 2 +- src/LevelTable.cc | 2 +- src/License.cc | 2 +- src/Lobby.cc | 4 +- src/Main.cc | 61 ++++++++++--------- src/PSOEncryption.cc | 17 +++--- src/PSOGCObjectGraph.cc | 4 +- src/PatchFileIndex.cc | 4 +- src/Player.cc | 30 +++++----- src/ProxyCommands.cc | 48 +++++++-------- src/ProxyServer.cc | 31 +++++----- src/Quest.cc | 20 +++---- src/QuestScript.cc | 2 +- src/ReceiveCommands.cc | 52 ++++++++-------- src/ReceiveSubcommands.cc | 2 +- src/ReplaySession.cc | 26 ++++---- src/SaveFileFormats.cc | 2 +- src/SendCommands.cc | 28 ++++----- src/Server.cc | 5 +- src/ServerShell.cc | 4 +- src/ServerState.cc | 116 +++++++++++++++++------------------- src/TeamIndex.cc | 4 +- src/TextArchive.cc | 6 +- 33 files changed, 279 insertions(+), 305 deletions(-) diff --git a/src/ARCodeTranslator.cc b/src/ARCodeTranslator.cc index 8896c77f..dae3d270 100644 --- a/src/ARCodeTranslator.cc +++ b/src/ARCodeTranslator.cc @@ -18,7 +18,7 @@ void run_ar_code_translator(const std::string& initial_directory, const std::str if (ends_with(filename, ".dol")) { string name = filename.substr(0, filename.size() - 4); string path = directory + "/" + filename; - files.emplace(name, new DOLFile(path.c_str())); + files.emplace(name, make_shared(path.c_str())); log.info("Loaded %s", name.c_str()); } } diff --git a/src/CatSession.cc b/src/CatSession.cc index 8a6849a4..be1de755 100644 --- a/src/CatSession.cc +++ b/src/CatSession.cc @@ -78,13 +78,13 @@ void CatSession::on_channel_input( if (command == 0x02 || command == 0x17 || command == 0x91 || command == 0x9B) { const auto& cmd = check_size_t(data, 0xFFFF); if (uses_v3_encryption(this->channel.version)) { - this->channel.crypt_in.reset(new PSOV3Encryption(cmd.server_key)); - this->channel.crypt_out.reset(new PSOV3Encryption(cmd.client_key)); + this->channel.crypt_in = make_shared(cmd.server_key); + this->channel.crypt_out = make_shared(cmd.client_key); this->log.info("Enabled V3 encryption (server key %08" PRIX32 ", client key %08" PRIX32 ")", cmd.server_key.load(), cmd.client_key.load()); } else { // PC, DC, or patch server - this->channel.crypt_in.reset(new PSOV2Encryption(cmd.server_key)); - this->channel.crypt_out.reset(new PSOV2Encryption(cmd.client_key)); + this->channel.crypt_in = make_shared(cmd.server_key); + this->channel.crypt_out = make_shared(cmd.client_key); this->log.info("Enabled V2 encryption (server key %08" PRIX32 ", client key %08" PRIX32 ")", cmd.server_key.load(), cmd.client_key.load()); } @@ -95,8 +95,8 @@ void CatSession::on_channel_input( throw runtime_error("BB encryption requires a key file"); } const auto& cmd = check_size_t(data, 0xFFFF); - this->channel.crypt_in.reset(new PSOBBEncryption(*this->bb_key_file, &cmd.server_key[0], sizeof(cmd.server_key))); - this->channel.crypt_out.reset(new PSOBBEncryption(*this->bb_key_file, &cmd.client_key[0], sizeof(cmd.client_key))); + this->channel.crypt_in = make_shared(*this->bb_key_file, &cmd.server_key[0], sizeof(cmd.server_key)); + this->channel.crypt_out = make_shared(*this->bb_key_file, &cmd.client_key[0], sizeof(cmd.client_key)); this->log.info("Enabled BB encryption"); } } diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index 0f7cebe1..b48ceef0 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -702,9 +702,8 @@ static void server_command_playrec(shared_ptr c, const std::string& args send_text_message(c, "$C4The recording does\nnot exist"); return; } - shared_ptr record(new Episode3::BattleRecord(data)); - shared_ptr battle_player( - new Episode3::BattleRecordPlayer(record, s->game_server->get_base())); + auto record = make_shared(data); + auto battle_player = make_shared(record, s->game_server->get_base()); auto game = create_game_generic( s, c, args, "", Episode::EP3, GameMode::NORMAL, 0, false, nullptr, battle_player); if (game) { diff --git a/src/CommonItemSet.cc b/src/CommonItemSet.cc index b3c3cecc..3050b071 100644 --- a/src/CommonItemSet.cc +++ b/src/CommonItemSet.cc @@ -205,7 +205,7 @@ AFSV2CommonItemSet::AFSV2CommonItemSet( for (size_t section_id = 0; section_id < 10; section_id++) { auto entry = pt_afs.get(difficulty * 10 + section_id); StringReader r(entry.first, entry.second); - shared_ptr table(new Table(pt_afs_data, r, false, false)); + auto table = make_shared
(pt_afs_data, r, false, false); this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::NORMAL, difficulty, section_id), table); this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::BATTLE, difficulty, section_id), table); this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::SOLO, difficulty, section_id), table); @@ -217,7 +217,7 @@ AFSV2CommonItemSet::AFSV2CommonItemSet( AFSArchive ct_afs(ct_afs_data); for (size_t difficulty = 0; difficulty < 4; difficulty++) { auto r = ct_afs.get_reader(difficulty * 10); - shared_ptr
table(new Table(ct_afs_data, r, false, false)); + auto table = make_shared
(ct_afs_data, r, false, false); for (size_t section_id = 0; section_id < 10; section_id++) { this->tables.emplace(this->key_for_table(Episode::EP1, GameMode::CHALLENGE, difficulty, section_id), table); } @@ -237,7 +237,7 @@ GSLV3CommonItemSet::GSLV3CommonItemSet(std::shared_ptr gsl_da tolower(abbreviation_for_difficulty(difficulty)), section_id); auto r = gsl.get_reader(filename); - shared_ptr
table(new Table(gsl_data, r, is_big_endian, true)); + auto table = make_shared
(gsl_data, r, is_big_endian, true); this->tables.emplace(this->key_for_table(episode, GameMode::NORMAL, difficulty, section_id), table); this->tables.emplace(this->key_for_table(episode, GameMode::BATTLE, difficulty, section_id), table); this->tables.emplace(this->key_for_table(episode, GameMode::SOLO, difficulty, section_id), table); @@ -256,7 +256,7 @@ GSLV3CommonItemSet::GSLV3CommonItemSet(std::shared_ptr gsl_da ((episode == Episode::EP2) ? "l" : ""), tolower(abbreviation_for_difficulty(difficulty))); auto r = gsl.get_reader(filename); - shared_ptr
table(new Table(gsl_data, r, is_big_endian, true)); + auto table = make_shared
(gsl_data, r, is_big_endian, true); for (size_t section_id = 0; section_id < 10; section_id++) { this->tables.emplace(this->key_for_table(episode, GameMode::CHALLENGE, difficulty, section_id), table); } diff --git a/src/Episode3/DataIndexes.cc b/src/Episode3/DataIndexes.cc index 4726f298..d12192be 100644 --- a/src/Episode3/DataIndexes.cc +++ b/src/Episode3/DataIndexes.cc @@ -2261,7 +2261,7 @@ CardIndex::CardIndex( continue; } - shared_ptr entry(new CardEntry({defs[x], "", "", "", {}})); + auto entry = make_shared(CardEntry{defs[x], "", "", "", {}}); if (!this->card_definitions.emplace(entry->def.card_id, entry).second) { throw runtime_error(string_printf( "duplicate card id: %08" PRIX32, entry->def.card_id.load())); @@ -2391,12 +2391,12 @@ MapIndex::VersionedMap::VersionedMap(std::string&& compressed_data, uint8_t lang "decompressed data size is incorrect (expected %zu bytes, read %zu bytes)", sizeof(MapDefinition), decompressed.size())); } - this->map.reset(new MapDefinition(*reinterpret_cast(decompressed.data()))); + this->map = make_shared(*reinterpret_cast(decompressed.data())); } shared_ptr MapIndex::VersionedMap::trial() const { if (!this->trial_map) { - this->trial_map.reset(new MapDefinitionTrial(*this->map)); + this->trial_map = make_shared(*this->map); } return this->trial_map; } @@ -2465,7 +2465,7 @@ MapIndex::MapIndex(const string& directory) { string compressed_data; shared_ptr decompressed_data; if (ends_with(filename, ".mnmd") || ends_with(filename, ".bind")) { - decompressed_data.reset(new MapDefinition(load_object_file(directory + "/" + filename))); + decompressed_data = make_shared(load_object_file(directory + "/" + filename)); base_filename = filename.substr(0, filename.size() - 5); } else if (ends_with(filename, ".mnm") || ends_with(filename, ".bin")) { compressed_data = load_file(directory + "/" + filename); @@ -2502,9 +2502,9 @@ MapIndex::MapIndex(const string& directory) { shared_ptr vm; if (decompressed_data) { - vm.reset(new VersionedMap(decompressed_data, language)); + vm = make_shared(decompressed_data, language); } else if (!compressed_data.empty()) { - vm.reset(new VersionedMap(std::move(compressed_data), language)); + vm = make_shared(std::move(compressed_data), language); } else { throw runtime_error("unknown map file format"); } @@ -2512,7 +2512,7 @@ MapIndex::MapIndex(const string& directory) { string name = vm->map->name.decode(vm->language); auto map_it = this->maps.find(vm->map->map_number); if (map_it == this->maps.end()) { - map_it = this->maps.emplace(vm->map->map_number, new Map(vm)).first; + map_it = this->maps.emplace(vm->map->map_number, make_shared(vm)).first; static_game_data_log.info("(%s) Created Episode 3 map %08" PRIX32 " %c (%s; %s)", filename.c_str(), vm->map->map_number.load(), @@ -2640,7 +2640,7 @@ COMDeckIndex::COMDeckIndex(const string& filename) { try { auto json = JSON::parse(load_file(filename)); for (const auto& def_json : json.as_list()) { - auto& def = this->decks.emplace_back(new COMDeckDefinition()); + auto& def = this->decks.emplace_back(make_shared()); def->index = this->decks.size() - 1; def->player_name = def_json->at(0).as_string(); def->deck_name = def_json->at(1).as_string(); diff --git a/src/Episode3/PlayerState.cc b/src/Episode3/PlayerState.cc index f29c1770..c28ce598 100644 --- a/src/Episode3/PlayerState.cc +++ b/src/Episode3/PlayerState.cc @@ -48,10 +48,7 @@ void PlayerState::init() { throw logic_error("replacing a player state object is not permitted"); } - this->deck_state.reset(new DeckState( - this->client_id, - s->deck_entries[client_id]->card_ids, - s->options.random_crypt)); + this->deck_state = make_shared(this->client_id, s->deck_entries[client_id]->card_ids, s->options.random_crypt); if (s->map_and_rules->rules.disable_deck_shuffle) { this->deck_state->disable_shuffle(); } @@ -77,10 +74,10 @@ void PlayerState::init() { throw runtime_error("SC card is not a Hunters or Arkz SC"); } - this->hand_and_equip.reset(new HandAndEquipState()); - this->card_short_statuses.reset(new parray()); - this->set_card_action_chains.reset(new parray()); - this->set_card_action_metadatas.reset(new parray()); + this->hand_and_equip = make_shared(); + this->card_short_statuses = make_shared>(); + this->set_card_action_chains = make_shared>(); + this->set_card_action_metadatas = make_shared>(); this->hand_and_equip->clear_FF(); for (size_t z = 0; z < 0x10; z++) { @@ -91,11 +88,7 @@ void PlayerState::init() { this->set_card_action_metadatas->at(z).clear_FF(); } - this->sc_card.reset(new Card( - this->deck_state->sc_card_id(), - this->sc_card_ref, - this->client_id, - s)); + this->sc_card = make_shared(this->deck_state->sc_card_id(), this->sc_card_ref, this->client_id, s); this->sc_card->init(); this->draw_initial_hand(); @@ -1232,8 +1225,7 @@ bool PlayerState::set_card_from_hand( auto s = this->server(); if (!skip_error_checks_and_atk_sub) { - int32_t code = this->error_code_for_client_setting_card( - card_ref, card_index, loc, assist_target_client_id); + int32_t code = this->error_code_for_client_setting_card(card_ref, card_index, loc, assist_target_client_id); if (code) { s->ruler_server->error_code1 = code; this->update_hand_and_equip_state_and_send_6xB4x02_if_needed(); @@ -1248,8 +1240,7 @@ bool PlayerState::set_card_from_hand( } if (!skip_error_checks_and_atk_sub) { - int16_t cost = s->ruler_server->set_cost_for_card( - this->client_id, card_ref); + int16_t cost = s->ruler_server->set_cost_for_card(this->client_id, card_ref); this->subtract_atk_points(cost); } @@ -1261,11 +1252,7 @@ bool PlayerState::set_card_from_hand( return 0; } this->card_refs[card_index + 1] = card_ref; - this->set_cards[card_index - 7].reset(new Card( - s->card_id_for_card_ref(card_ref), - card_ref, - this->client_id, - s)); + this->set_cards[card_index - 7] = make_shared(s->card_id_for_card_ref(card_ref), card_ref, this->client_id, s); auto new_card = this->set_cards[card_index - 7]; new_card->init(); diff --git a/src/Episode3/Server.cc b/src/Episode3/Server.cc index 04824008..fef9049c 100644 --- a/src/Episode3/Server.cc +++ b/src/Episode3/Server.cc @@ -75,32 +75,32 @@ Server::~Server() noexcept(false) { } void Server::init() { - this->map_and_rules.reset(new MapAndRulesState()); + this->map_and_rules = make_shared(); this->num_clients_present = 0; this->overlay_state.clear(); for (size_t z = 0; z < 4; z++) { this->presence_entries[z].clear(); - this->deck_entries[z].reset(new DeckEntry()); + this->deck_entries[z] = make_shared(); this->name_entries[z].clear(); this->name_entries_valid[z] = false; } - this->card_special.reset(new CardSpecial(this->shared_from_this())); + this->card_special = make_shared(this->shared_from_this()); // Note: The original implementation calls the default PSOV2Encryption // constructor for random_crypt, which just uses 0 as the seed. It then // re-seeds the generator later. We instead expect the caller to provide a // seeded generator, and we don't re-seed it at all. - // this->random_crypt.reset(new PSOV2Encryption(0)); + // this->random_crypt = make_shared(0); - this->state_flags.reset(new StateFlags()); + this->state_flags = make_shared(); this->clear_player_flags_after_dice_phase(); this->update_battle_state_flags_and_send_6xB4x03_if_needed(); - this->assist_server.reset(new AssistServer(this->shared_from_this())); - this->ruler_server.reset(new RulerServer(this->shared_from_this())); + this->assist_server = make_shared(this->shared_from_this()); + this->ruler_server = make_shared(this->shared_from_this()); this->ruler_server->link_objects(this->map_and_rules, this->state_flags, this->assist_server); this->send_6xB4x46(); @@ -1403,7 +1403,7 @@ void Server::setup_and_start_battle() { if (!this->check_presence_entry(z)) { this->name_entries[z].clear(); } else { - this->player_states[z].reset(new PlayerState(z, this->shared_from_this())); + this->player_states[z] = make_shared(z, this->shared_from_this()); this->player_states[z]->init(); } } diff --git a/src/Episode3/Tournament.cc b/src/Episode3/Tournament.cc index 05994c85..b573eb1f 100644 --- a/src/Episode3/Tournament.cc +++ b/src/Episode3/Tournament.cc @@ -364,10 +364,8 @@ void Tournament::init() { is_registration_complete = this->source_json.get_bool("is_registration_complete"); for (const auto& team_json : this->source_json.get_list("teams")) { - auto& team = this->teams.emplace_back(new Team( - this->shared_from_this(), - this->teams.size(), - team_json->get_int("max_players"))); + auto& team = this->teams.emplace_back(make_shared( + this->shared_from_this(), this->teams.size(), team_json->get_int("max_players"))); team->name = team_json->get_string("name"); team->password = team_json->get_string("password"); team_index_to_rounds_cleared.emplace_back(team_json->get_int("num_rounds_cleared")); @@ -806,7 +804,7 @@ TournamentIndex::TournamentIndex( } for (size_t z = 0; z < min(json.size(), 0x20); z++) { if (!json.at(z).is_null()) { - shared_ptr tourn(new Tournament(this->map_index, this->com_deck_index, json.at(z))); + auto tourn = make_shared(this->map_index, this->com_deck_index, json.at(z)); tourn->init(); if (!this->name_to_tournament.emplace(tourn->get_name(), tourn).second) { throw runtime_error("multiple tournaments have the same name: " + tourn->get_name()); @@ -820,7 +818,7 @@ TournamentIndex::TournamentIndex( throw runtime_error("tournament JSON dict length is incorrect"); } for (const auto& it : json.as_dict()) { - shared_ptr tourn(new Tournament(this->map_index, this->com_deck_index, *it.second)); + auto tourn = make_shared(this->map_index, this->com_deck_index, *it.second); tourn->init(); if (!this->name_to_tournament.emplace(tourn->get_name(), tourn).second) { // This is logic_error instead of runtime_error because JSON dicts are diff --git a/src/FileContentsCache.cc b/src/FileContentsCache.cc index 040c638e..e2638ed0 100644 --- a/src/FileContentsCache.cc +++ b/src/FileContentsCache.cc @@ -14,7 +14,7 @@ FileContentsCache::File::File( string&& data, uint64_t load_time) : name(name), - data(new string(std::move(data))), + data(make_shared(std::move(data))), load_time(load_time) {} shared_ptr FileContentsCache::replace( @@ -22,7 +22,7 @@ shared_ptr FileContentsCache::replace( if (t == 0) { t = now(); } - shared_ptr new_file(new File(name, std::move(data), t)); + auto new_file = make_shared(name, std::move(data), t); auto emplace_ret = this->name_to_file.emplace(name, new_file); if (!emplace_ret.second) { emplace_ret.first->second = new_file; diff --git a/src/FunctionCompiler.cc b/src/FunctionCompiler.cc index 500131bd..7a775266 100644 --- a/src/FunctionCompiler.cc +++ b/src/FunctionCompiler.cc @@ -127,7 +127,7 @@ shared_ptr compile_function_code( throw runtime_error("function compiler is not available"); #else - shared_ptr ret(new CompiledFunctionCode()); + auto ret = make_shared(); ret->arch = arch; ret->name = name; ret->index = 0; @@ -236,7 +236,7 @@ FunctionCodeIndex::FunctionCodeIndex(const string& directory) { shared_ptr FunctionCodeIndex::patch_menu(uint32_t specific_version) const { auto suffix = string_printf("-%08" PRIX32, specific_version); - shared_ptr ret(new Menu(MenuID::PATCHES, "Patches")); + auto ret = make_shared(MenuID::PATCHES, "Patches"); ret->items.emplace_back(PatchesMenuItemID::GO_BACK, "Go back", "Return to the\nmain menu", 0); for (const auto& it : this->name_and_specific_version_to_patch_function) { const auto& fn = it.second; @@ -266,7 +266,7 @@ DOLFileIndex::DOLFileIndex(const string& directory) { return; } - shared_ptr menu(new Menu(MenuID::PROGRAMS, "Programs")); + auto menu = make_shared(MenuID::PROGRAMS, "Programs"); this->menu = menu; menu->items.emplace_back(ProgramsMenuItemID::GO_BACK, "Go back", "Return to the\nmain menu", 0); @@ -280,7 +280,7 @@ DOLFileIndex::DOLFileIndex(const string& directory) { string name = filename.substr(0, filename.size() - (is_compressed_dol ? 8 : 4)); try { - shared_ptr dol(new File()); + auto dol = make_shared(); dol->menu_item_id = next_menu_item_id++; dol->name = name; diff --git a/src/IPStackSimulator.cc b/src/IPStackSimulator.cc index c36fa1a2..24275c3a 100644 --- a/src/IPStackSimulator.cc +++ b/src/IPStackSimulator.cc @@ -196,7 +196,7 @@ void IPStackSimulator::on_listen_accept(struct evconnlistener* listener, struct bufferevent* bev = bufferevent_socket_new(this->base.get(), fd, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS); - shared_ptr c(new IPClient(this->shared_from_this(), bev)); + auto c = make_shared(this->shared_from_this(), bev); this->bev_to_client.emplace(make_pair(bev, c)); bufferevent_setcb(bev, &IPStackSimulator::dispatch_on_client_input, nullptr, diff --git a/src/LevelTable.cc b/src/LevelTable.cc index 91107106..80e8fdd0 100644 --- a/src/LevelTable.cc +++ b/src/LevelTable.cc @@ -33,7 +33,7 @@ void PlayerStats::advance_to_level(uint8_t char_class, uint32_t level, shared_pt LevelTable::LevelTable(shared_ptr data, bool compressed) { if (compressed) { - this->data.reset(new string(prs_decompress(*data))); + this->data = make_shared(prs_decompress(*data)); } else { this->data = data; } diff --git a/src/License.cc b/src/License.cc index 782b9904..db26baba 100644 --- a/src/License.cc +++ b/src/License.cc @@ -141,7 +141,7 @@ LicenseIndex::LicenseIndex() { for (const auto& item : list_directory("system/licenses")) { if (ends_with(item, ".json")) { JSON json = JSON::parse(load_file("system/licenses/" + item)); - shared_ptr license(new License(json)); + auto license = make_shared(json); this->add(license); } } diff --git a/src/Lobby.cc b/src/Lobby.cc index d8e07e8a..3a064de5 100644 --- a/src/Lobby.cc +++ b/src/Lobby.cc @@ -87,7 +87,7 @@ void Lobby::create_item_creator() { default: throw logic_error("invalid lobby base version"); } - this->item_creator.reset(new ItemCreator( + this->item_creator = make_shared( common_item_set, rare_item_set, s->armor_random_set, @@ -101,7 +101,7 @@ void Lobby::create_item_creator() { this->difficulty, this->section_id, this->random_seed, - this->quest ? this->quest->battle_rules : nullptr)); + this->quest ? this->quest->battle_rules : nullptr); } void Lobby::create_ep3_server() { diff --git a/src/Main.cc b/src/Main.cc index b4264ffc..9b1e61be 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -363,13 +363,13 @@ static void a_encrypt_decrypt_fn(Arguments& args) { case Version::DC_V2: case Version::PC_V2: case Version::GC_NTE: - crypt.reset(new PSOV2Encryption(stoul(seed, nullptr, 16))); + crypt = make_shared(stoul(seed, nullptr, 16)); break; case Version::GC_V3: case Version::XB_V3: case Version::GC_EP3_TRIAL_EDITION: case Version::GC_EP3: - crypt.reset(new PSOV3Encryption(stoul(seed, nullptr, 16))); + crypt = make_shared(stoul(seed, nullptr, 16)); break; case Version::BB_V4: { string key_name = args.get("key"); @@ -378,7 +378,7 @@ static void a_encrypt_decrypt_fn(Arguments& args) { } seed = parse_data_string(seed, nullptr, ParseDataFlags::ALLOW_FILES); auto key = load_object_file("system/blueburst/keys/" + key_name + ".nsk"); - crypt.reset(new PSOBBEncryption(key, seed.data(), seed.size())); + crypt = make_shared(key, seed.data(), seed.size()); break; } default: @@ -1003,14 +1003,14 @@ Action a_encode_qst( string pvr_filename = ends_with(bin_filename, ".bin") ? (bin_filename.substr(0, bin_filename.size() - 3) + "pvr") : (bin_filename + ".pvr"); - shared_ptr bin_data(new string(load_file(bin_filename))); - shared_ptr dat_data(new string(load_file(dat_filename))); + auto bin_data = make_shared(load_file(bin_filename)); + auto dat_data = make_shared(load_file(dat_filename)); shared_ptr pvr_data; try { - pvr_data.reset(new string(load_file(pvr_filename))); + pvr_data = make_shared(load_file(pvr_filename)); } catch (const cannot_open_file&) { } - shared_ptr vq(new VersionedQuest(0, 0, version, 0, bin_data, dat_data, pvr_data)); + auto vq = make_shared(0, 0, version, 0, bin_data, dat_data, pvr_data); if (download) { vq = vq->create_download_quest(); } @@ -1064,7 +1064,7 @@ void a_extract_archive_fn(Arguments& args) { } string data = read_input_data(args); - shared_ptr data_shared(new string(std::move(data))); + auto data_shared = make_shared(std::move(data)); if (args.get(0) == "extract-afs") { AFSArchive arch(data_shared); @@ -1213,8 +1213,8 @@ Action a_cat_client( if (key_file_name.empty()) { throw runtime_error("a key filename is required for BB client emulation"); } - key.reset(new PSOBBEncryption::KeyFile( - load_object_file("system/blueburst/keys/" + key_file_name + ".nsk"))); + key = make_shared( + load_object_file("system/blueburst/keys/" + key_file_name + ".nsk")); } shared_ptr base(event_base_new(), event_base_free); auto cat_client_remote = make_sockaddr_storage(parse_netloc(args.get(1))).first; @@ -1246,18 +1246,18 @@ Action a_convert_rare_item_set( } auto version = get_cli_version(args); - shared_ptr data(new string(read_input_data(args))); + auto data = make_shared(read_input_data(args)); shared_ptr rs; if (ends_with(input_filename, ".json")) { - rs.reset(new RareItemSet(JSON::parse(*data), version, name_index)); + rs = make_shared(JSON::parse(*data), version, name_index); } else if (ends_with(input_filename, ".gsl")) { - rs.reset(new RareItemSet(GSLArchive(data, false), false)); + rs = make_shared(GSLArchive(data, false), false); } else if (ends_with(input_filename, ".gslb")) { - rs.reset(new RareItemSet(GSLArchive(data, true), true)); + rs = make_shared(GSLArchive(data, true), true); } else if (ends_with(input_filename, ".afs")) { - rs.reset(new RareItemSet(AFSArchive(data), is_v1(version))); + rs = make_shared(AFSArchive(data), is_v1(version)); } else if (ends_with(input_filename, ".rel")) { - rs.reset(new RareItemSet(*data, true)); + rs = make_shared(*data, true); } else { throw runtime_error("cannot determine input format; use a filename ending with .json, .gsl, .gslb, .afs, or .rel"); } @@ -1296,11 +1296,11 @@ Action a_describe_item( JSON::parse(load_file("system/item-tables/names-v2.json")), JSON::parse(load_file("system/item-tables/names-v3.json")), JSON::parse(load_file("system/item-tables/names-v4.json"))); - shared_ptr pmt_data_v2(new string(prs_decompress(load_file("system/item-tables/ItemPMT-v2.prs")))); + auto pmt_data_v2 = make_shared(prs_decompress(load_file("system/item-tables/ItemPMT-v2.prs"))); auto pmt_v2 = make_shared(pmt_data_v2, ItemParameterTable::Version::V2); - shared_ptr pmt_data_v3(new string(prs_decompress(load_file("system/item-tables/ItemPMT-gc.prs")))); + auto pmt_data_v3 = make_shared(prs_decompress(load_file("system/item-tables/ItemPMT-gc.prs"))); auto pmt_v3 = make_shared(pmt_data_v3, ItemParameterTable::Version::V3); - shared_ptr pmt_data_v4(new string(prs_decompress(load_file("system/item-tables/ItemPMT-bb.prs")))); + auto pmt_data_v4 = make_shared(prs_decompress(load_file("system/item-tables/ItemPMT-bb.prs"))); auto pmt_v4 = make_shared(pmt_data_v4, ItemParameterTable::Version::V4); ItemData item = name_index->parse_item_description(version, description); @@ -1375,7 +1375,7 @@ Action a_show_ep3_cards( unique_ptr text_english; try { JSON json = JSON::parse(load_file("system/ep3/text-english.json")); - text_english.reset(new TextArchive(json)); + text_english = make_unique(json); } catch (const exception& e) { } @@ -1426,7 +1426,7 @@ Action a_generate_ep3_cards_html( unique_ptr text_english; try { JSON json = JSON::parse(load_file("system/ep3/text-english.json")); - text_english.reset(new TextArchive(json)); + text_english = make_unique(json); } catch (const exception& e) { } @@ -1698,14 +1698,13 @@ Action a_run_server_replay_log( } shared_ptr base(event_base_new(), event_base_free); - shared_ptr state(new ServerState(config_filename, is_replay)); + auto state = make_shared(config_filename, is_replay); state->init(); shared_ptr dns_server; if (state->dns_server_port && !is_replay) { config_log.info("Starting DNS server on port %hu", state->dns_server_port); - dns_server.reset(new DNSServer(base, state->local_address, - state->external_address)); + dns_server = make_shared(base, state->local_address, state->external_address); dns_server->listen("", state->dns_server_port); } else { config_log.info("DNS server is disabled"); @@ -1716,9 +1715,9 @@ Action a_run_server_replay_log( shared_ptr ip_stack_simulator; if (is_replay) { config_log.info("Starting proxy server"); - state->proxy_server.reset(new ProxyServer(base, state)); + state->proxy_server = make_shared(base, state); config_log.info("Starting game server"); - state->game_server.reset(new Server(base, state)); + state->game_server = make_shared(base, state); auto nop_destructor = +[](FILE*) {}; shared_ptr log_f(stdin, nop_destructor); @@ -1726,7 +1725,7 @@ Action a_run_server_replay_log( log_f = fopen_shared(replay_log_filename, "rt"); } - replay_session.reset(new ReplaySession(base, log_f.get(), state, args.get("require-basic-credentials"))); + replay_session = make_shared(base, log_f.get(), state, args.get("require-basic-credentials")); replay_session->start(); } else { @@ -1736,7 +1735,7 @@ Action a_run_server_replay_log( if (pc->behavior == ServerBehavior::PROXY_SERVER) { if (!state->proxy_server.get()) { config_log.info("Starting proxy server"); - state->proxy_server.reset(new ProxyServer(base, state)); + state->proxy_server = make_shared(base, state); } if (state->proxy_server.get()) { // For PC and GC, proxy sessions are dynamically created when a client @@ -1761,7 +1760,7 @@ Action a_run_server_replay_log( } else { if (!state->game_server.get()) { config_log.info("Starting game server"); - state->game_server.reset(new Server(base, state)); + state->game_server = make_shared(base, state); } string spec = string_printf("T-%hu-%s-%s-%s", pc->port, name_for_enum(pc->version), pc->name.c_str(), name_for_enum(pc->behavior)); state->game_server->listen(spec, "", pc->port, pc->version, pc->behavior); @@ -1770,7 +1769,7 @@ Action a_run_server_replay_log( if (!state->ip_stack_addresses.empty()) { config_log.info("Starting IP stack simulator"); - ip_stack_simulator.reset(new IPStackSimulator(base, state)); + ip_stack_simulator = make_shared(base, state); for (const auto& it : state->ip_stack_addresses) { auto netloc = parse_netloc(it); string spec = (netloc.second == 0) ? ("T-IPS-" + netloc.first) : string_printf("T-IPS-%hu", netloc.second); @@ -1796,7 +1795,7 @@ Action a_run_server_replay_log( should_run_shell = !replay_session.get(); } if (should_run_shell) { - shell.reset(new ServerShell(base, state)); + shell = make_shared(base, state); } config_log.info("Ready"); diff --git a/src/PSOEncryption.cc b/src/PSOEncryption.cc index b6d73f18..da773561 100644 --- a/src/PSOEncryption.cc +++ b/src/PSOEncryption.cc @@ -718,11 +718,11 @@ void PSOV2OrV3DetectorEncryption::encrypt(void* data, size_t size, bool advance) le_uint32_t encrypted = *reinterpret_cast(data); le_uint32_t decrypted_v2 = encrypted; - unique_ptr v2_crypt(new PSOV2Encryption(this->key)); + auto v2_crypt = make_unique(this->key); v2_crypt->decrypt(&decrypted_v2, sizeof(decrypted_v2), false); le_uint32_t decrypted_v3 = encrypted; - unique_ptr v3_crypt(new PSOV3Encryption(this->key)); + auto v3_crypt = make_unique(this->key); v3_crypt->decrypt(&decrypted_v3, sizeof(decrypted_v3), false); bool v2_match = this->v2_matches.count(decrypted_v2); @@ -760,9 +760,9 @@ void PSOV2OrV3ImitatorEncryption::encrypt(void* data, size_t size, bool advance) if (!this->active_crypt) { auto t = this->detector_crypt->type(); if (t == Type::V2) { - this->active_crypt.reset(new PSOV2Encryption(this->key)); + this->active_crypt = make_shared(this->key); } else if (t == Type::V3) { - this->active_crypt.reset(new PSOV3Encryption(this->key)); + this->active_crypt = make_shared(this->key); } else { throw logic_error("detector crypt is not V2 or V3"); } @@ -801,8 +801,7 @@ void PSOBBMultiKeyDetectorEncryption::decrypt(void* data, size_t size, bool adva for (const auto& key : this->possible_keys) { this->active_key = key; - this->active_crypt.reset(new PSOBBEncryption( - *this->active_key, this->seed.data(), this->seed.size())); + this->active_crypt = make_shared(*this->active_key, this->seed.data(), this->seed.size()); string test_data(reinterpret_cast(data), size); this->active_crypt->decrypt(test_data.data(), test_data.size(), false); if (this->expected_first_data.count(test_data)) { @@ -854,11 +853,9 @@ shared_ptr PSOBBMultiKeyImitatorEncryption::ensure_crypt() { // To handle this, we use the other crypt's seed if the type is JSD1. if ((key->subtype == PSOBBEncryption::Subtype::JSD1) && this->jsd1_use_detector_seed) { const auto& detector_seed = this->detector_crypt->get_seed(); - this->active_crypt.reset(new PSOBBEncryption( - *key, detector_seed.data(), detector_seed.size())); + this->active_crypt = make_shared(*key, detector_seed.data(), detector_seed.size()); } else { - this->active_crypt.reset(new PSOBBEncryption( - *key, this->seed.data(), this->seed.size())); + this->active_crypt = make_shared(*key, this->seed.data(), this->seed.size()); } } return this->active_crypt; diff --git a/src/PSOGCObjectGraph.cc b/src/PSOGCObjectGraph.cc index e3f22130..0fa90208 100644 --- a/src/PSOGCObjectGraph.cc +++ b/src/PSOGCObjectGraph.cc @@ -38,7 +38,7 @@ shared_ptr PSOGCObjectGraph::parse_vtable_memo( } const auto& vt = r.pget(addr & 0x01FFFFFF); - auto ret = this->all_vtables.emplace(addr, new VTable()).first->second; + auto ret = this->all_vtables.emplace(addr, make_shared()).first->second; ret->address = addr; ret->destroy_addr = vt.destroy; ret->update_addr = vt.update; @@ -57,7 +57,7 @@ shared_ptr PSOGCObjectGraph::parse_object_memo( const auto& obj = r.pget(addr & 0x01FFFFFF); string type_name = r.pget_cstr(obj.type_name_addr & 0x01FFFFFF); - auto ret = this->all_objects.emplace(addr, new Object()).first->second; + auto ret = this->all_objects.emplace(addr, make_shared()).first->second; ret->address = addr; ret->flags = obj.flags; ret->type_name = std::move(type_name); diff --git a/src/PatchFileIndex.cc b/src/PatchFileIndex.cc index 19bd5338..a8a45735 100644 --- a/src/PatchFileIndex.cc +++ b/src/PatchFileIndex.cc @@ -23,7 +23,7 @@ std::shared_ptr PatchFileIndex::File::load_data() { string relative_path = join(this->path_directories, "/") + "/" + this->name; string full_path = this->index->root_dir + "/" + relative_path; patch_index_log.info("Loading data for %s", relative_path.c_str()); - this->loaded_data.reset(new string(load_file(full_path))); + this->loaded_data = make_shared(load_file(full_path)); this->size = this->loaded_data->size(); } return this->loaded_data; @@ -70,7 +70,7 @@ PatchFileIndex::PatchFileIndex(const string& root_dir) auto st = stat(full_item_path); - shared_ptr f(new File(this)); + auto f = make_shared(this); f->path_directories = path_directories; f->name = item; diff --git a/src/Player.cc b/src/Player.cc index 0a3a7278..5566840b 100644 --- a/src/Player.cc +++ b/src/Player.cc @@ -36,7 +36,7 @@ ClientGameData::~ClientGameData() { } void ClientGameData::create_battle_overlay(shared_ptr rules, shared_ptr level_table) { - this->overlay_character_data.reset(new PSOBBCharacterFile(*this->character(true, false))); + this->overlay_character_data = make_shared(*this->character(true, false)); if (rules->weapon_and_armor_mode != BattleRules::WeaponAndArmorMode::ALLOW) { this->overlay_character_data->inventory.remove_all_items_of_type(0); @@ -89,7 +89,7 @@ void ClientGameData::create_challenge_overlay(Version version, size_t template_i auto p = this->character(true, false); const auto& tpl = get_challenge_template_definition(version, p->disp.visual.class_flags, template_index); - this->overlay_character_data.reset(new PSOBBCharacterFile(*p)); + this->overlay_character_data = make_shared(*p); auto overlay = this->overlay_character_data; for (size_t z = 0; z < overlay->inventory.items.size(); z++) { @@ -236,9 +236,9 @@ void ClientGameData::create_character_file( void ClientGameData::load_all_files() { if (this->bb_username.empty()) { - this->system_data.reset(new PSOBBBaseSystemFile()); - this->character_data.reset(new PSOBBCharacterFile()); - this->guild_card_data.reset(new PSOBBGuildCardFile()); + this->system_data = make_shared(); + this->character_data = make_shared(); + this->guild_card_data = make_shared(); return; } @@ -248,7 +248,7 @@ void ClientGameData::load_all_files() { string sys_filename = this->system_filename(); if (isfile(sys_filename)) { - this->system_data.reset(new PSOBBBaseSystemFile(load_object_file(sys_filename, true))); + this->system_data = make_shared(load_object_file(sys_filename, true)); player_data_log.info("Loaded system data from %s", sys_filename.c_str()); } @@ -266,13 +266,13 @@ void ClientGameData::load_all_files() { if (header.flag != 0x00000000) { throw runtime_error("incorrect flag in character file header"); } - this->character_data.reset(new PSOBBCharacterFile(freadx(f.get()))); + this->character_data = make_shared(freadx(f.get())); player_data_log.info("Loaded character data from %s", char_filename.c_str()); // If there was no .psosys file, load the system file from the .psochar // file instead if (!this->system_data) { - this->system_data.reset(new PSOBBBaseSystemFile(freadx(f.get()))); + this->system_data = make_shared(freadx(f.get())); player_data_log.info("Loaded system data from %s", char_filename.c_str()); } } @@ -280,7 +280,7 @@ void ClientGameData::load_all_files() { string card_filename = this->guild_card_filename(); if (isfile(card_filename)) { - this->guild_card_data.reset(new PSOBBGuildCardFile(load_object_file(card_filename))); + this->guild_card_data = make_shared(load_object_file(card_filename)); player_data_log.info("Loaded Guild Card data from %s", card_filename.c_str()); } @@ -289,26 +289,26 @@ void ClientGameData::load_all_files() { string nsa_filename = this->legacy_account_filename(); shared_ptr nsa_data; if (isfile(nsa_filename)) { - nsa_data.reset(new LegacySavedAccountDataBB(load_object_file(nsa_filename))); + nsa_data = make_shared(load_object_file(nsa_filename)); if (!nsa_data->signature.eq(LegacySavedAccountDataBB::SIGNATURE)) { throw runtime_error("account data header is incorrect"); } if (!this->system_data) { - this->system_data.reset(new PSOBBBaseSystemFile(nsa_data->system_file.base)); + this->system_data = make_shared(nsa_data->system_file.base); player_data_log.info("Loaded legacy system data from %s", nsa_filename.c_str()); } if (!this->guild_card_data) { - this->guild_card_data.reset(new PSOBBGuildCardFile(nsa_data->guild_card_file)); + this->guild_card_data = make_shared(nsa_data->guild_card_file); player_data_log.info("Loaded legacy Guild Card data from %s", nsa_filename.c_str()); } } if (!this->system_data) { - this->system_data.reset(new PSOBBBaseSystemFile()); + this->system_data = make_shared(); player_data_log.info("Created new system data"); } if (!this->guild_card_data) { - this->guild_card_data.reset(new PSOBBGuildCardFile()); + this->guild_card_data = make_shared(); player_data_log.info("Created new Guild Card data"); } @@ -325,7 +325,7 @@ void ClientGameData::load_all_files() { throw runtime_error("legacy player data has incorrect signature"); } - this->character_data.reset(new PSOBBCharacterFile()); + this->character_data = make_shared(); this->character_data->inventory = nsc_data.inventory; this->character_data->disp = nsc_data.disp; this->character_data->play_time_seconds = nsc_data.disp.play_time; diff --git a/src/ProxyCommands.cc b/src/ProxyCommands.cc index edd699da..40ab22bb 100644 --- a/src/ProxyCommands.cc +++ b/src/ProxyCommands.cc @@ -229,15 +229,15 @@ static HandlerResult S_V123P_02_17( forward_command(ses, false, command, flag, data); if (uses_v3_encryption(ses->version())) { - ses->server_channel.crypt_in.reset(new PSOV3Encryption(cmd.server_key)); - ses->server_channel.crypt_out.reset(new PSOV3Encryption(cmd.client_key)); - ses->client_channel.crypt_in.reset(new PSOV3Encryption(cmd.client_key)); - ses->client_channel.crypt_out.reset(new PSOV3Encryption(cmd.server_key)); + ses->server_channel.crypt_in = make_shared(cmd.server_key); + ses->server_channel.crypt_out = make_shared(cmd.client_key); + ses->client_channel.crypt_in = make_shared(cmd.client_key); + ses->client_channel.crypt_out = make_shared(cmd.server_key); } else { // DC, PC, or patch server (they all use V2 encryption) - ses->server_channel.crypt_in.reset(new PSOV2Encryption(cmd.server_key)); - ses->server_channel.crypt_out.reset(new PSOV2Encryption(cmd.client_key)); - ses->client_channel.crypt_in.reset(new PSOV2Encryption(cmd.client_key)); - ses->client_channel.crypt_out.reset(new PSOV2Encryption(cmd.server_key)); + ses->server_channel.crypt_in = make_shared(cmd.server_key); + ses->server_channel.crypt_out = make_shared(cmd.client_key); + ses->client_channel.crypt_in = make_shared(cmd.client_key); + ses->client_channel.crypt_out = make_shared(cmd.server_key); } return HandlerResult::Type::SUPPRESS; @@ -247,11 +247,11 @@ static HandlerResult S_V123P_02_17( // This isn't forwarded to the client, so don't recreate the client's crypts if (uses_v3_encryption(ses->version())) { - ses->server_channel.crypt_in.reset(new PSOV3Encryption(cmd.server_key)); - ses->server_channel.crypt_out.reset(new PSOV3Encryption(cmd.client_key)); + ses->server_channel.crypt_in = make_shared(cmd.server_key); + ses->server_channel.crypt_out = make_shared(cmd.client_key); } else { - ses->server_channel.crypt_in.reset(new PSOV2Encryption(cmd.server_key)); - ses->server_channel.crypt_out.reset(new PSOV2Encryption(cmd.client_key)); + ses->server_channel.crypt_in = make_shared(cmd.server_key); + ses->server_channel.crypt_out = make_shared(cmd.client_key); } // Respond with an appropriate login command. We don't let the client do this @@ -466,10 +466,10 @@ static HandlerResult S_B_03(shared_ptr ses, uint16_t // being able to try all the crypts it knows to detect what type the client // uses, but the client can't do this since it sends the first encrypted // data on the connection. - ses->server_channel.crypt_in.reset(new PSOBBMultiKeyImitatorEncryption( - ses->detector_crypt, cmd.server_key.data(), sizeof(cmd.server_key), false)); - ses->server_channel.crypt_out.reset(new PSOBBMultiKeyImitatorEncryption( - ses->detector_crypt, cmd.client_key.data(), sizeof(cmd.client_key), false)); + ses->server_channel.crypt_in = make_shared( + ses->detector_crypt, cmd.server_key.data(), sizeof(cmd.server_key), false); + ses->server_channel.crypt_out = make_shared( + ses->detector_crypt, cmd.client_key.data(), sizeof(cmd.client_key), false); // Forward the login command we saved during the unlinked ses-> if (ses->enable_remote_ip_crc_patch && (ses->login_command_bb.size() >= 0x98)) { @@ -488,18 +488,18 @@ static HandlerResult S_B_03(shared_ptr ses, uint16_t // client receives the unencrypted data ses->client_channel.send(0x03, 0x00, data); - ses->detector_crypt.reset(new PSOBBMultiKeyDetectorEncryption( + ses->detector_crypt = make_shared( ses->require_server_state()->bb_private_keys, bb_crypt_initial_client_commands, cmd.client_key.data(), - sizeof(cmd.client_key))); + sizeof(cmd.client_key)); ses->client_channel.crypt_in = ses->detector_crypt; - ses->client_channel.crypt_out.reset(new PSOBBMultiKeyImitatorEncryption( - ses->detector_crypt, cmd.server_key.data(), sizeof(cmd.server_key), true)); - ses->server_channel.crypt_in.reset(new PSOBBMultiKeyImitatorEncryption( - ses->detector_crypt, cmd.server_key.data(), sizeof(cmd.server_key), false)); - ses->server_channel.crypt_out.reset(new PSOBBMultiKeyImitatorEncryption( - ses->detector_crypt, cmd.client_key.data(), sizeof(cmd.client_key), false)); + ses->client_channel.crypt_out = make_shared( + ses->detector_crypt, cmd.server_key.data(), sizeof(cmd.server_key), true); + ses->server_channel.crypt_in = make_shared( + ses->detector_crypt, cmd.server_key.data(), sizeof(cmd.server_key), false); + ses->server_channel.crypt_out = make_shared( + ses->detector_crypt, cmd.client_key.data(), sizeof(cmd.client_key), false); // We already forwarded the command, so don't do so again return HandlerResult::Type::SUPPRESS; diff --git a/src/ProxyServer.cc b/src/ProxyServer.cc index aa04d920..8bc42f08 100644 --- a/src/ProxyServer.cc +++ b/src/ProxyServer.cc @@ -44,8 +44,7 @@ ProxyServer::ProxyServer( next_unlicensed_session_id(0xFF00000000000001) {} void ProxyServer::listen(uint16_t port, Version version, const struct sockaddr_storage* default_destination) { - shared_ptr socket_obj(new ListeningSocket( - this, port, version, default_destination)); + auto socket_obj = make_shared(this, port, version, default_destination); auto l = this->listeners.emplace(port, socket_obj).first->second; } @@ -143,7 +142,7 @@ void ProxyServer::on_client_connect( this->next_unlicensed_session_id = 0xFF00000000000001; } - auto emplace_ret = this->id_to_session.emplace(session_id, new LinkedSession(this->shared_from_this(), session_id, listen_port, version, *default_destination)); + auto emplace_ret = this->id_to_session.emplace(session_id, make_shared(this->shared_from_this(), session_id, listen_port, version, *default_destination)); if (!emplace_ret.second) { throw logic_error("linked session already exists for unlicensed client"); } @@ -157,7 +156,7 @@ void ProxyServer::on_client_connect( // create an unlinked session - we'll have to get the destination from the // client's config, which we'll get via a 9E command soon. } else { - auto emplace_ret = this->bev_to_unlinked_session.emplace(bev, new UnlinkedSession(this->shared_from_this(), bev, listen_port, version)); + auto emplace_ret = this->bev_to_unlinked_session.emplace(bev, make_shared(this->shared_from_this(), bev, listen_port, version)); if (!emplace_ret.second) { throw logic_error("stale unlinked session exists"); } @@ -189,11 +188,11 @@ void ProxyServer::on_client_connect( auto cmd = prepare_server_init_contents_console(server_key, client_key, 0); ses->channel.send(0x02, 0x00, &cmd, sizeof(cmd)); if (uses_v2_encryption(version)) { - ses->channel.crypt_out.reset(new PSOV2Encryption(server_key)); - ses->channel.crypt_in.reset(new PSOV2Encryption(client_key)); + ses->channel.crypt_out = make_shared(server_key); + ses->channel.crypt_in = make_shared(client_key); } else { - ses->channel.crypt_out.reset(new PSOV3Encryption(server_key)); - ses->channel.crypt_in.reset(new PSOV3Encryption(client_key)); + ses->channel.crypt_out = make_shared(server_key); + ses->channel.crypt_in = make_shared(client_key); } break; } @@ -204,17 +203,17 @@ void ProxyServer::on_client_connect( random_data(client_key.data(), client_key.bytes()); auto cmd = prepare_server_init_contents_bb(server_key, client_key, 0); ses->channel.send(0x03, 0x00, &cmd, sizeof(cmd)); - ses->detector_crypt.reset(new PSOBBMultiKeyDetectorEncryption( + ses->detector_crypt = make_shared( this->state->bb_private_keys, bb_crypt_initial_client_commands, cmd.basic_cmd.client_key.data(), - sizeof(cmd.basic_cmd.client_key))); + sizeof(cmd.basic_cmd.client_key)); ses->channel.crypt_in = ses->detector_crypt; - ses->channel.crypt_out.reset(new PSOBBMultiKeyImitatorEncryption( + ses->channel.crypt_out = make_shared( ses->detector_crypt, cmd.basic_cmd.server_key.data(), sizeof(cmd.basic_cmd.server_key), - true)); + true); break; } default: @@ -381,7 +380,7 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3 if (!s->allow_unregistered_users) { throw; } - shared_ptr l(new License()); + auto l = make_shared(); l->serial_number = fnv1a32(cmd.username.decode()) & 0x7FFFFFFF; l->bb_username = cmd.username.decode(); l->bb_password = cmd.password.decode(); @@ -426,10 +425,10 @@ void ProxyServer::UnlinkedSession::on_input(Channel& ch, uint16_t command, uint3 // destination somewhere - either in the client config or in the unlinked // session if (ses->config.proxy_destination_address != 0) { - linked_ses.reset(new LinkedSession(server, ses->local_port, ses->version, ses->license, ses->config)); + linked_ses = make_shared(server, ses->local_port, ses->version, ses->license, ses->config); linked_ses->log.info("Opened licensed session for unlinked session based on client config"); } else if (ses->next_destination.ss_family == AF_INET) { - linked_ses.reset(new LinkedSession(server, ses->local_port, ses->version, ses->license, ses->next_destination)); + linked_ses = make_shared(server, ses->local_port, ses->version, ses->license, ses->next_destination); linked_ses->log.info("Opened licensed session for unlinked session based on unlinked default destination"); } else { ses->log.error("Cannot open linked session: no valid destination in client config or unlinked session"); @@ -876,7 +875,7 @@ shared_ptr ProxyServer::create_licensed_session( uint16_t local_port, Version version, const Client::Config& config) { - shared_ptr session(new LinkedSession(this->shared_from_this(), local_port, version, l, config)); + auto session = make_shared(this->shared_from_this(), local_port, version, l, config); auto emplace_ret = this->id_to_session.emplace(session->id, session); if (!emplace_ret.second) { throw runtime_error("session already exists for this license"); diff --git a/src/Quest.cc b/src/Quest.cc index 4d491a8b..56421dd1 100644 --- a/src/Quest.cc +++ b/src/Quest.cc @@ -32,7 +32,7 @@ QuestCategoryIndex::Category::Category(uint32_t category_id, const JSON& json) QuestCategoryIndex::QuestCategoryIndex(const JSON& json) { uint32_t next_category_id = 1; for (const auto& it : json.as_list()) { - this->categories.emplace_back(new Category(next_category_id++, *it)); + this->categories.emplace_back(make_shared(next_category_id++, *it)); } } @@ -471,7 +471,7 @@ QuestIndex::QuestIndex( if (categories.emplace(name, cat->category_id).first->second != cat->category_id) { throw runtime_error("file " + name + " exists in multiple categories"); } - shared_ptr data_ptr(new string(std::move(value))); + auto data_ptr = make_shared(std::move(value)); if (!files.emplace(name, data_ptr).second) { throw runtime_error("file " + name + " already exists"); } @@ -658,7 +658,7 @@ QuestIndex::QuestIndex( } if (!metadata_json.is_null()) { try { - battle_rules.reset(new BattleRules(metadata_json.at("BattleRules"))); + battle_rules = make_shared(metadata_json.at("BattleRules")); } catch (const out_of_range&) { } try { @@ -672,7 +672,7 @@ QuestIndex::QuestIndex( } } - shared_ptr vq(new VersionedQuest( + auto vq = make_shared( quest_number, category_id, version, @@ -683,7 +683,7 @@ QuestIndex::QuestIndex( battle_rules, challenge_template_index, require_flag, - require_team_reward_key)); + require_team_reward_key); auto category_name = this->category_index->at(vq->category_id)->name; string dat_str = dat_filename.empty() ? "" : (" with layout from " + dat_filename + ".dat"); @@ -702,7 +702,7 @@ QuestIndex::QuestIndex( battle_rules_str.c_str(), challenge_template_str.c_str()); } else { - shared_ptr q(new Quest(vq)); + auto q = make_shared(vq); this->quests_by_number.emplace(vq->quest_number, q); this->quests_by_category_id_and_number[q->category_id].emplace(vq->quest_number, q); static_game_data_log.info("(%s) Created %s %c quest %" PRIu32 " (%s) (%s, %s (%" PRIu32 "), %s)%s%s%s", @@ -873,11 +873,11 @@ shared_ptr VersionedQuest::create_download_quest(uint8_t overrid // Return a new VersionedQuest object with appropriately-processed .bin and // .dat file contents - shared_ptr dlq(new VersionedQuest(*this)); - dlq->bin_contents.reset(new string(encode_download_quest_data(compressed_bin, decompressed_bin.size()))); - dlq->dat_contents.reset(new string(encode_download_quest_data(*this->dat_contents))); + auto dlq = make_shared(*this); + dlq->bin_contents = make_shared(encode_download_quest_data(compressed_bin, decompressed_bin.size())); + dlq->dat_contents = make_shared(encode_download_quest_data(*this->dat_contents)); if (this->pvr_contents) { - dlq->pvr_contents.reset(new string(encode_download_quest_data(*this->pvr_contents))); + dlq->pvr_contents = make_shared(encode_download_quest_data(*this->pvr_contents)); } dlq->is_dlq_encoded = true; return dlq; diff --git a/src/QuestScript.cc b/src/QuestScript.cc index 724ed339..d5225203 100644 --- a/src/QuestScript.cc +++ b/src/QuestScript.cc @@ -975,7 +975,7 @@ std::string disassemble_quest_script(const void* data, size_t size, Version vers uint32_t function_id = function_table.size(); string name = string_printf("label%04" PRIX32, function_id); uint32_t offset = function_table_r.get_u32l(); - shared_ptr