Skip to content

Commit

Permalink
Fix find newline looping to have additional break early cases (Harbou…
Browse files Browse the repository at this point in the history
  • Loading branch information
Archez authored Dec 4, 2024
1 parent b442c15 commit 9b169af
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions soh/soh/Enhancements/custom-message/CustomMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,56 +376,62 @@ static size_t NextLineLength(const std::string* textStr, const size_t lastNewlin
}
}


size_t CustomMessage::FindNEWLINE(std::string& str, size_t lastNewline) const {
size_t newLine = str.find(NEWLINE()[0], lastNewline);
bool done;

// Bail out early
if (newLine == std::string::npos) {
return newLine;
}

do {
done = true;
if (newLine != 0){
switch (str[newLine - 1]){
case '\x05'://COLOR
case '\x06'://SHIFT
case '\x07'://TEXTID
case '\x0C'://BOX_BREAK_DELAYED
case '\x0E'://FADE
case '\x11'://FADE2
case '\x12'://SFX
case '\x13'://ITEM_ICON
case '\x14'://TEXT_SPEED
case '\x15'://BACKGROUND
case '\x1E'://POINTS/HIGH_SCORE
if (newLine != 0) {
switch (str[newLine - 1]) {
case '\x05': // COLOR
case '\x06': // SHIFT
case '\x07': // TEXTID
case '\x0C': // BOX_BREAK_DELAYED
case '\x0E': // FADE
case '\x11': // FADE2
case '\x12': // SFX
case '\x13': // ITEM_ICON
case '\x14': // TEXT_SPEED
case '\x15': // BACKGROUND
case '\x1E': // POINTS/HIGH_SCORE
done = false;
break;
default:
break;
}
if (newLine > 1){
switch (str[newLine - 2]){
case '\x07'://TEXTID
case '\x11'://FADE2
case '\x12'://SFX
case '\x15'://BACKGROUND
if (newLine > 1) {
switch (str[newLine - 2]) {
case '\x07': // TEXTID
case '\x11': // FADE2
case '\x12': // SFX
case '\x15': // BACKGROUND
done = false;
break;
default:
break;
}
if (newLine > 2){
if (str[newLine - 3] == '\x15'){//BACKGROUND
if (newLine > 2) {
if (str[newLine - 3] == '\x15') { // BACKGROUND
done = false;
}
}
}
}
if (!done){
if (!done) {
newLine = str.find(NEWLINE()[0], newLine + 1);
if (newLine != std::string::npos){
//if we reach the end of the string, quit now to save a loop
if (newLine == std::string::npos) {
// if we reach the end of the string, quit now to save a loop
done = true;
}
}
} while (!done);

return newLine;
}

Expand Down

0 comments on commit 9b169af

Please sign in to comment.