From 93906f8ff39c58470334705a83cca20508cca227 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Thu, 21 Sep 2023 17:07:58 -0700 Subject: [PATCH] default-clear all converted_endian parrays to zero --- src/PlayerSubordinates.cc | 50 ---------------------------- src/PlayerSubordinates.hh | 68 ++++++++++++++------------------------- src/SendCommands.cc | 10 ++---- src/Text.hh | 9 ++++-- 4 files changed, 32 insertions(+), 105 deletions(-) diff --git a/src/PlayerSubordinates.cc b/src/PlayerSubordinates.cc index a907cdbc..e9a2a196 100644 --- a/src/PlayerSubordinates.cc +++ b/src/PlayerSubordinates.cc @@ -17,32 +17,6 @@ FileContentsCache player_files_cache(300 * 1000 * 1000); -PlayerStats::PlayerStats() noexcept - : level(0), - experience(0), - meseta(0) {} - -PlayerVisualConfig::PlayerVisualConfig() noexcept - : unknown_a2(0), - name_color(0), - extra_model(0), - unknown_a3(0), - section_id(0), - char_class(0), - v2_flags(0), - version(0), - v1_flags(0), - costume(0), - skin(0), - face(0), - head(0), - hair(0), - hair_r(0), - hair_g(0), - hair_b(0), - proportion_x(0), - proportion_y(0) {} - void PlayerDispDataDCPCV3::enforce_v2_limits() { // V1/V2 have fewer classes, so we'll substitute some here if (this->visual.char_class == 11) { @@ -73,10 +47,6 @@ PlayerDispDataBB PlayerDispDataDCPCV3::to_bb() const { return bb; } -PlayerDispDataBB::PlayerDispDataBB() noexcept - : play_time(0), - unknown_a3(0) {} - PlayerDispDataDCPCV3 PlayerDispDataBB::to_dcpcv3() const { PlayerDispDataDCPCV3 ret; ret.stats = this->stats; @@ -127,26 +97,6 @@ void PlayerDispDataBB::apply_dressing_room(const PlayerDispDataBBPreview& pre) { this->name = pre.name; } -PlayerDispDataBBPreview::PlayerDispDataBBPreview() noexcept - : experience(0), - level(0), - play_time(0) {} - -GuildCardV3::GuildCardV3() noexcept - : player_tag(0), - guild_card_number(0), - present(0), - language(0), - section_id(0), - char_class(0) {} - -GuildCardBB::GuildCardBB() noexcept - : guild_card_number(0), - present(0), - language(0), - section_id(0), - char_class(0) {} - void GuildCardBB::clear() { this->guild_card_number = 0; this->name.clear(0); diff --git a/src/PlayerSubordinates.hh b/src/PlayerSubordinates.hh index f1c0a242..ad7f01ed 100644 --- a/src/PlayerSubordinates.hh +++ b/src/PlayerSubordinates.hh @@ -108,14 +108,12 @@ struct PlayerStats { /* 1C */ le_uint32_t experience = 0; /* 20 */ le_uint32_t meseta = 0; /* 24 */ - - PlayerStats() noexcept; } __attribute__((packed)); struct PlayerVisualConfig { /* 00 */ ptext name; /* 10 */ le_uint64_t unknown_a2 = 0; // Note: This is probably not actually a 64-bit int. - /* 18 */ le_uint32_t name_color = 0xFFFFFFFF; // RGBA + /* 18 */ le_uint32_t name_color = 0x00000000; // RGBA /* 1C */ uint8_t extra_model = 0; /* 1D */ parray unused; /* 2C */ le_uint32_t unknown_a3 = 0; @@ -135,8 +133,6 @@ struct PlayerVisualConfig { /* 48 */ le_float proportion_x = 0.0; /* 4C */ le_float proportion_y = 0.0; /* 50 */ - - PlayerVisualConfig() noexcept; } __attribute__((packed)); struct PlayerDispDataDCPCV3 { @@ -145,28 +141,19 @@ struct PlayerDispDataDCPCV3 { /* 74 */ parray config; /* BC */ parray v1_technique_levels; /* D0 */ - - // Note: This struct has a default constructor because it's used in a command - // that has a fixed-size array. If we didn't define this constructor, the - // trivial fields in that array's members would be uninitialized, and we could - // send uninitialized memory to the client. - PlayerDispDataDCPCV3() noexcept = default; - void enforce_v2_limits(); PlayerDispDataBB to_bb() const; } __attribute__((packed)); struct PlayerDispDataBBPreview { - /* 00 */ le_uint32_t experience; - /* 04 */ le_uint32_t level; + /* 00 */ le_uint32_t experience = 0; + /* 04 */ le_uint32_t level = 0; // The name field in this structure is used for the player's Guild Card // number, apparently (possibly because it's a char array and this is BB) /* 08 */ PlayerVisualConfig visual; /* 58 */ ptext name; - /* 78 */ uint32_t play_time; + /* 78 */ uint32_t play_time = 0; /* 7C */ - - PlayerDispDataBBPreview() noexcept; } __attribute__((packed)); // BB player appearance and stats data @@ -174,14 +161,12 @@ struct PlayerDispDataBB { /* 0000 */ PlayerStats stats; /* 0024 */ PlayerVisualConfig visual; /* 0074 */ ptext name; - /* 008C */ le_uint32_t play_time; - /* 0090 */ uint32_t unknown_a3; + /* 008C */ le_uint32_t play_time = 0; + /* 0090 */ uint32_t unknown_a3 = 0; /* 0094 */ parray config; /* 017C */ parray technique_levels; /* 0190 */ - PlayerDispDataBB() noexcept; - inline void enforce_v2_limits() {} PlayerDispDataDCPCV3 to_dcpcv3() const; PlayerDispDataBBPreview to_preview() const; @@ -192,32 +177,29 @@ struct PlayerDispDataBB { // TODO: Is this the same for XB as it is for GC? (This struct is based on the // GC format) struct GuildCardV3 { - /* 00 */ le_uint32_t player_tag; - /* 04 */ le_uint32_t guild_card_number; + /* 00 */ le_uint32_t player_tag = 0; + /* 04 */ le_uint32_t guild_card_number = 0; /* 08 */ ptext name; /* 20 */ ptext description; - /* 8C */ uint8_t present; // should be 1 - /* 8D */ uint8_t language; - /* 8E */ uint8_t section_id; - /* 8F */ uint8_t char_class; + /* 8C */ uint8_t present = 0; + /* 8D */ uint8_t language = 0; + /* 8E */ uint8_t section_id = 0; + /* 8F */ uint8_t char_class = 0; /* 90 */ - - GuildCardV3() noexcept; } __attribute__((packed)); // BB guild card format struct GuildCardBB { - /* 0000 */ le_uint32_t guild_card_number; + /* 0000 */ le_uint32_t guild_card_number = 0; /* 0004 */ ptext name; /* 0034 */ ptext team_name; /* 0054 */ ptext description; - /* 0104 */ uint8_t present; // should be 1 if guild card entry exists - /* 0105 */ uint8_t language; - /* 0106 */ uint8_t section_id; - /* 0107 */ uint8_t char_class; + /* 0104 */ uint8_t present = 0; + /* 0105 */ uint8_t language = 0; + /* 0106 */ uint8_t section_id = 0; + /* 0107 */ uint8_t char_class = 0; /* 0108 */ - GuildCardBB() noexcept; void clear(); } __attribute__((packed)); @@ -244,14 +226,14 @@ struct KeyAndTeamConfigBB { parray unknown_a1; // 0000 parray key_config; // 0114 parray joystick_config; // 0280 - le_uint32_t guild_card_number; // 02B8 - le_uint32_t team_id; // 02BC - le_uint64_t team_info; // 02C0 - le_uint16_t team_privilege_level; // 02C8 - le_uint16_t reserved; // 02CA + le_uint32_t guild_card_number = 0; // 02B8 + le_uint32_t team_id = 0; // 02BC + le_uint64_t team_info = 0; // 02C0 + le_uint16_t team_privilege_level = 0; // 02C8 + le_uint16_t reserved = 0; // 02CA ptext team_name; // 02CC parray team_flag; // 02EC - le_uint32_t team_rewards; // 0AEC + le_uint32_t team_rewards = 0; // 0AEC } __attribute__((packed)); struct PlayerLobbyDataPC { @@ -412,7 +394,7 @@ struct PlayerRecords_Battle { using U16T = typename std::conditional::type; // On Episode 3, place_counts[0] is win count and [1] is loss count /* 00 */ parray place_counts; - /* 08 */ U16T disconnect_count; + /* 08 */ U16T disconnect_count = 0; /* 0A */ parray unknown_a1; /* 10 */ parray unknown_a2; /* 18 */ @@ -429,8 +411,6 @@ struct ChoiceSearchConfig { parray entries; } __attribute__((packed)); -uint32_t compute_guild_card_checksum(const void* data, size_t size); - template DestT convert_player_disp_data(const SrcT&) { static_assert(always_false::v, diff --git a/src/SendCommands.cc b/src/SendCommands.cc index 0389ecd3..964659b3 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -1457,8 +1457,6 @@ static void send_join_spectator_team(shared_ptr c, shared_ptr l) e.level = wc->game_data.ep3_config ? (wc->game_data.ep3_config->online_clv_exp / 100) : wc->game_data.player()->disp.stats.level.load(); - e.unknown_a5.clear(0); - e.unknown_a6.clear(0); player_count++; } @@ -1497,8 +1495,6 @@ static void send_join_spectator_team(shared_ptr c, shared_ptr l) remove_language_marker_inplace(e.name); e.present = 1; e.level = entry.disp.stats.level.load(); - e.unknown_a5.clear(0); - e.unknown_a6.clear(0); player_count++; } @@ -1507,11 +1503,9 @@ static void send_join_spectator_team(shared_ptr c, shared_ptr l) } for (size_t z = 4; z < 12; z++) { - auto& p = cmd.spectator_players[z - 4]; - auto& e = cmd.entries[z]; - e.unknown_a5.clear(0); - e.unknown_a6.clear(0); if (l->clients[z]) { + auto& p = cmd.spectator_players[z - 4]; + auto& e = cmd.entries[z]; p.lobby_data.player_tag = 0x00010000; p.lobby_data.guild_card = l->clients[z]->license->serial_number; p.lobby_data.client_id = l->clients[z]->lobby_client_id; diff --git a/src/Text.hh b/src/Text.hh index 93a9a969..8b859741 100644 --- a/src/Text.hh +++ b/src/Text.hh @@ -190,15 +190,18 @@ struct parray { parray(ItemT v) { this->clear(v); } - template ::value, bool> = true> + template + requires(std::is_arithmetic_v || is_converted_endian_sc_v) parray() { this->clear(0); } - template ::value, bool> = true> + template + requires std::is_pointer_v parray() { this->clear(nullptr); } - template ::value && !std::is_pointer::value, bool> = true> + template + requires(!std::is_arithmetic_v && !std::is_pointer_v && !is_converted_endian_sc_v) parray() {} parray(const parray& other) {