diff --git a/libra/dat_container.c b/libra/dat_container.c index b7be722..ad4c3e6 100644 --- a/libra/dat_container.c +++ b/libra/dat_container.c @@ -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); @@ -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; @@ -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; diff --git a/libra/dependency_dag.c b/libra/dependency_dag.c index aeefb96..b8339d2 100644 --- a/libra/dependency_dag.c +++ b/libra/dependency_dag.c @@ -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; @@ -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"; @@ -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); @@ -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; diff --git a/test/test.c b/test/test.c index d2cb935..ff06b1d 100644 --- a/test/test.c +++ b/test/test.c @@ -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); } } @@ -66,6 +68,7 @@ static RA_Result test_file(const char* path) { } else { printf("skipped\n"); } + return RA_SUCCESS; } @@ -86,6 +89,7 @@ static RA_Result test_dat_file(u8* data, u32 size) { printf("skipped\n"); } } + return RA_SUCCESS; }