Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions src/courtroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3506,6 +3506,32 @@ void Courtroom::handle_ic_speaking()
start_chat_ticking();
}

struct PauseInfo
{
int ms;
int digit_count;
bool valid;
};

static PauseInfo parse_pause_duration(const QString &text, int start_pos)
{
static const int max_digits = QString::number(10000).length();
static const QRegularExpression pause_regex(QString("^([1-9]\\d{0,%1})").arg(max_digits - 1));
QRegularExpressionMatch match = pause_regex.match(text.mid(start_pos));
if (!match.hasMatch())
{
return {0, 0, false};
}
bool ok = false;
int value = match.captured(1).toInt(&ok);
int length = match.capturedLength(0);
if (!ok || value < 1 || value > 10000)
{
return {0, 0, false};
}
return {value, length, true};
}

QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, int default_color)
{
QString p_text_escaped;
Expand Down Expand Up @@ -3723,6 +3749,14 @@ QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, int
if (f_character == "s" || f_character == "f" || f_character == "p") // screenshake/flash/pause
{
skip = true;
if (f_character == "p") // also skip any following digits
{
PauseInfo info = parse_pause_duration(p_text, check_pos + f_char_bytes);
if (info.valid)
{
check_pos += info.digit_count;
}
}
}

parse_escape_seq = false;
Expand Down Expand Up @@ -4420,6 +4454,14 @@ void Courtroom::chat_tick()
if (f_character == "p")
{
formatting_char = true;
PauseInfo info = parse_pause_duration(f_message, tick_pos);
if (info.valid)
{
tick_pos += info.digit_count;
real_tick_pos += f_char_length;
chat_tick_timer->start(info.ms);
return;
}
}
next_character_is_not_special = false;
}
Expand All @@ -4441,15 +4483,8 @@ void Courtroom::chat_tick()

if ((msg_delay <= 0 && tick_pos < f_message.size() - 1) || formatting_char)
{
if (f_character == "p")
{
chat_tick_timer->start(100); // wait the pause lol
}
else
{
chat_tick_timer->start(0); // Don't bother rendering anything out as we're
// doing the SPEED. (there's latency otherwise)
}
chat_tick_timer->start(0); // Don't bother rendering anything out as we're
// doing the SPEED. (there's latency otherwise)
if (!formatting_char || f_character == "n" || f_character == "f" || f_character == "s" || f_character == "p")
{
real_tick_pos += f_char_length; // Adjust the tick position for the
Expand Down
2 changes: 2 additions & 0 deletions src/courtroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ class Courtroom : public QMainWindow
// amount by which we multiply the delay when we parse punctuation chars
const int punctuation_modifier = 3;

const int max_pause_duration = 10000;

// amount of ghost blocks
int ghost_blocks = 0;

Expand Down
Loading