load_669.cpp   load_669.cpp 
skipping to change at line 37 skipping to change at line 37
} FILEHEADER669; } FILEHEADER669;
typedef struct tagSAMPLE669 typedef struct tagSAMPLE669
{ {
BYTE filename[13]; BYTE filename[13];
BYTE length[4]; // when will somebody think about DWORD align ??? BYTE length[4]; // when will somebody think about DWORD align ???
BYTE loopstart[4]; BYTE loopstart[4];
BYTE loopend[4]; BYTE loopend[4];
} SAMPLE669; } SAMPLE669;
DWORD lengthArrayToDWORD(const BYTE length[4]) {
DWORD len = (length[3] << 24) +
(length[2] << 16) +
(length[1] << 8) +
(length[0]);
return(len);
}
BOOL CSoundFile::Read669(const BYTE *lpStream, DWORD dwMemLength) BOOL CSoundFile::Read669(const BYTE *lpStream, DWORD dwMemLength)
//--------------------------------------------------------------- //---------------------------------------------------------------
{ {
BOOL b669Ext; BOOL b669Ext;
const FILEHEADER669 *pfh = (const FILEHEADER669 *)lpStream; const FILEHEADER669 *pfh = (const FILEHEADER669 *)lpStream;
const SAMPLE669 *psmp = (const SAMPLE669 *)(lpStream + 0x1F1); const SAMPLE669 *psmp = (const SAMPLE669 *)(lpStream + 0x1F1);
DWORD dwMemPos = 0; DWORD dwMemPos = 0;
if ((!lpStream) || (dwMemLength < sizeof(FILEHEADER669))) return FAL SE; if ((!lpStream) || (dwMemLength < sizeof(FILEHEADER669))) return FAL SE;
if ((bswapLE16(pfh->sig) != 0x6669) && (bswapLE16(pfh->sig) != 0x4E4 A)) return FALSE; if ((bswapLE16(pfh->sig) != 0x6669) && (bswapLE16(pfh->sig) != 0x4E4 A)) return FALSE;
b669Ext = (bswapLE16(pfh->sig) == 0x4E4A) ? TRUE : FALSE; b669Ext = (bswapLE16(pfh->sig) == 0x4E4A) ? TRUE : FALSE;
if ((!pfh->samples) || (pfh->samples > 64) || (pfh->restartpos >= 12 8) if ((!pfh->samples) || (pfh->samples > 64) || (pfh->restartpos >= 12 8)
|| (!pfh->patterns) || (pfh->patterns > 128)) return FALSE; || (!pfh->patterns) || (pfh->patterns > 128)) return FALSE;
DWORD dontfuckwithme = 0x1F1 + pfh->samples * sizeof(SAMPLE669) + pf h->patterns * 0x600; DWORD dontfuckwithme = 0x1F1 + pfh->samples * sizeof(SAMPLE669) + pf h->patterns * 0x600;
if (dontfuckwithme > dwMemLength) return FALSE; if (dontfuckwithme > dwMemLength) return FALSE;
for (UINT ichk=0; ichk<pfh->samples; ichk++) for (UINT ichk=0; ichk<pfh->samples; ichk++)
{ {
DWORD len = bswapLE32(*((DWORD *)(&psmp[ichk].length))); DWORD len = lengthArrayToDWORD(psmp[ichk].length);
dontfuckwithme += len; dontfuckwithme += len;
} }
if (dontfuckwithme > dwMemLength) return FALSE; if (dontfuckwithme > dwMemLength) return FALSE;
// That should be enough checking: this must be a 669 module. // That should be enough checking: this must be a 669 module.
m_nType = MOD_TYPE_669; m_nType = MOD_TYPE_669;
m_dwSongFlags |= SONG_LINEARSLIDES; m_dwSongFlags |= SONG_LINEARSLIDES;
m_nMinPeriod = 28 << 2; m_nMinPeriod = 28 << 2;
m_nMaxPeriod = 1712 << 3; m_nMaxPeriod = 1712 << 3;
m_nDefaultTempo = 125; m_nDefaultTempo = 125;
m_nDefaultSpeed = 6; m_nDefaultSpeed = 6;
m_nChannels = 8; m_nChannels = 8;
memcpy(m_szNames[0], pfh->songmessage, 16); memcpy(m_szNames[0], pfh->songmessage, 16);
m_nSamples = pfh->samples; m_nSamples = pfh->samples;
for (UINT nins=1; nins<=m_nSamples; nins++, psmp++) for (UINT nins=1; nins<=m_nSamples; nins++, psmp++)
{ {
DWORD len = bswapLE32(*((DWORD *)(&psmp->length))); DWORD len = lengthArrayToDWORD(psmp->length);
DWORD loopstart = bswapLE32(*((DWORD *)(&psmp->loopstart))); DWORD loopstart = lengthArrayToDWORD(psmp->loopstart);
DWORD loopend = bswapLE32(*((DWORD *)(&psmp->loopend))); DWORD loopend = lengthArrayToDWORD(psmp->loopend);
if (len > MAX_SAMPLE_LENGTH) len = MAX_SAMPLE_LENGTH; if (len > MAX_SAMPLE_LENGTH) len = MAX_SAMPLE_LENGTH;
if ((loopend > len) && (!loopstart)) loopend = 0; if ((loopend > len) && (!loopstart)) loopend = 0;
if (loopend > len) loopend = len; if (loopend > len) loopend = len;
if (loopstart + 4 >= loopend) loopstart = loopend = 0; if (loopstart + 4 >= loopend) loopstart = loopend = 0;
Ins[nins].nLength = len; Ins[nins].nLength = len;
Ins[nins].nLoopStart = loopstart; Ins[nins].nLoopStart = loopstart;
Ins[nins].nLoopEnd = loopend; Ins[nins].nLoopEnd = loopend;
if (loopend) Ins[nins].uFlags |= CHN_LOOP; if (loopend) Ins[nins].uFlags |= CHN_LOOP;
memcpy(m_szNames[nins], psmp->filename, 13); memcpy(m_szNames[nins], psmp->filename, 13);
Ins[nins].nVolume = 256; Ins[nins].nVolume = 256;
 End of changes. 3 change blocks. 
4 lines changed or deleted 13 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/