use make_shared where appropriate

This commit is contained in:
Martin Michelsen
2023-11-30 10:24:27 -08:00
parent c833b575e4
commit 956e890ad6
33 changed files with 279 additions and 305 deletions
+1 -1
View File
@@ -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<DOLFile>(path.c_str()));
log.info("Loaded %s", name.c_str());
}
}
+6 -6
View File
@@ -78,13 +78,13 @@ void CatSession::on_channel_input(
if (command == 0x02 || command == 0x17 || command == 0x91 || command == 0x9B) {
const auto& cmd = check_size_t<S_ServerInitDefault_DC_PC_V3_02_17_91_9B>(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<PSOV3Encryption>(cmd.server_key);
this->channel.crypt_out = make_shared<PSOV3Encryption>(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<PSOV2Encryption>(cmd.server_key);
this->channel.crypt_out = make_shared<PSOV2Encryption>(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<S_ServerInitDefault_BB_03_9B>(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<PSOBBEncryption>(*this->bb_key_file, &cmd.server_key[0], sizeof(cmd.server_key));
this->channel.crypt_out = make_shared<PSOBBEncryption>(*this->bb_key_file, &cmd.client_key[0], sizeof(cmd.client_key));
this->log.info("Enabled BB encryption");
}
}
+2 -3
View File
@@ -702,9 +702,8 @@ static void server_command_playrec(shared_ptr<Client> c, const std::string& args
send_text_message(c, "$C4The recording does\nnot exist");
return;
}
shared_ptr<Episode3::BattleRecord> record(new Episode3::BattleRecord(data));
shared_ptr<Episode3::BattleRecordPlayer> battle_player(
new Episode3::BattleRecordPlayer(record, s->game_server->get_base()));
auto record = make_shared<Episode3::BattleRecord>(data);
auto battle_player = make_shared<Episode3::BattleRecordPlayer>(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) {
+4 -4
View File
@@ -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> table(new Table(pt_afs_data, r, false, false));
auto table = make_shared<Table>(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> table(new Table(ct_afs_data, r, false, false));
auto table = make_shared<Table>(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<const std::string> gsl_da
tolower(abbreviation_for_difficulty(difficulty)),
section_id);
auto r = gsl.get_reader(filename);
shared_ptr<Table> table(new Table(gsl_data, r, is_big_endian, true));
auto table = make_shared<Table>(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<const std::string> gsl_da
((episode == Episode::EP2) ? "l" : ""),
tolower(abbreviation_for_difficulty(difficulty)));
auto r = gsl.get_reader(filename);
shared_ptr<Table> table(new Table(gsl_data, r, is_big_endian, true));
auto table = make_shared<Table>(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);
}
+8 -8
View File
@@ -2261,7 +2261,7 @@ CardIndex::CardIndex(
continue;
}
shared_ptr<CardEntry> entry(new CardEntry({defs[x], "", "", "", {}}));
auto entry = make_shared<CardEntry>(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<const MapDefinition*>(decompressed.data())));
this->map = make_shared<MapDefinition>(*reinterpret_cast<const MapDefinition*>(decompressed.data()));
}
shared_ptr<const MapDefinitionTrial> MapIndex::VersionedMap::trial() const {
if (!this->trial_map) {
this->trial_map.reset(new MapDefinitionTrial(*this->map));
this->trial_map = make_shared<MapDefinitionTrial>(*this->map);
}
return this->trial_map;
}
@@ -2465,7 +2465,7 @@ MapIndex::MapIndex(const string& directory) {
string compressed_data;
shared_ptr<MapDefinition> decompressed_data;
if (ends_with(filename, ".mnmd") || ends_with(filename, ".bind")) {
decompressed_data.reset(new MapDefinition(load_object_file<MapDefinition>(directory + "/" + filename)));
decompressed_data = make_shared<MapDefinition>(load_object_file<MapDefinition>(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<VersionedMap> vm;
if (decompressed_data) {
vm.reset(new VersionedMap(decompressed_data, language));
vm = make_shared<VersionedMap>(decompressed_data, language);
} else if (!compressed_data.empty()) {
vm.reset(new VersionedMap(std::move(compressed_data), language));
vm = make_shared<VersionedMap>(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<Map>(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<COMDeckDefinition>());
def->index = this->decks.size() - 1;
def->player_name = def_json->at(0).as_string();
def->deck_name = def_json->at(1).as_string();
+9 -22
View File
@@ -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<DeckState>(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<CardShortStatus, 0x10>());
this->set_card_action_chains.reset(new parray<ActionChainWithConds, 9>());
this->set_card_action_metadatas.reset(new parray<ActionMetadata, 9>());
this->hand_and_equip = make_shared<HandAndEquipState>();
this->card_short_statuses = make_shared<parray<CardShortStatus, 0x10>>();
this->set_card_action_chains = make_shared<parray<ActionChainWithConds, 9>>();
this->set_card_action_metadatas = make_shared<parray<ActionMetadata, 9>>();
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<Card>(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<Card>(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();
+8 -8
View File
@@ -75,32 +75,32 @@ Server::~Server() noexcept(false) {
}
void Server::init() {
this->map_and_rules.reset(new MapAndRulesState());
this->map_and_rules = make_shared<MapAndRulesState>();
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<DeckEntry>();
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<CardSpecial>(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<PSOV2Encryption>(0);
this->state_flags.reset(new StateFlags());
this->state_flags = make_shared<StateFlags>();
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<AssistServer>(this->shared_from_this());
this->ruler_server = make_shared<RulerServer>(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<PlayerState>(z, this->shared_from_this());
this->player_states[z]->init();
}
}
+4 -6
View File
@@ -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<Team>(
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<size_t>(json.size(), 0x20); z++) {
if (!json.at(z).is_null()) {
shared_ptr<Tournament> tourn(new Tournament(this->map_index, this->com_deck_index, json.at(z)));
auto tourn = make_shared<Tournament>(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<Tournament> tourn(new Tournament(this->map_index, this->com_deck_index, *it.second));
auto tourn = make_shared<Tournament>(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
+2 -2
View File
@@ -14,7 +14,7 @@ FileContentsCache::File::File(
string&& data,
uint64_t load_time)
: name(name),
data(new string(std::move(data))),
data(make_shared<string>(std::move(data))),
load_time(load_time) {}
shared_ptr<const FileContentsCache::File> FileContentsCache::replace(
@@ -22,7 +22,7 @@ shared_ptr<const FileContentsCache::File> FileContentsCache::replace(
if (t == 0) {
t = now();
}
shared_ptr<File> new_file(new File(name, std::move(data), t));
auto new_file = make_shared<File>(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;
+4 -4
View File
@@ -127,7 +127,7 @@ shared_ptr<CompiledFunctionCode> compile_function_code(
throw runtime_error("function compiler is not available");
#else
shared_ptr<CompiledFunctionCode> ret(new CompiledFunctionCode());
auto ret = make_shared<CompiledFunctionCode>();
ret->arch = arch;
ret->name = name;
ret->index = 0;
@@ -236,7 +236,7 @@ FunctionCodeIndex::FunctionCodeIndex(const string& directory) {
shared_ptr<const Menu> FunctionCodeIndex::patch_menu(uint32_t specific_version) const {
auto suffix = string_printf("-%08" PRIX32, specific_version);
shared_ptr<Menu> ret(new Menu(MenuID::PATCHES, "Patches"));
auto ret = make_shared<Menu>(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> menu(new Menu(MenuID::PROGRAMS, "Programs"));
auto menu = make_shared<Menu>(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<File> dol(new File());
auto dol = make_shared<File>();
dol->menu_item_id = next_menu_item_id++;
dol->name = name;
+1 -1
View File
@@ -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<IPClient> c(new IPClient(this->shared_from_this(), bev));
auto c = make_shared<IPClient>(this->shared_from_this(), bev);
this->bev_to_client.emplace(make_pair(bev, c));
bufferevent_setcb(bev, &IPStackSimulator::dispatch_on_client_input, nullptr,
+1 -1
View File
@@ -33,7 +33,7 @@ void PlayerStats::advance_to_level(uint8_t char_class, uint32_t level, shared_pt
LevelTable::LevelTable(shared_ptr<const string> data, bool compressed) {
if (compressed) {
this->data.reset(new string(prs_decompress(*data)));
this->data = make_shared<string>(prs_decompress(*data));
} else {
this->data = data;
}
+1 -1
View File
@@ -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> license(new License(json));
auto license = make_shared<License>(json);
this->add(license);
}
}
+2 -2
View File
@@ -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<ItemCreator>(
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() {
+30 -31
View File
@@ -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<PSOV2Encryption>(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<PSOV3Encryption>(stoul(seed, nullptr, 16));
break;
case Version::BB_V4: {
string key_name = args.get<string>("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<PSOBBEncryption::KeyFile>("system/blueburst/keys/" + key_name + ".nsk");
crypt.reset(new PSOBBEncryption(key, seed.data(), seed.size()));
crypt = make_shared<PSOBBEncryption>(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<string> bin_data(new string(load_file(bin_filename)));
shared_ptr<string> dat_data(new string(load_file(dat_filename)));
auto bin_data = make_shared<string>(load_file(bin_filename));
auto dat_data = make_shared<string>(load_file(dat_filename));
shared_ptr<string> pvr_data;
try {
pvr_data.reset(new string(load_file(pvr_filename)));
pvr_data = make_shared<string>(load_file(pvr_filename));
} catch (const cannot_open_file&) {
}
shared_ptr<VersionedQuest> vq(new VersionedQuest(0, 0, version, 0, bin_data, dat_data, pvr_data));
auto vq = make_shared<VersionedQuest>(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<string> data_shared(new string(std::move(data)));
auto data_shared = make_shared<string>(std::move(data));
if (args.get<string>(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<PSOBBEncryption::KeyFile>("system/blueburst/keys/" + key_file_name + ".nsk")));
key = make_shared<PSOBBEncryption::KeyFile>(
load_object_file<PSOBBEncryption::KeyFile>("system/blueburst/keys/" + key_file_name + ".nsk"));
}
shared_ptr<struct event_base> base(event_base_new(), event_base_free);
auto cat_client_remote = make_sockaddr_storage(parse_netloc(args.get<string>(1))).first;
@@ -1246,18 +1246,18 @@ Action a_convert_rare_item_set(
}
auto version = get_cli_version(args);
shared_ptr<string> data(new string(read_input_data(args)));
auto data = make_shared<string>(read_input_data(args));
shared_ptr<RareItemSet> rs;
if (ends_with(input_filename, ".json")) {
rs.reset(new RareItemSet(JSON::parse(*data), version, name_index));
rs = make_shared<RareItemSet>(JSON::parse(*data), version, name_index);
} else if (ends_with(input_filename, ".gsl")) {
rs.reset(new RareItemSet(GSLArchive(data, false), false));
rs = make_shared<RareItemSet>(GSLArchive(data, false), false);
} else if (ends_with(input_filename, ".gslb")) {
rs.reset(new RareItemSet(GSLArchive(data, true), true));
rs = make_shared<RareItemSet>(GSLArchive(data, true), true);
} else if (ends_with(input_filename, ".afs")) {
rs.reset(new RareItemSet(AFSArchive(data), is_v1(version)));
rs = make_shared<RareItemSet>(AFSArchive(data), is_v1(version));
} else if (ends_with(input_filename, ".rel")) {
rs.reset(new RareItemSet(*data, true));
rs = make_shared<RareItemSet>(*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<string> pmt_data_v2(new string(prs_decompress(load_file("system/item-tables/ItemPMT-v2.prs"))));
auto pmt_data_v2 = make_shared<string>(prs_decompress(load_file("system/item-tables/ItemPMT-v2.prs")));
auto pmt_v2 = make_shared<ItemParameterTable>(pmt_data_v2, ItemParameterTable::Version::V2);
shared_ptr<string> pmt_data_v3(new string(prs_decompress(load_file("system/item-tables/ItemPMT-gc.prs"))));
auto pmt_data_v3 = make_shared<string>(prs_decompress(load_file("system/item-tables/ItemPMT-gc.prs")));
auto pmt_v3 = make_shared<ItemParameterTable>(pmt_data_v3, ItemParameterTable::Version::V3);
shared_ptr<string> pmt_data_v4(new string(prs_decompress(load_file("system/item-tables/ItemPMT-bb.prs"))));
auto pmt_data_v4 = make_shared<string>(prs_decompress(load_file("system/item-tables/ItemPMT-bb.prs")));
auto pmt_v4 = make_shared<ItemParameterTable>(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<TextArchive> text_english;
try {
JSON json = JSON::parse(load_file("system/ep3/text-english.json"));
text_english.reset(new TextArchive(json));
text_english = make_unique<TextArchive>(json);
} catch (const exception& e) {
}
@@ -1426,7 +1426,7 @@ Action a_generate_ep3_cards_html(
unique_ptr<TextArchive> text_english;
try {
JSON json = JSON::parse(load_file("system/ep3/text-english.json"));
text_english.reset(new TextArchive(json));
text_english = make_unique<TextArchive>(json);
} catch (const exception& e) {
}
@@ -1698,14 +1698,13 @@ Action a_run_server_replay_log(
}
shared_ptr<struct event_base> base(event_base_new(), event_base_free);
shared_ptr<ServerState> state(new ServerState(config_filename, is_replay));
auto state = make_shared<ServerState>(config_filename, is_replay);
state->init();
shared_ptr<DNSServer> 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<DNSServer>(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<IPStackSimulator> 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<ProxyServer>(base, state);
config_log.info("Starting game server");
state->game_server.reset(new Server(base, state));
state->game_server = make_shared<Server>(base, state);
auto nop_destructor = +[](FILE*) {};
shared_ptr<FILE> 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<bool>("require-basic-credentials")));
replay_session = make_shared<ReplaySession>(base, log_f.get(), state, args.get<bool>("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<ProxyServer>(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<Server>(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<IPStackSimulator>(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<ServerShell>(base, state);
}
config_log.info("Ready");
+7 -10
View File
@@ -718,11 +718,11 @@ void PSOV2OrV3DetectorEncryption::encrypt(void* data, size_t size, bool advance)
le_uint32_t encrypted = *reinterpret_cast<le_uint32_t*>(data);
le_uint32_t decrypted_v2 = encrypted;
unique_ptr<PSOEncryption> v2_crypt(new PSOV2Encryption(this->key));
auto v2_crypt = make_unique<PSOV2Encryption>(this->key);
v2_crypt->decrypt(&decrypted_v2, sizeof(decrypted_v2), false);
le_uint32_t decrypted_v3 = encrypted;
unique_ptr<PSOEncryption> v3_crypt(new PSOV3Encryption(this->key));
auto v3_crypt = make_unique<PSOV3Encryption>(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<PSOV2Encryption>(this->key);
} else if (t == Type::V3) {
this->active_crypt.reset(new PSOV3Encryption(this->key));
this->active_crypt = make_shared<PSOV3Encryption>(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<PSOBBEncryption>(*this->active_key, this->seed.data(), this->seed.size());
string test_data(reinterpret_cast<const char*>(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<PSOBBEncryption> 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<PSOBBEncryption>(*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<PSOBBEncryption>(*key, this->seed.data(), this->seed.size());
}
}
return this->active_crypt;
+2 -2
View File
@@ -38,7 +38,7 @@ shared_ptr<PSOGCObjectGraph::VTable> PSOGCObjectGraph::parse_vtable_memo(
}
const auto& vt = r.pget<TObjectVTable>(addr & 0x01FFFFFF);
auto ret = this->all_vtables.emplace(addr, new VTable()).first->second;
auto ret = this->all_vtables.emplace(addr, make_shared<VTable>()).first->second;
ret->address = addr;
ret->destroy_addr = vt.destroy;
ret->update_addr = vt.update;
@@ -57,7 +57,7 @@ shared_ptr<PSOGCObjectGraph::Object> PSOGCObjectGraph::parse_object_memo(
const auto& obj = r.pget<TObject>(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<Object>()).first->second;
ret->address = addr;
ret->flags = obj.flags;
ret->type_name = std::move(type_name);
+2 -2
View File
@@ -23,7 +23,7 @@ std::shared_ptr<const std::string> 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<string>(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<File> f(new File(this));
auto f = make_shared<File>(this);
f->path_directories = path_directories;
f->name = item;
+15 -15
View File
@@ -36,7 +36,7 @@ ClientGameData::~ClientGameData() {
}
void ClientGameData::create_battle_overlay(shared_ptr<const BattleRules> rules, shared_ptr<const LevelTable> level_table) {
this->overlay_character_data.reset(new PSOBBCharacterFile(*this->character(true, false)));
this->overlay_character_data = make_shared<PSOBBCharacterFile>(*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<PSOBBCharacterFile>(*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<PSOBBBaseSystemFile>();
this->character_data = make_shared<PSOBBCharacterFile>();
this->guild_card_data = make_shared<PSOBBGuildCardFile>();
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<PSOBBBaseSystemFile>(sys_filename, true)));
this->system_data = make_shared<PSOBBBaseSystemFile>(load_object_file<PSOBBBaseSystemFile>(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<PSOBBCharacterFile>(f.get())));
this->character_data = make_shared<PSOBBCharacterFile>(freadx<PSOBBCharacterFile>(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<PSOBBBaseSystemFile>(f.get())));
this->system_data = make_shared<PSOBBBaseSystemFile>(freadx<PSOBBBaseSystemFile>(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<PSOBBGuildCardFile>(card_filename)));
this->guild_card_data = make_shared<PSOBBGuildCardFile>(load_object_file<PSOBBGuildCardFile>(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<LegacySavedAccountDataBB> nsa_data;
if (isfile(nsa_filename)) {
nsa_data.reset(new LegacySavedAccountDataBB(load_object_file<LegacySavedAccountDataBB>(nsa_filename)));
nsa_data = make_shared<LegacySavedAccountDataBB>(load_object_file<LegacySavedAccountDataBB>(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<PSOBBBaseSystemFile>(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<PSOBBGuildCardFile>(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<PSOBBBaseSystemFile>();
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<PSOBBGuildCardFile>();
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<PSOBBCharacterFile>();
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;
+24 -24
View File
@@ -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<PSOV3Encryption>(cmd.server_key);
ses->server_channel.crypt_out = make_shared<PSOV3Encryption>(cmd.client_key);
ses->client_channel.crypt_in = make_shared<PSOV3Encryption>(cmd.client_key);
ses->client_channel.crypt_out = make_shared<PSOV3Encryption>(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<PSOV2Encryption>(cmd.server_key);
ses->server_channel.crypt_out = make_shared<PSOV2Encryption>(cmd.client_key);
ses->client_channel.crypt_in = make_shared<PSOV2Encryption>(cmd.client_key);
ses->client_channel.crypt_out = make_shared<PSOV2Encryption>(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<PSOV3Encryption>(cmd.server_key);
ses->server_channel.crypt_out = make_shared<PSOV3Encryption>(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<PSOV2Encryption>(cmd.server_key);
ses->server_channel.crypt_out = make_shared<PSOV2Encryption>(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<ProxyServer::LinkedSession> 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<PSOBBMultiKeyImitatorEncryption>(
ses->detector_crypt, cmd.server_key.data(), sizeof(cmd.server_key), false);
ses->server_channel.crypt_out = make_shared<PSOBBMultiKeyImitatorEncryption>(
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<ProxyServer::LinkedSession> 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<PSOBBMultiKeyDetectorEncryption>(
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<PSOBBMultiKeyImitatorEncryption>(
ses->detector_crypt, cmd.server_key.data(), sizeof(cmd.server_key), true);
ses->server_channel.crypt_in = make_shared<PSOBBMultiKeyImitatorEncryption>(
ses->detector_crypt, cmd.server_key.data(), sizeof(cmd.server_key), false);
ses->server_channel.crypt_out = make_shared<PSOBBMultiKeyImitatorEncryption>(
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;
+15 -16
View File
@@ -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<ListeningSocket> socket_obj(new ListeningSocket(
this, port, version, default_destination));
auto socket_obj = make_shared<ListeningSocket>(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<LinkedSession>(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<UnlinkedSession>(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<PSOV2Encryption>(server_key);
ses->channel.crypt_in = make_shared<PSOV2Encryption>(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<PSOV3Encryption>(server_key);
ses->channel.crypt_in = make_shared<PSOV3Encryption>(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<PSOBBMultiKeyDetectorEncryption>(
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<PSOBBMultiKeyImitatorEncryption>(
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<License> l(new License());
auto l = make_shared<License>();
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<LinkedSession>(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<LinkedSession>(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::LinkedSession> ProxyServer::create_licensed_session(
uint16_t local_port,
Version version,
const Client::Config& config) {
shared_ptr<LinkedSession> session(new LinkedSession(this->shared_from_this(), local_port, version, l, config));
auto session = make_shared<LinkedSession>(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");
+10 -10
View File
@@ -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<Category>(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<const string> data_ptr(new string(std::move(value)));
auto data_ptr = make_shared<string>(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<BattleRules>(metadata_json.at("BattleRules"));
} catch (const out_of_range&) {
}
try {
@@ -672,7 +672,7 @@ QuestIndex::QuestIndex(
}
}
shared_ptr<VersionedQuest> vq(new VersionedQuest(
auto vq = make_shared<VersionedQuest>(
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<Quest> q(new Quest(vq));
auto q = make_shared<Quest>(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> VersionedQuest::create_download_quest(uint8_t overrid
// Return a new VersionedQuest object with appropriately-processed .bin and
// .dat file contents
shared_ptr<VersionedQuest> 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<VersionedQuest>(*this);
dlq->bin_contents = make_shared<string>(encode_download_quest_data(compressed_bin, decompressed_bin.size()));
dlq->dat_contents = make_shared<string>(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<string>(encode_download_quest_data(*this->pvr_contents));
}
dlq->is_dlq_encoded = true;
return dlq;
+1 -1
View File
@@ -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<Label> l(new Label(name, offset, function_id));
auto l = make_shared<Label>(name, offset, function_id);
if (function_id == 0) {
l->add_data_type(Arg::DataType::SCRIPT);
}
+26 -26
View File
@@ -35,7 +35,7 @@ void on_login_complete(shared_ptr<Client> c);
static shared_ptr<const Menu> proxy_options_menu_for_client(shared_ptr<const Client> c) {
auto s = c->require_server_state();
shared_ptr<Menu> ret(new Menu(MenuID::PROXY_OPTIONS, "Proxy options"));
auto ret = make_shared<Menu>(MenuID::PROXY_OPTIONS, "Proxy options");
ret->items.emplace_back(ProxyOptionsMenuItemID::GO_BACK, "Go back", "Return to the\nProxy Server menu", 0);
auto add_bool_option = [&](uint32_t item_id, bool is_enabled, const char* text, const char* description) -> void {
@@ -188,7 +188,7 @@ void on_connect(std::shared_ptr<Client> c) {
static void send_main_menu(shared_ptr<Client> c) {
auto s = c->require_server_state();
shared_ptr<Menu> main_menu(new Menu(MenuID::MAIN, s->name));
auto main_menu = make_shared<Menu>(MenuID::MAIN, s->name);
main_menu->items.emplace_back(
MainMenuItemID::GO_TO_LOBBY, "Go to lobby",
[s, wc = weak_ptr<Client>(c)]() -> string {
@@ -411,7 +411,7 @@ static void on_DB_V3(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
c->should_disconnect = true;
return;
} else {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
l->serial_number = serial_number;
l->access_key = cmd.access_key.decode();
l->gc_password = cmd.password.decode();
@@ -455,7 +455,7 @@ static void on_88_DCNTE(shared_ptr<Client> c, uint16_t, uint32_t, string& data)
send_message_box(c, "Incorrect serial number");
c->should_disconnect = true;
} else {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
l->serial_number = serial_number;
l->access_key = cmd.access_key.decode();
s->license_index->add(l);
@@ -498,7 +498,7 @@ static void on_8B_DCNTE(shared_ptr<Client> c, uint16_t, uint32_t, string& data)
send_message_box(c, "Incorrect serial number");
c->should_disconnect = true;
} else {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
l->serial_number = serial_number;
l->access_key = cmd.access_key.decode();
s->license_index->add(l);
@@ -552,7 +552,7 @@ static void on_90_DC(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
send_command(c, 0x90, 0x03);
c->should_disconnect = true;
} else {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
l->serial_number = serial_number;
l->access_key = cmd.access_key.decode();
s->license_index->add(l);
@@ -609,7 +609,7 @@ static void on_93_DC(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
c->should_disconnect = true;
return;
} else {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
l->serial_number = serial_number;
l->access_key = cmd.access_key.decode();
s->license_index->add(l);
@@ -698,7 +698,7 @@ static void on_9A(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
c->should_disconnect = true;
return;
} else if (is_v1_or_v2(c->version())) {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
l->serial_number = serial_number;
l->access_key = cmd.access_key.decode();
s->license_index->add(l);
@@ -758,7 +758,7 @@ static void on_9C(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
c->should_disconnect = true;
return;
} else {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
l->serial_number = serial_number;
l->access_key = cmd.access_key.decode();
if (is_gc(c->version())) {
@@ -877,7 +877,7 @@ static void on_9D_9E(shared_ptr<Client> c, uint16_t command, uint32_t, string& d
c->should_disconnect = true;
return;
} else if (is_v1_or_v2(c->version())) {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
l->serial_number = serial_number;
l->access_key = base_cmd->access_key.decode();
s->license_index->add(l);
@@ -907,7 +907,7 @@ static void on_9E_XB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
}
}
c->xb_netloc.reset(new XBNetworkLocation(cmd.netloc));
c->xb_netloc = make_shared<XBNetworkLocation>(cmd.netloc);
c->xb_9E_unknown_a1a = cmd.unknown_a1a;
c->channel.language = cmd.language;
@@ -946,7 +946,7 @@ static void on_9E_XB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
return;
} catch (const LicenseIndex::missing_license& e) {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
l->serial_number = fnv1a32(xb_gamertag) & 0x7FFFFFFF;
l->xb_gamertag = xb_gamertag;
l->xb_user_id = xb_user_id;
@@ -1003,7 +1003,7 @@ static void on_93_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
c->should_disconnect = true;
return;
} else {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
l->serial_number = fnv1a32(cmd.username.decode()) & 0x7FFFFFFF;
l->bb_username = cmd.username.decode();
l->bb_password = cmd.password.decode();
@@ -1518,7 +1518,7 @@ static void on_CA_Ep3(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
}
}
}
l->battle_record.reset(new Episode3::BattleRecord(s->ep3_behavior_flags));
l->battle_record = make_shared<Episode3::BattleRecord>(s->ep3_behavior_flags);
for (auto existing_c : l->clients) {
if (existing_c) {
auto existing_p = existing_c->game_data.character();
@@ -2705,7 +2705,7 @@ static void on_AC_V3_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data)
send_command(c, 0xAC, 0x00);
c->log.info("Creating game join command queue");
c->game_join_command_queue.reset(new deque<Client::JoinCommand>());
c->game_join_command_queue = make_unique<deque<Client::JoinCommand>>();
send_command(c, 0x1D, 0x00);
} else if (c->config.check_flag(Client::Flag::LOADING_QUEST)) {
@@ -2792,14 +2792,14 @@ static void on_61_98(shared_ptr<Client> c, uint16_t command, uint32_t flag, stri
case Version::DC_V1_11_2000_PROTOTYPE:
case Version::DC_V1: {
const auto& cmd = check_size_t<C_CharacterData_DCv1_61_98>(data);
c->game_data.last_reported_disp_v1_v2.reset(new PlayerDispDataDCPCV3(cmd.disp));
c->game_data.last_reported_disp_v1_v2 = make_unique<PlayerDispDataDCPCV3>(cmd.disp);
player->inventory = cmd.inventory;
player->disp = cmd.disp.to_bb(player->inventory.language, player->inventory.language);
break;
}
case Version::DC_V2: {
const auto& cmd = check_size_t<C_CharacterData_DCv2_61_98>(data, 0xFFFF);
c->game_data.last_reported_disp_v1_v2.reset(new PlayerDispDataDCPCV3(cmd.disp));
c->game_data.last_reported_disp_v1_v2 = make_unique<PlayerDispDataDCPCV3>(cmd.disp);
player->inventory = cmd.inventory;
player->disp = cmd.disp.to_bb(player->inventory.language, player->inventory.language);
player->battle_records = cmd.records.battle;
@@ -2809,7 +2809,7 @@ static void on_61_98(shared_ptr<Client> c, uint16_t command, uint32_t flag, stri
}
case Version::PC_V2: {
const auto& cmd = check_size_t<C_CharacterData_PC_61_98>(data, 0xFFFF);
c->game_data.last_reported_disp_v1_v2.reset(new PlayerDispDataDCPCV3(cmd.disp));
c->game_data.last_reported_disp_v1_v2 = make_unique<PlayerDispDataDCPCV3>(cmd.disp);
player->inventory = cmd.inventory;
player->disp = cmd.disp.to_bb(player->inventory.language, player->inventory.language);
player->battle_records = cmd.records.battle;
@@ -2841,7 +2841,7 @@ static void on_61_98(shared_ptr<Client> c, uint16_t command, uint32_t flag, stri
throw runtime_error("non-Episode 3 client sent Episode 3 player data");
}
const auto* cmd3 = &check_size_t<C_CharacterData_GC_Ep3_61_98>(data);
c->game_data.ep3_config.reset(new Episode3::PlayerConfig(cmd3->ep3_config));
c->game_data.ep3_config = make_shared<Episode3::PlayerConfig>(cmd3->ep3_config);
cmd = reinterpret_cast<const C_CharacterData_V3_61_98*>(cmd3);
if (c->config.specific_version == 0x33000000) {
c->config.specific_version = 0x33534A30; // 3SJ0
@@ -2859,7 +2859,7 @@ static void on_61_98(shared_ptr<Client> c, uint16_t command, uint32_t flag, stri
}
if (c->version() == Version::GC_NTE) {
c->game_data.last_reported_disp_v1_v2.reset(new PlayerDispDataDCPCV3(cmd->disp));
c->game_data.last_reported_disp_v1_v2 = make_unique<PlayerDispDataDCPCV3>(cmd->disp);
}
auto s = c->require_server_state();
@@ -3867,13 +3867,13 @@ shared_ptr<Lobby> create_game_generic(
game->episode = episode;
game->mode = mode;
if (game->mode == GameMode::CHALLENGE) {
game->challenge_params.reset(new Lobby::ChallengeParameters());
game->challenge_params = make_shared<Lobby::ChallengeParameters>();
}
game->difficulty = difficulty;
if (c->config.check_flag(Client::Flag::USE_OVERRIDE_RANDOM_SEED)) {
game->random_seed = c->config.override_random_seed;
}
game->random_crypt.reset(new PSOV2Encryption(game->random_seed));
game->random_crypt = make_shared<PSOV2Encryption>(game->random_seed);
if (battle_player) {
game->battle_player = battle_player;
battle_player->set_lobby(game);
@@ -3913,7 +3913,7 @@ shared_ptr<Lobby> create_game_generic(
}
if (game->base_version == Version::BB_V4) {
game->map.reset(new Map());
game->map = make_shared<Map>();
for (size_t floor = 0; floor < 0x10; floor++) {
c->log.info("[Map/%zu] Using variations %" PRIX32 ", %" PRIX32,
floor, game->variations[floor * 2].load(), game->variations[floor * 2 + 1].load());
@@ -4271,7 +4271,7 @@ static void on_D0_V3_BB(shared_ptr<Client> c, uint16_t, uint32_t, string& data)
throw runtime_error("trade command sent to missing player");
}
c->game_data.pending_item_trade.reset(new PendingItemTrade());
c->game_data.pending_item_trade = make_unique<PendingItemTrade>();
c->game_data.pending_item_trade->other_client_id = cmd.target_client_id;
for (size_t x = 0; x < cmd.item_count; x++) {
auto& item = c->game_data.pending_item_trade->items.emplace_back(cmd.item_datas[x]);
@@ -4412,7 +4412,7 @@ static void on_EE_Ep3(shared_ptr<Client> c, uint16_t, uint32_t flag, string& dat
throw runtime_error("card trade target is not Episode 3");
}
c->game_data.pending_card_trade.reset(new PendingCardTrade());
c->game_data.pending_card_trade = make_unique<PendingCardTrade>();
c->game_data.pending_card_trade->other_client_id = cmd.target_client_id;
for (size_t x = 0; x < cmd.entry_count; x++) {
c->game_data.pending_card_trade->card_to_count.emplace_back(
@@ -4824,7 +4824,7 @@ static void on_04_P(shared_ptr<Client> c, uint16_t, uint32_t, string& data) {
return;
} else {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
l->serial_number = fnv1a32(cmd.username.decode()) & 0x7FFFFFFF;
l->bb_username = cmd.username.decode();
l->bb_password = cmd.password.decode();
+1 -1
View File
@@ -2421,7 +2421,7 @@ static void on_battle_restart_bb(shared_ptr<Client> c, uint8_t, uint8_t, const v
auto vq = l->quest->version(Version::BB_V4, c->language());
auto dat_contents = prs_decompress(*vq->dat_contents);
shared_ptr<BattleRules> new_rules(new BattleRules(cmd.rules));
auto new_rules = make_shared<BattleRules>(cmd.rules);
if (l->item_creator) {
l->item_creator->set_restrictions(new_rules);
l->item_creator->clear_destroyed_entities();
+13 -13
View File
@@ -58,7 +58,7 @@ string ReplaySession::Client::str() const {
shared_ptr<ReplaySession::Event> ReplaySession::create_event(
Event::Type type, shared_ptr<Client> c, size_t line_num) {
shared_ptr<Event> event(new Event(type, c->id, line_num));
auto event = make_shared<Event>(type, c->id, line_num);
if (!this->last_event.get()) {
this->first_event = event;
} else {
@@ -495,11 +495,11 @@ ReplaySession::ReplaySession(
throw runtime_error(string_printf("(ev-line %zu) client connection message listening socket token format is incorrect", line_num));
}
shared_ptr<Client> c(new Client(
auto c = make_shared<Client>(
this,
stoull(tokens[8].substr(2), nullptr, 16),
stoul(listen_tokens[1], nullptr, 10),
enum_for_name<Version>(listen_tokens[2].c_str())));
enum_for_name<Version>(listen_tokens[2].c_str()));
if (!this->clients.emplace(c->id, c).second) {
throw runtime_error(string_printf("(ev-line %zu) duplicate client ID in input log", line_num));
}
@@ -723,8 +723,8 @@ void ReplaySession::on_command_received(
case Version::BB_PATCH:
if (command == 0x02) {
auto& cmd = check_size_t<S_ServerInit_Patch_02>(data);
c->channel.crypt_in.reset(new PSOV2Encryption(cmd.server_key));
c->channel.crypt_out.reset(new PSOV2Encryption(cmd.client_key));
c->channel.crypt_in = make_shared<PSOV2Encryption>(cmd.server_key);
c->channel.crypt_out = make_shared<PSOV2Encryption>(cmd.client_key);
}
break;
case Version::DC_NTE:
@@ -740,11 +740,11 @@ void ReplaySession::on_command_received(
if (command == 0x02 || command == 0x17 || command == 0x91 || command == 0x9B) {
auto& cmd = check_size_t<S_ServerInitDefault_DC_PC_V3_02_17_91_9B>(data, 0xFFFF);
if (is_v1_or_v2(c->version)) {
c->channel.crypt_in.reset(new PSOV2Encryption(cmd.server_key));
c->channel.crypt_out.reset(new PSOV2Encryption(cmd.client_key));
c->channel.crypt_in = make_shared<PSOV2Encryption>(cmd.server_key);
c->channel.crypt_out = make_shared<PSOV2Encryption>(cmd.client_key);
} else { // V3
c->channel.crypt_in.reset(new PSOV3Encryption(cmd.server_key));
c->channel.crypt_out.reset(new PSOV3Encryption(cmd.client_key));
c->channel.crypt_in = make_shared<PSOV3Encryption>(cmd.server_key);
c->channel.crypt_out = make_shared<PSOV3Encryption>(cmd.client_key);
}
}
break;
@@ -753,10 +753,10 @@ void ReplaySession::on_command_received(
auto& cmd = check_size_t<S_ServerInitDefault_BB_03_9B>(data, 0xFFFF);
// TODO: At some point it may matter which BB private key file we use.
// Don't just blindly use the first one here.
c->channel.crypt_in.reset(new PSOBBEncryption(
*this->state->bb_private_keys[0], cmd.server_key.data(), cmd.server_key.size()));
c->channel.crypt_out.reset(new PSOBBEncryption(
*this->state->bb_private_keys[0], cmd.client_key.data(), cmd.client_key.size()));
c->channel.crypt_in = make_shared<PSOBBEncryption>(
*this->state->bb_private_keys[0], cmd.server_key.data(), cmd.server_key.size());
c->channel.crypt_out = make_shared<PSOBBEncryption>(
*this->state->bb_private_keys[0], cmd.client_key.data(), cmd.client_key.size());
}
break;
default:
+1 -1
View File
@@ -333,7 +333,7 @@ shared_ptr<PSOBBCharacterFile> PSOBBCharacterFile::create_from_preview(
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
shared_ptr<PSOBBCharacterFile> ret(new PSOBBCharacterFile());
auto ret = make_shared<PSOBBCharacterFile>();
const auto& initial_items = initial_inventory.at(preview.visual.char_class);
ret->inventory.num_items = initial_items.size();
+14 -14
View File
@@ -165,8 +165,8 @@ void send_server_init_dc_pc_v3(shared_ptr<Client> c, uint8_t flags) {
switch (c->version()) {
case Version::PC_V2:
c->channel.crypt_in.reset(new PSOV2Encryption(client_key));
c->channel.crypt_out.reset(new PSOV2Encryption(server_key));
c->channel.crypt_in = make_shared<PSOV2Encryption>(client_key);
c->channel.crypt_out = make_shared<PSOV2Encryption>(server_key);
break;
case Version::DC_NTE:
case Version::DC_V1_11_2000_PROTOTYPE:
@@ -176,15 +176,15 @@ void send_server_init_dc_pc_v3(shared_ptr<Client> c, uint8_t flags) {
case Version::GC_V3:
case Version::GC_EP3_TRIAL_EDITION:
case Version::GC_EP3: {
shared_ptr<PSOV2OrV3DetectorEncryption> det_crypt(new PSOV2OrV3DetectorEncryption(
client_key, v2_crypt_initial_client_commands, v3_crypt_initial_client_commands));
auto det_crypt = make_shared<PSOV2OrV3DetectorEncryption>(
client_key, v2_crypt_initial_client_commands, v3_crypt_initial_client_commands);
c->channel.crypt_in = det_crypt;
c->channel.crypt_out.reset(new PSOV2OrV3ImitatorEncryption(server_key, det_crypt));
c->channel.crypt_out = make_shared<PSOV2OrV3ImitatorEncryption>(server_key, det_crypt);
break;
}
case Version::XB_V3:
c->channel.crypt_in.reset(new PSOV3Encryption(client_key));
c->channel.crypt_out.reset(new PSOV3Encryption(server_key));
c->channel.crypt_in = make_shared<PSOV3Encryption>(client_key);
c->channel.crypt_out = make_shared<PSOV3Encryption>(server_key);
break;
default:
throw invalid_argument("incorrect client version");
@@ -216,15 +216,15 @@ void send_server_init_bb(shared_ptr<Client> c, uint8_t flags) {
static const string primary_expected_first_data("\xB4\x00\x93\x00\x00\x00\x00\x00", 8);
static const string secondary_expected_first_data("\xDC\x00\xDB\x00\x00\x00\x00\x00", 8);
shared_ptr<PSOBBMultiKeyDetectorEncryption> detector_crypt(new PSOBBMultiKeyDetectorEncryption(
auto detector_crypt = make_shared<PSOBBMultiKeyDetectorEncryption>(
c->require_server_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));
c->channel.crypt_in = detector_crypt;
c->channel.crypt_out.reset(new PSOBBMultiKeyImitatorEncryption(
c->channel.crypt_out = make_shared<PSOBBMultiKeyImitatorEncryption>(
detector_crypt, cmd.basic_cmd.server_key.data(),
sizeof(cmd.basic_cmd.server_key), true));
sizeof(cmd.basic_cmd.server_key), true);
}
void send_server_init_patch(shared_ptr<Client> c) {
@@ -237,8 +237,8 @@ void send_server_init_patch(shared_ptr<Client> c) {
cmd.client_key = client_key;
send_command_t(c, 0x02, 0x00, cmd);
c->channel.crypt_out.reset(new PSOV2Encryption(server_key));
c->channel.crypt_in.reset(new PSOV2Encryption(client_key));
c->channel.crypt_out = make_shared<PSOV2Encryption>(server_key);
c->channel.crypt_in = make_shared<PSOV2Encryption>(client_key);
}
void send_server_init(shared_ptr<Client> c, uint8_t flags) {
@@ -1824,7 +1824,7 @@ void send_join_game(shared_ptr<Client> c, shared_ptr<Lobby> l) {
}
c->log.info("Creating game join command queue");
c->game_join_command_queue.reset(new deque<Client::JoinCommand>());
c->game_join_command_queue = make_unique<deque<Client::JoinCommand>>();
send_command(c, 0x1D, 0x00);
}
+2 -3
View File
@@ -110,8 +110,7 @@ void Server::on_listen_accept(
struct bufferevent* bev = bufferevent_socket_new(this->base.get(), fd,
BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
shared_ptr<Client> c(new Client(
this->shared_from_this(), bev, listening_socket->version, listening_socket->behavior));
auto c = make_shared<Client>(this->shared_from_this(), bev, listening_socket->version, listening_socket->behavior);
c->channel.on_command_received = Server::on_client_input;
c->channel.on_error = Server::on_client_error;
c->channel.context_obj = this;
@@ -131,7 +130,7 @@ void Server::on_listen_accept(
void Server::connect_client(
struct bufferevent* bev, uint32_t address, uint16_t client_port,
uint16_t server_port, Version version, ServerBehavior initial_state) {
shared_ptr<Client> c(new Client(this->shared_from_this(), bev, version, initial_state));
auto c = make_shared<Client>(this->shared_from_this(), bev, version, initial_state);
c->channel.on_command_received = Server::on_client_input;
c->channel.on_error = Server::on_client_error;
c->channel.context_obj = this;
+2 -2
View File
@@ -321,7 +321,7 @@ Proxy session commands:\n\
}
} else if (command_name == "add-license") {
shared_ptr<License> l(new License());
auto l = make_shared<License>();
for (const string& token : split(command_args, ' ')) {
if (starts_with(token, "bb-username=")) {
@@ -376,7 +376,7 @@ Proxy session commands:\n\
uint32_t serial_number = stoul(tokens[0]);
tokens.erase(tokens.begin());
auto orig_l = this->state->license_index->get(serial_number);
shared_ptr<License> l(new License(*orig_l));
auto l = make_shared<License>(*orig_l);
this->state->license_index->remove(orig_l->serial_number);
try {
+56 -60
View File
@@ -253,7 +253,7 @@ shared_ptr<Lobby> ServerState::create_lobby() {
while (this->id_to_lobby.count(this->next_lobby_id)) {
this->next_lobby_id++;
}
shared_ptr<Lobby> l(new Lobby(this->shared_from_this(), this->next_lobby_id++));
auto l = make_shared<Lobby>(this->shared_from_this(), this->next_lobby_id++);
this->id_to_lobby.emplace(l->lobby_id, l);
l->log.info("Created lobby");
return l;
@@ -420,7 +420,7 @@ void ServerState::set_port_configuration(
bool any_port_is_pc_console_detect = false;
for (const auto& pc : port_configs) {
shared_ptr<PortConfiguration> spc(new PortConfiguration(pc));
auto spc = make_shared<PortConfiguration>(pc);
if (!this->name_to_port_config.emplace(spc->name, spc).second) {
// Note: This is a logic_error instead of a runtime_error because
// port_configs comes from a JSON map, so the names should already all be
@@ -470,7 +470,7 @@ shared_ptr<const string> ServerState::load_bb_file(
try {
// TODO: It's kinda not great that we copy the data here; find a way to
// avoid doing this (also in the below case)
shared_ptr<string> ret(new string(this->bb_data_gsl->get_copy(effective_gsl_filename)));
auto ret = make_shared<string>(this->bb_data_gsl->get_copy(effective_gsl_filename));
static_game_data_log.info("Loaded %s from data.gsl in BB patch tree", effective_gsl_filename.c_str());
return ret;
} catch (const out_of_range&) {
@@ -482,7 +482,7 @@ shared_ptr<const string> ServerState::load_bb_file(
if (dot_offset != string::npos) {
string no_ext_gsl_filename = effective_gsl_filename.substr(0, dot_offset);
try {
shared_ptr<string> ret(new string(this->bb_data_gsl->get_copy(no_ext_gsl_filename)));
auto ret = make_shared<string>(this->bb_data_gsl->get_copy(no_ext_gsl_filename));
static_game_data_log.info("Loaded %s from data.gsl in BB patch tree", no_ext_gsl_filename.c_str());
return ret;
} catch (const out_of_range&) {
@@ -700,7 +700,7 @@ void ServerState::parse_config(const JSON& json, bool is_reload) {
{
auto parse_ep3_ex_result_cmd = [&](const JSON& src) -> shared_ptr<G_SetEXResultValues_GC_Ep3_6xB4x4B> {
shared_ptr<G_SetEXResultValues_GC_Ep3_6xB4x4B> ret(new G_SetEXResultValues_GC_Ep3_6xB4x4B());
auto ret = make_shared<G_SetEXResultValues_GC_Ep3_6xB4x4B>();
const auto& win_json = src.at("Win");
for (size_t z = 0; z < min<size_t>(win_json.size(), 10); z++) {
ret->win_entries[z].threshold = win_json.at(z).at(0).as_int();
@@ -790,7 +790,7 @@ void ServerState::parse_config(const JSON& json, bool is_reload) {
if (!is_reload) {
try {
this->quest_category_index.reset(new QuestCategoryIndex(json.at("QuestCategories")));
this->quest_category_index = make_shared<QuestCategoryIndex>(json.at("QuestCategories"));
} catch (const exception& e) {
throw runtime_error(string_printf(
"QuestCategories is missing or invalid in config.json (%s) - see config.example.json for an example", e.what()));
@@ -799,10 +799,10 @@ void ServerState::parse_config(const JSON& json, bool is_reload) {
config_log.info("Creating menus");
shared_ptr<Menu> information_menu_v2(new Menu(MenuID::INFORMATION, "Information"));
shared_ptr<Menu> information_menu_v3(new Menu(MenuID::INFORMATION, "Information"));
shared_ptr<vector<string>> information_contents_v2(new vector<string>());
shared_ptr<vector<string>> information_contents_v3(new vector<string>());
auto information_menu_v2 = make_shared<Menu>(MenuID::INFORMATION, "Information");
auto information_menu_v3 = make_shared<Menu>(MenuID::INFORMATION, "Information");
shared_ptr<vector<string>> information_contents_v2 = make_shared<vector<string>>();
shared_ptr<vector<string>> information_contents_v3 = make_shared<vector<string>>();
information_menu_v2->items.emplace_back(InformationMenuItemID::GO_BACK, "Go back",
"Return to the\nmain menu", MenuItem::Flag::INVISIBLE_IN_INFO_MENU);
@@ -838,7 +838,7 @@ void ServerState::parse_config(const JSON& json, bool is_reload) {
this->information_contents_v3 = information_contents_v3;
auto generate_proxy_destinations_menu = [&](vector<pair<string, uint16_t>>& ret_pds, const char* key) -> shared_ptr<const Menu> {
shared_ptr<Menu> ret(new Menu(MenuID::PROXY_DESTINATIONS, "Proxy server"));
auto ret = make_shared<Menu>(MenuID::PROXY_DESTINATIONS, "Proxy server");
ret_pds.clear();
try {
@@ -910,7 +910,7 @@ void ServerState::load_bb_private_keys() {
if (!ends_with(filename, ".nsk")) {
continue;
}
this->bb_private_keys.emplace_back(new PSOBBEncryption::KeyFile(
this->bb_private_keys.emplace_back(make_shared<PSOBBEncryption::KeyFile>(
load_object_file<PSOBBEncryption::KeyFile>("system/blueburst/keys/" + filename)));
config_log.info("Loaded Blue Burst key file: %s", filename.c_str());
}
@@ -919,28 +919,28 @@ void ServerState::load_bb_private_keys() {
void ServerState::load_licenses() {
config_log.info("Indexing licenses");
this->license_index.reset(new LicenseIndex());
this->license_index = make_shared<LicenseIndex>();
}
void ServerState::load_teams() {
config_log.info("Indexing teams");
this->team_index.reset(new TeamIndex("system/teams", this->team_reward_defs_json));
this->team_index = make_shared<TeamIndex>("system/teams", this->team_reward_defs_json);
this->team_reward_defs_json = nullptr;
}
void ServerState::load_patch_indexes() {
if (isdir("system/patch-pc")) {
config_log.info("Indexing PSO PC patch files");
this->pc_patch_file_index.reset(new PatchFileIndex("system/patch-pc"));
this->pc_patch_file_index = make_shared<PatchFileIndex>("system/patch-pc");
} else {
config_log.info("PSO PC patch files not present");
}
if (isdir("system/patch-bb")) {
config_log.info("Indexing PSO BB patch files");
this->bb_patch_file_index.reset(new PatchFileIndex("system/patch-bb"));
this->bb_patch_file_index = make_shared<PatchFileIndex>("system/patch-bb");
try {
auto gsl_file = this->bb_patch_file_index->get("./data/data.gsl");
this->bb_data_gsl.reset(new GSLArchive(gsl_file->load_data(), false));
this->bb_data_gsl = make_shared<GSLArchive>(gsl_file->load_data(), false);
config_log.info("data.gsl found in BB patch files");
} catch (const out_of_range&) {
config_log.info("data.gsl is not present in BB patch files");
@@ -952,31 +952,31 @@ void ServerState::load_patch_indexes() {
void ServerState::load_battle_params() {
config_log.info("Loading battle parameters");
this->battle_params.reset(new BattleParamsIndex(
this->battle_params = make_shared<BattleParamsIndex>(
this->load_bb_file("BattleParamEntry_on.dat"),
this->load_bb_file("BattleParamEntry_lab_on.dat"),
this->load_bb_file("BattleParamEntry_ep4_on.dat"),
this->load_bb_file("BattleParamEntry.dat"),
this->load_bb_file("BattleParamEntry_lab.dat"),
this->load_bb_file("BattleParamEntry_ep4.dat")));
this->load_bb_file("BattleParamEntry_ep4.dat"));
}
void ServerState::load_level_table() {
config_log.info("Loading level table");
this->level_table.reset(new LevelTable(this->load_bb_file("PlyLevelTbl.prs"), true));
this->level_table = make_shared<LevelTable>(this->load_bb_file("PlyLevelTbl.prs"), true);
}
void ServerState::load_word_select_table() {
config_log.info("Loading Word Select table");
this->word_select_table.reset(new WordSelectTable(JSON::parse(load_file("system/word-select-table.json"))));
this->word_select_table = make_shared<WordSelectTable>(JSON::parse(load_file("system/word-select-table.json")));
}
void ServerState::load_item_tables() {
config_log.info("Loading item name index");
this->item_name_index.reset(new ItemNameIndex(
this->item_name_index = make_shared<ItemNameIndex>(
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"))));
JSON::parse(load_file("system/item-tables/names-v4.json")));
config_log.info("Loading rare item sets");
unordered_map<string, shared_ptr<const RareItemSet>> new_rare_item_sets;
@@ -1030,25 +1030,23 @@ void ServerState::load_item_tables() {
this->rare_item_sets.swap(new_rare_item_sets);
config_log.info("Loading v2 common item table");
shared_ptr<string> ct_data_v2(new string(load_file("system/item-tables/ItemCT-v2.afs")));
shared_ptr<string> pt_data_v2(new string(load_file("system/item-tables/ItemPT-v2.afs")));
this->common_item_set_v2.reset(new AFSV2CommonItemSet(pt_data_v2, ct_data_v2));
auto ct_data_v2 = make_shared<string>(load_file("system/item-tables/ItemCT-v2.afs"));
auto pt_data_v2 = make_shared<string>(load_file("system/item-tables/ItemPT-v2.afs"));
this->common_item_set_v2 = make_shared<AFSV2CommonItemSet>(pt_data_v2, ct_data_v2);
config_log.info("Loading v3 common item table");
shared_ptr<string> pt_data_v3(new string(load_file("system/item-tables/ItemPT-gc.gsl")));
this->common_item_set_v3.reset(new GSLV3CommonItemSet(pt_data_v3, true));
auto pt_data_v3 = make_shared<string>(load_file("system/item-tables/ItemPT-gc.gsl"));
this->common_item_set_v3 = make_shared<GSLV3CommonItemSet>(pt_data_v3, true);
// Note: The ItemPT files don't exist in BB, so we use the GC versions of them
// instead. This doesn't include Episode 4 of course, so we use Episode 1
// parameters for Episode 4 implicitly.
config_log.info("Loading armor table");
shared_ptr<string> armor_data(new string(load_file(
"system/item-tables/ArmorRandom-gc.rel")));
this->armor_random_set.reset(new ArmorRandomSet(armor_data));
auto armor_data = make_shared<string>(load_file("system/item-tables/ArmorRandom-gc.rel"));
this->armor_random_set = make_shared<ArmorRandomSet>(armor_data);
config_log.info("Loading tool table");
shared_ptr<string> tool_data(new string(load_file(
"system/item-tables/ToolRandom-gc.rel")));
this->tool_random_set.reset(new ToolRandomSet(tool_data));
auto tool_data = make_shared<string>(load_file("system/item-tables/ToolRandom-gc.rel"));
this->tool_random_set = make_shared<ToolRandomSet>(tool_data);
config_log.info("Loading weapon tables");
const char* filenames[4] = {
@@ -1058,54 +1056,52 @@ void ServerState::load_item_tables() {
"system/item-tables/WeaponRandomUltimate-gc.rel",
};
for (size_t z = 0; z < 4; z++) {
shared_ptr<string> weapon_data(new string(load_file(filenames[z])));
this->weapon_random_sets[z].reset(new WeaponRandomSet(weapon_data));
auto weapon_data = make_shared<string>(load_file(filenames[z]));
this->weapon_random_sets[z] = make_shared<WeaponRandomSet>(weapon_data);
}
config_log.info("Loading tekker adjustment table");
shared_ptr<string> tekker_data(new string(load_file(
"system/item-tables/JudgeItem-gc.rel")));
this->tekker_adjustment_set.reset(new TekkerAdjustmentSet(tekker_data));
auto tekker_data = make_shared<string>(load_file("system/item-tables/JudgeItem-gc.rel"));
this->tekker_adjustment_set = make_shared<TekkerAdjustmentSet>(tekker_data);
config_log.info("Loading item definition tables");
shared_ptr<string> pmt_data_v2(new string(prs_decompress(load_file("system/item-tables/ItemPMT-v2.prs"))));
this->item_parameter_table_v2.reset(new ItemParameterTable(pmt_data_v2, ItemParameterTable::Version::V2));
shared_ptr<string> pmt_data_v3(new string(prs_decompress(load_file("system/item-tables/ItemPMT-gc.prs"))));
this->item_parameter_table_v3.reset(new ItemParameterTable(pmt_data_v3, ItemParameterTable::Version::V3));
shared_ptr<string> pmt_data_v4(new string(prs_decompress(load_file("system/item-tables/ItemPMT-bb.prs"))));
this->item_parameter_table_v4.reset(new ItemParameterTable(pmt_data_v4, ItemParameterTable::Version::V4));
auto pmt_data_v2 = make_shared<string>(prs_decompress(load_file("system/item-tables/ItemPMT-v2.prs")));
this->item_parameter_table_v2 = make_shared<ItemParameterTable>(pmt_data_v2, ItemParameterTable::Version::V2);
auto pmt_data_v3 = make_shared<string>(prs_decompress(load_file("system/item-tables/ItemPMT-gc.prs")));
this->item_parameter_table_v3 = make_shared<ItemParameterTable>(pmt_data_v3, ItemParameterTable::Version::V3);
auto pmt_data_v4 = make_shared<string>(prs_decompress(load_file("system/item-tables/ItemPMT-bb.prs")));
this->item_parameter_table_v4 = make_shared<ItemParameterTable>(pmt_data_v4, ItemParameterTable::Version::V4);
config_log.info("Loading mag evolution table");
shared_ptr<string> mag_data(new string(prs_decompress(load_file(
"system/item-tables/ItemMagEdit-bb.prs"))));
this->mag_evolution_table.reset(new MagEvolutionTable(mag_data));
auto mag_data = make_shared<string>(prs_decompress(load_file("system/item-tables/ItemMagEdit-bb.prs")));
this->mag_evolution_table = make_shared<MagEvolutionTable>(mag_data);
}
void ServerState::load_ep3_data() {
config_log.info("Collecting Episode 3 maps");
this->ep3_map_index.reset(new Episode3::MapIndex("system/ep3/maps"));
this->ep3_map_index = make_shared<Episode3::MapIndex>("system/ep3/maps");
config_log.info("Loading Episode 3 card definitions");
this->ep3_card_index.reset(new Episode3::CardIndex(
this->ep3_card_index = make_shared<Episode3::CardIndex>(
"system/ep3/card-definitions.mnr",
"system/ep3/card-definitions.mnrd",
"system/ep3/card-text.mnr",
"system/ep3/card-text.mnrd",
"system/ep3/card-dice-text.mnr",
"system/ep3/card-dice-text.mnrd"));
"system/ep3/card-dice-text.mnrd");
config_log.info("Loading Episode 3 trial card definitions");
this->ep3_card_index_trial.reset(new Episode3::CardIndex(
this->ep3_card_index_trial = make_shared<Episode3::CardIndex>(
"system/ep3/card-definitions-trial.mnr",
"system/ep3/card-definitions-trial.mnrd",
"system/ep3/card-text-trial.mnr",
"system/ep3/card-text-trial.mnrd",
"system/ep3/card-dice-text-trial.mnr",
"system/ep3/card-dice-text-trial.mnrd"));
"system/ep3/card-dice-text-trial.mnrd");
config_log.info("Loading Episode 3 COM decks");
this->ep3_com_deck_index.reset(new Episode3::COMDeckIndex("system/ep3/com-decks.json"));
this->ep3_com_deck_index = make_shared<Episode3::COMDeckIndex>("system/ep3/com-decks.json");
const string& tournament_state_filename = "system/ep3/tournament-state.json";
this->ep3_tournament_index.reset(new Episode3::TournamentIndex(
this->ep3_map_index, this->ep3_com_deck_index, tournament_state_filename));
this->ep3_tournament_index = make_shared<Episode3::TournamentIndex>(
this->ep3_map_index, this->ep3_com_deck_index, tournament_state_filename);
this->ep3_tournament_index->link_all_clients(this->shared_from_this());
config_log.info("Loaded Episode 3 tournament state");
}
@@ -1143,19 +1139,19 @@ void ServerState::resolve_ep3_card_names() {
void ServerState::load_quest_index() {
config_log.info("Collecting quests");
this->default_quest_index.reset(new QuestIndex("system/quests", this->quest_category_index, false));
this->default_quest_index = make_shared<QuestIndex>("system/quests", this->quest_category_index, false);
config_log.info("Collecting Episode 3 download quests");
this->ep3_download_quest_index.reset(new QuestIndex("system/ep3/maps-download", this->quest_category_index, true));
this->ep3_download_quest_index = make_shared<QuestIndex>("system/ep3/maps-download", this->quest_category_index, true);
}
void ServerState::compile_functions() {
config_log.info("Compiling client functions");
this->function_code_index.reset(new FunctionCodeIndex("system/ppc"));
this->function_code_index = make_shared<FunctionCodeIndex>("system/ppc");
}
void ServerState::load_dol_files() {
config_log.info("Loading DOL files");
this->dol_file_index.reset(new DOLFileIndex("system/dol"));
this->dol_file_index = make_shared<DOLFileIndex>("system/dol");
}
shared_ptr<const vector<string>> ServerState::information_contents_for_client(shared_ptr<const Client> c) const {
+2 -2
View File
@@ -241,7 +241,7 @@ TeamIndex::TeamIndex(const string& directory, const JSON& reward_defs_json)
if (ends_with(filename, ".json")) {
try {
uint32_t team_id = stoul(filename.substr(0, filename.size() - 5), nullptr, 16);
shared_ptr<Team> team(new Team(team_id));
auto team = make_shared<Team>(team_id);
team->load_config();
try {
team->load_flag();
@@ -294,7 +294,7 @@ vector<shared_ptr<const TeamIndex::Team>> TeamIndex::all() const {
}
shared_ptr<const TeamIndex::Team> TeamIndex::create(string& name, uint32_t master_serial_number, const string& master_name) {
shared_ptr<Team> team(new Team(this->next_team_id++));
auto team = make_shared<Team>(this->next_team_id++);
save_file(this->directory + "/base.json", JSON::dict({{"NextTeamID", this->next_team_id}}).serialize());
Team::Member m;
+3 -3
View File
@@ -29,7 +29,7 @@ TextArchive::TextArchive(const JSON& json) {
}
for (const auto& keyboard_json : json.at("keyboards").as_list()) {
auto& keyboard = this->keyboards.emplace_back(new Keyboard());
auto& keyboard = this->keyboards.emplace_back(make_unique<Keyboard>());
for (size_t y = 0; y < keyboard->size(); y++) {
auto& row = keyboard->at(y);
const auto& row_json = keyboard_json->at(y);
@@ -116,7 +116,7 @@ void TextArchive::set_keyboard(size_t kb_index, const Keyboard& kb) {
if (kb_index >= this->keyboards.size()) {
this->keyboards.resize(kb_index + 1);
}
this->keyboards[kb_index].reset(new Keyboard(kb));
this->keyboards[kb_index] = make_unique<Keyboard>(kb);
}
void TextArchive::resize_keyboards(size_t num_keyboards) {
@@ -171,7 +171,7 @@ void TextArchive::load_t(const string& pr2_data) {
while (this->keyboards.size() < num_keyboards) {
uint32_t keyboard_offset = r.pget<U32T>(keyboards_offset + 4 * this->keyboards.size());
used_offsets.emplace(keyboard_offset);
auto& kb = this->keyboards.emplace_back(new Keyboard());
auto& kb = this->keyboards.emplace_back(make_unique<Keyboard>());
auto key_r = r.sub(keyboard_offset, sizeof(Keyboard));
for (size_t y = 0; y < kb->size(); y++) {
auto& row = kb->at(y);