Skip to content
Merged
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
22 changes: 14 additions & 8 deletions code/source/rnd/custom_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern "C" {
#define DEFAULT_WIDTH 8
#define INSTANT_FLAG 0x8000
#define REPEAT_FLAG 0x4000
#define LINE_PADDING(msg) (((msg.flags & 0x00FF0000) == 0x00FF0000) ? 0 : 20)

// Pixel widths of printable characters (many are replaced by * which is 8 pixels)
char width[MAX_CHAR] = {
Expand Down Expand Up @@ -229,8 +230,7 @@ class MsgBuilder {
MsgBuilder* sound(u16 id) {
// Must have a sufficient delay if used multiple times in one box
addCom(0x32);
// Has 2 extra padding bytes if not the first command in a message
pad(*size != 4);
pad(true);
addChr(id & 0xFF);
addChr(id >> 0x8);
addChr(0x00);
Expand Down Expand Up @@ -266,6 +266,10 @@ class MsgBuilder {
addCom(0x31, 0x00);
return addCom(0x00);
}
MsgBuilder* pseudoEnd() {
addCom(0x31, 0x00);
return addCom(0x02);
}

void format(UnformattedMessage msg) {
// @ - filename min: 4px max: 120px
Expand All @@ -279,7 +283,7 @@ class MsgBuilder {
u16 colIdx = 0, colIdxAtLastSpace = 0;
u16 iconIdx = 0, iconIdxAtLastSpace = 0;
u16 delayIdx = 0, delayIdxAtLastSpace = 0;
u16 sizeAtLastSpace = 0, resolvedChar = 0, lineLen = 0;
u16 sizeAtLastSpace = 0, resolvedChar = 0, lineLen = LINE_PADDING(msg);
bool inCol = false, inColAtLastSpace = false;
bool lineWrap = true;
u16 sfx = msg.sfxAndFlags & 0x3FFF;
Expand Down Expand Up @@ -350,7 +354,7 @@ class MsgBuilder {
case '&': // Newline
newline();
lastSpaceIdx = 0;
lineLen = 0;
lineLen = LINE_PADDING(msg);
break;

case '^': // Newbox
Expand All @@ -366,7 +370,7 @@ class MsgBuilder {
instant();

lastSpaceIdx = 0;
lineLen = 0;
lineLen = LINE_PADDING(msg);
break;

case '$': // Icon marker
Expand Down Expand Up @@ -488,7 +492,7 @@ class MsgBuilder {
*size = sizeAtLastSpace;
newline();
lastSpaceIdx = 0;
lineLen = 0;
lineLen = LINE_PADDING(msg);
}
}

Expand All @@ -499,8 +503,10 @@ class MsgBuilder {
#endif
if (msg.id >= 0x1D11 && msg.id <= 0x1D16)
addCom(0x00);
else
else if ((msg.flags & 0x01000000) == 0)
end();
else
pseudoEnd();
}
};

Expand Down Expand Up @@ -535,7 +541,7 @@ bool SetCustomMessage(u16 id, game::MessageResEntry* msgResEntry) {
msgResEntry->id = customMsg.id = id;
msgResEntry->field_2 = customMsgData.field_2;
msgResEntry->field_4 = customMsgData.field_4;
msgResEntry->flags = customMsgData.flags;
msgResEntry->flags = customMsgData.flags & 0x00FFFFFF;
msgResEntry->texts[0].offset = customMsg.data;
msgResEntry->texts[0].length = customMsg.size;
return true;
Expand Down