Files
jak-project/common/util/dgo_util.cpp
T
Tyler Wilding d3cc739e43 jakx: Commit existing work from other PRs (#4112)
This attempts to get into master whatever work was done in this PR /
it's earlier PR https://github.com/open-goal/jak-project/pull/3965

I don't want this work to be lost / floating around in massive PRs.

However the changes are:
- switch to ntsc_v1 instead of PAL as the development target, as we have
done for all other games
- remove most of the copied-from-jak2/3 changes as they need to be
confirmed during the decompilation process not just assumed
- avoids committing any changes to `game/kernel/common` as it was not
clear to me if these were changes made in jak x's kernel that were not
properly broken out into it's own functions. We don't want to
accidentally introduce bugs into jak1-3's kernel code.
- in other words, if the change in the kernel only happens in jak x...it
should likely be specific to jak x's kernel, not common.

---------

Co-authored-by: VodBox <dillon@vodbox.io>
Co-authored-by: yodah <greenboyyodah@gmail.com>
2025-12-31 21:08:44 -05:00

61 lines
1.8 KiB
C++

#include "dgo_util.h"
#include <cstring>
#include "common/util/Assert.h"
#include "common/versions/versions.h"
#include "fmt/format.h"
/*!
* Assert false if the char[] has non-null data after the null terminated string.
* Used to sanity check the sizes of strings in DGO/object file headers.
*/
void assert_string_empty_after(const char* str, int size) {
auto ptr = str;
while (*ptr)
ptr++;
while (ptr - str < size) {
ASSERT(!*ptr);
ptr++;
}
}
std::string get_object_file_name(const std::string& original_name, const u8* data, int size) {
const std::string art_group_text_strings[] = {
fmt::format("/src/next/data/art-group{}/", versions::jak1::ART_FILE_VERSION),
fmt::format("/src/jak2/final/art-group{}/", versions::jak2::ART_FILE_VERSION),
fmt::format("/src/jak3/final/art-group{}/", versions::jak3::ART_FILE_VERSION),
fmt::format("/src/jakx/final/art-group{}/", versions::jakx::ART_FILE_VERSION)};
const std::string suffix = "-ag.go";
for (auto& art_group_text : art_group_text_strings) {
int len = int(art_group_text.length());
for (int start = 0; start < size; start++) {
bool failed = false;
for (int i = 0; i < len; i++) {
if (start + i >= size || data[start + i] != art_group_text[i]) {
failed = true;
break;
}
}
if (!failed) {
for (int i = 0; i < int(original_name.length()); i++) {
if (start + len + i >= size || data[start + len + i] != original_name[i]) {
ASSERT(false);
}
}
ASSERT(int(suffix.length()) + start + len + int(original_name.length()) < size);
ASSERT(!memcmp(data + start + len + original_name.length(), suffix.data(),
suffix.length() + 1));
return original_name + "-ag";
}
}
}
return original_name;
}