mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 21:27:52 -04:00
78cde74d5a
* update readme deps * replace assert * bump timeout * fix memory corruption in kernel * use unknown if level name is invalid
54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
#include <cstring>
|
|
#include "dgo_util.h"
|
|
#include "common/versions.h"
|
|
#include "third-party/fmt/core.h"
|
|
#include "common/util/Assert.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, u8* data, int size) {
|
|
const std::string art_group_text =
|
|
fmt::format("/src/next/data/art-group{}/",
|
|
versions::ART_FILE_VERSION); // todo, this may change in other games
|
|
const std::string suffix = "-ag.go";
|
|
|
|
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;
|
|
}
|