Skip to content

Commit

Permalink
Implements function to return custom message if one exists.
Browse files Browse the repository at this point in the history
`CustomMessage_RetrieveIfExists` is placed at the very beginning of the z_message_PAL.c `Message_OpenText` if statement after any special changes to textIds are made. This function will either return either true or false and if true it will populate the necessary values of font and msgCtx to display said message. It's placement at the beginning also allows for overriding existing textIds to have new information, which will come in handy later.
  • Loading branch information
leggettc18 committed Jul 17, 2022
1 parent f57a912 commit 69d2b5b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
29 changes: 29 additions & 0 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1512,3 +1512,32 @@ extern "C" int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer,
}
return CopyStringToCharBuffer(getItemText, buffer, maxBufferSize);
}

extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx, char* buffer, const int maxBufferSize) {
MessageContext* msgCtx = &globalCtx->msgCtx;
Font* font = &msgCtx->font;
if (gSaveContext.n64ddFlag) {
if (msgCtx->textId == 0xF8) {
if (msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage(
(GetItemID)GET_PLAYER(globalCtx)->getItemId, font->msgBuf, sizeof(font->msgBuf))) {
font->charTexBuf[0] = 0x23;
return true;
} else {
switch (gSaveContext.language) {
case LANGUAGE_FRA:
return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer(
"Il n'y a pas de message personnalisé pour cet élément.", buffer, maxBufferSize);
case LANGUAGE_GER:
return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer(
"Für diesen Artikel gibt es keine benutzerdefinierte Nachricht.", buffer,
maxBufferSize);
case LANGUAGE_ENG:
default:
return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer(
"There is no custom message for this item.", buffer, maxBufferSize);
}
}
}
}
return false;
}
1 change: 1 addition & 0 deletions soh/soh/OTRGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ s32 GetItemIDFromGetItemID(s32 getItemId);
s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum);
s32 GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId);
int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, const int maxBufferSize);
int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx, char* buffer, const int maxBufferSize);
#endif

#endif
8 changes: 5 additions & 3 deletions soh/src/code/z_message_PAL.c
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,9 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) {
gSaveContext.eventInf[0] = gSaveContext.eventInf[1] = gSaveContext.eventInf[2] = gSaveContext.eventInf[3] = 0;
}

if (sTextIsCredits) {
if (CustomMessage_RetrieveIfExists(globalCtx, font->msgBuf, sizeof(font->msgBuf))) {
osSyncPrintf("Found custom message");
} else if (sTextIsCredits) {
Message_FindCreditsMessage(globalCtx, textId);
msgCtx->msgLength = font->msgLength;
char* src = (uintptr_t)font->msgOffset;
Expand Down Expand Up @@ -1735,11 +1737,11 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) {
} else {
msgCtx->msgLength = font->msgLength = CopyGanonHintText(font->msgBuf, sizeof(font->msgBuf));
}
} else if (gSaveContext.n64ddFlag && textId == 0xF8) {
} /*else if (gSaveContext.n64ddFlag && textId == 0xF8) {
msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage(
GET_PLAYER(globalCtx)->getItemId, font->msgBuf, sizeof(font->msgBuf));
font->charTexBuf[0] = 0x23;
} else {
}*/ else {
msgCtx->msgLength = font->msgLength;
char* src = (uintptr_t)font->msgOffset;
memcpy(font->msgBuf, src, font->msgLength);
Expand Down

0 comments on commit 69d2b5b

Please sign in to comment.