summaryrefslogtreecommitdiff
path: root/ZAPD/ZText.cpp
diff options
context:
space:
mode:
authorbriaguya <70942617+briaguya-ai@users.noreply.github.com>2023-10-17 22:04:12 -0400
committerbriaguya <70942617+briaguya-ai@users.noreply.github.com>2023-10-17 22:04:12 -0400
commite9f4fc638ed904cc0dcdac24ea7708c9a220a702 (patch)
tree114c3d432697e04831741e623ae2340f6239bbe9 /ZAPD/ZText.cpp
parentdcf56d93ecbd4db3bfd8a4832d7f991467964b98 (diff)
update to latest version used by SoH
Diffstat (limited to 'ZAPD/ZText.cpp')
-rw-r--r--ZAPD/ZText.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/ZAPD/ZText.cpp b/ZAPD/ZText.cpp
new file mode 100644
index 0000000..95e4b52
--- /dev/null
+++ b/ZAPD/ZText.cpp
@@ -0,0 +1,137 @@
+#include "ZText.h"
+
+#include "Globals.h"
+#include "Utils/BitConverter.h"
+#include <Utils/DiskFile.h>
+#include "Utils/Path.h"
+#include "Utils/StringHelper.h"
+#include "ZFile.h"
+
+REGISTER_ZFILENODE(Text, ZText);
+
+ZText::ZText(ZFile* nParent) : ZResource(nParent)
+{
+ RegisterRequiredAttribute("CodeOffset");
+ RegisterOptionalAttribute("LangOffset", "0");
+}
+
+void ZText::ParseRawData()
+{
+ ZResource::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;
+
+ if (Globals::Instance->fileMode == ZFileMode::ExtractDirectory)
+ codeData = Globals::Instance->GetBaseromFile("code");
+ else
+ codeData = Globals::Instance->GetBaseromFile(Globals::Instance->baseRomPath.string() + "code");
+
+ while (true)
+ {
+ MessageEntry msgEntry;
+ msgEntry.id = BitConverter::ToInt16BE(codeData, currentPtr + 0);
+ msgEntry.textboxType = (codeData[currentPtr + 2] & 0xF0) >> 4;
+ msgEntry.textboxYPos = (codeData[currentPtr + 2] & 0x0F);
+
+ 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];
+ unsigned int extra = 0;
+ bool stop = false;
+
+ // Continue parsing until we are told to stop and all extra bytes are read
+ while ((c != '\0' && !stop) || extra > 0)
+ {
+ msgEntry.msg += c;
+ msgPtr++;
+
+ // Some control codes require reading extra bytes
+ if (extra == 0)
+ {
+ // End marker, so stop this message and do not read anything else
+ if (c == 0x02)
+ {
+ stop = true;
+ }
+ else if (c == 0x05 || c == 0x13 || c == 0x0E || c == 0x0C || c == 0x1E || c == 0x06 ||
+ c == 0x14)
+ {
+ extra = 1;
+ }
+ // "Continue to new text ID", so stop this message and read two more bytes for the text ID
+ else if (c == 0x07)
+ {
+ extra = 2;
+ stop = true;
+ }
+ else if (c == 0x12 || c == 0x11)
+ {
+ extra = 2;
+ }
+ else if (c == 0x15)
+ {
+ extra = 3;
+ }
+ }
+ else
+ {
+ extra--;
+ }
+
+ c = rawData[msgPtr];
+ }
+
+ messages.push_back(msgEntry);
+
+ if (msgEntry.id == 0xFFFC || msgEntry.id == 0xFFFF)
+ break;
+
+ currentPtr += 8;
+
+ if (isPalLang)
+ langPtr += 4;
+ else
+ langPtr += 8;
+ }
+
+ int bp2 = 0;
+}
+
+std::string ZText::GetSourceTypeName() const
+{
+ return "u8";
+}
+
+size_t ZText::GetRawDataSize() const
+{
+ return 1;
+}
+
+ZResourceType ZText::GetResourceType() const
+{
+ return ZResourceType::Text;
+}