diff --git a/Source/3rdPartyLibs/DiscordRpc.dll b/Source/3rdPartyLibs/DiscordRpc.dll new file mode 100644 index 0000000000..78ce5d4536 Binary files /dev/null and b/Source/3rdPartyLibs/DiscordRpc.dll differ diff --git a/Source/Discord/Discord.csproj b/Source/Discord/Discord.csproj new file mode 100644 index 0000000000..69604a3fec --- /dev/null +++ b/Source/Discord/Discord.csproj @@ -0,0 +1,56 @@ + + + + + Debug + AnyCPU + {1BEF94C6-3E4A-4E00-A148-216CDF6C464F} + Library + Properties + Discord + Discord + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\3rdPartyLibs\DiscordRpc.dll + + + + + + + + + + + + + + + + + CD $(SolutionDir) +CD ..\ +XCOPY "Source\3rdPartyLibs\DiscordRpc.dll" "Program\" /S /Y + + \ No newline at end of file diff --git a/Source/Discord/OrDiscord.cs b/Source/Discord/OrDiscord.cs new file mode 100644 index 0000000000..d65f651061 --- /dev/null +++ b/Source/Discord/OrDiscord.cs @@ -0,0 +1,53 @@ +using System; +using System.Reflection; +using System.Security.Principal; +using System.Threading.Tasks; +using DiscordRpc; +/* DISCORD RICH PRESENCE +* In this file, you can specify the texts for the rich presence, and the client ID for Discord App. +* https://discord.com/rich-presence +* https://discord.com/developers/docs/rich-presence/how-to +* +* This class uses the following open-source library: https://github.com/Jimmacle/discord-rpc.net (DiscordRpc.dll) +* +* +*/ +namespace Discord +{ + public class OrDiscord + { + //private DiscordRpc.EventHandlers handlers; // EVENT HANDLERS + //private DiscordRpc.RichPresence presence; // DISCORD RICH PRESENCE PROPERTIES - List of properties: DiscordRpc.cs - Line 62 + private string CLIENT_ID = "789239264336543814"; // APP CLIENT ID (Working Discord app, configured on the Discord side.) + private RichPresence Client; + + public OrDiscord() + { + Client = new RichPresence(); + Client.Initialize(CLIENT_ID); + this.UpdateStatus(false); + } + public void Dispose() + { + this.Client.Dispose(); + } + private long getCurrentTime() //UNIX FORMAT - for DISCORD API needs. + { + TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0); + return (long)timeSpan.TotalSeconds; + + } + + public void UpdateStatus(bool inGame, string startAt = "", string HeadTo = "") + { + if (inGame == true) { + Client.Update(new RichPresenceBuilder().WithState(startAt + " - " + HeadTo, "Driving train between:").WithArtwork("in-game-image", "Open Rails (MSTS) - Train Simulator", "orts-image", "").WithTimeInfo(DateTime.Now,null)); + } + else{ + Client.Update(new RichPresenceBuilder().WithState("", "In Main Menu").WithArtwork("orts-image", "Open Rails (MSTS) - Train Simulator","","")); + } + + } + + } +} diff --git a/Source/Discord/Properties/AssemblyInfo.cs b/Source/Discord/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..a87335ebd5 --- /dev/null +++ b/Source/Discord/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Discord")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Discord")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1bef94c6-3e4a-4e00-a148-216cdf6c464f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Documentation/SampleFiles/Discord-RichPresence-Images/ORTS-1024x1024-discord-rpc.png b/Source/Documentation/SampleFiles/Discord-RichPresence-Images/ORTS-1024x1024-discord-rpc.png new file mode 100644 index 0000000000..42915aab50 Binary files /dev/null and b/Source/Documentation/SampleFiles/Discord-RichPresence-Images/ORTS-1024x1024-discord-rpc.png differ diff --git a/Source/Documentation/SampleFiles/Discord-RichPresence-Images/discord-rpc-in-game.jpg b/Source/Documentation/SampleFiles/Discord-RichPresence-Images/discord-rpc-in-game.jpg new file mode 100644 index 0000000000..ffb8cc4caf Binary files /dev/null and b/Source/Documentation/SampleFiles/Discord-RichPresence-Images/discord-rpc-in-game.jpg differ diff --git a/Source/Menu/MainForm.cs b/Source/Menu/MainForm.cs index af3622fd03..ba14b046a0 100644 --- a/Source/Menu/MainForm.cs +++ b/Source/Menu/MainForm.cs @@ -34,6 +34,7 @@ using System.Threading; using System.Windows.Forms; using Path = ORTS.Menu.Path; +using Discord; namespace ORTS { @@ -113,6 +114,8 @@ internal string RunActivityProgram GettextResourceManager catalog = new GettextResourceManager("Menu"); + OrDiscord orDiscord = new OrDiscord(); + #region Main Form public MainForm() { @@ -260,6 +263,7 @@ orderby tool.Text LoadFolderList(); Initialized = true; } + orDiscord.UpdateStatus(false); } private void LoadDocuments(List docs, string folderPath, string code = null) @@ -603,6 +607,7 @@ void buttonStart_Click(object sender, EventArgs e) if (SelectedTimetableTrain != null) DialogResult = DialogResult.OK; } + orDiscord.UpdateStatus(true, comboBoxStartAt.Text, comboBoxHeadTo.Text); } void buttonResume_Click(object sender, EventArgs e) diff --git a/Source/Menu/Menu.csproj b/Source/Menu/Menu.csproj index cf7a0de7ad..71c5edfa18 100644 --- a/Source/Menu/Menu.csproj +++ b/Source/Menu/Menu.csproj @@ -177,6 +177,10 @@ + + {1bef94c6-3e4a-4e00-a148-216cdf6c464f} + Discord + {0da86c52-ffb5-4cd6-a2c0-08f1610e6399} Orts.ExternalDevices diff --git a/Source/ORTS.sln b/Source/ORTS.sln index cb13914cc8..59194e2550 100644 --- a/Source/ORTS.sln +++ b/Source/ORTS.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26730.16 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31729.503 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RunActivity", "RunActivity\RunActivity.csproj", "{9BE44F64-417D-4AA6-AF4D-2A6A0CBC814D}" EndProject @@ -57,6 +57,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orts.ExternalDevices", "Ort EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Launcher64", "Launcher64\Launcher64.csproj", "{B558F620-3BF7-4371-B7A1-9EE8D828DE21}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord", "Discord\Discord.csproj", "{1BEF94C6-3E4A-4E00-A148-216CDF6C464F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -281,6 +283,14 @@ Global {B558F620-3BF7-4371-B7A1-9EE8D828DE21}.Release|Any CPU.Build.0 = Release|x64 {B558F620-3BF7-4371-B7A1-9EE8D828DE21}.Release|x64.ActiveCfg = Release|x64 {B558F620-3BF7-4371-B7A1-9EE8D828DE21}.Release|x64.Build.0 = Release|x64 + {1BEF94C6-3E4A-4E00-A148-216CDF6C464F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1BEF94C6-3E4A-4E00-A148-216CDF6C464F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1BEF94C6-3E4A-4E00-A148-216CDF6C464F}.Debug|x64.ActiveCfg = Debug|Any CPU + {1BEF94C6-3E4A-4E00-A148-216CDF6C464F}.Debug|x64.Build.0 = Debug|Any CPU + {1BEF94C6-3E4A-4E00-A148-216CDF6C464F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1BEF94C6-3E4A-4E00-A148-216CDF6C464F}.Release|Any CPU.Build.0 = Release|Any CPU + {1BEF94C6-3E4A-4E00-A148-216CDF6C464F}.Release|x64.ActiveCfg = Release|Any CPU + {1BEF94C6-3E4A-4E00-A148-216CDF6C464F}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE