allow including shared files via .include_native
This commit is contained in:
+1
-1
@@ -1525,7 +1525,7 @@ Action a_assemble_quest_script(
|
|||||||
? phosg::dirname(input_filename)
|
? phosg::dirname(input_filename)
|
||||||
: ".";
|
: ".";
|
||||||
|
|
||||||
string result = assemble_quest_script(text, include_dir);
|
string result = assemble_quest_script(text, {include_dir, "system/client-functions/System"});
|
||||||
bool compress = !args.get<bool>("decompressed");
|
bool compress = !args.get<bool>("decompressed");
|
||||||
if (compress) {
|
if (compress) {
|
||||||
if (args.get<bool>("optimal")) {
|
if (args.get<bool>("optimal")) {
|
||||||
|
|||||||
+1
-2
@@ -637,8 +637,7 @@ QuestIndex::QuestIndex(
|
|||||||
file_data = decode_dlq_data(phosg::load_file(file_path));
|
file_data = decode_dlq_data(phosg::load_file(file_path));
|
||||||
filename.resize(filename.size() - 4);
|
filename.resize(filename.size() - 4);
|
||||||
} else if (phosg::ends_with(filename, ".bin.txt")) {
|
} else if (phosg::ends_with(filename, ".bin.txt")) {
|
||||||
string include_dir = phosg::dirname(file_path);
|
file_data = assemble_quest_script(phosg::load_file(file_path), {phosg::dirname(file_path), "system/client-functions/System"});
|
||||||
file_data = assemble_quest_script(phosg::load_file(file_path), include_dir);
|
|
||||||
filename.resize(filename.size() - 4);
|
filename.resize(filename.size() - 4);
|
||||||
if (phosg::ends_with(filename, ".bin")) {
|
if (phosg::ends_with(filename, ".bin")) {
|
||||||
filename.push_back('d');
|
filename.push_back('d');
|
||||||
|
|||||||
+14
-3
@@ -3989,7 +3989,7 @@ struct RegisterAssigner {
|
|||||||
array<shared_ptr<Register>, 0x100> numbered_regs;
|
array<shared_ptr<Register>, 0x100> numbered_regs;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string assemble_quest_script(const std::string& text, const std::string& include_directory) {
|
std::string assemble_quest_script(const std::string& text, const vector<string>& include_directories) {
|
||||||
auto lines = phosg::split(text, '\n');
|
auto lines = phosg::split(text, '\n');
|
||||||
|
|
||||||
// Strip comments and whitespace
|
// Strip comments and whitespace
|
||||||
@@ -4198,6 +4198,17 @@ std::string assemble_quest_script(const std::string& text, const std::string& in
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Assemble code segment
|
// Assemble code segment
|
||||||
|
|
||||||
|
auto get_include = [&](const std::string& filename) -> std::string {
|
||||||
|
for (const auto& include_dir : include_directories) {
|
||||||
|
string path = include_dir + "/" + filename;
|
||||||
|
if (phosg::isfile(path)) {
|
||||||
|
return phosg::load_file(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw runtime_error("data not found for include: " + filename);
|
||||||
|
};
|
||||||
|
|
||||||
bool version_has_args = F_HAS_ARGS & v_flag(quest_version);
|
bool version_has_args = F_HAS_ARGS & v_flag(quest_version);
|
||||||
const auto& opcodes = opcodes_by_name_for_version(quest_version);
|
const auto& opcodes = opcodes_by_name_for_version(quest_version);
|
||||||
phosg::StringWriter code_w;
|
phosg::StringWriter code_w;
|
||||||
@@ -4232,12 +4243,12 @@ std::string assemble_quest_script(const std::string& text, const std::string& in
|
|||||||
} else if (phosg::starts_with(line, ".include_bin ")) {
|
} else if (phosg::starts_with(line, ".include_bin ")) {
|
||||||
string filename = line.substr(13);
|
string filename = line.substr(13);
|
||||||
phosg::strip_whitespace(filename);
|
phosg::strip_whitespace(filename);
|
||||||
code_w.write(phosg::load_file(include_directory + "/" + filename));
|
code_w.write(get_include(filename));
|
||||||
} else if (phosg::starts_with(line, ".include_native ")) {
|
} else if (phosg::starts_with(line, ".include_native ")) {
|
||||||
#ifdef HAVE_RESOURCE_FILE
|
#ifdef HAVE_RESOURCE_FILE
|
||||||
string filename = line.substr(16);
|
string filename = line.substr(16);
|
||||||
phosg::strip_whitespace(filename);
|
phosg::strip_whitespace(filename);
|
||||||
string native_text = phosg::load_file(include_directory + "/" + filename);
|
string native_text = get_include(filename);
|
||||||
string code;
|
string code;
|
||||||
if (is_ppc(quest_version)) {
|
if (is_ppc(quest_version)) {
|
||||||
code = std::move(ResourceDASM::PPC32Emulator::assemble(native_text).code);
|
code = std::move(ResourceDASM::PPC32Emulator::assemble(native_text).code);
|
||||||
|
|||||||
+1
-1
@@ -91,6 +91,6 @@ std::string disassemble_quest_script(
|
|||||||
uint8_t override_language = 0xFF,
|
uint8_t override_language = 0xFF,
|
||||||
bool reassembly_mode = false,
|
bool reassembly_mode = false,
|
||||||
bool use_qedit_names = false);
|
bool use_qedit_names = false);
|
||||||
std::string assemble_quest_script(const std::string& text, const std::string& include_directory);
|
std::string assemble_quest_script(const std::string& text, const std::vector<std::string>& include_directories);
|
||||||
|
|
||||||
Episode find_quest_episode_from_script(const void* data, size_t size, Version version);
|
Episode find_quest_episode_from_script(const void* data, size_t size, Version version);
|
||||||
|
|||||||
Reference in New Issue
Block a user