Mostly nuking old system
Some checks failed
Build Dusk / build-linux (push) Failing after 1m24s
Build Dusk / run-tests (push) Failing after 1m17s
Build Dusk / build-psp (push) Failing after 1m34s
Build Dusk / build-dolphin (push) Failing after 2m5s

This commit is contained in:
2026-02-13 19:13:26 -06:00
parent b37e5f45ca
commit e5e8c49f6c
97 changed files with 1454 additions and 408 deletions

View File

@@ -232,6 +232,20 @@ errorret_t assetLoad(const char_t *filename, void *output) {
assertStrLenMax(filename, FILENAME_MAX, "Filename too long.");
assertNotNull(output, "Output pointer cannot be NULL.");
// Determine the asset type by reading the extension
const assettypedef_t *def = NULL;
for(uint_fast8_t i = 0; i < ASSET_TYPE_COUNT; i++) {
const assettypedef_t *cmp = &ASSET_TYPE_DEFINITIONS[i];
assertNotNull(cmp, "Asset type definition cannot be NULL.");
assertNotNull(cmp->extension, "Asset type definition has NULL extension.");
if(!stringEndsWithCaseInsensitive(filename, cmp->extension)) continue;
def = cmp;
break;
}
if(def == NULL) {
errorThrow("Unknown asset type for file: %s", filename);
}
// Get file size of the asset.
zip_stat_t st;
zip_stat_init(&st);
@@ -241,8 +255,8 @@ errorret_t assetLoad(const char_t *filename, void *output) {
// Minimum file size.
zip_int64_t fileSize = (zip_int64_t)st.size;
if(fileSize < sizeof(assetheader_t)) {
errorThrow("Asset file too small to contain header: %s", filename);
if(fileSize <= 0) {
errorThrow("Asset file is empty: %s", filename);
}
// Try to open the file
@@ -250,61 +264,19 @@ errorret_t assetLoad(const char_t *filename, void *output) {
if(file == NULL) {
errorThrow("Failed to open asset file: %s", filename);
}
// Read the header.
zip_int64_t bytesRemaining = fileSize;
assetheader_t header;
memoryZero(&header, sizeof(assetheader_t));
zip_int64_t bytesRead = zip_fread(
file,
&header,
(zip_uint64_t)sizeof(assetheader_t)
);
if((size_t)bytesRead != sizeof(assetheader_t)) {
zip_fclose(file);
errorThrow("Failed to read asset header for: %s", filename);
}
bytesRemaining -= (zip_uint64_t)bytesRead;
assertTrue(sizeof(assetheader_t) == ASSET_HEADER_SIZE, "Asset header size mismatch.");
assertTrue(bytesRead == ASSET_HEADER_SIZE, "Asset header read size mismatch.");
// Find the asset type based on the header
const assettypedef_t *def = NULL;
for(uint_fast8_t i = 0; i < ASSET_TYPE_COUNT; i++) {
const assettypedef_t *cmp = &ASSET_TYPE_DEFINITIONS[i];
if(cmp->header == NULL) continue;
// strcmp didn't work because it's a fixed char_t[3] I think, or maybe
// because of the packed struct?
bool_t match = true;
for(size_t h = 0; h < ASSET_HEADER_SIZE; h++) {
if(header.header[h] == cmp->header[h]) continue;
match = false;
break;
}
if(!match) continue;
def = cmp;
break;
}
if(def == NULL) {
zip_fclose(file);
errorThrow("Unknown asset type for file: %s", filename);
}
// We found the asset type, now load the asset data
// Load the asset data
switch(def->loadStrategy) {
case ASSET_LOAD_STRAT_ENTIRE:
assertNotNull(def->entire, "Asset load function cannot be NULL.");
// Must have more to read
if(bytesRemaining <= 0) {
if(fileSize <= 0) {
zip_fclose(file);
errorThrow("No data remaining to read for asset: %s", filename);
}
if(bytesRemaining > def->dataSize) {
if(fileSize > def->dataSize) {
zip_fclose(file);
errorThrow(
"Asset file has too much data remaining after header: %s",
@@ -313,20 +285,20 @@ errorret_t assetLoad(const char_t *filename, void *output) {
}
// Create space to read the entire asset data
void *data = memoryAllocate(bytesRemaining);
void *data = memoryAllocate(fileSize);
if(!data) {
zip_fclose(file);
errorThrow("Failed to allocate memory for asset data of file: %s", filename);
}
// Read in the asset data.
bytesRead = zip_fread(file, data, bytesRemaining);
if(bytesRead == 0 || bytesRead > bytesRemaining) {
zip_int64_t bytesRead = zip_fread(file, data, fileSize);
if(bytesRead == 0 || bytesRead > fileSize) {
memoryFree(data);
zip_fclose(file);
errorThrow("Failed to read asset data for file: %s", filename);
}
bytesRemaining -= bytesRead;
fileSize -= bytesRead;
// Close the file now we have the data
zip_fclose(file);