Skip to content

Commit

Permalink
1.0.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Exle committed Mar 14, 2020
1 parent 07d4dd5 commit b2e4229
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
url = https://github.com/discordapp/discord-rpc.git
[submodule "aimp_sdk"]
path = aimp_sdk
url = https://github.com/Exle/AIMP-SDK.git
url = https://github.com/Exle/AIMP-SDK.git
49 changes: 35 additions & 14 deletions AIMPPlugin.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
#pragma once

#include <apiPlugin.h>
#include "IUnknownInterfaceImpl.h"
#include "aimpSettings.h"
#include "IUnknownInterface.h"

#include "aimpRemote.h"
#include "discord_rpc.h"

class AIMPPlugin : public IUnknownInterfaceImpl<IAIMPPlugin>
class Plugin :
public IUnknownInterface<IAIMPPlugin>
{
public:
AIMPPlugin();
~AIMPPlugin();
Plugin(){ AddRef(); }

static VOID UpdatePlayerState(INT AIMPRemote_State);
static VOID UpdateTrackInfo(PAIMPTrackInfo AIMPRemote_TrackInfo);
static VOID UpdateTrackPosition(PAIMPPosition AIMPRemote_Position);

PWCHAR WINAPI InfoGet(INT Index);
DWORD WINAPI InfoGetCategories();
~Plugin() { Finalize(); }

HRESULT WINAPI Initialize(IAIMPCore* Core);
HRESULT WINAPI Finalize();

VOID WINAPI SystemNotification(INT NotifyID, IUnknown* Data);
PWCHAR WINAPI InfoGet(INT Index)
{
switch (Index)
{
case AIMP_PLUGIN_INFO_NAME: return const_cast<PWCHAR>(AIMPPLUGIN_NAME);
case AIMP_PLUGIN_INFO_AUTHOR: return const_cast<PWCHAR>(AIMPPLUGIN_AUTHOR);
case AIMP_PLUGIN_INFO_SHORT_DESCRIPTION: return const_cast<PWCHAR>(AIMPPLUGIN_SHORT_DESC);
case AIMP_PLUGIN_INFO_FULL_DESCRIPTION: return const_cast<PWCHAR>(AIMPPLUGIN_FULL_DESC);
}

return nullptr;
}

static VOID DiscordReady(VOID);
private:
bool bFinalised;
DWORD WINAPI InfoGetCategories()
{
return AIMPPLUGIN_CATEGORY;
}

VOID WINAPI SystemNotification(INT NotifyID, IUnknown* Data) {}
public:
static VOID DiscordReady(const DiscordUser* connectedUser);
public:
static VOID UpdatePlayerState(INT AIMPRemote_State);
static VOID UpdateTrackInfo(PAIMPTrackInfo AIMPRemote_TrackInfo);
static VOID UpdateTrackPosition(PAIMPPosition AIMPRemote_Position);
};
155 changes: 84 additions & 71 deletions AIMPRemote.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#include "AIMPRemote.h"
//#define _CRT_SECURE_NO_WARNINGS
#include "aimpRemote.h"
//#include <malloc.h>
#include <wchar.h>

AIMPRemote *AIMPRemote::PAIMPRemote;
AIMPRemote* AIMPRemote::PAIMPRemote;

AIMPRemote::AIMPRemote()
: FAIMPRemoteHandle(NULL),
MyWnd(NULL)
MyWnd(NULL)
{
PAIMPRemote = this;
ARTrackInfo = { 0 };
ARVersion = { 0 };
ARPosition = { 0 };
AREvents = { 0 };
ARState = AIMPREMOTE_PLAYER_STATE_STOPPED;
//ARTrackInfo = { 0 };
//ARVersion = { 0 };
//ARPosition = { 0 };
//AREvents = { 0 };
}

AIMPRemote::~AIMPRemote()
Expand All @@ -26,40 +30,40 @@ AIMPRemote::~AIMPRemote()
}
}

