Implemented PAL language support.

This commit is contained in:
Nicholas Estelami 2022-04-26 15:05:56 -04:00
parent c66c874549
commit bd5a563dae
7 changed files with 113 additions and 127 deletions

View File

@ -12,6 +12,7 @@ REGISTER_ZFILENODE(Text, ZText);
ZText::ZText(ZFile* nParent) : ZResource(nParent)
{
RegisterRequiredAttribute("CodeOffset");
RegisterOptionalAttribute("LangOffset", "0");
}
void ZText::ParseRawData()
@ -20,6 +21,16 @@ void ZText::ParseRawData()
const auto& rawData = parent->GetRawData();
uint32_t currentPtr = StringHelper::StrToL(registeredAttributes.at("CodeOffset").value, 16);
uint32_t langPtr = currentPtr;
bool isPalLang = false;
if (StringHelper::StrToL(registeredAttributes.at("LangOffset").value, 16) != 0)
{
langPtr = StringHelper::StrToL(registeredAttributes.at("LangOffset").value, 16);
if (langPtr != currentPtr)
isPalLang = true;
}
std::vector<uint8_t> codeData;
@ -34,8 +45,18 @@ void ZText::ParseRawData()
msgEntry.id = BitConverter::ToInt16BE(codeData, currentPtr + 0);
msgEntry.textboxType = (codeData[currentPtr + 2] & 0xF0) >> 4;
msgEntry.textboxYPos = (codeData[currentPtr + 2] & 0x0F);
msgEntry.segmentId = (codeData[currentPtr + 4]);
msgEntry.msgOffset = BitConverter::ToInt32BE(codeData, currentPtr + 4) & 0x00FFFFFF;
if (isPalLang)
{
msgEntry.segmentId = (codeData[langPtr + 0]);
msgEntry.msgOffset = BitConverter::ToInt32BE(codeData, langPtr + 0) & 0x00FFFFFF;
}
else
{
msgEntry.segmentId = (codeData[langPtr + 4]);
msgEntry.msgOffset = BitConverter::ToInt32BE(codeData, langPtr + 4) & 0x00FFFFFF;
}
uint32_t msgPtr = msgEntry.msgOffset;
unsigned char c = rawData[msgPtr];
@ -82,6 +103,11 @@ void ZText::ParseRawData()
break;
currentPtr += 8;
if (isPalLang)
langPtr += 4;
else
langPtr += 8;
}
int bp2 = 0;

View File

@ -0,0 +1,5 @@
<Root>
<File Name="fra_message_data_static">
<Text Name="fra_message_data_static" CodeOffset="0x12E4E0" LangOffset="0x134818"/>
</File>
</Root>

View File

@ -0,0 +1,5 @@
<Root>
<File Name="ger_message_data_static">
<Text Name="ger_message_data_static" CodeOffset="0x12E4E0" LangOffset="0x132708"/>
</File>
</Root>

View File

@ -0,0 +1,5 @@
<Root>
<File Name="fra_message_data_static">
<Text Name="fra_message_data_static" CodeOffset="0xF6910" LangOffset="0xFCC48"/>
</File>
</Root>

View File

@ -0,0 +1,5 @@
<Root>
<File Name="ger_message_data_static">
<Text Name="ger_message_data_static" CodeOffset="0xF6910" LangOffset="0xFAB38"/>
</File>
</Root>

View File

