Skip to content

Commit

Permalink
Moar text fixes (HarbourMasters#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjoecox authored Jan 16, 2024
1 parent aaf3714 commit b4d8c21
Showing 1 changed file with 20 additions and 38 deletions.
58 changes: 20 additions & 38 deletions ZAPD/ZTextMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,50 +65,32 @@ void ZTextMM::ParseMM()
msgPtr += 11;

unsigned char c = rawData[msgPtr];
unsigned int extra = 0;
bool stop = false;
bool shouldTerminateOnNull = parent->GetName() == "staff_message_data_static";

// Continue parsing until we are told to stop and all extra bytes are read
while (( (c != '\0' || !shouldTerminateOnNull) && !stop) || extra > 0)
{
// Read until end marker (0xBF)
while (true) {
msgEntry.msg += c;
msgPtr++;

// Some control codes require reading extra bytes
if (extra == 0)
{
// End marker, so stop this message and do not read anything else
if (c == 0xBF)
{
stop = true;
}
else if (c == 0x05 || c == 0x13 || c == 0x0E || c == 0x0C || c == 0x1E ||
c == 0x06 || c == 0x14)
{
extra = 1;
}
// "Continue to new text ID", so stop this message and read two more bytes for the
// text ID
else if (c == 0x07)
{
extra = 2;
stop = true;
}
else if (c == 0x12 || c == 0x11)
{
extra = 2;
}
else if (c == 0x15)
{
extra = 3;
}
if (c == 0xBF) { // End marker
break;
}
else
{
extra--;

switch (c) {
case 0x14: // Print: xx Spaces
msgEntry.msg += rawData[msgPtr + 1];
msgPtr++;
break;
case 0x1B: // Delay for xxxx Before Printing Remaining Text
case 0x1C: // Keep Text on Screen for xxxx Before Closing
case 0x1D: // Delay for xxxx Before Ending Conversation
case 0x1E: // Play Sound Effect xxxx
case 0x1F: // Delay for xxxx Before Resuming Text Flow
msgEntry.msg += rawData[msgPtr + 1];
msgEntry.msg += rawData[msgPtr + 2];
msgPtr += 2;
break;
}

msgPtr++;
c = rawData[msgPtr];
}

Expand Down

0 comments on commit b4d8c21

Please sign in to comment.