mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-25 19:02:19 -05:00
Custom message loading (#3713)
* Add custom text message loading * Use "override" folder for text mods * Replace only existing messages * Use std::find_if to check for existing messages
This commit is contained in:
parent
01529126ba
commit
bfe2f58feb
@ -15,7 +15,34 @@ extern "C" MessageTableEntry* sFraMessageEntryTablePtr;
|
|||||||
extern "C" MessageTableEntry* sStaffMessageEntryTablePtr;
|
extern "C" MessageTableEntry* sStaffMessageEntryTablePtr;
|
||||||
//extern "C" MessageTableEntry* _message_0xFFFC_nes;
|
//extern "C" MessageTableEntry* _message_0xFFFC_nes;
|
||||||
|
|
||||||
MessageTableEntry* OTRMessage_LoadTable(const char* filePath, bool isNES) {
|
static void SetMessageEntry(MessageTableEntry& entry, const LUS::MessageEntry& msgEntry) {
|
||||||
|
entry.textId = msgEntry.id;
|
||||||
|
entry.typePos = (msgEntry.textboxType << 4) | msgEntry.textboxYPos;
|
||||||
|
entry.segment = msgEntry.msg.c_str();
|
||||||
|
entry.msgSize = msgEntry.msg.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OTRMessage_LoadCustom(const std::string& folderPath, MessageTableEntry*& table, size_t tableSize) {
|
||||||
|
auto lst = *LUS::Context::GetInstance()->GetResourceManager()->GetArchive()->ListFiles(folderPath).get();
|
||||||
|
|
||||||
|
for (auto& tPath : lst) {
|
||||||
|
auto file = std::static_pointer_cast<LUS::Text>(LUS::Context::GetInstance()->GetResourceManager()->LoadResource(tPath));
|
||||||
|
|
||||||
|
for (size_t j = 0; j < file->messages.size(); ++j) {
|
||||||
|
// Check if same text ID exists already
|
||||||
|
auto existingEntry = std::find_if(table, table + tableSize, [id = file->messages[j].id](const auto& entry) {
|
||||||
|
return entry.textId == id;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (existingEntry != table + tableSize) {
|
||||||
|
// Replace existing message
|
||||||
|
SetMessageEntry(*existingEntry, file->messages[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageTableEntry* OTRMessage_LoadTable(const std::string& filePath, bool isNES) {
|
||||||
auto file = std::static_pointer_cast<LUS::Text>(LUS::Context::GetInstance()->GetResourceManager()->LoadResource(filePath));
|
auto file = std::static_pointer_cast<LUS::Text>(LUS::Context::GetInstance()->GetResourceManager()->LoadResource(filePath));
|
||||||
|
|
||||||
if (file == nullptr)
|
if (file == nullptr)
|
||||||
@ -63,14 +90,12 @@ MessageTableEntry* OTRMessage_LoadTable(const char* filePath, bool isNES) {
|
|||||||
table[file->messages.size()].msgSize = kaeporaMsgSize;
|
table[file->messages.size()].msgSize = kaeporaMsgSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
table[i].textId = file->messages[i].id;
|
SetMessageEntry(table[i], file->messages[i]);
|
||||||
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)
|
if (isNES && file->messages[i].id == 0xFFFC)
|
||||||
_message_0xFFFC_nes = (char*)file->messages[i].msg.c_str();
|
_message_0xFFFC_nes = (char*)file->messages[i].msg.c_str();
|
||||||
}
|
}
|
||||||
|
OTRMessage_LoadCustom("override/" + filePath.substr(0, filePath.find_last_of('/')) + "/*", table, file->messages.size() + 1);
|
||||||
|
|
||||||
// Assert that the first message starts at the first text ID
|
// Assert that the first message starts at the first text ID
|
||||||
assert(table[0].textId == 0x0001);
|
assert(table[0].textId == 0x0001);
|
||||||
@ -101,12 +126,9 @@ extern "C" void OTRMessage_Init()
|
|||||||
sStaffMessageEntryTablePtr = (MessageTableEntry*)malloc(sizeof(MessageTableEntry) * file2->messages.size());
|
sStaffMessageEntryTablePtr = (MessageTableEntry*)malloc(sizeof(MessageTableEntry) * file2->messages.size());
|
||||||
|
|
||||||
for (size_t i = 0; i < file2->messages.size(); i++) {
|
for (size_t i = 0; i < file2->messages.size(); i++) {
|
||||||
sStaffMessageEntryTablePtr[i].textId = file2->messages[i].id;
|
SetMessageEntry(sStaffMessageEntryTablePtr[i], file2->messages[i]);
|
||||||
sStaffMessageEntryTablePtr[i].typePos =
|
|
||||||
(file2->messages[i].textboxType << 4) | file2->messages[i].textboxYPos;
|
|
||||||
sStaffMessageEntryTablePtr[i].segment = file2->messages[i].msg.c_str();
|
|
||||||
sStaffMessageEntryTablePtr[i].msgSize = file2->messages[i].msg.size();
|
|
||||||
}
|
}
|
||||||
|
OTRMessage_LoadCustom("override/text/staff_message_data_static/*", sStaffMessageEntryTablePtr, file2->messages.size());
|
||||||
|
|
||||||
// Assert staff credits start at the first credits ID
|
// Assert staff credits start at the first credits ID
|
||||||
assert(sStaffMessageEntryTablePtr[0].textId == 0x0500);
|
assert(sStaffMessageEntryTablePtr[0].textId == 0x0500);
|
||||||
|
Loading…
Reference in New Issue
Block a user