comparison src/main.c @ 1:7abb5d8b20ea v1.0

Initial commit: part 2 I added a config GUI, and actual stuff to the README. The GUI was 'made' in Visual Studio, but I trimmed down the resource file because it had weird VS2010 skid marks all over it.
author Paper <mrpapersonic@gmail.com>
date Sun, 07 Aug 2022 10:23:10 -0400
parents d91dfd53b8b4
children 712c7fd6702a
comparison
equal deleted inserted replaced
0:d91dfd53b8b4 1:7abb5d8b20ea
7 #include "main.h" 7 #include "main.h"
8 #include "discord_game_sdk.h" 8 #include "discord_game_sdk.h"
9 #include "timer.h" 9 #include "timer.h"
10 #include "config.h" 10 #include "config.h"
11 #include "dirtools.h" 11 #include "dirtools.h"
12 #include "resource.h"
12 #ifndef WIN32_LEAN_AND_MEAN 13 #ifndef WIN32_LEAN_AND_MEAN
13 # define WIN32_LEAN_AND_MEAN 14 # define WIN32_LEAN_AND_MEAN
14 #endif 15 #endif
15 #include <windows.h> 16 #include <windows.h>
17 #include <windowsx.h>
16 18
17 #define CLIENT_ID 969367220599803955 19 #define CLIENT_ID 969367220599803955
18 #define DISCORD_REQUIRE(x) \ 20 #define DISCORD_REQUIRE(x) \
19 assert(x == DiscordResult_Ok) 21 assert(x == DiscordResult_Ok)
20 22
21 #define GPPHDR_VER 0x10 23 #define GPPHDR_VER 0x10
22 24
23 winamp_general_purpose_plugin g_plugin = { 25 winamp_general_purpose_plugin g_plugin = {
24 GPPHDR_VER, // version of the plugin, defined in "gen_myplugin.h" 26 GPPHDR_VER, // version of the plugin, defined in "gen_myplugin.h"
25 "Discord GameSDK", // name/title of the plugin, defined in "gen_myplugin.h" 27 "Discord GameSDK", // name/title of the plugin, defined in "gen_myplugin.h"
26 init, // function name which will be executed on init event 28 init, // function name which will be executed on init event
27 NULL, // function name which will be executed on config event 29 conf, // function name which will be executed on config event
28 quit, // function name which will be executed on quit event 30 quit, // function name which will be executed on quit event
29 0, // handle to Winamp main window, loaded by winamp when this dll is loaded 31 0, // handle to Winamp main window, loaded by winamp when this dll is loaded
30 0 // hinstance to this dll, loaded by winamp when this dll is loaded 32 0 // hinstance to this dll, loaded by winamp when this dll is loaded
31 }; 33 };
32 34
33 WNDPROC g_lpWndProcOld = 0; 35 WNDPROC g_lpWndProcOld = 0;
34 36
35 struct timer_t timer_callbacks = { .interval = 16 }; 37 struct timer_t timer_callbacks = { .interval = 16 };
48 50
49 struct app_t app; 51 struct app_t app;
50 52
51 void update_activity_callback(void* data, enum EDiscordResult result) 53 void update_activity_callback(void* data, enum EDiscordResult result)
52 { 54 {
53 DISCORD_REQUIRE(result); 55 DISCORD_REQUIRE(result);
54 } 56 }
55 57
56 void report_current_song_status(int playbackState) 58 void report_current_song_status(int playbackState)
57 { 59 {
58 assert(playbackState != 0); 60 assert(playbackState != 0);
59 activity.timestamps.start = 0; 61 activity.timestamps.start = 0;
60 strcpy(activity.state, playbackState == 1 ? "(Playing)" : "(Paused)"); 62 strcpy(activity.state, playbackState == 1 ? "(Playing)" : "(Paused)");
61 63
62 if (playbackState == 1) { 64 if (playbackState == 1 && config.show_elapsed_time) {
63 FILETIME ft; 65 FILETIME ft;
64 GetSystemTimeAsFileTime(&ft); 66 GetSystemTimeAsFileTime(&ft);
65 ULARGE_INTEGER ul; 67 ULARGE_INTEGER ul;
66 ul.LowPart = ft.dwLowDateTime; 68 ul.LowPart = ft.dwLowDateTime;
67 ul.HighPart = ft.dwHighDateTime; 69 ul.HighPart = ft.dwHighDateTime;
68 long long dtn = ((ul.QuadPart - 116444736000000000ULL)/10000000); 70 long long dtn = ((ul.QuadPart - 116444736000000000ULL)/10000000);
69 71
70 activity.timestamps.start = dtn - SendMessage(g_plugin.hwndParent, WM_WA_IPC, 0, IPC_GETOUTPUTTIME) / 1000; 72 activity.timestamps.start = dtn - SendMessage(g_plugin.hwndParent, WM_WA_IPC, 0, IPC_GETOUTPUTTIME) / 1000;
71 } else { 73 } else {
72 activity.timestamps.start = 0; 74 activity.timestamps.start = 0;
73 } 75 }
74 76
75 char* detailsMessage = calloc(256, sizeof(char)); 77 char* detailsMessage = calloc(256, sizeof(char));
76 //if (g_pluginSettings.DisplayTitleInStatus) 78 if (config.display_title) {
77 //{
78 wchar_t* title = (wchar_t*)SendMessageW(g_plugin.hwndParent, WM_WA_IPC, 0, IPC_GET_PLAYING_TITLE); 79 wchar_t* title = (wchar_t*)SendMessageW(g_plugin.hwndParent, WM_WA_IPC, 0, IPC_GET_PLAYING_TITLE);
79 assert(WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, title, -1, detailsMessage, 256, NULL, NULL)); 80 assert(WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, title, -1, detailsMessage, 256, NULL, NULL));
80 //} 81 } else {
81 //else 82 strcpy(activity.details, "");
82 //{ 83 }
83 // strcpy(activity.details, "");
84 //}
85 strcpy(activity.details, detailsMessage); 84 strcpy(activity.details, detailsMessage);
86 free(detailsMessage); 85 free(detailsMessage);
87 86
88 app.activities->update_activity(app.activities, &activity, &app, update_activity_callback); 87 app.activities->update_activity(app.activities, &activity, &app, update_activity_callback);
89 } 88 }
116 115
117 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 116 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
118 { 117 {
119 if (message == WM_WA_IPC && lParam == IPC_CB_MISC && wParam == IPC_CB_MISC_STATUS) 118 if (message == WM_WA_IPC && lParam == IPC_CB_MISC && wParam == IPC_CB_MISC_STATUS)
120 { 119 {
121 // Notification sent from Winamp on any change in playback.
122
123 update_rich_presence_details(); 120 update_rich_presence_details();
124 } 121 }
125 122
126 return CallWindowProc(g_lpWndProcOld, hwnd, message, wParam, lParam); 123 return CallWindowProc(g_lpWndProcOld, hwnd, message, wParam, lParam);
127 } 124 }
130 char* path = dirtools_concat_paths(getenv("APPDATA"), "Winamp\\Plugins\\wgsdk"); 127 char* path = dirtools_concat_paths(getenv("APPDATA"), "Winamp\\Plugins\\wgsdk");
131 printf("%s", path); 128 printf("%s", path);
132 memset(&app, 0, sizeof(app)); 129 memset(&app, 0, sizeof(app));
133 if (IsWindowUnicode(g_plugin.hwndParent)) { 130 if (IsWindowUnicode(g_plugin.hwndParent)) {
134 g_lpWndProcOld = (WNDPROC)SetWindowLongW(g_plugin.hwndParent, -4, (LONG)WndProc); 131 g_lpWndProcOld = (WNDPROC)SetWindowLongW(g_plugin.hwndParent, -4, (LONG)WndProc);
135 } else { 132 } else {
136 g_lpWndProcOld = (WNDPROC)SetWindowLongA(g_plugin.hwndParent, -4, (LONG)WndProc); 133 g_lpWndProcOld = (WNDPROC)SetWindowLongA(g_plugin.hwndParent, -4, (LONG)WndProc);
137 } 134 }
138 135
139 memset(&activity, 0, sizeof(activity)); 136 memset(&activity, 0, sizeof(activity));
140 memset(&activities_events, 0, sizeof(activities_events)); 137 memset(&activities_events, 0, sizeof(activities_events));
141 138
142 struct DiscordCreateParams params; 139 struct DiscordCreateParams params;
143 DiscordCreateParamsSetDefault(&params); 140 DiscordCreateParamsSetDefault(&params);
144 params.client_id = CLIENT_ID; 141 params.client_id = CLIENT_ID;
145 params.flags = DiscordCreateFlags_Default; 142 params.flags = DiscordCreateFlags_Default;
169 166
170 void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) { 167 void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) {
171 DISCORD_REQUIRE(app.core->run_callbacks(app.core)); 168 DISCORD_REQUIRE(app.core->run_callbacks(app.core));
172 } 169 }
173 170
171 void conf() {
172 DialogBoxW(g_plugin.hDllInstance, (LPWSTR)DIALOG_CONFIG, g_plugin.hwndParent, &cfg_win_proc);
173 }
174
174 __declspec(dllexport) winamp_general_purpose_plugin* winampGetGeneralPurposePlugin() { 175 __declspec(dllexport) winamp_general_purpose_plugin* winampGetGeneralPurposePlugin() {
175 return &g_plugin; 176 return &g_plugin;
176 } 177 }