jak-project/tools/dgo_unpacker.cpp
water111 8846968963
[Debugger] windows debugger and process drawable (#953)
* Update assert.h

* stuff for `process-drawable` to work

* add windows code for debugger

* debugger attaches

* something works

* remove bad ideas

* `(:break)` works

* connection fixes

* fixes + update docs

* crates & `defskelgroup` macro

* clang

* update tests and a few types

* temp

* temp

* fix files

* game builds

* reverse TypeConsistency operation

* add eye stuff for merc art login

* add `(:sym-name)`

* oops

* add `--auto-dbg` option to gc args

* codacy

* improve robustness of dgo unpacker and objectfiledb reading

* `cavegeyserrock`

* hopefully fix linux

* windows FormatMessage weirdness?

* mutex fixes

* fix merge conflicts

Co-authored-by: ManDude <7569514+ManDude@users.noreply.github.com>
2021-10-31 11:01:15 -04:00

58 lines
1.8 KiB
C++

#include <cstdio>
#include <stdexcept>
#include "common/versions.h"
#include "common/util/FileUtil.h"
#include "common/util/DgoReader.h"
namespace {
int run(int argc, char** argv) {
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);
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());
}
// read as a DGO
auto dgo = DgoReader(base, data);
// write dgo description
file_util::create_dir_if_needed(out_path);
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),
(const void*)entry.data.data(), entry.data.size());
}
}
printf("Done\n");
return 0;
}
} // namespace
int main(int argc, char** argv) {
try {
return run(argc, argv);
} catch (const std::exception& e) {
printf("An error occurred: %s\n", e.what());
return 1;
}
}