Last active
August 29, 2015 14:05
-
-
Save cdfmr/7458344d8b3f2616a829 to your computer and use it in GitHub Desktop.
Replacement for RaidenII's background music playing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include "audiere.h" | |
using namespace audiere; | |
#define FAKECD_API __declspec(dllexport) | |
AudioDevicePtr g_device = 0; | |
OutputStreamPtr g_stream = 0; | |
StopCallbackPtr g_callback = 0; | |
unsigned int g_volume = 100; | |
signed int (*g_stop_callback)(int, int, int) = 0; | |
#ifdef NDEBUG | |
#define dbgprint(format, args...) | |
#else | |
#define dbgprint(format, args...) \ | |
{ \ | |
char buffer[1024]; \ | |
sprintf(buffer, format, ##args); \ | |
OutputDebugString(buffer); \ | |
} | |
#endif | |
class fakecd_stop_callback : public RefImplementation<StopCallback> | |
{ | |
public: | |
void ADR_CALL streamStopped(StopEvent* event) | |
{ | |
if (event->getReason() == StopEvent::STREAM_ENDED) | |
{ | |
dbgprint("FAKECD_CALLBACK"); | |
if (g_stop_callback) | |
g_stop_callback(0, 0, 0); | |
} | |
} | |
}; | |
extern "C" | |
{ | |
FAKECD_API DWORD fakecd_init(signed int (*stop_callback)(int, int, int)) | |
{ | |
dbgprint("FAKECD_INIT: %x", (int)stop_callback); | |
g_device = OpenDevice(); | |
if (!g_device) | |
return EXIT_FAILURE; | |
g_callback = new fakecd_stop_callback(); | |
g_device->registerCallback(g_callback.get()); | |
g_stop_callback = stop_callback; | |
return EXIT_SUCCESS; | |
} | |
FAKECD_API DWORD fakecd_play(unsigned char track) | |
{ | |
dbgprint("FAKECD_PLAY: %d", (int)track); | |
if (!g_device) | |
return EXIT_FAILURE; | |
char base_path[MAX_PATH]; | |
HMODULE happ = GetModuleHandle(0); | |
GetModuleFileName(happ, base_path, MAX_PATH); | |
int i = strlen(base_path) - 1; | |
while (i > 0 && base_path[i] != '\\') i--; | |
base_path[i] = 0; | |
char ogg_path[MAX_PATH]; | |
sprintf(ogg_path, "%s\\MUSIC\\BGM%02d.OGG", base_path, track); | |
dbgprint("FILE: %s", ogg_path); | |
g_stream = OpenSound(g_device, ogg_path, true, FF_OGG); | |
if (!g_stream) | |
return EXIT_FAILURE; | |
g_stream->setVolume(g_volume / 100.0); | |
g_stream->play(); | |
return EXIT_SUCCESS; | |
} | |
FAKECD_API DWORD fakecd_pause() | |
{ | |
dbgprint("FAKECD_PAUSE"); | |
if (g_stream) | |
g_stream->stop(); | |
return EXIT_SUCCESS; | |
} | |
FAKECD_API DWORD fakecd_resume() | |
{ | |
dbgprint("FAKECD_RESUME"); | |
if (g_stream) | |
g_stream->play(); | |
return EXIT_SUCCESS; | |
} | |
FAKECD_API DWORD fakecd_stop() | |
{ | |
dbgprint("FAKECD_STOP"); | |
fakecd_pause(); | |
g_stream = 0; | |
return EXIT_SUCCESS; | |
} | |
FAKECD_API DWORD fakecd_set_volume(unsigned int volume) | |
{ | |
dbgprint("FAKECD_VOLUME: %d", (int)volume); | |
g_volume = volume; | |
if (g_volume > 100) | |
g_volume = 100; | |
if (g_stream) | |
g_stream->setVolume(g_volume / 100.0); | |
return EXIT_SUCCESS; | |
} | |
FAKECD_API DWORD fakecd_uninit() | |
{ | |
dbgprint("FAKECD_UNINIT"); | |
fakecd_stop(); | |
g_device = 0; | |
g_callback = 0; | |
return EXIT_SUCCESS; | |
} | |
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) | |
{ | |
if (fdwReason == DLL_PROCESS_DETACH) | |
fakecd_uninit(); | |
return TRUE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment