Skip to content

Commit

Permalink
Create helpers for making custom messages (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto-Nessy authored Aug 10, 2023
1 parent 284cb79 commit 1a9d09a
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 2 deletions.
19 changes: 19 additions & 0 deletions code/include/rnd/custom_message.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef _RND_CUSTOM_MESSAGE_H_
#define _RND_CUSTOM_MESSAGE_H_

#include "common/utils.h"

#define MAX_MSG_SIZE 512

void CustomMessage_Init(void);

typedef struct {
char data[MAX_MSG_SIZE];
u16 size;
} CustomMessage;

/*----- Custom Message Declarations -----*/
extern CustomMessage iceTrapMsg;
/*----- Custom Message Declarations -----*/

#endif
5 changes: 3 additions & 2 deletions code/source/game/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Brought in from the Project Restoration libraries. Modified for custom messages.
*/
#include "game/message.h"
#include "rnd/custom_message.h"

#include "common/utils.h"

Expand Down Expand Up @@ -67,8 +68,8 @@ namespace game {
customIceMessage.flags = 0xFF0000;
// customIceMessage.texts[0].offset = "Hmmph... I've been made a
// \x7f:\x00\x01\x00\x46OOL\x7f\x00:\x00\x0b\x00 of!\x7f\x00\x31";
customIceMessage.texts[0].offset = " \x7f:\x00\x01\x00\x46OOL!\x7f:\x00\x0b\x00\x7f\x00\x31";
customIceMessage.texts[0].length = 22;
customIceMessage.texts[0].offset = iceTrapMsg.data;
customIceMessage.texts[0].length = iceTrapMsg.size;
entry = &customIceMessage;
isCustom = true;
} else if (id == 0x0037) {
Expand Down
2 changes: 2 additions & 0 deletions code/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "game/sound.h"
#include "game/states/state.h"
#include "game/ui.h"
#include "rnd/custom_message.h"
#include "rnd/extdata.h"
#include "rnd/icetrap.h"
#include "rnd/item_override.h"
Expand All @@ -28,6 +29,7 @@ namespace rnd {

rHeap_Init();
ItemOverride_Init();
CustomMessage_Init();
// SaveFile_LoadExtSaveData(1);
// TODO: Maybe make this an option?
link::FixSpeedIssues();
Expand Down
136 changes: 136 additions & 0 deletions code/source/rnd/custom_messages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#include "rnd/custom_message.h"

/*----- Custom Message Declarations -----*/
CustomMessage iceTrapMsg;
/*----- Custom Message Declarations -----*/

typedef enum {
blank = 0x00,
aButton,
bButton,
xButton,
yButton,
lButton,
rButton,
startButton,
homeButton,
powerButton,
dPad,
dPadUp,
dPadRight,
dPadDown,
dPadLeft,
dPadVertical,
dPadHorizontal,
cPad,
cPadUp,
cPadRight,
cPadDown,
cPadLeft,
cPadVertical,
cPadHorizontal,
touchI,
touchX,
touchY,
touchII,
touchItems,

touchMasks = 0x1E,
touchOcarina,
touchPictobox,
targetReticle,

sun = 0x28,
moon,
oneBlock,
twoBlock,
threeBlock,
touchGear,
touchMap,
flag,
tatl,
tilde,
notebook,
firstPerson,
zlButton,
zrButton,
majora,
} iconList;

typedef enum {
WHITE,
RED,
GREEN,
BLUE,
YELLOW,
CYAN,
MAGENTA,
GREY,
ORANGE,
DARK_GREY,
BLACK,
DEFAULT,
} colList;

class MsgBuilder {
public:
char* data;
u16* size;

MsgBuilder* set(CustomMessage* msg) {
data = &msg->data[0];
size = &msg->size;
return this;
}

MsgBuilder* addChr(char chr, bool txt = false) {
if (*size < MAX_MSG_SIZE)
data[(*size)++] = chr;
return this;
}

MsgBuilder* text(const char* txt) {
for (u16 idx = 0; txt[idx]; idx++)
addChr(txt[idx], true);
return this;
}

MsgBuilder* addCom(char com) {
addChr(0x7f);
if (*size % 2)
addChr(0x00);
addChr(com);
return addChr(0x00);
}

MsgBuilder* addCom(char com, char arg) {
addCom(com);
addChr(arg);
return addChr(0x00);
}

MsgBuilder* col(colList c) { return addCom(0x3a, c); } // Change text colour until used again or new box
MsgBuilder* icon(iconList img) { return addCom(0x25, img); } // Insert an icon. See: https://cdn.discordapp.com/attachments/896879784162918400/1138941632675328010/image.png
MsgBuilder* delay(char time) { return addCom(0x29, time); } // Time measured in 20ths of a second
MsgBuilder* top() { return addCom(0x28); } // Applies to all boxes in message
MsgBuilder* instant() { return addCom(0x27); } // Applies only to current box
MsgBuilder* newline() { return addCom(0x01); }
MsgBuilder* newBox() { addCom(0x31, 0x01); return addCom(0x02); }
MsgBuilder* end() { addCom(0x31, 0x00); return addCom(0x00); }
};

MsgBuilder builder;
bool init = false;

void CustomMessage_Init(void) {
if (!init) {
// ----- Custom Message Definitions -----
builder.set(&iceTrapMsg)->instant()->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->text("You")->delay(10)->newline()
->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->text("are")->delay(10)->newline()
->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->text(" a")->delay(20)->newline()
->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->col(RED)->text(" FOOL")->col(WHITE)->text("!")->newBox()

->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->icon(blank)->col(YELLOW)->text("<3")->end();
}
init = true;
}

0 comments on commit 1a9d09a

Please sign in to comment.