DiscordIntegrationModule.cs 6.9 KB

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