libgme / game-music-emu

Blargg's video game music emulation library, which allows audio applications to easily add playback support for the music of many classic video game consoles.
GNU Lesser General Public License v2.1
68 stars 12 forks source link

Improve support for packed GYM files #21

Open Wohlstand opened 6 years ago

Wohlstand commented 6 years ago

Original report by Michael Pyne (Bitbucket: mpyne, GitHub: mpyne).


A user reports that packed GYM files are not handled well by libgme and that we could, without much effort, support those. Doing this would be helpful since many of the available GYM files are delivered in packed format.

The user has a player which already does this, and submitted the following patch:

#!c++
if ( memcmp( inBuffer, "GYMX", 4 ) == 0 ) {     // seems to be easier to unpack here than to fix the emu
        // A 32-bit unsigned integer in little-endian format denoting how large the
        //             remainder of the data is if it's GZipped;
        unsigned long unpackedSize= getLE((unsigned char*)&((Gym_Emu::header_t const*) inBuffer)->packed[0]);
        if (unpackedSize != 0 ) {       // Packed GYM file
                if (unpacked) free(unpacked);   // limit the garbage

                unpacked= (unsigned char *)malloc(Gym_Emu::header_size+unpackedSize);
                memcpy(unpacked, inBuffer, Gym_Emu::header_size);       // header
                *((unsigned int*)(((Gym_Emu::header_t const*) unpacked)->packed))= 0;   // mark as unpacked
                if (Z_OK != uncompress(unpacked+Gym_Emu::header_size, &unpackedSize, (const unsigned char*)inBuffer+Gym_Emu::header_size, inBufSize-Gym_Emu::header_size))
                        fprintf(stderr, "ERROR uncompressing\n");

                inBuffer = (void*)unpacked;
                inBufSize= Gym_Emu::header_size+unpackedSize;
        }
}

This code was for the current git master version of game-music-emu, though it may not translate directly to the library itself.

gym-compressed.patch.zip

Wohlstand commented 6 years ago

Original comment by Michael Pyne (Bitbucket: mpyne, GitHub: mpyne).


Adding this issue clued me into how little I've done to setup the issue tracker for new bugs.

Reassigning to the right version, for starters.

Wohlstand commented 1 year ago

Original comment by mywave (Bitbucket: mywave, GitHub: mywave).


Updated code provided earlier in your code into working condition, and verified against real compressed GYM files

Wohlstand commented 1 year ago

Original comment by mywave (Bitbucket: mywave, GitHub: mywave).


No public access for creating Pull requests, so I added the refined patch files here instead.