public static void InitDiscord() { // Handlers var eventHandlers = default(DiscordRPC.EventHandlers); eventHandlers.readyCallback = ReadyCallback; eventHandlers.disconnectedCallback = DisconnectedCallback; eventHandlers.errorCallback = ErrorCallback; // Initialize DiscordRPC.Initialize("448509316450877458", ref eventHandlers, true, "264710"); // Presence Presence = new DiscordRPC.RichPresence { largeImageKey = "subnautica_main", details = "In Menu", }; // Run the callbacks DiscordRPC.RunCallbacks(); // Set the presence DiscordRPC.UpdatePresence(ref Presence); }
private void UpdatePresence() { DiscordRPC.RunCallbacks(); if (state != PlayerState.Playing) { Main.Presence.details = (state == PlayerState.Menu) ? "In Menu" : "Loading"; Main.Presence.state = ""; Main.Presence.largeImageKey = "subnautica_main"; Main.Presence.smallImageKey = ""; DiscordRPC.UpdatePresence(ref Main.Presence); return; } Main.Presence.largeImageKey = ""; var biome = Utility.GetBiomeDisplayName(Player.main.GetBiomeString()); var stringName = Utility.GetBiomeStringName(biome); Main.Presence.details = "At " + biome; Main.Presence.largeImageKey = stringName; var subRoot = Player.main.GetCurrentSub(); var vehicle = Player.main.GetVehicle(); var depth = Mathf.Round(Player.main.GetDepth()); if (subRoot) { var type = subRoot.GetType().Equals(typeof(BaseRoot)) ? "Base" : "Cyclops"; Main.Presence.state = "In " + type; if (type != "Base") { Main.Presence.smallImageKey = type.ToLower(); } } else if (vehicle) { var type = vehicle.GetType().Equals(typeof(SeaMoth)) ? "Seamoth" : "Prawn"; Main.Presence.state = "In " + type; Main.Presence.smallImageKey = type.ToLower(); } else if (Player.main.IsUnderwaterForSwimming()) { Main.Presence.state = "Swimming"; Main.Presence.smallImageKey = "swimming"; } else if (!Player.main.IsSwimming()) { Main.Presence.state = "On Foot"; Main.Presence.smallImageKey = ""; } if (Main.Presence.state != "") { Main.Presence.state += " (Depth: " + depth + "m)"; } DiscordRPC.UpdatePresence(ref Main.Presence); }