This repository has moved! Please check out the latest version at the new location https://git.exmods.org/NGnius/GameSDKcraft
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

90 lines
2.9KB

  1. using System;
  2. using System.Reflection;
  3. using IllusionPlugin;
  4. // using GamecraftModdingAPI;
  5. using GamecraftModdingAPI.Commands;
  6. using DiscordRPC;
  7. namespace GamecraftRPC
  8. {
  9. public class MyPlugin : IPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin'
  10. {
  11. public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
  12. public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
  13. private static readonly string CLIENT_ID = "692733325902872619";
  14. private DiscordRpcClient discordRPC;
  15. // called when Gamecraft shuts down
  16. public void OnApplicationQuit()
  17. {
  18. // Shutdown this mod
  19. GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown");
  20. // Shutdown the Gamecraft modding API last
  21. GamecraftModdingAPI.Main.Shutdown();
  22. }
  23. // called when Gamecraft starts up
  24. public void OnApplicationStart()
  25. {
  26. // Initialize the Gamecraft modding API first
  27. GamecraftModdingAPI.Main.Init();
  28. // Initialize this mod
  29. SimpleCustomCommandEngine rpcCommand = new SimpleCustomCommandEngine(
  30. () => { }, // TODO: command action
  31. // also try using CommandLogWarning or CommandLogError instead of CommandLog
  32. "RPC", // command name (used to invoke it in the console)
  33. "DiscordRPC Experimental command" // command description (displayed when help command is executed)
  34. ); // this command can also be executed using the Command Computer
  35. // register the command so the modding API knows about it
  36. CommandManager.AddCommand(rpcCommand);
  37. discordRPC = new DiscordRpcClient(CLIENT_ID);
  38. discordRPC.OnReady += (sender, e) =>
  39. {
  40. GamecraftModdingAPI.Utility.Logging.LogDebug($"Received Ready from user {e.User.Username}");
  41. };
  42. discordRPC.OnPresenceUpdate += (sender, e) =>
  43. {
  44. GamecraftModdingAPI.Utility.Logging.LogDebug($"Received Update! {e.Presence}");
  45. };
  46. discordRPC.Initialize();
  47. discordRPC.SetPresence(new RichPresence()
  48. {
  49. Details = "Gamecraft Rich Presence",
  50. State = "Gamecraft RPC test",
  51. Assets = new DiscordRPC.Assets()
  52. {
  53. LargeImageKey = "image_large",
  54. LargeImageText = "Testing stuff",
  55. SmallImageKey = "image_small"
  56. }
  57. });
  58. GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has started up");
  59. }
  60. // unused methods
  61. public void OnFixedUpdate() { } // called once per physics update
  62. public void OnLevelWasInitialized(int level) { } // called after a level is initialized
  63. public void OnLevelWasLoaded(int level) { } // called after a level is loaded
  64. public void OnUpdate() // called once per rendered frame (frame update)
  65. {
  66. if (discordRPC != null ) discordRPC.Invoke();
  67. }
  68. }
  69. }