mirror of
https://github.com/HarbourMasters/Shipwright
synced 2026-08-10 03:25:25 -04:00
7b3efb1e7b
Defines the hook for OnTextLoad. Intercepts message loading with hooks. Adds file to handle the CustomMessage creation for items. Handles Ice Traps, Triforce Pieces, and Custom Items. Handle maps, compasses, and keys Converts gossip stone hints to hook. Handle one-off merchant messages. Convert scrubs and shop text and remove now-unused code Convert Sheik and Ganondorf hint text. Convert skulltula people messages. Convert more static hints Specifically Dampe, Greg, Warp Songs, Frogs, Loach, Fishing Pole, and Saria Convert Biggoron Hint. Convert Big Poes hint. Convert Anju hint dialogue. Convert Malon hint. Convert Horseback Archery hints. Convert Mask Shop SIgn hint Convert Lake Hylia Switch related text. Convert Shooting Gallery bow reminder message Convert random rupee names. Convert Rando-Relevant Navi Enhancement. Convert Random Goron messages Convert Injecting Skull token counts. Add in a way to AutoFormat with an item icon.. Fix some errors with skull tokens and apply icon Convert heart container item counts. Convert Inject Item Count for Heart Pieces. Port Better Bombchu Shopping. Convert Market Sneak Port Quit Fishing At Door and clean up unused stuff. Reintroduce missing Mysterious warp song hint Make ShipInitFuncs static Adds and uses per-item articles for get item messages Fix Entrance Hints and port toggle from dev-copper
115 lines
5.1 KiB
C++
115 lines
5.1 KiB
C++
#include "OTRGlobals.h"
|
|
#include <libultraship/libultraship.h>
|
|
#include "soh/resource/type/Scene.h"
|
|
#include <ship/utils/StringHelper.h>
|
|
#include "global.h"
|
|
#include "vt.h"
|
|
#include "soh/resource/type/Text.h"
|
|
#include <message_data_static.h>
|
|
#include "Enhancements/custom-message/CustomMessageManager.h"
|
|
#include "Enhancements/custom-message/CustomMessageTypes.h"
|
|
|
|
extern "C" MessageTableEntry* sNesMessageEntryTablePtr;
|
|
extern "C" MessageTableEntry* sGerMessageEntryTablePtr;
|
|
extern "C" MessageTableEntry* sFraMessageEntryTablePtr;
|
|
extern "C" MessageTableEntry* sJpnMessageEntryTablePtr;
|
|
extern "C" MessageTableEntry* sStaffMessageEntryTablePtr;
|
|
// extern "C" MessageTableEntry* _message_0xFFFC_nes;
|
|
|
|
static void SetMessageEntry(MessageTableEntry& entry, const SOH::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 = *Ship::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->ListFiles(folderPath).get();
|
|
|
|
for (auto& tPath : lst) {
|
|
auto file = std::static_pointer_cast<SOH::Text>(
|
|
Ship::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<SOH::Text>(Ship::Context::GetInstance()->GetResourceManager()->LoadResource(filePath));
|
|
|
|
if (file == nullptr)
|
|
return nullptr;
|
|
|
|
// Allocate room for an additional message
|
|
// OTRTODO: Should not be malloc'ing here. It's fine for now since we check elsewhere that the message table is
|
|
// already null.
|
|
MessageTableEntry* table = (MessageTableEntry*)malloc(sizeof(MessageTableEntry) * file->messages.size());
|
|
|
|
for (size_t i = 0; i < file->messages.size(); i++) {
|
|
SetMessageEntry(table[i], file->messages[i]);
|
|
|
|
if (isNES && file->messages[i].id == 0xFFFC)
|
|
_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(table[0].textId == 0x0001);
|
|
|
|
return table;
|
|
}
|
|
|
|
extern "C" void OTRMessage_Init() {
|
|
// OTRTODO: Added a lot of null checks here so that we don't malloc the table multiple times causing a memory leak.
|
|
// We really ought to fix the implementation such that we aren't malloc'ing new tables.
|
|
// Once we fix the implementation, remove these NULL checks.
|
|
if (sNesMessageEntryTablePtr == NULL) {
|
|
sNesMessageEntryTablePtr = OTRMessage_LoadTable("text/nes_message_data_static/nes_message_data_static", true);
|
|
}
|
|
if (sGerMessageEntryTablePtr == NULL) {
|
|
sGerMessageEntryTablePtr = OTRMessage_LoadTable("text/ger_message_data_static/ger_message_data_static", false);
|
|
}
|
|
if (sFraMessageEntryTablePtr == NULL) {
|
|
sFraMessageEntryTablePtr = OTRMessage_LoadTable("text/fra_message_data_static/fra_message_data_static", false);
|
|
}
|
|
if (sJpnMessageEntryTablePtr == NULL) {
|
|
sJpnMessageEntryTablePtr = OTRMessage_LoadTable("text/jpn_message_data_static/jpn_message_data_static", false);
|
|
}
|
|
// Note: Make sure this loads after PAL nes_message_data_static, so that message 0xFFFC is definitely loaded if it
|
|
// exists
|
|
if (sNesMessageEntryTablePtr == NULL) {
|
|
sNesMessageEntryTablePtr =
|
|
OTRMessage_LoadTable("text/nes_message_data_static/ntsc_nes_message_data_static", false);
|
|
}
|
|
|
|
if (sStaffMessageEntryTablePtr == NULL) {
|
|
auto file2 =
|
|
std::static_pointer_cast<SOH::Text>(Ship::Context::GetInstance()->GetResourceManager()->LoadResource(
|
|
"text/staff_message_data_static/staff_message_data_static"));
|
|
// OTRTODO: Should not be malloc'ing here. It's fine for now since we check that the message table is already
|
|
// null.
|
|
sStaffMessageEntryTablePtr = (MessageTableEntry*)malloc(sizeof(MessageTableEntry) * file2->messages.size());
|
|
|
|
for (size_t i = 0; i < file2->messages.size(); i++) {
|
|
SetMessageEntry(sStaffMessageEntryTablePtr[i], file2->messages[i]);
|
|
}
|
|
OTRMessage_LoadCustom("override/text/staff_message_data_static/*", sStaffMessageEntryTablePtr,
|
|
file2->messages.size());
|
|
|
|
// Assert staff credits start at the first credits ID
|
|
assert(sStaffMessageEntryTablePtr[0].textId == 0x0500);
|
|
}
|
|
}
|