DiscordIntegrationModule.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using DiscordRPC;
  2. using Ryujinx.Common;
  3. using System;
  4. using System.Linq;
  5. namespace Ryujinx.Configuration
  6. {
  7. static class DiscordIntegrationModule
  8. {
  9. private static DiscordRpcClient _discordClient;
  10. private static string LargeDescription = "Ryujinx is a Nintendo Switch emulator.";
  11. public static RichPresence DiscordPresence { get; private set; }
  12. public static void Initialize()
  13. {
  14. DiscordPresence = new RichPresence
  15. {
  16. Assets = new Assets
  17. {
  18. LargeImageKey = "ryujinx",
  19. LargeImageText = LargeDescription
  20. },
  21. Details = "Main Menu",
  22. State = "Idling",
  23. Timestamps = new Timestamps(DateTime.UtcNow)
  24. };
  25. ConfigurationState.Instance.EnableDiscordIntegration.Event += Update;
  26. }
  27. private static void Update(object sender, ReactiveEventArgs<bool> e)
  28. {
  29. if (e.OldValue != e.NewValue)
  30. {
  31. // If the integration was active, disable it and unload everything
  32. if (e.OldValue)
  33. {
  34. _discordClient?.Dispose();
  35. _discordClient = null;
  36. }
  37. // If we need to activate it and the client isn't active, initialize it
  38. if (e.NewValue && _discordClient == null)
  39. {
  40. _discordClient = new DiscordRpcClient("568815339807309834");
  41. _discordClient.Initialize();
  42. _discordClient.SetPresence(DiscordPresence);
  43. }
  44. }
  45. }
  46. public static void SwitchToPlayingState(string titleId, string titleName)
  47. {
  48. if (SupportedTitles.Contains(titleId))
  49. {
  50. DiscordPresence.Assets.LargeImageKey = titleId;
  51. }
  52. string state = titleId;
  53. if (state == null)
  54. {
  55. state = "Ryujinx";
  56. }
  57. else
  58. {
  59. state = state.ToUpper();
  60. }
  61. string details = "Idling";
  62. if (titleName != null)
  63. {
  64. details = $"Playing {titleName}";
  65. }
  66. DiscordPresence.Details = details;
  67. DiscordPresence.State = state;
  68. DiscordPresence.Assets.LargeImageText = titleName;
  69. DiscordPresence.Assets.SmallImageKey = "ryujinx";
  70. DiscordPresence.Assets.SmallImageText = LargeDescription;
  71. DiscordPresence.Timestamps = new Timestamps(DateTime.UtcNow);
  72. _discordClient?.SetPresence(DiscordPresence);
  73. }
  74. public static void SwitchToMainMenu()
  75. {
  76. DiscordPresence.Details = "Main Menu";
  77. DiscordPresence.State = "Idling";
  78. DiscordPresence.Assets.LargeImageKey = "ryujinx";
  79. DiscordPresence.Assets.LargeImageText = LargeDescription;
  80. DiscordPresence.Assets.SmallImageKey = null;
  81. DiscordPresence.Assets.SmallImageText = null;
  82. DiscordPresence.Timestamps = new Timestamps(DateTime.UtcNow);
  83. _discordClient?.SetPresence(DiscordPresence);
  84. }
  85. public static void Exit()
  86. {
  87. _discordClient?.Dispose();
  88. }
  89. private static readonly string[] SupportedTitles =
  90. {
  91. "0100000000010000", // Super Mario Odyssey™
  92. "01000b900d8b0000", // Cadence of Hyrule – Crypt of the NecroDancer Featuring The Legend of Zelda
  93. "01000d200ac0c000", // Bud Spencer & Terence Hill - Slaps And Beans
  94. "01000d700be88000", // My Girlfriend is a Mermaid!?
  95. "01000dc007e90000", // Sparkle Unleashed
  96. "01000e2003fa0000", // MIGHTY GUNVOLT BURST
  97. "0100225000fee000", // Blaster Master Zero
  98. "010028d0045ce000", // Sparkle 2
  99. "01002b30028f6000", // Celeste
  100. "01002fc00c6d0000", // Witch Thief
  101. "010034e005c9c000", // Code of Princess EX
  102. "010036b0034e4000", // Super Mario Party™
  103. "01003d200baa2000", // Pokémon Mystery Dungeon™: Rescue Team DX
  104. "01004f8006a78000", // Super Meat Boy
  105. "010051f00ac5e000", // SEGA AGES Sonic The Hedgehog
  106. "010055d009f78000", // Fire Emblem™: Three Houses
  107. "010056e00853a000", // A Hat in Time
  108. "0100574009f9e000", // 嘘つき姫と盲目王子
  109. "01005d700e742000", // DOOM 64
  110. "0100628004bce000", // Nights of Azure 2: Bride of the New Moon
  111. "0100633007d48000", // Hollow Knight
  112. "010065500b218000", // メモリーズオフ -Innocent Fille-
  113. "010068f00aa78000", // FINAL FANTASY XV POCKET EDITION HD
  114. "01006bb00c6f0000", // The Legend of Zelda™: Link’s Awakening
  115. "01006f8002326000", // Animal Crossing™: New Horizons
  116. "01006a800016e000", // Super Smash Bros.™ Ultimate
  117. "010072800cbe8000", // PC Building Simulator
  118. "01007300020fa000", // ASTRAL CHAIN
  119. "01007330027ee000", // Ultra Street Fighter® II: The Final Challengers
  120. "0100749009844000", // 20XX
  121. "01007a4008486000", // Enchanting Mahjong Match
  122. "01007ef00011e000", // The Legend of Zelda™: Breath of the Wild
  123. "010080b00ad66000", // Undertale
  124. "010082400bcc6000", // Untitled Goose Game
  125. "01008db008c2c000", // Pokémon™ Shield
  126. "010094e00b52e000", // Capcom Beat 'Em Up Bundle
  127. "01009aa000faa000", // Sonic Mania
  128. "01009b90006dc000", // Super Mario Maker™ 2
  129. "01009cc00c97c000", // DEAD OR ALIVE Xtreme 3 Scarlet 基本無料版
  130. "0100ea80032ea000", // New Super Mario Bros.™ U Deluxe
  131. "0100a4200a284000", // LUMINES REMASTERED
  132. "0100a5c00d162000", // Cuphead
  133. "0100abf008968000", // Pokémon™ Sword
  134. "0100ae000aebc000", // Angels of Death
  135. "0100b3f000be2000", // Pokkén Tournament™ DX
  136. "0100bc2004ff4000", // Owlboy
  137. "0100cf3007578000", // Atari Flashback Classics
  138. "0100d5d00c6be000", // Our World Is Ended.
  139. "0100d6b00cd88000", // YUMENIKKI -DREAM DIARY-
  140. "0100d870045b6000", // Nintendo Entertainment System™ - Nintendo Switch Online
  141. "0100e0c00adac000", // SENRAN KAGURA Reflexions
  142. "0100e46006708000", // Terraria
  143. "0100e7200b272000", // Lanota
  144. "0100e9f00b882000", // null
  145. "0100eab00605c000", // Poly Bridge
  146. "0100efd00a4fa000", // Shantae and the Pirate's Curse
  147. "0100f6a00a684000", // ひぐらしのなく頃に奉
  148. "0100f9f00c696000", // Crash™ Team Racing Nitro-Fueled
  149. "051337133769a000", // RGB-Seizure
  150. };
  151. }
  152. }