external/libmodplug-0.8.8.4/src/load_umx.cpp
changeset 639 f8901a7ff3f1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/external/libmodplug-0.8.8.4/src/load_umx.cpp	Sun Jun 09 16:22:42 2013 -0700
     1.3 @@ -0,0 +1,53 @@
     1.4 +/*
     1.5 + * This source code is public domain.
     1.6 + *
     1.7 + * Authors: Olivier Lapicque <olivierl@jps.net>
     1.8 +*/
     1.9 +
    1.10 +#include "stdafx.h"
    1.11 +#include "sndfile.h"
    1.12 +
    1.13 +#define MODMAGIC_OFFSET	(20+31*30+130)
    1.14 +
    1.15 +
    1.16 +BOOL CSoundFile::ReadUMX(const BYTE *lpStream, DWORD dwMemLength)
    1.17 +//---------------------------------------------------------------
    1.18 +{
    1.19 +	if ((!lpStream) || (dwMemLength < 0x800)) return FALSE;
    1.20 +	// Rip Mods from UMX
    1.21 +	if ((bswapLE32(*((DWORD *)(lpStream+0x20))) < dwMemLength)
    1.22 +	 && (bswapLE32(*((DWORD *)(lpStream+0x18))) <= dwMemLength - 0x10)
    1.23 +	 && (bswapLE32(*((DWORD *)(lpStream+0x18))) >= dwMemLength - 0x200))
    1.24 +	{
    1.25 +		for (UINT uscan=0x40; uscan<0x500; uscan++)
    1.26 +		{
    1.27 +			DWORD dwScan = bswapLE32(*((DWORD *)(lpStream+uscan)));
    1.28 +			// IT
    1.29 +			if (dwScan == 0x4D504D49)
    1.30 +			{
    1.31 +				DWORD dwRipOfs = uscan;
    1.32 +				return ReadIT(lpStream + dwRipOfs, dwMemLength - dwRipOfs);
    1.33 +			}
    1.34 +			// S3M
    1.35 +			if (dwScan == 0x4D524353)
    1.36 +			{
    1.37 +				DWORD dwRipOfs = uscan - 44;
    1.38 +				return ReadS3M(lpStream + dwRipOfs, dwMemLength - dwRipOfs);
    1.39 +			}
    1.40 +			// XM
    1.41 +			if (!strnicmp((LPCSTR)(lpStream+uscan), "Extended Module", 15))
    1.42 +			{
    1.43 +				DWORD dwRipOfs = uscan;
    1.44 +				return ReadXM(lpStream + dwRipOfs, dwMemLength - dwRipOfs);
    1.45 +			}
    1.46 +			// MOD
    1.47 +			if ((uscan > MODMAGIC_OFFSET) && (dwScan == 0x2e4b2e4d))
    1.48 +			{
    1.49 +				DWORD dwRipOfs = uscan - MODMAGIC_OFFSET;
    1.50 +				return ReadMod(lpStream+dwRipOfs, dwMemLength-dwRipOfs);
    1.51 +			}
    1.52 +		}
    1.53 +	}
    1.54 +	return FALSE;
    1.55 +}
    1.56 +