Skip to content

Commit

Permalink
project: Update for recent upstream merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sibras committed Feb 13, 2022
1 parent 2f40f53 commit 9fb257d
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 66 deletions.
7 changes: 4 additions & 3 deletions SMP/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.sln text=auto
*.vcxproj text=auto
*.vcxproj.filters text=auto
*.sln text eol=crlf
*.vcxproj text eol=crlf
*.vcxproj.filters text eol=crlf
*.bat text eol=crlf
239 changes: 239 additions & 0 deletions SMP/SMP.patch
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>
+#include <strsafe.h>
#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 <stdlib.h>
@@ -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<ientries; i++) if (i < m_nSamples)
{
- lstrcpyn(m_szNames[i+1], psznames + i*ientrysz, maxnamelen);
+ lstrcpynA(m_szNames[i+1], psznames + i*ientrysz, maxnamelen);
m_szNames[i+1][31] = '\0';
}
}
@@ -768,7 +768,7 @@ BOOL CSoundFile::ReadMed(const BYTE *lpStream, DWORD dwMemLength)
if (trknamelen > 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; ipat<nbp; ipat++) if (Patterns[ipat])
diff --git a/src/load_psm.cpp b/src/load_psm.cpp
index d594c76..3902216 100644
--- a/src/load_psm.cpp
+++ b/src/load_psm.cpp
@@ -202,7 +202,7 @@ BOOL CSoundFile::ReadPSM(LPCBYTE lpStream, DWORD dwMemLength)
CHAR s[8], s2[64];
*(DWORD *)s = pchunk.id;
s[4] = 0;
- wsprintf(s2, "%s: %4d bytes @ %4d\n", s, pchunk.len, dwMemPos);
+ wsprintfA(s2, "%s: %4d bytes @ %4d\n", s, pchunk.len, dwMemPos);
OutputDebugString(s2);
}
#endif
diff --git a/src/load_ptm.cpp b/src/load_ptm.cpp
index 0ace71a..6ddb9a7 100644
--- a/src/load_ptm.cpp
+++ b/src/load_ptm.cpp
@@ -109,7 +109,7 @@ BOOL CSoundFile::ReadPTM(const BYTE *lpStream, DWORD dwMemLength)
MODINSTRUMENT *pins = &Ins[ismp+1];
PTMSAMPLE *psmp = (PTMSAMPLE *)(lpStream+dwMemPos);

- lstrcpyn(m_szNames[ismp+1], psmp->samplename, 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)
2 changes: 1 addition & 1 deletion SMP/appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ before_build:
</ItemGroup>
</Target>
<Target Name="Build" DependsOnTargets="List">
<MSBuild Projects="@(ProjectToBuild)" BuildInParallel="true" />
<MSBuild Projects="@(ProjectToBuild)" BuildInParallel="false" />
</Target>
<Target Name="GitLink" DependsOnTargets="Build" Outputs="%(PlatformList.Identity)">
<PropertyGroup>
Expand Down
118 changes: 59 additions & 59 deletions SMP/libmodplug_with_latest_sdk.bat
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 9fb257d

Please sign in to comment.