VOID AIMPRemote::AIMPExecuteCommand(INT ACommand)
VOID AIMPRemote::AIMPExecuteCommand(INT Command)
{
if (PAIMPRemote->FAIMPRemoteHandle != NULL)
{
SendMessage(PAIMPRemote->FAIMPRemoteHandle, WM_AIMP_COMMAND, ACommand, 0);
SendMessage(PAIMPRemote->FAIMPRemoteHandle, WM_AIMP_COMMAND, Command, 0);
}
}

INT AIMPRemote::AIMPGetPropertyValue(INT APropertyID)
INT AIMPRemote::AIMPGetPropertyValue(INT PropertyID)
{
if (PAIMPRemote->FAIMPRemoteHandle != NULL)
{
return SendMessage(PAIMPRemote->FAIMPRemoteHandle, WM_AIMP_PROPERTY, APropertyID | AIMP_RA_PROPVALUE_GET, 0);
return SendMessage(PAIMPRemote->FAIMPRemoteHandle, WM_AIMP_PROPERTY, PropertyID | AIMP_RA_PROPVALUE_GET, 0);
}

return 0;
}

BOOL AIMPRemote::AIMPSetPropertyValue(INT APropertyID, INT AValue)
BOOL AIMPRemote::AIMPSetPropertyValue(INT PropertyID, INT AValue)
{
if (PAIMPRemote->FAIMPRemoteHandle != NULL)
{
return SendMessage(PAIMPRemote->FAIMPRemoteHandle, WM_AIMP_PROPERTY, APropertyID | AIMP_RA_PROPVALUE_SET, AValue);
return SendMessage(PAIMPRemote->FAIMPRemoteHandle, WM_AIMP_PROPERTY, PropertyID | AIMP_RA_PROPVALUE_SET, AValue);
}

return false;
}

VOID AIMPRemote::AIMPSetEvents(AIMPEvents *Events)
VOID AIMPRemote::AIMPSetEvents(AIMPEvents* Events)
{
PAIMPRemote->AREvents = *Events;
}

