Compare commits

...

2 Commits

Author SHA1 Message Date
31d78bfcd3 Populate the toc_entries in asset_pack_t 2023-10-24 00:40:35 +01:00
07daa2ca19 Add debug config for pakrd_test 2023-10-24 00:40:21 +01:00
2 changed files with 46 additions and 5 deletions

24
.vscode/launch.json vendored
View File

@ -54,6 +54,30 @@
"ignoreFailures": true
}
]
},
{
"name": "(gdb) Debug pakrd_test",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/pakrd_test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}

View File

@ -132,7 +132,7 @@ asset_pack_t *load_asset_pack(const char *filepath) {
pack->fp = fopen(full_path, "rb");
if (!(pack->fp)) {
free(pack);
close_asset_pack(&pack);
return NULL;
}
@ -145,16 +145,29 @@ asset_pack_t *load_asset_pack(const char *filepath) {
pack->toc = (u8 *)malloc(toc_size);
if (!(pack->toc)) {
fclose(pack->fp);
free(pack);
close_asset_pack(&pack);
return NULL;
}
fread((void *)(pack->toc), toc_size, 1, pack->fp);
// TODO (Abdelrahman): Populate the entries array
u64 entries_size = sizeof(toc_entry_t *) * pack->header.toc.count;
pack->toc_entries = (toc_entry_t **)malloc(entries_size);
if (!(pack->toc_entries)) {
close_asset_pack(&pack);
return NULL;
}
toc_entry_t *next = (toc_entry_t *)pack->toc;
for (u64 i = 0; i < pack->header.toc.count; ++i) {
pack->toc_entries[i] = next;
next = (toc_entry_t *)((u8 *)next + sizeof(toc_entry_t) + next->length);
}
pack->assets_offset = ftell(pack->fp);
@ -170,6 +183,10 @@ void close_asset_pack(asset_pack_t **pack) {
return;
}
if ((*pack)->toc_entries) {
free((*pack)->toc_entries);
}
if ((*pack)->toc) {
free((*pack)->toc);
}