gosu 0.15.1 → 1.1.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/COPYING +1 -1
- data/dependencies/SDL/include/SDL.h +138 -0
- data/dependencies/SDL/include/SDL_assert.h +293 -0
- data/dependencies/SDL/include/SDL_atomic.h +295 -0
- data/dependencies/SDL/include/SDL_audio.h +859 -0
- data/dependencies/SDL/include/SDL_bits.h +121 -0
- data/dependencies/SDL/include/SDL_blendmode.h +123 -0
- data/dependencies/SDL/include/SDL_clipboard.h +71 -0
- data/dependencies/SDL/include/SDL_config.h +55 -0
- data/dependencies/SDL/include/SDL_config_android.h +182 -0
- data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
- data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
- data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
- data/dependencies/SDL/include/SDL_config_os2.h +188 -0
- data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
- data/dependencies/SDL/include/SDL_config_psp.h +165 -0
- data/dependencies/SDL/include/SDL_config_windows.h +288 -0
- data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
- data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
- data/dependencies/SDL/include/SDL_copying.h +20 -0
- data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
- data/dependencies/SDL/include/SDL_egl.h +1676 -0
- data/dependencies/SDL/include/SDL_endian.h +263 -0
- data/dependencies/SDL/include/SDL_error.h +112 -0
- data/dependencies/SDL/include/SDL_events.h +827 -0
- data/dependencies/SDL/include/SDL_filesystem.h +136 -0
- data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
- data/dependencies/SDL/include/SDL_gesture.h +87 -0
- data/dependencies/SDL/include/SDL_haptic.h +1247 -0
- data/dependencies/SDL/include/SDL_hints.h +1578 -0
- data/dependencies/SDL/include/SDL_joystick.h +499 -0
- data/dependencies/SDL/include/SDL_keyboard.h +217 -0
- data/dependencies/SDL/include/SDL_keycode.h +351 -0
- data/dependencies/SDL/include/SDL_loadso.h +81 -0
- data/dependencies/SDL/include/SDL_locale.h +101 -0
- data/dependencies/SDL/include/SDL_log.h +211 -0
- data/dependencies/SDL/include/SDL_main.h +180 -0
- data/dependencies/SDL/include/SDL_messagebox.h +146 -0
- data/dependencies/SDL/include/SDL_metal.h +117 -0
- data/dependencies/SDL/include/SDL_misc.h +75 -0
- data/dependencies/SDL/include/SDL_mouse.h +302 -0
- data/dependencies/SDL/include/SDL_mutex.h +251 -0
- data/dependencies/SDL/include/SDL_name.h +33 -0
- data/dependencies/SDL/include/SDL_opengl.h +2183 -0
- data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
- data/dependencies/SDL/include/SDL_opengles.h +39 -0
- data/dependencies/SDL/include/SDL_opengles2.h +52 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
- data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
- data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
- data/dependencies/SDL/include/SDL_pixels.h +479 -0
- data/dependencies/SDL/include/SDL_platform.h +198 -0
- data/dependencies/SDL/include/SDL_power.h +75 -0
- data/dependencies/SDL/include/SDL_quit.h +58 -0
- data/dependencies/SDL/include/SDL_rect.h +174 -0
- data/dependencies/SDL/include/SDL_render.h +1158 -0
- data/dependencies/SDL/include/SDL_revision.h +2 -0
- data/dependencies/SDL/include/SDL_rwops.h +283 -0
- data/dependencies/SDL/include/SDL_scancode.h +413 -0
- data/dependencies/SDL/include/SDL_sensor.h +267 -0
- data/dependencies/SDL/include/SDL_shape.h +144 -0
- data/dependencies/SDL/include/SDL_stdinc.h +647 -0
- data/dependencies/SDL/include/SDL_surface.h +563 -0
- data/dependencies/SDL/include/SDL_system.h +325 -0
- data/dependencies/SDL/include/SDL_syswm.h +354 -0
- data/dependencies/SDL/include/SDL_test.h +69 -0
- data/dependencies/SDL/include/SDL_test_assert.h +105 -0
- data/dependencies/SDL/include/SDL_test_common.h +218 -0
- data/dependencies/SDL/include/SDL_test_compare.h +69 -0
- data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
- data/dependencies/SDL/include/SDL_test_font.h +81 -0
- data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
- data/dependencies/SDL/include/SDL_test_harness.h +134 -0
- data/dependencies/SDL/include/SDL_test_images.h +78 -0
- data/dependencies/SDL/include/SDL_test_log.h +67 -0
- data/dependencies/SDL/include/SDL_test_md5.h +129 -0
- data/dependencies/SDL/include/SDL_test_memory.h +63 -0
- data/dependencies/SDL/include/SDL_test_random.h +115 -0
- data/dependencies/SDL/include/SDL_thread.h +366 -0
- data/dependencies/SDL/include/SDL_timer.h +115 -0
- data/dependencies/SDL/include/SDL_touch.h +102 -0
- data/dependencies/SDL/include/SDL_types.h +29 -0
- data/dependencies/SDL/include/SDL_version.h +162 -0
- data/dependencies/SDL/include/SDL_video.h +1282 -0
- data/dependencies/SDL/include/SDL_vulkan.h +276 -0
- data/dependencies/SDL/include/begin_code.h +166 -0
- data/dependencies/SDL/include/close_code.h +40 -0
- 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 +795 -0
- data/dependencies/SDL_sound/SDL_sound.h +725 -0
- data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
- data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
- data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
- data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
- data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
- data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
- data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
- data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
- data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
- data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
- data/dependencies/SDL_sound/dr_flac.h +5906 -0
- data/dependencies/SDL_sound/dr_mp3.h +2832 -0
- data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
- data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
- data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
- data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
- data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
- data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
- data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
- data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
- data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
- data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
- data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
- data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
- data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
- data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
- data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
- data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
- data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
- data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
- data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
- data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
- data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
- data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
- data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
- data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
- data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
- data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
- data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
- data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
- data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
- data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
- data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
- data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +143 -78
- data/dependencies/al_soft/AL/al.h +655 -0
- data/dependencies/al_soft/AL/alc.h +270 -0
- data/dependencies/al_soft/AL/alext.h +585 -0
- data/dependencies/al_soft/AL/efx-creative.h +3 -0
- data/dependencies/al_soft/AL/efx-presets.h +402 -0
- data/dependencies/al_soft/AL/efx.h +762 -0
- data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
- data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
- data/{src → dependencies/stb}/stb_image.h +330 -127
- data/{src → dependencies/stb}/stb_image_write.h +156 -85
- data/{src → dependencies/stb}/stb_truetype.h +192 -69
- data/{src → dependencies/utf8proc}/utf8proc.c +0 -0
- data/{src → dependencies/utf8proc}/utf8proc.h +0 -0
- data/{src → dependencies/utf8proc}/utf8proc_data.h +0 -0
- data/ext/gosu/extconf.rb +53 -39
- data/{Gosu → include/Gosu}/Audio.hpp +6 -8
- data/include/Gosu/Bitmap.hpp +100 -0
- data/{Gosu → include/Gosu}/Buttons.hpp +104 -44
- data/{Gosu → include/Gosu}/Color.hpp +0 -0
- data/{Gosu → include/Gosu}/Directories.hpp +0 -0
- data/{Gosu → include/Gosu}/Font.hpp +1 -1
- data/{Gosu → include/Gosu}/Fwd.hpp +0 -5
- data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
- data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
- data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
- data/{Gosu → include/Gosu}/IO.hpp +0 -0
- data/{Gosu → include/Gosu}/Image.hpp +7 -6
- data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
- data/{Gosu → include/Gosu}/Input.hpp +39 -51
- data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
- data/{Gosu → include/Gosu}/Math.hpp +0 -0
- data/{Gosu → include/Gosu}/Platform.hpp +0 -0
- data/{Gosu → include/Gosu}/Text.hpp +0 -0
- data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
- data/{Gosu → include/Gosu}/Timing.hpp +0 -0
- data/{Gosu → include/Gosu}/Utility.hpp +15 -4
- data/{Gosu → include/Gosu}/Version.hpp +3 -3
- data/{Gosu → include/Gosu}/Window.hpp +46 -34
- data/lib/OpenAL32.dll +0 -0
- data/lib/SDL2.dll +0 -0
- data/lib/gosu.rb +0 -3
- data/lib/gosu/patches.rb +0 -23
- data/lib/gosu/preview.rb +1 -3
- data/lib/gosu/swig_patches.rb +6 -8
- data/lib64/OpenAL32.dll +0 -0
- data/lib64/SDL2.dll +0 -0
- data/rdoc/gosu.rb +112 -23
- data/src/Audio.cpp +50 -224
- data/src/AudioFile.hpp +20 -37
- data/src/AudioFileAudioToolbox.cpp +237 -0
- data/src/AudioFileSDLSound.cpp +147 -0
- data/src/AudioImpl.cpp +3 -12
- data/src/AudioImpl.hpp +3 -1
- data/src/Bitmap.cpp +85 -83
- data/src/BitmapIO.cpp +52 -58
- data/src/Font.cpp +4 -1
- data/src/Graphics.cpp +7 -4
- data/src/Image.cpp +13 -16
- data/src/Input.cpp +412 -164
- data/src/LargeImageData.cpp +2 -1
- data/src/MarkupParser.cpp +2 -1
- data/src/Resolution.cpp +8 -8
- data/src/RubyGosu.cxx +1184 -352
- data/src/RubyGosu.h +3 -2
- data/src/TexChunk.cpp +1 -1
- data/src/Text.cpp +1 -0
- data/src/TextBuilder.cpp +3 -1
- data/src/Texture.cpp +1 -1
- data/src/TrueTypeFont.cpp +2 -1
- data/src/TrueTypeFontWin.cpp +3 -3
- data/src/Utility.cpp +11 -7
- data/src/Window.cpp +90 -62
- data/src/WindowUIKit.cpp +21 -9
- metadata +195 -46
- data/Gosu/AutoLink.hpp +0 -14
- data/Gosu/Bitmap.hpp +0 -113
- data/lib/gosu/zen.rb +0 -89
- data/src/AudioToolboxFile.hpp +0 -210
- data/src/MPEGFile.hpp +0 -90
- data/src/OggFile.hpp +0 -92
- data/src/SndFile.hpp +0 -174
- data/src/WinMain.cpp +0 -64
@@ -0,0 +1,382 @@
|
|
1
|
+
/*
|
2
|
+
* This source code is public domain.
|
3
|
+
*
|
4
|
+
* Handles unpacking of Powerpack PP20
|
5
|
+
* Authors: Olivier Lapicque <olivierl@jps.net>
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include "libmodplug.h"
|
9
|
+
|
10
|
+
BOOL PP20_Unpack(LPCBYTE *ppMemFile, LPDWORD pdwMemLength);
|
11
|
+
|
12
|
+
typedef struct MMCMPFILEHEADER
|
13
|
+
{
|
14
|
+
DWORD id_ziRC; // "ziRC"
|
15
|
+
DWORD id_ONia; // "ONia"
|
16
|
+
WORD hdrsize;
|
17
|
+
} MMCMPFILEHEADER, *LPMMCMPFILEHEADER;
|
18
|
+
|
19
|
+
typedef struct MMCMPHEADER
|
20
|
+
{
|
21
|
+
WORD version;
|
22
|
+
WORD nblocks;
|
23
|
+
DWORD filesize;
|
24
|
+
DWORD blktable;
|
25
|
+
BYTE glb_comp;
|
26
|
+
BYTE fmt_comp;
|
27
|
+
} MMCMPHEADER, *LPMMCMPHEADER;
|
28
|
+
|
29
|
+
typedef struct MMCMPBLOCK
|
30
|
+
{
|
31
|
+
DWORD unpk_size;
|
32
|
+
DWORD pk_size;
|
33
|
+
DWORD xor_chk;
|
34
|
+
WORD sub_blk;
|
35
|
+
WORD flags;
|
36
|
+
WORD tt_entries;
|
37
|
+
USHORT num_bits;
|
38
|
+
} MMCMPBLOCK, *LPMMCMPBLOCK;
|
39
|
+
|
40
|
+
typedef struct MMCMPSUBBLOCK
|
41
|
+
{
|
42
|
+
DWORD unpk_pos;
|
43
|
+
DWORD unpk_size;
|
44
|
+
} MMCMPSUBBLOCK, *LPMMCMPSUBBLOCK;
|
45
|
+
|
46
|
+
#define MMCMP_COMP 0x0001
|
47
|
+
#define MMCMP_DELTA 0x0002
|
48
|
+
#define MMCMP_16BIT 0x0004
|
49
|
+
#define MMCMP_STEREO 0x0100
|
50
|
+
#define MMCMP_ABS16 0x0200
|
51
|
+
#define MMCMP_ENDIAN 0x0400
|
52
|
+
|
53
|
+
typedef struct MMCMPBITBUFFER
|
54
|
+
{
|
55
|
+
UINT bitcount;
|
56
|
+
DWORD bitbuffer;
|
57
|
+
LPCBYTE pSrc;
|
58
|
+
LPCBYTE pEnd;
|
59
|
+
} MMCMPBITBUFFER;
|
60
|
+
|
61
|
+
|
62
|
+
static DWORD MMCMPBITBUFFER_GetBits(MMCMPBITBUFFER *_this, UINT nBits)
|
63
|
+
//---------------------------------------
|
64
|
+
{
|
65
|
+
DWORD d;
|
66
|
+
if (!nBits) return 0;
|
67
|
+
while (_this->bitcount < 24)
|
68
|
+
{
|
69
|
+
_this->bitbuffer |= ((_this->pSrc < _this->pEnd) ? *_this->pSrc++ : 0) << _this->bitcount;
|
70
|
+
_this->bitcount += 8;
|
71
|
+
}
|
72
|
+
d = _this->bitbuffer & ((1 << nBits) - 1);
|
73
|
+
_this->bitbuffer >>= nBits;
|
74
|
+
_this->bitcount -= nBits;
|
75
|
+
return d;
|
76
|
+
}
|
77
|
+
|
78
|
+
const DWORD MMCMP8BitCommands[8] =
|
79
|
+
{
|
80
|
+
0x01, 0x03, 0x07, 0x0F, 0x1E, 0x3C, 0x78, 0xF8
|
81
|
+
};
|
82
|
+
|
83
|
+
const UINT MMCMP8BitFetch[8] =
|
84
|
+
{
|
85
|
+
3, 3, 3, 3, 2, 1, 0, 0
|
86
|
+
};
|
87
|
+
|
88
|
+
const DWORD MMCMP16BitCommands[16] =
|
89
|
+
{
|
90
|
+
0x01, 0x03, 0x07, 0x0F, 0x1E, 0x3C, 0x78, 0xF0,
|
91
|
+
0x1F0, 0x3F0, 0x7F0, 0xFF0, 0x1FF0, 0x3FF0, 0x7FF0, 0xFFF0
|
92
|
+
};
|
93
|
+
|
94
|
+
const UINT MMCMP16BitFetch[16] =
|
95
|
+
{
|
96
|
+
4, 4, 4, 4, 3, 2, 1, 0,
|
97
|
+
0, 0, 0, 0, 0, 0, 0, 0
|
98
|
+
};
|
99
|
+
|
100
|
+
|
101
|
+
BOOL MMCMP_Unpack(LPCBYTE *ppMemFile, LPDWORD pdwMemLength)
|
102
|
+
//---------------------------------------------------------
|
103
|
+
{
|
104
|
+
DWORD dwMemLength = *pdwMemLength;
|
105
|
+
LPCBYTE lpMemFile = *ppMemFile;
|
106
|
+
LPBYTE pBuffer;
|
107
|
+
LPMMCMPFILEHEADER pmfh = (LPMMCMPFILEHEADER)(lpMemFile);
|
108
|
+
LPMMCMPHEADER pmmh = (LPMMCMPHEADER)(lpMemFile+10);
|
109
|
+
LPDWORD pblk_table;
|
110
|
+
DWORD dwFileSize;
|
111
|
+
|
112
|
+
if (PP20_Unpack(ppMemFile, pdwMemLength))
|
113
|
+
{
|
114
|
+
return TRUE;
|
115
|
+
}
|
116
|
+
if ((dwMemLength < 256) || (!pmfh) || (pmfh->id_ziRC != 0x4352697A) || (pmfh->id_ONia != 0x61694e4f) || (pmfh->hdrsize < 14)
|
117
|
+
|| (!pmmh->nblocks) || (pmmh->filesize < 16) || (pmmh->filesize > 0x8000000)
|
118
|
+
|| (pmmh->blktable >= dwMemLength) || (pmmh->blktable + 4*pmmh->nblocks > dwMemLength)) return FALSE;
|
119
|
+
dwFileSize = pmmh->filesize;
|
120
|
+
if ((pBuffer = (LPBYTE)GlobalAllocPtr(GHND, (dwFileSize + 31) & ~15)) == NULL) return FALSE;
|
121
|
+
pblk_table = (LPDWORD)(lpMemFile+pmmh->blktable);
|
122
|
+
for (UINT nBlock=0; nBlock<pmmh->nblocks; nBlock++)
|
123
|
+
{
|
124
|
+
DWORD dwMemPos = pblk_table[nBlock];
|
125
|
+
LPMMCMPBLOCK pblk = (LPMMCMPBLOCK)(lpMemFile+dwMemPos);
|
126
|
+
LPMMCMPSUBBLOCK psubblk = (LPMMCMPSUBBLOCK)(lpMemFile+dwMemPos+20);
|
127
|
+
|
128
|
+
if ((dwMemPos + 20 >= dwMemLength) || (dwMemPos + 20 + pblk->sub_blk*8 >= dwMemLength)) break;
|
129
|
+
dwMemPos += 20 + pblk->sub_blk*8;
|
130
|
+
// Data is not packed
|
131
|
+
if (!(pblk->flags & MMCMP_COMP))
|
132
|
+
{
|
133
|
+
for (UINT i=0; i<pblk->sub_blk; i++)
|
134
|
+
{
|
135
|
+
if ((psubblk->unpk_pos >= dwFileSize) ||
|
136
|
+
(psubblk->unpk_size >= dwFileSize) ||
|
137
|
+
(psubblk->unpk_size > dwFileSize - psubblk->unpk_pos)) break;
|
138
|
+
SDL_memcpy(pBuffer+psubblk->unpk_pos, lpMemFile+dwMemPos, psubblk->unpk_size);
|
139
|
+
dwMemPos += psubblk->unpk_size;
|
140
|
+
psubblk++;
|
141
|
+
}
|
142
|
+
} else
|
143
|
+
// Data is 16-bit packed
|
144
|
+
if (pblk->flags & MMCMP_16BIT && pblk->num_bits < 16)
|
145
|
+
{
|
146
|
+
MMCMPBITBUFFER bb;
|
147
|
+
LPWORD pDest = (LPWORD)(pBuffer + psubblk->unpk_pos);
|
148
|
+
DWORD dwSize = psubblk->unpk_size >> 1;
|
149
|
+
DWORD dwPos = 0;
|
150
|
+
UINT numbits = pblk->num_bits;
|
151
|
+
UINT subblk = 0, oldval = 0;
|
152
|
+
bb.bitcount = 0;
|
153
|
+
bb.bitbuffer = 0;
|
154
|
+
bb.pSrc = lpMemFile+dwMemPos+pblk->tt_entries;
|
155
|
+
bb.pEnd = lpMemFile+dwMemPos+pblk->pk_size;
|
156
|
+
while (subblk < pblk->sub_blk)
|
157
|
+
{
|
158
|
+
UINT newval = 0x10000;
|
159
|
+
DWORD d = MMCMPBITBUFFER_GetBits(&bb, numbits+1);
|
160
|
+
|
161
|
+
if (d >= MMCMP16BitCommands[numbits])
|
162
|
+
{
|
163
|
+
UINT nFetch = MMCMP16BitFetch[numbits];
|
164
|
+
UINT newbits = MMCMPBITBUFFER_GetBits(&bb, nFetch) + ((d - MMCMP16BitCommands[numbits]) << nFetch);
|
165
|
+
if (newbits != numbits)
|
166
|
+
{
|
167
|
+
numbits = newbits & 0x0F;
|
168
|
+
} else
|
169
|
+
{
|
170
|
+
if ((d = MMCMPBITBUFFER_GetBits(&bb, 4)) == 0x0F)
|
171
|
+
{
|
172
|
+
if (MMCMPBITBUFFER_GetBits(&bb, 1)) break;
|
173
|
+
newval = 0xFFFF;
|
174
|
+
} else
|
175
|
+
{
|
176
|
+
newval = 0xFFF0 + d;
|
177
|
+
}
|
178
|
+
}
|
179
|
+
} else
|
180
|
+
{
|
181
|
+
newval = d;
|
182
|
+
}
|
183
|
+
if (newval < 0x10000)
|
184
|
+
{
|
185
|
+
newval = (newval & 1) ? (UINT)(-(LONG)((newval+1) >> 1)) : (UINT)(newval >> 1);
|
186
|
+
if (pblk->flags & MMCMP_DELTA)
|
187
|
+
{
|
188
|
+
newval += oldval;
|
189
|
+
oldval = newval;
|
190
|
+
} else
|
191
|
+
if (!(pblk->flags & MMCMP_ABS16))
|
192
|
+
{
|
193
|
+
newval ^= 0x8000;
|
194
|
+
}
|
195
|
+
pDest[dwPos++] = (WORD)newval;
|
196
|
+
}
|
197
|
+
if (dwPos >= dwSize)
|
198
|
+
{
|
199
|
+
subblk++;
|
200
|
+
dwPos = 0;
|
201
|
+
dwSize = psubblk[subblk].unpk_size >> 1;
|
202
|
+
pDest = (LPWORD)(pBuffer + psubblk[subblk].unpk_pos);
|
203
|
+
}
|
204
|
+
}
|
205
|
+
} else if (pblk->num_bits < 8)
|
206
|
+
// Data is 8-bit packed
|
207
|
+
{
|
208
|
+
MMCMPBITBUFFER bb;
|
209
|
+
LPBYTE pDest = pBuffer + psubblk->unpk_pos;
|
210
|
+
DWORD dwSize = psubblk->unpk_size;
|
211
|
+
DWORD dwPos = 0;
|
212
|
+
UINT numbits = pblk->num_bits;
|
213
|
+
UINT subblk = 0, oldval = 0;
|
214
|
+
LPCBYTE ptable = lpMemFile+dwMemPos;
|
215
|
+
|
216
|
+
bb.bitcount = 0;
|
217
|
+
bb.bitbuffer = 0;
|
218
|
+
bb.pSrc = lpMemFile+dwMemPos+pblk->tt_entries;
|
219
|
+
bb.pEnd = lpMemFile+dwMemPos+pblk->pk_size;
|
220
|
+
while (subblk < pblk->sub_blk)
|
221
|
+
{
|
222
|
+
UINT newval = 0x100;
|
223
|
+
DWORD d = MMCMPBITBUFFER_GetBits(&bb, numbits+1);
|
224
|
+
|
225
|
+
if (d >= MMCMP8BitCommands[numbits])
|
226
|
+
{
|
227
|
+
UINT nFetch = MMCMP8BitFetch[numbits];
|
228
|
+
UINT newbits = MMCMPBITBUFFER_GetBits(&bb, nFetch) + ((d - MMCMP8BitCommands[numbits]) << nFetch);
|
229
|
+
if (newbits != numbits)
|
230
|
+
{
|
231
|
+
numbits = newbits & 0x07;
|
232
|
+
} else
|
233
|
+
{
|
234
|
+
if ((d = MMCMPBITBUFFER_GetBits(&bb, 3)) == 7)
|
235
|
+
{
|
236
|
+
if (MMCMPBITBUFFER_GetBits(&bb, 1)) break;
|
237
|
+
newval = 0xFF;
|
238
|
+
} else
|
239
|
+
{
|
240
|
+
newval = 0xF8 + d;
|
241
|
+
}
|
242
|
+
}
|
243
|
+
} else
|
244
|
+
{
|
245
|
+
newval = d;
|
246
|
+
}
|
247
|
+
if (newval < 0x100)
|
248
|
+
{
|
249
|
+
int n = ptable[newval];
|
250
|
+
if (pblk->flags & MMCMP_DELTA)
|
251
|
+
{
|
252
|
+
n += oldval;
|
253
|
+
oldval = n;
|
254
|
+
}
|
255
|
+
pDest[dwPos++] = (BYTE)n;
|
256
|
+
}
|
257
|
+
if (dwPos >= dwSize)
|
258
|
+
{
|
259
|
+
subblk++;
|
260
|
+
dwPos = 0;
|
261
|
+
dwSize = psubblk[subblk].unpk_size;
|
262
|
+
pDest = pBuffer + psubblk[subblk].unpk_pos;
|
263
|
+
}
|
264
|
+
}
|
265
|
+
} else
|
266
|
+
{
|
267
|
+
return FALSE;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
*ppMemFile = pBuffer;
|
271
|
+
*pdwMemLength = dwFileSize;
|
272
|
+
return TRUE;
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
//////////////////////////////////////////////////////////////////////////////
|
277
|
+
//
|
278
|
+
// PowerPack PP20 Unpacker
|
279
|
+
//
|
280
|
+
|
281
|
+
typedef struct _PPBITBUFFER
|
282
|
+
{
|
283
|
+
UINT bitcount;
|
284
|
+
ULONG bitbuffer;
|
285
|
+
LPCBYTE pStart;
|
286
|
+
LPCBYTE pSrc;
|
287
|
+
} PPBITBUFFER;
|
288
|
+
|
289
|
+
|
290
|
+
static ULONG PPBITBUFFER_GetBits(PPBITBUFFER *_this, UINT n)
|
291
|
+
{
|
292
|
+
ULONG result = 0;
|
293
|
+
|
294
|
+
for (UINT i=0; i<n; i++)
|
295
|
+
{
|
296
|
+
if (!_this->bitcount)
|
297
|
+
{
|
298
|
+
_this->bitcount = 8;
|
299
|
+
if (_this->pSrc != _this->pStart) _this->pSrc--;
|
300
|
+
_this->bitbuffer = *_this->pSrc;
|
301
|
+
}
|
302
|
+
result = (result<<1) | (_this->bitbuffer&1);
|
303
|
+
_this->bitbuffer >>= 1;
|
304
|
+
_this->bitcount--;
|
305
|
+
}
|
306
|
+
return result;
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
VOID PP20_DoUnpack(const BYTE *pSrc, UINT nSrcLen, BYTE *pDst, UINT nDstLen)
|
311
|
+
{
|
312
|
+
PPBITBUFFER BitBuffer;
|
313
|
+
ULONG nBytesLeft;
|
314
|
+
|
315
|
+
BitBuffer.pStart = pSrc;
|
316
|
+
BitBuffer.pSrc = pSrc + nSrcLen - 4;
|
317
|
+
BitBuffer.bitbuffer = 0;
|
318
|
+
BitBuffer.bitcount = 0;
|
319
|
+
PPBITBUFFER_GetBits(&BitBuffer, pSrc[nSrcLen-1]);
|
320
|
+
nBytesLeft = nDstLen;
|
321
|
+
while (nBytesLeft > 0)
|
322
|
+
{
|
323
|
+
if (!PPBITBUFFER_GetBits(&BitBuffer, 1))
|
324
|
+
{
|
325
|
+
UINT n = 1;
|
326
|
+
while (n < nBytesLeft)
|
327
|
+
{
|
328
|
+
UINT code = PPBITBUFFER_GetBits(&BitBuffer, 2);
|
329
|
+
n += code;
|
330
|
+
if (code != 3) break;
|
331
|
+
}
|
332
|
+
for (UINT i=0; i<n; i++)
|
333
|
+
{
|
334
|
+
pDst[--nBytesLeft] = (BYTE)PPBITBUFFER_GetBits(&BitBuffer, 8);
|
335
|
+
}
|
336
|
+
if (!nBytesLeft) break;
|
337
|
+
}
|
338
|
+
{
|
339
|
+
UINT n = PPBITBUFFER_GetBits(&BitBuffer, 2)+1;
|
340
|
+
UINT nbits = pSrc[n-1];
|
341
|
+
UINT nofs;
|
342
|
+
if (n==4)
|
343
|
+
{
|
344
|
+
nofs = PPBITBUFFER_GetBits(&BitBuffer, (PPBITBUFFER_GetBits(&BitBuffer, 1)) ? nbits : 7 );
|
345
|
+
while (n < nBytesLeft)
|
346
|
+
{
|
347
|
+
UINT code = PPBITBUFFER_GetBits(&BitBuffer, 3);
|
348
|
+
n += code;
|
349
|
+
if (code != 7) break;
|
350
|
+
}
|
351
|
+
} else
|
352
|
+
{
|
353
|
+
nofs = PPBITBUFFER_GetBits(&BitBuffer, nbits);
|
354
|
+
}
|
355
|
+
for (UINT i=0; i<=n; i++)
|
356
|
+
{
|
357
|
+
pDst[nBytesLeft-1] = (nBytesLeft+nofs < nDstLen) ? pDst[nBytesLeft+nofs] : 0;
|
358
|
+
if (!--nBytesLeft) break;
|
359
|
+
}
|
360
|
+
}
|
361
|
+
}
|
362
|
+
}
|
363
|
+
|
364
|
+
|
365
|
+
BOOL PP20_Unpack(LPCBYTE *ppMemFile, LPDWORD pdwMemLength)
|
366
|
+
{
|
367
|
+
DWORD dwMemLength = *pdwMemLength;
|
368
|
+
LPCBYTE lpMemFile = *ppMemFile;
|
369
|
+
DWORD dwDstLen;
|
370
|
+
LPBYTE pBuffer;
|
371
|
+
|
372
|
+
if ((!lpMemFile) || (dwMemLength < 256) || (*(DWORD *)lpMemFile != 0x30325050)) return FALSE;
|
373
|
+
dwDstLen = (lpMemFile[dwMemLength-4]<<16) | (lpMemFile[dwMemLength-3]<<8) | (lpMemFile[dwMemLength-2]);
|
374
|
+
//Log("PP20 detected: Packed length=%d, Unpacked length=%d\n", dwMemLength, dwDstLen);
|
375
|
+
if ((dwDstLen < 512) || (dwDstLen > 0x400000) || (dwDstLen > 16*dwMemLength)) return FALSE;
|
376
|
+
if ((pBuffer = (LPBYTE)GlobalAllocPtr(GHND, (dwDstLen + 31) & ~15)) == NULL) return FALSE;
|
377
|
+
PP20_DoUnpack(lpMemFile+4, dwMemLength-4, pBuffer, dwDstLen);
|
378
|
+
*ppMemFile = pBuffer;
|
379
|
+
*pdwMemLength = dwDstLen;
|
380
|
+
return TRUE;
|
381
|
+
}
|
382
|
+
|
@@ -0,0 +1,170 @@
|
|
1
|
+
/*
|
2
|
+
* This source code is public domain.
|
3
|
+
*
|
4
|
+
* Authors: Kenton Varda <temporal@gauge3d.org> (C interface wrapper)
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include "modplug.h"
|
8
|
+
#include "libmodplug.h"
|
9
|
+
|
10
|
+
void ModPlug_Quit(void) { /* does nothing. */ }
|
11
|
+
|
12
|
+
int ModPlug_Init(void)
|
13
|
+
{
|
14
|
+
extern void init_modplug_filters(void);
|
15
|
+
init_modplug_filters();
|
16
|
+
return 1;
|
17
|
+
}
|
18
|
+
|
19
|
+
ModPlugFile* ModPlug_Load(const void* data, int size, const ModPlug_Settings *settings)
|
20
|
+
{
|
21
|
+
return (ModPlugFile *) new_CSoundFile((const BYTE*)data, size, settings);
|
22
|
+
}
|
23
|
+
|
24
|
+
void ModPlug_Unload(ModPlugFile* file)
|
25
|
+
{
|
26
|
+
delete_CSoundFile((CSoundFile *) file);
|
27
|
+
}
|
28
|
+
|
29
|
+
int ModPlug_Read(ModPlugFile* file, void* buffer, int size)
|
30
|
+
{
|
31
|
+
CSoundFile *sndfile = (CSoundFile *) file;
|
32
|
+
return CSoundFile_Read(sndfile, buffer, size) * sndfile->gSampleSize;
|
33
|
+
}
|
34
|
+
|
35
|
+
int ModPlug_GetLength(ModPlugFile* file)
|
36
|
+
{
|
37
|
+
return CSoundFile_GetLength((CSoundFile *) file, FALSE, TRUE) * 1000;
|
38
|
+
}
|
39
|
+
|
40
|
+
void ModPlug_Seek(ModPlugFile* file, int millisecond)
|
41
|
+
{
|
42
|
+
int maxpos;
|
43
|
+
int maxtime = CSoundFile_GetLength((CSoundFile *) file, FALSE, TRUE) * 1000;
|
44
|
+
float postime;
|
45
|
+
|
46
|
+
if(millisecond > maxtime)
|
47
|
+
millisecond = maxtime;
|
48
|
+
maxpos = CSoundFile_GetMaxPosition((CSoundFile *) file);
|
49
|
+
postime = 0.0f;
|
50
|
+
if (maxtime != 0.0f)
|
51
|
+
postime = (float)maxpos / (float)maxtime;
|
52
|
+
|
53
|
+
CSoundFile_SetCurrentPos((CSoundFile *) file, (int)(millisecond * postime));
|
54
|
+
}
|
55
|
+
|
56
|
+
// inefficient, but oh well.
|
57
|
+
char *rwops_fgets(char *buf, int buflen, SDL_RWops *rwops)
|
58
|
+
{
|
59
|
+
char *retval = buf;
|
60
|
+
if (!buflen) return buf;
|
61
|
+
while (buflen > 1) {
|
62
|
+
char ch;
|
63
|
+
if (SDL_RWread(rwops, &ch, 1, 1) != 1) {
|
64
|
+
break;
|
65
|
+
}
|
66
|
+
*(buf++) = ch;
|
67
|
+
buflen--;
|
68
|
+
if (ch == '\n') {
|
69
|
+
break;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
*(buf) = '\0';
|
73
|
+
return retval;
|
74
|
+
}
|
75
|
+
|
76
|
+
long mmftell(MMFILE *mmfile)
|
77
|
+
{
|
78
|
+
return mmfile->pos;
|
79
|
+
}
|
80
|
+
|
81
|
+
void mmfseek(MMFILE *mmfile, long p, int whence)
|
82
|
+
{
|
83
|
+
int newpos = mmfile->pos;
|
84
|
+
switch(whence) {
|
85
|
+
case SEEK_SET:
|
86
|
+
newpos = p;
|
87
|
+
break;
|
88
|
+
case SEEK_CUR:
|
89
|
+
newpos += p;
|
90
|
+
break;
|
91
|
+
case SEEK_END:
|
92
|
+
newpos = mmfile->sz + p;
|
93
|
+
break;
|
94
|
+
}
|
95
|
+
if (newpos < mmfile->sz)
|
96
|
+
mmfile->pos = newpos;
|
97
|
+
else {
|
98
|
+
mmfile->error = 1;
|
99
|
+
// printf("WARNING: seeking too far\n");
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
void mmreadUBYTES(BYTE *buf, long sz, MMFILE *mmfile)
|
104
|
+
{
|
105
|
+
int sztr = sz;
|
106
|
+
// do not overread.
|
107
|
+
if (sz > mmfile->sz - mmfile->pos)
|
108
|
+
sztr = mmfile->sz - mmfile->pos;
|
109
|
+
SDL_memcpy(buf, &mmfile->mm[mmfile->pos], sztr);
|
110
|
+
mmfile->pos += sz;
|
111
|
+
// if truncated read, populate the rest of the array with zeros.
|
112
|
+
if (sz > sztr)
|
113
|
+
SDL_memset(buf+sztr, 0, sz-sztr);
|
114
|
+
}
|
115
|
+
|
116
|
+
void mmreadSBYTES(char *buf, long sz, MMFILE *mmfile)
|
117
|
+
{
|
118
|
+
// do not overread.
|
119
|
+
if (sz > mmfile->sz - mmfile->pos)
|
120
|
+
sz = mmfile->sz - mmfile->pos;
|
121
|
+
SDL_memcpy(buf, &mmfile->mm[mmfile->pos], sz);
|
122
|
+
mmfile->pos += sz;
|
123
|
+
}
|
124
|
+
|
125
|
+
BYTE mmreadUBYTE(MMFILE *mmfile)
|
126
|
+
{
|
127
|
+
BYTE b;
|
128
|
+
b = (BYTE)mmfile->mm[mmfile->pos];
|
129
|
+
mmfile->pos++;
|
130
|
+
return b;
|
131
|
+
}
|
132
|
+
|
133
|
+
void mmfclose(MMFILE *mmfile)
|
134
|
+
{
|
135
|
+
SDL_free(mmfile);
|
136
|
+
}
|
137
|
+
|
138
|
+
int mmfeof(MMFILE *mmfile)
|
139
|
+
{
|
140
|
+
if( mmfile->pos < 0 ) return TRUE;
|
141
|
+
if( mmfile->pos < mmfile->sz ) return FALSE;
|
142
|
+
return TRUE;
|
143
|
+
}
|
144
|
+
|
145
|
+
int mmfgetc(MMFILE *mmfile)
|
146
|
+
{
|
147
|
+
int b = EOF;
|
148
|
+
if( mmfeof(mmfile) ) return EOF;
|
149
|
+
b = mmfile->mm[mmfile->pos];
|
150
|
+
mmfile->pos++;
|
151
|
+
if( b=='\r' && !mmfeof(mmfile) && mmfile->mm[mmfile->pos] == '\n' ) {
|
152
|
+
b = '\n';
|
153
|
+
mmfile->pos++;
|
154
|
+
}
|
155
|
+
return b;
|
156
|
+
}
|
157
|
+
|
158
|
+
void mmfgets(char buf[], unsigned int bufsz, MMFILE *mmfile)
|
159
|
+
{
|
160
|
+
int i = 0;
|
161
|
+
int b;
|
162
|
+
for( i=0; i<(int)bufsz-1; i++ ) {
|
163
|
+
b = mmfgetc(mmfile);
|
164
|
+
if( b==EOF ) break;
|
165
|
+
buf[i] = b;
|
166
|
+
if( b == '\n' ) break;
|
167
|
+
}
|
168
|
+
buf[i] = '\0';
|
169
|
+
}
|
170
|
+
|