Skip to content

Commit

Permalink
[jak3] Support jaextern.str, stub for blue fog fix (#3455)
Browse files Browse the repository at this point in the history
  • Loading branch information
water111 authored Apr 7, 2024
1 parent ae0f139 commit 0124a0b
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 15 deletions.
13 changes: 13 additions & 0 deletions decompiler/ObjectFile/ObjectFileDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ ObjectFileDB::ObjectFileDB(const std::vector<fs::path>& _dgos,
const std::vector<fs::path>& object_files,
const std::vector<fs::path>& str_files,
const std::vector<fs::path>& str_tex_files,
const std::vector<fs::path>& str_art_files,
const Config& config)
: dts(config.game_version), m_version(config.game_version) {
Timer timer;
Expand Down Expand Up @@ -237,6 +238,18 @@ ObjectFileDB::ObjectFileDB(const std::vector<fs::path>& _dgos,
}
}

if (!str_art_files.empty()) {
lg::info("-Loading {} streaming art files...", str_art_files.size());
for (auto& obj : str_art_files) {
StrFileReader reader(obj, version());
for (int i = 0; i < reader.chunk_count(); i++) {
auto name = reader.get_chunk_art_name(i);
add_obj_from_dgo(name, name, reader.get_chunk(i).data(), reader.get_chunk(i).size(),
"ARTSPOOL", config, name);
}
}
}

lg::info("ObjectFileDB Initialized");
if (obj_files_by_name.empty()) {
lg::error(
Expand Down
1 change: 1 addition & 0 deletions decompiler/ObjectFile/ObjectFileDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class ObjectFileDB {
const std::vector<fs::path>& object_files,
const std::vector<fs::path>& str_files,
const std::vector<fs::path>& str_tex_files,
const std::vector<fs::path>& str_art_files,
const Config& config);
std::string generate_dgo_listing();
std::string generate_obj_listing(const std::unordered_set<std::string>& merged_objs);
Expand Down
5 changes: 5 additions & 0 deletions decompiler/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ Config make_config_via_json(nlohmann::json& json) {
inputs_json.at("str_texture_file_names").get<std::vector<std::string>>();
}

if (inputs_json.contains("str_art_file_names")) {
config.str_art_file_names =
inputs_json.at("str_art_file_names").get<std::vector<std::string>>();
}

config.audio_dir_file_name = inputs_json.at("audio_dir_file_name").get<std::string>();
config.streamed_audio_file_names =
inputs_json.at("streamed_audio_file_names").get<std::vector<std::string>>();
Expand Down
1 change: 1 addition & 0 deletions decompiler/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct Config {
std::vector<std::string> object_file_names;
std::vector<std::string> str_file_names;
std::vector<std::string> str_texture_file_names;
std::vector<std::string> str_art_file_names;

std::string audio_dir_file_name;
std::vector<std::string> streamed_audio_file_names;
Expand Down
2 changes: 1 addition & 1 deletion decompiler/config/jak3/jak3_config.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

// optional: a predetermined object file name map from a file.
// this will make decompilation naming consistent even if you only run on some objects.
"obj_file_name_map_file": "goal_src/jak3/build/all_objs.json",
// "obj_file_name_map_file": "goal_src/jak3/build/all_objs.json",

////////////////////////////
// LEVEL EXTRACTION
Expand Down
5 changes: 5 additions & 0 deletions decompiler/config/jak3/ntsc_v1/inputs.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@
// some objects are part of STR files (streaming data).
"str_file_names": [],

// streaming "art" that should be added to GAME.FR3.
"str_art_file_names": [
"STR/JAEXTERN.STR"
],

// some objects are directly stored as files on the DVD. This is just text files.
"object_file_names": [
"TEXT/0COMMON.TXT",
Expand Down
15 changes: 15 additions & 0 deletions decompiler/data/StrFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,21 @@ FullName extract_name(const std::string& file_info_name) {

} // namespace

std::string StrFileReader::get_chunk_art_name(int idx) const {
const auto& file_info_string = get_art_group_file_info_string();
const auto& chunk = m_chunks.at(idx);
int offset;
if (find_string_in_data(chunk.data(), int(chunk.size()), file_info_string, &offset)) {
offset += file_info_string.length();
} else {
ASSERT_MSG(false, fmt::format("did not find string '{}'", file_info_string));
}

// extract the name info as a "name" + "chunk id" + "-ag.go" format.
return extract_name(get_string_of_max_length((const char*)(chunk.data() + offset), 128)).name +
"-ag";
}

/*!
* Look inside the chunks to determine the source file name.
* Does a lot of checking, might not work in future versions without some updating.
Expand Down
2 changes: 2 additions & 0 deletions decompiler/data/StrFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class StrFileReader {
explicit StrFileReader(const fs::path& file_path, GameVersion version);
int chunk_count() const;
const std::vector<u8>& get_chunk(int idx) const;
std::string get_chunk_art_name(int idx) const;

std::string get_full_name(const std::string& short_name) const;
std::string get_texture_name() const;

Expand Down
9 changes: 7 additions & 2 deletions decompiler/extractor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void decompile(const fs::path& iso_data_path, const std::string& data_subfolder)
fmt::format("{}_config.jsonc", version_info.game_name),
version_info.decomp_config_version);

std::vector<fs::path> dgos, objs, tex_strs;
std::vector<fs::path> dgos, objs, tex_strs, art_strs;

// grab all DGOS we need (level + common)
// TODO - Jak 2 - jak 1 specific code?
Expand Down Expand Up @@ -141,8 +141,13 @@ void decompile(const fs::path& iso_data_path, const std::string& data_subfolder)
tex_strs.push_back(iso_data_path / str_name);
}

for (const auto& str_name : config.str_art_file_names) {
art_strs.push_back(iso_data_path / str_name);
}

// set up objects
ObjectFileDB db(dgos, fs::path(config.obj_file_name_map_file), objs, {}, tex_strs, config);
ObjectFileDB db(dgos, fs::path(config.obj_file_name_map_file), objs, {}, tex_strs, art_strs,
config);

// save object files
auto out_folder = file_util::get_jak_project_dir() / "decompiler_out" / data_subfolder;
Expand Down
18 changes: 11 additions & 7 deletions decompiler/level_extractor/extract_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ tfrag3::Texture make_texture(u32 id,
void add_all_textures_from_level(tfrag3::Level& lev,
const std::string& level_name,
const TextureDB& tex_db) {
ASSERT(lev.textures.empty());
const auto& level_it = tex_db.texture_ids_per_level.find(level_name);
if (level_it != tex_db.texture_ids_per_level.end()) {
for (auto id : level_it->second) {
Expand Down Expand Up @@ -125,12 +124,14 @@ void extract_art_groups_from_level(const ObjectFileDB& db,
const std::string& dgo_name,
tfrag3::Level& level_data,
std::map<std::string, level_tools::ArtData>& art_group_data) {
const auto& files = db.obj_files_by_dgo.at(dgo_name);
for (const auto& file : files) {
if (file.name.length() > 3 && !file.name.compare(file.name.length() - 3, 3, "-ag")) {
const auto& ag_file = db.lookup_record(file);
extract_merc(ag_file, tex_db, db.dts, tex_remap, level_data, false, db.version());
extract_joint_group(ag_file, db.dts, db.version(), art_group_data);
if (db.obj_files_by_name.count(dgo_name)) {
const auto& files = db.obj_files_by_dgo.at(dgo_name);
for (const auto& file : files) {
if (file.name.length() > 3 && !file.name.compare(file.name.length() - 3, 3, "-ag")) {
const auto& ag_file = db.lookup_record(file);
extract_merc(ag_file, tex_db, db.dts, tex_remap, level_data, false, db.version());
extract_joint_group(ag_file, db.dts, db.version(), art_group_data);
}
}
}
}
Expand Down Expand Up @@ -281,6 +282,9 @@ void extract_common(const ObjectFileDB& db,
add_all_textures_from_level(tfrag_level, dgo_name, tex_db);
extract_art_groups_from_level(db, tex_db, {}, dgo_name, tfrag_level, art_group_data);

add_all_textures_from_level(tfrag_level, "ARTSPOOL", tex_db);
extract_art_groups_from_level(db, tex_db, {}, "ARTSPOOL", tfrag_level, art_group_data);

std::set<std::string> textures_we_have;

// put _all_ index textures in common.
Expand Down
9 changes: 7 additions & 2 deletions decompiler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int main(int argc, char** argv) {

mem_log("After init: {} MB\n", get_peak_rss() / (1024 * 1024));

std::vector<fs::path> dgos, objs, strs, tex_strs;
std::vector<fs::path> dgos, objs, strs, tex_strs, art_strs;
for (const auto& dgo_name : config.dgo_names) {
dgos.push_back(in_folder / dgo_name);
}
Expand All @@ -149,11 +149,16 @@ int main(int argc, char** argv) {
tex_strs.push_back(in_folder / str_name);
}

for (const auto& str_name : config.str_art_file_names) {
art_strs.push_back(in_folder / str_name);
}

mem_log("After config read: {} MB", get_peak_rss() / (1024 * 1024));

// build file database
lg::info("Setting up object file DB...");
ObjectFileDB db(dgos, fs::path(config.obj_file_name_map_file), objs, strs, tex_strs, config);
ObjectFileDB db(dgos, fs::path(config.obj_file_name_map_file), objs, strs, tex_strs, art_strs,
config);

// Explicitly fail if a file in the 'allowed_objects' list wasn't found in the DB
// as this is another silent error that can be confusing
Expand Down
7 changes: 7 additions & 0 deletions goal_src/jak3/engine/gfx/blit-displays.gc
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,12 @@
)
)

;; stub:

(defmethod blit-displays-work-method-19 ((this blit-displays-work))
(set! (-> this slow-time) (- 1.0 (-> *setting-control* user-current slow-time)))
(none)
)

;; DECOMP BEGINS

2 changes: 1 addition & 1 deletion goalc/build_level/jak1/build_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ bool run_build_level(const std::string& input_file,
objs.push_back(iso_folder / obj_name);
}

decompiler::ObjectFileDB db(dgos, fs::path(config.obj_file_name_map_file), objs, {}, {},
decompiler::ObjectFileDB db(dgos, fs::path(config.obj_file_name_map_file), objs, {}, {}, {},
config);

// need to process link data for tpages
Expand Down
2 changes: 1 addition & 1 deletion goalc/build_level/jak2/build_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ bool run_build_level(const std::string& input_file,
objs.push_back(iso_folder / obj_name);
}

decompiler::ObjectFileDB db(dgos, fs::path(config.obj_file_name_map_file), objs, {}, {},
decompiler::ObjectFileDB db(dgos, fs::path(config.obj_file_name_map_file), objs, {}, {}, {},
config);

// need to process link data for tpages
Expand Down
2 changes: 1 addition & 1 deletion test/offline/framework/orchestration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ OfflineTestDecompiler setup_decompiler(const OfflineTestWorkGroup& work,

dc.db = std::make_unique<decompiler::ObjectFileDB>(
dgo_paths, dc.config->obj_file_name_map_file, std::vector<fs::path>{},
std::vector<fs::path>{}, std::vector<fs::path>{}, *dc.config);
std::vector<fs::path>{}, std::vector<fs::path>{}, std::vector<fs::path>{}, *dc.config);
dc.db->dts.art_group_info = dc.config->art_group_info_dump;
dc.db->dts.jg_info = dc.config->jg_info_dump;
dc.db->dts.textures = dc.config->texture_info_dump;
Expand Down

0 comments on commit 0124a0b

Please sign in to comment.