mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
message
This commit is contained in:
@@ -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());
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user