Created
November 5, 2015 22:52
-
-
Save theraphim/09ae783ede60984e808a to your computer and use it in GitHub Desktop.
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
#define PLUGIN_VERSION ("mIRCAMP 2 (c) 2001, Stingray // (http)stingr.net") | |
#define WINAMP_WINDOW_CLASS ("Winamp v1.x") | |
#define WINAMP_PLAYLIST_DEFAULT ("C:\\Program Files\\Winamp\\Winamp.m3u") | |
#define WINAMP_PLAYLIST_SHORT_DEFAULT ("Winamp.m3u") | |
// winamp | |
HWND FindWinampWindow() { | |
return FindWindow(WINAMP_WINDOW_CLASS, NULL); | |
} | |
int GetPlaylistItemIndex(HWND hWinamp) { | |
return SendMessage(hWinamp, WM_WA_IPC, 0, IPC_WRITEPLAYLIST); | |
} | |
// will cause undefined results under old windows | |
void GetWinampPlaylistFile(HWND hWinamp, char* cPlaylist) { | |
if (GetWindowModuleFileName(hWinamp, cPlaylist, MAX_PATH)) { | |
strcpy(strrchr(cPlaylist, '\\') + 1, WINAMP_PLAYLIST_SHORT_DEFAULT); | |
} else { | |
strncpy(cPlaylist, WINAMP_PLAYLIST_DEFAULT, MAX_PATH); | |
} | |
} | |
#define WINAMP_STOPPED 0 | |
#define WINAMP_PLAYING 1 | |
#define WINAMP_PAUSED 3 | |
int GetWinampState(HWND hWinamp) { | |
return SendMessage(hWinamp, WM_WA_IPC, 0, IPC_ISPLAYING); | |
} | |
int GetWinampPosition(HWND hWinamp) { | |
int iLength = SendMessage(hWinamp, WM_WA_IPC, 1, IPC_GETOUTPUTTIME); | |
if (iLength <= 0) | |
return 0; | |
int iPosition = SendMessage(hWinamp, WM_WA_IPC, 0, IPC_GETOUTPUTTIME); | |
return (iPosition / iLength) / 10; | |
} | |
void GetWinampTitle(HWND hWinamp, char* cTitle) { | |
GetWindowText(hWinamp, cTitle, MAX_PATH); | |
} | |
void GetPlaylistItemTitle(const char* cPlaylist, int iIndex, char* cTitle) { | |
char cBuffer[MAX_PATH]; | |
FILE* fStream; | |
if (fStream = fopen(cPlaylist, "r")) { | |
if (!feof(fStream)) { | |
fgets(cBuffer, MAX_PATH, fStream); | |
if (cBuffer[0] == '#') { | |
while ((!feof(fStream)) && (iIndex >= 0)) { | |
fgets(cBuffer, MAX_PATH, fStream); | |
if (cBuffer[0] == '#') { | |
strncpy(cTitle, strchr(cBuffer, ',') + 1, MAX_PATH); | |
fgets(cBuffer, MAX_PATH, fStream); | |
} else { | |
strncpy(cTitle, strrchr(cBuffer, '\\') + 1, MAX_PATH); | |
} | |
iIndex--; | |
} | |
} | |
} | |
fclose(fStream); | |
} | |
} | |
// Win32 DLL Load stuff | |
/* | |
BOOL APIENTRY DllMain( HANDLE hModule, | |
DWORD ul_reason_for_call, | |
LPVOID lpReserved | |
) | |
{ | |
switch (ul_reason_for_call) | |
{ | |
case DLL_PROCESS_ATTACH: | |
case DLL_THREAD_ATTACH: | |
case DLL_THREAD_DETACH: | |
case DLL_PROCESS_DETACH: | |
break; | |
} | |
return TRUE; | |
} | |
*/ | |
// mIRC Stuff | |
void MIRCAPI LoadDll(LOADINFO* info) { | |
} | |
// mIRC Entrypoints | |
int MIRCAPI GetPlayItem(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause) { | |
char cTitle[MAX_PATH]; | |
ZeroMemory(cTitle, sizeof(cTitle)); | |
HWND hWinamp; | |
if (hWinamp = FindWinampWindow()) { | |
int iItem = GetPlaylistItemIndex(hWinamp); | |
char cPlaylist[MAX_PATH]; | |
GetWinampPlaylistFile(hWinamp, cPlaylist); | |
GetPlaylistItemTitle(cPlaylist, iItem, cTitle); | |
strncpy(data, cTitle, 900); | |
} | |
return 3; | |
} | |
int MIRCAPI GetPlayItemInfo(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause) { | |
char cTitle[MAX_PATH]; | |
ZeroMemory(cTitle, sizeof(cTitle)); | |
HWND hWinamp; | |
if (hWinamp = FindWinampWindow()) { | |
int iState = GetWinampState(hWinamp); | |
if (iState != WINAMP_STOPPED) { | |
int iPercent = GetWinampPosition(hWinamp); | |
itoa(iPercent, cTitle, 10); | |
strcat(cTitle, "%"); | |
} | |
if (iState != WINAMP_PLAYING) { | |
switch (iState) { | |
case WINAMP_STOPPED: | |
strcat(cTitle, " [stopped]"); | |
break; | |
case WINAMP_PAUSED: | |
strcat(cTitle, " [paused]"); | |
break; | |
} | |
} | |
strncpy(data, cTitle, 900); | |
} | |
return 3; | |
} | |
int MIRCAPI GetWinampWindowTitle(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause) { | |
char cTitle[MAX_PATH]; | |
ZeroMemory(cTitle, sizeof(cTitle)); | |
HWND hWinamp; | |
if (hWinamp = FindWinampWindow()) { | |
GetWinampTitle(hWinamp, cTitle); | |
strncpy(data, cTitle, 900); | |
} | |
return 3; | |
} | |
int MIRCAPI GetPluginVersion(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause) { | |
strcpy(data, PLUGIN_VERSION); | |
return 3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment