PAL & NTSC-J support + updates (#1490)

* PAL dumps files

* alrighty then

* make PAL warning slightly more specific

* PAL patches for `title-obs`

* Update all-types.gc

* PAL patch `beach-obs`

* `process-taskable` PAL patch

* `ambient` PAL patch

* `yakow` PAL patch

* `village-obs` PAL patch

* `sparticle-launcher` patch

* `swamp-obs` PAL patch

* `sequence-a-village1` PAL patch

* typo

* errors

* `powerups` PAL patch

* `ogreboss` PAL patch

* jak 1 v2 encoding

* `load-boundary` PAL patch

* `flying-lurker` PAL patch

* `mayor` PAL patch

* update game encoding to PAL (v2) encoding

* `cam-debug` and `cam-update` PAL patch

* `fisher` PAL patch

* `target` PAL patch

* `target2` PAL patch and fix text compiling

* `target-death` PAL patch

* `target-racer-h` PAL patch

* `logic-target` PAL patch

* `main` PAL patch

* `snow-flutflut-obs` PAL patch

* `rolling-obs` PAL patch

* `gsound` PAL patch

* update refs

* `progress` and `progress-draw` PAL patches

* clang

* wrong.

* complain

* clang

* fix test

* fix blurry jp text

* fix weird interrupt lag from setting window size

* patch more text lines, special handling for credits

* Update FontUtils.cpp

* Add xdelta3 and file patching interface

* add window lock toggle and update settings ver

* better particle hacks

* add PAL support to extractor

* Fix credits

* also NTSC-J support

* make xdelta3 a separate library

* address feedback

Co-authored-by: water <awaterford111445@gmail.com>
This commit is contained in:
ManDude
2022-06-22 05:16:34 +01:00
committed by GitHub
parent 90a049dcc5
commit 7d5045ab3f
92 changed files with 14446 additions and 9934 deletions
+57 -2
View File
@@ -27,6 +27,7 @@
#include "common/log/log.h"
#include "common/util/json_util.h"
#include "common/util/crc32.h"
#include "third-party/xdelta3/xdelta3.h"
namespace decompiler {
namespace {
@@ -140,6 +141,59 @@ ObjectFileDB::ObjectFileDB(const std::vector<std::string>& _dgos,
for (auto& obj : object_files) {
auto data = file_util::read_binary_file(obj);
auto name = obj_filename_to_name(obj);
if (auto it = config.object_patches.find(name); it != config.object_patches.end()) {
// print the file CRC
fmt::print("CRC for {} is: 0x{:X}\n", name, crc32(data.data(), data.size()));
// write patch file if necessary
if (config.write_patches) {
// this is the "target" file we want to patch to
auto data2 = file_util::read_binary_file(
(file_util::get_jak_project_dir() / it->second.target_file).string());
// we need to allocate a buffer to store the delta patch
// we make it 2x the source file's size because... it seems like a good size?
// ideally the delta patch should never be that big.
int buf_sz = data.size() * 2;
u8* out_buf = (u8*)malloc(buf_sz);
size_t out_sz = 0; // this is where the actual used size of the delta patch will be stored
int xd3_res = xd3_encode_memory(data2.data(), data2.size(), data.data(), data.size(),
out_buf, &out_sz, buf_sz, 0);
if (xd3_res) {
lg::error("error patching {} with {} (out {}): {}", name, it->second.target_file,
it->second.patch_file, xd3_strerror(xd3_res));
} else {
std::vector<u8> patch_data(out_sz);
memcpy(patch_data.data(), out_buf, patch_data.size());
file_util::write_binary_file(
(file_util::get_jak_project_dir() / it->second.patch_file).string(),
patch_data.data(), patch_data.size());
}
free(out_buf);
}
// apply patch file if necessary
// note that xd3 doesnt really have any safety against bad files so we check crc ourselves
if (config.apply_patches && it->second.crc == crc32(data.data(), data.size())) {
// this is the delta patch file
auto data2 = file_util::read_binary_file(
(file_util::get_jak_project_dir() / it->second.patch_file).string());
// we need to allocate a buffer to store the patched file
// the delta patch isn't gonna be this big but we allocate 2x the source file's size + the
// delta patch's size
int buf_sz = data.size() * 2 + data2.size();
u8* out_buf = (u8*)malloc(buf_sz);
size_t out_sz = 0;
int xd3_res = xd3_decode_memory(data2.data(), data2.size(), data.data(), data.size(),
out_buf, &out_sz, buf_sz, 0);
if (xd3_res) {
lg::error("error patching {} with {} (out {}): {}", name, it->second.target_file,
it->second.patch_file, xd3_strerror(xd3_res));
} else {
data.resize(out_sz);
memcpy(data.data(), out_buf, data.size());
}
free(out_buf);
}
}
add_obj_from_dgo(name, name, data.data(), data.size(), "NO-XGO", config);
}
@@ -220,7 +274,8 @@ void ObjectFileDB::get_objs_from_dgo(const std::string& filename, const Config&
if (i == header.object_count - 1) {
if (reader.bytes_left() == obj_header.object_count - 0x30) {
if (config.is_pal) {
lg::warn("Skipping {} because it is a broken PAL object", obj_header.name);
lg::warn("Skipping {} in {} because it is a broken PAL object", obj_header.name,
dgo_base_name);
reader.ffwd(reader.bytes_left());
continue;
} else {
@@ -646,7 +701,7 @@ std::string ObjectFileDB::process_game_text_files(const Config& cfg) {
if (text_by_language_by_id.empty()) {
return {};
}
return write_game_text(cfg, text_by_language_by_id);
return write_game_text(cfg.text_version, text_by_language_by_id);
}
std::string ObjectFileDB::process_game_count_file() {