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

Commit

Permalink
Fix qsort compare functions
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoticgd committed Aug 21, 2023
1 parent 312cc4c commit 54443a9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ Executable files will be written out into the bin directory.

## Credit

A lot of the lump names were reverse engineered by [doesthisusername](https://github.com/doesthisusername). A large portion of the model format was reverse engineered by [thtrandomlurker](https://github.com/thtrandomlurker). Some of the swizzle tables were originally reverse engineered by Slipsy.
A lot of the lump names were reverse engineered by [doesthisusername](https://github.com/doesthisusername). A large portion of the model format was reverse engineered by [thtrandomlurker](https://github.com/thtrandomlurker). Many bugs were pointed out by [Tkachov](https://github.com/Tkachov) who helped out by reviewing my code. Some of the swizzle tables were originally reverse engineered by Slipsy.
4 changes: 2 additions & 2 deletions extractall.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ static void print_help();

static int compare_toc_assets(const void* lhs, const void* rhs) {
if(((RA_TocAsset*) lhs)->location.archive_index != ((RA_TocAsset*) rhs)->location.archive_index) {
return ((RA_TocAsset*) lhs)->location.archive_index > ((RA_TocAsset*) rhs)->location.archive_index;
return ((RA_TocAsset*) lhs)->location.archive_index - ((RA_TocAsset*) rhs)->location.archive_index;
} else {
return ((RA_TocAsset*) lhs)->location.offset > ((RA_TocAsset*) rhs)->location.offset;
return ((RA_TocAsset*) lhs)->location.offset - ((RA_TocAsset*) rhs)->location.offset;
}
}

Expand Down
2 changes: 1 addition & 1 deletion libra/dat_container.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ u32 RA_dat_writer_string(RA_DatWriter* writer, const char* string) {
}

static int compare_lumps(const void* lhs, const void* rhs) {
return ((LumpHeader*) lhs)->type_crc > ((LumpHeader*) rhs)->type_crc;
return ((LumpHeader*) lhs)->type_crc - ((LumpHeader*) rhs)->type_crc;
}

void RA_dat_writer_finish(RA_DatWriter* writer, u8** data_dest, s64* size_dest) {
Expand Down
8 changes: 4 additions & 4 deletions libra/table_of_contents.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ RA_Result RA_toc_parse(RA_TableOfContents* toc, u8* data, u32 size) {
}

static int compare_toc_assets(const void* lhs, const void* rhs) {
if(((RA_TocAsset*) lhs)->group != ((RA_TocAsset*) rhs)->group) {
return ((RA_TocAsset*) lhs)->group > ((RA_TocAsset*) rhs)->group;
if(((RA_TocAsset*) lhs)->group != ((RA_TocAsset*) rhs)->group) {
return ((RA_TocAsset*) lhs)->group - ((RA_TocAsset*) rhs)->group;
} else {
return ((RA_TocAsset*) lhs)->path_hash > ((RA_TocAsset*) rhs)->path_hash;
return ((RA_TocAsset*) lhs)->path_hash - ((RA_TocAsset*) rhs)->path_hash;
}
}

Expand All @@ -142,7 +142,7 @@ RA_Result RA_toc_build(RA_TableOfContents* toc, u8** data_dest, s64* size_dest)
u32 asset_group_top = 0;
for(u32 i = 0; i <= toc->asset_count; i++) {
if(i == toc->asset_count || toc->assets[i].group != last_group) {
while(last_group != asset_group_top) {
while(asset_group_top != last_group) {
if(asset_group_top > last_group) {
return RA_FAILURE("asset group index mismatch");
}
Expand Down

0 comments on commit 54443a9

Please sign in to comment.