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-Aurora/Profiles/Osu/GSI/OsuSyncAuroraPlugin.dll index 193cd1e6d..3c2aaaa0f 100644 Binary files a/Project-Aurora/Project-Aurora/Profiles/Osu/GSI/OsuSyncAuroraPlugin.dll and b/Project-Aurora/Project-Aurora/Profiles/Osu/GSI/OsuSyncAuroraPlugin.dll differ diff --git a/Project-Aurora/Project-Aurora/Project-Aurora.csproj b/Project-Aurora/Project-Aurora/Project-Aurora.csproj index 378f87c50..e639d7d7c 100644 --- a/Project-Aurora/Project-Aurora/Project-Aurora.csproj +++ b/Project-Aurora/Project-Aurora/Project-Aurora.csproj @@ -367,6 +367,7 @@ Control_FieldPresenter.xaml + Control_Skype.xaml