From b294195fcef7defbfb2c921d866eba3976f74d44 Mon Sep 17 00:00:00 2001 From: Will Bennion Date: Sun, 22 Sep 2019 20:12:48 +0100 Subject: [PATCH] Added support for getting osu's game mode state. Also changed mode and status to be enums. --- .../Project-Aurora/Profiles/Node.cs | 28 ++++++++---------- .../Project-Aurora/Profiles/Osu/GSI/Enums.cs | 21 +++++++++++++ .../Profiles/Osu/GSI/GameState_Osu.cs | 7 +++-- .../Profiles/Osu/GSI/OsuSyncAuroraPlugin.dll | Bin 8192 -> 8704 bytes .../Project-Aurora/Project-Aurora.csproj | 1 + 5 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 Project-Aurora/Project-Aurora/Profiles/Osu/GSI/Enums.cs diff --git a/Project-Aurora/Project-Aurora/Profiles/Node.cs b/Project-Aurora/Project-Aurora/Profiles/Node.cs index 627eb5a7a..72dd9fa41 100644 --- a/Project-Aurora/Project-Aurora/Profiles/Node.cs +++ b/Project-Aurora/Project-Aurora/Profiles/Node.cs @@ -69,7 +69,7 @@ internal long GetLong(string Name) return -1; } - internal T GetEnum(string Name) + internal T GetEnum(string Name) where T : struct { Newtonsoft.Json.Linq.JToken value; @@ -77,24 +77,20 @@ internal T GetEnum(string Name) { var type = typeof(T); if (!type.IsEnum) throw new InvalidOperationException(); - foreach (var field in type.GetFields()) - { - var attribute = Attribute.GetCustomAttribute(field, - typeof(DescriptionAttribute)) as DescriptionAttribute; - if (attribute != null) - { - if (attribute.Description.ToLowerInvariant().Equals(value.ToString().ToLowerInvariant())) - return (T)field.GetValue(null); - } - if (field.Name.ToLowerInvariant().Equals(value.ToString().ToLowerInvariant())) - return (T)field.GetValue(null); - } + // Attempt to parse it by name or number + if (Enum.TryParse(value.ToString(), true, out var val)) + return val; - return (T)Enum.Parse(typeof(T), "Undefined", true); + // If that wasn't successful, try by DescriptionAttribute + foreach (var field in type.GetFields()) + if (Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute + && attribute.Description.ToLowerInvariant().Equals(value.ToString().ToLowerInvariant())) + return (T)field.GetValue(null); } - else - return (T)Enum.Parse(typeof(T), "Undefined", true); + + // If there is an "undefined" enum value, return that else just do the default(T). + return Enum.TryParse("Undefined", true, out var u) ? u : default(T); } internal bool GetBool(string Name) diff --git a/Project-Aurora/Project-Aurora/Profiles/Osu/GSI/Enums.cs b/Project-Aurora/Project-Aurora/Profiles/Osu/GSI/Enums.cs new file mode 100644 index 000000000..86edf95d6 --- /dev/null +++ b/Project-Aurora/Project-Aurora/Profiles/Osu/GSI/Enums.cs @@ -0,0 +1,21 @@ +namespace Aurora.Profiles.Osu.GSI { + public enum OsuStatus { + NoFoundProcess = 1, + Unkonwn = 2, + SelectSong = 4, + Playing = 8, + Editing = 16, + Rank = 32, + MatchSetup = 64, + Lobby = 128, + Idle = 256 + } + + public enum OsuPlayMode { + Unknown = -1, + Osu = 0, + Taiko = 1, + CatchTheBeat = 2, + Mania = 3 + } +} diff --git a/Project-Aurora/Project-Aurora/Profiles/Osu/GSI/GameState_Osu.cs b/Project-Aurora/Project-Aurora/Profiles/Osu/GSI/GameState_Osu.cs index a74712227..a79115f24 100644 --- a/Project-Aurora/Project-Aurora/Profiles/Osu/GSI/GameState_Osu.cs +++ b/Project-Aurora/Project-Aurora/Profiles/Osu/GSI/GameState_Osu.cs @@ -26,7 +26,9 @@ internal ProviderNode(string json) : base(json) { public class GameNode : Node { - public string Status; + public OsuStatus StatusEnum; + public string Status => StatusEnum.ToString(); // Only here for legacy reasons - don't wanna break any profiles that may now depend on this + public OsuPlayMode PlayMode; public float HP; public float Accuracy; public int Combo; @@ -39,7 +41,8 @@ public class GameNode : Node { public int CountMiss; internal GameNode(string json) : base(json) { - Status = GetString("status"); + StatusEnum = GetEnum("status"); + PlayMode = GetEnum("playMode"); HP = GetFloat("hp"); Accuracy = GetFloat("accuracy"); Combo = GetInt("combo"); diff --git a/Project-Aurora/Project-Aurora/Profiles/Osu/GSI/OsuSyncAuroraPlugin.dll b/Project-Aurora/Project-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