Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 28, 2025

Dmod_ReadModuleHeader reads raw bytes from files, failing on compressed (.dmfc) modules where it reads compression headers instead of module headers. This breaks Dmod_ReadNextModule iteration over compressed modules.

Changes

  • Read full file into buffer before header extraction to enable compression detection
  • Decompress DMFC files using Dmod_IsDMFC() check and Dmod_FromDMFC() decompression
  • Validate header size post-decompression since compressed files are smaller than header size
  • Track allocation ownership with dmfDataNeedsFree flag to avoid double-free
// Before: direct read fails on DMFC
Dmod_FileRead(Header, sizeof(Dmod_ModuleHeader_t), 1, file);

// After: decompress if needed, then extract header
void* buffer = /* read entire file */;
if (Dmod_IsDMFC(buffer, fileSize)) {
    Dmod_FromDMFC(buffer, fileSize, &dmfData, &dmfSize);
    Dmod_Free(buffer);
    dmfDataNeedsFree = true;
}
memcpy(Header, dmfData, sizeof(Dmod_ModuleHeader_t));

Follows the same pattern as Dmod_LoadFile and Dmod_LoadFromPackage.

Original prompt

This section details on the original issue you should resolve

<issue_title>Dmod_ReadNextModule nie działa poprawnie dla modułów z paczek</issue_title>
<issue_description>Dmod_ReadNextModule jest niepoprawnie zaimplementowany, bo dla każdego modułu próbuje odczytać header jak z pliku, podczas gdy nie każdy moduł jest dostępny w systemie plików - paczki nie są dostępne, więc trzeba je odczytać podobnie jak robi to Dmod_LoadFromPackage</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits December 28, 2025 16:49
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Dmod_ReadNextModule implementation for package modules Fix Dmod_ReadModuleHeader to handle compressed DMFC files Dec 28, 2025
Copilot AI requested a review from JohnAmadis December 28, 2025 16:57
@JohnAmadis JohnAmadis marked this pull request as ready for review December 28, 2025 17:16
@JohnAmadis JohnAmadis merged commit 16fec55 into develop Dec 28, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dmod_ReadNextModule nie działa poprawnie dla modułów z paczek

2 participants