diff --git a/CMakeLists.txt b/CMakeLists.txt index ebaaae253..41373cc6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,7 @@ qt_add_executable(Attorney_Online src/screenslidetimer.h src/screenslidetimer.cpp src/moderation_functions.h src/moderation_functions.cpp src/network/serverinfo.h src/network/serverinfo.cpp + src/packets/msdata.h src/packets/msdata.cpp ) set_target_properties(Attorney_Online PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin") diff --git a/src/animationlayer.cpp b/src/animationlayer.cpp index 42d903916..a0c4d0eb6 100644 --- a/src/animationlayer.cpp +++ b/src/animationlayer.cpp @@ -469,42 +469,33 @@ void CharacterAnimationLayer::loadCharacterEmote(QString character, QString file m_duration = durationLimit; } -void CharacterAnimationLayer::setFrameEffects(QStringList data) +void CharacterAnimationLayer::setFrameEffects(const QList &f_screenshakes, const QList &f_realisations, const QList &f_sfxs) { m_effects.clear(); - static const QList EFFECT_TYPE_LIST{ShakeEffect, FlashEffect, SfxEffect}; - for (int i = 0; i < data.length(); ++i) + foreach (const auto &framedata, f_screenshakes) { - const EffectType effect_type = EFFECT_TYPE_LIST.at(i); - - QStringList emotes = data.at(i).split("^"); - for (const QString &emote : std::as_const(emotes)) - { - QStringList emote_effects = emote.split("|"); - - const QString emote_name = emote_effects.takeFirst(); - - for (const QString &raw_effect : std::as_const(emote_effects)) - { - QStringList frame_data = raw_effect.split("="); - if (frame_data.size() < 2) - { - continue; - } - const int frame_number = frame_data.at(0).toInt(); + FrameEffect effect; + effect.emote_name = framedata.m_emote; + effect.type = ShakeEffect; + m_effects[framedata.m_frame].append(effect); + } - FrameEffect effect; - effect.emote_name = emote_name; - effect.type = effect_type; - if (effect_type == EffectType::SfxEffect) - { - effect.file_name = frame_data.at(1); - } + foreach (const auto &framedata, f_realisations) + { + FrameEffect effect; + effect.emote_name = framedata.m_emote; + effect.type = FlashEffect; + m_effects[framedata.m_frame].append(effect); + } - m_effects[frame_number].append(effect); - } - } + foreach (const auto &framedata, f_sfxs) + { + FrameEffect effect; + effect.emote_name = framedata.m_emote; + effect.type = SfxEffect; + effect.file_name = framedata.m_value; + m_effects[framedata.m_frame].append(effect); } } diff --git a/src/animationlayer.h b/src/animationlayer.h index 79ffcfa68..3f24b1b0f 100644 --- a/src/animationlayer.h +++ b/src/animationlayer.h @@ -2,6 +2,7 @@ #include "animationloader.h" #include "datatypes.h" +#include "packets/msdata.h" #include #include @@ -160,7 +161,7 @@ class CharacterAnimationLayer : public AnimationLayer void loadCharacterEmote(QString character, QString fileName, EmoteType emoteType, int durationLimit = 0); - void setFrameEffects(QStringList data); + void setFrameEffects(const QList &f_screenshakes, const QList &f_realisations, const QList &f_sfxs); Q_SIGNALS: void finishedPreOrPostEmotePlayback(); diff --git a/src/aoapplication.h b/src/aoapplication.h index 5e67fc862..8c5834a65 100644 --- a/src/aoapplication.h +++ b/src/aoapplication.h @@ -4,6 +4,7 @@ #include "datatypes.h" #include "demoserver.h" #include "discord_rich_presence.h" +#include "packets/msdata.h" #include "serverdata.h" #include "widgets/aooptionsdialog.h" @@ -292,10 +293,10 @@ class AOApplication : public QObject int get_sfx_delay(QString p_char, int p_emote); // Returns the modifier for p_char's p_emote - int get_emote_mod(QString p_char, int p_emote); + ms2::EmoteMod get_emote_mod(QString p_char, int p_emote); // Returns the desk modifier for p_char's p_emote - int get_desk_mod(QString p_char, int p_emote); + ms2::DeskMod get_desk_mod(QString p_char, int p_emote); // Returns p_char's blipname by reading char.ini for blips (previously called "gender") QString get_blipname(QString p_char, int p_emote = -1); diff --git a/src/courtroom.cpp b/src/courtroom.cpp index fd6b4c554..bb1cdd1e7 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -4,6 +4,7 @@ #include "moderation_functions.h" #include "options.h" +#include #include // #define DEBUG_TRANSITION @@ -1435,7 +1436,7 @@ void Courtroom::set_background(QString p_background, bool display) // Show it if chatbox always shows if (Options::getInstance().characterStickerEnabled() && chatbox_always_show) { - ui_vp_sticker->loadAndPlayAnimation(m_chatmessage[CHAR_NAME]); + ui_vp_sticker->loadAndPlayAnimation(m_chatmessage.m_char_name); } // Hide the face sticker else @@ -1646,16 +1647,16 @@ void Courtroom::enter_courtroom() switch (objection_state) // no need to reset these as it was done in set_widgets() { - case 1: + case ms2::ObjectionMod::HoldIt: ui_hold_it->setImage("holdit_selected"); break; - case 2: + case ms2::ObjectionMod::Objection: ui_objection->setImage("objection_selected"); break; - case 3: + case ms2::ObjectionMod::TakeThat: ui_take_that->setImage("takethat_selected"); break; - case 4: + case ms2::ObjectionMod::Custom: ui_custom_objection->setImage("custom_selected"); break; default: @@ -1980,292 +1981,238 @@ void Courtroom::on_chat_return_pressed() // self_offset# // immediate_preanim#% - QStringList packet_contents; - // have to fetch this early for a workaround. i hate this system, but i am stuck with it for now - int f_emote_mod = ao_app->get_emote_mod(current_char, current_emote); - - int f_desk_mod = DESK_SHOW; + ms2::OldMSFlatData packet_contents{}; - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::DESKMOD)) { - f_desk_mod = ao_app->get_desk_mod(current_char, current_emote); - {} - if (!ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EXPANDED_DESK_MODS)) + ms2::DeskMod f_desk_mod = ms2::DeskMod::Shown; + + if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::DESKMOD)) { - if (f_desk_mod == DESK_PRE_ONLY_EX || f_desk_mod == DESK_PRE_ONLY) - { - f_desk_mod = DESK_HIDE; - } - else if (f_desk_mod == DESK_EMOTE_ONLY_EX || f_desk_mod == DESK_EMOTE_ONLY) + f_desk_mod = ao_app->get_desk_mod(current_char, current_emote); + {} + if (!ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EXPANDED_DESK_MODS)) { - f_desk_mod = DESK_SHOW; + if (f_desk_mod == ms2::DeskMod::ShownThenHiddenCentre || f_desk_mod == ms2::DeskMod::ShowDuringPreThenHidden) + { + f_desk_mod = ms2::DeskMod::Hidden; + } + else if (f_desk_mod == ms2::DeskMod::HiddenCentreThenShown || f_desk_mod == ms2::DeskMod::HiddenDuringPreThenShown) + { + f_desk_mod = ms2::DeskMod::Shown; + } } } - if (f_desk_mod == -1 && (f_emote_mod == 5 || f_emote_mod == 6)) // workaround for inis that broke after deprecating "chat" - { - f_desk_mod = DESK_HIDE; - } - else if (f_desk_mod == -1) - { - f_desk_mod = DESK_SHOW; - } - } - - packet_contents.append(QString::number(f_desk_mod)); - QString f_pre = ao_app->get_pre_emote(current_char, current_emote); - QString f_sfx = "1"; - int f_sfx_delay = get_char_sfx_delay(); - - // EMOTE MOD OVERRIDES: - // Emote_mod 2 is only used by objection check later, having it in the char.ini does nothing - if (f_emote_mod == 2) - { - f_emote_mod = PREANIM; - } - // No clue what emote_mod 3 is even supposed to be. - if (f_emote_mod == 3) - { - f_emote_mod = IDLE; + packet_contents.m_desk_mod = f_desk_mod; } - // Emote_mod 4 seems to be a legacy bugfix that just refers it to emote_mod 5 which is zoom emote - if (f_emote_mod == 4) - { - f_emote_mod = ZOOM; - } - // If we have "pre" on, and immediate is not checked - if (ui_pre->isChecked() && !ui_immediate->isChecked()) + QString f_sfx{}; + { - // Turn idle into preanim - if (f_emote_mod == IDLE) - { - f_emote_mod = PREANIM; - } - // Turn zoom into preanim zoom - else if (f_emote_mod == ZOOM && ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::PREZOOM)) + ms2::EmoteMod f_emote_mod = ao_app->get_emote_mod(current_char, current_emote); + + if (f_emote_mod == ms2::EmoteMod::PreAndObject) { - f_emote_mod = PREANIM_ZOOM; + // Emote_mod 2 is only used by objection check later, having it in the char.ini does nothing + f_emote_mod = ms2::EmoteMod::Pre; } - // Play the sfx - f_sfx = get_char_sfx(); - } - // If we have "pre" off, or immediate is checked - else - { - // Turn preanim into idle - if (f_emote_mod == PREANIM) + + if (ui_pre->isChecked() && !ui_immediate->isChecked()) { - f_emote_mod = IDLE; + // Turn idle into preanim + if (f_emote_mod == ms2::EmoteMod::Idle) + { + f_emote_mod = ms2::EmoteMod::Pre; + } + // Turn zoom into preanim zoom + else if (f_emote_mod == ms2::EmoteMod::Zoom && ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::PREZOOM)) + { + f_emote_mod = ms2::EmoteMod::PreZoom; + } + // Play the sfx + f_sfx = get_char_sfx(); } - // Turn preanim zoom into zoom - else if (f_emote_mod == PREANIM_ZOOM) + // If we have "pre" off, or immediate is checked + else { - f_emote_mod = ZOOM; - } + // Turn preanim into idle + if (f_emote_mod == ms2::EmoteMod::Pre) + { + f_emote_mod = ms2::EmoteMod::Idle; + } + // Turn preanim zoom into zoom + else if (f_emote_mod == ms2::EmoteMod::PreZoom) + { + f_emote_mod = ms2::EmoteMod::Zoom; + } - // Play the sfx if pre is checked - if (ui_pre->isChecked()) - { - f_sfx = get_char_sfx(); + // Play the sfx if pre is checked + if (ui_pre->isChecked()) + { + f_sfx = get_char_sfx(); + } } + + packet_contents.m_emote_mod = f_emote_mod; } + packet_contents.m_sfx_delay = get_char_sfx_delay(); + packet_contents.m_preanim = ao_app->get_pre_emote(current_char, current_emote); + // Custom sfx override via sound list dropdown. if (!custom_sfx.isEmpty() || ui_sfx_dropdown->currentIndex() != 0) { f_sfx = get_char_sfx(); // We have a custom sfx but we're on idle emotes. // Turn them into pre so the sound plays if client setting sfx_on_idle is enabled. - if (Options::getInstance().playSelectedSFXOnIdle() && (f_emote_mod == IDLE || f_emote_mod == ZOOM)) + if (Options::getInstance().playSelectedSFXOnIdle() && (packet_contents.m_emote_mod == ms2::EmoteMod::Idle || packet_contents.m_emote_mod == ms2::EmoteMod::Zoom)) { // We turn idle into preanim, but make it not send a pre animation - f_pre = ""; + packet_contents.m_preanim = ""; // Set sfx delay to 0 so the sfx plays immediately - f_sfx_delay = 0; + packet_contents.m_sfx_delay = 0; // Set the emote mod to preanim so the sound plays - f_emote_mod = f_emote_mod == IDLE ? PREANIM : PREANIM_ZOOM; + packet_contents.m_emote_mod = packet_contents.m_emote_mod == ms2::EmoteMod::Idle ? ms2::EmoteMod::Pre : ms2::EmoteMod::PreZoom; } } - packet_contents.append(f_pre); - - packet_contents.append(current_char); - - packet_contents.append(ao_app->get_emote(current_char, current_emote)); - - packet_contents.append(ui_ic_chat_message->text()); - - packet_contents.append(current_or_default_side()); - - packet_contents.append(f_sfx); - packet_contents.append(QString::number(f_emote_mod)); - packet_contents.append(QString::number(m_cid)); + packet_contents.m_char_name = current_char; + packet_contents.m_emote = ao_app->get_emote(current_char, current_emote); + packet_contents.m_message_text = ui_ic_chat_message->text(); + packet_contents.m_side = current_or_default_side(); + packet_contents.m_sfx_name = f_sfx; + packet_contents.m_char_id = m_cid; - packet_contents.append(QString::number(f_sfx_delay)); - - QString f_obj_state; - - if ((objection_state == 4 && !ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CUSTOMOBJECTIONS)) || (objection_state < 0)) - { - f_obj_state = "0"; - } - else if (objection_custom != "" && objection_state == 4) + if (objection_state == ms2::ObjectionMod::Custom && !ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CUSTOMOBJECTIONS)) { - f_obj_state = QString::number(objection_state) + "&" + objection_custom; // we add the name of the objection so the - // packet is like: 4&(name of custom obj) + packet_contents.m_objection_mod = ms2::ObjectionMod::None; } else { - f_obj_state = QString::number(objection_state); + packet_contents.m_objection_mod = objection_state; + packet_contents.m_objection_custom = objection_custom; } // We're doing an Objection (custom objections not yet supported) - if (objection_state == 2 && Options::getInstance().objectionStopMusic()) + if (objection_state == ms2::ObjectionMod::Objection && Options::getInstance().objectionStopMusic()) { music_stop(true); } - packet_contents.append(f_obj_state); - if (is_presenting_evidence) { // the evidence index is shifted by 1 because 0 is no evidence per legacy // standards besides, older clients crash if we pass -1 - packet_contents.append(QString::number(current_evidence + 1)); + packet_contents.m_evidence = current_evidence + 1; } else { - packet_contents.append("0"); + packet_contents.m_evidence = 0; } - QString f_flip; + packet_contents.m_flip = ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::FLIPPING) && ui_flip->isChecked(); + packet_contents.m_realisation = realization_state > 0; - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::FLIPPING)) + if (text_color < 0) { - if (ui_flip->isChecked()) - { - f_flip = "1"; - } - else - { - f_flip = "0"; - } + packet_contents.m_text_colour = 0; + } + else if (text_color >= max_colors) + { + packet_contents.m_text_colour = 0; } else { - f_flip = QString::number(m_cid); + packet_contents.m_text_colour = text_color; } - packet_contents.append(f_flip); - - packet_contents.append(QString::number(realization_state)); - - QString f_text_color; - - if (text_color < 0) + // If there is a showname entered, use that -- else, just send an empty + // packet-part. + if (!ui_ic_chat_name->text().isEmpty()) { - f_text_color = "0"; + packet_contents.m_showname = ui_ic_chat_name->text(); } - else if (text_color >= max_colors) + else { - f_text_color = "0"; + packet_contents.m_showname = ao_app->get_showname(current_char, current_emote); } - else + + if (other_charid > -1 && other_charid != m_cid) { - f_text_color = QString::number(text_color); + packet_contents.m_other = ms2::OtherData{other_charid, + "-", // Doesn't matter from client's side. + "-", // Doesn't matter from client's side. + {0, 0}, // Doesn't matter from client's side. + false, // Doesn't matter from client's side. + pair_order > 0}; } - packet_contents.append(f_text_color); + packet_contents.m_offset = {char_offset, char_vert_offset}; + packet_contents.m_sfx_looping = !ao_app->get_sfx_looping(current_char, current_emote).compare("0"); + packet_contents.m_screenshake = screenshake_state > 0; + packet_contents.m_immediate = ui_immediate->isChecked() && ui_pre->isChecked(); - // If the server we're on supports CCCC stuff, we should use it! - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CCCC_IC_SUPPORT)) + if (Options::getInstance().networkedFrameSfxEnabled()) { - // If there is a showname entered, use that -- else, just send an empty - // packet-part. - if (!ui_ic_chat_name->text().isEmpty()) - { - packet_contents.append(ui_ic_chat_name->text()); - } - else - { - packet_contents.append(ao_app->get_showname(current_char, current_emote)); - } + QStringList emotes_to_check = {packet_contents.m_preanim, "(b)" + packet_contents.m_emote, "(a)" + packet_contents.m_emote}; - // Similarly, we send over whom we're paired with, unless we have chosen - // ourselves. Or a charid of -1 or lower, through some means. - if (other_charid > -1 && other_charid != m_cid) + // Screenshake + foreach (QString f_emote, emotes_to_check) { - QString packet = QString::number(other_charid); - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EFFECTS)) // Only servers with effects - // enabled will support pair - // reordering + ms2::FrameData l_frameEffect; + l_frameEffect.m_emote = f_emote; + + QStringList l_in = ao_app->read_ini_tags(ao_app->get_character_path(current_char, "char.ini"), f_emote.append("_FrameScreenshake")); + foreach (const auto &l_frameData, l_in) { - packet += "^" + QString::number(pair_order); + const auto &l_separated = l_frameData.split("="); + if (l_separated.length() > 1 && !l_separated.at(0).isEmpty()) + { + l_frameEffect.m_frame = l_separated.at(0).toInt(); + packet_contents.m_frames_shake.append(l_frameEffect); + } } - packet_contents.append(packet); - } - else - { - packet_contents.append("-1"); - } - // Send the offset as it's gonna be used regardless - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::Y_OFFSET)) - { - packet_contents.append(QString::number(char_offset) + "&" + QString::number(char_vert_offset)); - } - else - { - packet_contents.append(QString::number(char_offset)); } - // Finally, we send over if we want our pres to not interrupt. - if (ui_immediate->isChecked() && ui_pre->isChecked()) + // Realisation + foreach (QString f_emote, emotes_to_check) { - packet_contents.append("1"); - } - else - { - packet_contents.append("0"); - } - } - - // If the server we're on supports Looping SFX and Screenshake, use it if the - // emote uses it. - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::LOOPING_SFX)) - { - packet_contents.append(ao_app->get_sfx_looping(current_char, current_emote)); - packet_contents.append(QString::number(screenshake_state)); + ms2::FrameData l_frameEffect; + l_frameEffect.m_emote = f_emote; - QString pre_emote = ao_app->get_pre_emote(current_char, current_emote); - QString emote = ao_app->get_emote(current_char, current_emote); - QStringList emotes_to_check = {pre_emote, "(b)" + emote, "(a)" + emote}; - QStringList effects_to_check = {"_FrameScreenshake", "_FrameRealization", "_FrameSFX"}; + QStringList l_in = ao_app->read_ini_tags(ao_app->get_character_path(current_char, "char.ini"), f_emote.append("_FrameRealization")); + foreach (const auto &l_frameData, l_in) + { + const auto &l_separated = l_frameData.split("="); + if (l_separated.length() > 1 && !l_separated.at(0).isEmpty()) + { + l_frameEffect.m_frame = l_separated.at(0).toInt(); + packet_contents.m_frames_realisation.append(l_frameEffect); + } + } + } - foreach (QString f_effect, effects_to_check) + // SFX + foreach (QString f_emote, emotes_to_check) { - QString packet; - foreach (QString f_emote, emotes_to_check) + ms2::FrameData l_frameEffect; + l_frameEffect.m_emote = f_emote; + + QStringList l_in = ao_app->read_ini_tags(ao_app->get_character_path(current_char, "char.ini"), f_emote.append("_FrameSFX")); + foreach (const auto &l_frameData, l_in) { - packet += f_emote; - if (Options::getInstance().networkedFrameSfxEnabled()) + const auto &l_separated = l_frameData.split("="); + if (l_separated.length() == 2 && !l_separated.at(1).isEmpty()) { - QString sfx_frames = ao_app->read_ini_tags(ao_app->get_character_path(current_char, "char.ini"), f_emote.append(f_effect)).join("|"); - if (sfx_frames != "") - { - packet += "|" + sfx_frames; - } + l_frameEffect.m_frame = l_separated.at(0).toInt(); + l_frameEffect.m_value = l_separated.at(1); + packet_contents.m_frames_sfx.append(l_frameEffect); } - packet += "^"; } - packet_contents.append(packet); } } - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::ADDITIVE)) - { - packet_contents.append(ui_additive->isChecked() ? "1" : "0"); - } - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::EFFECTS)) + packet_contents.m_additive = ui_additive->isChecked(); + { QString p_effect_folder = ao_app->read_char_ini(current_char, "effects", "Options"); QString fx_sound = ao_app->get_effect_property(effect, current_char, p_effect_folder, "sound"); @@ -2273,20 +2220,17 @@ void Courtroom::on_chat_return_pressed() // Don't overlap the two sfx if (!ui_pre->isChecked() && (!custom_sfx.isEmpty() || ui_sfx_dropdown->currentIndex() == 1)) { - fx_sound = "0"; + fx_sound = {}; } - packet_contents.append(effect + "|" + p_effect_folder + "|" + fx_sound); + packet_contents.m_effect = ms2::EffectData{effect, fx_sound, p_effect_folder}; } - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CUSTOM_BLIPS)) - { - packet_contents.append(ao_app->get_blipname(current_char, current_emote)); + packet_contents.m_blips = ao_app->get_blipname(current_char, current_emote); + packet_contents.m_slide = ui_slide_enable->isChecked(); // just let the server figure out what to do with this - packet_contents.append(ui_slide_enable->isChecked() ? "1" : "0"); // just let the server figure out what to do with this - } - - ao_app->send_server_packet(AOPacket("MS", packet_contents)); + const auto l_message = QJsonDocument{packet_contents.toJson()}.toJson(QJsonDocument::Compact); + ao_app->send_server_packet(AOPacket("MS", {l_message})); } void Courtroom::reset_ui() @@ -2296,7 +2240,7 @@ void Courtroom::reset_ui() { ui_ic_chat_message->insert(" "); } - objection_state = 0; + objection_state = ms2::ObjectionMod::None; realization_state = 0; screenshake_state = 0; is_presenting_evidence = false; @@ -2335,47 +2279,38 @@ void Courtroom::reset_ui() ui_slide_enable->setChecked(false); } -void Courtroom::chatmessage_enqueue(QStringList p_contents) +void Courtroom::chatmessage_enqueue(const QStringList &p_contents) { - // Instead of checking for whether a message has at least chatmessage_size - // amount of packages, we'll check if it has at least 15. - // That was the original chatmessage_size. - if (p_contents.size() < MS_MINIMUM) + ms2::OldMSFlatData l_incomingMessage; + const QJsonDocument l_jsonData = QJsonDocument::fromJson(p_contents.at(0).toUtf8()); + if (!ms2::OldMSFlatData::fromJson(l_jsonData.object(), l_incomingMessage)) { return; } // Check the validity of the character ID we got - int f_char_id = p_contents[CHAR_ID].toInt(); - if (f_char_id < -1 || f_char_id >= char_list.size()) + if (l_incomingMessage.m_char_id < -1 || l_incomingMessage.m_char_id >= char_list.size()) { return; } // We muted this char, gtfo - if (mute_map.value(f_char_id)) + if (mute_map.value(l_incomingMessage.m_char_id)) { return; } - // Use null showname if packet does not support 2.6+ extensions - QString showname = QString(); - if (SHOWNAME < p_contents.size()) - { - showname = p_contents[SHOWNAME]; - } - // if the char ID matches our client's char ID (most likely, this is our message coming back to us) - bool sender = f_char_id == m_cid; + bool sender = l_incomingMessage.m_char_id == m_cid; // Record the log I/O, log files should be accurate. LogMode log_mode = IO_ONLY; // User-created blankpost - if (p_contents[MESSAGE].trimmed().isEmpty()) + if (l_incomingMessage.m_message_text.trimmed().isEmpty()) { // Turn it into true blankpost - p_contents[MESSAGE] = ""; + l_incomingMessage.m_message_text = ""; } // If we determine we sent this message @@ -2388,15 +2323,14 @@ void Courtroom::chatmessage_enqueue(QStringList p_contents) if (sender || Options::getInstance().desynchronisedLogsEnabled()) { // Initialize operation "message queue ghost" - log_chatmessage(p_contents[MESSAGE], f_char_id, p_contents[SHOWNAME], p_contents[CHAR_NAME], p_contents[OBJECTION_MOD], p_contents[EVIDENCE_ID].toInt(), p_contents[TEXT_COLOR].toInt(), QUEUED, sender || Options::getInstance().desynchronisedLogsEnabled()); + log_chatmessage(l_incomingMessage, QUEUED, sender || Options::getInstance().desynchronisedLogsEnabled()); } bool is_objection = false; // If the user wants to clear queue on objection if (Options::getInstance().objectionSkipQueueEnabled()) { - int objection_mod = p_contents[OBJECTION_MOD].split("&")[0].toInt(); - is_objection = objection_mod >= 1 && objection_mod <= 5; + is_objection = l_incomingMessage.m_objection_mod != ms2::ObjectionMod::None; // If this is an objection, nuke the queue if (is_objection) { @@ -2405,10 +2339,10 @@ void Courtroom::chatmessage_enqueue(QStringList p_contents) } } // Log the IO file - log_chatmessage(p_contents[MESSAGE], f_char_id, p_contents[SHOWNAME], p_contents[CHAR_NAME], p_contents[OBJECTION_MOD], p_contents[EVIDENCE_ID].toInt(), p_contents[TEXT_COLOR].toInt(), log_mode, sender); + log_chatmessage(l_incomingMessage, log_mode, sender); // Send this boi into the queue - chatmessage_queue.enqueue(p_contents); + chatmessage_queue.enqueue(l_incomingMessage); // Our settings disabled queue, or no message is being parsed right now and we're not waiting on one bool start_queue = Options::getInstance().textStayTime() <= 0 || (text_state >= 2 && !text_queue_timer->isActive()); @@ -2441,42 +2375,26 @@ void Courtroom::skip_chatmessage_queue() { while (!chatmessage_queue.isEmpty()) { - QStringList p_contents = chatmessage_queue.dequeue(); + const auto p_contents = chatmessage_queue.dequeue(); // if the char ID matches our client's char ID (most likely, this is our message coming back to us) - bool sender = Options::getInstance().desynchronisedLogsEnabled() || p_contents[CHAR_ID].toInt() == m_cid; - log_chatmessage(p_contents[MESSAGE], p_contents[CHAR_ID].toInt(), p_contents[SHOWNAME], p_contents[CHAR_NAME], p_contents[OBJECTION_MOD], p_contents[EVIDENCE_ID].toInt(), p_contents[TEXT_COLOR].toInt(), DISPLAY_ONLY, sender); + bool sender = Options::getInstance().desynchronisedLogsEnabled() || p_contents.m_char_id == m_cid; + log_chatmessage(p_contents, DISPLAY_ONLY, sender); } } -void Courtroom::unpack_chatmessage(QStringList p_contents) +void Courtroom::unpack_chatmessage(const ms2::OldMSFlatData &f_message) { - for (int n_string = 0; n_string < MS_MAXIMUM; ++n_string) - { - m_previous_chatmessage[n_string] = m_chatmessage[n_string]; - - // Note that we have added stuff that vanilla clients and servers simply - // won't send. So now, we have to check if the thing we want even exists - // amongst the packet's content. We also have to check if the server even - // supports CCCC's IC features, or if it's just japing us. Also, don't - // forget! A size 15 message will have indices from 0 to 14. - if (n_string < p_contents.size() && (n_string < MS_MINIMUM || ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CCCC_IC_SUPPORT))) - { - m_chatmessage[n_string] = p_contents.at(n_string); - } - else - { - m_chatmessage[n_string] = ""; - } - } - // if the char ID matches our client's char ID (most likely, this is our message coming back to us) - bool sender = Options::getInstance().desynchronisedLogsEnabled() || m_chatmessage[CHAR_ID].toInt() == m_cid; + bool sender = Options::getInstance().desynchronisedLogsEnabled() || f_message.m_char_id == m_cid; // We have logs displaying as soon as we reach the message in our queue, which is a less confusing but also less accurate experience for the user. - log_chatmessage(m_chatmessage[MESSAGE], m_chatmessage[CHAR_ID].toInt(), p_contents[SHOWNAME], m_chatmessage[CHAR_NAME], m_chatmessage[OBJECTION_MOD], m_chatmessage[EVIDENCE_ID].toInt(), m_chatmessage[TEXT_COLOR].toInt(), DISPLAY_ONLY, sender); + log_chatmessage(f_message, DISPLAY_ONLY, sender); // Process the callwords for this message - handle_callwords(); + handle_callwords(f_message.m_message_text); + + m_previous_chatmessage = m_chatmessage; + m_chatmessage = f_message; // Reset the interface to make room for objection handling ui_vp_chat_arrow->hide(); @@ -2494,101 +2412,91 @@ void Courtroom::unpack_chatmessage(QStringList p_contents) } } -void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_showname, QString f_char, QString f_objection_mod, int f_evi_id, int f_color, LogMode f_log_mode, bool sender) +void Courtroom::log_chatmessage(const ms2::OldMSFlatData &f_message, LogMode f_log_mode, bool sender) { - // Display name will use the showname - QString f_displayname = f_showname; - if (f_char_id != -1) - { - // Grab the char.ini showname - f_showname = ao_app->get_showname(char_list.at(f_char_id).name); - } - // If display name is just whitespace, use the char.ini showname. - if (f_displayname.trimmed().isEmpty()) - { - f_displayname = f_showname; - } + const QString l_displayedName = f_message.m_showname.isEmpty() ? f_message.m_char_name : f_message.m_showname; bool ghost = f_log_mode == QUEUED; // Detect if we're trying to log a blankpost - bool blankpost = (f_log_mode != IO_ONLY && // if we're not in I/O only mode, - f_message.isEmpty() && // our current message is a blankpost, - !ic_chatlog_history.isEmpty() && // the chat log isn't empty, - last_ic_message == f_displayname + ":" && // the chat log's last message is a blank post, and - last_ic_message.mid(0, last_ic_message.lastIndexOf(":")) == f_displayname); // the blankpost's showname is the same as ours - bool selfname = f_char_id == m_cid; + bool blankpost = (f_log_mode != IO_ONLY && // if we're not in I/O only mode, + f_message.m_message_text.isEmpty() && // our current message is a blankpost, + !ic_chatlog_history.isEmpty() && // the chat log isn't empty, + last_ic_message == l_displayedName + ":" && // the chat log's last message is a blank post, and + last_ic_message.mid(0, last_ic_message.lastIndexOf(":")) == l_displayedName); // the blankpost's showname is the same as ours + bool selfname = f_message.m_char_id == m_cid; if (log_ic_actions) { - // Check if a custom objection is in use - int objection_mod = 0; - QString custom_objection; - if (f_objection_mod.contains("4&")) - { - objection_mod = 4; - custom_objection = f_objection_mod.split("4&")[1]; // takes the name of custom objection. - } - else - { - objection_mod = f_objection_mod.toInt(); - } - // QString f_custom_theme = ao_app->get_chat(f_char); - if (objection_mod <= 4 && objection_mod >= 1) + if (f_message.m_objection_mod != ms2::ObjectionMod::None) { blankpost = false; QString shout_message; - switch (objection_mod) + + switch (f_message.m_objection_mod) + { + case ms2::ObjectionMod::HoldIt: { - case 1: - shout_message = ao_app->read_char_ini(f_char, "holdit_message", "Shouts"); - if (shout_message == "") + shout_message = ao_app->read_char_ini(f_message.m_char_name, "holdit_message", "Shouts"); + if (shout_message.isEmpty()) { shout_message = tr("HOLD IT!"); } break; - case 2: - shout_message = ao_app->read_char_ini(f_char, "objection_message", "Shouts"); - if (shout_message == "") + } + case ms2::ObjectionMod::Objection: + { + shout_message = ao_app->read_char_ini(f_message.m_char_name, "objection_message", "Shouts"); + if (shout_message.isEmpty()) { shout_message = tr("OBJECTION!"); } break; - case 3: - shout_message = ao_app->read_char_ini(f_char, "takethat_message", "Shouts"); - if (shout_message == "") + } + case ms2::ObjectionMod::TakeThat: + { + shout_message = ao_app->read_char_ini(f_message.m_char_name, "takethat_message", "Shouts"); + if (shout_message.isEmpty()) { shout_message = tr("TAKE THAT!"); } break; - // case 4 is AO2 only - case 4: - if (custom_objection != "") + } + case ms2::ObjectionMod::Custom: + { + if (!f_message.m_objection_custom.isEmpty()) { - shout_message = ao_app->read_char_ini(f_char, custom_objection.split('.')[0] + "_message", "Shouts"); - if (shout_message == "") + shout_message = ao_app->read_char_ini(f_message.m_char_name, f_message.m_objection_custom.split('.')[0] + "_message", "Shouts"); + if (shout_message.isEmpty()) { - shout_message = custom_objection.split('.')[0]; + shout_message = f_message.m_objection_custom.split('.')[0]; } } else { - shout_message = ao_app->read_char_ini(f_char, "custom_message", "Shouts"); - if (shout_message == "") + shout_message = ao_app->read_char_ini(f_message.m_char_name, "custom_message", "Shouts"); + if (shout_message.isEmpty()) { shout_message = tr("CUSTOM OBJECTION!"); } } break; } + default: + { + // Should never happen, as custom shouts are to be done with ObjectionMod::Custom, buuut just in case. + shout_message = "???"; + } + } + switch (f_log_mode) { case IO_ONLY: - log_ic_text(f_char, f_displayname, shout_message, tr("shouts"), 0, selfname); + log_ic_text(f_message.m_char_name, l_displayedName, shout_message, tr("shouts"), 0, selfname); break; case DISPLAY_AND_IO: - log_ic_text(f_char, f_displayname, shout_message, tr("shouts")); - append_ic_text(shout_message, f_displayname, f_char, tr("shouts"), 0, selfname, QDateTime::currentDateTime(), false); + log_ic_text(f_message.m_char_name, l_displayedName, shout_message, tr("shouts")); + append_ic_text(shout_message, l_displayedName, f_message.m_char_name, tr("shouts"), 0, selfname, QDateTime::currentDateTime(), false); break; case DISPLAY_ONLY: case QUEUED: @@ -2596,25 +2504,25 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show { pop_ic_ghost(); } - append_ic_text(shout_message, f_displayname, f_char, tr("shouts"), 0, selfname, QDateTime::currentDateTime(), ghost); + append_ic_text(shout_message, l_displayedName, f_message.m_char_name, tr("shouts"), 0, selfname, QDateTime::currentDateTime(), ghost); break; } } // If the evidence ID is in the valid range - if (f_evi_id > 0 && f_evi_id <= global_evidence_list.size()) + if (f_message.m_evidence > 0 && f_message.m_evidence <= global_evidence_list.size()) { blankpost = false; // Obtain the evidence name - QString f_evi_name = global_evidence_list.at(f_evi_id - 1).name; + QString f_evi_name = global_evidence_list.at(f_message.m_evidence - 1).name; switch (f_log_mode) { case IO_ONLY: - log_ic_text(f_char, f_displayname, f_evi_name, tr("has presented evidence"), 0, selfname); + log_ic_text(f_message.m_char_name, l_displayedName, f_evi_name, tr("has presented evidence"), 0, selfname); break; case DISPLAY_AND_IO: - log_ic_text(f_char, f_displayname, f_evi_name, tr("has presented evidence")); - append_ic_text(f_evi_name, f_displayname, f_char, tr("has presented evidence"), 0, selfname, QDateTime::currentDateTime(), false); + log_ic_text(f_message.m_char_name, l_displayedName, f_evi_name, tr("has presented evidence")); + append_ic_text(f_evi_name, l_displayedName, f_message.m_char_name, tr("has presented evidence"), 0, selfname, QDateTime::currentDateTime(), false); break; case DISPLAY_ONLY: case QUEUED: @@ -2622,7 +2530,7 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show { pop_ic_ghost(); } - append_ic_text(f_evi_name, f_displayname, f_char, tr("has presented evidence"), 0, selfname, QDateTime::currentDateTime(), ghost); + append_ic_text(f_evi_name, l_displayedName, f_message.m_char_name, tr("has presented evidence"), 0, selfname, QDateTime::currentDateTime(), ghost); break; } } @@ -2642,11 +2550,11 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show switch (f_log_mode) { case IO_ONLY: - log_ic_text(f_char, f_displayname, f_message, "", f_color, selfname); + log_ic_text(f_message.m_char_name, l_displayedName, f_message.m_message_text, "", f_message.m_text_colour, selfname); break; case DISPLAY_AND_IO: - log_ic_text(f_char, f_displayname, f_message, "", f_color, selfname); - append_ic_text(f_message, f_displayname, f_char, "", f_color, selfname, QDateTime::currentDateTime(), false); + log_ic_text(f_message.m_char_name, l_displayedName, f_message.m_message_text, "", f_message.m_text_colour, selfname); + append_ic_text(f_message.m_message_text, l_displayedName, f_message.m_char_name, "", f_message.m_text_colour, selfname, QDateTime::currentDateTime(), false); break; case DISPLAY_ONLY: case QUEUED: @@ -2654,28 +2562,15 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show { pop_ic_ghost(); } - append_ic_text(f_message, f_displayname, f_char, "", f_color, selfname, QDateTime::currentDateTime(), ghost); + append_ic_text(f_message.m_message_text, l_displayedName, f_message.m_char_name, "", f_message.m_text_colour, selfname, QDateTime::currentDateTime(), ghost); break; } } bool Courtroom::handle_objection() { - // Check if a custom objection is in use - int objection_mod = 0; - QString custom_objection; - if (m_chatmessage[OBJECTION_MOD].contains("4&")) - { - objection_mod = 4; - custom_objection = m_chatmessage[OBJECTION_MOD].split("4&")[1]; // takes the name of custom objection. - } - else - { - objection_mod = m_chatmessage[OBJECTION_MOD].toInt(); - } - // if an objection is used - if (objection_mod <= 4 && objection_mod >= 1) + if (m_chatmessage.m_objection_mod != ms2::ObjectionMod::None) { ui_vp_chatbox->setVisible(chatbox_always_show); ui_vp_message->setVisible(chatbox_always_show); @@ -2683,41 +2578,55 @@ bool Courtroom::handle_objection() ui_vp_showname->setVisible(chatbox_always_show); ui_vp_objection->setMaximumDurationPerFrame(shout_max_time); QString filename; - switch (objection_mod) + + switch (m_chatmessage.m_objection_mod) + { + case ms2::ObjectionMod::None: + { + // Literally only here to stop clang from bitching. + break; + } + case ms2::ObjectionMod::HoldIt: { - case 1: filename = "holdit_bubble"; - objection_player->findAndPlayCharacterShout("holdit", m_chatmessage[CHAR_NAME], ao_app->get_chat(m_chatmessage[CHAR_NAME])); + objection_player->findAndPlayCharacterShout("holdit", m_chatmessage.m_char_name, ao_app->get_chat(m_chatmessage.m_char_name)); break; - case 2: + } + case ms2::ObjectionMod::Objection: + { filename = "objection_bubble"; - objection_player->findAndPlayCharacterShout("objection", m_chatmessage[CHAR_NAME], ao_app->get_chat(m_chatmessage[CHAR_NAME])); + objection_player->findAndPlayCharacterShout("objection", m_chatmessage.m_char_name, ao_app->get_chat(m_chatmessage.m_char_name)); break; - case 3: + } + case ms2::ObjectionMod::TakeThat: + { filename = "takethat_bubble"; - objection_player->findAndPlayCharacterShout("takethat", m_chatmessage[CHAR_NAME], ao_app->get_chat(m_chatmessage[CHAR_NAME])); + objection_player->findAndPlayCharacterShout("takethat", m_chatmessage.m_char_name, ao_app->get_chat(m_chatmessage.m_char_name)); break; - // case 4 is AO2 only - case 4: - if (custom_objection != "") + } + case ms2::ObjectionMod::Custom: + { + if (!m_chatmessage.m_objection_custom.isEmpty()) { - filename = "custom_objections/" + custom_objection.left(custom_objection.lastIndexOf(".")); - objection_player->findAndPlayCharacterShout(filename, m_chatmessage[CHAR_NAME], ao_app->get_chat(m_chatmessage[CHAR_NAME])); + filename = "custom_objections/" + m_chatmessage.m_objection_custom.left(m_chatmessage.m_objection_custom.lastIndexOf(".")); + objection_player->findAndPlayCharacterShout(filename, m_chatmessage.m_char_name, ao_app->get_chat(m_chatmessage.m_char_name)); } else { filename = "custom"; - objection_player->findAndPlayCharacterShout("custom", m_chatmessage[CHAR_NAME], ao_app->get_chat(m_chatmessage[CHAR_NAME])); + objection_player->findAndPlayCharacterShout("custom", m_chatmessage.m_char_name, ao_app->get_chat(m_chatmessage.m_char_name)); } break; - m_chatmessage[EMOTE_MOD] = QChar(PREANIM); + m_chatmessage.m_emote_mod = ms2::EmoteMod::Pre; + } } - ui_vp_objection->loadAndPlayAnimation(filename, m_chatmessage[CHAR_NAME], ao_app->get_chat(m_chatmessage[CHAR_NAME])); + + ui_vp_objection->loadAndPlayAnimation(filename, m_chatmessage.m_char_name, ao_app->get_chat(m_chatmessage.m_char_name)); sfx_player->stopAll(); // Objection played! Cut all sfx. ui_vp_player_char->setPlayOnce(true); return true; } - if (m_chatmessage[EMOTE] != "") + if (!m_chatmessage.m_emote.isEmpty()) { display_character(); } @@ -2739,7 +2648,7 @@ void Courtroom::display_character() // Show it if chatbox always shows if (Options::getInstance().characterStickerEnabled() && chatbox_always_show) { - ui_vp_sticker->loadAndPlayAnimation(m_chatmessage[CHAR_NAME]); + ui_vp_sticker->loadAndPlayAnimation(m_chatmessage.m_char_name); } // Hide the face sticker else @@ -2748,126 +2657,65 @@ void Courtroom::display_character() } // Arrange the netstrings of the frame SFX for the character to know about - if (!m_chatmessage[FRAME_SFX].isEmpty() && Options::getInstance().networkedFrameSfxEnabled()) + if (!m_chatmessage.m_frames_sfx.isEmpty() && Options::getInstance().networkedFrameSfxEnabled()) { // ORDER IS IMPORTANT!! - QStringList netstrings = {m_chatmessage[FRAME_SCREENSHAKE], m_chatmessage[FRAME_REALIZATION], m_chatmessage[FRAME_SFX]}; - ui_vp_player_char->setFrameEffects(netstrings); + ui_vp_player_char->setFrameEffects(m_chatmessage.m_frames_shake, m_chatmessage.m_frames_realisation, m_chatmessage.m_frames_sfx); } else { - ui_vp_player_char->setFrameEffects(QStringList()); + ui_vp_player_char->setFrameEffects({}, {}, {}); } // Determine if we should flip the character or not - ui_vp_player_char->setFlipped(m_chatmessage[FLIP].toInt() == 1); + ui_vp_player_char->setFlipped(m_chatmessage.m_flip); } -void Courtroom::display_pair_character(QString other_charid, QString other_offset) +void Courtroom::display_pair_character(const ms2::OtherData &f_other) { - // If pair information exists - if (!other_charid.isEmpty()) - { - // Initialize the "ok" bool check to see if the toInt conversion succeeded - bool ok; - // Grab the charid of the pair - int charid = other_charid.split("^")[0].toInt(&ok); - // If the charid is an int and is valid... - if (ok && charid > -1) - { - // Show the pair character - ui_vp_sideplayer_char->show(); - // Obtain the offsets, splitting it up by & char - QStringList offsets = other_offset.split("&"); - int offset_x; - int offset_y; - // If we only got one number... - if (offsets.length() <= 1) - { - // That's just the X offset. Make Y offset 0. - offset_x = other_offset.toInt(); - offset_y = 0; - } - else - { - // We got two numbers, set x and y offsets! - offset_x = offsets[0].toInt(); - offset_y = offsets[1].toInt(); - } - // Move pair character according to the offsets - ui_vp_sideplayer_char->move(ui_viewport->width() * offset_x / 100, ui_viewport->height() * offset_y / 100); - // Split the charid according to the ^ to determine if we have "ordering" info - QStringList args = other_charid.split("^"); - if (args.size() > 1) // This ugly workaround is so we don't make an extra packet just - // for this purpose. Rewrite pairing when? - { - // Change the order of appearance based on the pair order variable - int order = args.at(1).toInt(); - switch (order) - { - case 0: // Our character is in front - ui_vp_sideplayer_char->stackUnder(ui_vp_player_char); - break; - case 1: // Our character is behind - ui_vp_player_char->stackUnder(ui_vp_sideplayer_char); - break; - default: - break; - } - } + if (f_other.m_charid == -1) + return; - // Play the other pair character's idle animation - ui_vp_sideplayer_char->loadCharacterEmote(m_chatmessage[OTHER_NAME], m_chatmessage[OTHER_EMOTE], kal::CharacterAnimationLayer::IdleEmote); - ui_vp_sideplayer_char->show(); - ui_vp_sideplayer_char->setPlayOnce(false); + // Show the pair character + ui_vp_sideplayer_char->show(); + // Move pair character according to the offsets + ui_vp_sideplayer_char->move(ui_viewport->width() * f_other.m_offset.x / 100, ui_viewport->height() * f_other.m_offset.y / 100); - // Flip the pair character - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::FLIPPING) && m_chatmessage[OTHER_FLIP].toInt() == 1) - { - ui_vp_sideplayer_char->setFlipped(true); - } - else - { - ui_vp_sideplayer_char->setFlipped(false); - } + if (!f_other.m_under) + ui_vp_sideplayer_char->stackUnder(ui_vp_player_char); + else + ui_vp_player_char->stackUnder(ui_vp_sideplayer_char); - ui_vp_sideplayer_char->startPlayback(); - } - } -} + // Play the other pair character's idle animation + ui_vp_sideplayer_char->loadCharacterEmote(f_other.m_name, f_other.m_emote, kal::CharacterAnimationLayer::IdleEmote); + ui_vp_sideplayer_char->show(); + ui_vp_sideplayer_char->setPlayOnce(false); -void Courtroom::handle_emote_mod(int emote_mod, bool p_immediate) -{ - // Deal with invalid emote modifiers - if (emote_mod != IDLE && emote_mod != PREANIM && emote_mod != ZOOM && emote_mod != PREANIM_ZOOM) + // Flip the pair character + if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::FLIPPING) && f_other.m_flip) { - // If emote mod is 4... - if (emote_mod == 4) - { - emote_mod = PREANIM_ZOOM; // Addresses issue with an old bug that sent the wrong - // emote modifier for zoompre - } - else if (emote_mod == 2) - { - // Addresses the deprecated "objection preanim" - emote_mod = PREANIM; - } - else - { - emote_mod = IDLE; // Reset emote mod to 0 - } + ui_vp_sideplayer_char->setFlipped(true); + } + else + { + ui_vp_sideplayer_char->setFlipped(false); } + ui_vp_sideplayer_char->startPlayback(); +} + +void Courtroom::handle_emote_mod(ms2::EmoteMod emote_mod, bool p_immediate) +{ // Handle the emote mod switch (emote_mod) { - case PREANIM: - case PREANIM_ZOOM: + case ms2::EmoteMod::Pre: + case ms2::EmoteMod::PreZoom: // play preanim that makes the chatbox wait for it to finish. play_preanim(false); break; - case IDLE: - case ZOOM: + case ms2::EmoteMod::Idle: + case ms2::EmoteMod::Zoom: // If immediate is not ticked on... if (!p_immediate) { @@ -2883,7 +2731,7 @@ void Courtroom::handle_emote_mod(int emote_mod, bool p_immediate) break; default: // This should never happen, but if it does anyway, yell in the console about it. - qWarning() << "invalid emote mod: " << QString::number(emote_mod); + qWarning() << "invalid emote mod: " << QString::number(static_cast(emote_mod)); } } @@ -2896,9 +2744,9 @@ void Courtroom::handle_ic_message() { // Update the chatbox information initialize_chatbox(); - if (m_chatmessage[EMOTE] != "") + if (!m_chatmessage.m_emote.isEmpty()) { - do_transition(m_chatmessage[DESK_MOD], last_side, m_chatmessage[SIDE]); + do_transition(m_chatmessage.m_desk_mod, last_side, m_chatmessage.m_side); } else { @@ -2909,11 +2757,8 @@ void Courtroom::handle_ic_message() // if we have instant objections disabled, and queue is not empty, check if next message after this is an objection. if (!Options::getInstance().objectionSkipQueueEnabled() && chatmessage_queue.size() > 0) { - QStringList p_contents = chatmessage_queue.head(); - int objection_mod = p_contents[OBJECTION_MOD].split("&")[0].toInt(); - bool is_objection = objection_mod >= 1 && objection_mod <= 5; // If this is an objection, we'll need to interrupt our current message. - if (is_objection) + if (chatmessage_queue.head().m_objection_mod != ms2::ObjectionMod::None) { text_queue_timer->start(objection_threshold); } @@ -2965,7 +2810,7 @@ void Courtroom::do_screenshake() m_screenshake_anim_group->start(); } -void Courtroom::do_transition(QString p_desk_mod, QString oldPosId, QString newPosId) +void Courtroom::do_transition(ms2::DeskMod p_desk_mod, QString oldPosId, QString newPosId) { display_character(); @@ -2990,7 +2835,7 @@ void Courtroom::do_transition(QString p_desk_mod, QString oldPosId, QString newP int duration = ao_app->get_pos_transition_duration(t_old_pos, t_new_pos); // conditions to stop slide - if (oldPosId == newPosId || old_pos.background != new_pos.background || !old_pos.origin.has_value() || !new_pos.origin.has_value() || !Options::getInstance().slidesEnabled() || m_chatmessage[SLIDE] != "1" || duration == -1 || m_chatmessage[EMOTE_MOD].toInt() == ZOOM || m_chatmessage[EMOTE_MOD].toInt() == PREANIM_ZOOM) + if (oldPosId == newPosId || old_pos.background != new_pos.background || !old_pos.origin.has_value() || !new_pos.origin.has_value() || !Options::getInstance().slidesEnabled() || !m_chatmessage.m_slide || duration == -1 || m_chatmessage.m_emote_mod == ms2::EmoteMod::Zoom || m_chatmessage.m_emote_mod == ms2::EmoteMod::PreZoom) { #ifdef DEBUG_TRANSITION qDebug() << "skipping transition - not applicable"; @@ -3007,7 +2852,7 @@ void Courtroom::do_transition(QString p_desk_mod, QString oldPosId, QString newP qDebug() << "STARTING TRANSITION"; #endif - set_scene(p_desk_mod.toInt(), oldPosId); + set_scene(p_desk_mod != ms2::DeskMod::Hidden, oldPosId); int viewport_width = ui_viewport->width(); int viewport_height = ui_viewport->height(); @@ -3029,14 +2874,10 @@ void Courtroom::do_transition(QString p_desk_mod, QString oldPosId, QString newP m_screenslide_timer->addAnimation(transition_animation); } - auto calculate_offset_and_setup_layer = [&, this](kal::CharacterAnimationLayer *layer, QPoint newPos, QString rawOffset) { + auto calculate_offset_and_setup_layer = [&, this](kal::CharacterAnimationLayer *layer, QPoint newPos, const ms2::OffsetData &offset_data) { QPoint offset; - QStringList offset_data = rawOffset.split("&"); - offset.setX(viewport_width * offset_data.at(0).toInt() * 0.01); - if (offset_data.size() > 1) - { - offset.setY(viewport_height * offset_data.at(1).toInt() * 0.01); - } + offset.setX(viewport_width * offset_data.x * 0.01); + offset.setY(viewport_height * offset_data.y * 0.01); layer->setParent(ui_vp_background); layer->setPlayOnce(false); @@ -3046,30 +2887,26 @@ void Courtroom::do_transition(QString p_desk_mod, QString oldPosId, QString newP layer->show(); }; - ui_vp_player_char->loadCharacterEmote(m_chatmessage[CHAR_NAME], m_chatmessage[EMOTE], kal::CharacterAnimationLayer::IdleEmote); + ui_vp_player_char->loadCharacterEmote(m_chatmessage.m_char_name, m_chatmessage.m_emote, kal::CharacterAnimationLayer::IdleEmote); ui_vp_player_char->show(); - ui_vp_player_char->setFlipped(m_chatmessage[FLIP].toInt() == 1); - calculate_offset_and_setup_layer(ui_vp_player_char, scaled_new_pos, m_chatmessage[SELF_OFFSET]); + ui_vp_player_char->setFlipped(m_chatmessage.m_flip); + calculate_offset_and_setup_layer(ui_vp_player_char, scaled_new_pos, m_chatmessage.m_offset); - auto is_pairing = [](QString *data) { - return (data[OTHER_CHARID].toInt() != -1 && !data[OTHER_NAME].isEmpty()); - }; - auto is_pair_under = [](QString data) -> bool { - QStringList pair_data = data.split("^"); - return (pair_data.size() > 1) ? (pair_data.at(1).toInt() == 1) : false; + auto is_pairing = [](const ms2::OldMSFlatData &data) { + return (data.m_other.m_charid != -1 && !data.m_other.m_name.isEmpty()); }; - ui_vp_dummy_char->loadCharacterEmote(m_previous_chatmessage[CHAR_NAME], m_previous_chatmessage[EMOTE], kal::CharacterAnimationLayer::IdleEmote); - ui_vp_dummy_char->setFlipped(m_previous_chatmessage[FLIP].toInt() == 1); - calculate_offset_and_setup_layer(ui_vp_dummy_char, scaled_old_pos, m_previous_chatmessage[SELF_OFFSET]); + ui_vp_dummy_char->loadCharacterEmote(m_previous_chatmessage.m_char_name, m_previous_chatmessage.m_emote, kal::CharacterAnimationLayer::IdleEmote); + ui_vp_dummy_char->setFlipped(m_previous_chatmessage.m_flip); + calculate_offset_and_setup_layer(ui_vp_dummy_char, scaled_old_pos, m_previous_chatmessage.m_offset); if (is_pairing(m_previous_chatmessage)) { qDebug() << "last message WAS paired"; - ui_vp_sidedummy_char->loadCharacterEmote(m_previous_chatmessage[OTHER_NAME], m_previous_chatmessage[OTHER_EMOTE], kal::CharacterAnimationLayer::IdleEmote); - ui_vp_sidedummy_char->setFlipped(m_previous_chatmessage[OTHER_FLIP].toInt() == 1); - calculate_offset_and_setup_layer(ui_vp_sidedummy_char, scaled_old_pos, m_previous_chatmessage[OTHER_OFFSET]); - if (is_pair_under(m_previous_chatmessage[OTHER_CHARID])) + ui_vp_sidedummy_char->loadCharacterEmote(m_previous_chatmessage.m_other.m_name, m_previous_chatmessage.m_other.m_emote, kal::CharacterAnimationLayer::IdleEmote); + ui_vp_sidedummy_char->setFlipped(m_previous_chatmessage.m_other.m_flip); + calculate_offset_and_setup_layer(ui_vp_sidedummy_char, scaled_old_pos, m_previous_chatmessage.m_other.m_offset); + if (m_previous_chatmessage.m_other.m_under) { ui_vp_dummy_char->stackUnder(ui_vp_sidedummy_char); } @@ -3081,9 +2918,9 @@ void Courtroom::do_transition(QString p_desk_mod, QString oldPosId, QString newP if (is_pairing(m_chatmessage)) { - ui_vp_sideplayer_char->loadCharacterEmote(m_chatmessage[OTHER_NAME], m_chatmessage[OTHER_EMOTE], kal::CharacterAnimationLayer::IdleEmote); - calculate_offset_and_setup_layer(ui_vp_sideplayer_char, scaled_new_pos, m_chatmessage[OTHER_OFFSET]); - if (is_pair_under(m_chatmessage[OTHER_CHARID])) + ui_vp_sideplayer_char->loadCharacterEmote(m_chatmessage.m_other.m_name, m_chatmessage.m_other.m_emote, kal::CharacterAnimationLayer::IdleEmote); + calculate_offset_and_setup_layer(ui_vp_sideplayer_char, scaled_new_pos, m_chatmessage.m_other.m_offset); + if (m_chatmessage.m_other.m_under) { ui_vp_player_char->stackUnder(ui_vp_sideplayer_char); } @@ -3120,23 +2957,20 @@ void Courtroom::post_transition_cleanup() ui_vp_sideplayer_char->hide(); ui_vp_sideplayer_char->move(0, 0); - set_scene(m_chatmessage[DESK_MOD].toInt(), m_chatmessage[SIDE]); + set_scene(m_chatmessage.m_desk_mod != ms2::DeskMod::Hidden, m_chatmessage.m_side); // Move the character on the viewport according to the offsets - set_self_offset(m_chatmessage[SELF_OFFSET], ui_vp_player_char); - - int emote_mod = m_chatmessage[EMOTE_MOD].toInt(); - bool immediate = m_chatmessage[IMMEDIATE].toInt() == 1; + set_self_offset(m_chatmessage.m_offset, ui_vp_player_char); // If the emote_mod is not zooming - if (emote_mod != ZOOM && emote_rows != PREANIM_ZOOM) + if (m_chatmessage.m_emote_mod != ms2::EmoteMod::Zoom && m_chatmessage.m_emote_mod != ms2::EmoteMod::PreZoom) { // Display the pair character - display_pair_character(m_chatmessage[OTHER_CHARID], m_chatmessage[OTHER_OFFSET]); + display_pair_character(m_chatmessage.m_other); } // Parse the emote_mod part of the chat message - handle_emote_mod(emote_mod, immediate); + handle_emote_mod(m_chatmessage.m_emote_mod, m_chatmessage.m_immediate); } void Courtroom::do_flash() @@ -3146,18 +2980,19 @@ void Courtroom::do_flash() return; } - QString f_char = m_chatmessage[CHAR_NAME]; + QString f_char = m_chatmessage.m_char_name; QString f_custom_theme = ao_app->get_chat(f_char); - do_effect("realization", "", f_char, f_custom_theme); + ms2::EffectData l_realisation{"realization", "", f_custom_theme}; + do_effect(f_char, l_realisation, m_chatmessage.m_offset); } -void Courtroom::do_effect(QString fx_path, QString fx_sound, QString p_char, QString p_folder) +void Courtroom::do_effect(QString p_char, const ms2::EffectData &f_effect, const ms2::OffsetData &f_offset) { - if (fx_path == "") + if (f_effect.m_name.isEmpty()) { return; } - QString effect = ao_app->get_effect(fx_path, p_char, p_folder); + QString effect = ao_app->get_effect(f_effect.m_name, p_char, f_effect.m_folder); if (effect.isEmpty()) { ui_vp_effect->stopPlayback(); @@ -3165,9 +3000,9 @@ void Courtroom::do_effect(QString fx_path, QString fx_sound, QString p_char, QSt return; } - if (fx_sound != "") + if (!f_effect.m_sound.isEmpty()) { - sfx_player->findAndPlaySfx(fx_sound); + sfx_player->findAndPlaySfx(f_effect.m_sound); } // Only check if effects are disabled after playing the sound if it exists @@ -3175,18 +3010,18 @@ void Courtroom::do_effect(QString fx_path, QString fx_sound, QString p_char, QSt { return; } - ui_vp_effect->setStretchToFit(ao_app->get_effect_property(fx_path, p_char, p_folder, "stretch").startsWith("true")); - ui_vp_effect->setResizeMode(ao_app->get_scaling(ao_app->get_effect_property(fx_path, p_char, p_folder, "scaling"))); - ui_vp_effect->setFlipped(ao_app->get_effect_property(fx_path, p_char, p_folder, "respect_flip").startsWith("true") && m_chatmessage[FLIP].toInt() == 1); + ui_vp_effect->setStretchToFit(ao_app->get_effect_property(f_effect.m_name, p_char, f_effect.m_folder, "stretch").startsWith("true")); + ui_vp_effect->setResizeMode(ao_app->get_scaling(ao_app->get_effect_property(f_effect.m_name, p_char, f_effect.m_folder, "scaling"))); + ui_vp_effect->setFlipped(ao_app->get_effect_property(f_effect.m_name, p_char, f_effect.m_folder, "respect_flip").startsWith("true") && m_chatmessage.m_flip); - bool looping = ao_app->get_effect_property(fx_path, p_char, p_folder, "loop").startsWith("true"); + bool looping = ao_app->get_effect_property(f_effect.m_name, p_char, f_effect.m_folder, "loop").startsWith("true"); - int max_duration = ao_app->get_effect_property(fx_path, p_char, p_folder, "max_duration").toInt(); + int max_duration = ao_app->get_effect_property(f_effect.m_name, p_char, f_effect.m_folder, "max_duration").toInt(); - bool cull = ao_app->get_effect_property(fx_path, p_char, p_folder, "cull").startsWith("true"); + bool cull = ao_app->get_effect_property(f_effect.m_name, p_char, f_effect.m_folder, "cull").startsWith("true"); // Possible values: "chat", "character", "behind" - QString layer = ao_app->get_effect_property(fx_path, p_char, p_folder, "layer").toLower(); + QString layer = ao_app->get_effect_property(f_effect.m_name, p_char, f_effect.m_folder, "layer").toLower(); if (layer == "behind") { ui_vp_effect->setParent(ui_viewport); @@ -3218,24 +3053,12 @@ void Courtroom::do_effect(QString fx_path, QString fx_sound, QString p_char, QSt effect_y = ui_viewport->y(); } // This effect respects the character offset settings - if (ao_app->get_effect_property(fx_path, p_char, p_folder, "respect_offset") == "true") + if (ao_app->get_effect_property(f_effect.m_name, p_char, f_effect.m_folder, "respect_offset") == "true") { - QStringList self_offsets = m_chatmessage[SELF_OFFSET].split("&"); - int self_offset = self_offsets[0].toInt(); - int self_offset_v; - if (self_offsets.length() <= 1) - { - self_offset_v = 0; - } - else - { - self_offset_v = self_offsets[1].toInt(); - } - // Move the effects layer to match the position of our character const int percent = 100; - effect_x += ui_viewport->width() * self_offset / percent; - effect_y += ui_viewport->height() * self_offset_v / percent; + effect_x += ui_viewport->width() * f_offset.x / percent; + effect_y += ui_viewport->height() * f_offset.y / percent; } ui_vp_effect->move(effect_x, effect_y); @@ -3251,22 +3074,21 @@ void Courtroom::play_char_sfx(QString sfx_name) void Courtroom::initialize_chatbox() { - int f_charid = m_chatmessage[CHAR_ID].toInt(); - if (f_charid >= 0 && f_charid < char_list.size() && (m_chatmessage[SHOWNAME].isEmpty() || !custom_shownames)) + if (m_chatmessage.m_char_id >= 0 && m_chatmessage.m_char_id < char_list.size() && (m_chatmessage.m_showname.isEmpty() || !custom_shownames)) { - QString real_name = char_list.at(f_charid).name; + QString real_name = char_list.at(m_chatmessage.m_char_id).name; QString f_showname = ao_app->get_showname(real_name); ui_vp_showname->setText(f_showname); } else { - ui_vp_showname->setText(m_chatmessage[SHOWNAME]); + ui_vp_showname->setText(m_chatmessage.m_showname); } QString customchar; if (Options::getInstance().customChatboxEnabled()) { - customchar = m_chatmessage[CHAR_NAME]; + customchar = m_chatmessage.m_char_name; } QString p_misc = ao_app->get_chat(customchar); @@ -3365,14 +3187,14 @@ void Courtroom::initialize_chatbox() } QString font_name; - QString chatfont = ao_app->get_chat_font(m_chatmessage[CHAR_NAME]); + QString chatfont = ao_app->get_chat_font(m_chatmessage.m_char_name); if (chatfont != "") { font_name = chatfont; } int f_pointsize = 0; - int chatsize = ao_app->get_chat_size(m_chatmessage[CHAR_NAME]); + int chatsize = ao_app->get_chat_size(m_chatmessage.m_char_name); if (chatsize > 0) { f_pointsize = chatsize; @@ -3380,17 +3202,15 @@ void Courtroom::initialize_chatbox() set_font(ui_vp_message, "", "message", customchar, font_name, f_pointsize); } -void Courtroom::handle_callwords() +void Courtroom::handle_callwords(const QString &f_text) { - // Quickly check through the message for the word_call (callwords) sfx - QString f_message = m_chatmessage[MESSAGE]; // No more file IO on every message. QStringList call_words = Options::getInstance().callwords(); // Loop through each word in the call words list for (const QString &word : std::as_const(call_words)) { // If our message contains that specific call word - if (f_message.contains(word, Qt::CaseInsensitive)) + if (f_text.contains(word, Qt::CaseInsensitive)) { // Play the call word sfx on the modcall_player sound container modcall_player->findAndPlaySfx(ao_app->get_court_sfx("word_call")); @@ -3402,17 +3222,15 @@ void Courtroom::handle_callwords() } } -void Courtroom::display_evidence_image() +void Courtroom::display_evidence_image(qint32 f_evidence_id, const QString &f_side) { - QString side = m_chatmessage[SIDE]; - int f_evi_id = m_chatmessage[EVIDENCE_ID].toInt(); - if (f_evi_id > 0 && f_evi_id <= global_evidence_list.size()) + if (f_evidence_id > 0 && f_evidence_id <= global_evidence_list.size()) { // shifted by 1 because 0 is no evidence per legacy standards - QString f_image = global_evidence_list.at(f_evi_id - 1).image; + QString f_image = global_evidence_list.at(f_evidence_id - 1).image; // def jud and hlp should display the evidence icon on the RIGHT side - bool is_left_side = !(side.startsWith("def") || side == "hlp"); // FIXME : Hardcoded - ui_vp_evidence_display->show_evidence(f_evi_id, f_image, is_left_side, sfx_player->volume()); + bool is_left_side = !(f_side.startsWith("def") || f_side == "hlp"); // FIXME : Hardcoded + ui_vp_evidence_display->show_evidence(f_evidence_id, f_image, is_left_side, sfx_player->volume()); } else { @@ -3422,10 +3240,7 @@ void Courtroom::display_evidence_image() void Courtroom::handle_ic_speaking() { - QString side = m_chatmessage[SIDE]; - int emote_mod = m_chatmessage[EMOTE_MOD].toInt(); - // emote_mod 5 is zoom and emote_mod 6 is zoom w/ preanim. - if (emote_mod == ZOOM || emote_mod == PREANIM_ZOOM) + if (m_chatmessage.m_emote_mod == ms2::EmoteMod::Zoom || m_chatmessage.m_emote_mod == ms2::EmoteMod::PreZoom) { // Hide the desks ui_vp_desk->hide(); @@ -3433,7 +3248,7 @@ void Courtroom::handle_ic_speaking() // Obtain character information for our character QString filename; // I still hate this hardcoding. If we're on pos pro, hlp and wit, use prosecution_speedlines. Otherwise, defense_speedlines. - if (side.startsWith("pro") || side == "hlp" || side.startsWith("wit")) + if (m_chatmessage.m_side.startsWith("pro") || m_chatmessage.m_side == "hlp" || m_chatmessage.m_side.startsWith("wit")) { filename = "prosecution_speedlines"; } @@ -3445,19 +3260,19 @@ void Courtroom::handle_ic_speaking() // We're zooming, so hide the pair character and ignore pair offsets. This ain't about them. ui_vp_sideplayer_char->hide(); ui_vp_player_char->move(0, 0); - ui_vp_speedlines->loadAndPlayAnimation(filename, m_chatmessage[CHAR_NAME], ao_app->get_chat(m_chatmessage[CHAR_NAME])); + ui_vp_speedlines->loadAndPlayAnimation(filename, m_chatmessage.m_char_name, ao_app->get_chat(m_chatmessage.m_char_name)); } // Check if this is a talking color (white text, etc.) - color_is_talking = color_markdown_talking_list.at(m_chatmessage[TEXT_COLOR].toInt()); + color_is_talking = color_markdown_talking_list.at(m_chatmessage.m_text_colour); QString filename; // If color is talking, and our state isn't already talking if (color_is_talking && text_state == 1 && anim_state < 2) { // Play the talking animation anim_state = 2; - filename = m_chatmessage[EMOTE]; - ui_vp_player_char->loadCharacterEmote(m_chatmessage[CHAR_NAME], m_chatmessage[EMOTE], kal::CharacterAnimationLayer::TalkEmote); + filename = m_chatmessage.m_emote; + ui_vp_player_char->loadCharacterEmote(m_chatmessage.m_char_name, m_chatmessage.m_emote, kal::CharacterAnimationLayer::TalkEmote); ui_vp_player_char->setPlayOnce(false); ui_vp_player_char->show(); ui_vp_player_char->startPlayback(); @@ -3467,8 +3282,8 @@ void Courtroom::handle_ic_speaking() { // Play the idle animation anim_state = 3; - filename = m_chatmessage[EMOTE]; - ui_vp_player_char->loadCharacterEmote(m_chatmessage[CHAR_NAME], m_chatmessage[EMOTE], kal::CharacterAnimationLayer::IdleEmote); + filename = m_chatmessage.m_emote; + ui_vp_player_char->loadCharacterEmote(m_chatmessage.m_char_name, m_chatmessage.m_emote, kal::CharacterAnimationLayer::IdleEmote); ui_vp_player_char->setPlayOnce(false); ui_vp_player_char->show(); ui_vp_player_char->startPlayback(); @@ -3985,16 +3800,14 @@ void Courtroom::pop_ic_ghost() void Courtroom::play_preanim(bool immediate) { - QString f_char = m_chatmessage[CHAR_NAME]; - QString f_preanim = m_chatmessage[PRE_EMOTE]; // all time values in char.inis are multiplied by a constant(time_mod) to get // the actual time - int preanim_duration = ao_app->get_preanim_duration(f_char, f_preanim); - int stay_time = ao_app->get_text_delay(f_char, f_preanim) * time_mod; - int sfx_delay = m_chatmessage[SFX_DELAY].toInt() * time_mod; + int preanim_duration = ao_app->get_preanim_duration(m_chatmessage.m_char_name, m_chatmessage.m_preanim); + int stay_time = ao_app->get_text_delay(m_chatmessage.m_char_name, m_chatmessage.m_preanim) * time_mod; + int sfx_delay = m_chatmessage.m_sfx_delay * time_mod; sfx_delay_timer->start(sfx_delay); - QString anim_to_find = ao_app->get_image_suffix(ao_app->get_character_path(f_char, f_preanim)); + QString anim_to_find = ao_app->get_image_suffix(ao_app->get_character_path(m_chatmessage.m_char_name, m_chatmessage.m_preanim)); if (!file_exists(anim_to_find)) { if (immediate) @@ -4006,29 +3819,28 @@ void Courtroom::play_preanim(bool immediate) anim_state = 1; } preanim_done(); - qWarning() << "could not find preanim" << f_preanim << "for character" << f_char; + qWarning() << "could not find preanim" << m_chatmessage.m_preanim << "for character" << m_chatmessage.m_char_name; return; } - ui_vp_player_char->loadCharacterEmote(f_char, f_preanim, kal::CharacterAnimationLayer::PreEmote, preanim_duration); + ui_vp_player_char->loadCharacterEmote(m_chatmessage.m_char_name, m_chatmessage.m_preanim, kal::CharacterAnimationLayer::PreEmote, preanim_duration); ui_vp_player_char->setPlayOnce(true); ui_vp_player_char->startPlayback(); - switch (m_chatmessage[DESK_MOD].toInt()) + switch (m_chatmessage.m_desk_mod) { - case DESK_EMOTE_ONLY_EX: + case ms2::DeskMod::HiddenCentreThenShown: ui_vp_sideplayer_char->hide(); ui_vp_player_char->move(0, 0); [[fallthrough]]; - case DESK_EMOTE_ONLY: - case DESK_HIDE: - set_scene(false, m_chatmessage[SIDE]); + case ms2::DeskMod::HiddenDuringPreThenShown: + case ms2::DeskMod::Hidden: + set_scene(false, m_chatmessage.m_side); break; - - case DESK_PRE_ONLY_EX: - case DESK_PRE_ONLY: - case DESK_SHOW: - set_scene(true, m_chatmessage[SIDE]); + case ms2::DeskMod::ShownThenHiddenCentre: + case ms2::DeskMod::ShowDuringPreThenHidden: + case ms2::DeskMod::Shown: + set_scene(true, m_chatmessage.m_side); break; } @@ -4070,63 +3882,44 @@ void Courtroom::start_chat_ticking() } // Display the evidence - display_evidence_image(); + display_evidence_image(m_chatmessage.m_evidence, m_chatmessage.m_side); // handle expanded desk mods - switch (m_chatmessage[DESK_MOD].toInt()) + switch (m_chatmessage.m_desk_mod) { - case DESK_EMOTE_ONLY_EX: - set_self_offset(m_chatmessage[SELF_OFFSET], ui_vp_player_char); + case ms2::DeskMod::HiddenCentreThenShown: + set_self_offset(m_chatmessage.m_offset, ui_vp_player_char); [[fallthrough]]; - case DESK_EMOTE_ONLY: - case DESK_SHOW: - set_scene(true, m_chatmessage[SIDE]); + case ms2::DeskMod::HiddenDuringPreThenShown: + case ms2::DeskMod::Shown: + set_scene(true, m_chatmessage.m_side); break; - - case DESK_PRE_ONLY_EX: + case ms2::DeskMod::ShownThenHiddenCentre: ui_vp_sideplayer_char->hide(); ui_vp_player_char->move(0, 0); [[fallthrough]]; - case DESK_PRE_ONLY: - case DESK_HIDE: - set_scene(false, m_chatmessage[SIDE]); + case ms2::DeskMod::ShowDuringPreThenHidden: + case ms2::DeskMod::Hidden: + set_scene(false, m_chatmessage.m_side); break; } - if (m_chatmessage[EFFECTS] != "") - { - QStringList fx_list = m_chatmessage[EFFECTS].split("|"); - QString fx = fx_list[0]; - QString fx_sound; - QString fx_folder; - - if (fx_list.length() > 1) - { - fx_sound = fx_list[1]; - } - - if (fx_list.length() > 2) - { - fx_folder = fx_list[1]; - fx_sound = fx_list[2]; - } - this->do_effect(fx, fx_sound, m_chatmessage[CHAR_NAME], fx_folder); - } - else if (m_chatmessage[REALIZATION] == "1") + if (!m_chatmessage.m_effect.m_name.isEmpty()) + this->do_effect(m_chatmessage.m_char_name, m_chatmessage.m_effect, m_chatmessage.m_offset); + else if (m_chatmessage.m_realisation) { this->do_flash(); - sfx_player->findAndPlaySfx(ao_app->get_custom_realization(m_chatmessage[CHAR_NAME])); + sfx_player->findAndPlaySfx(ao_app->get_custom_realization(m_chatmessage.m_char_name)); } - int emote_mod = m_chatmessage[EMOTE_MOD].toInt(); // text meme bonanza - if ((emote_mod == IDLE || emote_mod == ZOOM) && m_chatmessage[SCREENSHAKE] == "1") + if ((m_chatmessage.m_emote_mod == ms2::EmoteMod::Idle || m_chatmessage.m_emote_mod == ms2::EmoteMod::Zoom) && m_chatmessage.m_screenshake) { this->do_screenshake(); } - if (m_chatmessage[MESSAGE].isEmpty()) + if (m_chatmessage.m_message_text.isEmpty()) { // since the message is empty, it's technically done ticking text_state = 2; - if (m_chatmessage[ADDITIVE] == "1") + if (m_chatmessage.m_additive) { // Cool behavior ui_vp_chatbox->show(); @@ -4139,7 +3932,7 @@ void Courtroom::start_chat_ticking() // Show it if chatbox always shows if (Options::getInstance().characterStickerEnabled() && chatbox_always_show) { - ui_vp_sticker->loadAndPlayAnimation(m_chatmessage[CHAR_NAME]); + ui_vp_sticker->loadAndPlayAnimation(m_chatmessage.m_char_name); } // Hide the face sticker else @@ -4161,10 +3954,10 @@ void Courtroom::start_chat_ticking() if (Options::getInstance().characterStickerEnabled()) { - ui_vp_sticker->loadAndPlayAnimation(m_chatmessage[CHAR_NAME]); + ui_vp_sticker->loadAndPlayAnimation(m_chatmessage.m_char_name); } - if (m_chatmessage[ADDITIVE] != "1") + if (!m_chatmessage.m_additive) { ui_vp_message->clear(); real_tick_pos = 0; @@ -4182,17 +3975,17 @@ void Courtroom::start_chat_ticking() chat_tick_timer->start(0); // Display the first char right away last_misc = current_misc; - current_misc = ao_app->get_chat(m_chatmessage[CHAR_NAME]); + current_misc = ao_app->get_chat(m_chatmessage.m_char_name); if ((last_misc != current_misc || char_color_rgb_list.size() < max_colors) && Options::getInstance().customChatboxEnabled()) { gen_char_rgb_list(current_misc); } - QString f_blips = ao_app->get_blipname(m_chatmessage[CHAR_NAME]); + QString f_blips = ao_app->get_blipname(m_chatmessage.m_char_name); f_blips = ao_app->get_blips(f_blips); - if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CUSTOM_BLIPS) && !m_chatmessage[BLIPNAME].isEmpty()) + if (ao_app->m_serverdata.get_feature(server::BASE_FEATURE_SET::CUSTOM_BLIPS) && !m_chatmessage.m_blips.isEmpty()) { - f_blips = ao_app->get_blips(m_chatmessage[BLIPNAME]); + f_blips = ao_app->get_blips(m_chatmessage.m_blips); } blip_player->setBlip(f_blips); @@ -4204,36 +3997,31 @@ void Courtroom::start_chat_ticking() void Courtroom::chat_tick() { - // note: this is called fairly often - // do not perform heavy operations here - - QString f_message = m_chatmessage[MESSAGE]; - // Due to our new text speed system, we always need to stop the timer now. chat_tick_timer->stop(); - if (tick_pos >= f_message.size()) + if (tick_pos >= m_chatmessage.m_message_text.size()) { text_state = 2; // Check if we're a narrator msg - if (m_chatmessage[EMOTE] != "") + if (!m_chatmessage.m_emote.isEmpty()) { if (anim_state < 3) { - QStringList c_paths = {ao_app->get_image_suffix(ao_app->get_character_path(m_chatmessage[CHAR_NAME], "(c)" + m_chatmessage[EMOTE])), ao_app->get_image_suffix(ao_app->get_character_path(m_chatmessage[CHAR_NAME], "(c)/" + m_chatmessage[EMOTE]))}; + QStringList c_paths = {ao_app->get_image_suffix(ao_app->get_character_path(m_chatmessage.m_char_name, "(c)" + m_chatmessage.m_emote)), ao_app->get_image_suffix(ao_app->get_character_path(m_chatmessage.m_char_name, "(c)/" + m_chatmessage.m_emote))}; // if there is a (c) animation for this emote and we haven't played it already if (file_exists(ao_app->find_image(c_paths)) && (!c_played)) { anim_state = 5; c_played = true; - ui_vp_player_char->loadCharacterEmote(m_chatmessage[CHAR_NAME], m_chatmessage[EMOTE], kal::CharacterAnimationLayer::PostEmote); + ui_vp_player_char->loadCharacterEmote(m_chatmessage.m_char_name, m_chatmessage.m_emote, kal::CharacterAnimationLayer::PostEmote); ui_vp_player_char->setPlayOnce(true); ui_vp_player_char->startPlayback(); } else { anim_state = 3; - ui_vp_player_char->loadCharacterEmote(m_chatmessage[CHAR_NAME], m_chatmessage[EMOTE], kal::CharacterAnimationLayer::IdleEmote); + ui_vp_player_char->loadCharacterEmote(m_chatmessage.m_char_name, m_chatmessage.m_emote, kal::CharacterAnimationLayer::IdleEmote); ui_vp_player_char->setPlayOnce(false); ui_vp_player_char->startPlayback(); } @@ -4247,12 +4035,12 @@ void Courtroom::chat_tick() QString f_custom_theme; if (Options::getInstance().customChatboxEnabled()) { - f_char = m_chatmessage[CHAR_NAME]; + f_char = m_chatmessage.m_char_name; f_custom_theme = ao_app->get_chat(f_char); } ui_vp_chat_arrow->setResizeMode(ao_app->get_misc_scaling(f_custom_theme)); ui_vp_chat_arrow->loadAndPlayAnimation("chat_arrow", f_custom_theme); // Chat stopped being processed, indicate that. - QString f_message_filtered = filter_ic_text(f_message, true, -1, m_chatmessage[TEXT_COLOR].toInt()); + QString f_message_filtered = filter_ic_text(m_chatmessage.m_message_text, true, -1, m_chatmessage.m_text_colour); if (Options::getInstance().customChatboxEnabled()) { // chatbox colors for (int c = 0; c < max_colors; ++c) @@ -4282,11 +4070,8 @@ void Courtroom::chat_tick() // if we have instant objections disabled, and queue is not empty, check if next message after this is an objection. if (!Options::getInstance().objectionSkipQueueEnabled() && chatmessage_queue.size() > 0) { - QStringList p_contents = chatmessage_queue.head(); - int objection_mod = p_contents[OBJECTION_MOD].split("&")[0].toInt(); - bool is_objection = objection_mod >= 1 && objection_mod <= 5; // If this is an objection, we'll need to interrupt our current message. - if (is_objection) + if (chatmessage_queue.head().m_objection_mod != ms2::ObjectionMod::None) { chatmessage_dequeue(); } @@ -4297,7 +4082,7 @@ void Courtroom::chat_tick() // Stops blips from playing when we have a formatting option. bool formatting_char = false; - QString f_rest = f_message; + QString f_rest = m_chatmessage.m_message_text; // Alignment characters if (tick_pos < 2) @@ -4411,7 +4196,7 @@ void Courtroom::chat_tick() msg_delay = text_crawl * message_display_mult[current_display_speed]; } - if ((msg_delay <= 0 && tick_pos < f_message.size() - 1) || formatting_char) + if ((msg_delay <= 0 && tick_pos < m_chatmessage.m_message_text.size() - 1) || formatting_char) { if (f_character == "p") { @@ -4431,7 +4216,7 @@ void Courtroom::chat_tick() else { // Do the colors, gradual showing, etc. in here - QString f_message_filtered = filter_ic_text(f_message, true, tick_pos, m_chatmessage[TEXT_COLOR].toInt()); + QString f_message_filtered = filter_ic_text(m_chatmessage.m_message_text, true, tick_pos, m_chatmessage.m_text_colour); if (Options::getInstance().customChatboxEnabled()) { // use chatbox colors for (int c = 0; c < max_colors; ++c) @@ -4503,21 +4288,21 @@ void Courtroom::chat_tick() msg_delay = qMin(max_delay, msg_delay * punctuation_modifier); } - if (m_chatmessage[EMOTE] != "") + if (!m_chatmessage.m_emote.isEmpty()) { // If this color is talking if (color_is_talking && anim_state != 2 && anim_state < 4) // Set it to talking as we're not on that already (though we have // to avoid interrupting a non-interrupted preanim) { anim_state = 2; - ui_vp_player_char->loadCharacterEmote(m_chatmessage[CHAR_NAME], m_chatmessage[EMOTE], kal::CharacterAnimationLayer::TalkEmote); + ui_vp_player_char->loadCharacterEmote(m_chatmessage.m_char_name, m_chatmessage.m_emote, kal::CharacterAnimationLayer::TalkEmote); ui_vp_player_char->setPlayOnce(false); ui_vp_player_char->startPlayback(); } else if (!color_is_talking && anim_state < 3 && anim_state != 3) // Set it to idle as we're not on that already { anim_state = 3; - ui_vp_player_char->loadCharacterEmote(m_chatmessage[CHAR_NAME], m_chatmessage[EMOTE], kal::CharacterAnimationLayer::IdleEmote); + ui_vp_player_char->loadCharacterEmote(m_chatmessage.m_char_name, m_chatmessage.m_emote, kal::CharacterAnimationLayer::IdleEmote); ui_vp_player_char->setPlayOnce(false); ui_vp_player_char->startPlayback(); } @@ -4529,17 +4314,16 @@ void Courtroom::chat_tick() void Courtroom::play_sfx() { - QString sfx_name = m_chatmessage[SFX_NAME]; - if (m_chatmessage[SCREENSHAKE] == "1") // Screenshake dependant on preanim sfx delay meme + if (m_chatmessage.m_screenshake) // Screenshake dependant on preanim sfx delay meme { this->do_screenshake(); } - if (sfx_name == "1") + if (m_chatmessage.m_sfx_name == "1") { return; } - sfx_player->findAndPlaySfx(sfx_name); + sfx_player->findAndPlaySfx(m_chatmessage.m_sfx_name); if (Options::getInstance().loopingSfx()) { sfx_player->setLooping(ao_app->get_sfx_looping(current_char, current_emote) == "1"); @@ -4603,20 +4387,9 @@ void Courtroom::set_scene(bool show_desk, const QString f_side) } } -void Courtroom::set_self_offset(const QString &p_list, kal::AnimationLayer *p_layer) +void Courtroom::set_self_offset(const ms2::OffsetData &p_offsetData, kal::AnimationLayer *p_layer) { - QStringList self_offsets = p_list.split("&"); - int self_offset = self_offsets[0].toInt(); - int self_offset_v; - if (self_offsets.length() <= 1) - { - self_offset_v = 0; - } - else - { - self_offset_v = self_offsets[1].toInt(); - } - p_layer->move(ui_viewport->width() * self_offset / 100, ui_viewport->height() * self_offset_v / 100); + p_layer->move(ui_viewport->width() * p_offsetData.x / 100, ui_viewport->height() * p_offsetData.y / 100); } void Courtroom::set_ip_list(QString p_list) @@ -4901,7 +4674,7 @@ void Courtroom::set_hp_bar(int p_bar, int p_state) } else { - do_effect(effect_name, "", "", ""); + do_effect(QString{}, ms2::EffectData{"0", QString{}, QString{}}, ms2::OffsetData{}); } if (!sfx_name.isEmpty()) @@ -5966,10 +5739,10 @@ void Courtroom::on_area_list_double_clicked(QTreeWidgetItem *p_item, int column) void Courtroom::on_hold_it_clicked() { - if (objection_state == 1) + if (objection_state == ms2::ObjectionMod::HoldIt) { ui_hold_it->setImage("holdit"); - objection_state = 0; + objection_state = ms2::ObjectionMod::None; } else { @@ -5978,7 +5751,7 @@ void Courtroom::on_hold_it_clicked() ui_custom_objection->setImage("custom"); ui_hold_it->setImage("holdit_selected"); - objection_state = 1; + objection_state = ms2::ObjectionMod::HoldIt; } focus_ic_input(); @@ -5986,10 +5759,10 @@ void Courtroom::on_hold_it_clicked() void Courtroom::on_objection_clicked() { - if (objection_state == 2) + if (objection_state == ms2::ObjectionMod::Objection) { ui_objection->setImage("objection"); - objection_state = 0; + objection_state = ms2::ObjectionMod::None; } else { @@ -5998,7 +5771,7 @@ void Courtroom::on_objection_clicked() ui_custom_objection->setImage("custom"); ui_objection->setImage("objection_selected"); - objection_state = 2; + objection_state = ms2::ObjectionMod::Objection; } focus_ic_input(); @@ -6006,10 +5779,10 @@ void Courtroom::on_objection_clicked() void Courtroom::on_take_that_clicked() { - if (objection_state == 3) + if (objection_state == ms2::ObjectionMod::TakeThat) { ui_take_that->setImage("takethat"); - objection_state = 0; + objection_state = ms2::ObjectionMod::None; } else { @@ -6018,7 +5791,7 @@ void Courtroom::on_take_that_clicked() ui_custom_objection->setImage("custom"); ui_take_that->setImage("takethat_selected"); - objection_state = 3; + objection_state = ms2::ObjectionMod::TakeThat; } focus_ic_input(); @@ -6026,10 +5799,10 @@ void Courtroom::on_take_that_clicked() void Courtroom::on_custom_objection_clicked() { - if (objection_state == 4) + if (objection_state == ms2::ObjectionMod::Custom) { ui_custom_objection->setImage("custom"); - objection_state = 0; + objection_state = ms2::ObjectionMod::Custom; } else { @@ -6038,7 +5811,7 @@ void Courtroom::on_custom_objection_clicked() ui_hold_it->setImage("holdit"); ui_custom_objection->setImage("custom_selected"); - objection_state = 4; + objection_state = ms2::ObjectionMod::Custom; } focus_ic_input(); @@ -6069,7 +5842,7 @@ void Courtroom::show_custom_objection_menu(const QPoint &pos) } } } - objection_state = 4; + objection_state = ms2::ObjectionMod::Custom; custom_obj_menu->setDefaultAction(selecteditem); } } diff --git a/src/courtroom.h b/src/courtroom.h index dc8cdf3ae..0ca66b63e 100644 --- a/src/courtroom.h +++ b/src/courtroom.h @@ -23,6 +23,7 @@ #include "file_functions.h" #include "hardware_functions.h" #include "lobby.h" +#include "packets/msdata.h" #include "screenslidetimer.h" #include "scrolltext.h" #include "widgets/aooptionsdialog.h" @@ -156,7 +157,7 @@ class Courtroom : public QMainWindow // sets p_layer according to SELF_OFFSET, only a function bc it's used with // desk_mod 4 and 5 - void set_self_offset(const QString &p_list, kal::AnimationLayer *p_layer); + void set_self_offset(const ms2::OffsetData &p_offsetData, kal::AnimationLayer *p_layer); // takes in serverD-formatted IP list as prints a converted version to server // OOC admittedly poorly named @@ -192,10 +193,10 @@ class Courtroom : public QMainWindow void append_server_chatmessage(QString p_name, QString p_message, QString p_color); // Add the message packet to the stack - void chatmessage_enqueue(QStringList p_contents); + void chatmessage_enqueue(const QStringList &p_contents); // Parse the chat message packet and unpack it into the m_chatmessage[ITEM] format - void unpack_chatmessage(QStringList p_contents); + void unpack_chatmessage(const ms2::OldMSFlatData &f_message); // Skip the current queue, adding all the queue messages to the logs if desynchronized logs are disabled void skip_chatmessage_queue(); @@ -208,32 +209,32 @@ class Courtroom : public QMainWindow QUEUED, }; // Log the message contents and information such as evidence presenting etc. into the log file, the IC log, or both. - void log_chatmessage(QString f_message, int f_char_id, QString f_showname = QString(), QString f_char = QString(), QString f_objection_mod = QString(), int f_evi_id = 0, int f_color = 0, LogMode f_log_mode = IO_ONLY, bool sender = false); + void log_chatmessage(const ms2::OldMSFlatData &f_message, LogMode f_log_mode = IO_ONLY, bool sender = false); // Log the message contents and information such as evidence presenting etc. into the IC logs - void handle_callwords(); + void handle_callwords(const QString &f_text); // Handle the objection logic, if it's interrupting the currently parsing message. // Returns true if this message has an objection, otherwise returns false. The result decides when to call handle_ic_message() bool handle_objection(); // Display the evidence image box when presenting evidence in IC - void display_evidence_image(); + void display_evidence_image(qint32 f_evidence_id, const QString &f_side); // Handle the stuff that comes when the character appears on screen and starts animating (preanims etc.) void handle_ic_message(); // Start the logic for doing a courtroom pan slide - void do_transition(QString desk_mod, QString oldPosId, QString new_pos); + void do_transition(ms2::DeskMod p_desk_mod, QString oldPosId, QString new_pos); // Display the character. void display_character(); // Display the character's pair if present. - void display_pair_character(QString other_charid, QString other_offset); + void display_pair_character(const ms2::OtherData &f_other); // Handle the emote modifier value and proceed through the logic accordingly. - void handle_emote_mod(int emote_mod, bool p_immediate); + void handle_emote_mod(ms2::EmoteMod emote_mod, bool p_immediate); // Initialize the chatbox image, showname shenanigans, custom chatboxes, etc. void initialize_chatbox(); @@ -358,7 +359,7 @@ class Courtroom : public QMainWindow QVector ic_chatlog_history; QString last_ic_message; - QQueue chatmessage_queue; + QQueue chatmessage_queue; // triggers ping_server() every 45 seconds QTimer *keepalive_timer; @@ -454,10 +455,8 @@ class Courtroom : public QMainWindow int ghost_blocks = 0; // Minumum and maximum number of parameters in the MS packet - static const int MS_MINIMUM = 15; - static const int MS_MAXIMUM = 32; - QString m_chatmessage[MS_MAXIMUM]; - QString m_previous_chatmessage[MS_MAXIMUM]; + ms2::OldMSFlatData m_chatmessage; + ms2::OldMSFlatData m_previous_chatmessage; QString additive_previous; @@ -486,7 +485,7 @@ class Courtroom : public QMainWindow // cid and this may differ in cases of ini-editing QString current_char; - int objection_state = 0; + ms2::ObjectionMod objection_state = ms2::ObjectionMod::None; QString objection_custom; struct CustomObjection { @@ -811,7 +810,7 @@ public Q_SLOTS: void preanim_done(); void do_screenshake(); void do_flash(); - void do_effect(QString fx_path, QString fx_sound, QString p_char, QString p_folder); + void do_effect(QString p_char, const ms2::EffectData &f_effect, const ms2::OffsetData &f_offset); void play_char_sfx(QString sfx_name); void mod_called(QString p_ip); diff --git a/src/emotes.cpp b/src/emotes.cpp index 9746abcee..57f8536d7 100644 --- a/src/emotes.cpp +++ b/src/emotes.cpp @@ -202,7 +202,7 @@ void Courtroom::select_emote(int p_id) ui_emote_list.at(current_emote % max_emotes_on_page)->setImage(current_char, current_emote, true); } - int emote_mod = ao_app->get_emote_mod(current_char, current_emote); + ms2::EmoteMod emote_mod = ao_app->get_emote_mod(current_char, current_emote); if (old_emote == current_emote) { @@ -210,7 +210,7 @@ void Courtroom::select_emote(int p_id) } else if (!Options::getInstance().clearPreOnPlayEnabled()) { - if (emote_mod == PREANIM || emote_mod == PREANIM_ZOOM) + if (emote_mod == ms2::EmoteMod::Pre || emote_mod == ms2::EmoteMod::PreZoom) { ui_pre->setChecked(true); } diff --git a/src/lobby.h b/src/lobby.h index 0221b5f5c..b678b5f8d 100644 --- a/src/lobby.h +++ b/src/lobby.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include diff --git a/src/packets/msdata.cpp b/src/packets/msdata.cpp new file mode 100644 index 000000000..acfec93c1 --- /dev/null +++ b/src/packets/msdata.cpp @@ -0,0 +1,377 @@ +#include "packets/msdata.h" + +#include + +bool ms2::OldMSFlatData::fromJson(const QJsonObject &f_json, OldMSFlatData &f_data) +{ + if (const QJsonValue v = f_json["desk_mod"]; v.isDouble()) + f_data.m_desk_mod = DeskMod(v.toInt()); + else + return false; + + if (const QJsonValue v = f_json["preanim"]; v.isString()) + f_data.m_preanim = v.toString(); + else + return false; + + if (const QJsonValue v = f_json["char_name"]; v.isString()) + f_data.m_char_name = v.toString(); + else + return false; + + if (const QJsonValue v = f_json["emote"]; v.isString()) + f_data.m_emote = v.toString(); + else + return false; + + if (const QJsonValue v = f_json["message_text"]; v.isString()) + f_data.m_message_text = v.toString(); + else + return false; + + if (const QJsonValue v = f_json["side"]; v.isString()) + { + f_data.m_side = v.toString(); + f_data.m_side.replace("../", "").replace("..\\", ""); + } + else + return false; + + if (const QJsonValue v = f_json["sfx_name"]; v.isString()) + f_data.m_sfx_name = v.toString(); + else + return false; + + if (const QJsonValue v = f_json["emote_mod"]; v.isDouble()) + f_data.m_emote_mod = EmoteMod(v.toInt()); + else + return false; + + if (const QJsonValue v = f_json["char_id"]; v.isDouble()) + f_data.m_char_id = v.toInt(); + else + return false; + + if (const QJsonValue v = f_json["sfx_delay"]; v.isDouble()) + f_data.m_sfx_delay = v.toInt(); + else + return false; + + if (const QJsonValue v = f_json["objection_mod"]; v.isDouble()) + { + f_data.m_objection_mod = ObjectionMod(v.toInt()); + if (f_data.m_objection_mod == ObjectionMod::Custom) + { + if (const QJsonValue v = f_json["objection_custom"]; v.isString()) + f_data.m_objection_custom = v.toString(); + } + } + else + return false; + + if (const QJsonValue v = f_json["evidence"]; v.isDouble()) + f_data.m_evidence = v.toInt(); + else + return false; + + if (const QJsonValue v = f_json["flip"]; v.isBool()) + f_data.m_flip = v.toBool(); + else + return false; + + if (const QJsonValue v = f_json["realisation"]; v.isBool()) + f_data.m_realisation = v.toBool(); + else + return false; + + if (const QJsonValue v = f_json["text_colour"]; v.isDouble()) + f_data.m_text_colour = v.toInt(); + else + return false; + + if (const QJsonValue v = f_json["showname"]; v.isString()) + f_data.m_showname = v.toString(); + + if (const QJsonValue v = f_json["other"]; v.isObject()) + { + OtherData l_other; + QJsonObject l_json = v.toObject(); + if (OtherData::fromJson(l_json, l_other)) + { + f_data.m_other = l_other; + } + } + + if (const QJsonValue v = f_json["offset"]; v.isObject()) + { + OffsetData l_offset{0, 0}; + QJsonObject l_json = v.toObject(); + if (OffsetData::fromJson(l_json, l_offset)) + { + f_data.m_offset = l_offset; + } + } + + if (const QJsonValue v = f_json["immediate"]; v.isBool()) + f_data.m_immediate = v.toBool(); + + if (const QJsonValue v = f_json["sfx_looping"]; v.isBool()) + f_data.m_sfx_looping = v.toBool(); + + if (const QJsonValue v = f_json["screenshake"]; v.isBool()) + f_data.m_screenshake = v.toBool(); + + if (const QJsonValue v = f_json["frames_shake"]; v.isArray()) + { + const QJsonArray frames = v.toArray(); + f_data.m_frames_shake.reserve(frames.size()); + for (const QJsonValue &frame : frames) + { + FrameData l_data{}; + if (frame.isObject() && FrameData::fromJson(frame.toObject(), l_data)) + f_data.m_frames_shake.append(l_data); + } + } + + if (const QJsonValue v = f_json["frames_realisation"]; v.isArray()) + { + const QJsonArray frames = v.toArray(); + f_data.m_frames_realisation.reserve(frames.size()); + for (const QJsonValue &frame : frames) + { + FrameData l_data{}; + if (frame.isObject() && FrameData::fromJson(frame.toObject(), l_data)) + f_data.m_frames_realisation.append(l_data); + } + } + + if (const QJsonValue v = f_json["frames_sfx"]; v.isArray()) + { + const QJsonArray frames = v.toArray(); + f_data.m_frames_sfx.reserve(frames.size()); + for (const QJsonValue &frame : frames) + { + FrameData l_data{}; + if (frame.isObject() && FrameData::fromJson(frame.toObject(), l_data) && !l_data.m_value.isEmpty()) + f_data.m_frames_sfx.append(l_data); + } + } + + if (const QJsonValue v = f_json["additive"]; v.isBool()) + f_data.m_additive = v.toBool(); + + if (const QJsonValue v = f_json["effect"]; v.isObject()) + { + EffectData l_effect{}; + QJsonObject l_json = v.toObject(); + if (EffectData::fromJson(l_json, l_effect)) + { + f_data.m_effect = l_effect; + } + } + + if (const QJsonValue v = f_json["blips"]; v.isString()) + f_data.m_blips = v.toString(); + + if (const QJsonValue v = f_json["slide"]; v.isBool()) + f_data.m_slide = v.toBool(); + + return true; +} + +QJsonObject ms2::OldMSFlatData::toJson() const +{ + QJsonObject json; + + json["desk_mod"] = static_cast(m_desk_mod); + json["preanim"] = m_preanim; + json["char_name"] = m_char_name; + json["emote"] = m_emote; + json["message_text"] = m_message_text; + json["side"] = m_side; + json["sfx_name"] = m_sfx_name; + json["emote_mod"] = static_cast(m_emote_mod); + json["char_id"] = m_char_id; + json["sfx_delay"] = m_sfx_delay; + json["objection_mod"] = static_cast(m_objection_mod); + json["objection_custom"] = m_objection_custom; + json["evidence"] = m_evidence; + json["flip"] = m_flip; + json["realisation"] = m_realisation; + json["text_colour"] = m_text_colour; + json["showname"] = m_showname; + json["other"] = m_other.toJson(); + json["offset"] = m_offset.toJson(); + json["immediate"] = m_immediate; + json["sfx_looping"] = m_sfx_looping; + json["screenshake"] = m_screenshake; + + { + QJsonArray frameShakeArray; + for (const auto &frame : m_frames_shake) + frameShakeArray.append(frame.toJson()); + json["frames_shake"] = frameShakeArray; + } + { + QJsonArray frameRealisationArray; + for (const auto &frame : m_frames_realisation) + frameRealisationArray.append(frame.toJson()); + json["frames_realisation"] = frameRealisationArray; + } + { + QJsonArray frameSfxArray; + for (const auto &frame : m_frames_sfx) + frameSfxArray.append(frame.toJson()); + json["frames_sfx"] = frameSfxArray; + } + + json["additive"] = m_additive; + json["effect"] = m_effect.toJson(); + json["blips"] = m_blips; + json["slide"] = m_slide; + + return json; +} + +bool ms2::FrameData::fromJson(const QJsonObject &f_json, FrameData &f_data) +{ + if (const QJsonValue v = f_json["emote"]; v.isString()) + f_data.m_emote = v.toString(); + else + return false; + + if (const QJsonValue v = f_json["frame"]; v.isDouble()) + f_data.m_frame = v.toInt(); + else + return false; + + if (const QJsonValue v = f_json["value"]; v.isString()) + f_data.m_value = v.toString(); + + return true; +} + +QJsonObject ms2::FrameData::toJson() const +{ + QJsonObject json; + + json["emote"] = m_emote; + json["frame"] = m_frame; + + if (!m_value.isEmpty()) + { + json["value"] = m_value; + } + + return json; +} + +bool ms2::OffsetData::fromJson(const QJsonObject &f_json, OffsetData &f_data) +{ + if (const QJsonValue v = f_json["x"]; v.isDouble()) + f_data.x = std::max(-100, std::min(v.toInt(), 100)); + else + return false; + + if (const QJsonValue v = f_json["y"]; v.isDouble()) + f_data.y = std::max(-100, std::min(v.toInt(), 100)); + else + return false; + + return true; +} + +QJsonObject ms2::OffsetData::toJson() const +{ + QJsonObject json; + + json["x"] = x; + json["y"] = y; + + return json; +} + +bool ms2::OtherData::fromJson(const QJsonObject &f_json, OtherData &f_data) +{ + if (const QJsonValue v = f_json["charid"]; v.isDouble()) + f_data.m_charid = v.toInt(); + else + return false; + + if (const QJsonValue v = f_json["name"]; v.isString()) + f_data.m_name = v.toString(); + else + return false; + + if (const QJsonValue v = f_json["emote"]; v.isString()) + f_data.m_emote = v.toString(); + else + return false; + + if (const QJsonValue v = f_json["offset"]; v.isObject()) + { + OffsetData l_offset{0, 0}; + QJsonObject l_json = v.toObject(); + if (OffsetData::fromJson(l_json, l_offset)) + { + f_data.m_offset = l_offset; + } + else + return false; + } + else + return false; + + if (const QJsonValue v = f_json["flip"]; v.isBool()) + f_data.m_flip = v.toBool(); + else + return false; + + if (const QJsonValue v = f_json["under"]; v.isBool()) + f_data.m_under = v.toBool(); + else + return false; + + return true; +} + +QJsonObject ms2::OtherData::toJson() const +{ + QJsonObject json; + + json["charid"] = m_charid; + json["name"] = m_name; + json["emote"] = m_emote; + json["offset"] = m_offset.toJson(); + json["flip"] = m_flip; + json["under"] = m_under; + + return json; +} + +bool ms2::EffectData::fromJson(const QJsonObject &f_json, EffectData &f_data) +{ + if (const QJsonValue v = f_json["name"]; v.isString()) + f_data.m_name = v.toString(); + else + return false; + + if (const QJsonValue v = f_json["sound"]; v.isString()) + f_data.m_sound = v.toString(); + + if (const QJsonValue v = f_json["folder"]; v.isString()) + f_data.m_folder = v.toString(); + + return true; +} + +QJsonObject ms2::EffectData::toJson() const +{ + QJsonObject json; + + json["name"] = m_name; + json["sound"] = m_sound; + json["folder"] = m_folder; + + return json; +} diff --git a/src/packets/msdata.h b/src/packets/msdata.h new file mode 100644 index 000000000..77b69537e --- /dev/null +++ b/src/packets/msdata.h @@ -0,0 +1,116 @@ +#pragma once + +#include +#include + +namespace ms2 +{ +enum class DeskMod +{ + Hidden = 0, + Shown, + HiddenDuringPreThenShown, + ShowDuringPreThenHidden, + HiddenCentreThenShown, + ShownThenHiddenCentre, +}; + +enum class EmoteMod +{ + Idle = 0, + Pre, + PreAndObject, + Zoom, + PreZoom, +}; + +enum class ObjectionMod +{ + None = 0, + HoldIt, + Objection, + TakeThat, + Custom, +}; + +struct FrameData +{ + QString m_emote; + qint32 m_frame; + QString m_value; + + static bool fromJson(const QJsonObject &f_json, FrameData &f_data); + QJsonObject toJson() const; +}; + +struct OffsetData +{ + qint32 x; + qint32 y; + + static bool fromJson(const QJsonObject &f_json, OffsetData &f_data); + QJsonObject toJson() const; +}; + +struct OtherData +{ + qint32 m_charid; + QString m_name; + QString m_emote; + OffsetData m_offset; + bool m_flip; + bool m_under; + + static bool fromJson(const QJsonObject &f_json, OtherData &f_data); + QJsonObject toJson() const; +}; + +struct EffectData +{ + QString m_name; + QString m_sound; + QString m_folder; + + static bool fromJson(const QJsonObject &f_json, EffectData &f_data); + QJsonObject toJson() const; +}; + +/// This is a super-basic representation of the old MS packet in the flattest JSON form possible. +/// Intentionally minimal types, almost no error checking. +struct OldMSFlatData +{ + DeskMod m_desk_mod; + QString m_preanim; + QString m_char_name; + QString m_emote; + QString m_message_text; + QString m_side; + QString m_sfx_name; + EmoteMod m_emote_mod; + qint32 m_char_id; + qint32 m_sfx_delay; + ObjectionMod m_objection_mod; + QString m_objection_custom; + qint32 m_evidence; + bool m_flip; + bool m_realisation; + qint32 m_text_colour; + QString m_showname; + OffsetData m_offset; + bool m_immediate; + bool m_sfx_looping; + bool m_screenshake; + OtherData m_other; + QList m_frames_shake; + QList m_frames_realisation; + QList m_frames_sfx; + bool m_additive; + EffectData m_effect; + QString m_blips; + bool m_slide; + + /// Returns true if the minimal error-checking it does reported no issues when reading from JSON. + static bool fromJson(const QJsonObject &f_json, OldMSFlatData &f_data); + QJsonObject toJson() const; +}; +} // namespace ms2 diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index 91660c993..424a03269 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -651,7 +651,7 @@ QString AOApplication::get_emote(QString p_char, int p_emote) return result_contents.at(2); } -int AOApplication::get_emote_mod(QString p_char, int p_emote) +ms2::EmoteMod AOApplication::get_emote_mod(QString p_char, int p_emote) { QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); @@ -660,12 +660,26 @@ int AOApplication::get_emote_mod(QString p_char, int p_emote) if (result_contents.size() < 4) { qWarning() << "misformatted char.ini: " << p_char << ", " << QString::number(p_emote); - return 0; + return ms2::EmoteMod::Idle; + } + qint32 l_result = result_contents.at(3).toInt(); + + if (l_result == 3 || l_result == 4) + { + qWarning() << "char.ini refers to unused emote mod: " << p_char << ", " << QString::number(p_emote); + return ms2::EmoteMod::Idle; + } + + if (l_result > 4) + { + // Accounting for the nonexistence of emote mods 3 and 4 in ms2::EmoteMod. + l_result -= 2; } - return result_contents.at(3).toInt(); + + return static_cast(l_result); } -int AOApplication::get_desk_mod(QString p_char, int p_emote) +ms2::DeskMod AOApplication::get_desk_mod(QString p_char, int p_emote) { QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); @@ -673,16 +687,16 @@ int AOApplication::get_desk_mod(QString p_char, int p_emote) if (result_contents.size() < 5) { - return -1; + return ms2::DeskMod::Shown; } QString string_result = result_contents.at(4); if (string_result == "") { - return -1; + return ms2::DeskMod::Shown; } - return string_result.toInt(); + return static_cast(string_result.toInt()); } QString AOApplication::get_sfx_name(QString p_char, int p_emote)