2022-07-23 10:30:23 -04:00
|
|
|
#include "common/util/Assert.h"
|
|
|
|
#include "common/util/DgoReader.h"
|
2021-10-31 13:12:50 -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
|
|
|
|
2021-10-31 13:12:50 -04:00
|
|
|
#include "decompiler/ObjectFile/LinkedObjectFile.h"
|
|
|
|
#include "decompiler/ObjectFile/LinkedObjectFileCreation.h"
|
2021-12-04 12:33:18 -05:00
|
|
|
#include "decompiler/level_extractor/BspHeader.h"
|
2022-07-23 10:30:23 -04:00
|
|
|
#include "decompiler/util/goal_data_reader.h"
|
2021-10-31 13:12:50 -04:00
|
|
|
|
2022-07-23 10:30:23 -04:00
|
|
|
#include "third-party/fmt/core.h"
|
2021-10-31 13:12:50 -04:00
|
|
|
|
2022-06-06 17:58:49 -04:00
|
|
|
constexpr GameVersion kGameVersion = GameVersion::Jak1;
|
|
|
|
|
2021-10-31 13:12:50 -04:00
|
|
|
/*!
|
|
|
|
* Get the level data from a DGO File.
|
|
|
|
* Will ignore all the other things in the level DGO and just return the bsp file.
|
|
|
|
*/
|
|
|
|
decompiler::LinkedObjectFile load_bsp_from_dgo(const std::string& file_name,
|
|
|
|
decompiler::DecompilerTypeSystem& dts) {
|
|
|
|
std::string short_name = file_util::base_name(file_name);
|
|
|
|
fmt::print("Loading DGO file: {}\n", short_name);
|
|
|
|
auto dgo_file_data = file_util::read_binary_file(file_name);
|
|
|
|
|
|
|
|
auto dgo = DgoReader(short_name, dgo_file_data);
|
|
|
|
auto entries = dgo.entries();
|
2022-02-08 19:02:47 -05:00
|
|
|
ASSERT(entries.size() > 0);
|
2021-10-31 13:12:50 -04:00
|
|
|
|
|
|
|
const auto& level_file = entries.back();
|
|
|
|
|
|
|
|
fmt::print("Using level file: {}, size {} kB\n", level_file.internal_name,
|
|
|
|
level_file.data.size() / 1024);
|
|
|
|
|
2022-06-06 17:58:49 -04:00
|
|
|
return decompiler::to_linked_object_file(level_file.data, level_file.internal_name, dts,
|
|
|
|
kGameVersion);
|
2021-10-31 13:12:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_valid_bsp(const decompiler::LinkedObjectFile& file) {
|
|
|
|
if (file.segments != 1) {
|
|
|
|
fmt::print("Got {} segments, but expected 1\n", file.segments);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& first_word = file.words_by_seg.at(0).at(0);
|
2021-12-04 12:33:18 -05:00
|
|
|
if (first_word.kind() != decompiler::LinkedWord::TYPE_PTR) {
|
2021-10-31 13:12:50 -04:00
|
|
|
fmt::print("Expected the first word to be a type pointer, but it wasn't.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-04 12:33:18 -05:00
|
|
|
if (first_word.symbol_name() != "bsp-header") {
|
|
|
|
fmt::print("Expected to get a bsp-header, but got {} instead.\n", first_word.symbol_name());
|
2021-10-31 13:12:50 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10-31 13:12:50 -04:00
|
|
|
try {
|
|
|
|
fmt::print("Level Dump Tool\n");
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
fmt::print("Usage: level_dump <path-to-dgo>\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt::print("Setting up types...\n");
|
2022-07-08 19:23:49 -04:00
|
|
|
decompiler::DecompilerTypeSystem dts(kGameVersion);
|
2021-10-31 13:12:50 -04:00
|
|
|
dts.parse_type_defs({"decompiler", "config", "all-types.gc"});
|
|
|
|
|
|
|
|
std::string file_name = argv[1];
|
|
|
|
|
|
|
|
fmt::print("Loading data...\n");
|
|
|
|
auto data = load_bsp_from_dgo(file_name, dts);
|
|
|
|
data.set_ordered_label_names();
|
|
|
|
|
|
|
|
if (!is_valid_bsp(data)) {
|
|
|
|
fmt::print("Invalid level file.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
level_tools::DrawStats draw_stats;
|
|
|
|
// draw_stats.debug_print_dma_data = true;
|
|
|
|
level_tools::BspHeader bsp_header;
|
2022-09-05 20:29:12 -04:00
|
|
|
bsp_header.read_from_file(data, dts, &draw_stats, kGameVersion);
|
2021-10-31 13:12:50 -04:00
|
|
|
|
|
|
|
level_tools::PrintSettings settings;
|
|
|
|
fmt::print("{}\n", bsp_header.print(settings));
|
|
|
|
fmt::print("Stats:\n{}\n", draw_stats.print());
|
|
|
|
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
fmt::print("Error: {}\n", e.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2022-07-05 20:38:13 -04:00
|
|
|
}
|