summaryrefslogtreecommitdiff
path: root/src/factories
diff options
context:
space:
mode:
authorpetrie911 <petrie911@yahoo.com>2024-04-24 05:05:49 -0500
committerLywx <kiritodev01@gmail.com>2024-04-24 13:41:23 -0600
commitdf54367b676f44d2b925e681ae05eef665f7c45f (patch)
tree50ba65d2ed4471fd3d2aad9316f1de24e06ed0a1 /src/factories
parent91e834d819c82f0d64cf4f71ea9d1788c9135bda (diff)
message
Diffstat (limited to 'src/factories')
-rw-r--r--src/factories/sf64/MessageFactory.cpp81
-rw-r--r--src/factories/sf64/MessageFactory.h3
-rw-r--r--src/factories/sf64/ScriptFactory.cpp16
3 files changed, 51 insertions, 49 deletions
diff --git a/src/factories/sf64/MessageFactory.cpp b/src/factories/sf64/MessageFactory.cpp
index c8d5ae5..ee1beb0 100644
--- a/src/factories/sf64/MessageFactory.cpp
+++ b/src/factories/sf64/MessageFactory.cpp
@@ -3,11 +3,12 @@
#include "utils/Decompressor.h"
#include "spdlog/spdlog.h"
#include "Companion.h"
+#include <regex>
-#define END_CODE 0x0
-#define NEWLINE_CODE 0x1
-#define SPC 15
-#define CLF 16
+#define END_CODE 0
+#define NEWLINE_CODE 1
+#define NXT_CODE 15
+#define CLF_CODE 16
#define CUP 17
#define CRT 18
#define CDN 19
@@ -61,48 +62,13 @@ ExportResult SF64::MessageHeaderExporter::Export(std::ostream &write, std::share
return std::nullopt;
}
-void TextToStream(std::ostream& stream, int charCode) {
- std::string enumCode = gCharCodeEnums[charCode];
-
- if(enumCode.starts_with("_")){
- stream << enumCode.substr(1);
- return;
- }
-
- if(ASCIITable.contains(enumCode)){
- stream << ASCIITable[enumCode];
- }
-}
-
ExportResult SF64::MessageCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto message = std::static_pointer_cast<MessageData>(raw)->mMessage;
+ auto mesgStr = std::static_pointer_cast<MessageData>(raw)->mMesgStr;
const auto symbol = GetSafeNode(node, "symbol", entryName);
auto offset = GetSafeNode<uint32_t>(node, "offset");
- write << "// ";
- bool lastWasSpace = false;
- for (int i = 0; i < message.size(); ++i) {
- const auto charCode = message[i];
- std::string enumCode = gCharCodeEnums[charCode];
-
- if(enumCode.find("SP") != std::string::npos){
- if (lastWasSpace){
- continue;
- }
- if (!enumCode.empty() && enumCode.back() != ' ') {
- write << " ";
- lastWasSpace = true;
- }
- } else {
- lastWasSpace = false;
- }
-
- TextToStream(write,charCode );
- if(message[i] == NEWLINE_CODE && i != message.size() - 2){
- write << "\n// ";
- }
- }
- write << "\n";
+ write << "// " << std::regex_replace(mesgStr, std::regex(R"(\n)"), "\n// ") << "\n";
write << "u16 " << symbol << "[] = {\n" << fourSpaceTab;
for (int i = 0; i < message.size(); ++i) {
@@ -141,17 +107,36 @@ ExportResult SF64::MessageBinaryExporter::Export(std::ostream &write, std::share
std::optional<std::shared_ptr<IParsedData>> SF64::MessageFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
std::vector<uint16_t> message;
-
+ std::ostringstream mesgStr;
auto [_, segment] = Decompressor::AutoDecode(node, buffer);
LUS::BinaryReader reader(segment.data, segment.size);
reader.SetEndianness(LUS::Endianness::Big);
- bool processing = true;
- while(processing){
- uint16_t c = reader.ReadUInt16();
+ uint16_t c;
+ bool lastWasSpace = false;
+ std::string whitespace = "";
+ do {
+ c = reader.ReadUInt16();
message.push_back(c);
- processing = c != END_CODE;
- }
- return std::make_shared<MessageData>(message);
+ std::string enumCode = gCharCodeEnums[c];
+ if((enumCode.find("SP") != std::string::npos) && whitespace.empty()) {
+ whitespace = " ";
+ }
+ if(c == NEWLINE_CODE) {
+ whitespace += "\n";
+ }
+ if (c >= CLF_CODE) {
+ mesgStr << whitespace;
+ whitespace = "";
+ }
+ if(enumCode.starts_with("_")){
+ mesgStr << enumCode.substr(1);
+ } else if(ASCIITable.contains(enumCode)){
+ mesgStr << ASCIITable[enumCode];
+ }
+
+ } while(c != END_CODE);
+
+ return std::make_shared<MessageData>(message, mesgStr.str());
} \ No newline at end of file
diff --git a/src/factories/sf64/MessageFactory.h b/src/factories/sf64/MessageFactory.h
index f59ae91..9b119f6 100644
--- a/src/factories/sf64/MessageFactory.h
+++ b/src/factories/sf64/MessageFactory.h
@@ -7,8 +7,9 @@ namespace SF64 {
class MessageData : public IParsedData {
public:
std::vector<uint16_t> mMessage;
+ std::string mMesgStr;
- MessageData(std::vector<uint16_t> message) : mMessage(message) {}
+ MessageData(std::vector<uint16_t> message, std::string mesgStr) : mMessage(message), mMesgStr(mesgStr) {}
};
class MessageCodeExporter : public BaseExporter {
diff --git a/src/factories/sf64/ScriptFactory.cpp b/src/factories/sf64/ScriptFactory.cpp
index b968e23..d925046 100644
--- a/src/factories/sf64/ScriptFactory.cpp
+++ b/src/factories/sf64/ScriptFactory.cpp
@@ -4,6 +4,7 @@
#include "Companion.h"
#include "utils/Decompressor.h"
#include "utils/TorchUtils.h"
+#include "factories/sf64/MessageFactory.h"
#include <regex>
#include "storm/SWrapper.h"
@@ -28,6 +29,17 @@ ExportResult SF64::ScriptHeaderExporter::Export(std::ostream &write, std::shared
return std::nullopt;
}
+std::string GetMsg(uint16_t msgId) {
+ std::string msg = "";
+ auto rawmsg = Companion::Instance->GetParseDataBySymbol("gMsg_ID_" + std::to_string(msgId));
+
+ if(rawmsg.has_value() && rawmsg.value().data.has_value()) {
+ auto msgData = std::static_pointer_cast<SF64::MessageData>(rawmsg.value().data.value());
+ auto msg = std::regex_replace(msgData->mMesgStr, std::regex(R"(\n)"), " ");
+ }
+ return msg;
+}
+
std::string MakeScriptCmd(uint16_t s1, uint16_t s2) {
auto opcode = (s1 & 0xFE00) >> 9;
auto arg1 = s1 & 0x1FF;
@@ -136,6 +148,10 @@ std::string MakeScriptCmd(uint16_t s1, uint16_t s2) {
case 120: {
auto rcidName = VALUE_TO_ENUM(arg1, "RadioCharacterId", "RCID_UNK");
cmd << "EVENT_PLAY_MSG(" << rcidName << ", " << std::dec << s2;
+ auto msg = GetMsg(s2);
+ if(!msg.empty()) {
+ comment << " // " << msg;
+ }
} break;
case 121: {
auto teamId = VALUE_TO_ENUM(s2, "TeamId", "TEAMID_UNK");