2021-01-27 20:46:58 -05:00
|
|
|
#include <cstdio>
|
2021-07-24 11:17:27 -04:00
|
|
|
#include <stdexcept>
|
2022-07-23 10:30:23 -04:00
|
|
|
|
2021-01-27 20:46:58 -05:00
|
|
|
#include "common/util/DgoReader.h"
|
2022-07-23 10:30:23 -04:00
|
|
|
#include "common/util/FileUtil.h"
|
2022-12-22 18:12:59 -05:00
|
|
|
#include "common/util/unicode_util.h"
|
2022-07-23 10:30:23 -04:00
|
|
|
#include "common/versions.h"
|
2021-01-27 20:46:58 -05:00
|
|
|
|
2021-07-24 11:17:27 -04:00
|
|
|
namespace {
|
|
|
|
int run(int argc, char** argv) {
|
2021-01-27 20:46:58 -05:00
|
|
|
printf("OpenGOAL version %d.%d\n", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR);
|
|
|
|
printf("DGO Unpacking Tool\n");
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
printf("usage: dgo_unpacker <output path> <dgo files>\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string out_path = argv[1];
|
|
|
|
|
|
|
|
for (int i = 2; i < argc; i++) {
|
|
|
|
std::string file_name = argv[i];
|
|
|
|
std::string base = file_util::base_name(file_name);
|
|
|
|
printf("Unpacking %s\n", base.c_str());
|
|
|
|
// read the file
|
|
|
|
auto data = file_util::read_binary_file(file_name);
|
2021-03-06 16:06:08 -05:00
|
|
|
if (file_util::dgo_header_is_compressed(data)) {
|
|
|
|
printf(" Detected compressed dgo, decompressing...\n");
|
|
|
|
auto original_size = data.size();
|
|
|
|
data = file_util::decompress_dgo(data);
|
|
|
|
printf(" Decompressed from %d to %d bytes (%.2f%% compression)\n", int(original_size),
|
|
|
|
int(data.size()), 100.f * original_size / data.size());
|
|
|
|
}
|
2021-01-27 20:46:58 -05:00
|
|
|
// read as a DGO
|
|
|
|
auto dgo = DgoReader(base, data);
|
|
|
|
// write dgo description
|
2021-10-31 11:01:15 -04:00
|
|
|
file_util::create_dir_if_needed(out_path);
|
2021-01-27 20:46:58 -05:00
|
|
|
file_util::write_text_file(file_util::combine_path(out_path, base + ".txt"),
|
|
|
|
dgo.description_as_json());
|
|
|
|
// write files:
|
|
|
|
for (auto& entry : dgo.entries()) {
|
|
|
|
file_util::write_binary_file(file_util::combine_path(out_path, entry.unique_name),
|
2021-02-05 19:41:09 -05:00
|
|
|
(const void*)entry.data.data(), entry.data.size());
|
2021-01-27 20:46:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Done\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2021-07-24 11:17:27 -04:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2022-07-23 10:30:23 -04:00
|
|
|
ArgumentGuard u8_guard(argc, argv);
|
2022-07-05 20:38:13 -04:00
|
|
|
|
2021-07-24 11:17:27 -04:00
|
|
|
try {
|
|
|
|
return run(argc, argv);
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
printf("An error occurred: %s\n", e.what());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|