mirror of
https://github.com/open-goal/jak-project
synced 2026-07-11 15:28:58 -04:00
make decompiler at least unpack jak 2 and jak 3 files again (#313)
This commit is contained in:
@@ -495,6 +495,11 @@ void LinkedObjectFile::process_fp_relative_links() {
|
||||
case InstructionKind::DADDU:
|
||||
case InstructionKind::ADDU: {
|
||||
assert(prev_instr);
|
||||
if (prev_instr->kind != InstructionKind::ORI) {
|
||||
lg::error("Failed to process fp relative links for (d)addu preceded by: {}",
|
||||
prev_instr->to_string(labels));
|
||||
return;
|
||||
}
|
||||
assert(prev_instr->kind == InstructionKind::ORI);
|
||||
int offset_reg_src_id = instr.kind == InstructionKind::DADDU ? 0 : 1;
|
||||
auto offset_reg = instr.get_src(offset_reg_src_id).get_reg();
|
||||
@@ -814,7 +819,9 @@ std::string LinkedObjectFile::get_goal_string(int seg, int word_idx, bool with_q
|
||||
char cword[4];
|
||||
memcpy(cword, &word.data, 4);
|
||||
result += cword[byte_offset];
|
||||
assert(result.back() != 0);
|
||||
if (result.back() == 0) {
|
||||
return "invalid string! (check me!)";
|
||||
}
|
||||
}
|
||||
if (with_quotes) {
|
||||
result += "\"";
|
||||
|
||||
@@ -302,7 +302,7 @@ static void link_v2_or_v4(LinkedObjectFile& f,
|
||||
for (uint8_t i = 0; i < count; i++) {
|
||||
if (!f.pointer_link_word(0, code_ptr_offset - code_offset, 0,
|
||||
*((const uint32_t*)(&data.at(code_ptr_offset))))) {
|
||||
printf("WARNING bad link in %s\n", name.c_str());
|
||||
lg::error("Skipping link in {} because it is out of range!", name.c_str());
|
||||
}
|
||||
f.stats.total_v2_pointers++;
|
||||
code_ptr_offset += 4;
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "decompiler/data/game_count.h"
|
||||
#include "LinkedObjectFileCreation.h"
|
||||
#include "decompiler/config.h"
|
||||
#include "third-party/lzokay/lzokay.hpp"
|
||||
#include "common/util/BinaryReader.h"
|
||||
#include "common/util/Timer.h"
|
||||
#include "common/util/FileUtil.h"
|
||||
@@ -343,8 +342,11 @@ std::string ObjectFileDB::generate_dgo_listing() {
|
||||
|
||||
namespace {
|
||||
std::string pad_string(const std::string& in, size_t length) {
|
||||
assert(in.length() < length);
|
||||
return in + std::string(length - in.length(), ' ');
|
||||
if (in.length() < length) {
|
||||
return in + std::string(length - in.length(), ' ');
|
||||
} else {
|
||||
return in;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -366,11 +368,16 @@ std::string ObjectFileDB::generate_obj_listing() {
|
||||
pad_string(x.name_in_dgo + "\", ", 50) + std::to_string(x.obj_version) + ", " +
|
||||
dgos + ", \"\"],\n";
|
||||
unique_count++;
|
||||
if (all_unique_names.find(x.to_unique_name()) != all_unique_names.end()) {
|
||||
lg::error("Object file {} appears multiple times with the same name.", x.to_unique_name());
|
||||
}
|
||||
all_unique_names.insert(x.to_unique_name());
|
||||
}
|
||||
// this check is extremely important. It makes sure we don't have any repeat names. This could
|
||||
// be caused by two files with the same name, in the same DGOs, but different data.
|
||||
assert(int(all_unique_names.size()) == unique_count);
|
||||
if (int(all_unique_names.size()) != unique_count) {
|
||||
lg::error("Object files are not named properly, data will be lost!");
|
||||
}
|
||||
}
|
||||
|
||||
if (result.length() >= 2) {
|
||||
|
||||
Reference in New Issue
Block a user