gosu 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dependencies/SDL/include/SDL.h +108 -14
- data/dependencies/SDL/include/SDL_assert.h +81 -50
- data/dependencies/SDL/include/SDL_atomic.h +135 -35
- data/dependencies/SDL/include/SDL_audio.h +960 -355
- data/dependencies/SDL/include/SDL_bits.h +11 -6
- data/dependencies/SDL/include/SDL_blendmode.h +91 -14
- data/dependencies/SDL/include/SDL_clipboard.h +30 -7
- data/dependencies/SDL/include/SDL_config.h +277 -27
- data/dependencies/SDL/include/SDL_config_android.h +13 -38
- data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
- data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
- data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
- data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
- data/dependencies/SDL/include/SDL_config_psp.h +16 -37
- data/dependencies/SDL/include/SDL_config_windows.h +28 -91
- data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
- data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
- data/dependencies/SDL/include/SDL_copying.h +1 -1
- data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
- data/dependencies/SDL/include/SDL_egl.h +906 -280
- data/dependencies/SDL/include/SDL_endian.h +101 -47
- data/dependencies/SDL/include/SDL_error.h +70 -19
- data/dependencies/SDL/include/SDL_events.h +387 -79
- data/dependencies/SDL/include/SDL_filesystem.h +73 -64
- data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
- data/dependencies/SDL/include/SDL_gesture.h +36 -6
- data/dependencies/SDL/include/SDL_haptic.h +304 -210
- data/dependencies/SDL/include/SDL_hidapi.h +451 -0
- data/dependencies/SDL/include/SDL_hints.h +1286 -897
- data/dependencies/SDL/include/SDL_joystick.h +577 -130
- data/dependencies/SDL/include/SDL_keyboard.h +162 -63
- data/dependencies/SDL/include/SDL_keycode.h +7 -5
- data/dependencies/SDL/include/SDL_loadso.h +42 -8
- data/dependencies/SDL/include/SDL_locale.h +34 -32
- data/dependencies/SDL/include/SDL_log.h +212 -19
- data/dependencies/SDL/include/SDL_main.h +72 -17
- data/dependencies/SDL/include/SDL_messagebox.h +70 -23
- data/dependencies/SDL/include/SDL_metal.h +27 -32
- data/dependencies/SDL/include/SDL_misc.h +19 -15
- data/dependencies/SDL/include/SDL_mouse.h +262 -110
- data/dependencies/SDL/include/SDL_mutex.h +286 -66
- data/dependencies/SDL/include/SDL_name.h +1 -1
- data/dependencies/SDL/include/SDL_opengl.h +1 -1
- data/dependencies/SDL/include/SDL_opengles.h +1 -1
- data/dependencies/SDL/include/SDL_opengles2.h +2 -2
- data/dependencies/SDL/include/SDL_pixels.h +199 -34
- data/dependencies/SDL/include/SDL_platform.h +39 -2
- data/dependencies/SDL/include/SDL_power.h +23 -10
- data/dependencies/SDL/include/SDL_quit.h +1 -1
- data/dependencies/SDL/include/SDL_rect.h +78 -28
- data/dependencies/SDL/include/SDL_render.h +1204 -472
- data/dependencies/SDL/include/SDL_revision.h +2 -2
- data/dependencies/SDL/include/SDL_rwops.h +605 -33
- data/dependencies/SDL/include/SDL_scancode.h +1 -1
- data/dependencies/SDL/include/SDL_sensor.h +76 -42
- data/dependencies/SDL/include/SDL_shape.h +38 -27
- data/dependencies/SDL/include/SDL_stdinc.h +96 -24
- data/dependencies/SDL/include/SDL_surface.h +571 -139
- data/dependencies/SDL/include/SDL_system.h +339 -101
- data/dependencies/SDL/include/SDL_syswm.h +50 -20
- data/dependencies/SDL/include/SDL_test.h +1 -1
- data/dependencies/SDL/include/SDL_test_assert.h +2 -2
- data/dependencies/SDL/include/SDL_test_common.h +23 -6
- data/dependencies/SDL/include/SDL_test_compare.h +1 -1
- data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
- data/dependencies/SDL/include/SDL_test_font.h +3 -3
- data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
- data/dependencies/SDL/include/SDL_test_harness.h +6 -6
- data/dependencies/SDL/include/SDL_test_images.h +1 -1
- data/dependencies/SDL/include/SDL_test_log.h +1 -1
- data/dependencies/SDL/include/SDL_test_md5.h +1 -1
- data/dependencies/SDL/include/SDL_test_memory.h +1 -1
- data/dependencies/SDL/include/SDL_test_random.h +2 -2
- data/dependencies/SDL/include/SDL_thread.h +226 -128
- data/dependencies/SDL/include/SDL_timer.h +129 -22
- data/dependencies/SDL/include/SDL_touch.h +48 -8
- data/dependencies/SDL/include/SDL_types.h +1 -1
- data/dependencies/SDL/include/SDL_version.h +72 -46
- data/dependencies/SDL/include/SDL_video.h +1266 -460
- data/dependencies/SDL/include/SDL_vulkan.h +100 -161
- data/dependencies/SDL/include/begin_code.h +22 -1
- data/dependencies/SDL/include/close_code.h +1 -1
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.c +83 -7
- data/dependencies/SDL_sound/SDL_sound.h +4 -4
- data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
- data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
- data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
- data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
- data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
- data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
- data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
- data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
- data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
- data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
- data/dependencies/SDL_sound/dr_flac.h +618 -220
- data/dependencies/SDL_sound/dr_mp3.h +263 -94
- data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
- data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
- data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
- data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
- data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
- data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
- data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
- data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
- data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
- data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
- data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
- data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
- data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
- data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
- data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
- data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
- data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
- data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
- data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
- data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
- data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
- data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
- data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
- data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
- data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
- data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
- data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
- data/dependencies/SDL_sound/stb_vorbis.h +508 -325
- data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
- data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
- data/dependencies/mojoAL/mojoal.c +4594 -0
- data/ext/gosu/extconf.rb +29 -30
- data/include/Gosu/Audio.hpp +70 -85
- data/include/Gosu/Color.hpp +19 -11
- data/include/Gosu/Font.hpp +40 -44
- data/include/Gosu/Graphics.hpp +58 -71
- data/include/Gosu/GraphicsBase.hpp +26 -33
- data/include/Gosu/Image.hpp +56 -62
- data/include/Gosu/ImageData.hpp +23 -27
- data/include/Gosu/Inspection.hpp +1 -4
- data/include/Gosu/TextInput.hpp +34 -40
- data/include/Gosu/Version.hpp +1 -1
- data/include/Gosu/Window.hpp +71 -70
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/compat.rb +24 -37
- data/lib/gosu.rb +2 -2
- data/lib64/SDL2.dll +0 -0
- data/src/Audio.cpp +86 -86
- data/src/AudioFile.hpp +6 -6
- data/src/AudioFileAudioToolbox.cpp +1 -1
- data/src/AudioFileSDLSound.cpp +1 -1
- data/src/AudioImpl.hpp +5 -5
- data/src/BitmapIO.cpp +0 -20
- data/src/BlockAllocator.cpp +2 -1
- data/src/Channel.cpp +22 -20
- data/src/Color.cpp +12 -9
- data/src/EmptyImageData.hpp +15 -17
- data/src/FileUnix.cpp +1 -1
- data/src/FileWin.cpp +1 -1
- data/src/Font.cpp +48 -53
- data/src/Graphics.cpp +135 -143
- data/src/Image.cpp +41 -42
- data/src/Input.cpp +1 -1
- data/src/InputUIKit.cpp +1 -1
- data/src/LargeImageData.cpp +108 -101
- data/src/LargeImageData.hpp +17 -15
- data/src/Log.hpp +6 -6
- data/src/Macro.cpp +35 -37
- data/src/Macro.hpp +11 -11
- data/src/Math.cpp +8 -1
- data/src/Resolution.cpp +12 -7
- data/src/RubyGosu.cxx +5 -5
- data/src/TexChunk.cpp +50 -41
- data/src/TexChunk.hpp +22 -22
- data/src/Text.cpp +37 -37
- data/src/TextBuilder.cpp +60 -57
- data/src/TextBuilder.hpp +20 -20
- data/src/TextInput.cpp +127 -135
- data/src/TrueTypeFont.cpp +107 -107
- data/src/TrueTypeFont.hpp +39 -38
- data/src/TrueTypeFontApple.cpp +19 -22
- data/src/TrueTypeFontUnix.cpp +21 -26
- data/src/TrueTypeFontWin.cpp +30 -30
- data/src/Window.cpp +95 -86
- data/src/WindowUIKit.cpp +46 -49
- metadata +7 -17
- data/dependencies/SDL/include/SDL_config_os2.h +0 -188
- data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
- data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
- data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
- data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
- data/dependencies/al_soft/AL/alext.h +0 -585
- data/dependencies/al_soft/AL/efx-creative.h +0 -3
- data/dependencies/al_soft/AL/efx-presets.h +0 -402
- data/dependencies/al_soft/AL/efx.h +0 -762
- data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
- data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
- data/lib/OpenAL32.dll +0 -0
- data/lib64/OpenAL32.dll +0 -0
@@ -16,7 +16,7 @@
|
|
16
16
|
typedef struct tagFILEHEADER669
|
17
17
|
{
|
18
18
|
WORD sig; // 'if' or 'JN'
|
19
|
-
|
19
|
+
signed char songmessage[108]; // Song Message
|
20
20
|
BYTE samples; // number of samples (1-64)
|
21
21
|
BYTE patterns; // number of patterns (1-128)
|
22
22
|
BYTE restartpos;
|
@@ -25,7 +25,6 @@ typedef struct tagFILEHEADER669
|
|
25
25
|
BYTE breaks[128];
|
26
26
|
} FILEHEADER669;
|
27
27
|
|
28
|
-
|
29
28
|
typedef struct tagSAMPLE669
|
30
29
|
{
|
31
30
|
BYTE filename[13];
|
@@ -34,11 +33,11 @@ typedef struct tagSAMPLE669
|
|
34
33
|
BYTE loopend[4];
|
35
34
|
} SAMPLE669;
|
36
35
|
|
37
|
-
DWORD lengthArrayToDWORD(const BYTE length[4]) {
|
36
|
+
static DWORD lengthArrayToDWORD(const BYTE length[4]) {
|
38
37
|
DWORD len = (length[3] << 24) +
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
(length[2] << 16) +
|
39
|
+
(length[1] << 8) +
|
40
|
+
(length[0]);
|
42
41
|
|
43
42
|
return(len);
|
44
43
|
}
|
@@ -47,14 +46,14 @@ DWORD lengthArrayToDWORD(const BYTE length[4]) {
|
|
47
46
|
BOOL CSoundFile_Read669(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLength)
|
48
47
|
//---------------------------------------------------------------
|
49
48
|
{
|
50
|
-
BOOL b669Ext;
|
49
|
+
// BOOL b669Ext;
|
51
50
|
const FILEHEADER669 *pfh = (const FILEHEADER669 *)lpStream;
|
52
51
|
const SAMPLE669 *psmp = (const SAMPLE669 *)(lpStream + 0x1F1);
|
53
52
|
DWORD dwMemPos = 0;
|
54
53
|
|
55
54
|
if ((!lpStream) || (dwMemLength < sizeof(FILEHEADER669))) return FALSE;
|
56
55
|
if ((bswapLE16(pfh->sig) != 0x6669) && (bswapLE16(pfh->sig) != 0x4E4A)) return FALSE;
|
57
|
-
b669Ext = (bswapLE16(pfh->sig) == 0x4E4A) ? TRUE : FALSE;
|
56
|
+
// b669Ext = (bswapLE16(pfh->sig) == 0x4E4A) ? TRUE : FALSE;
|
58
57
|
if ((!pfh->samples) || (pfh->samples > 64) || (pfh->restartpos >= 128)
|
59
58
|
|| (!pfh->patterns) || (pfh->patterns > 128)) return FALSE;
|
60
59
|
DWORD donttouchme = 0x1F1 + pfh->samples * sizeof(SAMPLE669) + pfh->patterns * 0x600;
|
@@ -70,7 +69,7 @@ BOOL CSoundFile_Read669(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
70
69
|
_this->m_dwSongFlags |= SONG_LINEARSLIDES;
|
71
70
|
_this->m_nMinPeriod = 28 << 2;
|
72
71
|
_this->m_nMaxPeriod = 1712 << 3;
|
73
|
-
_this->m_nDefaultTempo =
|
72
|
+
_this->m_nDefaultTempo = 78;
|
74
73
|
_this->m_nDefaultSpeed = 6;
|
75
74
|
_this->m_nChannels = 8;
|
76
75
|
_this->m_nSamples = pfh->samples;
|
@@ -147,11 +146,11 @@ BOOL CSoundFile_Read669(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
147
146
|
case 0x02: command = CMD_TONEPORTAMENTO; break;
|
148
147
|
case 0x03: command = CMD_MODCMDEX; param |= 0x50; break;
|
149
148
|
case 0x04: command = CMD_VIBRATO; param |= 0x40; break;
|
150
|
-
case 0x05: if (param) command = CMD_SPEED; else command = 0;
|
151
|
-
case 0x06: if (param == 0) { command = CMD_PANNINGSLIDE; param = 0xFE; }
|
152
|
-
|
153
|
-
|
154
|
-
|
149
|
+
case 0x05: if (param) command = CMD_SPEED; else command = 0; break;
|
150
|
+
case 0x06: if (param == 0) { command = CMD_PANNINGSLIDE; param = 0xFE; }
|
151
|
+
else if (param == 1) { command = CMD_PANNINGSLIDE; param = 0xEF; }
|
152
|
+
else command = 0;
|
153
|
+
break;
|
155
154
|
default: command = 0;
|
156
155
|
}
|
157
156
|
if (command)
|
@@ -167,7 +166,7 @@ BOOL CSoundFile_Read669(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
167
166
|
for (UINT i=0; i<8; i++) if (!mspeed[i].command)
|
168
167
|
{
|
169
168
|
mspeed[i].command = CMD_SPEED;
|
170
|
-
mspeed[i].param = pfh->tempolist[npat]
|
169
|
+
mspeed[i].param = pfh->tempolist[npat];
|
171
170
|
break;
|
172
171
|
}
|
173
172
|
}
|
@@ -184,5 +183,3 @@ BOOL CSoundFile_Read669(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
184
183
|
}
|
185
184
|
return TRUE;
|
186
185
|
}
|
187
|
-
|
188
|
-
|
@@ -39,11 +39,10 @@ typedef struct _AMFSAMPLE
|
|
39
39
|
UCHAR volume;
|
40
40
|
} AMFSAMPLE;
|
41
41
|
|
42
|
-
|
43
42
|
#pragma pack()
|
44
43
|
|
45
44
|
|
46
|
-
VOID AMF_Unpack(MODCOMMAND *pPat, const BYTE *pTrack, UINT nRows, UINT nChannels)
|
45
|
+
static VOID AMF_Unpack(MODCOMMAND *pPat, const BYTE *pTrack, UINT nRows, UINT nChannels)
|
47
46
|
//-------------------------------------------------------------------------------
|
48
47
|
{
|
49
48
|
UINT lastinstr = 0;
|
@@ -139,6 +138,7 @@ VOID AMF_Unpack(MODCOMMAND *pPat, const BYTE *pTrack, UINT nRows, UINT nChannels
|
|
139
138
|
case 0x17: param = (param+64)&0x7F;
|
140
139
|
if (m->command) { if (!m->volcmd) { m->volcmd = VOLCMD_PANNING; m->vol = param/2; } command = 0; }
|
141
140
|
else { command = CMD_PANNING8; }
|
141
|
+
break;
|
142
142
|
// Unknown effects
|
143
143
|
default: command = param = 0;
|
144
144
|
}
|
@@ -153,7 +153,6 @@ VOID AMF_Unpack(MODCOMMAND *pPat, const BYTE *pTrack, UINT nRows, UINT nChannels
|
|
153
153
|
}
|
154
154
|
|
155
155
|
|
156
|
-
|
157
156
|
BOOL CSoundFile_ReadAMF(CSoundFile *_this, LPCBYTE lpStream, const DWORD dwMemLength)
|
158
157
|
//-----------------------------------------------------------
|
159
158
|
{
|
@@ -300,8 +299,12 @@ BOOL CSoundFile_ReadAMF(CSoundFile *_this, LPCBYTE lpStream, const DWORD dwMemLe
|
|
300
299
|
_this->PatternSize[iOrd] = 64;
|
301
300
|
if (pfh->version >= 14)
|
302
301
|
{
|
302
|
+
if (dwMemPos + _this->m_nChannels * sizeof(USHORT) + 2 > dwMemLength) return FALSE;
|
303
303
|
_this->PatternSize[iOrd] = bswapLE16(*(USHORT *)(lpStream+dwMemPos));
|
304
304
|
dwMemPos += 2;
|
305
|
+
} else
|
306
|
+
{
|
307
|
+
if (dwMemPos + _this->m_nChannels * sizeof(USHORT) > dwMemLength) return FALSE;
|
305
308
|
}
|
306
309
|
ptracks[iOrd] = (USHORT *)(lpStream+dwMemPos);
|
307
310
|
dwMemPos += _this->m_nChannels * sizeof(USHORT);
|
@@ -345,14 +348,16 @@ BOOL CSoundFile_ReadAMF(CSoundFile *_this, LPCBYTE lpStream, const DWORD dwMemLe
|
|
345
348
|
USHORT *pTrackMap = (USHORT *)(lpStream+dwMemPos);
|
346
349
|
UINT realtrackcnt = 0;
|
347
350
|
dwMemPos += pfh->numtracks * sizeof(USHORT);
|
351
|
+
if (dwMemPos >= dwMemLength)
|
352
|
+
return TRUE;
|
353
|
+
|
348
354
|
for (UINT iTrkMap=0; iTrkMap<pfh->numtracks; iTrkMap++)
|
349
355
|
{
|
350
356
|
if (realtrackcnt < pTrackMap[iTrkMap]) realtrackcnt = pTrackMap[iTrkMap];
|
351
357
|
}
|
352
358
|
// Store tracks positions
|
353
|
-
BYTE **pTrackData = (BYTE **)
|
354
|
-
|
355
|
-
SDL_memset(pTrackData, 0, sizeof(BYTE *) * realtrackcnt);
|
359
|
+
BYTE **pTrackData = (BYTE **) SDL_calloc(realtrackcnt, sizeof(BYTE*));
|
360
|
+
if (!pTrackData) return TRUE;/*FIXME: return FALSE? */
|
356
361
|
for (UINT iTrack=0; iTrack<realtrackcnt; iTrack++) if (dwMemPos <= dwMemLength - 3)
|
357
362
|
{
|
358
363
|
UINT nTrkSize = bswapLE16(*(USHORT *)(lpStream+dwMemPos));
|
@@ -400,4 +405,3 @@ BOOL CSoundFile_ReadAMF(CSoundFile *_this, LPCBYTE lpStream, const DWORD dwMemLe
|
|
400
405
|
}
|
401
406
|
return TRUE;
|
402
407
|
}
|
403
|
-
|
@@ -34,18 +34,18 @@ typedef struct AMSSAMPLEHEADER
|
|
34
34
|
BYTE infobyte;
|
35
35
|
} AMSSAMPLEHEADER;
|
36
36
|
|
37
|
-
|
38
37
|
#pragma pack()
|
39
38
|
|
39
|
+
static BOOL AMSUnpackCheck(const BYTE *lpStream, DWORD dwMemLength, MODINSTRUMENT *ins);
|
40
40
|
|
41
41
|
BOOL CSoundFile_ReadAMS(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
42
42
|
//-----------------------------------------------------------
|
43
43
|
{
|
44
|
-
BYTE pkinf[MAX_SAMPLES];
|
45
|
-
AMSFILEHEADER *pfh = (AMSFILEHEADER *)lpStream;
|
44
|
+
// BYTE pkinf[MAX_SAMPLES];
|
45
|
+
const AMSFILEHEADER *pfh = (AMSFILEHEADER *)lpStream;
|
46
46
|
DWORD dwMemPos;
|
47
47
|
UINT tmp, tmp2;
|
48
|
-
|
48
|
+
|
49
49
|
if ((!lpStream) || (dwMemLength < 1024)) return FALSE;
|
50
50
|
if ((pfh->verhi != 0x01) || (SDL_strncmp(pfh->szHeader, "Extreme", 7))
|
51
51
|
|| (!pfh->patterns) || (!pfh->orders) || (!pfh->samples) || (pfh->samples >= MAX_SAMPLES)
|
@@ -61,7 +61,7 @@ BOOL CSoundFile_ReadAMS(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
61
61
|
_this->m_nSamples = pfh->samples;
|
62
62
|
for (UINT nSmp=1; nSmp<=_this->m_nSamples; nSmp++, dwMemPos += sizeof(AMSSAMPLEHEADER))
|
63
63
|
{
|
64
|
-
AMSSAMPLEHEADER *psh = (AMSSAMPLEHEADER *)(lpStream + dwMemPos);
|
64
|
+
const AMSSAMPLEHEADER *psh = (AMSSAMPLEHEADER *)(lpStream + dwMemPos);
|
65
65
|
MODINSTRUMENT *pins = &_this->Ins[nSmp];
|
66
66
|
pins->nLength = psh->length;
|
67
67
|
pins->nLoopStart = psh->loopstart;
|
@@ -74,7 +74,7 @@ BOOL CSoundFile_ReadAMS(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
74
74
|
pins->nFineTune = MOD2XMFineTune(psh->finetune_and_pan & 0x0F);
|
75
75
|
pins->uFlags = (psh->infobyte & 0x80) ? CHN_16BIT : 0;
|
76
76
|
if ((pins->nLoopEnd <= pins->nLength) && (pins->nLoopStart+4 <= pins->nLoopEnd)) pins->uFlags |= CHN_LOOP;
|
77
|
-
|
77
|
+
// pkinf[nSmp] = psh->infobyte;
|
78
78
|
}
|
79
79
|
// Read Song Name
|
80
80
|
tmp = lpStream[dwMemPos++];
|
@@ -95,10 +95,9 @@ BOOL CSoundFile_ReadAMS(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
95
95
|
dwMemPos += tmp;
|
96
96
|
}
|
97
97
|
// Read Pattern Names
|
98
|
-
_this->m_lpszPatternNames = (char *)
|
98
|
+
_this->m_lpszPatternNames = (char *) SDL_calloc(pfh->patterns, 32); // changed from CHAR
|
99
99
|
if (!_this->m_lpszPatternNames) return TRUE;
|
100
100
|
_this->m_nPatternNames = pfh->patterns;
|
101
|
-
SDL_memset(_this->m_lpszPatternNames, 0, _this->m_nPatternNames * 32);
|
102
101
|
for (UINT pNam=0; pNam < _this->m_nPatternNames; pNam++)
|
103
102
|
{
|
104
103
|
if (dwMemPos + 32 >= dwMemLength) return TRUE;
|
@@ -108,14 +107,16 @@ BOOL CSoundFile_ReadAMS(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
108
107
|
dwMemPos += tmp;
|
109
108
|
}
|
110
109
|
// Read Song Comments
|
110
|
+
if (dwMemPos + 2 > dwMemLength) return TRUE;
|
111
111
|
tmp = *((WORD *)(lpStream+dwMemPos));
|
112
112
|
dwMemPos += 2;
|
113
|
-
if (dwMemPos
|
113
|
+
if (tmp >= dwMemLength || dwMemPos > dwMemLength - tmp) return TRUE;
|
114
114
|
if (tmp)
|
115
115
|
{
|
116
116
|
dwMemPos += tmp;
|
117
117
|
}
|
118
118
|
// Read Order List
|
119
|
+
if (2*pfh->orders >= dwMemLength || dwMemPos > dwMemLength - 2*pfh->orders) return TRUE;
|
119
120
|
for (UINT iOrd=0; iOrd<pfh->orders; iOrd++, dwMemPos += 2)
|
120
121
|
{
|
121
122
|
UINT n = *((WORD *)(lpStream+dwMemPos));
|
@@ -127,7 +128,7 @@ BOOL CSoundFile_ReadAMS(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
127
128
|
if (dwMemPos + 4 >= dwMemLength) return TRUE;
|
128
129
|
UINT len = *((DWORD *)(lpStream + dwMemPos));
|
129
130
|
dwMemPos += 4;
|
130
|
-
if ((len >= dwMemLength) || (dwMemPos
|
131
|
+
if ((len >= dwMemLength) || (dwMemPos > dwMemLength - len)) return TRUE;
|
131
132
|
_this->PatternSize[iPat] = 64;
|
132
133
|
MODCOMMAND *m = CSoundFile_AllocatePattern(_this->PatternSize[iPat], _this->m_nChannels);
|
133
134
|
if (!m) return TRUE;
|
@@ -143,6 +144,7 @@ BOOL CSoundFile_ReadAMS(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
143
144
|
// Note+Instr
|
144
145
|
if (!(b0 & 0x40))
|
145
146
|
{
|
147
|
+
if (i+1 > len) break;
|
146
148
|
b2 = p[i++];
|
147
149
|
if (ch < _this->m_nChannels)
|
148
150
|
{
|
@@ -151,6 +153,7 @@ BOOL CSoundFile_ReadAMS(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
151
153
|
}
|
152
154
|
if (b1 & 0x80)
|
153
155
|
{
|
156
|
+
if (i+1 > len) break;
|
154
157
|
b0 |= 0x40;
|
155
158
|
b1 = p[i++];
|
156
159
|
}
|
@@ -168,6 +171,7 @@ BOOL CSoundFile_ReadAMS(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
168
171
|
}
|
169
172
|
} else
|
170
173
|
{
|
174
|
+
if (i+1 > len) break;
|
171
175
|
b2 = p[i++];
|
172
176
|
if (ch < _this->m_nChannels)
|
173
177
|
{
|
@@ -210,6 +214,7 @@ BOOL CSoundFile_ReadAMS(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
210
214
|
}
|
211
215
|
if (b1 & 0x80)
|
212
216
|
{
|
217
|
+
if (i+1 > len) break;
|
213
218
|
b1 = p[i++];
|
214
219
|
if (i <= len) goto anothercommand;
|
215
220
|
}
|
@@ -227,7 +232,8 @@ BOOL CSoundFile_ReadAMS(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
227
232
|
{
|
228
233
|
if (dwMemPos >= dwMemLength - 9) return TRUE;
|
229
234
|
UINT flags = (_this->Ins[iSmp].uFlags & CHN_16BIT) ? RS_AMS16 : RS_AMS8;
|
230
|
-
|
235
|
+
if (!AMSUnpackCheck(lpStream+dwMemPos, dwMemLength-dwMemPos, &_this->Ins[iSmp])) break;
|
236
|
+
dwMemPos += CSoundFile_ReadSample(_this, &_this->Ins[iSmp], flags, (LPCSTR)(lpStream+dwMemPos), dwMemLength-dwMemPos);
|
231
237
|
}
|
232
238
|
return TRUE;
|
233
239
|
}
|
@@ -290,7 +296,6 @@ typedef struct AMS2SAMPLE
|
|
290
296
|
BYTE flags;
|
291
297
|
} AMS2SAMPLE;
|
292
298
|
|
293
|
-
|
294
299
|
#pragma pack()
|
295
300
|
|
296
301
|
|
@@ -298,7 +303,7 @@ BOOL CSoundFile_ReadAMS2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
298
303
|
//------------------------------------------------------------
|
299
304
|
{
|
300
305
|
const AMS2FILEHEADER *pfh = (AMS2FILEHEADER *)lpStream;
|
301
|
-
AMS2SONGHEADER *psh;
|
306
|
+
const AMS2SONGHEADER *psh;
|
302
307
|
DWORD dwMemPos;
|
303
308
|
BYTE smpmap[16];
|
304
309
|
BYTE packedsamples[MAX_SAMPLES];
|
@@ -319,23 +324,25 @@ BOOL CSoundFile_ReadAMS2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
319
324
|
if (psh->flags & 0x40) _this->m_dwSongFlags |= SONG_LINEARSLIDES;
|
320
325
|
for (UINT nIns=1; nIns<=_this->m_nInstruments; nIns++)
|
321
326
|
{
|
327
|
+
if (dwMemPos >= dwMemLength) return TRUE;
|
322
328
|
const UINT insnamelen = lpStream[dwMemPos];
|
323
|
-
CHAR *pinsname = (CHAR *)(lpStream+dwMemPos+1);
|
324
329
|
dwMemPos += insnamelen + 1;
|
325
|
-
AMS2INSTRUMENT *pins = (AMS2INSTRUMENT *)(lpStream + dwMemPos);
|
330
|
+
const AMS2INSTRUMENT *pins = (AMS2INSTRUMENT *)(lpStream + dwMemPos);
|
326
331
|
dwMemPos += sizeof(AMS2INSTRUMENT);
|
327
|
-
|
328
|
-
AMS2ENVELOPE
|
332
|
+
const AMS2ENVELOPE *volenv, *panenv, *pitchenv;
|
333
|
+
if (dwMemPos + sizeof(AMS2ENVELOPE) > dwMemLength) return TRUE;
|
329
334
|
volenv = (AMS2ENVELOPE *)(lpStream+dwMemPos);
|
330
335
|
dwMemPos += 5 + volenv->points*3;
|
336
|
+
if (dwMemPos + sizeof(AMS2ENVELOPE) > dwMemLength) return TRUE;
|
331
337
|
panenv = (AMS2ENVELOPE *)(lpStream+dwMemPos);
|
332
338
|
dwMemPos += 5 + panenv->points*3;
|
339
|
+
if (dwMemPos + sizeof(AMS2ENVELOPE) > dwMemLength) return TRUE;
|
333
340
|
pitchenv = (AMS2ENVELOPE *)(lpStream+dwMemPos);
|
334
341
|
dwMemPos += 5 + pitchenv->points*3;
|
335
|
-
|
342
|
+
if (dwMemPos >= dwMemLength) return TRUE;
|
343
|
+
INSTRUMENTHEADER *penv = (INSTRUMENTHEADER *) SDL_calloc(1, sizeof (INSTRUMENTHEADER));
|
336
344
|
if (!penv) return TRUE;
|
337
345
|
SDL_memset(smpmap, 0, sizeof(smpmap));
|
338
|
-
SDL_memset(penv, 0, sizeof(INSTRUMENTHEADER));
|
339
346
|
for (UINT ismpmap=0; ismpmap<pins->samples; ismpmap++)
|
340
347
|
{
|
341
348
|
if ((ismpmap >= 16) || (_this->m_nSamples+1 >= MAX_SAMPLES)) break;
|
@@ -365,6 +372,7 @@ BOOL CSoundFile_ReadAMS2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
365
372
|
penv->VolPoints[i] = (WORD)pos;
|
366
373
|
}
|
367
374
|
}
|
375
|
+
if (dwMemPos + 5 > dwMemLength) return TRUE;
|
368
376
|
penv->nFadeOut = (((lpStream[dwMemPos+2] & 0x0F) << 8) | (lpStream[dwMemPos+1])) << 3;
|
369
377
|
UINT envflags = lpStream[dwMemPos+3];
|
370
378
|
if (envflags & 0x01) penv->dwFlags |= ENV_VOLLOOP;
|
@@ -374,12 +382,15 @@ BOOL CSoundFile_ReadAMS2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
374
382
|
// Read Samples
|
375
383
|
for (UINT ismp=0; ismp<pins->samples; ismp++)
|
376
384
|
{
|
385
|
+
if (dwMemPos + 1 > dwMemLength) return TRUE;
|
377
386
|
MODINSTRUMENT *psmp = ((ismp < 16) && (smpmap[ismp])) ? &_this->Ins[smpmap[ismp]] : NULL;
|
378
387
|
const UINT smpnamelen = lpStream[dwMemPos];
|
388
|
+
if (dwMemPos + smpnamelen + 1 > dwMemLength) return TRUE;
|
379
389
|
dwMemPos += smpnamelen + 1;
|
390
|
+
if (dwMemPos + sizeof(AMS2SAMPLE) > dwMemLength) return TRUE;
|
380
391
|
if (psmp)
|
381
392
|
{
|
382
|
-
AMS2SAMPLE *pams = (AMS2SAMPLE *)(lpStream+dwMemPos);
|
393
|
+
const AMS2SAMPLE *pams = (AMS2SAMPLE *)(lpStream+dwMemPos);
|
383
394
|
psmp->nGlobalVol = 64;
|
384
395
|
psmp->nPan = 128;
|
385
396
|
psmp->nLength = pams->length;
|
@@ -506,16 +517,40 @@ BOOL CSoundFile_ReadAMS2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
506
517
|
if (packedsamples[iSmp] & 0x03)
|
507
518
|
{
|
508
519
|
flags = (_this->Ins[iSmp].uFlags & CHN_16BIT) ? RS_AMS16 : RS_AMS8;
|
520
|
+
if (!AMSUnpackCheck(lpStream+dwMemPos, dwMemLength-dwMemPos, &_this->Ins[iSmp])) break;
|
509
521
|
} else
|
510
522
|
{
|
511
523
|
flags = (_this->Ins[iSmp].uFlags & CHN_16BIT) ? RS_PCM16S : RS_PCM8S;
|
512
524
|
}
|
513
|
-
dwMemPos += CSoundFile_ReadSample(_this, &_this->Ins[iSmp], flags, (
|
525
|
+
dwMemPos += CSoundFile_ReadSample(_this, &_this->Ins[iSmp], flags, (LPCSTR)(lpStream+dwMemPos), dwMemLength-dwMemPos);
|
514
526
|
}
|
515
527
|
return TRUE;
|
516
528
|
}
|
517
529
|
|
518
530
|
|
531
|
+
// Precheck AMS packed sample size to determine whether or not it could fit the actual size.
|
532
|
+
static BOOL AMSUnpackCheck(const BYTE *lpStream, DWORD dwMemLength, MODINSTRUMENT *ins)
|
533
|
+
// -----------------------------------------------------------------------------------
|
534
|
+
{
|
535
|
+
if (dwMemLength < 9) return FALSE;
|
536
|
+
DWORD packedbytes = *((DWORD *)(lpStream + 4));
|
537
|
+
|
538
|
+
DWORD samplebytes = ins->nLength;
|
539
|
+
if (samplebytes > MAX_SAMPLE_LENGTH) samplebytes = MAX_SAMPLE_LENGTH;
|
540
|
+
if (ins->uFlags & CHN_16BIT) samplebytes *= 2;
|
541
|
+
|
542
|
+
// RLE can pack a run of up to 255 bytes into 3 bytes.
|
543
|
+
DWORD packedmin = (samplebytes * 3) >> 8;
|
544
|
+
if (packedbytes < packedmin)
|
545
|
+
{
|
546
|
+
samplebytes = packedbytes * (255 / 3) + 2;
|
547
|
+
ins->nLength = samplebytes;
|
548
|
+
if (ins->uFlags & CHN_16BIT) ins->nLength >>= 1;
|
549
|
+
}
|
550
|
+
|
551
|
+
return TRUE;
|
552
|
+
}
|
553
|
+
|
519
554
|
/////////////////////////////////////////////////////////////////////
|
520
555
|
// AMS Sample unpacking
|
521
556
|
|
@@ -523,7 +558,7 @@ void AMSUnpack(const char *psrc, UINT inputlen, char *pdest, UINT dmax, char pac
|
|
523
558
|
{
|
524
559
|
UINT tmplen = dmax;
|
525
560
|
signed char *amstmp = (signed char *) SDL_malloc(tmplen);
|
526
|
-
|
561
|
+
|
527
562
|
if (!amstmp) return;
|
528
563
|
// Unpack Loop
|
529
564
|
{
|
@@ -534,9 +569,11 @@ void AMSUnpack(const char *psrc, UINT inputlen, char *pdest, UINT dmax, char pac
|
|
534
569
|
signed char ch = psrc[i++];
|
535
570
|
if (ch == packcharacter)
|
536
571
|
{
|
572
|
+
if (i >= inputlen) break;
|
537
573
|
BYTE ch2 = psrc[i++];
|
538
574
|
if (ch2)
|
539
575
|
{
|
576
|
+
if (i >= inputlen) break;
|
540
577
|
ch = psrc[i++];
|
541
578
|
while (ch2--)
|
542
579
|
{
|
@@ -546,6 +583,12 @@ void AMSUnpack(const char *psrc, UINT inputlen, char *pdest, UINT dmax, char pac
|
|
546
583
|
} else p[j++] = packcharacter;
|
547
584
|
} else p[j++] = ch;
|
548
585
|
}
|
586
|
+
if (j < tmplen)
|
587
|
+
{
|
588
|
+
// Truncated or invalid; don't try to unpack this.
|
589
|
+
SDL_free(amstmp);
|
590
|
+
return;
|
591
|
+
}
|
549
592
|
}
|
550
593
|
// Bit Unpack Loop
|
551
594
|
{
|
@@ -131,6 +131,9 @@ BOOL CSoundFile_ReadDBM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
131
131
|
// Instruments
|
132
132
|
if (chunk_id == bswapLE32(DBM_ID_INST))
|
133
133
|
{
|
134
|
+
// Skip duplicate chunks.
|
135
|
+
if (_this->m_nInstruments) continue;
|
136
|
+
|
134
137
|
if (nInstruments >= MAX_INSTRUMENTS) nInstruments = MAX_INSTRUMENTS-1;
|
135
138
|
for (UINT iIns=0; iIns<nInstruments; iIns++)
|
136
139
|
{
|
@@ -140,11 +143,10 @@ BOOL CSoundFile_ReadDBM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
140
143
|
UINT nsmp;
|
141
144
|
|
142
145
|
if (chunk_pos + sizeof(DBMINSTRUMENT) > dwMemPos) break;
|
143
|
-
if ((penv = (INSTRUMENTHEADER *)
|
146
|
+
if ((penv = (INSTRUMENTHEADER *) SDL_calloc(1, sizeof (INSTRUMENTHEADER))) == NULL) break;
|
144
147
|
pih = (DBMINSTRUMENT *)(lpStream+chunk_pos);
|
145
148
|
nsmp = bswapBE16(pih->sampleno);
|
146
149
|
psmp = ((nsmp) && (nsmp < MAX_SAMPLES)) ? &_this->Ins[nsmp] : NULL;
|
147
|
-
SDL_memset(penv, 0, sizeof(INSTRUMENTHEADER));
|
148
150
|
_this->Headers[iIns+1] = penv;
|
149
151
|
penv->nFadeOut = 1024; // ???
|
150
152
|
penv->nGlobalVol = 64;
|
@@ -228,6 +230,9 @@ BOOL CSoundFile_ReadDBM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
228
230
|
DWORD pksize;
|
229
231
|
UINT nRows;
|
230
232
|
|
233
|
+
// Skip duplicate chunks.
|
234
|
+
if (_this->Patterns[iPat]) break;
|
235
|
+
|
231
236
|
if (chunk_pos + sizeof(DBMPATTERN) > dwMemPos) break;
|
232
237
|
pph = (DBMPATTERN *)(lpStream+chunk_pos);
|
233
238
|
pksize = bswapBE32(pph->packedsize);
|
@@ -238,7 +243,7 @@ BOOL CSoundFile_ReadDBM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
238
243
|
MODCOMMAND *m = CSoundFile_AllocatePattern(nRows, _this->m_nChannels);
|
239
244
|
if (m)
|
240
245
|
{
|
241
|
-
LPBYTE pkdata = (LPBYTE)
|
246
|
+
LPBYTE pkdata = (LPBYTE)pph->patterndata;
|
242
247
|
UINT row = 0;
|
243
248
|
UINT i = 0;
|
244
249
|
|
@@ -354,4 +359,3 @@ BOOL CSoundFile_ReadDBM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
354
359
|
}
|
355
360
|
return TRUE;
|
356
361
|
}
|
357
|
-
|