2021-01-28 01:46:58 +00:00
|
|
|
#include <cstdio>
|
2022-07-23 14:30:23 +00:00
|
|
|
|
2021-01-28 01:46:58 +00:00
|
|
|
#include "common/util/BinaryWriter.h"
|
2022-07-23 14:30:23 +00:00
|
|
|
#include "common/util/FileUtil.h"
|
2022-12-22 23:12:59 +00:00
|
|
|
#include "common/util/unicode_util.h"
|
2023-04-22 18:13:57 +00:00
|
|
|
#include "common/versions/versions.h"
|
2021-01-28 01:46:58 +00:00
|
|
|
|
2022-07-23 14:30:23 +00:00
|
|
|
#include "third-party/json.hpp"
|
|
|
|
|
2021-01-28 01:46:58 +00:00
|
|
|
int main(int argc, char** argv) {
|
2022-07-23 14:30:23 +00:00
|
|
|
ArgumentGuard u8_guard(argc, argv);
|
2022-07-06 00:38:13 +00:00
|
|
|
|
2021-01-28 01:46:58 +00:00
|
|
|
printf("OpenGOAL version %d.%d\n", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR);
|
|
|
|
printf("DGO Packing Tool\n");
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
printf("usage: dgo_packer <path> <dgo description file>\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string out_path = argv[1];
|
|
|
|
|
|
|
|
for (int i = 2; i < argc; i++) {
|
|
|
|
std::string file_name = argv[i];
|
|
|
|
std::string file_text = file_util::read_text_file(file_name);
|
|
|
|
|
|
|
|
auto x = nlohmann::json::parse(file_text);
|
|
|
|
std::string out_file_name = x["file_name"];
|
|
|
|
std::string internal_name = x["internal_name"];
|
|
|
|
printf("Packing %s\n", internal_name.c_str());
|
|
|
|
|
|
|
|
BinaryWriter writer;
|
|
|
|
writer.add<u32>(x["objects"].size());
|
|
|
|
writer.add_cstr_len(x["internal_name"].get<std::string>().c_str(), 60);
|
|
|
|
|
|
|
|
for (auto& entry : x["objects"]) {
|
|
|
|
auto obj_data =
|
|
|
|
file_util::read_binary_file(file_util::combine_path(out_path, entry["unique_name"]));
|
2021-03-07 00:06:45 +00:00
|
|
|
auto aligned_size = ((obj_data.size() + 15) / 16) * 16;
|
2021-01-28 01:46:58 +00:00
|
|
|
// size
|
2021-03-07 00:06:45 +00:00
|
|
|
writer.add<uint32_t>(aligned_size);
|
2021-01-28 01:46:58 +00:00
|
|
|
// name
|
|
|
|
writer.add_str_len(entry["internal_name"].get<std::string>().c_str(), 60);
|
|
|
|
// data
|
|
|
|
writer.add_data(obj_data.data(), obj_data.size());
|
|
|
|
// pad
|
2021-03-07 00:06:45 +00:00
|
|
|
while (writer.get_size() & 15) {
|
2021-01-28 01:46:58 +00:00
|
|
|
writer.add<uint8_t>(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
writer.write_to_file(file_util::combine_path(out_path, "mod_" + out_file_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Done\n");
|
|
|
|
return 0;
|
|
|
|
}
|