Skip to content

Commit 8ff8aa7

Browse files
authored
Merge pull request #18 from PrawyCoD1/master
Discord RPC
2 parents 3643d85 + 21fb79a commit 8ff8aa7

28 files changed

+5851
-434
lines changed

Project1/DiscordIntegration.c

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
#pragma comment(lib, "discord-rpc.lib")
3+
4+
#include <windows.h>
5+
#include <string.h>
6+
#include <stdio.h>
7+
8+
#include "discord_rpc.h"
9+
10+
#define BUFF_SIZE 4096
11+
12+
void DiscordInitialize() {
13+
DiscordEventHandlers handlers;
14+
memset(&handlers, 0x0, sizeof(handlers));
15+
Discord_Initialize("1109509865279332392", &handlers, 1, NULL);
16+
}
17+
18+
int main(void) {
19+
//puts("Starting discord");
20+
DiscordInitialize();
21+
//puts("Discord initialized");
22+
FreeConsole();
23+
char buff[BUFF_SIZE + 1];
24+
char rpc[7][128] = { 0 };
25+
while (1) {
26+
DiscordRichPresence discord_presence;
27+
memset(&discord_presence, 0, sizeof(discord_presence));
28+
int readed_bytes = _read(0, buff, BUFF_SIZE);
29+
if (readed_bytes == 0) {
30+
MessageBoxA(0, "Error: Discord RPC has crashed", "ERROR", 0);
31+
return -1;
32+
}
33+
// Overwrite \n character with \0 (We do not need \n anymore)
34+
buff[readed_bytes - 1] = '\0';
35+
for (int i = 0, j = 0, r = 0; i < readed_bytes - 1; i++) {
36+
if (buff[i] == '\t') {
37+
rpc[r][j] = '\0';
38+
j = 0; r++;
39+
rpc[r][j] = '\0';
40+
continue;
41+
}
42+
rpc[r][j] = buff[i];
43+
j++;
44+
}
45+
/*
46+
0 = state
47+
1 = hostname
48+
2 = mapname
49+
3 = picture_name
50+
4 = GAMETYPE
51+
5 = players
52+
6 = max players
53+
*/
54+
discord_presence.state = rpc[0];
55+
discord_presence.details = rpc[1];
56+
discord_presence.largeImageText = rpc[2];
57+
discord_presence.largeImageKey = rpc[3];
58+
if (atoi(rpc[5]) > 0 && atoi(rpc[5]) < 65) {
59+
discord_presence.partySize = atoi(rpc[5]);
60+
discord_presence.partyMax = atoi(rpc[6]);
61+
}
62+
63+
Discord_UpdatePresence(&discord_presence);
64+
//For debugging
65+
//for (int i = 0; i < 7; i++) {
66+
// printf("%s\\t\t", rpc[i]);
67+
// rpc[i][0] = '\0';
68+
//}
69+
//printf("\r\n");
70+
}
71+
}

