diff --git a/components/chatwnd.c b/components/chatwnd.c index 46901f4..5c71542 100755 --- a/components/chatwnd.c +++ b/components/chatwnd.c @@ -1,5 +1,6 @@ #include "chatwnd.h" #include +#include #include #include "snoctrl.h" #include "../discordtypes.h" @@ -22,6 +23,7 @@ ChatWnd *GetChatControlDetails(HWND hwnd) { return &chatwnds[i]; } } + return NULL; } void ChatView_SetUserPfp(char *path, char *user) { HANDLE f = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, NULL, diff --git a/components/guildwnd.c b/components/guildwnd.c index 4c2ebba..403a77f 100755 --- a/components/guildwnd.c +++ b/components/guildwnd.c @@ -13,6 +13,7 @@ GuildWnd *GetGuildControlDetails(HWND hwnd) { return &guildwnds[i]; } } + return NULL; } void GuildView_InsertGuild(HWND hwnd, GUIGuild gld) { GuildWnd *guildwnd = GetGuildControlDetails(hwnd); diff --git a/discordapi.c b/discordapi.c index 05029ed..c432341 100755 --- a/discordapi.c +++ b/discordapi.c @@ -335,8 +335,8 @@ void HandleREADY(cJSON *json) { : 0) { if (che->GuildID) { DiscordGuild *gld = GetGuild(che->GuildID); - MessageBoxA(NULL, gld->name, "AAAAAAAAAA", 0); if (gld) { + MessageBoxA(NULL, gld->name, "AAAAAAAAAA", 0); gld->MentionCount += che->ReadState.MentionCount; onDiscordUpdatedGuildReadState(*gld); } diff --git a/discordapi.h b/discordapi.h index ef641db..891d021 100755 --- a/discordapi.h +++ b/discordapi.h @@ -7,6 +7,7 @@ int DiscordListGuildChannels(char* guildID, DiscordChannel** out); #define GUILD_VOICE 2 #define GROUPCHAT 3 #define GUILD_CATEGORY 4 +#define GUILD_ANNOUNCEMENT 5 int DiscordGetChannelHistory(const char* channelID, unsigned int amount, DiscordMessage** msgs); char *DiscordFetchTmpPfp(char *userID, char *hash); char *DiscordFetchTmpGuildIcon(char *guildID, char *hash); diff --git a/login.c b/login.c index 3985af2..deca702 100644 --- a/login.c +++ b/login.c @@ -1,6 +1,3 @@ -#include -#include -#include #include #include int ret = 1; @@ -64,7 +61,7 @@ char *PromptToken() { wc.hCursor = LoadCursorA(NULL, IDC_ARROW); wc.lpfnWndProc = loginwndproc; RegisterClassA(&wc); - HWND hwnd = CreateWindowExA(0, clsname, "Backcord - Login", WS_OVERLAPPED, + HWND hwnd = CreateWindowExA(0, clsname, "Backcord - Login", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 320, 480, NULL, NULL, GetModuleHandleA(NULL), NULL); RECT clientrect; diff --git a/main.c b/main.c index bf37855..92df5b5 100755 --- a/main.c +++ b/main.c @@ -34,9 +34,11 @@ static HWND hPfpAreaPfp; static HWND hPfpAreaDispName; static HWND hPfpAreaUserName; static HIMAGELIST hSidePfps; +static HIMAGELIST hChannelImgList; HINSTANCE hInstance; SSL *GatewaySSL; char *token; +HWND hDMsProfileSide; int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nCmdShow) { #ifdef test_token @@ -69,6 +71,9 @@ int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, PSTR pCmdLine, InitCommonControls(); InitSnowsControls(); hSidePfps = ImageList_Create(32, 32, ILC_COLOR32 | ILC_MASK, 12, 1); + hChannelImgList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 8, 1); + ImageList_AddMasked(hChannelImgList,LoadBitmap(hinstance,MAKEINTRESOURCE(IDI_CHANNEL_VC)),RGB(255,0,255)); + ImageList_AddMasked(hChannelImgList,LoadBitmap(hinstance,MAKEINTRESOURCE(IDI_CHANNEL_ANC)),RGB(255,0,255)); hInstance = hinstance; // register the window claws const char CLASS_NAME[] = "BackcordMain"; @@ -124,7 +129,7 @@ void onDiscordGuildLoad(DiscordGuild *guild, char *id) { char *path = malloc(MAX_PATH + strlen(guild->id) + 1); wsprintfA(path, "%s%s.png", tempPath, guild->IconHash); if (GetFileAttributesA(path) == INVALID_FILE_ATTRIBUTES) { - char *path = DiscordFetchTmpGuildIcon(guild->id, + path = DiscordFetchTmpGuildIcon(guild->id, guild->IconHash); // testing } GuildView_SetIcon(hGSel, LoadPNGImage(path), id); @@ -244,7 +249,6 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, HFONT BoldSysFont = CreateFontIndirect(&ncm.lfMessageFont); InitHTTP(); - OpenWebSocket("gateway.discord.gg", "/?encoding=json&v=9", &GatewaySSL); RECT rc; GetClientRect(hwnd, &rc); @@ -345,6 +349,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, NULL // Additional application data ); SendMessage(hSend, WM_SETFONT, (WPARAM)regfont, 0); + OpenWebSocket("gateway.discord.gg", "/?encoding=json&v=9", &GatewaySSL); return 0; break; case WM_SIZE: { @@ -417,8 +422,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, tvInsert.hParent = hParent; // Parent is the root item tvInsert.hInsertAfter = TVI_LAST; - tvInsert.item.mask = TVIF_TEXT | TVIF_PARAM | - TVIS_EXPANDED | TVIF_STATE | + tvInsert.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_STATE | TVIF_IMAGE; tvInsert.item.pszText = dms[i].receipents[0].DisplayName @@ -447,7 +451,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, int ChannelCount = DiscordListGuildChannels(guild->id, &Channels); TreeView_DeleteAllItems(hChTree); - TreeView_SetImageList(hChTree, NULL, TVSIL_NORMAL); + //TreeView_SetImageList(hChTree, hChannelImgList, TVSIL_NORMAL); struct hashmap *ChannelUITable = hashmap_new(sizeof(ChannelUIEntry), 0, 0, 0, channel_hash, channel_compare, NULL, NULL); @@ -476,11 +480,12 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, tvInsert.hParent = hParent; // Parent is the root item tvInsert.hInsertAfter = TVI_LAST; tvInsert.item.mask = - TVIF_TEXT | TVIF_PARAM | TVIS_EXPANDED | TVIF_STATE; + TVIF_TEXT | TVIF_PARAM | TVIF_STATE; tvInsert.item.pszText = (VisualName); tvInsert.item.lParam = (LPARAM) & (Channels[i]); tvInsert.item.state = TVIS_EXPANDED; tvInsert.item.stateMask = TVIS_EXPANDED; + HTREEITEM lres = (HTREEITEM)SendMessage( hChTree, TVM_INSERTITEM, 0, (LPARAM)&tvInsert); if (Channels[i].type == GUILD_CATEGORY) { @@ -494,6 +499,35 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, } } else if (pNMHDR.hwndFrom == hChTree) { LPNMTREEVIEW pnmv = (LPNMTREEVIEW)lParam; + if (pNMHDR.code == NM_CUSTOMDRAW) { + LPNMTVCUSTOMDRAW pcd = (LPNMTVCUSTOMDRAW)lParam; + switch (pcd->nmcd.dwDrawStage) { + case CDDS_PREPAINT: + SetWindowLongPtr(hwnd, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW); + return CDRF_NOTIFYITEMDRAW; + case CDDS_ITEMPREPAINT: + return CDRF_NOTIFYPOSTPAINT; + case CDDS_ITEMPOSTPAINT: { + DiscordChannel *chnl = (DiscordChannel *)pcd->nmcd.lItemlParam; + if (chnl && chnl->type == GUILD_VOICE) { + RECT rc; + TreeView_GetItemRect(hChTree, (HTREEITEM)pcd->nmcd.dwItemSpec, &rc, TRUE); + // draw icon to the left of the label rect + ImageList_Draw(hChannelImgList, 0, pcd->nmcd.hdc, + rc.left - 18, rc.top + (rc.bottom - rc.top - 16) / 2, + ILD_TRANSPARENT); + } else if (chnl && chnl->type == GUILD_ANNOUNCEMENT) { + RECT rc; + TreeView_GetItemRect(hChTree, (HTREEITEM)pcd->nmcd.dwItemSpec, &rc, TRUE); + // draw icon to the left of the label rect + ImageList_Draw(hChannelImgList, 1, pcd->nmcd.hdc, + rc.left - 18, rc.top + (rc.bottom - rc.top - 16) / 2, + ILD_TRANSPARENT); + } + return CDRF_DODEFAULT; + } + } + } if (pNMHDR.code == TVN_SELCHANGED && pnmv->itemNew.state & TVIS_SELECTED) { DiscordChannel *chnl = ((DiscordChannel *)pnmv->itemNew.lParam); diff --git a/makefile b/makefile index 0c66481..adbd670 100755 --- a/makefile +++ b/makefile @@ -7,9 +7,9 @@ RES = rc/res.o Backcord: $(RES) $(WINDRES) rc/res.rc -o rc/res.o $(CC) $(SRCS) $(RES) \ - -Wl,-Bstatic -lpng -lz \ + -D _WIN32_WINNT=0x401 -D WINVER=0x401 -Wl,-Bstatic -lpng -lz \ -Wl,-Bdynamic -lgdi32 -lssl -lcrypto -lcrypt32 -lws2_32 \ - -luser32 -lcomctl32 -lcomdlg32 -lcjson -lntdll \ + -luser32 -lcomctl32 -lmsvcrt -lcomdlg32 -lcjson -lntdll \ -o Backcord.exe clean: diff --git a/rc/anc.bmp b/rc/anc.bmp new file mode 100644 index 0000000..e82436d Binary files /dev/null and b/rc/anc.bmp differ diff --git a/rc/res.h b/rc/res.h index 9133aff..4049a05 100644 --- a/rc/res.h +++ b/rc/res.h @@ -1,2 +1,4 @@ #define IDI_BACKCORDIC 101 -#define IDI_BACKCORDBANNERIC 102 \ No newline at end of file +#define IDI_BACKCORDBANNERIC 102 +#define IDI_CHANNEL_VC 111 +#define IDI_CHANNEL_ANC 112 \ No newline at end of file diff --git a/rc/res.o b/rc/res.o index d52f319..3ee846f 100644 Binary files a/rc/res.o and b/rc/res.o differ diff --git a/rc/res.rc b/rc/res.rc index 8c9b332..d4231b6 100644 --- a/rc/res.rc +++ b/rc/res.rc @@ -1,4 +1,6 @@ #include "res.h" IDI_BACKCORDIC RCDATA "backcord_icon.png" -IDI_BACKCORDBANNERIC BITMAP "backcordbanner.bmp" \ No newline at end of file +IDI_BACKCORDBANNERIC BITMAP "backcordbanner.bmp" +IDI_CHANNEL_VC BITMAP "vc.bmp" +IDI_CHANNEL_ANC BITMAP "anc.bmp" \ No newline at end of file diff --git a/rc/vc.bmp b/rc/vc.bmp new file mode 100644 index 0000000..2ef2ed3 Binary files /dev/null and b/rc/vc.bmp differ diff --git a/ws.c b/ws.c index 9932259..f104533 100755 --- a/ws.c +++ b/ws.c @@ -201,7 +201,7 @@ int ReadWebSocket(SSL *ssl, char **out_buffer, size_t *out_length) { unsigned char tlen = (plHeaders << 1) >> 1; if (tlen == 127) { SSL_read(ssl, &curPayloadLen, 8); - curPayloadLen = ntohll(curPayloadLen); + curPayloadLen = ntohl(curPayloadLen); payloadLen += curPayloadLen; } else if (tlen == 126) { unsigned short templen;