This repository has been archived by the owner on Feb 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
196 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
using HarmonyLib; | ||
using System.Reflection; | ||
|
||
namespace QualityOfSpeen | ||
{ | ||
public static class Extensions | ||
{ | ||
public static void PatchAll<T>(this Harmony harmony) => harmony.PatchAll(typeof(T)); | ||
|
||
// Source: https://stackoverflow.com/a/46488844 | ||
public static T GetFieldValue<T>(this object obj, string name) | ||
{ | ||
// Set the flags so that private and public fields from instances will be found | ||
var bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; | ||
var field = obj.GetType().GetField(name, bindingFlags); | ||
return (T)field?.GetValue(obj); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,91 @@ | ||
using HarmonyLib; | ||
using System.Reflection; | ||
using UnityEngine; | ||
|
||
namespace QualityOfSpeen.Features | ||
{ | ||
public class DiscordRPCFix | ||
{ | ||
public static bool UpdateDiscord; | ||
public static bool SecretMode; | ||
public static bool UpdateDiscord = Main.ModConfig.GetValueOrDefaultTo("Discord", "EnableRichPresence", true); | ||
public static bool SecretMode = Main.ModConfig.GetValueOrDefaultTo("Discord", "StartInSecretMode", false); | ||
|
||
private static void Awake() | ||
[HarmonyPatch] | ||
class SpinDiscordPatch | ||
{ | ||
UpdateDiscord = Main.ModConfig.GetValueOrDefaultTo("Discord", "EnableRichPresence", true); | ||
SecretMode = Main.ModConfig.GetValueOrDefaultTo("Discord", "StartInSecretMode", false); | ||
} | ||
|
||
[HarmonyPatch(typeof(SpinDiscord), nameof(SpinDiscord.UpdateActivityPresence))] | ||
[HarmonyPrefix] | ||
private static bool UpdateActivityPresencePrefix(ref string state, ref string details, ref string coverArt, ref string trackArtist, ref string trackTitle, ref string trackLabel, ref long endTime) | ||
{ | ||
if (!UpdateDiscord) return false; | ||
static MethodBase TargetMethod() | ||
{ | ||
var type = AccessTools.TypeByName("SpinDiscord"); | ||
return AccessTools.Method(type, "UpdateActivityPresence"); | ||
} | ||
|
||
if (Main.InGameState == InGameState.Editor) | ||
static bool Prefix(ref string state, ref string details, ref string coverArt, ref string trackArtist, ref string trackTitle, ref string trackLabel, ref long endTime) | ||
{ | ||
if (SecretMode) | ||
//Main.Logger.LogMessage("Activity Update"); | ||
if (!UpdateDiscord) return false; | ||
|
||
|
||
if (Main.InGameState == InGameState.Editor) | ||
{ | ||
details = "Editing <SECRET>"; | ||
state = "Secret Mode enabled!"; | ||
trackArtist = "Secret"; | ||
trackTitle = "Secret"; | ||
trackLabel = "Secret"; | ||
endTime = 0; | ||
if (SecretMode) | ||
{ | ||
details = "Editing <SECRET>"; | ||
state = "Secret Mode enabled!"; | ||
trackArtist = "Secret"; | ||
trackTitle = "Secret"; | ||
trackLabel = "Secret"; | ||
endTime = 0; | ||
} | ||
else | ||
{ | ||
details = "Editing " + trackTitle; | ||
endTime = 0; | ||
} | ||
} | ||
else | ||
|
||
if (Main.IsDead) | ||
{ | ||
details = "Editing " + trackTitle; | ||
state = "Failed"; | ||
endTime = 0; | ||
} | ||
} | ||
|
||
if (Main.IsDead) | ||
{ | ||
state = "Failed"; | ||
endTime = 0; | ||
} | ||
if (Main.InGameState == InGameState.CustomLevelSelectMenu) | ||
{ | ||
state = "Picking Custom Track"; | ||
endTime = 0; | ||
} | ||
|
||
if (Main.InGameState == InGameState.CustomLevelSelectMenu) | ||
{ | ||
state = "Picking Custom Track"; | ||
endTime = 0; | ||
return true; | ||
} | ||
} | ||
|
||
return true; | ||
[HarmonyPatch(typeof(Track), "UpdateRichPresence")] | ||
[HarmonyPrefix] | ||
private static bool TrackUpdateRichPresencePrefix() | ||
{ | ||
return UpdateDiscord; | ||
} | ||
|
||
[HarmonyPatch(typeof(Track), nameof(Track.Update))] | ||
[HarmonyPostfix] | ||
private static void TrackUpdatePostfix() | ||
{ | ||
if (Input.GetKeyDown(KeyCode.F5)) | ||
if (Input.GetKeyDown(KeyCode.F4)) | ||
{ | ||
SecretMode = !SecretMode; | ||
Main.Logger.LogWarning("Secret Mode " + (SecretMode ? "Enabled" : "Disabled")); | ||
NotificationSystemGUI.AddMessage("Secret Mode " + (SecretMode ? "Enabled" : "Disabled")); | ||
} | ||
if (Input.GetKeyDown(KeyCode.F3)) | ||
{ | ||
UpdateDiscord = !UpdateDiscord; | ||
NotificationSystemGUI.AddMessage("Discord Rich Presence Toggled " + (UpdateDiscord ? "On" : "Off")); | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(XDCustomLevelSelectMenu), nameof(XDCustomLevelSelectMenu.Awake))] | ||
[HarmonyPatch(typeof(XDCustomLevelSelectMenu), "Awake")] | ||
[HarmonyPostfix] | ||
private static void XDCustomLevelSelectMenuAwakePostfix() | ||
{ | ||
Main.Logger.LogWarning("Reminder: Secret Mode is currently " + (SecretMode ? "Enabled" : "Disabled")); | ||
NotificationSystemGUI.AddMessage("Reminder: Secret Mode is currently " + (SecretMode ? "Enabled" : "Disabled")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.