gosu 1.1.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/COPYING +1 -1
- 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 +33 -30
- data/include/Gosu/Audio.hpp +70 -85
- data/include/Gosu/Color.hpp +63 -107
- data/include/Gosu/Font.hpp +44 -50
- data/include/Gosu/Fwd.hpp +1 -1
- data/include/Gosu/Graphics.hpp +64 -75
- data/include/Gosu/GraphicsBase.hpp +32 -39
- data/include/Gosu/Image.hpp +56 -62
- data/include/Gosu/ImageData.hpp +23 -27
- data/include/Gosu/Inspection.hpp +1 -4
- data/include/Gosu/Math.hpp +4 -16
- data/include/Gosu/Platform.hpp +1 -51
- data/include/Gosu/Text.hpp +37 -40
- data/include/Gosu/TextInput.hpp +34 -40
- data/include/Gosu/Utility.hpp +10 -8
- data/include/Gosu/Version.hpp +1 -1
- data/include/Gosu/Window.hpp +73 -70
- data/lib/SDL2.dll +0 -0
- data/lib/gosu/compat.rb +28 -37
- data/lib/gosu/swig_patches.rb +31 -3
- data/lib/gosu.rb +2 -2
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +9 -1
- 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/Bitmap.cpp +13 -13
- data/src/BitmapIO.cpp +0 -20
- data/src/BlockAllocator.cpp +2 -1
- data/src/Channel.cpp +22 -20
- data/src/Color.cpp +62 -55
- data/src/EmptyImageData.hpp +16 -18
- data/src/FileUnix.cpp +1 -1
- data/src/FileWin.cpp +1 -1
- data/src/Font.cpp +52 -57
- data/src/GosuViewController.cpp +2 -0
- data/src/Graphics.cpp +135 -143
- data/src/Image.cpp +42 -42
- data/src/Input.cpp +1 -1
- data/src/InputUIKit.cpp +1 -1
- data/src/LargeImageData.cpp +120 -113
- data/src/LargeImageData.hpp +18 -16
- data/src/Log.hpp +6 -6
- data/src/Macro.cpp +124 -169
- data/src/Macro.hpp +11 -11
- data/src/Math.cpp +8 -1
- data/src/RenderState.hpp +5 -5
- data/src/Resolution.cpp +114 -61
- data/src/RubyGosu.cxx +470 -501
- data/src/RubyGosu.h +3 -2
- data/src/TexChunk.cpp +50 -41
- data/src/TexChunk.hpp +22 -22
- data/src/Text.cpp +58 -59
- data/src/TextBuilder.cpp +60 -57
- data/src/TextBuilder.hpp +20 -20
- data/src/TextInput.cpp +127 -135
- data/src/TrueTypeFont.cpp +108 -108
- data/src/TrueTypeFont.hpp +39 -38
- data/src/TrueTypeFontApple.cpp +27 -23
- data/src/TrueTypeFontUnix.cpp +21 -26
- data/src/TrueTypeFontWin.cpp +30 -30
- data/src/Utility.cpp +82 -23
- data/src/WinUtility.hpp +2 -1
- data/src/Window.cpp +103 -86
- data/src/WindowUIKit.cpp +48 -51
- metadata +8 -20
- 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
- data/src/UtilityApple.cpp +0 -16
- data/src/UtilityWin.cpp +0 -17
@@ -6,7 +6,6 @@
|
|
6
6
|
*/
|
7
7
|
|
8
8
|
#include "libmodplug.h"
|
9
|
-
#include "tables.h"
|
10
9
|
|
11
10
|
//////////////////////////////////////////////////////////
|
12
11
|
// ProTracker / NoiseTracker MOD/NST file support
|
@@ -34,7 +33,9 @@ void CSoundFile_ConvertModCommand(CSoundFile *_this, MODCOMMAND *m)
|
|
34
33
|
case 0x0D: command = CMD_PATTERNBREAK; param = ((param >> 4) * 10) + (param & 0x0F); break;
|
35
34
|
case 0x0E: command = CMD_MODCMDEX; break;
|
36
35
|
case 0x0F: command = (param <= (UINT)((_this->m_nType & (MOD_TYPE_XM|MOD_TYPE_MT2)) ? 0x1F : 0x20)) ? CMD_SPEED : CMD_TEMPO;
|
37
|
-
|
36
|
+
if((param == 0xFF) && (_this->m_nSamples == 15))
|
37
|
+
command = 0;
|
38
|
+
break;
|
38
39
|
// Extension for XM extended effects
|
39
40
|
case 'G' - 55: command = CMD_GLOBALVOLUME; break;
|
40
41
|
case 'H' - 55: command = CMD_GLOBALVOLSLIDE; if (param & 0xF0) param &= 0xF0; break;
|
@@ -54,9 +55,7 @@ void CSoundFile_ConvertModCommand(CSoundFile *_this, MODCOMMAND *m)
|
|
54
55
|
m->param = param;
|
55
56
|
}
|
56
57
|
|
57
|
-
|
58
58
|
#pragma pack(1)
|
59
|
-
|
60
59
|
typedef struct _MODSAMPLE
|
61
60
|
{
|
62
61
|
CHAR name[22];
|
@@ -74,19 +73,33 @@ typedef struct _MODMAGIC
|
|
74
73
|
BYTE Orders[128];
|
75
74
|
char Magic[4]; // changed from CHAR
|
76
75
|
} MODMAGIC, *PMODMAGIC;
|
77
|
-
|
78
76
|
#pragma pack()
|
79
77
|
|
78
|
+
static BOOL IsValidName(LPCSTR s, int length, CHAR minChar)
|
79
|
+
//-----------------------------------------------------------------
|
80
|
+
{
|
81
|
+
int i, nt;
|
82
|
+
for (i = 0, nt = 0; i < length; i++)
|
83
|
+
{
|
84
|
+
if(s[i])
|
85
|
+
{
|
86
|
+
if (nt) return FALSE;// garbage after null
|
87
|
+
if (s[i] < minChar) return FALSE;// caller says it's garbage
|
88
|
+
}
|
89
|
+
else if (!nt) nt = i;// found null terminator
|
90
|
+
}
|
91
|
+
return TRUE;
|
92
|
+
}
|
93
|
+
|
80
94
|
static BOOL IsMagic(LPCSTR s1, LPCSTR s2)
|
81
95
|
{
|
82
96
|
return ((*(DWORD *)s1) == (*(DWORD *)s2)) ? TRUE : FALSE;
|
83
97
|
}
|
84
98
|
|
85
|
-
|
86
99
|
BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLength)
|
87
100
|
//---------------------------------------------------------------
|
88
101
|
{
|
89
|
-
|
102
|
+
char s[1024]; // changed from CHAR
|
90
103
|
DWORD dwMemPos, dwTotalSampleLen;
|
91
104
|
PMODMAGIC pMagic;
|
92
105
|
UINT nErr;
|
@@ -101,6 +114,7 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
101
114
|
if ((IsMagic(s, "M.K.")) || (IsMagic(s, "M!K!"))
|
102
115
|
|| (IsMagic(s, "M&K!")) || (IsMagic(s, "N.T."))) _this->m_nChannels = 4; else
|
103
116
|
if ((IsMagic(s, "CD81")) || (IsMagic(s, "OKTA"))) _this->m_nChannels = 8; else
|
117
|
+
if (IsMagic(s, "CD61")) _this->m_nChannels = 6; else
|
104
118
|
if ((s[0]=='F') && (s[1]=='L') && (s[2]=='T') && (s[3]>='4') && (s[3]<='9')) _this->m_nChannels = s[3] - '0'; else
|
105
119
|
if ((s[0]>='2') && (s[0]<='9') && (s[1]=='C') && (s[2]=='H') && (s[3]=='N')) _this->m_nChannels = s[0] - '0'; else
|
106
120
|
if ((s[0]=='1') && (s[1]>='0') && (s[1]<='9') && (s[2]=='C') && (s[3]=='H')) _this->m_nChannels = s[1] - '0' + 10; else
|
@@ -108,7 +122,12 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
108
122
|
if ((s[0]=='3') && (s[1]>='0') && (s[1]<='2') && (s[2]=='C') && (s[3]=='H')) _this->m_nChannels = s[1] - '0' + 30; else
|
109
123
|
if ((s[0]=='T') && (s[1]=='D') && (s[2]=='Z') && (s[3]>='4') && (s[3]<='9')) _this->m_nChannels = s[3] - '0'; else
|
110
124
|
if (IsMagic(s,"16CN")) _this->m_nChannels = 16; else
|
111
|
-
if (IsMagic(s,"32CN")) _this->m_nChannels = 32;
|
125
|
+
if (IsMagic(s,"32CN")) _this->m_nChannels = 32;
|
126
|
+
else {
|
127
|
+
if (!IsValidName((LPCSTR)lpStream, 20, ' '))
|
128
|
+
return FALSE;
|
129
|
+
_this->m_nSamples = 15;
|
130
|
+
}
|
112
131
|
// Load Samples
|
113
132
|
nErr = 0;
|
114
133
|
dwTotalSampleLen = 0;
|
@@ -118,6 +137,14 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
118
137
|
MODINSTRUMENT *psmp = &_this->Ins[i];
|
119
138
|
UINT loopstart, looplen;
|
120
139
|
|
140
|
+
if (_this->m_nSamples == 15)
|
141
|
+
{
|
142
|
+
if (!IsValidName((LPCSTR)pms->name, 22, 14)) return FALSE;
|
143
|
+
if (pms->finetune>>4) return FALSE;
|
144
|
+
if (pms->volume > 64) return FALSE;
|
145
|
+
if (bswapBE16(pms->length) > 32768) return FALSE;
|
146
|
+
}
|
147
|
+
|
121
148
|
psmp->uFlags = 0;
|
122
149
|
psmp->nLength = bswapBE16(pms->length)*2;
|
123
150
|
dwTotalSampleLen += psmp->nLength;
|
@@ -158,7 +185,10 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
158
185
|
if ((_this->m_nSamples == 15) && (dwTotalSampleLen > dwMemLength * 4)) return FALSE;
|
159
186
|
pMagic = (PMODMAGIC)(lpStream+dwMemPos);
|
160
187
|
dwMemPos += sizeof(MODMAGIC);
|
161
|
-
if (_this->m_nSamples == 15)
|
188
|
+
if (_this->m_nSamples == 15) {
|
189
|
+
dwMemPos -= 4;
|
190
|
+
if (pMagic->nOrders > 128) return FALSE;
|
191
|
+
}
|
162
192
|
SDL_memset(_this->Order, 0,sizeof(_this->Order));
|
163
193
|
SDL_memcpy(_this->Order, pMagic->Orders, 128);
|
164
194
|
|
@@ -247,7 +277,7 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
247
277
|
LPSTR p = (LPSTR)(lpStream+dwMemPos);
|
248
278
|
UINT flags = 0;
|
249
279
|
if (dwMemPos + 5 >= dwMemLength) break;
|
250
|
-
if (!
|
280
|
+
if (!SDL_strncmp(p, "ADPCM", 5))
|
251
281
|
{
|
252
282
|
flags = 3;
|
253
283
|
p += 5;
|
@@ -260,10 +290,5 @@ BOOL CSoundFile_ReadMod(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
260
290
|
dwErrCheck++;
|
261
291
|
}
|
262
292
|
}
|
263
|
-
#ifdef MODPLUG_TRACKER
|
264
|
-
return TRUE;
|
265
|
-
#else
|
266
293
|
return (dwErrCheck) ? TRUE : FALSE;
|
267
|
-
#endif
|
268
294
|
}
|
269
|
-
|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
#include "libmodplug.h"
|
2
3
|
|
3
4
|
#pragma pack(1)
|
@@ -55,6 +56,7 @@ typedef struct _MT2AUTOMATION
|
|
55
56
|
|
56
57
|
typedef struct _MT2INSTRUMENT
|
57
58
|
{
|
59
|
+
CHAR szName[32];
|
58
60
|
DWORD dwDataLen;
|
59
61
|
WORD wSamples;
|
60
62
|
BYTE GroupsMapping[96];
|
@@ -93,6 +95,7 @@ typedef struct _MT2SYNTH
|
|
93
95
|
|
94
96
|
typedef struct _MT2SAMPLE
|
95
97
|
{
|
98
|
+
CHAR szName[32];
|
96
99
|
DWORD dwDataLen;
|
97
100
|
DWORD dwLength;
|
98
101
|
DWORD dwFrequency;
|
@@ -204,6 +207,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
204
207
|
_this->Order[iOrd] = (BYTE)((iOrd < pfh->nOrders) ? pfh->Orders[iOrd] : 0xFF);
|
205
208
|
}
|
206
209
|
dwMemPos = sizeof(MT2FILEHEADER);
|
210
|
+
if (dwMemPos+2 > dwMemLength) return TRUE;
|
207
211
|
nDrumDataLen = *(WORD *)(lpStream + dwMemPos);
|
208
212
|
dwDrumDataPos = dwMemPos + 2;
|
209
213
|
if (nDrumDataLen >= 2) pdd = (MT2DRUMSDATA *)(lpStream+dwDrumDataPos);
|
@@ -220,7 +224,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
220
224
|
DWORD dwId = *(DWORD *)(lpStream+dwMemPos);
|
221
225
|
DWORD dwLen = *(DWORD *)(lpStream+dwMemPos+4);
|
222
226
|
dwMemPos += 8;
|
223
|
-
if (
|
227
|
+
if (dwLen >= dwMemLength || dwMemPos > dwMemLength - dwLen) return TRUE;
|
224
228
|
switch(dwId)
|
225
229
|
{
|
226
230
|
// MSG
|
@@ -241,7 +245,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
241
245
|
const MT2PATTERN *pmp = (MT2PATTERN *)(lpStream+dwMemPos);
|
242
246
|
UINT wDataLen = (pmp->wDataLen + 1) & ~1;
|
243
247
|
dwMemPos += 6;
|
244
|
-
if (dwMemPos
|
248
|
+
if (dwMemPos > dwMemLength - wDataLen || wDataLen > dwMemLength) break;
|
245
249
|
UINT nLines = pmp->wLines;
|
246
250
|
if ((iPat < MAX_PATTERNS) && (nLines > 0) && (nLines <= 256))
|
247
251
|
{
|
@@ -252,7 +256,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
252
256
|
UINT len = wDataLen;
|
253
257
|
if (pfh->fulFlags & 1) // Packed Patterns
|
254
258
|
{
|
255
|
-
BYTE *p =
|
259
|
+
const BYTE *p = lpStream+dwMemPos;
|
256
260
|
UINT pos = 0, row=0, ch=0;
|
257
261
|
while (pos < len)
|
258
262
|
{
|
@@ -261,6 +265,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
261
265
|
UINT rptcount = 0;
|
262
266
|
if (infobyte == 0xff)
|
263
267
|
{
|
268
|
+
if (pos + 2 > len) break;
|
264
269
|
rptcount = p[pos++];
|
265
270
|
infobyte = p[pos++];
|
266
271
|
}
|
@@ -268,13 +273,13 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
268
273
|
{
|
269
274
|
UINT patpos = row*_this->m_nChannels+ch;
|
270
275
|
cmd.note = cmd.instr = cmd.vol = cmd.pan = cmd.fxcmd = cmd.fxparam1 = cmd.fxparam2 = 0;
|
271
|
-
if (infobyte & 1) cmd.note = p[pos++];
|
272
|
-
if (infobyte & 2) cmd.instr = p[pos++];
|
273
|
-
if (infobyte & 4) cmd.vol = p[pos++];
|
274
|
-
if (infobyte & 8) cmd.pan = p[pos++];
|
275
|
-
if (infobyte & 16) cmd.fxcmd = p[pos++];
|
276
|
-
if (infobyte & 32) cmd.fxparam1 = p[pos++];
|
277
|
-
if (infobyte & 64) cmd.fxparam2 = p[pos++];
|
276
|
+
if ((infobyte & 1) && (pos < len)) cmd.note = p[pos++];
|
277
|
+
if ((infobyte & 2) && (pos < len)) cmd.instr = p[pos++];
|
278
|
+
if ((infobyte & 4) && (pos < len)) cmd.vol = p[pos++];
|
279
|
+
if ((infobyte & 8) && (pos < len)) cmd.pan = p[pos++];
|
280
|
+
if ((infobyte & 16) && (pos < len)) cmd.fxcmd = p[pos++];
|
281
|
+
if ((infobyte & 32) && (pos < len)) cmd.fxparam1 = p[pos++];
|
282
|
+
if ((infobyte & 64) && (pos < len)) cmd.fxparam2 = p[pos++];
|
278
283
|
ConvertMT2Command(_this, &m[patpos], &cmd);
|
279
284
|
}
|
280
285
|
row += rptcount+1;
|
@@ -284,11 +289,12 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
284
289
|
} else
|
285
290
|
{
|
286
291
|
const MT2COMMAND *p = (MT2COMMAND *)(lpStream+dwMemPos);
|
292
|
+
UINT pos = 0;
|
287
293
|
UINT n = 0;
|
288
|
-
while ((
|
294
|
+
while ((pos + sizeof(MT2COMMAND) <= len) && (n < _this->m_nChannels*nLines))
|
289
295
|
{
|
290
296
|
ConvertMT2Command(_this, m, p);
|
291
|
-
|
297
|
+
pos += sizeof(MT2COMMAND);
|
292
298
|
n++;
|
293
299
|
p++;
|
294
300
|
m++;
|
@@ -338,11 +344,10 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
338
344
|
INSTRUMENTHEADER *penv = NULL;
|
339
345
|
if (iIns <= _this->m_nInstruments)
|
340
346
|
{
|
341
|
-
penv = (INSTRUMENTHEADER *)
|
347
|
+
penv = (INSTRUMENTHEADER *) SDL_calloc(1,sizeof(INSTRUMENTHEADER));
|
342
348
|
_this->Headers[iIns] = penv;
|
343
349
|
if (penv)
|
344
350
|
{
|
345
|
-
SDL_memset(penv, 0, sizeof(INSTRUMENTHEADER));
|
346
351
|
penv->nGlobalVol = 64;
|
347
352
|
penv->nPan = 128;
|
348
353
|
for (UINT i=0; i<NOTE_MAX; i++)
|
@@ -351,8 +356,10 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
351
356
|
}
|
352
357
|
}
|
353
358
|
}
|
354
|
-
if (
|
359
|
+
if (pmi->dwDataLen > dwMemLength - (dwMemPos+36)) return TRUE;
|
360
|
+
if (pmi->dwDataLen > 0)
|
355
361
|
{
|
362
|
+
if (dwMemPos + sizeof(MT2INSTRUMENT) - 4 > dwMemLength) return TRUE;
|
356
363
|
InstrMap[iIns-1] = pmi;
|
357
364
|
if (penv)
|
358
365
|
{
|
@@ -365,6 +372,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
365
372
|
if (pfh->wVersion <= 0x201)
|
366
373
|
{
|
367
374
|
DWORD dwEnvPos = dwMemPos + sizeof(MT2INSTRUMENT) - 4;
|
375
|
+
if (dwEnvPos + 2*sizeof(MT2ENVELOPE) > dwMemLength) return TRUE;
|
368
376
|
pehdr[0] = (MT2ENVELOPE *)(lpStream+dwEnvPos);
|
369
377
|
pehdr[1] = (MT2ENVELOPE *)(lpStream+dwEnvPos+8);
|
370
378
|
pehdr[2] = pehdr[3] = NULL;
|
@@ -374,10 +382,12 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
374
382
|
} else
|
375
383
|
{
|
376
384
|
DWORD dwEnvPos = dwMemPos + sizeof(MT2INSTRUMENT);
|
385
|
+
if (dwEnvPos > dwMemLength) return TRUE;
|
377
386
|
for (UINT i=0; i<4; i++)
|
378
387
|
{
|
379
388
|
if (pmi->wEnvFlags1 & (1<<i))
|
380
389
|
{
|
390
|
+
if (dwEnvPos + sizeof(MT2ENVELOPE) > dwMemLength) return TRUE;
|
381
391
|
pehdr[i] = (MT2ENVELOPE *)(lpStream+dwEnvPos);
|
382
392
|
pedata[i] = (WORD *)pehdr[i]->EnvData;
|
383
393
|
dwEnvPos += sizeof(MT2ENVELOPE);
|
@@ -459,6 +469,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
459
469
|
{
|
460
470
|
if (dwMemPos+36 > dwMemLength) return TRUE;
|
461
471
|
const MT2SAMPLE *pms = (MT2SAMPLE *)(lpStream+dwMemPos);
|
472
|
+
if (pms->dwDataLen > dwMemLength - (dwMemPos+36)) return TRUE;
|
462
473
|
if (pms->dwDataLen > 0)
|
463
474
|
{
|
464
475
|
SampleMap[iSmp-1] = pms;
|
@@ -466,6 +477,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
466
477
|
{
|
467
478
|
MODINSTRUMENT *psmp = &_this->Ins[iSmp];
|
468
479
|
psmp->nGlobalVol = 64;
|
480
|
+
if (dwMemPos+sizeof(MT2SAMPLE) > dwMemLength) return TRUE;
|
469
481
|
psmp->nVolume = (pms->wVolume >> 7);
|
470
482
|
psmp->nPan = (pms->nPan == 0x80) ? 128 : (pms->nPan^0x80);
|
471
483
|
psmp->nLength = pms->dwLength;
|
@@ -488,12 +500,12 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
488
500
|
}
|
489
501
|
for (UINT iMap=0; iMap<255; iMap++) if (InstrMap[iMap])
|
490
502
|
{
|
491
|
-
if (dwMemPos+8 > dwMemLength) return TRUE;
|
492
503
|
const MT2INSTRUMENT *pmi = InstrMap[iMap];
|
493
504
|
INSTRUMENTHEADER *penv = NULL;
|
494
505
|
if (iMap<_this->m_nInstruments) penv = _this->Headers[iMap+1];
|
495
506
|
for (UINT iGrp=0; iGrp<pmi->wSamples; iGrp++)
|
496
507
|
{
|
508
|
+
if (dwMemPos+8 > dwMemLength) return TRUE;
|
497
509
|
if (penv)
|
498
510
|
{
|
499
511
|
const MT2GROUP *pmg = (MT2GROUP *)(lpStream+dwMemPos);
|
@@ -522,7 +534,7 @@ BOOL CSoundFile_ReadMT2(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
|
|
522
534
|
MODINSTRUMENT *psmp = &_this->Ins[iData+1];
|
523
535
|
if (!(pms->nFlags & 5))
|
524
536
|
{
|
525
|
-
if (psmp->nLength > 0)
|
537
|
+
if (psmp->nLength > 0 && dwMemPos < dwMemLength)
|
526
538
|
{
|
527
539
|
UINT rsflags;
|
528
540
|
|
@@ -40,7 +40,7 @@ BOOL CSoundFile_ReadOKT(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
40
40
|
{
|
41
41
|
const OKTFILEHEADER *pfh = (OKTFILEHEADER *)lpStream;
|
42
42
|
DWORD dwMemPos = sizeof(OKTFILEHEADER);
|
43
|
-
UINT nsamples = 0,
|
43
|
+
UINT nsamples = 0, norders = 0;//, npatterns = 0
|
44
44
|
|
45
45
|
if ((!lpStream) || (dwMemLength < 1024)) return FALSE;
|
46
46
|
if ((pfh->okta != 0x41544B4F) || (pfh->song != 0x474E4F53)
|
@@ -56,11 +56,12 @@ BOOL CSoundFile_ReadOKT(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
56
56
|
// Reading samples
|
57
57
|
for (UINT smp=1; smp <= nsamples; smp++)
|
58
58
|
{
|
59
|
-
if (dwMemPos >= dwMemLength) return TRUE;
|
59
|
+
if (dwMemPos + sizeof(OKTSAMPLE) >= dwMemLength) return TRUE;
|
60
60
|
if (smp < MAX_SAMPLES)
|
61
61
|
{
|
62
62
|
OKTSAMPLE *psmp = (OKTSAMPLE *)(lpStream + dwMemPos);
|
63
63
|
MODINSTRUMENT *pins = &_this->Ins[smp];
|
64
|
+
|
64
65
|
pins->uFlags = 0;
|
65
66
|
pins->nLength = bswapBE32(psmp->length) & ~1;
|
66
67
|
pins->nLoopStart = bswapBE16(psmp->loopstart);
|
@@ -73,33 +74,36 @@ BOOL CSoundFile_ReadOKT(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
|
|
73
74
|
dwMemPos += sizeof(OKTSAMPLE);
|
74
75
|
}
|
75
76
|
// SPEE
|
76
|
-
if (dwMemPos
|
77
|
+
if (dwMemPos + 10 > dwMemLength) return TRUE;
|
77
78
|
if (*((DWORD *)(lpStream + dwMemPos)) == 0x45455053)
|
78
79
|
{
|
79
80
|
_this->m_nDefaultSpeed = lpStream[dwMemPos+9];
|
80
81
|
dwMemPos += bswapBE32(*((DWORD *)(lpStream + dwMemPos + 4))) + 8;
|
81
82
|
}
|
82
83
|
// SLEN
|
83
|
-
if (dwMemPos
|
84
|
+
if (dwMemPos + 10 > dwMemLength) return TRUE;
|
84
85
|
if (*((DWORD *)(lpStream + dwMemPos)) == 0x4E454C53)
|
85
86
|
{
|
86
|
-
|
87
|
+
if (dwMemPos + 10 > dwMemLength) return TRUE;
|
88
|
+
// npatterns = lpStream[dwMemPos+9];
|
87
89
|
dwMemPos += bswapBE32(*((DWORD *)(lpStream + dwMemPos + 4))) + 8;
|
88
90
|
}
|
89
91
|
// PLEN
|
90
|
-
if (dwMemPos
|
92
|
+
if (dwMemPos + 10 > dwMemLength) return TRUE;
|
91
93
|
if (*((DWORD *)(lpStream + dwMemPos)) == 0x4E454C50)
|
92
94
|
{
|
95
|
+
if (dwMemPos + 10 > dwMemLength) return TRUE;
|
93
96
|
norders = lpStream[dwMemPos+9];
|
94
97
|
dwMemPos += bswapBE32(*((DWORD *)(lpStream + dwMemPos + 4))) + 8;
|
95
98
|
}
|
96
99
|
// PATT
|
97
|
-
if (dwMemPos
|
100
|
+
if (dwMemPos + 8 > dwMemLength) return TRUE;
|
98
101
|
if (*((DWORD *)(lpStream + dwMemPos)) == 0x54544150)
|
99
102
|
{
|
100
103
|
UINT orderlen = norders;
|
101
104
|
if (orderlen >= MAX_ORDERS) orderlen = MAX_ORDERS-1;
|
102
|
-
|
105
|
+
if (dwMemPos + 8 + orderlen > dwMemLength) return TRUE;
|
106
|
+
for (UINT i=0; i<orderlen; i++) _this->Order[i] = lpStream[dwMemPos+8+i];
|
103
107
|
for (UINT j=orderlen; j>1; j--) { if (_this->Order[j-1]) break; _this->Order[j-1] = 0xFF; }
|
104
108
|
dwMemPos += bswapBE32(*((DWORD *)(lpStream + dwMemPos + 4))) + 8;
|
105
109
|
}
|