From 8d81295f43d6d097baff352b15569fc741c2f961 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Mon, 29 Jun 2020 20:19:50 -0400 Subject: [PATCH] Add additional development info --- GamecraftRPC/CallbackUtility.cs | 1 + GamecraftRPC/Plugin.cs | 53 ++++++++++++++++++++++----------- README.md | 5 +++- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/GamecraftRPC/CallbackUtility.cs b/GamecraftRPC/CallbackUtility.cs index 60f558d..3648c10 100644 --- a/GamecraftRPC/CallbackUtility.cs +++ b/GamecraftRPC/CallbackUtility.cs @@ -50,6 +50,7 @@ namespace GamecraftRPC public static void MenuEnter(object sender, MenuEventArgs data) { + if (PresenceUtility.IsConnecting) return; PresenceUtility.LastGameStart = 0; PresenceUtility.Activity.Timestamps.Start = 0; PresenceUtility.Activity.Timestamps.End = 0; diff --git a/GamecraftRPC/Plugin.cs b/GamecraftRPC/Plugin.cs index c8c2df4..59bdefd 100644 --- a/GamecraftRPC/Plugin.cs +++ b/GamecraftRPC/Plugin.cs @@ -36,31 +36,31 @@ namespace GamecraftRPC internal static Discord.Discord DiscordRPC; - // called when Gamecraft shuts down + // called when Gamecraft shuts down public void OnApplicationQuit() { - // Shutdown this mod - if (DiscordRPC != null) - { + // Shutdown this mod + if (DiscordRPC != null) + { DiscordRPC.GetActivityManager().ClearActivity((result) => { GamecraftModdingAPI.Utility.Logging.LogDebug($"Cleared status: {result}"); DiscordRPC.Dispose(); }); - } + } GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown"); - // Shutdown the Gamecraft modding API last + // Shutdown the Gamecraft modding API last GamecraftModdingAPI.Main.Shutdown(); } - // called when Gamecraft starts up + // called when Gamecraft starts up public void OnApplicationStart() { - // Initialize the Gamecraft modding API first + // Initialize the Gamecraft modding API first GamecraftModdingAPI.Main.Init(); // detect Wine (maybe?) bool isWineDetected = false; foreach (var key in Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software").GetSubKeyNames()) { - if (key == "Wine") + if (key == "Wine") { isWineDetected = true; break; @@ -72,7 +72,7 @@ namespace GamecraftRPC GamecraftModdingAPI.Utility.Logging.MetaLog("\n--------------------------------\n\nIt looks like you may be using Wine/Proton, cool!\nPlease install https://github.com/0e4ef622/wine-discord-ipc-bridge to get this to work.\n\n--------------------------------"); } - // Initialize this mod + // Initialize this mod DiscordRPC = new Discord.Discord(CLIENT_ID, (UInt64)Discord.CreateFlags.NoRequireDiscord); DiscordRPC.SetLogHook(LOG_LEVEL, (_, msg) => { GamecraftModdingAPI.Utility.Logging.MetaLog(msg); }); //DiscordRPC.GetActivityManager().RegisterSteam(1078000); @@ -92,7 +92,7 @@ namespace GamecraftRPC Game.Simulate += CallbackUtility.SimulationEnter; Client.EnterMenu += CallbackUtility.MenuEnter; - GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new Engines.PlayerCountEngine()); + GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new Engines.PlayerCountEngine()); CommandBuilder.Builder() .Name("JoinDiscord") @@ -133,18 +133,35 @@ namespace GamecraftRPC .Action(() => { if (DiscordRPC != null) - { - Game game = Game.CurrentGame(); + { + Game game = Game.CurrentGame(); Client client = new Client(); GamecraftModdingAPI.Utility.Logging.CommandLog($"Gamecraft {client.Version}\nUnity {client.UnityVersion}\n{Name} {Version}\nSDK {DiscordRPC.ToString()}\nGame {game.Name}"); - } - else - { - GamecraftModdingAPI.Utility.Logging.CommandLogError("Discord GameSDK functionality is unavailable. Please make sure Discord is open when launching Gamecraft."); - } + } + else + { + GamecraftModdingAPI.Utility.Logging.CommandLogError("Discord GameSDK functionality is unavailable. Please make sure Discord is open when launching Gamecraft."); + } }) .Build(); +#if !RELEASE + bool alreadyWarned = false; + Client.EnterMenu += (_, args) => + { + if (alreadyWarned) return; + //GamecraftModdingAPI.Utility.Logging.LogDebug($"Displaying {Name} {Version} DEBUG warning"); + /* + RobocraftX.Services.ErrorBuilder.DisplayCustomError( + $"THIS IS NOT ACTUALLY AN ERROR! {Name} v{Version} is a pre-release. If you encounter a bug or other issue, please report it to NGnius or Exmods on Discord.", + "Discord", () => { UnityEngine.Application.OpenURL("https://discord.exmods.org"); }, + "Ok!", () => { GamecraftModdingAPI.Utility.Logging.LogDebug($"Dismissed {Name} {Version} DEBUG warning"); } + ); + */ + RobocraftX.Services.ErrorBuilder.DisplayWarning($"{Name} v{Version} is a pre-release. If you encounter a bug or other issue, please report it to NGnius or Exmods on Discord."); + alreadyWarned = true; + }; +#endif GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has started up"); } diff --git a/README.md b/README.md index a2e8498..e746a23 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # GamecraftRPC 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'. +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. ## Dev environment Setup @@ -19,6 +19,9 @@ For any mod to work, you will have to patch your game with [GCIPA](https://git.e This project also requires the [GamecraftModdingAPI](https://git.exmods.org/modtainers/GamecraftModdingAPI) library to be installed (in `ref/Plugins/GamecraftModdingAPI.dll`). [Direct link to install guide](https://www.exmods.org/guides/install.html). +For rich presence functionality, files in lib/x86_64 of Discord's [GameSDK](https://discord.com/developers/docs/game-sdk/sdk-starter-guide) must be copied to ref/Gamecraft_Data/Plugins. +The GameSDK csharp folder is already included in the git repo. + ## Building After you've completed the setup, open the solution file `GamecraftRPC.sln` in your prefered C# .NET/Mono development environment.