Project1/Project1.sln

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33712.159
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DiscordIntegrationProgram", "Project1.vcxproj", "{0B1C2C0D-BF9E-4E62-8F1F-AB4D55B91D4B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{0B1C2C0D-BF9E-4E62-8F1F-AB4D55B91D4B}.Debug|x64.ActiveCfg = Debug|x64
17+
{0B1C2C0D-BF9E-4E62-8F1F-AB4D55B91D4B}.Debug|x64.Build.0 = Debug|x64
18+
{0B1C2C0D-BF9E-4E62-8F1F-AB4D55B91D4B}.Debug|x86.ActiveCfg = Debug|Win32
19+
{0B1C2C0D-BF9E-4E62-8F1F-AB4D55B91D4B}.Debug|x86.Build.0 = Debug|Win32
20+
{0B1C2C0D-BF9E-4E62-8F1F-AB4D55B91D4B}.Release|x64.ActiveCfg = Release|x64
21+
{0B1C2C0D-BF9E-4E62-8F1F-AB4D55B91D4B}.Release|x64.Build.0 = Release|x64
22+
{0B1C2C0D-BF9E-4E62-8F1F-AB4D55B91D4B}.Release|x86.ActiveCfg = Release|Win32
23+
{0B1C2C0D-BF9E-4E62-8F1F-AB4D55B91D4B}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {535D7C5A-E561-4260-8B8C-031DD4F33D0C}
30+
EndGlobalSection
31+
EndGlobal

Project1/Project1.vcxproj

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{0b1c2c0d-bf9e-4e62-8f1f-ab4d55b91d4b}</ProjectGuid>
25+
<RootNamespace>Project1</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
<ProjectName>discord</ProjectName>
28+
</PropertyGroup>
29+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
30+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
31+
<ConfigurationType>Application</ConfigurationType>
32+
<UseDebugLibraries>true</UseDebugLibraries>
33+
<PlatformToolset>v143</PlatformToolset>
34+
<CharacterSet>Unicode</CharacterSet>
35+
</PropertyGroup>
36+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
37+
<ConfigurationType>Application</ConfigurationType>
38+
<UseDebugLibraries>false</UseDebugLibraries>
39+
<PlatformToolset>v143</PlatformToolset>
40+
<WholeProgramOptimization>true</WholeProgramOptimization>
41+
<CharacterSet>Unicode</CharacterSet>
42+
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
44+
<ConfigurationType>Application</ConfigurationType>
45+
<UseDebugLibraries>true</UseDebugLibraries>
46+
<PlatformToolset>v143</PlatformToolset>
47+
<CharacterSet>Unicode</CharacterSet>
48+
</PropertyGroup>
49+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
50+
<ConfigurationType>Application</ConfigurationType>
51+
<UseDebugLibraries>false</UseDebugLibraries>
52+
<PlatformToolset>v143</PlatformToolset>
53+
<WholeProgramOptimization>true</WholeProgramOptimization>
54+
<CharacterSet>Unicode</CharacterSet>
55+
</PropertyGroup>
56+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
57+
<ImportGroup Label="ExtensionSettings">
58+
</ImportGroup>
59+
<ImportGroup Label="Shared">
60+
</ImportGroup>
61+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
62+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
63+
</ImportGroup>
64+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
65+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
66+
</ImportGroup>
67+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
68+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69+
</ImportGroup>
70+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
71+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
72+
</ImportGroup>
73+
<PropertyGroup Label="UserMacros" />
74+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
75+
<ClCompile>
76+
<WarningLevel>Level3</WarningLevel>
77+
<SDLCheck>true</SDLCheck>
78+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
79+
<ConformanceMode>true</ConformanceMode>
80+
</ClCompile>
81+
<Link>
82+
<SubSystem>Console</SubSystem>
83+
<GenerateDebugInformation>true</GenerateDebugInformation>
84+
</Link>
85+
</ItemDefinitionGroup>
86+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
87+
<ClCompile>
88+
<WarningLevel>Level3</WarningLevel>
89+
<FunctionLevelLinking>true</FunctionLevelLinking>
90+
<IntrinsicFunctions>true</IntrinsicFunctions>
91+
<SDLCheck>true</SDLCheck>
92+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
93+
<ConformanceMode>true</ConformanceMode>
94+
</ClCompile>
95+
<Link>
96+
<SubSystem>Console</SubSystem>
97+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
98+
<OptimizeReferences>true</OptimizeReferences>
99+
<GenerateDebugInformation>true</GenerateDebugInformation>
100+
</Link>
101+
</ItemDefinitionGroup>
102+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
103+
<ClCompile>
104+
<WarningLevel>Level3</WarningLevel>
105+
<SDLCheck>true</SDLCheck>
106+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107+
<ConformanceMode>true</ConformanceMode>
108+
</ClCompile>
109+
<Link>
110+
<SubSystem>Console</SubSystem>
111+
<GenerateDebugInformation>true</GenerateDebugInformation>
112+
<AdditionalDependencies>discord-rpc.lib;%(AdditionalDependencies)</AdditionalDependencies>
113+
</Link>
114+
</ItemDefinitionGroup>
115+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
116+
<ClCompile>
117+
<WarningLevel>Level3</WarningLevel>
118+
<FunctionLevelLinking>true</FunctionLevelLinking>
119+
<IntrinsicFunctions>true</IntrinsicFunctions>
120+
<SDLCheck>true</SDLCheck>
121+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
122+
<ConformanceMode>true</ConformanceMode>
123+
</ClCompile>
124+
<Link>
125+
<SubSystem>Console</SubSystem>
126+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
127+
<OptimizeReferences>true</OptimizeReferences>
128+
<GenerateDebugInformation>true</GenerateDebugInformation>
129+
</Link>
130+
</ItemDefinitionGroup>
131+
<ItemGroup>
132+
<ClCompile Include="DiscordIntegration.c" />
133+
</ItemGroup>
134+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
135+
<ImportGroup Label="ExtensionTargets">
136+
</ImportGroup>
137+
</Project>

Project1/Project1.vcxproj.filters

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Pliki źródłowe">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Pliki nagłówkowe">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Pliki zasobów">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="DiscordIntegration.c">
19+
<Filter>Pliki źródłowe</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>

Project1/Project1.vcxproj.user

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ShowAllFiles>true</ShowAllFiles>
5+
</PropertyGroup>
6+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
7+
<LocalDebuggerEnvironment>TRACEDESIGNTIME = true
8+
$(LocalDebuggerEnvironment)</LocalDebuggerEnvironment>
9+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
10+
</PropertyGroup>
11+
</Project>

Project1/discord-rpc.lib.old

179 KB
Binary file not shown.

Project1/discord_register.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#if defined(DISCORD_DYNAMIC_LIB)
4+
#if defined(_WIN32)
5+
#if defined(DISCORD_BUILDING_SDK)
6+
#define DISCORD_EXPORT __declspec(dllexport)
7+
#else
8+
#define DISCORD_EXPORT __declspec(dllimport)
9+
#endif
10+
#else
11+
#define DISCORD_EXPORT __attribute__((visibility("default")))
12+
#endif
13+
#else
14+
#define DISCORD_EXPORT
15+
#endif
16+
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command);
22+
DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId);
23+
24+
#ifdef __cplusplus
25+
}
26+
#endif

