diff --git a/HelloModdingWorld.sln b/GamecraftRPC.sln similarity index 85% rename from HelloModdingWorld.sln rename to GamecraftRPC.sln index 53b74f0..4b1b05c 100644 --- a/HelloModdingWorld.sln +++ b/GamecraftRPC.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29609.76 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloModdingWorld", "HelloModdingWorld\HelloModdingWorld.csproj", "{E0EEA15D-AB3C-4C73-A000-C49B5AE9EA66}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GamecraftRPC", "GamecraftRPC\GamecraftRPC.csproj", "{E0EEA15D-AB3C-4C73-A000-C49B5AE9EA66}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/HelloModdingWorld/HelloModdingWorld.csproj b/GamecraftRPC/GamecraftRPC.csproj similarity index 99% rename from HelloModdingWorld/HelloModdingWorld.csproj rename to GamecraftRPC/GamecraftRPC.csproj index 0430e52..d93aae5 100644 --- a/HelloModdingWorld/HelloModdingWorld.csproj +++ b/GamecraftRPC/GamecraftRPC.csproj @@ -6,12 +6,13 @@ 0.0.1 Me MIT - https://git.exmods.org/modtainers/HelloModdingWorld + https://git.exmods.org/???/??? en-CA + diff --git a/GamecraftRPC/MyPlugin.cs b/GamecraftRPC/MyPlugin.cs new file mode 100644 index 0000000..daad0b8 --- /dev/null +++ b/GamecraftRPC/MyPlugin.cs @@ -0,0 +1,90 @@ +using System; +using System.Reflection; + +using IllusionPlugin; +// using GamecraftModdingAPI; +using GamecraftModdingAPI.Commands; +using DiscordRPC; + +namespace GamecraftRPC +{ + public class MyPlugin : IPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin' + { + public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; + + public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + + private static readonly string CLIENT_ID = "692733325902872619"; + + private DiscordRpcClient discordRPC; + + // called when Gamecraft shuts down + public void OnApplicationQuit() + { + // Shutdown this mod + GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown"); + + // Shutdown the Gamecraft modding API last + GamecraftModdingAPI.Main.Shutdown(); + } + + // called when Gamecraft starts up + public void OnApplicationStart() + { + // Initialize the Gamecraft modding API first + GamecraftModdingAPI.Main.Init(); + + // Initialize this mod + SimpleCustomCommandEngine rpcCommand = new SimpleCustomCommandEngine( + () => { }, // TODO: command action + // also try using CommandLogWarning or CommandLogError instead of CommandLog + "RPC", // command name (used to invoke it in the console) + "DiscordRPC Experimental command" // command description (displayed when help command is executed) + ); // this command can also be executed using the Command Computer + + // register the command so the modding API knows about it + CommandManager.AddCommand(rpcCommand); + + discordRPC = new DiscordRpcClient(CLIENT_ID); + + discordRPC.OnReady += (sender, e) => + { + GamecraftModdingAPI.Utility.Logging.LogDebug($"Received Ready from user {e.User.Username}"); + }; + + discordRPC.OnPresenceUpdate += (sender, e) => + { + GamecraftModdingAPI.Utility.Logging.LogDebug($"Received Update! {e.Presence}"); + }; + + discordRPC.Initialize(); + + discordRPC.SetPresence(new RichPresence() + { + Details = "Gamecraft Rich Presence", + State = "Gamecraft RPC test", + Assets = new DiscordRPC.Assets() + { + LargeImageKey = "image_large", + LargeImageText = "Testing stuff", + SmallImageKey = "image_small" + } + }); + + GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has started up"); + } + + // unused methods + + public void OnFixedUpdate() { } // called once per physics update + + public void OnLevelWasInitialized(int level) { } // called after a level is initialized + + public void OnLevelWasLoaded(int level) { } // called after a level is loaded + + public void OnUpdate() // called once per rendered frame (frame update) + { + if (discordRPC != null ) discordRPC.Invoke(); + } + } +} \ No newline at end of file diff --git a/HelloModdingWorld/MyPlugin.cs b/HelloModdingWorld/MyPlugin.cs deleted file mode 100644 index 57bc909..0000000 --- a/HelloModdingWorld/MyPlugin.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System.Reflection; - -using IllusionPlugin; -// using GamecraftModdingAPI; -using GamecraftModdingAPI.Commands; - -namespace HelloModdingWorld -{ - public class MyPlugin : IPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin' - { - public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; // HelloModdingWorld by default - // To change the name, change the project's name - - public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); // 0.0.1 by default - // To change the version, change 0.0.1 in HelloModdingWorld.csproj - - private static readonly string helloWorldCommandName = "HelloWorld"; // command name - - // called when Gamecraft shuts down - public void OnApplicationQuit() - { - // Shutdown this mod - GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown"); - - // Shutdown the Gamecraft modding API last - GamecraftModdingAPI.Main.Shutdown(); - } - - // called when Gamecraft starts up - public void OnApplicationStart() - { - // Initialize the Gamecraft modding API first - GamecraftModdingAPI.Main.Init(); - // check out the modding API docs here: https://mod.exmods.org/ - - // Initialize this mod - // create SimpleCustomCommandEngine - // this writes "Hello modding world!" when you execute it in Gamecraft's console - // (use the forward-slash key '/' to open the console in Gamecraft when in a game) - SimpleCustomCommandEngine helloWorldCommand = new SimpleCustomCommandEngine( - () => { GamecraftModdingAPI.Utility.Logging.CommandLog("Hello modding world!"); }, // command action - // also try using CommandLogWarning or CommandLogError instead of CommandLog - helloWorldCommandName, // command name (used to invoke it in the console) - "Says Hello modding world!" // command description (displayed when help command is executed) - ); // this command can also be executed using the Command Computer - - // register the command so the modding API knows about it - CommandManager.AddCommand(helloWorldCommand); - - GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has started up"); - } - - // unused methods - - public void OnFixedUpdate() { } // called once per physics update - - public void OnLevelWasInitialized(int level) { } // called after a level is initialized - - public void OnLevelWasLoaded(int level) { } // called after a level is loaded - - public void OnUpdate() { } // called once per rendered frame (frame update) - } -} \ No newline at end of file diff --git a/LICENSE b/LICENSE index d449d3e..4d0a1dd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) +Copyright (c) 2020 Exmods Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 6715fc9..a2e8498 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ -# HelloModdingWorld +# GamecraftRPC -Shell project for Gamecraft mods. -Use this as a quick-start project structure for your own mods, or to learn how modding works. +Experimental project for Discord Rich Presence in Gamecraft. +This currently only works in native environments (eg this does not work with Wine/Proton) although I'm sure someone can find a way to fix that'. -## Setup +## Dev environment Setup This project requires most of Gamecraft's `.dll` files to function correctly. Most, but not all, of these files are stored in Gamecraft's `Gamecraft_Data\Managed` folder. The project is pre-configured to look in a folder called ref in the solution's main directory or one level up from that. -You can make sure HelloModdingWorld can find all of `.dll` files it needs by copying your Gamecraft folder here and renaming it to `ref`, but you'll have to re-copy it after every Gamecraft update. +You can make sure GamecraftRPC can find all of `.dll` files it needs by copying your Gamecraft folder here and renaming it to `ref`, but you'll have to re-copy it after every Gamecraft update. You can also create a symbolic link (look it up) to your Gamecraft install folder named `ref` in this folder to avoid having to re-copy files. For any mod to work, you will have to patch your game with [GCIPA](https://git.exmods.org/modtainers/GCIPA). @@ -21,12 +21,12 @@ This project also requires the [GamecraftModdingAPI](https://git.exmods.org/modt ## Building -After you've completed the setup, open the solution file `HelloModdingWorld.sln` in your prefered C# .NET/Mono development environment. +After you've completed the setup, open the solution file `GamecraftRPC.sln` in your prefered C# .NET/Mono development environment. I'd recommend Visual Studio Community Edition or JetBrains Rider for Windows and Monodevelop for Linux. -If you've successfully completed setup, you should be able to build the HelloModdingWorld project without errors. +If you've successfully completed setup, you should be able to build the GamecraftRPC project without errors. If it doesn't work and you can't figure out why, ask for help on [our Discord server](https://discord.gg/xjnFxQV). ## Installation -To install the HelloModdingWorld mod, copy the build's `HelloModdingWorld.dll` into the `Plugins` folder in Gamecraft's main folder. +To install the GamecraftRPC mod, copy the build's `GamecraftRPC.dll` into the `Plugins` folder in Gamecraft's main folder.