eliminate using namespace
This commit is contained in:
+147
-153
@@ -23,13 +23,11 @@
|
||||
#include "StaticGameData.hh"
|
||||
#include "Text.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Tools
|
||||
|
||||
string str_for_flag_ranges(const vector<bool>& flags) {
|
||||
string ret;
|
||||
std::string str_for_flag_ranges(const std::vector<bool>& flags) {
|
||||
std::string ret;
|
||||
auto add_result = [&](size_t start, size_t end) {
|
||||
if (!ret.empty()) {
|
||||
ret.push_back(',');
|
||||
@@ -174,19 +172,19 @@ struct ChatCommandDefinition {
|
||||
std::vector<const char*> names;
|
||||
Handler handler;
|
||||
|
||||
static unordered_map<string, const ChatCommandDefinition*> all_defs;
|
||||
static std::unordered_map<std::string, const ChatCommandDefinition*> all_defs;
|
||||
|
||||
ChatCommandDefinition(std::initializer_list<const char*> names, Handler handler)
|
||||
: names(names), handler(handler) {
|
||||
for (const char* name : this->names) {
|
||||
if (!this->all_defs.emplace(name, this).second) {
|
||||
throw logic_error("duplicate command definition: " + string(name));
|
||||
throw std::logic_error("duplicate command definition: " + std::string(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
unordered_map<string, const ChatCommandDefinition*> ChatCommandDefinition::all_defs;
|
||||
std::unordered_map<std::string, const ChatCommandDefinition*> ChatCommandDefinition::all_defs;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// All commands (in alphabetical order)
|
||||
@@ -332,7 +330,7 @@ ChatCommandDefinition cc_auction(
|
||||
co_return;
|
||||
});
|
||||
|
||||
static string name_for_client(shared_ptr<Client> c) {
|
||||
static std::string name_for_client(std::shared_ptr<Client> c) {
|
||||
auto player = c->character_file(false);
|
||||
if (player.get()) {
|
||||
return escape_player_name(player->disp.name.decode(player->inventory.language));
|
||||
@@ -355,11 +353,11 @@ ChatCommandDefinition cc_ban(
|
||||
auto l = a.c->require_lobby();
|
||||
|
||||
size_t space_pos = a.text.find(' ');
|
||||
if (space_pos == string::npos) {
|
||||
if (space_pos == std::string::npos) {
|
||||
throw precondition_failed("$C6Incorrect arguments");
|
||||
}
|
||||
|
||||
string identifier = a.text.substr(space_pos + 1);
|
||||
std::string identifier = a.text.substr(space_pos + 1);
|
||||
auto target = s->find_client(&identifier);
|
||||
if (!target->login) {
|
||||
// This should be impossible, but I'll bet it's not actually
|
||||
@@ -372,7 +370,7 @@ ChatCommandDefinition cc_ban(
|
||||
if (a.c == target) {
|
||||
// This shouldn't be possible because you need BAN_USER to get here, but the target can't have BAN_USER if we
|
||||
// get here, so if a.c and target are the same, one of the preceding conditions must be false.
|
||||
throw logic_error("client attempts to ban themself");
|
||||
throw std::logic_error("client attempts to ban themself");
|
||||
}
|
||||
|
||||
uint64_t usecs = stoull(a.text, nullptr, 0) * 1000000;
|
||||
@@ -397,9 +395,8 @@ ChatCommandDefinition cc_ban(
|
||||
target->login->account->ban_end_time = phosg::now() + usecs;
|
||||
target->login->account->save();
|
||||
send_message_box(target, "$C6You have been banned.");
|
||||
string target_name = name_for_client(target);
|
||||
send_text_message_fmt(a.c, "$C6{} banned", name_for_client(target));
|
||||
target->channel->disconnect();
|
||||
send_text_message_fmt(a.c, "$C6{} banned", target_name);
|
||||
co_return;
|
||||
});
|
||||
|
||||
@@ -409,10 +406,10 @@ ChatCommandDefinition cc_bank(
|
||||
a.check_is_proxy(false);
|
||||
a.check_version(Version::BB_V4);
|
||||
if (a.c->check_flag(Client::Flag::AT_BANK_COUNTER)) {
|
||||
throw runtime_error("cannot change banks while at the bank counter");
|
||||
throw std::runtime_error("cannot change banks while at the bank counter");
|
||||
}
|
||||
if (a.c->has_overlay()) {
|
||||
throw runtime_error("cannot change banks while Battle or Challenge is in progress");
|
||||
throw std::runtime_error("cannot change banks while Battle or Challenge is in progress");
|
||||
}
|
||||
|
||||
ssize_t new_char_index = a.text.empty() ? (a.c->bb_character_index + 1) : stol(a.text, nullptr, 0);
|
||||
@@ -450,17 +447,17 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
||||
throw precondition_failed("$C6Episode 3 players\ncannot be converted\nto BB format");
|
||||
}
|
||||
|
||||
shared_ptr<Account> dest_account;
|
||||
shared_ptr<BBLicense> dest_bb_license;
|
||||
std::shared_ptr<Account> dest_account;
|
||||
std::shared_ptr<BBLicense> dest_bb_license;
|
||||
size_t dest_character_index = 0;
|
||||
if (is_bb_conversion) {
|
||||
vector<string> tokens = phosg::split(a.text, ' ');
|
||||
std::vector<std::string> tokens = phosg::split(a.text, ' ');
|
||||
if (tokens.size() != 3) {
|
||||
throw precondition_failed("$C6Incorrect argument\ncount");
|
||||
}
|
||||
|
||||
// username/password are tokens[0] and [1]
|
||||
dest_character_index = stoull(tokens[2]) - 1;
|
||||
dest_character_index = std::stoull(tokens[2]) - 1;
|
||||
if (dest_character_index >= 127) {
|
||||
throw precondition_failed("$C6Player index must\nbe in range 1-127");
|
||||
}
|
||||
@@ -469,7 +466,7 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
||||
auto dest_login = s->account_index->from_bb_credentials(tokens[0], &tokens[1], false);
|
||||
dest_account = dest_login->account;
|
||||
dest_bb_license = dest_login->bb_license;
|
||||
} catch (const exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
throw precondition_failed("$C6Login failed: {}", e.what());
|
||||
}
|
||||
|
||||
@@ -490,7 +487,7 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
||||
ch = co_await send_get_player_info(a.c, true);
|
||||
}
|
||||
|
||||
string filename = dest_bb_license
|
||||
std::string filename = dest_bb_license
|
||||
? Client::character_filename(dest_bb_license->username, dest_character_index)
|
||||
: Client::backup_character_filename(dest_account->account_id, dest_character_index, is_ep3(a.c->version()));
|
||||
|
||||
@@ -500,7 +497,7 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
||||
try {
|
||||
Client::save_ep3_character_file(filename, *ch.ep3_character);
|
||||
send_text_message(a.c, "$C7Character data saved\n(full save file)");
|
||||
} catch (const exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what());
|
||||
}
|
||||
}
|
||||
@@ -508,7 +505,7 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
||||
try {
|
||||
Client::save_character_file(filename, a.c->system_file(), ch.character);
|
||||
send_text_message(a.c, "$C7Character data saved\n(full save file)");
|
||||
} catch (const exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what());
|
||||
}
|
||||
}
|
||||
@@ -553,7 +550,7 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
||||
try {
|
||||
Client::save_character_file(filename, a.c->system_file(), bb_player);
|
||||
send_text_message(a.c, "$C7Character data saved\n(basic only)");
|
||||
} catch (const exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what());
|
||||
}
|
||||
}
|
||||
@@ -608,16 +605,16 @@ ChatCommandDefinition cc_checkchar(
|
||||
if (a.text.empty()) {
|
||||
bool is_ep3 = ::is_ep3(a.c->version());
|
||||
|
||||
vector<bool> flags;
|
||||
std::vector<bool> flags;
|
||||
flags.emplace_back(false);
|
||||
for (size_t z = 0; z < s->num_backup_character_slots; z++) {
|
||||
string filename = a.c->backup_character_filename(a.c->login->account->account_id, z, is_ep3);
|
||||
std::string filename = a.c->backup_character_filename(a.c->login->account->account_id, z, is_ep3);
|
||||
flags.emplace_back(std::filesystem::is_regular_file(filename));
|
||||
}
|
||||
string used_str = str_for_flag_ranges(flags);
|
||||
std::string used_str = str_for_flag_ranges(flags);
|
||||
flags.flip();
|
||||
flags[0] = false;
|
||||
string free_str = str_for_flag_ranges(flags);
|
||||
std::string free_str = str_for_flag_ranges(flags);
|
||||
send_text_message_fmt(a.c, "Used: {}\nFree: {}", used_str, free_str);
|
||||
|
||||
} else {
|
||||
@@ -628,7 +625,7 @@ ChatCommandDefinition cc_checkchar(
|
||||
|
||||
try {
|
||||
if (is_ep3(a.c->version())) {
|
||||
string filename = a.c->backup_character_filename(a.c->login->account->account_id, index, true);
|
||||
std::string filename = a.c->backup_character_filename(a.c->login->account->account_id, index, true);
|
||||
auto ch = phosg::load_object_file<PSOGCEp3CharacterFile::Character>(filename);
|
||||
send_text_message_fmt(a.c, "Slot {}: $C6{}$C7\n{} {}\nCLv: on {}.{}, off {}.{}",
|
||||
index + 1, ch.disp.visual.name.decode(),
|
||||
@@ -636,7 +633,7 @@ ChatCommandDefinition cc_checkchar(
|
||||
(ch.ep3_config.online_clv_exp / 100) + 1, ch.ep3_config.online_clv_exp % 100,
|
||||
(ch.ep3_config.offline_clv_exp / 100) + 1, ch.ep3_config.offline_clv_exp % 100);
|
||||
} else {
|
||||
string filename = a.c->backup_character_filename(a.c->login->account->account_id, index, false);
|
||||
std::string filename = a.c->backup_character_filename(a.c->login->account->account_id, index, false);
|
||||
auto ch = PSOCHARFile::load_shared(filename, false).character_file;
|
||||
send_text_message_fmt(a.c, "Slot {}: $C6{}$C7\n{} {}\nLevel {}",
|
||||
index + 1, ch->disp.name.decode(),
|
||||
@@ -673,7 +670,7 @@ ChatCommandDefinition cc_deletechar(
|
||||
throw precondition_failed("$C6Player index must\nbe in range 1-16");
|
||||
}
|
||||
|
||||
string filename = a.c->backup_character_filename(a.c->login->account->account_id, index, is_ep3(a.c->version()));
|
||||
std::string filename = a.c->backup_character_filename(a.c->login->account->account_id, index, is_ep3(a.c->version()));
|
||||
if (std::filesystem::is_regular_file(filename)) {
|
||||
std::filesystem::remove(filename);
|
||||
send_text_message_fmt(a.c, "Character in slot\n{} deleted", index + 1);
|
||||
@@ -694,7 +691,7 @@ ChatCommandDefinition cc_dicerange(
|
||||
|
||||
auto l = a.c->require_lobby();
|
||||
if (l->episode != Episode::EP3) {
|
||||
throw logic_error("non-Ep3 client in Ep3 game");
|
||||
throw std::logic_error("non-Ep3 client in Ep3 game");
|
||||
}
|
||||
if (!l->ep3_server) {
|
||||
throw precondition_failed("$C6Episode 3 server\nis not initialized");
|
||||
@@ -706,7 +703,7 @@ ChatCommandDefinition cc_dicerange(
|
||||
throw precondition_failed("$C6Cannot override\ndice ranges in a\ntournament");
|
||||
}
|
||||
|
||||
auto parse_dice_range = +[](const string& spec) -> uint8_t {
|
||||
auto parse_dice_range = +[](const std::string& spec) -> uint8_t {
|
||||
auto tokens = phosg::split(spec, '-');
|
||||
if (tokens.size() == 1) {
|
||||
uint8_t v = stoull(spec);
|
||||
@@ -714,7 +711,7 @@ ChatCommandDefinition cc_dicerange(
|
||||
} else if (tokens.size() == 2) {
|
||||
return (stoull(tokens[0]) << 4) | (stoull(tokens[1]) & 0x0F);
|
||||
} else {
|
||||
throw runtime_error("invalid dice spec format");
|
||||
throw std::runtime_error("invalid dice spec format");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -891,33 +888,33 @@ ChatCommandDefinition cc_edit(
|
||||
(s->cheat_mode_behavior != ServerState::BehaviorSwitch::OFF) ||
|
||||
a.c->login->account->check_flag(Account::Flag::CHEAT_ANYWHERE));
|
||||
|
||||
string encoded_args = phosg::tolower(a.text);
|
||||
vector<string> tokens = phosg::split(encoded_args, ' ');
|
||||
std::string encoded_args = phosg::tolower(a.text);
|
||||
std::vector<std::string> tokens = phosg::split(encoded_args, ' ');
|
||||
|
||||
using MatType = PSOBBCharacterFile::MaterialType;
|
||||
|
||||
try {
|
||||
auto p = a.c->character_file();
|
||||
if (tokens.at(0) == "atp" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
p->disp.stats.char_stats.atp = stoul(tokens.at(1));
|
||||
p->disp.stats.char_stats.atp = std::stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "mst" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
p->disp.stats.char_stats.mst = stoul(tokens.at(1));
|
||||
p->disp.stats.char_stats.mst = std::stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "evp" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
p->disp.stats.char_stats.evp = stoul(tokens.at(1));
|
||||
p->disp.stats.char_stats.evp = std::stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "hp" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
p->disp.stats.char_stats.hp = stoul(tokens.at(1));
|
||||
p->disp.stats.char_stats.hp = std::stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "dfp" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
p->disp.stats.char_stats.dfp = stoul(tokens.at(1));
|
||||
p->disp.stats.char_stats.dfp = std::stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "ata" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
p->disp.stats.char_stats.ata = stoul(tokens.at(1));
|
||||
p->disp.stats.char_stats.ata = std::stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "lck" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
p->disp.stats.char_stats.lck = stoul(tokens.at(1));
|
||||
p->disp.stats.char_stats.lck = std::stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "meseta" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
p->disp.stats.meseta = stoul(tokens.at(1));
|
||||
p->disp.stats.meseta = std::stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "exp" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
p->disp.stats.exp = stoul(tokens.at(1));
|
||||
p->disp.stats.exp = std::stoul(tokens.at(1));
|
||||
} else if (tokens.at(0) == "level" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
p->disp.stats.level = stoul(tokens.at(1)) - 1;
|
||||
p->disp.stats.level = std::stoul(tokens.at(1)) - 1;
|
||||
p->recompute_stats(s->level_table(a.c->version()), true);
|
||||
} else if (((tokens.at(0) == "material") || (tokens.at(0) == "mat")) && !is_v1_or_v2(a.c->version()) && (cheats_allowed || !s->cheat_flags.reset_materials)) {
|
||||
if (tokens.at(1) == "reset") {
|
||||
@@ -958,10 +955,10 @@ ChatCommandDefinition cc_edit(
|
||||
}
|
||||
p->recompute_stats(s->level_table(a.c->version()), false);
|
||||
} else if (tokens.at(0) == "namecolor") {
|
||||
p->disp.visual.name_color = stoul(tokens.at(1), nullptr, 16);
|
||||
p->disp.visual.name_color = std::stoul(tokens.at(1), nullptr, 16);
|
||||
} else if (tokens.at(0) == "language" || tokens.at(0) == "lang") {
|
||||
if (tokens.at(1).size() != 1) {
|
||||
throw runtime_error("invalid language");
|
||||
throw std::runtime_error("invalid language");
|
||||
}
|
||||
Language new_language = language_for_char(tokens.at(1).at(0));
|
||||
a.c->channel->language = new_language;
|
||||
@@ -982,7 +979,7 @@ ChatCommandDefinition cc_edit(
|
||||
p->disp.visual.section_id = secid;
|
||||
}
|
||||
} else if (tokens.at(0) == "name") {
|
||||
vector<string> orig_tokens = phosg::split(a.text, ' ', 1);
|
||||
std::vector<std::string> orig_tokens = phosg::split(a.text, ' ', 1);
|
||||
p->disp.name.encode(orig_tokens.at(1), p->inventory.language);
|
||||
} else if (tokens.at(0) == "npc") {
|
||||
if (tokens.at(1) == "none") {
|
||||
@@ -999,7 +996,7 @@ ChatCommandDefinition cc_edit(
|
||||
p->disp.visual.validation_flags |= 0x02;
|
||||
}
|
||||
} else if (tokens.at(0) == "tech" && (cheats_allowed || !s->cheat_flags.edit_stats)) {
|
||||
uint8_t level = stoul(tokens.at(2)) - 1;
|
||||
uint8_t level = std::stoul(tokens.at(2)) - 1;
|
||||
if (tokens.at(1) == "all") {
|
||||
for (size_t x = 0; x < 0x14; x++) {
|
||||
p->set_technique_level(x, level);
|
||||
@@ -1011,14 +1008,14 @@ ChatCommandDefinition cc_edit(
|
||||
}
|
||||
try {
|
||||
p->set_technique_level(tech_id, level);
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
throw precondition_failed("$C6Invalid technique");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw precondition_failed("$C6Unknown field");
|
||||
}
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
throw precondition_failed("$C6Not enough arguments");
|
||||
}
|
||||
|
||||
@@ -1111,10 +1108,10 @@ ChatCommandDefinition cc_exit(
|
||||
a.c->check_flag(Client::Flag::SEND_FUNCTION_CALL_ACTUALLY_RUNS_CODE)) {
|
||||
co_await prepare_client_for_patches(a.c);
|
||||
auto s = a.c->require_server_state();
|
||||
shared_ptr<const ClientFunctionIndex::Function> fn;
|
||||
std::shared_ptr<const ClientFunctionIndex::Function> fn;
|
||||
try {
|
||||
fn = s->client_functions->get("ExitAnywhere", a.c->specific_version);
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
}
|
||||
if (fn) {
|
||||
co_await send_function_call(a.c, fn);
|
||||
@@ -1182,7 +1179,7 @@ ChatCommandDefinition cc_inftime(
|
||||
|
||||
auto l = a.c->require_lobby();
|
||||
if (l->episode != Episode::EP3) {
|
||||
throw logic_error("non-Ep3 client in Ep3 game");
|
||||
throw std::logic_error("non-Ep3 client in Ep3 game");
|
||||
}
|
||||
if (!l->ep3_server) {
|
||||
throw precondition_failed("$C6Episode 3 server\nis not initialized");
|
||||
@@ -1258,7 +1255,7 @@ ChatCommandDefinition cc_item(
|
||||
}
|
||||
}
|
||||
|
||||
string name = s->describe_item(a.c->version(), item, ItemNameIndex::Flag::INCLUDE_PSO_COLOR_ESCAPES);
|
||||
std::string name = s->describe_item(a.c->version(), item, ItemNameIndex::Flag::INCLUDE_PSO_COLOR_ESCAPES);
|
||||
if (was_enqueued) {
|
||||
send_text_message(a.c, "$C7Next item:\n" + name);
|
||||
} else {
|
||||
@@ -1307,13 +1304,12 @@ ChatCommandDefinition cc_kick(
|
||||
if (a.c == target) {
|
||||
// This shouldn't be possible because you need KICK_USER to get here, but the target can't have KICK_USER if we
|
||||
// get here, so if a.c and target are the same, one of the preceding conditions must be false.
|
||||
throw logic_error("client attempts to kick themself off");
|
||||
throw std::logic_error("client attempts to kick themself off");
|
||||
}
|
||||
|
||||
send_message_box(target, "$C6You have been kicked off the server.");
|
||||
string target_name = name_for_client(target);
|
||||
send_text_message_fmt(a.c, "$C6{} kicked off", name_for_client(target));
|
||||
target->channel->disconnect();
|
||||
send_text_message_fmt(a.c, "$C6{} kicked off", target_name);
|
||||
co_return;
|
||||
});
|
||||
|
||||
@@ -1323,7 +1319,7 @@ ChatCommandDefinition cc_killcount(
|
||||
a.check_is_proxy(false);
|
||||
|
||||
auto p = a.c->character_file();
|
||||
vector<size_t> item_indexes;
|
||||
std::vector<size_t> item_indexes;
|
||||
for (size_t z = 0; z < p->inventory.num_items; z++) {
|
||||
const auto& item = p->inventory.items[z];
|
||||
if (item.is_equipped() && item.data.has_kill_count()) {
|
||||
@@ -1348,7 +1344,7 @@ ChatCommandDefinition cc_killcount(
|
||||
auto s = a.c->require_server_state();
|
||||
for (size_t z : item_indexes) {
|
||||
const auto& item = p->inventory.items[z];
|
||||
string name = s->describe_item(
|
||||
std::string name = s->describe_item(
|
||||
a.c->version(), item.data, ItemNameIndex::Flag::INCLUDE_PSO_COLOR_ESCAPES | ItemNameIndex::Flag::NAME_ONLY);
|
||||
send_text_message_fmt(a.c, "{}$C7: {} kills", name, item.data.get_kill_count());
|
||||
}
|
||||
@@ -1360,7 +1356,7 @@ ChatCommandDefinition cc_lobby_info(
|
||||
{"$li"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
if (a.c->proxy_session) {
|
||||
string msg;
|
||||
std::string msg;
|
||||
// On non-masked-GC sessions (BB), there is no remote Guild Card number, so we don't show it. (The user can see
|
||||
// it in the pause menu, unlike in masked-GC sessions like GC.)
|
||||
if (a.c->proxy_session->remote_guild_card_number >= 0) {
|
||||
@@ -1384,7 +1380,7 @@ ChatCommandDefinition cc_lobby_info(
|
||||
}
|
||||
}
|
||||
|
||||
vector<const char*> cheats_tokens;
|
||||
std::vector<const char*> cheats_tokens;
|
||||
if (a.c->check_flag(Client::Flag::INFINITE_HP_ENABLED)) {
|
||||
cheats_tokens.emplace_back("HP");
|
||||
}
|
||||
@@ -1396,7 +1392,7 @@ ChatCommandDefinition cc_lobby_info(
|
||||
msg += phosg::join(cheats_tokens, ",");
|
||||
}
|
||||
|
||||
vector<const char*> behaviors_tokens;
|
||||
std::vector<const char*> behaviors_tokens;
|
||||
if (a.c->check_flag(Client::Flag::SWITCH_ASSIST_ENABLED)) {
|
||||
behaviors_tokens.emplace_back("SWA");
|
||||
}
|
||||
@@ -1419,7 +1415,7 @@ ChatCommandDefinition cc_lobby_info(
|
||||
send_text_message(a.c->channel, msg);
|
||||
|
||||
} else { // Not proxy session
|
||||
vector<string> lines;
|
||||
std::vector<std::string> lines;
|
||||
|
||||
auto l = a.c->lobby.lock();
|
||||
if (!l) {
|
||||
@@ -1476,7 +1472,7 @@ ChatCommandDefinition cc_lobby_info(
|
||||
lines.emplace_back(std::format("$C7Lobby ID: $C6{:08X}$C7", l->lobby_id));
|
||||
}
|
||||
|
||||
string slots_str = "Slots: ";
|
||||
std::string slots_str = "Slots: ";
|
||||
for (size_t z = 0; z < l->clients.size(); z++) {
|
||||
if (!l->clients[z]) {
|
||||
slots_str += std::format("$C0{:X}$C7", z);
|
||||
@@ -1542,7 +1538,7 @@ ChatCommandDefinition cc_loadchar(
|
||||
throw precondition_failed("$C6Player index must\nbe in range 1-{}", s->num_backup_character_slots);
|
||||
}
|
||||
|
||||
shared_ptr<PSOGCEp3CharacterFile::Character> ep3_char;
|
||||
std::shared_ptr<PSOGCEp3CharacterFile::Character> ep3_char;
|
||||
if (is_ep3(a.c->version())) {
|
||||
ep3_char = a.c->load_ep3_backup_character(a.c->login->account->account_id, index);
|
||||
} else {
|
||||
@@ -1578,7 +1574,7 @@ ChatCommandDefinition cc_loadchar(
|
||||
send_player_leave_notification(l, a.c->lobby_client_id);
|
||||
s->send_lobby_join_notifications(l, a.c);
|
||||
}
|
||||
} catch (const exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
a.c->log.warning_f("Failed to set extended player info: {}", e.what());
|
||||
throw precondition_failed("Failed to set\nplayer info:\n{}", e.what());
|
||||
}
|
||||
@@ -1600,14 +1596,14 @@ ChatCommandDefinition cc_loadchar(
|
||||
co_await send_set_extended_player_info(*ep3_char);
|
||||
} else if (a.c->version() == Version::XB_V3) {
|
||||
if (!a.c->login || !a.c->login->xb_license) {
|
||||
throw runtime_error("XB client is not logged in");
|
||||
throw std::runtime_error("XB client is not logged in");
|
||||
}
|
||||
PSOXBCharacterFile::Character xb_char = *a.c->character_file();
|
||||
xb_char.guild_card.xb_user_id_high = (a.c->login->xb_license->user_id >> 32) & 0xFFFFFFFF;
|
||||
xb_char.guild_card.xb_user_id_low = a.c->login->xb_license->user_id & 0xFFFFFFFF;
|
||||
co_await send_set_extended_player_info(xb_char);
|
||||
} else {
|
||||
throw logic_error("unimplemented extended player info version");
|
||||
throw std::logic_error("unimplemented extended player info version");
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -1627,10 +1623,10 @@ ChatCommandDefinition cc_makeobj(
|
||||
|
||||
auto tokens = phosg::split(a.text, ' ');
|
||||
if (tokens.size() < 1) {
|
||||
throw runtime_error("not enough arguments");
|
||||
throw std::runtime_error("not enough arguments");
|
||||
}
|
||||
|
||||
uint32_t base_type_high = stoul(tokens[0], nullptr, 0) << 16;
|
||||
uint32_t base_type_high = std::stoul(tokens[0], nullptr, 0) << 16;
|
||||
VectorXYZF pos = a.c->pos;
|
||||
VectorXYZI angle{0, 0, 0};
|
||||
VectorXYZF param123{0, 0, 0};
|
||||
@@ -1638,7 +1634,7 @@ ChatCommandDefinition cc_makeobj(
|
||||
for (size_t z = 1; z < tokens.size(); z++) {
|
||||
auto subtokens = phosg::split(tokens[z], ':');
|
||||
if (subtokens.size() != 2 || subtokens[0].size() != 1) {
|
||||
throw runtime_error("invalid argument: " + tokens[z]);
|
||||
throw std::runtime_error("invalid argument: " + tokens[z]);
|
||||
}
|
||||
switch (tolower(subtokens[0].front())) {
|
||||
case 'X':
|
||||
@@ -1684,11 +1680,11 @@ ChatCommandDefinition cc_makeobj(
|
||||
param456.z = stol(subtokens[1], nullptr, 0);
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("invalid argument: " + tokens[z]);
|
||||
throw std::runtime_error("invalid argument: " + tokens[z]);
|
||||
}
|
||||
}
|
||||
|
||||
unordered_map<string, uint32_t> label_writes{
|
||||
std::unordered_map<std::string, uint32_t> label_writes{
|
||||
{"base_type_high", base_type_high},
|
||||
{"floor_low", a.c->floor},
|
||||
{"pos_x", std::bit_cast<uint32_t>(pos.x.load())},
|
||||
@@ -1809,8 +1805,7 @@ ChatCommandDefinition cc_password(
|
||||
|
||||
} else {
|
||||
l->password = a.text;
|
||||
string escaped = remove_color(l->password);
|
||||
send_text_message_fmt(l, "$C6Game password:\n{}", escaped);
|
||||
send_text_message_fmt(l, "$C6Game password:\n{}", remove_color(l->password));
|
||||
}
|
||||
co_return;
|
||||
});
|
||||
@@ -1820,15 +1815,15 @@ ChatCommandDefinition cc_patch(
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
auto tokens = phosg::split(a.text, ' ');
|
||||
if (tokens.empty()) {
|
||||
throw runtime_error("not enough arguments");
|
||||
throw std::runtime_error("not enough arguments");
|
||||
}
|
||||
|
||||
string patch_name = std::move(tokens[0]);
|
||||
unordered_map<string, uint32_t> label_writes;
|
||||
std::string patch_name = std::move(tokens[0]);
|
||||
std::unordered_map<std::string, uint32_t> label_writes;
|
||||
for (size_t z = 0; z < tokens.size() - 1; z++) {
|
||||
const auto& token = tokens[z + 1];
|
||||
size_t equals_pos = token.find('=');
|
||||
string key, value;
|
||||
std::string key, value;
|
||||
if (equals_pos == std::string::npos) {
|
||||
key = std::format("arg{}", z);
|
||||
value = token;
|
||||
@@ -1837,9 +1832,9 @@ ChatCommandDefinition cc_patch(
|
||||
value = token.substr(equals_pos + 1);
|
||||
}
|
||||
if (value.contains('.')) { // float
|
||||
label_writes.emplace(std::move(key), std::bit_cast<uint32_t>(stof(value, nullptr)));
|
||||
label_writes.emplace(std::move(key), std::bit_cast<uint32_t>(std::stof(value, nullptr)));
|
||||
} else { // int
|
||||
label_writes.emplace(std::move(key), stoul(value, nullptr, 0));
|
||||
label_writes.emplace(std::move(key), std::stoul(value, nullptr, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1870,7 +1865,7 @@ ChatCommandDefinition cc_patch(
|
||||
ret.return_value.load(), ret.return_value.load(), std::bit_cast<float>(ret.return_value.load()));
|
||||
}
|
||||
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
send_text_message(a.c, "$C6Invalid function");
|
||||
}
|
||||
co_return;
|
||||
@@ -1911,10 +1906,10 @@ ChatCommandDefinition cc_ping(
|
||||
co_return;
|
||||
});
|
||||
|
||||
static string file_path_for_recording(const std::string& args, uint32_t account_id, bool compressed) {
|
||||
static std::string file_path_for_recording(const std::string& args, uint32_t account_id, bool compressed) {
|
||||
for (char ch : args) {
|
||||
if (ch <= 0x20 || ch > 0x7E || ch == '/') {
|
||||
throw runtime_error("invalid recording name");
|
||||
throw std::runtime_error("invalid recording name");
|
||||
}
|
||||
}
|
||||
return std::format("system/ep3/battle-records/{:010}_{}.mzr{}", account_id, args, compressed ? "" : "d");
|
||||
@@ -1932,13 +1927,13 @@ ChatCommandDefinition cc_playrec(
|
||||
} else if (!l->is_game()) {
|
||||
|
||||
auto s = a.c->require_server_state();
|
||||
string filename = a.text;
|
||||
std::string filename = a.text;
|
||||
bool start_battle_player_immediately = (filename.at(0) != '!');
|
||||
if (!start_battle_player_immediately) {
|
||||
filename = filename.substr(1);
|
||||
}
|
||||
|
||||
string data;
|
||||
std::string data;
|
||||
try {
|
||||
data = phosg::load_file(file_path_for_recording(filename, a.c->login->account->account_id, false));
|
||||
} catch (const phosg::cannot_open_file&) {
|
||||
@@ -1949,8 +1944,8 @@ ChatCommandDefinition cc_playrec(
|
||||
throw precondition_failed("$C4The recording does\nnot exist");
|
||||
}
|
||||
}
|
||||
auto record = make_shared<Episode3::BattleRecord>(data);
|
||||
auto battle_player = make_shared<Episode3::BattleRecordPlayer>(s->io_context, record);
|
||||
auto record = std::make_shared<Episode3::BattleRecord>(data);
|
||||
auto battle_player = std::make_shared<Episode3::BattleRecordPlayer>(s->io_context, record);
|
||||
auto game = create_game_generic(
|
||||
s, a.c, filename, "", Episode::EP3, GameMode::NORMAL, Difficulty::NORMAL, false, nullptr, battle_player);
|
||||
if (game) {
|
||||
@@ -1975,7 +1970,7 @@ ChatCommandDefinition cc_qcall(
|
||||
|
||||
auto l = a.c->require_lobby();
|
||||
if (l->is_game() && l->quest) {
|
||||
send_quest_function_call(a.c, stoul(a.text, nullptr, 0));
|
||||
send_quest_function_call(a.c, std::stoul(a.text, nullptr, 0));
|
||||
}
|
||||
co_return;
|
||||
});
|
||||
@@ -1986,7 +1981,7 @@ ChatCommandDefinition cc_qcheck(
|
||||
a.check_is_proxy(false);
|
||||
|
||||
auto l = a.c->require_lobby();
|
||||
uint16_t flag_num = stoul(a.text, nullptr, 0);
|
||||
uint16_t flag_num = std::stoul(a.text, nullptr, 0);
|
||||
|
||||
if (l->is_game()) {
|
||||
if (!l->quest_flags_known || l->quest_flags_known->get(l->difficulty, flag_num)) {
|
||||
@@ -2009,7 +2004,7 @@ ChatCommandDefinition cc_qcheck(
|
||||
|
||||
static void command_qset_qclear(const Args& a, bool should_set) {
|
||||
a.check_is_game(true);
|
||||
uint16_t flag_num = stoul(a.text, nullptr, 0);
|
||||
uint16_t flag_num = std::stoul(a.text, nullptr, 0);
|
||||
|
||||
if (!a.c->proxy_session) {
|
||||
a.check_debug_enabled();
|
||||
@@ -2072,11 +2067,11 @@ ChatCommandDefinition cc_qfread(
|
||||
const auto& def = s->quest_counter_fields.at(a.text);
|
||||
counter_index = def.first;
|
||||
mask = def.second;
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
throw precondition_failed("$C4Invalid field name");
|
||||
}
|
||||
if (mask == 0) {
|
||||
throw runtime_error("invalid quest counter definition");
|
||||
throw std::runtime_error("invalid quest counter definition");
|
||||
}
|
||||
|
||||
uint32_t counter_value = a.c->character_file()->quest_counters.at(counter_index) & mask;
|
||||
@@ -2098,7 +2093,7 @@ ChatCommandDefinition cc_qgread(
|
||||
{"$qgread"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
a.check_is_proxy(false);
|
||||
uint8_t counter_num = stoul(a.text, nullptr, 0);
|
||||
uint8_t counter_num = std::stoul(a.text, nullptr, 0);
|
||||
const auto& counters = a.c->character_file()->quest_counters;
|
||||
if (counter_num >= counters.size()) {
|
||||
throw precondition_failed("$C7Counter ID must be\nless than {}", counters.size());
|
||||
@@ -2126,8 +2121,8 @@ ChatCommandDefinition cc_qgwrite(
|
||||
throw precondition_failed("$C6Incorrect number\nof arguments");
|
||||
}
|
||||
|
||||
uint8_t counter_num = stoul(tokens[0], nullptr, 0);
|
||||
uint32_t value = stoul(tokens[1], nullptr, 0);
|
||||
uint8_t counter_num = std::stoul(tokens[0], nullptr, 0);
|
||||
uint32_t value = std::stoul(tokens[1], nullptr, 0);
|
||||
auto& counters = a.c->character_file()->quest_counters;
|
||||
if (counter_num >= counters.size()) {
|
||||
throw precondition_failed("$C7Counter ID must be\nless than {}", counters.size());
|
||||
@@ -2158,10 +2153,10 @@ static void command_qsync_qsyncall(const Args& a, bool send_to_lobby) {
|
||||
|
||||
G_SyncQuestRegister_6x77 cmd;
|
||||
cmd.header = {0x77, 0x03, 0x0000};
|
||||
cmd.register_number = stoul(tokens[0].substr(1), nullptr, 0);
|
||||
cmd.register_number = std::stoul(tokens[0].substr(1), nullptr, 0);
|
||||
cmd.unused = 0;
|
||||
if (tokens[0][0] == 'r') {
|
||||
cmd.value.as_int = stoul(tokens[1], nullptr, 0);
|
||||
cmd.value.as_int = std::stoul(tokens[1], nullptr, 0);
|
||||
} else if (tokens[0][0] == 'f') {
|
||||
cmd.value.as_float = stof(tokens[1]);
|
||||
} else {
|
||||
@@ -2287,24 +2282,24 @@ ChatCommandDefinition cc_readmem(
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
a.check_debug_enabled();
|
||||
|
||||
uint32_t addr = stoul(a.text, nullptr, 16);
|
||||
uint32_t addr = std::stoul(a.text, nullptr, 16);
|
||||
if (!console_address_in_range(a.c->version(), addr)) {
|
||||
throw precondition_failed("$C4Address out of\nrange");
|
||||
}
|
||||
|
||||
co_await prepare_client_for_patches(a.c);
|
||||
|
||||
shared_ptr<const ClientFunctionIndex::Function> fn;
|
||||
std::shared_ptr<const ClientFunctionIndex::Function> fn;
|
||||
try {
|
||||
auto s = a.c->require_server_state();
|
||||
fn = s->client_functions->get("ReadMemoryWord", a.c->specific_version);
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
throw precondition_failed("Invalid patch name");
|
||||
}
|
||||
|
||||
unordered_map<string, uint32_t> label_writes{{"address", addr}};
|
||||
std::unordered_map<std::string, uint32_t> label_writes{{"address", addr}};
|
||||
auto res = co_await send_function_call(a.c, fn, label_writes);
|
||||
string data_str;
|
||||
std::string data_str;
|
||||
if (is_big_endian(a.c->version())) {
|
||||
be_uint32_t v = res.return_value.load();
|
||||
data_str = phosg::format_data_string(&v, sizeof(v));
|
||||
@@ -2362,9 +2357,9 @@ ChatCommandDefinition cc_saverec(
|
||||
if (!a.c->ep3_prev_battle_record) {
|
||||
throw precondition_failed("$C4No finished\nrecording is\npresent");
|
||||
}
|
||||
string file_path = file_path_for_recording(a.text, a.c->login->account->account_id, false);
|
||||
string data = a.c->ep3_prev_battle_record->serialize();
|
||||
phosg::save_file(file_path, data);
|
||||
phosg::save_file(
|
||||
file_path_for_recording(a.text, a.c->login->account->account_id, false),
|
||||
a.c->ep3_prev_battle_record->serialize());
|
||||
send_text_message(a.c, "$C7Recording saved");
|
||||
a.c->ep3_prev_battle_record.reset();
|
||||
co_return;
|
||||
@@ -2374,7 +2369,7 @@ static asio::awaitable<void> command_send_command(const Args& a, bool to_client,
|
||||
if (!a.c->proxy_session) {
|
||||
a.check_debug_enabled();
|
||||
}
|
||||
string data = phosg::parse_data_string(a.text);
|
||||
std::string data = phosg::parse_data_string(a.text);
|
||||
data.resize((data.size() + 3) & (~3));
|
||||
if (to_client) {
|
||||
if (send_protected) {
|
||||
@@ -2452,7 +2447,7 @@ ChatCommandDefinition cc_setassist(
|
||||
|
||||
auto l = a.c->require_lobby();
|
||||
if (l->episode != Episode::EP3) {
|
||||
throw logic_error("non-Ep3 client in Ep3 game");
|
||||
throw std::logic_error("non-Ep3 client in Ep3 game");
|
||||
}
|
||||
if (!l->ep3_server) {
|
||||
throw precondition_failed("$C6Episode 3 server\nis not initialized");
|
||||
@@ -2465,10 +2460,10 @@ ChatCommandDefinition cc_setassist(
|
||||
}
|
||||
|
||||
size_t client_id;
|
||||
string card_name;
|
||||
std::string card_name;
|
||||
if (isdigit(a.text[0])) {
|
||||
auto tokens = phosg::split(a.text, ' ', 1);
|
||||
client_id = stoul(tokens.at(0), nullptr, 0) - 1;
|
||||
client_id = std::stoul(tokens.at(0), nullptr, 0) - 1;
|
||||
card_name = tokens.at(1);
|
||||
} else {
|
||||
client_id = a.c->lobby_client_id;
|
||||
@@ -2478,10 +2473,10 @@ ChatCommandDefinition cc_setassist(
|
||||
throw precondition_failed("$C6Invalid client ID");
|
||||
}
|
||||
|
||||
shared_ptr<const Episode3::CardIndex::CardEntry> ce;
|
||||
std::shared_ptr<const Episode3::CardIndex::CardEntry> ce;
|
||||
try {
|
||||
ce = l->ep3_server->options.card_index->definition_for_name_normalized(card_name);
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
throw precondition_failed("$C6Card not found");
|
||||
}
|
||||
if (ce->def.type != Episode3::CardType::ASSIST) {
|
||||
@@ -2495,7 +2490,7 @@ ChatCommandDefinition cc_server_info(
|
||||
{"$si"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
auto s = a.c->require_server_state();
|
||||
string uptime_str = phosg::format_duration(phosg::now() - s->creation_time);
|
||||
std::string uptime_str = phosg::format_duration(phosg::now() - s->creation_time);
|
||||
send_text_message_fmt(a.c,
|
||||
"Uptime: $C6{}$C7\nLobbies: $C6{}$C7\nClients: $C6{}$C7(g) $C6{}$C7(p)",
|
||||
uptime_str,
|
||||
@@ -2523,7 +2518,7 @@ ChatCommandDefinition cc_silence(
|
||||
}
|
||||
|
||||
target->can_chat = !target->can_chat;
|
||||
string target_name = name_for_client(target);
|
||||
std::string target_name = name_for_client(target);
|
||||
send_text_message_fmt(a.c, "$C6{} {}silenced", target_name, target->can_chat ? "un" : "");
|
||||
co_return;
|
||||
});
|
||||
@@ -2538,7 +2533,7 @@ ChatCommandDefinition cc_song(
|
||||
song = -song;
|
||||
send_ep3_change_music(a.c->proxy_session->server_channel, song);
|
||||
}
|
||||
send_ep3_change_music(a.c->channel, stoul(a.text, nullptr, 0));
|
||||
send_ep3_change_music(a.c->channel, std::stoul(a.text, nullptr, 0));
|
||||
co_return;
|
||||
});
|
||||
|
||||
@@ -2546,7 +2541,7 @@ ChatCommandDefinition cc_sound(
|
||||
{"$sound"},
|
||||
+[](const Args& a) -> asio::awaitable<void> {
|
||||
bool echo_to_all = (!a.text.empty() && a.text[0] == '!');
|
||||
uint32_t sound_id = stoul(echo_to_all ? a.text.substr(1) : a.text, nullptr, 16);
|
||||
uint32_t sound_id = std::stoul(echo_to_all ? a.text.substr(1) : a.text, nullptr, 16);
|
||||
|
||||
auto l = a.c->require_lobby();
|
||||
uint8_t area = l->is_game() ? l->area_for_floor(a.c->version(), a.c->floor) : 0x0F;
|
||||
@@ -2571,7 +2566,7 @@ ChatCommandDefinition cc_spec(
|
||||
a.check_is_ep3(true);
|
||||
auto l = a.c->require_lobby();
|
||||
if (!l->is_ep3()) {
|
||||
throw logic_error("Episode 3 client in non-Episode 3 game");
|
||||
throw std::logic_error("Episode 3 client in non-Episode 3 game");
|
||||
}
|
||||
|
||||
// In non-tournament games, only the leader can do this; in a tournament match, the players don't have control
|
||||
@@ -2613,7 +2608,7 @@ ChatCommandDefinition cc_stat(
|
||||
a.check_is_ep3(true);
|
||||
auto l = a.c->require_lobby();
|
||||
if (l->episode != Episode::EP3) {
|
||||
throw logic_error("non-Ep3 client in Ep3 game");
|
||||
throw std::logic_error("non-Ep3 client in Ep3 game");
|
||||
}
|
||||
if (!l->ep3_server) {
|
||||
throw precondition_failed("$C6Episode 3 server\nis not initialized");
|
||||
@@ -2627,7 +2622,7 @@ ChatCommandDefinition cc_stat(
|
||||
}
|
||||
uint8_t team_id = ps->get_team_id();
|
||||
if (team_id > 1) {
|
||||
throw logic_error("team ID is incorrect");
|
||||
throw std::logic_error("team ID is incorrect");
|
||||
}
|
||||
|
||||
if (a.text == "rank") {
|
||||
@@ -2636,8 +2631,8 @@ ChatCommandDefinition cc_stat(
|
||||
const char* rank_name = ps->stats.name_for_rank(rank);
|
||||
send_text_message_fmt(a.c, "$C7Score: {:g}\nRank: {} ({})", score, rank, rank_name);
|
||||
} else if (a.text == "duration") {
|
||||
string s = phosg::format_duration(phosg::now() - l->ep3_server->battle_start_usecs);
|
||||
send_text_message_fmt(a.c, "$C7Duration: {}", s);
|
||||
send_text_message_fmt(a.c, "$C7Duration: {}",
|
||||
phosg::format_duration(phosg::now() - l->ep3_server->battle_start_usecs));
|
||||
} else if (a.text == "fcs-destroyed") {
|
||||
send_text_message_fmt(a.c, "$C7Team FCs destroyed:\n{}", l->ep3_server->team_num_ally_fcs_destroyed[team_id]);
|
||||
} else if (a.text == "cards-destroyed") {
|
||||
@@ -2694,7 +2689,7 @@ ChatCommandDefinition cc_surrender(
|
||||
a.check_is_ep3(true);
|
||||
auto l = a.c->require_lobby();
|
||||
if (l->episode != Episode::EP3) {
|
||||
throw logic_error("non-Ep3 client in Ep3 game");
|
||||
throw std::logic_error("non-Ep3 client in Ep3 game");
|
||||
}
|
||||
if (!l->ep3_server) {
|
||||
throw precondition_failed("$C6Episode 3 server\nis not initialized");
|
||||
@@ -2706,7 +2701,7 @@ ChatCommandDefinition cc_surrender(
|
||||
if (!ps || !ps->is_alive()) {
|
||||
throw precondition_failed("$C6Defeated players\ncannot surrender");
|
||||
}
|
||||
string name = remove_color(a.c->character_file()->disp.name.decode(a.c->language()));
|
||||
std::string name = remove_color(a.c->character_file()->disp.name.decode(a.c->language()));
|
||||
send_text_message_fmt(l, "$C6{} has\nsurrendered", name);
|
||||
for (const auto& watcher_l : l->watcher_lobbies) {
|
||||
send_text_message_fmt(watcher_l, "$C6{} has\nsurrendered", name);
|
||||
@@ -2736,10 +2731,10 @@ static void command_swset_swclear(const Args& a, bool should_set) {
|
||||
uint8_t floor, flag_num;
|
||||
if (tokens.size() == 1) {
|
||||
floor = a.c->floor;
|
||||
flag_num = stoul(tokens[0], nullptr, 0);
|
||||
flag_num = std::stoul(tokens[0], nullptr, 0);
|
||||
} else if (tokens.size() == 2) {
|
||||
floor = stoul(tokens[0], nullptr, 0);
|
||||
flag_num = stoul(tokens[1], nullptr, 0);
|
||||
floor = std::stoul(tokens[0], nullptr, 0);
|
||||
flag_num = std::stoul(tokens[1], nullptr, 0);
|
||||
} else {
|
||||
throw precondition_failed("$C4Incorrect parameters");
|
||||
}
|
||||
@@ -2859,7 +2854,7 @@ ChatCommandDefinition cc_unset(
|
||||
a.check_cheats_enabled_in_game(s->cheat_flags.ep3_unset_field_character);
|
||||
auto l = a.c->require_lobby();
|
||||
if (l->episode != Episode::EP3) {
|
||||
throw logic_error("non-Ep3 client in Ep3 game");
|
||||
throw std::logic_error("non-Ep3 client in Ep3 game");
|
||||
}
|
||||
if (!l->ep3_server) {
|
||||
throw precondition_failed("$C6Episode 3 server\nis not initialized");
|
||||
@@ -2886,8 +2881,8 @@ ChatCommandDefinition cc_variations(
|
||||
auto s = a.c->require_server_state();
|
||||
a.check_cheats_enabled_in_game(s->cheat_flags.override_variations);
|
||||
|
||||
a.c->override_variations = make_unique<Variations>();
|
||||
for (size_t z = 0; z < min<size_t>(a.c->override_variations->entries.size() * 2, a.text.size()); z++) {
|
||||
a.c->override_variations = std::make_unique<Variations>();
|
||||
for (size_t z = 0; z < std::min<size_t>(a.c->override_variations->entries.size() * 2, a.text.size()); z++) {
|
||||
auto& entry = a.c->override_variations->entries.at(z / 2);
|
||||
if (z & 1) {
|
||||
entry.entities = a.text[z] - '0';
|
||||
@@ -2905,7 +2900,7 @@ static void command_warp(const Args& a, bool is_warpall) {
|
||||
auto s = a.c->require_server_state();
|
||||
a.check_cheats_enabled_or_allowed(s->cheat_flags.warp);
|
||||
|
||||
uint32_t floor = stoul(a.text, nullptr, 0);
|
||||
uint32_t floor = std::stoul(a.text, nullptr, 0);
|
||||
if (!is_warpall && (a.c->floor == floor)) {
|
||||
return;
|
||||
}
|
||||
@@ -2959,7 +2954,7 @@ ChatCommandDefinition cc_what(
|
||||
co_return;
|
||||
}
|
||||
|
||||
shared_ptr<const Lobby::FloorItem> nearest_fi;
|
||||
std::shared_ptr<const Lobby::FloorItem> nearest_fi;
|
||||
float min_dist2 = 0.0f;
|
||||
for (const auto& it : l->floor_item_managers.at(a.c->floor).items) {
|
||||
if (!it.second->visible_to_client(a.c->lobby_client_id)) {
|
||||
@@ -2976,9 +2971,8 @@ ChatCommandDefinition cc_what(
|
||||
throw precondition_failed("$C4No items are near you");
|
||||
} else {
|
||||
auto s = a.c->require_server_state();
|
||||
string name = s->describe_item(
|
||||
a.c->version(), nearest_fi->data, ItemNameIndex::Flag::INCLUDE_PSO_COLOR_ESCAPES);
|
||||
send_text_message(a.c, name);
|
||||
send_text_message(
|
||||
a.c, s->describe_item(a.c->version(), nearest_fi->data, ItemNameIndex::Flag::INCLUDE_PSO_COLOR_ESCAPES));
|
||||
}
|
||||
co_return;
|
||||
});
|
||||
@@ -3005,8 +2999,8 @@ static void whatobj_whatene_fn(const Args& a, bool include_objs, bool include_en
|
||||
|
||||
double min_dist2 = -1.0;
|
||||
VectorXYZF nearest_worldspace_pos;
|
||||
shared_ptr<const MapState::ObjectState> nearest_obj;
|
||||
shared_ptr<const MapState::EnemyState> nearest_ene;
|
||||
std::shared_ptr<const MapState::ObjectState> nearest_obj;
|
||||
std::shared_ptr<const MapState::EnemyState> nearest_ene;
|
||||
|
||||
auto check_entity = [&](auto& nearest_entity, auto entity, const auto& def) -> void {
|
||||
VectorXYZF worldspace_pos;
|
||||
@@ -3015,7 +3009,7 @@ static void whatobj_whatene_fn(const Args& a, bool include_objs, bool include_en
|
||||
const auto& room = s->room_layout_index->get_room(area, layout_var, def.set_entry->room);
|
||||
// This is the order in which the game does the rotations; not sure why
|
||||
worldspace_pos = def.set_entry->pos.rotate_x(room.angle.x).rotate_z(room.angle.z).rotate_y(room.angle.y) + room.position;
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
a.c->log.warning_f("Can't find definition for room {:02X}:{:02X}:{:08X}", area, layout_var, def.set_entry->room);
|
||||
worldspace_pos = def.set_entry->pos;
|
||||
}
|
||||
@@ -3056,7 +3050,7 @@ static void whatobj_whatene_fn(const Args& a, bool include_objs, bool include_en
|
||||
// we print that if it's set, and print the object if not.
|
||||
if (nearest_ene) {
|
||||
const auto* set_entry = nearest_ene->super_ene->version(a.c->version()).set_entry;
|
||||
string type_name = MapFile::name_for_enemy_type(set_entry->base_type, a.c->version(), area);
|
||||
std::string type_name = MapFile::name_for_enemy_type(set_entry->base_type, a.c->version(), area);
|
||||
uint8_t area = l->area_for_floor(a.c->version(), a.c->floor);
|
||||
send_text_message_fmt(a.c, "$C5E-{:03X}\n$C6{}\n$C2{}\n$C7X:{:.2f} Z:{:.2f}",
|
||||
nearest_ene->e_id, phosg::name_for_enum(nearest_ene->type(a.c->version(), area, l->difficulty, l->event)),
|
||||
@@ -3120,7 +3114,7 @@ ChatCommandDefinition cc_where(
|
||||
if (!a.c->proxy_session && l && l->is_game()) {
|
||||
for (auto lc : l->clients) {
|
||||
if (lc && (lc != a.c)) {
|
||||
string name = lc->character_file()->disp.name.decode(lc->language());
|
||||
std::string name = lc->character_file()->disp.name.decode(lc->language());
|
||||
send_text_message_fmt(a.c, "$C6{}$C7 {:X}:{}",
|
||||
name, lc->floor, FloorDefinition::get(l->episode, lc->floor).short_name);
|
||||
}
|
||||
@@ -3139,7 +3133,7 @@ ChatCommandDefinition cc_writemem(
|
||||
throw precondition_failed("Incorrect arguments");
|
||||
}
|
||||
|
||||
uint32_t addr = stoul(tokens[0], nullptr, 16);
|
||||
uint32_t addr = std::stoul(tokens[0], nullptr, 16);
|
||||
if (!console_address_in_range(a.c->version(), addr)) {
|
||||
throw precondition_failed("$C4Address out of\nrange");
|
||||
}
|
||||
@@ -3152,9 +3146,9 @@ ChatCommandDefinition cc_writemem(
|
||||
try {
|
||||
auto s = a.c->require_server_state();
|
||||
auto fn = s->client_functions->get("WriteMemory", a.c->specific_version);
|
||||
unordered_map<string, uint32_t> label_writes{{"dest_addr", addr}, {"size", data.size()}};
|
||||
std::unordered_map<std::string, uint32_t> label_writes{{"dest_addr", addr}, {"size", data.size()}};
|
||||
co_await send_function_call(a.c, fn, label_writes, data.data(), data.size());
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
throw precondition_failed("Invalid patch name");
|
||||
}
|
||||
co_return;
|
||||
@@ -3177,12 +3171,12 @@ ChatCommandDefinition cc_nativecall(
|
||||
throw precondition_failed("Incorrect arguments");
|
||||
}
|
||||
|
||||
uint32_t addr = stoul(tokens[0], nullptr, 16);
|
||||
uint32_t addr = std::stoul(tokens[0], nullptr, 16);
|
||||
if (!console_address_in_range(a.c->version(), addr)) {
|
||||
throw precondition_failed("$C4Function address\nout of range");
|
||||
}
|
||||
|
||||
unordered_map<string, uint32_t> label_writes{{"call_addr", addr}};
|
||||
std::unordered_map<std::string, uint32_t> label_writes{{"call_addr", addr}};
|
||||
for (size_t z = 0; z < tokens.size() - 1; z++) {
|
||||
label_writes.emplace(std::format("arg{}", z), stoull(tokens[z + 1], nullptr, 16));
|
||||
}
|
||||
@@ -3193,7 +3187,7 @@ ChatCommandDefinition cc_nativecall(
|
||||
auto s = a.c->require_server_state();
|
||||
auto fn = s->client_functions->get("CallNativeFunction", a.c->specific_version);
|
||||
co_await send_function_call(a.c, fn, label_writes);
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
throw precondition_failed("Invalid patch name");
|
||||
}
|
||||
co_return;
|
||||
@@ -3203,12 +3197,12 @@ ChatCommandDefinition cc_nativecall(
|
||||
// Dispatch methods
|
||||
|
||||
struct SplitCommand {
|
||||
string name;
|
||||
string args;
|
||||
std::string name;
|
||||
std::string args;
|
||||
|
||||
SplitCommand(const string& text) {
|
||||
SplitCommand(const std::string& text) {
|
||||
size_t space_pos = text.find(' ');
|
||||
if (space_pos != string::npos) {
|
||||
if (space_pos != std::string::npos) {
|
||||
this->name = text.substr(0, space_pos);
|
||||
this->args = text.substr(space_pos + 1);
|
||||
} else {
|
||||
@@ -3231,7 +3225,7 @@ asio::awaitable<void> on_chat_command(std::shared_ptr<Client> c, const std::stri
|
||||
const ChatCommandDefinition* def = nullptr;
|
||||
try {
|
||||
def = ChatCommandDefinition::all_defs.at(cmd.name);
|
||||
} catch (const out_of_range&) {
|
||||
} catch (const std::out_of_range&) {
|
||||
}
|
||||
if (!def) {
|
||||
send_text_message(c, "$C6Unknown command");
|
||||
@@ -3242,7 +3236,7 @@ asio::awaitable<void> on_chat_command(std::shared_ptr<Client> c, const std::stri
|
||||
co_await def->handler(Args{cmd.args, check_permissions, c});
|
||||
} catch (const precondition_failed& e) {
|
||||
send_text_message(c, e.what());
|
||||
} catch (const exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
send_text_message(c, "$C6Failed:\n" + remove_color(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user