From 9fb257d2e337d9cb14bec6983ed431a2a7ac9450 Mon Sep 17 00:00:00 2001 From: Matt Oliver Date: Sun, 13 Feb 2022 19:29:09 +1100 Subject: [PATCH] project: Update for recent upstream merge. --- SMP/.gitattributes | 7 +- SMP/SMP.patch | 239 +++++++++++++++++++++++++++++ SMP/appveyor.yml | 2 +- SMP/libmodplug_with_latest_sdk.bat | 118 +++++++------- SMP/readme.txt | 22 ++- 5 files changed, 322 insertions(+), 66 deletions(-) create mode 100644 SMP/SMP.patch diff --git a/SMP/.gitattributes b/SMP/.gitattributes index 677750e..0c8ec15 100644 --- a/SMP/.gitattributes +++ b/SMP/.gitattributes @@ -1,3 +1,4 @@ -*.sln text=auto -*.vcxproj text=auto -*.vcxproj.filters text=auto \ No newline at end of file +*.sln text eol=crlf +*.vcxproj text eol=crlf +*.vcxproj.filters text eol=crlf +*.bat text eol=crlf \ No newline at end of file diff --git a/SMP/SMP.patch b/SMP/SMP.patch new file mode 100644 index 0000000..568e638 --- /dev/null +++ b/SMP/SMP.patch @@ -0,0 +1,239 @@ +diff --git a/src/libmodplug/sndfile.h b/src/libmodplug/sndfile.h +index 1888500..7ad2c83 100644 +--- a/src/libmodplug/sndfile.h ++++ b/src/libmodplug/sndfile.h +@@ -613,7 +613,7 @@ public: + UINT GetMaxPosition() const; + void SetCurrentPos(UINT nPos); + void SetCurrentOrder(UINT nOrder); +- void GetTitle(LPSTR s) const { lstrcpyn(s,m_szNames[0],32); } ++ void GetTitle(LPSTR s) const { lstrcpynA(s,m_szNames[0],32); } + LPCSTR GetTitle() const { return m_szNames[0]; } + UINT GetSampleName(UINT nSample,LPSTR s=NULL) const; + UINT GetInstrumentName(UINT nInstr,LPSTR s=NULL) const; +diff --git a/src/libmodplug/stdafx.h b/src/libmodplug/stdafx.h +index 2599306..1cb3a07 100644 +--- a/src/libmodplug/stdafx.h ++++ b/src/libmodplug/stdafx.h +@@ -46,6 +46,7 @@ typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + #else + #include ++#include + #endif + + #define sleep(_ms) Sleep(_ms * 1000) +@@ -65,6 +66,62 @@ inline void ProcessPlugins(int n) { (void)n; } + #define isblank(c) ((c) == ' ' || (c) == '\t') + #endif + ++#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) ++static __inline LPSTR lstrcpynA(LPSTR lpDst, LPCSTR lpStr, int iMaxLength) ++{ ++ WCHAR wlpSrc[MAX_PATH]; ++ if (MultiByteToWideChar(CP_UTF8, 0, lpStr, -1, wlpSrc, MAX_PATH) == 0) { ++ return NULL; ++ } ++ WCHAR wlpDst[MAX_PATH]; ++ if (StringCchCopyNW(wlpDst, MAX_PATH, wlpSrc, iMaxLength) == NULL) { ++ return NULL; ++ } ++ if (WideCharToMultiByte(CP_UTF8, 0, wlpDst, iMaxLength, lpDst, MAX_PATH, NULL, NULL) == 0) { ++ return NULL; ++ } ++ return lpDst; ++} ++static __inline LPSTR lstrcpyA(LPSTR lpDst, LPCSTR lpStr) ++{ ++ WCHAR wlpSrc[MAX_PATH]; ++ if (MultiByteToWideChar(CP_UTF8, 0, lpStr, -1, wlpSrc, MAX_PATH) == 0) { ++ return NULL; ++ } ++ WCHAR wlpDst[MAX_PATH]; ++ if (StringCchCopyW(wlpDst, MAX_PATH, wlpSrc) == NULL) { ++ return NULL; ++ } ++ if (WideCharToMultiByte(CP_UTF8, 0, wlpDst, -1, lpDst, MAX_PATH, NULL, NULL) == 0) { ++ return NULL; ++ } ++ return lpDst; ++} ++static __inline int wsprintfA(LPSTR lpDst, LPCSTR lpFmt, ...) ++{ ++ WCHAR wlpDst[MAX_PATH]; ++ if (MultiByteToWideChar(CP_UTF8, 0, lpDst, -1, wlpDst, MAX_PATH) == 0) { ++ return 0; ++ } ++ WCHAR wlpFmt[MAX_PATH]; ++ if (MultiByteToWideChar(CP_UTF8, 0, lpFmt, -1, wlpFmt, MAX_PATH) == 0) { ++ return 0; ++ } ++ va_list args; ++ va_start(args, lpFmt); ++ int length = StringCchVPrintfW(wlpDst, MAX_PATH, wlpFmt, args); ++ va_end(args); ++ if (WideCharToMultiByte(CP_UTF8, 0, wlpDst, -1, lpDst, MAX_PATH, NULL, NULL) == 0) { ++ return 0; ++ } ++ return length; ++} ++#endif ++ ++#ifndef WAVE_FORMAT_PCM ++#define WAVE_FORMAT_PCM 1 ++#endif ++ + #else + + #include +@@ -97,10 +154,10 @@ typedef void* PVOID; + typedef void VOID; + + #define LPCTSTR LPCSTR +-#define lstrcpyn strncpy +-#define lstrcpy strcpy ++#define lstrcpynA strncpy ++#define lstrcpyA strcpy + #define lstrcmp strcmp +-#define wsprintf sprintf ++#define wsprintfA sprintf + + #define WAVE_FORMAT_PCM 1 + +diff --git a/src/load_amf.cpp b/src/load_amf.cpp +index 89876af..c826c96 100644 +--- a/src/load_amf.cpp ++++ b/src/load_amf.cpp +@@ -171,7 +171,7 @@ BOOL CSoundFile::ReadAMF(LPCBYTE lpStream, const DWORD dwMemLength) + DWORD dwMemPos; + + if ((!lpStream) || (dwMemLength < 2048)) return FALSE; +- if ((!strncmp((LPCTSTR)lpStream, "ASYLUM Music Format V1.0", 25)) && (dwMemLength > 4096)) ++ if ((!strncmp((LPCSTR)lpStream, "ASYLUM Music Format V1.0", 25)) && (dwMemLength > 4096)) + { + UINT numorders, numpats, numsamples; + +diff --git a/src/load_it.cpp b/src/load_it.cpp +index 45fa8e4..fcece62 100644 +--- a/src/load_it.cpp ++++ b/src/load_it.cpp +@@ -624,7 +624,7 @@ BOOL CSoundFile::SaveIT(LPCSTR lpszFileName, UINT nPacking) + dwPatNamLen = 0; + dwChnNamLen = 0; + header.id = 0x4D504D49; // IMPM +- lstrcpyn((char *)header.songname, m_szNames[0], 27); ++ lstrcpynA((char *)header.songname, m_szNames[0], 27); + header.reserved1 = 0x1004; + header.ordnum = 0; + while ((header.ordnum < MAX_ORDERS) && (Order[header.ordnum] < 0xFF)) header.ordnum++; +diff --git a/src/load_med.cpp b/src/load_med.cpp +index e5b3076..380292c 100644 +--- a/src/load_med.cpp ++++ b/src/load_med.cpp +@@ -737,7 +737,7 @@ BOOL CSoundFile::ReadMed(const BYTE *lpStream, DWORD dwMemLength) + if (maxnamelen > 32) maxnamelen = 32; + for (UINT i=0; i MAX_CHANNELNAME) trknamelen = MAX_CHANNELNAME; + if ((trknameofs) && (trknamelen < dwMemLength) && (trknameofs < dwMemLength - trknamelen)) + { +- lstrcpyn(ChnSettings[i].szName, (LPCSTR)(lpStream+trknameofs), trknamelen); ++ lstrcpynA(ChnSettings[i].szName, (LPCSTR)(lpStream+trknameofs), trknamelen); + ChnSettings[i].szName[MAX_CHANNELNAME-1] = '\0'; + } + } +diff --git a/src/load_mod.cpp b/src/load_mod.cpp +index 4b64b23..b78c5c9 100644 +--- a/src/load_mod.cpp ++++ b/src/load_mod.cpp +@@ -469,9 +469,9 @@ BOOL CSoundFile::SaveMod(LPCSTR lpszFileName, UINT nPacking) + fwrite(ord, 128, 1, f); + // Writing signature + if (m_nChannels == 4) +- lstrcpy((LPSTR)&bTab, "M.K."); ++ lstrcpyA((LPSTR)&bTab, "M.K."); + else +- wsprintf((LPSTR)&bTab, "%luCHN", m_nChannels); ++ wsprintfA((LPSTR)&bTab, "%luCHN", m_nChannels); + fwrite(bTab, 4, 1, f); + // Writing patterns + for (UINT ipat=0; ipatsamplename, 28); ++ lstrcpynA(m_szNames[ismp+1], psmp->samplename, 28); + memcpy(pins->name, psmp->filename, 12); + pins->name[12] = 0; + pins->nGlobalVol = 64; +diff --git a/src/load_xm.cpp b/src/load_xm.cpp +index 4d5a493..bd254c3 100644 +--- a/src/load_xm.cpp ++++ b/src/load_xm.cpp +@@ -610,7 +610,7 @@ BOOL CSoundFile::SaveXM(LPCSTR lpszFileName, UINT nPacking) + fwrite("Extended Module: ", 17, 1, f); + fwrite(m_szNames[0], 20, 1, f); + s[0] = 0x1A; +- lstrcpy((LPSTR)&s[1], (nPacking) ? "MOD Plugin packed " : "FastTracker v2.00 "); ++ lstrcpyA((LPSTR)&s[1], (nPacking) ? "MOD Plugin packed " : "FastTracker v2.00 "); + s[21] = 0x04; + s[22] = 0x01; + fwrite(s, 23, 1, f); +diff --git a/src/sndfile.cpp b/src/sndfile.cpp +index 24550de..c3488b8 100644 +--- a/src/sndfile.cpp ++++ b/src/sndfile.cpp +@@ -376,13 +376,13 @@ void CSoundFile::ResetMidiCfg() + //----------------------------- + { + memset(&m_MidiCfg, 0, sizeof(m_MidiCfg)); +- lstrcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_START*32], "FF"); +- lstrcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_STOP*32], "FC"); +- lstrcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_NOTEON*32], "9c n v"); +- lstrcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_NOTEOFF*32], "9c n 0"); +- lstrcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_PROGRAM*32], "Cc p"); +- lstrcpy(&m_MidiCfg.szMidiSFXExt[0], "F0F000z"); +- for (int iz=0; iz<16; iz++) wsprintf(&m_MidiCfg.szMidiZXXExt[iz*32], "F0F001%02X", iz*8); ++ lstrcpyA(&m_MidiCfg.szMidiGlb[MIDIOUT_START*32], "FF"); ++ lstrcpyA(&m_MidiCfg.szMidiGlb[MIDIOUT_STOP*32], "FC"); ++ lstrcpyA(&m_MidiCfg.szMidiGlb[MIDIOUT_NOTEON*32], "9c n v"); ++ lstrcpyA(&m_MidiCfg.szMidiGlb[MIDIOUT_NOTEOFF*32], "9c n 0"); ++ lstrcpyA(&m_MidiCfg.szMidiGlb[MIDIOUT_PROGRAM*32], "Cc p"); ++ lstrcpyA(&m_MidiCfg.szMidiSFXExt[0], "F0F000z"); ++ for (int iz=0; iz<16; iz++) wsprintfA(&m_MidiCfg.szMidiZXXExt[iz*32], "F0F001%02X", iz*8); + } + + +@@ -1789,7 +1789,7 @@ BOOL CSoundFile::SetPatternName(UINT nPat, LPCSTR lpszName) + if (nPat >= MAX_PATTERNS) return FALSE; + if (lpszName == NULL) return(FALSE); + +- if (lpszName) lstrcpyn(szName, lpszName, MAX_PATTERNNAME); ++ if (lpszName) lstrcpynA(szName, lpszName, MAX_PATTERNNAME); + szName[MAX_PATTERNNAME-1] = 0; + if (!m_lpszPatternNames) m_nPatternNames = 0; + if (nPat >= m_nPatternNames) diff --git a/SMP/appveyor.yml b/SMP/appveyor.yml index e4487b4..7f31275 100644 --- a/SMP/appveyor.yml +++ b/SMP/appveyor.yml @@ -80,7 +80,7 @@ before_build: - + diff --git a/SMP/libmodplug_with_latest_sdk.bat b/SMP/libmodplug_with_latest_sdk.bat index 1df5d62..9790649 100644 --- a/SMP/libmodplug_with_latest_sdk.bat +++ b/SMP/libmodplug_with_latest_sdk.bat @@ -1,59 +1,59 @@ -@ECHO OFF - -SET PROJECT=libmodplug - -@REM Detect the newest available Windows SDK -CALL :GetWindowsSdkVer - -@REM Open the project -%PROJECT%.sln - -EXIT /B 0 - -:GetWindowsSdkVer -SET WindowsTargetPlatformVersion= - -IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin10SdkVer -IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin81SdkVer -EXIT /B 0 - -:GetWin10SdkVer -CALL :GetWin10SdkVerHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1 -IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1 -IF errorlevel 1 CALL :GetWin10SdkVerHelper HKLM\SOFTWARE > nul 2>&1 -IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE > nul 2>&1 -IF errorlevel 1 EXIT /B 1 -EXIT /B 0 - -:GetWin10SdkVerHelper -@REM Get Windows 10 SDK installed folder -FOR /F "tokens=1,2*" %%i IN ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO ( - IF "%%i"=="InstallationFolder" ( - SET WindowsSdkDir=%%~k - ) -) - -@REM get windows 10 sdk version number -SETLOCAL enableDelayedExpansion -IF NOT "%WindowsSdkDir%"=="" FOR /f %%i IN ('dir "%WindowsSdkDir%include\" /b /ad-h /on') DO ( - @REM Skip if Windows.h is not found in %%i\um. This would indicate that only the UCRT MSIs were - @REM installed for this Windows SDK version. - IF EXIST "%WindowsSdkDir%include\%%i\um\Windows.h" ( - SET result=%%i - IF "!result:~0,3!"=="10." ( - SET SDK=!result! - IF "!result!"=="%VSCMD_ARG_WINSDK%" SET findSDK=1 - ) - ) -) - -IF "%findSDK%"=="1" SET SDK=%VSCMD_ARG_WINSDK% -ENDLOCAL & SET WindowsTargetPlatformVersion=%SDK% -IF "%WindowsTargetPlatformVersion%"=="" ( - EXIT /B 1 -) -EXIT /B 0 - -:GetWin81SdkVer -SET WindowsTargetPlatformVersion=8.1 -EXIT /B 0 +@ECHO OFF + +SET PROJECT=libmodplug + +@REM Detect the newest available Windows SDK +CALL :GetWindowsSdkVer + +@REM Open the project +%PROJECT%.sln + +EXIT /B 0 + +:GetWindowsSdkVer +SET WindowsTargetPlatformVersion= + +IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin10SdkVer +IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin81SdkVer +EXIT /B 0 + +:GetWin10SdkVer +CALL :GetWin10SdkVerHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1 +IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1 +IF errorlevel 1 CALL :GetWin10SdkVerHelper HKLM\SOFTWARE > nul 2>&1 +IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE > nul 2>&1 +IF errorlevel 1 EXIT /B 1 +EXIT /B 0 + +:GetWin10SdkVerHelper +@REM Get Windows 10 SDK installed folder +FOR /F "tokens=1,2*" %%i IN ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO ( + IF "%%i"=="InstallationFolder" ( + SET WindowsSdkDir=%%~k + ) +) + +@REM get windows 10 sdk version number +SETLOCAL enableDelayedExpansion +IF NOT "%WindowsSdkDir%"=="" FOR /f %%i IN ('dir "%WindowsSdkDir%include\" /b /ad-h /on') DO ( + @REM Skip if Windows.h is not found in %%i\um. This would indicate that only the UCRT MSIs were + @REM installed for this Windows SDK version. + IF EXIST "%WindowsSdkDir%include\%%i\um\Windows.h" ( + SET result=%%i + IF "!result:~0,3!"=="10." ( + SET SDK=!result! + IF "!result!"=="%VSCMD_ARG_WINSDK%" SET findSDK=1 + ) + ) +) + +IF "%findSDK%"=="1" SET SDK=%VSCMD_ARG_WINSDK% +ENDLOCAL & SET WindowsTargetPlatformVersion=%SDK% +IF "%WindowsTargetPlatformVersion%"=="" ( + EXIT /B 1 +) +EXIT /B 0 + +:GetWin81SdkVer +SET WindowsTargetPlatformVersion=8.1 +EXIT /B 0 diff --git a/SMP/readme.txt b/SMP/readme.txt index bd91a3e..a5c1734 100644 --- a/SMP/readme.txt +++ b/SMP/readme.txt @@ -1,6 +1,22 @@ -This is a small list of steps in order to build modplug into a msvc DLL and lib file. +This is a small list of steps in order to build libmodplug into a msvc dll and/or lib file. The project contains Release and Debug builds for static lib files (Debug/Release) - as well as dynamic shared dll files (DebugDLL/ReleaseDLL). -Choose whichever project configuration meets your requirements. \ No newline at end of file + as well as dynamic shared dll files (DebugDLL/ReleaseDLL). Along with the standard + windows dll/lib configurations mentioned above there are also equivalent variants that + can be used to compile for WinRT/UWP (These configurations have a WinRT suffix). +There are also architecture configurations for either 32bit (x86) or 64bit (x64) compilation. +Choose whichever project configuration meets your requirements. + +The project configurations support being built with various different windows SDK versions. + By default they will use the lowest SDK version that would be available for Visual Studio + version 2013 and up (This is the 8.1 SDK). However a batch file is also included + (libfribidi_with_latest_sdk.bat) which can be used to auto detect the newest available SDK + installed on the host machine and then open the project using that as the compilation SDK. + +When using the WinRT/UWP project configurations the projects will automatically compile towards + the default application target for the Version of Visual Studio being used: + VS 2013: 8.1 + VS 2015: 8.1 + VS 2017+: 10.0.10240.0 +