Initial commit

This commit is contained in:
ultrasn0w
2017-11-22 01:29:40 +01:00
committed by GitHub
parent a0e5d40676
commit 2893638e68
9 changed files with 502 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2017
Copyright (c) 2017 ultrasn0w
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

44
foo_drpc.sln Normal file
View File

@@ -0,0 +1,44 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foo_drpc", "foo_drpc\foo_drpc.vcxproj", "{CC272D9D-8B6A-43D0-AA2E-9F46B0D07C38}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foobar2000_component_client", "..\foobar2000_component_client\foobar2000_component_client.vcxproj", "{71AD2674-065B-48F5-B8B0-E1F9D3892081}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foobar2000_SDK", "..\SDK\foobar2000_SDK.vcxproj", "{E8091321-D79D-4575-86EF-064EA1A4A20D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pfc", "..\..\pfc\pfc.vcxproj", "{EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "foobar2000_sdk_helpers", "..\helpers\foobar2000_sdk_helpers.vcxproj", "{EE47764E-A202-4F85-A767-ABDAB4AFF35F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CC272D9D-8B6A-43D0-AA2E-9F46B0D07C38}.Debug|Win32.ActiveCfg = Debug|Win32
{CC272D9D-8B6A-43D0-AA2E-9F46B0D07C38}.Debug|Win32.Build.0 = Debug|Win32
{CC272D9D-8B6A-43D0-AA2E-9F46B0D07C38}.Release|Win32.ActiveCfg = Release|Win32
{CC272D9D-8B6A-43D0-AA2E-9F46B0D07C38}.Release|Win32.Build.0 = Release|Win32
{71AD2674-065B-48F5-B8B0-E1F9D3892081}.Debug|Win32.ActiveCfg = Debug|Win32
{71AD2674-065B-48F5-B8B0-E1F9D3892081}.Debug|Win32.Build.0 = Debug|Win32
{71AD2674-065B-48F5-B8B0-E1F9D3892081}.Release|Win32.ActiveCfg = Release|Win32
{71AD2674-065B-48F5-B8B0-E1F9D3892081}.Release|Win32.Build.0 = Release|Win32
{E8091321-D79D-4575-86EF-064EA1A4A20D}.Debug|Win32.ActiveCfg = Debug|Win32
{E8091321-D79D-4575-86EF-064EA1A4A20D}.Debug|Win32.Build.0 = Debug|Win32
{E8091321-D79D-4575-86EF-064EA1A4A20D}.Release|Win32.ActiveCfg = Release|Win32
{E8091321-D79D-4575-86EF-064EA1A4A20D}.Release|Win32.Build.0 = Release|Win32
{EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Debug|Win32.ActiveCfg = Debug|Win32
{EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Debug|Win32.Build.0 = Debug|Win32
{EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Release|Win32.ActiveCfg = Release|Win32
{EBFFFB4E-261D-44D3-B89C-957B31A0BF9C}.Release|Win32.Build.0 = Release|Win32
{EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Debug|Win32.ActiveCfg = Debug|Win32
{EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Debug|Win32.Build.0 = Debug|Win32
{EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Release|Win32.ActiveCfg = Release|Win32
{EE47764E-A202-4F85-A767-ABDAB4AFF35F}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

222
foo_drpc/Plugin.cpp Normal file
View File

@@ -0,0 +1,222 @@
#include <cmath>
#include "Plugin.h"
DECLARE_COMPONENT_VERSION(
"foo_drpc",
"0.1",
"<EFBFBD> 2017 - ultrasn0w");
static initquit_factory_t<foo_drpc> foo_interface;
static std::chrono::time_point<std::chrono::high_resolution_clock> lastT;
static std::chrono::time_point<std::chrono::high_resolution_clock> req;
static bool errored; // Still kind of unused
static bool connected;
static bool first;
foo_drpc::foo_drpc()
{
errored = false;
connected = true;
first = true;
}
foo_drpc::~foo_drpc()
{
}
void foo_drpc::on_init()
{
static_api_ptr_t<play_callback_manager> pcm;
pcm->register_callback(
this,
play_callback::flag_on_playback_starting |
play_callback::flag_on_playback_stop |
play_callback::flag_on_playback_pause |
play_callback::flag_on_playback_new_track |
play_callback::flag_on_playback_edited |
play_callback::flag_on_playback_dynamic_info_track,
false);
discordInit();
initDiscordPresence();
}
void foo_drpc::on_quit()
{
Discord_Shutdown();
static_api_ptr_t<play_callback_manager>()->unregister_callback(this);
}
void foo_drpc::on_playback_starting(play_control::t_track_command command, bool pause)
{
if (!connected) return;
if (pause)
{
discordPresence.state = "Paused";
discordPresence.smallImageKey = "pause";
}
else
{
switch (command)
{
case play_control::track_command_play:
case play_control::track_command_resume:
case play_control::track_command_settrack:
discordPresence.state = "Listening";
discordPresence.smallImageKey = "play";
break;
}
}
metadb_handle_ptr track;
static_api_ptr_t<playback_control> pbc;
if (pbc->get_now_playing(track))
{
on_playback_new_track(track);
}
// updateDiscordPresence();
}
void foo_drpc::on_playback_stop(play_control::t_stop_reason reason)
{
if (!connected) return;
switch (reason)
{
case play_control::stop_reason_user:
case play_control::stop_reason_eof:
case play_control::stop_reason_shutting_down:
discordPresence.state = "Stopped";
discordPresence.smallImageKey = "stop";
break;
}
updateDiscordPresence();
}
void foo_drpc::on_playback_pause(bool pause)
{
if (!connected) return;
discordPresence.state = (pause ? "Paused" : "Listening");
discordPresence.smallImageKey = (pause ? "pause" : "play");
updateDiscordPresence();
}
void foo_drpc::on_playback_new_track(metadb_handle_ptr track)
{
if (!connected) return;
service_ptr_t<titleformat_object> script;
pfc::string8 format = "%artist% - %title%";
if (static_api_ptr_t<titleformat_compiler>()->compile(script, format))
{
static_api_ptr_t<playback_control> pbc;
pbc->playback_format_title_ex(
track,
nullptr,
format,
script,
nullptr,
playback_control::display_level_titles);
if (format.get_length() + 1 <= 128) {
static char nya[128];
size_t destination_size = sizeof(nya);
strncpy_s(nya, format.get_ptr(), destination_size);
nya[destination_size - 1] = '\0';
discordPresence.state = "Listening";
discordPresence.smallImageKey = "play";
discordPresence.details = nya;
updateDiscordPresence();
}
}
}
void foo_drpc::on_playback_dynamic_info_track(const file_info& info)
{
metadb_handle_ptr track;
static_api_ptr_t<playback_control> pbc;
if (pbc->get_now_playing(track))
{
on_playback_new_track(track);
}
}
void foo_drpc::initDiscordPresence()
{
memset(&discordPresence, 0, sizeof(discordPresence));
discordPresence.state = "Initialized";
discordPresence.details = "topkek";
discordPresence.largeImageKey = "logo";
discordPresence.smallImageKey = "stop";
// discordPresence.partyId = "party1234";
// discordPresence.partySize = 1;
// discordPresence.partyMax = 6;
updateDiscordPresence();
}
void foo_drpc::updateDiscordPresence()
{
if (first) {
lastT = std::chrono::high_resolution_clock::now();
first = false;
Discord_UpdatePresence(&discordPresence);
}
else {
req = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = req - lastT;
// spam protection
if (elapsed.count() > 1.0) {
Discord_UpdatePresence(&discordPresence);
lastT = std::chrono::high_resolution_clock::now();
}
}
}
void connectedF()
{
connected = true;
}
void disconnectedF(int errorCode, const char* message)
{
connected = false;
}
void erroredF(int errorCode, const char* message)
{
errored = true;
}
void foo_drpc::discordInit()
{
memset(&handlers, 0, sizeof(handlers));
handlers.ready = connectedF;
handlers.disconnected = disconnectedF;
handlers.errored = erroredF;
// handlers.joinGame = [](const char* joinSecret) {};
// handlers.spectateGame = [](const char* spectateSecret) {};
// handlers.joinRequest = [](const DiscordJoinRequest* request) {};
Discord_Initialize(APPLICATION_ID, &handlers, 1, NULL);
}
// thx SuperKoko (unused)
LPSTR foo_drpc::UnicodeToAnsi(LPCWSTR s)
{
if (s == NULL) return NULL;
int cw = lstrlenW(s);
if (cw == 0) { CHAR *psz = new CHAR[1]; *psz = '\0'; return psz; }
int cc = WideCharToMultiByte(CP_UTF8, 0, s, cw, NULL, 0, NULL, NULL);
if (cc == 0) return NULL;
CHAR *psz = new CHAR[cc + 1];
cc = WideCharToMultiByte(CP_UTF8, 0, s, cw, psz, cc, NULL, NULL);
if (cc == 0) { delete[] psz; return NULL; }
psz[cc] = '\0';
return psz;
}

42
foo_drpc/Plugin.h Normal file
View File

@@ -0,0 +1,42 @@
#ifndef FOODRPC_PLUGIN_H_
#define FOODRPC_PLUGIN_H_
#include "../../SDK/foobar2000.h"
#include "discord-rpc.h"
#include <chrono>
class foo_drpc :
public initquit,
public play_callback
{
public:
foo_drpc();
~foo_drpc();
DiscordEventHandlers handlers;
DiscordRichPresence discordPresence;
// Censored on GitHub :)
const char* APPLICATION_ID = "FILL_IN_HERE";
void on_init();
void on_quit();
void discordInit();
void initDiscordPresence();
void updateDiscordPresence();
LPSTR UnicodeToAnsi(LPCWSTR s);
void on_playback_starting(play_control::t_track_command command, bool paused);
void on_playback_stop(play_control::t_stop_reason reason);
void on_playback_pause(bool state);
void on_playback_new_track(metadb_handle_ptr track);
void on_playback_edited(metadb_handle_ptr track) { on_playback_new_track(track); }
void on_playback_dynamic_info_track(const file_info& info);
void on_playback_time(double time) {}
void on_playback_seek(double time) {}
void on_playback_dynamic_info(file_info const& info) {}
void on_volume_change(float p_new_val) {}
};
#endif

BIN
foo_drpc/Plugin.rc Normal file

Binary file not shown.

120
foo_drpc/foo_drpc.vcxproj Normal file
View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{CC272D9D-8B6A-43D0-AA2E-9F46B0D07C38}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>foo_drpc</RootNamespace>
<ProjectName>foo_drpc</ProjectName>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;FOO_DRPC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\shared\</AdditionalLibraryDirectories>
<AdditionalDependencies>shared.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;FOO_DRPC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<ExceptionHandling>false</ExceptionHandling>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>..\..\shared\</AdditionalLibraryDirectories>
<AdditionalDependencies>shared.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Plugin.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="discord-rpc.h" />
<ClInclude Include="Plugin.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Plugin.rc" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\foobar2000_component_client\foobar2000_component_client.vcxproj">
<Project>{71ad2674-065b-48f5-b8b0-e1f9d3892081}</Project>
</ProjectReference>
<ProjectReference Include="..\..\helpers\foobar2000_sdk_helpers.vcxproj">
<Project>{ee47764e-a202-4f85-a767-abdab4aff35f}</Project>
</ProjectReference>
<ProjectReference Include="..\..\SDK\foobar2000_SDK.vcxproj">
<Project>{e8091321-d79d-4575-86ef-064ea1a4a20d}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\pfc\pfc.vcxproj">
<Project>{ebfffb4e-261d-44d3-b89c-957b31a0bf9c}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Library Include="lib\discord-rpc.lib" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="lib">
<UniqueIdentifier>{694477ed-4bc3-430d-8c5a-53a392832187}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Plugin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Plugin.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="discord-rpc.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Plugin.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Library Include="lib\discord-rpc.lib">
<Filter>lib</Filter>
</Library>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

23
foo_drpc/resource.h Normal file
View File

@@ -0,0 +1,23 @@
//{{NO_DEPENDENCIES}}
// Von Microsoft Visual C++ generierte Includedatei.
// Verwendet durch Plugin.rc
//
#define VS_VERSION_INFO 1
#define VFFF_ISSHAREDFILE 0x0001
#define VFF_CURNEDEST 0x0001
#define VIFF_FORCEINSTALL 0x0001
#define VFF_FILEINUSE 0x0002
#define VIFF_DONTDELETEOLD 0x0002
#define VFF_BUFFTOOSMALL 0x0004
#define VS_USER_DEFINED 100
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif