centralize command formats; fix a few range bugs

This commit is contained in:
Martin Michelsen
2022-03-30 23:28:14 -07:00
parent db099ed2dd
commit 7dce8b6c2c
19 changed files with 2226 additions and 1937 deletions
+42 -63
View File
@@ -16,11 +16,29 @@ using namespace std;
// originally there was going to be a language-based header, but then I decided against it.
// these strings were already in use for that parser, so I didn't bother changing them.
#define PLAYER_FILE_SIGNATURE "newserv player file format; 10 sections present; sequential;"
#define ACCOUNT_FILE_SIGNATURE "newserv account file format; 7 sections present; sequential;"
#define PLAYER_FILE_SIGNATURE "newserv player file format; 10 sections present; sequential;"
#define ACCOUNT_FILE_SIGNATURE "newserv account file format; 7 sections present; sequential;"
void PlayerDispDataPCGC::enforce_pc_limits() {
// PC has fewer classes, so we'll substitute some here
if (this->char_class == 11) {
this->char_class = 0; // fomar -> humar
} else if (this->char_class == 10) {
this->char_class = 1; // ramarl -> hunewearl
} else if (this->char_class == 9) {
this->char_class = 5; // hucaseal -> racaseal
}
// if the player is still not a valid class, make them appear as the "ninja" NPC
if (this->char_class > 8) {
this->extra_model = 0;
this->v2_flags |= 2;
}
this->version = 2;
}
// converts PC/GC player data to BB format
PlayerDispDataBB PlayerDispDataPCGC::to_bb() const {
PlayerDispDataBB bb;
@@ -38,7 +56,7 @@ PlayerDispDataBB PlayerDispDataPCGC::to_bb() const {
bb.experience = this->experience;
bb.meseta = this->meseta;
memset(bb.guild_card, 0, sizeof(bb.guild_card));
strcpy(bb.guild_card, " 0");
strncpy(bb.guild_card, " 0", 0x10);
bb.unknown3[0] = this->unknown3[0];
bb.unknown3[1] = this->unknown3[1];
bb.name_color = this->name_color;
@@ -119,7 +137,7 @@ PlayerDispDataBBPreview PlayerDispDataBB::to_preview() const {
pre.level = this->level;
pre.experience = this->experience;
memset(pre.guild_card, 0, sizeof(pre.guild_card));
strcpy(pre.guild_card, this->guild_card);
strncpy(pre.guild_card, this->guild_card, 0x10);
pre.unknown3[0] = this->unknown3[0];
pre.unknown3[1] = this->unknown3[1];
pre.name_color = this->name_color;
@@ -142,7 +160,7 @@ PlayerDispDataBBPreview PlayerDispDataBB::to_preview() const {
pre.proportion_x = this->proportion_x;
pre.proportion_y = this->proportion_y;
memset(pre.name, 0, sizeof(pre.name));
char16cpy(pre.name, this->name, 16);
char16ncpy(pre.name, this->name, 16);
pre.play_time = this->play_time;
return pre;
}
@@ -151,7 +169,7 @@ void PlayerDispDataBB::apply_preview(const PlayerDispDataBBPreview& pre) {
this->level = pre.level;
this->experience = pre.experience;
memset(this->guild_card, 0, sizeof(this->guild_card));
strcpy(this->guild_card, pre.guild_card);
strncpy(this->guild_card, pre.guild_card, 0x10);
this->unknown3[0] = pre.unknown3[0];
this->unknown3[1] = pre.unknown3[1];
this->name_color = pre.name_color;
@@ -174,7 +192,7 @@ void PlayerDispDataBB::apply_preview(const PlayerDispDataBBPreview& pre) {
this->proportion_x = pre.proportion_x;
this->proportion_y = pre.proportion_y;
memset(this->name, 0, sizeof(this->name));
char16cpy(this->name, pre.name, 16);
char16ncpy(this->name, pre.name, 0x10);
this->play_time = 0;
}
@@ -226,55 +244,16 @@ void Player::import(const PSOPlayerDataBB& bb) {
// note: we don't copy the inventory and disp here because we already have
// it (we sent the player data to the client in the first place)
memset(this->info_board, 0, sizeof(this->info_board));
char16cpy(this->info_board, bb.info_board, 0xAC);
char16ncpy(this->info_board, bb.info_board, 0xAC);
memcpy(&this->blocked, bb.blocked, sizeof(uint32_t) * 30);
memset(this->auto_reply, 0, sizeof(this->auto_reply));
if (bb.auto_reply_enabled) {
char16cpy(this->auto_reply, bb.auto_reply, 0xAC);
char16ncpy(this->auto_reply, bb.auto_reply, 0xAC);
} else {
this->auto_reply[0] = 0;
}
}
// generates data for 65/67/68 commands (joining games/lobbies)
PlayerLobbyJoinDataPCGC Player::export_lobby_data_pc() const {
PlayerLobbyJoinDataPCGC pc;
pc.inventory = this->inventory;
pc.disp = this->disp.to_pcgc();
// PC has fewer classes, so we'll substitute some here
if (pc.disp.char_class == 11) {
pc.disp.char_class = 0; // fomar -> humar
} else if (pc.disp.char_class == 10) {
pc.disp.char_class = 1; // ramarl -> hunewearl
} else if (pc.disp.char_class == 9) {
pc.disp.char_class = 5; // hucaseal -> racaseal
}
// if the player is still not a valid class, make them appear as the "ninja" NPC
if (pc.disp.char_class > 8) {
pc.disp.extra_model = 0;
pc.disp.v2_flags |= 2;
}
pc.disp.version = 2;
return pc;
}
PlayerLobbyJoinDataPCGC Player::export_lobby_data_gc() const {
PlayerLobbyJoinDataPCGC gc;
gc.inventory = this->inventory;
gc.disp = this->disp.to_pcgc();
return gc;
}
PlayerLobbyJoinDataBB Player::export_lobby_data_bb() const {
PlayerLobbyJoinDataBB bb;
bb.inventory = this->inventory;
bb.disp = this->disp;
return bb;
}
PlayerBB Player::export_bb_player_data() const {
PlayerBB bb;
bb.inventory = this->inventory;
@@ -285,11 +264,11 @@ PlayerBB Player::export_bb_player_data() const {
bb.bank = this->bank;
bb.serial_number = this->serial_number;
memset(bb.name, 0, sizeof(bb.name));
char16cpy(bb.name, this->disp.name, 24);
char16ncpy(bb.name, this->disp.name, 24);
memset(bb.team_name, 0, sizeof(bb.team_name));
char16cpy(bb.team_name, this->team_name, 16);
char16ncpy(bb.team_name, this->team_name, 16);
memset(bb.guild_card_desc, 0, sizeof(bb.guild_card_desc));
char16cpy(bb.guild_card_desc, this->guild_card_desc, 0x58);
char16ncpy(bb.guild_card_desc, this->guild_card_desc, 0x58);
bb.reserved1 = 0;
bb.reserved2 = 0;
bb.section_id = this->disp.section_id;
@@ -298,9 +277,9 @@ PlayerBB Player::export_bb_player_data() const {
memcpy(bb.symbol_chats, this->symbol_chats, 0x04E0);
memcpy(bb.shortcuts, this->shortcuts, 0x0A40);
memset(bb.auto_reply, 0, sizeof(bb.auto_reply));
char16cpy(bb.auto_reply, this->auto_reply, 0xAC);
char16ncpy(bb.auto_reply, this->auto_reply, 0xAC);
memset(bb.info_board, 0, sizeof(bb.info_board));
char16cpy(bb.info_board, this->info_board, 0xAC);
char16ncpy(bb.info_board, this->info_board, 0xAC);
memset(bb.unknown5, 0, 0x1C);
memcpy(bb.challenge_data, this->challenge_data, 0x0140);
memcpy(bb.tech_menu_config, this->tech_menu_config, 0x0028);
@@ -344,13 +323,13 @@ void Player::load_account_data(const string& filename) {
memcpy(&this->shortcuts, &account.shortcuts, 0x0A40);
memcpy(&this->symbol_chats, &account.symbol_chats, 0x04E0);
memset(this->team_name, 0, sizeof(this->team_name));
char16cpy(this->team_name, account.team_name, 16);
char16ncpy(this->team_name, account.team_name, 16);
}
void Player::save_account_data(const string& filename) const {
SavedAccountBB account;
strcpy(account.signature, ACCOUNT_FILE_SIGNATURE);
strncpy(account.signature, ACCOUNT_FILE_SIGNATURE, sizeof(account.signature));
memcpy(&account.blocked, &this->blocked, sizeof(uint32_t) * 30);
account.guild_cards = this->guild_cards;
account.key_config = this->key_config;
@@ -358,7 +337,7 @@ void Player::save_account_data(const string& filename) const {
memcpy(&account.shortcuts, &this->shortcuts, 0x0A40);
memcpy(&account.symbol_chats, &this->symbol_chats, 0x04E0);
memset(account.team_name, 0, sizeof(account.team_name));
char16cpy(account.team_name, this->team_name, 16);
char16ncpy(account.team_name, this->team_name, 16);
save_file(filename, &account, sizeof(account));
}
@@ -371,14 +350,14 @@ void Player::load_player_data(const string& filename) {
}
memset(this->auto_reply, 0, sizeof(this->auto_reply));
char16cpy(this->auto_reply, player.auto_reply, 0xAC);
char16ncpy(this->auto_reply, player.auto_reply, 0xAC);
this->bank = player.bank;
memcpy(&this->challenge_data, &player.challenge_data, 0x0140);
this->disp = player.disp;
memset(this->guild_card_desc, 0, sizeof(this->guild_card_desc));
char16cpy(this->guild_card_desc, player.guild_card_desc, 0x58);
char16ncpy(this->guild_card_desc, player.guild_card_desc, 0x58);
memset(this->info_board, 0, sizeof(this->info_board));
char16cpy(this->info_board, player.info_board, 0xAC);
char16ncpy(this->info_board, player.info_board, 0xAC);
this->inventory = player.inventory;
memcpy(&this->quest_data1, &player.quest_data1, 0x0208);
memcpy(&this->quest_data2, &player.quest_data2, 0x0058);
@@ -388,17 +367,17 @@ void Player::load_player_data(const string& filename) {
void Player::save_player_data(const string& filename) const {
SavedPlayerBB player;
strcpy(player.signature, PLAYER_FILE_SIGNATURE);
strncpy(player.signature, PLAYER_FILE_SIGNATURE, sizeof(player.signature));
player.preview = this->disp.to_preview();
memset(player.auto_reply, 0, sizeof(player.auto_reply));
char16cpy(player.auto_reply, this->auto_reply, 0xAC);
char16ncpy(player.auto_reply, this->auto_reply, 0xAC);
player.bank = this->bank;
memcpy(&player.challenge_data, &this->challenge_data, 0x0140);
player.disp = this->disp;
memset(player.guild_card_desc, 0, sizeof(player.guild_card_desc));
char16cpy(player.guild_card_desc,this->guild_card_desc, 0x58);
char16ncpy(player.guild_card_desc,this->guild_card_desc, 0x58);
memset(player.info_board, 0, sizeof(player.info_board));
char16cpy(player.info_board, this->info_board, 0xAC);
char16ncpy(player.info_board, this->info_board, 0xAC);
player.inventory = this->inventory;
memcpy(&player.quest_data1, &this->quest_data1, 0x0208);
memcpy(&player.quest_data2, &this->quest_data2, 0x0058);