diff --git a/thcrap_tasofro/src/pl.cpp b/thcrap_tasofro/src/pl.cpp index 5e2613a7..ed60632d 100644 --- a/thcrap_tasofro/src/pl.cpp +++ b/thcrap_tasofro/src/pl.cpp @@ -8,6 +8,7 @@ */ #include +#include "thcrap_tasofro.h" #include "pl.h" void TasofroPl::readField(const char *in, size_t& pos, size_t size, std::string& out) @@ -54,7 +55,7 @@ TasofroPl::ALine* TasofroPl::readLine(const char*& file, size_t& size) if (size > 0 && *file == '#') { pos = 0; - while (file[pos] != '\n') { + while (pos < size && file[pos] != '\n') { pos++; } if (pos > 0 && file[pos - 1] == '\r') { @@ -384,20 +385,18 @@ bool TasofroPl::Text::parseCommand(json_t *patch, int json_line_num) } this->nb_lines = i - json_line_num; - // If this is the staffroll line, try to see if we are in the last balloon. - this->is_staffroll_last_balloon = false; - if (this->is_staffroll) { - unsigned int j; - for (j = i + 1; j < json_array_size(patch); j++) { - line = json_array_get_string(patch, j); - if (strncmp(line, "= json_array_size(patch)) { - this->is_staffroll_last_balloon = true; + // Try to see if we are in the last balloon. + this->is_last_balloon = false; + unsigned int j; + for (j = i + 1; j < json_array_size(patch); j++) { + line = json_array_get_string(patch, j); + if (strncmp(line, "= json_array_size(patch)) { + this->is_last_balloon = true; + } // If the balloon is too small for our text to fit, expand it automatically. if (this->nb_lines > 1 && balloon_size == "05x2") { @@ -441,7 +440,7 @@ void TasofroPl::Text::beginLine(std::list file, std::list::itera this->ignore_clear_balloon = false; - if (this->is_staffroll_last_balloon) { + if (game_id >= TH145 && this->is_last_balloon) { this->last_char = ""; } else if (this->is_staffroll) { @@ -453,7 +452,12 @@ void TasofroPl::Text::patchLine(const char *text, std::list file, std::l { std::string formattedText = text; if (this->cur_line == this->nb_lines) { - formattedText += this->last_char; + if (this->last_char.empty() == false) { + formattedText += this->last_char; + } + else if (this->is_last_balloon == false) { + formattedText += "\\"; + } } if (this->syntax == STORY) { diff --git a/thcrap_tasofro/src/pl.h b/thcrap_tasofro/src/pl.h index acccaa81..b6485d2f 100644 --- a/thcrap_tasofro/src/pl.h +++ b/thcrap_tasofro/src/pl.h @@ -105,7 +105,7 @@ namespace TasofroPl std::string last_char; Syntax syntax; bool is_staffroll; - bool is_staffroll_last_balloon; + bool is_last_balloon; int cur_line; int nb_lines; diff --git a/thcrap_tasofro/src/thcrap_tasofro.h b/thcrap_tasofro/src/thcrap_tasofro.h index cacd520d..80b7b4a5 100644 --- a/thcrap_tasofro/src/thcrap_tasofro.h +++ b/thcrap_tasofro/src/thcrap_tasofro.h @@ -22,6 +22,7 @@ typedef enum { // • filename hash: uses hash = (hash ^ ch) * 0x1000193 // • XOR: uses an additional AUX parameter // • XOR: key compunents are multiplied by -1 + // • endings: the last line in the text may be on another line in the pl file, and it doesn't wait for an input. // • spells: using data/csv/spellcards/*.csv and data/system/char_select3/*/equip/*/000.png.csv TH145,