@ -8,27 +8,37 @@
#include <Text.h>
extern "C" MessageTableEntry* sNesMessageEntryTablePtr;
extern "C" MessageTableEntry* sGerMessageEntryTablePtr;
extern "C" MessageTableEntry* sFraMessageEntryTablePtr;
extern "C" MessageTableEntry* sStaffMessageEntryTablePtr;
//extern "C" MessageTableEntry* _message_0xFFFC_nes;
//extern "C" MessageTableEntry* _message_0xFFFC_nes;
MessageTableEntry* OTRMessage_LoadTable(const char* filePath, bool isNES) {
auto file = std::static_pointer_cast<Ship::Text>(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(filePath));
if (file == nullptr)
return nullptr;
MessageTableEntry* table = (MessageTableEntry*)malloc(sizeof(MessageTableEntry) * file->messages.size());
for (int i = 0; i < file->messages.size(); i++) {
table[i].textId = file->messages[i].id;
table[i].typePos = (file->messages[i].textboxType << 4) | file->messages[i].textboxYPos;
table[i].segment = file->messages[i].msg.c_str();
table[i].msgSize = file->messages[i].msg.size();
if (isNES && file->messages[i].id == 0xFFFC)
_message_0xFFFC_nes = (char*)file->messages[i].msg.c_str();
}
return table;
}
extern "C" void OTRMessage_Init()
{
auto file = std::static_pointer_cast<Ship::Text>(OTRGlobals::Instance->context->GetResourceManager()->LoadResource("text/nes_message_data_static/nes_message_data_static"));
sNesMessageEntryTablePtr = (MessageTableEntry*)malloc(sizeof(MessageTableEntry) * file->messages.size());
for (int i = 0; i < file->messages.size(); i++)
{
sNesMessageEntryTablePtr[i].textId = file->messages[i].id;
sNesMessageEntryTablePtr[i].typePos = (file->messages[i].textboxType << 4) | file->messages[i].textboxYPos;
sNesMessageEntryTablePtr[i].segment = file->messages[i].msg.c_str();
sNesMessageEntryTablePtr[i].msgSize = file->messages[i].msg.size();
if (file->messages[i].id == 0xFFFC)
{
_message_0xFFFC_nes = (char*)file->messages[i].msg.c_str();
}
}
sNesMessageEntryTablePtr = OTRMessage_LoadTable("text/nes_message_data_static/nes_message_data_static", true);
sGerMessageEntryTablePtr = OTRMessage_LoadTable("text/ger_message_data_static/ger_message_data_static", false);
sFraMessageEntryTablePtr = OTRMessage_LoadTable("text/fra_message_data_static/fra_message_data_static", false);
auto file2 = std::static_pointer_cast<Ship::Text>(OTRGlobals::Instance->context->GetResourceManager()->LoadResource("text/staff_message_data_static/staff_message_data_static"));

View File

@ -33,42 +33,12 @@ s16 sMessageHasSetSfx = false;
u16 sOcarinaSongBitFlags = 0; // ocarina bit flags
MessageTableEntry* sNesMessageEntryTablePtr;
MessageTableEntry* sGerMessageEntryTablePtr;
MessageTableEntry* sFraMessageEntryTablePtr;
MessageTableEntry* sStaffMessageEntryTablePtr;
char* _message_0xFFFC_nes;
//MessageTableEntry sNesMessageEntryTable[] = {
//#define DEFINE_MESSAGE(textId, type, yPos, nesMessage, gerMessage, fraMessage) \
// { textId, (_SHIFTL(type, 4, 8) | _SHIFTL(yPos, 0, 8)), _message_##textId##_nes },
//#define DEFINE_MESSAGE_FFFC
//#include "text/message_data.h"
//#undef DEFINE_MESSAGE_FFFC
//#undef DEFINE_MESSAGE
// { 0xFFFF, 0, NULL },
//};
//
//const char* sGerMessageEntryTable[] = {
//#define DEFINE_MESSAGE(textId, type, yPos, nesMessage, gerMessage, fraMessage) _message_##textId##_ger,
//#include "text/message_data.h"
//#undef DEFINE_MESSAGE
// NULL,
//};
//
//const char* sFraMessageEntryTable[] = {
//#define DEFINE_MESSAGE(textId, type, yPos, nesMessage, gerMessage, fraMessage) _message_##textId##_fra,
//#include "text/message_data.h"
//#undef DEFINE_MESSAGE
// NULL,
//};
//
//MessageTableEntry sStaffMessageEntryTable[] = {
//#define DEFINE_MESSAGE(textId, type, yPos, staffMessage) \
// { textId, (_SHIFTL(type, 4, 8) | _SHIFTL(yPos, 0, 8)), _message_##textId##_staff },
//#include "text/message_data_staff.h"
//#undef DEFINE_MESSAGE
// { 0xFFFF, 0, NULL },
//};
//MessageTableEntry* sNesMessageEntryTablePtr = sNesMessageEntryTable;
//const char** sGerMessageEntryTablePtr = sGerMessageEntryTable;
//const char** sFraMessageEntryTablePtr = sFraMessageEntryTable;
@ -310,69 +280,46 @@ void Message_FindMessage(GlobalContext* globalCtx, u16 textId) {
Font* font;
const char* seg;
if (gSaveContext.language == LANGUAGE_ENG) {
seg = messageTableEntry->segment;
if (gSaveContext.language == LANGUAGE_GER)
messageTableEntry = sGerMessageEntryTablePtr;
else if (gSaveContext.language == LANGUAGE_FRA)
messageTableEntry = sFraMessageEntryTablePtr;
while (messageTableEntry->textId != 0xFFFF) {
font = &globalCtx->msgCtx.font;
// If PAL languages are not present in the OTR file, default to English
if (messageTableEntry == NULL)
messageTableEntry = sNesMessageEntryTablePtr;
if (messageTableEntry->textId == textId) {
foundSeg = messageTableEntry->segment;
font->charTexBuf[0] = messageTableEntry->typePos;
//messageTableEntry++;
nextSeg = messageTableEntry->segment;
font->msgOffset = messageTableEntry->segment;
font->msgLength = messageTableEntry->msgSize;
// "Message found!!!"
osSyncPrintf(" メッセージが,見つかった!!! = %x "
"(data=%x) (data0=%x) (data1=%x) (data2=%x) (data3=%x)\n",
textId, font->msgOffset, font->msgLength, foundSeg, seg, nextSeg);
return;
}
messageTableEntry++;
}
} else {
//languageSegmentTable = (gSaveContext.language == LANGUAGE_GER) ? sGerMessageEntryTablePtr : sFraMessageEntryTablePtr; // OTRTODO
seg = messageTableEntry->segment;
while (messageTableEntry->textId != 0xFFFF) {
font = &globalCtx->msgCtx.font;
if (messageTableEntry->textId == textId) {
foundSeg = *languageSegmentTable;
font->charTexBuf[0] = messageTableEntry->typePos;
languageSegmentTable++;
nextSeg = *languageSegmentTable;
font->msgOffset = foundSeg - seg;
font->msgLength = nextSeg - foundSeg;
// "Message found!!!"
osSyncPrintf(" メッセージが,見つかった!!! = %x "
"(data=%x) (data0=%x) (data1=%x) (data2=%x) (data3=%x)\n",
textId, font->msgOffset, font->msgLength, foundSeg, seg, nextSeg);
return;
}
messageTableEntry++;
languageSegmentTable++;
seg = messageTableEntry->segment;
while (messageTableEntry->textId != 0xFFFF) {
font = &globalCtx->msgCtx.font;
if (messageTableEntry->textId == textId) {
foundSeg = messageTableEntry->segment;
font->charTexBuf[0] = messageTableEntry->typePos;
nextSeg = messageTableEntry->segment;
font->msgOffset = messageTableEntry->segment;
font->msgLength = messageTableEntry->msgSize;
// "Message found!!!"
osSyncPrintf(" メッセージが,見つかった!!! = %x "
"(data=%x) (data0=%x) (data1=%x) (data2=%x) (data3=%x)\n",
textId, font->msgOffset, font->msgLength, foundSeg, seg, nextSeg);
return;
}
messageTableEntry++;
}
// "Message not found!!!"
osSyncPrintf(" メッセージが,見つからなかった!!! = %x\n", textId);
font = &globalCtx->msgCtx.font;
messageTableEntry = sNesMessageEntryTablePtr;
if (gSaveContext.language == LANGUAGE_ENG) {
foundSeg = messageTableEntry->segment;
font->charTexBuf[0] = messageTableEntry->typePos;
messageTableEntry++;
nextSeg = messageTableEntry->segment;
} else {
//languageSegmentTable = (gSaveContext.language == LANGUAGE_GER) ? sGerMessageEntryTablePtr : sFraMessageEntryTablePtr; // OTRTODO
foundSeg = *languageSegmentTable;
font->charTexBuf[0] = messageTableEntry->typePos;
languageSegmentTable++;
nextSeg = *languageSegmentTable;
}
foundSeg = messageTableEntry->segment;
font->charTexBuf[0] = messageTableEntry->typePos;
messageTableEntry++;
nextSeg = messageTableEntry->segment;
font->msgOffset = foundSeg - seg;
font->msgLength = nextSeg - foundSeg;
}
@ -391,7 +338,6 @@ void Message_FindCreditsMessage(GlobalContext* globalCtx, u16 textId) {
if (messageTableEntry->textId == textId) {
foundSeg = messageTableEntry->segment;
font->charTexBuf[0] = messageTableEntry->typePos;
//messageTableEntry++;
nextSeg = messageTableEntry->segment;
font->msgOffset = messageTableEntry->segment;
font->msgLength = messageTableEntry->msgSize;
@ -1145,7 +1091,7 @@ void Message_DrawText(GlobalContext* globalCtx, Gfx** gfxP) {
}
}
if (msgCtx->textDelayTimer == 0) {
msgCtx->textDrawPos = i + 1;
msgCtx->textDrawPos = i + CVar_GetS32("gTextSpeed", 1);
msgCtx->textDelayTimer = msgCtx->textDelay;
} else {
msgCtx->textDelayTimer--;
@ -1640,26 +1586,10 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) {
//DmaMgr_SendRequest1(font->msgBuf, (uintptr_t)(_staff_message_data_staticSegmentRomStart + 4 + font->msgOffset),
//font->msgLength, "../z_message_PAL.c", 1954);
} else {
if (gSaveContext.language == LANGUAGE_ENG)
{
Message_FindMessage(globalCtx, textId);
msgCtx->msgLength = font->msgLength;
char* src = (uintptr_t)font->msgOffset;
memcpy(font->msgBuf, src, font->msgLength);
} else if (gSaveContext.language == LANGUAGE_GER) {
// OTRTODO
//Message_FindMessage(globalCtx, textId);
//msgCtx->msgLength = font->msgLength;
//DmaMgr_SendRequest1(font->msgBuf, (uintptr_t)(_ger_message_data_staticSegmentRomStart + font->msgOffset),
//font->msgLength, "../z_message_PAL.c", 1978);
} else
{
// OTRTODO
//Message_FindMessage(globalCtx, textId);
//msgCtx->msgLength = font->msgLength;
//DmaMgr_SendRequest1(font->msgBuf, (uintptr_t)(_fra_message_data_staticSegmentRomStart + font->msgOffset),
//font->msgLength, "../z_message_PAL.c", 1990);
}
Message_FindMessage(globalCtx, textId);
msgCtx->msgLength = font->msgLength;
char* src = (uintptr_t)font->msgOffset;
memcpy(font->msgBuf, src, font->msgLength);
}
msgCtx->textBoxProperties = font->charTexBuf[0];