Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Fix the dat test
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoticgd committed Aug 1, 2023
1 parent b9f5360 commit eff447b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
11 changes: 6 additions & 5 deletions libra/dat_container.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ RA_Result RA_dat_test(const u8* original, u32 original_size, const u8* repacked,

for(u32 i = 0; i < original_header->lump_count; i++) {
LumpHeader* original_lump = (LumpHeader*) &original_header->lumps[i];
LumpHeader* repacked_lump = (LumpHeader*) &original_header->lumps[i];
LumpHeader* repacked_lump = (LumpHeader*) &repacked_header->lumps[i];

if(original_lump->type_crc != repacked_lump->type_crc) return RA_failure("lump %u crcs differ", i);
if(original_lump->size != repacked_lump->size) return RA_failure("lump %u sizes differ", i);
Expand All @@ -287,7 +287,7 @@ RA_Result RA_dat_test(const u8* original, u32 original_size, const u8* repacked,
if(repacked_lump->offset + repacked_lump->size > original_size) return RA_failure("repacked lump %u out of bounds", i);

const u8* original_data = &original[original_lump->offset];
const u8* repacked_data = &original[repacked_lump->offset];
const u8* repacked_data = &repacked[repacked_lump->offset];

if((result = diff_buffers(original_data, original_lump->size, repacked_data, repacked_lump->size, i, print_hex_dump_on_failure)) != RA_SUCCESS) {
return result;
Expand All @@ -309,16 +309,17 @@ static RA_Result diff_buffers(const u8* lhs, u32 lhs_size, const u8* rhs, u32 rh
}
}

if(diff_offset == UINT32_MAX) {
if(lhs_size == rhs_size && diff_offset == UINT32_MAX) {
return RA_SUCCESS;
}

RA_Result error = RA_failure("lump %u differs at offset %x", lump, diff_offset);
if(print_hex_dump_on_failure) {
printf("%s\n", error);

return error;
}

printf("%s\n", error);

s64 row_start = (diff_offset / 0x10) * 0x10;
s64 hexdump_begin = MAX(0, row_start - 0x50);
s64 hexdump_end = max_size;
Expand Down
19 changes: 10 additions & 9 deletions libra/dependency_dag.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
static RA_Result alloc_assets(RA_DependencyDag* dag, u32 asset_count);

RA_Result RA_dag_parse(RA_DependencyDag* dag, u8* data, u32 size) {
u32 asset_types_crc = RA_crc_string("Asset Types");
u32 hashes_crc = 0x933c0d32;
u32 dependency_crc = 0xbc91d1cc;
u32 unk_crc = 0xbfec699f;
u32 paths_crc = 0xd101a6cc;
u32 asset_types_crc = RA_crc_string("Asset Types");
u32 dependency_indices_crc = 0xf958372e;
u32 dependency_crc = 0xbc91d1cc;
u32 unk_crc = 0xbfec699f;

RA_Result result;

Expand Down Expand Up @@ -77,7 +77,7 @@ RA_Result RA_dag_parse(RA_DependencyDag* dag, u8* data, u32 size) {
if(dependency_list_index > -1) {
if(!dependencies) return "no dependencies lump";
if(dependency_list_index * 4 >= dependency_lump_size) return "dependency list index out of range";
dag->assets[i].dependencies = &dependencies[dependency_list_index];
dag->assets[i].dependencies = (u32*) &dependencies[dependency_list_index];
s32* dependency = &dependencies[dependency_list_index];
while(*dependency > -1) {
if(*dependency >= dag->asset_count) return "dependency index out of range";
Expand Down Expand Up @@ -111,12 +111,12 @@ static RA_Result alloc_assets(RA_DependencyDag* dag, u32 asset_count) {
}

RA_Result RA_dag_build(RA_DependencyDag* dag, u8** data_dest, u32* size_dest) {
u32 asset_types_crc = RA_crc_string("Asset Types");
u32 hashes_crc = 0x933c0d32;
u32 dependency_crc = 0xbc91d1cc;
u32 unk_crc = 0xbfec699f;
u32 paths_crc = 0xd101a6cc;
u32 asset_types_crc = RA_crc_string("Asset Types");
u32 dependency_indices_crc = 0xf958372e;
u32 dependency_crc = 0xbc91d1cc;
u32 unk_crc = 0xbfec699f;

RA_DatWriter* writer = RA_dat_writer_begin(RA_ASSET_TYPE_DAG, 0xc);

Expand All @@ -125,11 +125,12 @@ RA_Result RA_dag_build(RA_DependencyDag* dag, u8** data_dest, u32* size_dest) {
dependency_count += dag->assets[i].dependency_count + 1;
}

u8* asset_types = RA_dat_writer_lump(writer, asset_types_crc, dag->asset_count);
u64* hashes = RA_dat_writer_lump(writer, hashes_crc, dag->asset_count * 8);
s32* dependency = RA_dat_writer_lump(writer, dependency_crc, dependency_count * 4);
u32* paths = RA_dat_writer_lump(writer, paths_crc, dag->asset_count * 4);
u8* asset_types = RA_dat_writer_lump(writer, asset_types_crc, dag->asset_count);
u32* dependency_indices = RA_dat_writer_lump(writer, dependency_indices_crc, dag->asset_count * 4);
s32* dependency = RA_dat_writer_lump(writer, dependency_crc, dependency_count * 4);
u32* unk = RA_dat_writer_lump(writer, unk_crc, 1);

for(u32 i = 0; i < dag->asset_count; i++) {
asset_types[i] = dag->assets[i].type;
Expand Down
6 changes: 5 additions & 1 deletion test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ int main(int argc, const char** argv) {
char file_path[1024];
snprintf(file_path, 1024, "%s/%s", directory_path, entry->d_name);

if((result = test_file(file_path)) != RA_SUCCESS) {
if((result = test_file(file_path)) == RA_SUCCESS) {
printf("success\n");
} else {
printf("%s\n", result);
}
}
Expand Down Expand Up @@ -66,6 +68,7 @@ static RA_Result test_file(const char* path) {
} else {
printf("skipped\n");
}

return RA_SUCCESS;
}

Expand All @@ -86,6 +89,7 @@ static RA_Result test_dat_file(u8* data, u32 size) {
printf("skipped\n");
}
}

return RA_SUCCESS;
}

Expand Down

0 comments on commit eff447b

Please sign in to comment.