BOOL AIMPRemote::AIMPSetRemoteHandle(const HWND *Value)
BOOL AIMPRemote::AIMPSetRemoteHandle(const HWND* Value)
{
if (PAIMPRemote->FAIMPRemoteHandle == *Value)
{
Expand All @@ -78,11 +82,11 @@ BOOL AIMPRemote::AIMPSetRemoteHandle(const HWND *Value)

if (!PAIMPRemote->MyWnd)
{
WNDCLASSEX wx = {};
wx.cbSize = sizeof(WNDCLASSEX);
wx.lpfnWndProc = WMAIMPNotify;
wx.hInstance = GetModuleHandle(NULL);
wx.lpszClassName = AIMPRemoteClassName;
WNDCLASSEX wx = {};
wx.cbSize = sizeof(WNDCLASSEX);
wx.lpfnWndProc = WMAIMPNotify;
wx.hInstance = GetModuleHandle(NULL);
wx.lpszClassName = AIMPRemoteClassName;
if (RegisterClassEx(&wx))
{
PAIMPRemote->MyWnd = CreateWindowExW(WS_EX_CLIENTEDGE, AIMPRemoteClassName, AIMPRemoteClassName, NULL, NULL, NULL, NULL, NULL, HWND_MESSAGE, NULL, NULL, NULL);
Expand Down Expand Up @@ -116,7 +120,6 @@ BOOL AIMPRemote::InfoUpdateTrackInfo()
HANDLE hFile;
PAIMPRemoteFileInfo AIMPRemote_TrackInfo;
LPWSTR offset;
WCHAR buffer[256];

hFile = OpenFileMappingA(FILE_MAP_READ, true, AIMPRemoteAccessClass);
if (!hFile)
Expand All @@ -133,54 +136,64 @@ BOOL AIMPRemote::InfoUpdateTrackInfo()

offset = reinterpret_cast<LPWSTR>(reinterpret_cast<PBYTE>(AIMPRemote_TrackInfo) + AIMPRemote_TrackInfo->Deprecated1);

ARTrackInfo = { 0 };

ARTrackInfo.Active = AIMPRemote_TrackInfo->Active;

ARTrackInfo.BitRate = AIMPRemote_TrackInfo->BitRate;
ARTrackInfo.Channels = AIMPRemote_TrackInfo->Channels;
ARTrackInfo.Duration = AIMPRemote_TrackInfo->Duration;
ARTrackInfo.FileSize = AIMPRemote_TrackInfo->FileSize;
ARTrackInfo.FileMark = AIMPRemote_TrackInfo->FileMark;
ARTrackInfo.SampleRate = AIMPRemote_TrackInfo->SampleRate;
ARTrackInfo.TrackNumber = AIMPRemote_TrackInfo->TrackNumber;

ARTrackInfo.AlbumLength = AIMPRemote_TrackInfo->AlbumLength;
ARTrackInfo.ArtistLength = AIMPRemote_TrackInfo->ArtistLength;
ARTrackInfo.DateLength = AIMPRemote_TrackInfo->DateLength;
ARTrackInfo.FileNameLength = AIMPRemote_TrackInfo->FileNameLength;
ARTrackInfo.GenreLength = AIMPRemote_TrackInfo->GenreLength;
ARTrackInfo.TitleLength = AIMPRemote_TrackInfo->TitleLength;

memcpy(buffer, offset, AIMPRemote_TrackInfo->AlbumLength * 2);
buffer[AIMPRemote_TrackInfo->AlbumLength] = 0;
WideCharToMultiByte(CP_UTF8, NULL, buffer, -1, ARTrackInfo.Album, sizeof(ARTrackInfo.Album), NULL, NULL);
if(strlen(ARTrackInfo.Album)==1)strcat_s(ARTrackInfo.Album, sizeof(ARTrackInfo.Album), " ");

memcpy(buffer, offset += AIMPRemote_TrackInfo->AlbumLength, AIMPRemote_TrackInfo->ArtistLength * 2);
buffer[AIMPRemote_TrackInfo->ArtistLength] = 0;
WideCharToMultiByte(CP_UTF8, NULL, buffer, -1, ARTrackInfo.Artist, sizeof(ARTrackInfo.Artist), NULL, NULL);
if(strlen(ARTrackInfo.Artist)==1)strcat_s(ARTrackInfo.Artist, sizeof(ARTrackInfo.Artist), " ");

memcpy(buffer, offset += AIMPRemote_TrackInfo->ArtistLength, AIMPRemote_TrackInfo->DateLength * 2);
buffer[AIMPRemote_TrackInfo->DateLength] = 0;
WideCharToMultiByte(CP_UTF8, NULL, buffer, -1, ARTrackInfo.Date, sizeof(ARTrackInfo.Date), NULL, NULL);
if(strlen(ARTrackInfo.Date)==1)strcat_s(ARTrackInfo.Date, sizeof(ARTrackInfo.Date), " ");

memcpy(buffer, offset += AIMPRemote_TrackInfo->DateLength, AIMPRemote_TrackInfo->FileNameLength * 2);
buffer[AIMPRemote_TrackInfo->FileNameLength] = 0;
WideCharToMultiByte(CP_UTF8, NULL, buffer, -1, ARTrackInfo.FileName, sizeof(ARTrackInfo.FileName), NULL, NULL);
if(strlen(ARTrackInfo.FileName)==1)strcat_s(ARTrackInfo.FileName, sizeof(ARTrackInfo.FileName), " ");

memcpy(buffer, offset += AIMPRemote_TrackInfo->FileNameLength, AIMPRemote_TrackInfo->GenreLength * 2);
buffer[AIMPRemote_TrackInfo->GenreLength] = 0;
WideCharToMultiByte(CP_UTF8, NULL, buffer, -1, ARTrackInfo.Genre, sizeof(ARTrackInfo.Genre), NULL, NULL);
if(strlen(ARTrackInfo.Genre)==1)strcat_s(ARTrackInfo.Genre, sizeof(ARTrackInfo.Genre), " ");

memcpy(buffer, offset += AIMPRemote_TrackInfo->GenreLength, AIMPRemote_TrackInfo->TitleLength * 2);
buffer[AIMPRemote_TrackInfo->TitleLength] = 0;
WideCharToMultiByte(CP_UTF8, NULL, buffer, -1, ARTrackInfo.Title, sizeof(ARTrackInfo.Title), NULL, NULL);
if(strlen(ARTrackInfo.Title)==1)strcat_s(ARTrackInfo.Title, sizeof(ARTrackInfo.Title), " ");
ARTrackInfo = { 0 };

ARTrackInfo.Active = AIMPRemote_TrackInfo->Active;

ARTrackInfo.BitRate = AIMPRemote_TrackInfo->BitRate;
ARTrackInfo.Channels = AIMPRemote_TrackInfo->Channels;
ARTrackInfo.Duration = AIMPRemote_TrackInfo->Duration;
ARTrackInfo.FileSize = AIMPRemote_TrackInfo->FileSize;
ARTrackInfo.FileMark = AIMPRemote_TrackInfo->FileMark;
ARTrackInfo.SampleRate = AIMPRemote_TrackInfo->SampleRate;
ARTrackInfo.TrackNumber = AIMPRemote_TrackInfo->TrackNumber;

ARTrackInfo.AlbumLength = AIMPRemote_TrackInfo->AlbumLength;
ARTrackInfo.ArtistLength = AIMPRemote_TrackInfo->ArtistLength;
ARTrackInfo.DateLength = AIMPRemote_TrackInfo->DateLength;
ARTrackInfo.FileNameLength = AIMPRemote_TrackInfo->FileNameLength;
ARTrackInfo.GenreLength = AIMPRemote_TrackInfo->GenreLength;
ARTrackInfo.TitleLength = AIMPRemote_TrackInfo->TitleLength;

PWCHAR buffer;

ARTrackInfo.Album = new char[AIMPRemote_TrackInfo->AlbumLength * 2];
ARTrackInfo.Artist = new char[AIMPRemote_TrackInfo->ArtistLength * 2];
ARTrackInfo.Date = new char[AIMPRemote_TrackInfo->DateLength * 2];
ARTrackInfo.FileName = new char[AIMPRemote_TrackInfo->FileNameLength * 2];
ARTrackInfo.Genre = new char[AIMPRemote_TrackInfo->GenreLength * 2];
ARTrackInfo.Title = new char[AIMPRemote_TrackInfo->TitleLength * 2];

buffer = new WCHAR[AIMPRemote_TrackInfo->AlbumLength * 2];
wmemcpy(buffer, offset, AIMPRemote_TrackInfo->AlbumLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.Album, AIMPRemote_TrackInfo->AlbumLength, NULL, NULL);

buffer = new WCHAR[AIMPRemote_TrackInfo->ArtistLength * 2];
wmemcpy(buffer, offset += AIMPRemote_TrackInfo->AlbumLength, AIMPRemote_TrackInfo->ArtistLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.Artist, AIMPRemote_TrackInfo->ArtistLength, NULL, NULL);

buffer = new WCHAR[AIMPRemote_TrackInfo->DateLength * 2];
wmemcpy(buffer, offset += AIMPRemote_TrackInfo->ArtistLength, AIMPRemote_TrackInfo->DateLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.Date, AIMPRemote_TrackInfo->DateLength, NULL, NULL);

buffer = new WCHAR[AIMPRemote_TrackInfo->FileNameLength * 2];
wmemcpy(buffer, offset += AIMPRemote_TrackInfo->DateLength, AIMPRemote_TrackInfo->FileNameLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.FileName, AIMPRemote_TrackInfo->FileNameLength, NULL, NULL);

buffer = new WCHAR[AIMPRemote_TrackInfo->GenreLength * 2];
wmemcpy(buffer, offset += AIMPRemote_TrackInfo->FileNameLength, AIMPRemote_TrackInfo->GenreLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.Genre, AIMPRemote_TrackInfo->GenreLength, NULL, NULL);

buffer = new WCHAR[AIMPRemote_TrackInfo->TitleLength * 2];
wmemcpy(buffer, offset += AIMPRemote_TrackInfo->GenreLength, AIMPRemote_TrackInfo->TitleLength * 2);
WideCharToMultiByte(CP_UTF8, 0, buffer, -1, ARTrackInfo.Title, AIMPRemote_TrackInfo->TitleLength, NULL, NULL);

ARTrackInfo.Album[AIMPRemote_TrackInfo->AlbumLength] =
ARTrackInfo.Artist[AIMPRemote_TrackInfo->ArtistLength] =
ARTrackInfo.Date[AIMPRemote_TrackInfo->DateLength] =
ARTrackInfo.FileName[AIMPRemote_TrackInfo->FileNameLength] =
ARTrackInfo.Genre[AIMPRemote_TrackInfo->GenreLength] =
ARTrackInfo.Title[AIMPRemote_TrackInfo->TitleLength] = 0;

UnmapViewOfFile(AIMPRemote_TrackInfo);
CloseHandle(hFile);
Expand All @@ -197,7 +210,7 @@ BOOL AIMPRemote::InfoUpdatePlayerState()
return true;
}

int AIMPRemote_State = AIMPGetPropertyValue(AIMP_RA_PROPERTY_PLAYER_STATE);
INT AIMPRemote_State = AIMPGetPropertyValue(AIMP_RA_PROPERTY_PLAYER_STATE);
if (ARState == AIMPRemote_State)
{
return false;
Expand All @@ -221,7 +234,7 @@ BOOL AIMPRemote::InfoUpdateTrackPositionInfo()
int AIMPRemote_PositionPos = AIMPGetPropertyValue(AIMP_RA_PROPERTY_PLAYER_POSITION) / 1000;

if (ARPosition.Duration == AIMPRemote_PositionDur
&& ARPosition.Position == AIMPRemote_PositionPos)
&& ARPosition.Position == AIMPRemote_PositionPos)
{
return false;
}
Expand Down
32 changes: 17 additions & 15 deletions AIMPRemote.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include <apiRemote.h>

#define AIMPREMOTE_PLAYER_STATE_STOPPED 0
Expand Down Expand Up @@ -31,12 +33,12 @@ typedef struct AIMPTrackInfo
DWORD GenreLength;
DWORD TitleLength;

CHAR Album[256];
CHAR Artist[256];
CHAR Date[256];
CHAR FileName[256];
CHAR Genre[256];
CHAR Title[256];
PCHAR Album;
PCHAR Artist;
PCHAR Date;
PCHAR FileName;
PCHAR Genre;
PCHAR Title;
} *PAIMPTrackInfo;

typedef struct AIMPPosition
Expand All @@ -62,8 +64,8 @@ class AIMPRemote
static VOID AIMPExecuteCommand(INT ACommand);
static INT AIMPGetPropertyValue(INT APropertyID);
static BOOL AIMPSetPropertyValue(INT APropertyID, INT AValue);
static VOID AIMPSetEvents(AIMPEvents *Events);
static BOOL AIMPSetRemoteHandle(const HWND *Value);
static VOID AIMPSetEvents(AIMPEvents* Events);
static BOOL AIMPSetRemoteHandle(const HWND* Value);
static AIMPTrackInfo AIMPGetTrackInfo();
protected:
static LRESULT CALLBACK WMAIMPNotify(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Expand All @@ -76,10 +78,10 @@ class AIMPRemote
HWND FAIMPRemoteHandle;
HWND MyWnd;

static AIMPRemote *PAIMPRemote;
AIMPTrackInfo ARTrackInfo;
AIMPVersion ARVersion;
AIMPPosition ARPosition;
AIMPEvents AREvents;
int ARState;
};
static AIMPRemote* PAIMPRemote;
AIMPTrackInfo ARTrackInfo = { 0 };
AIMPVersion ARVersion = { 0 };
AIMPPosition ARPosition = { 0 };
AIMPEvents AREvents = { 0 };
INT ARState = AIMPREMOTE_PLAYER_STATE_STOPPED;
};

0 comments on commit b2e4229

Please sign in to comment.