Project1/discord_rpc.h

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#pragma once
2+
#include <stdint.h>
3+
4+
// clang-format off
5+
6+
#if defined(DISCORD_DYNAMIC_LIB)
7+
# if defined(_WIN32)
8+
# if defined(DISCORD_BUILDING_SDK)
9+
# define DISCORD_EXPORT __declspec(dllexport)
10+
# else
11+
# define DISCORD_EXPORT __declspec(dllimport)
12+
# endif
13+
# else
14+
# define DISCORD_EXPORT __attribute__((visibility("default")))
15+
# endif
16+
#else
17+
# define DISCORD_EXPORT
18+
#endif
19+
20+
// clang-format on
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
typedef struct DiscordRichPresence {
27+
const char* state; /* max 128 bytes */
28+
const char* details; /* max 128 bytes */
29+
int64_t startTimestamp;
30+
int64_t endTimestamp;
31+
const char* largeImageKey; /* max 32 bytes */
32+
const char* largeImageText; /* max 128 bytes */
33+
const char* smallImageKey; /* max 32 bytes */
34+
const char* smallImageText; /* max 128 bytes */
35+
const char* partyId; /* max 128 bytes */
36+
int partySize;
37+
int partyMax;
38+
const char* matchSecret; /* max 128 bytes */
39+
const char* joinSecret; /* max 128 bytes */
40+
const char* spectateSecret; /* max 128 bytes */
41+
int8_t instance;
42+
} DiscordRichPresence;
43+
44+
typedef struct DiscordUser {
45+
const char* userId;
46+
const char* username;
47+
const char* discriminator;
48+
const char* avatar;
49+
} DiscordUser;
50+
51+
typedef struct DiscordEventHandlers {
52+
void (*ready)(const DiscordUser* request);
53+
void (*disconnected)(int errorCode, const char* message);
54+
void (*errored)(int errorCode, const char* message);
55+
void (*joinGame)(const char* joinSecret);
56+
void (*spectateGame)(const char* spectateSecret);
57+
void (*joinRequest)(const DiscordUser* request);
58+
} DiscordEventHandlers;
59+
60+
#define DISCORD_REPLY_NO 0
61+
#define DISCORD_REPLY_YES 1
62+
#define DISCORD_REPLY_IGNORE 2
63+
64+
DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
65+
DiscordEventHandlers* handlers,
66+
int autoRegister,
67+
const char* optionalSteamId);
68+
DISCORD_EXPORT void Discord_Shutdown(void);
69+
70+
/* checks for incoming messages, dispatches callbacks */
71+
DISCORD_EXPORT void Discord_RunCallbacks(void);
72+
73+
/* If you disable the lib starting its own io thread, you'll need to call this from your own */
74+
#ifdef DISCORD_DISABLE_IO_THREAD
75+
DISCORD_EXPORT void Discord_UpdateConnection(void);
76+
#endif
77+
78+
DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence);
79+
DISCORD_EXPORT void Discord_ClearPresence(void);
80+
81+
DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply);
82+
83+
DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* handlers);
84+
85+
#ifdef __cplusplus
86+
} /* extern "C" */
87+
#endif

Release/mss32.dll

191 KB
Binary file not shown.

0 commit comments

Comments
 (0)