From f14d2bddf8bfb40fe7e0e9af1708cc836144abf0 Mon Sep 17 00:00:00 2001 From: Taoshi Date: Fri, 2 Feb 2024 18:36:23 +0100 Subject: [PATCH] Clean up some mess done by aefrogdog --- LeewayCalculator.cs | 619 ++++++++++++++++++++++---------------------- 1 file changed, 312 insertions(+), 307 deletions(-) diff --git a/LeewayCalculator.cs b/LeewayCalculator.cs index 36d2a7e..346e7e6 100644 --- a/LeewayCalculator.cs +++ b/LeewayCalculator.cs @@ -18,34 +18,27 @@ public static partial class Program { public class LeewayCalculator { - private const float DT = 1.5f; - private const float HT = 0.75f; - private const int HR = 16; - private const int EZ = 2; - private const int CIRCLE = 0; - private const int SLIDER = 1; - private const int SPINNER = 3; - private WebClient wc = new WebClient(); + private WebClient _webClient = new WebClient(); public float CalcRotations(int length, float adjustTime) { float num1 = 0.0f; - float num2 = (float)(8E-05 + (double)System.Math.Max(0.0f, 5000f - (float)length) / 1000.0 / 2000.0) / adjustTime; + float num2 = (float)(8E-05 + (double)Math.Max(0.0f, 5000f - length) / 1000.0 / 2000.0) / adjustTime; float val1 = 0.0f; - int num3 = (int)((double)length - System.Math.Floor(50.0 / 3.0 * (double)adjustTime)); + int num3 = (int)(length - Math.Floor(50.0 / 3.0 * (double)adjustTime)); for (int index = 0; index < num3; ++index) { val1 += num2; - num1 += (float)(System.Math.Min((double)val1, 0.05) / System.Math.PI); + num1 += (float)(Math.Min((double)val1, 0.05) / Math.PI); } return num1; } public double CalcLeeway(int length, float adjustTime, double od, int difficultyModifier) { - int num = this.CalcRotReq(length, od, difficultyModifier); - float d = this.CalcRotations(length, adjustTime); - return num % 2 != 0 && System.Math.Floor((double)d) % 2.0 != 0.0 ? (double)d - System.Math.Floor((double)d) + 1.0 : (double)d - System.Math.Floor((double)d); + int num = CalcRotReq(length, od, difficultyModifier); + float d = CalcRotations(length, adjustTime); + return num % 2 != 0 && Math.Floor((double)d) % 2.0 != 0.0 ? (double)d - Math.Floor((double)d) + 1.0 : (double)d - Math.Floor((double)d); } public int CalcRotReq(int length, double od, int difficultyModifier) @@ -56,29 +49,29 @@ public int CalcRotReq(int length, double od, int difficultyModifier) od /= 2.0; break; case 16: - od = System.Math.Min(10.0, od * 1.4); + od = Math.Min(10.0, od * 1.4); break; } double num = od <= 5.0 ? 3.0 + 0.4 * od : 2.5 + 0.5 * od; - return (int)((double)length / 1000.0 * num); + return (int)(length / 1000.0 * num); } public string CalcAmount(int rotations, int rotReq) { - double num = (double)System.Math.Max(0, rotations - (rotReq + 3)); + double num = Math.Max(0, rotations - (rotReq + 3)); if (rotReq % 2 != 0) - return System.Math.Floor(num / 2.0).ToString() + "k (F)"; - return num % 2.0 == 0.0 ? (num / 2.0).ToString() + "k (T)" : System.Math.Floor(num / 2.0).ToString() + "k+100 (T)"; + return Math.Floor(num / 2.0).ToString() + "k (F)"; + return num % 2.0 == 0.0 ? (num / 2.0).ToString() + "k (T)" : Math.Floor(num / 2.0).ToString() + "k+100 (T)"; } public int CalcSpinBonus(int length, double od, float adjustTime, int difficultyModifier) { - int num1 = (int)this.CalcRotations(length, adjustTime); - int num2 = this.CalcRotReq(length, od, difficultyModifier); - return (num2 % 2 != 0 ? (num2 + 3) / 2 * 100 : (int)System.Math.Floor((double)num1 / 2.0) * 100) + (int)System.Math.Floor((double)(num1 - (num2 + 3)) / 2.0) * 1100; + int num1 = (int)CalcRotations(length, adjustTime); + int num2 = CalcRotReq(length, od, difficultyModifier); + return (num2 % 2 != 0 ? (num2 + 3) / 2 * 100 : (int)Math.Floor(num1 / 2.0) * 100) + (int)Math.Floor((num1 - (num2 + 3)) / 2.0) * 1100; } - public string GetBeatmap(int id) => this.wc.DownloadString("https://old.ppy.sh/osu/" + (object)id); + public string GetBeatmap(int id) => _webClient.DownloadString("https://old.ppy.sh/osu/" + id); public List GetBeatmapHitObjects(string beatmap) { @@ -96,15 +89,15 @@ public List GetBeatmapHitObjects(string beatmap) return beatmapHitObjects; } - public float GetHP(string beatmap) => float.Parse(Regex.Match(beatmap, "HPDrainRate:(.*?)\n").Groups[1].Value, (IFormatProvider)CultureInfo.InvariantCulture); + public float GetHP(string beatmap) => float.Parse(Regex.Match(beatmap, "HPDrainRate:(.*?)\n").Groups[1].Value, CultureInfo.InvariantCulture); - public float GetCS(string beatmap) => float.Parse(Regex.Match(beatmap, "CircleSize:(.*?)\n").Groups[1].Value, (IFormatProvider)CultureInfo.InvariantCulture); + public float GetCS(string beatmap) => float.Parse(Regex.Match(beatmap, "CircleSize:(.*?)\n").Groups[1].Value, CultureInfo.InvariantCulture); - public float GetOD(string beatmap) => float.Parse(Regex.Match(beatmap, "OverallDifficulty:(.*?)\n").Groups[1].Value, (IFormatProvider)CultureInfo.InvariantCulture); + public float GetOD(string beatmap) => float.Parse(Regex.Match(beatmap, "OverallDifficulty:(.*?)\n").Groups[1].Value, CultureInfo.InvariantCulture); - public double GetSliderMult(string beatmap) => double.Parse(Regex.Match(beatmap, "SliderMultiplier:(.*?)\n").Groups[1].Value, (IFormatProvider)CultureInfo.InvariantCulture); + public double GetSliderMult(string beatmap) => double.Parse(Regex.Match(beatmap, "SliderMultiplier:(.*?)\n").Groups[1].Value, CultureInfo.InvariantCulture); - public double GetSliderTRate(string beatmap) => double.Parse(Regex.Match(beatmap, "SliderTickRate:(.*?)\n").Groups[1].Value, (IFormatProvider)CultureInfo.InvariantCulture); + public double GetSliderTRate(string beatmap) => double.Parse(Regex.Match(beatmap, "SliderTickRate:(.*?)\n").Groups[1].Value, CultureInfo.InvariantCulture); public string GetTitle(string beatmap) => Regex.Match(beatmap, "Title:(.*?)\n").Groups[1].Value.Trim(); @@ -145,27 +138,27 @@ public int GetDifficultyModifier(string[] mods) public List GetSpinners(string beatmap) { - List beatmapHitObjects = this.GetBeatmapHitObjects(beatmap); - List timingPoints = this.GetTimingPoints(beatmap); - int beatmapVersion = this.GetBeatmapVersion(beatmap); - double sliderMult = this.GetSliderMult(beatmap); - double sliderTrate = this.GetSliderTRate(beatmap); + List beatmapHitObjects = GetBeatmapHitObjects(beatmap); + List timingPoints = GetTimingPoints(beatmap); + int beatmapVersion = GetBeatmapVersion(beatmap); + double sliderMult = GetSliderMult(beatmap); + double sliderTrate = GetSliderTRate(beatmap); List spinners = new List(); int num = 0; foreach (string str in beatmapHitObjects) { char[] chArray = new char[1] { ',' }; string[] strArray = str.Split(chArray); - switch (this.GetObjectType(int.Parse(strArray[3]))) + switch (GetObjectType(int.Parse(strArray[3]))) { case 0: ++num; break; case 1: - double length = double.Parse(strArray[7], (IFormatProvider)CultureInfo.InvariantCulture); + double length = double.Parse(strArray[7], CultureInfo.InvariantCulture); int slides = int.Parse(strArray[6]); - double[] beatLengthAt = this.GetBeatLengthAt(int.Parse(strArray[2]), timingPoints); - int tickCount = this.CalculateTickCount(length, slides, sliderMult, sliderTrate, beatLengthAt[0], beatLengthAt[1], beatmapVersion); + double[] beatLengthAt = GetBeatLengthAt(int.Parse(strArray[2]), timingPoints); + int tickCount = CalculateTickCount(length, slides, sliderMult, sliderTrate, beatLengthAt[0], beatLengthAt[1], beatmapVersion); num += tickCount + slides + 1; break; case 3: @@ -209,55 +202,55 @@ public string BestModCombination(string beatmap) bestMods = GetModsString(mods); } } - return $"{string.Format("{0:n0}", (object)highestScore)} ({ReorderMods(bestMods)})"; + return $"{string.Format("{0:n0}", highestScore)} ({ReorderMods(bestMods)})"; } public int CalculateMaxScore(string beatmap, string[] mods) { - double hp = (double)this.GetHP(beatmap); - double cs = (double)this.GetCS(beatmap); - double od = (double)this.GetOD(beatmap); - int beatmapVersion = this.GetBeatmapVersion(beatmap); - float adjustTime = this.GetAdjustTime(mods); - int difficultyModifier = this.GetDifficultyModifier(mods); - double sliderMult = this.GetSliderMult(beatmap); - double sliderTrate = this.GetSliderTRate(beatmap); - List beatmapHitObjects = this.GetBeatmapHitObjects(beatmap); + double hp = (double)GetHP(beatmap); + double cs = (double)GetCS(beatmap); + double od = (double)GetOD(beatmap); + int beatmapVersion = GetBeatmapVersion(beatmap); + float adjustTime = GetAdjustTime(mods); + int difficultyModifier = GetDifficultyModifier(mods); + double sliderMult = GetSliderMult(beatmap); + double sliderTrate = GetSliderTRate(beatmap); + List beatmapHitObjects = GetBeatmapHitObjects(beatmap); int startTime = int.Parse(beatmapHitObjects[0].Split(',')[2]); int endTime = int.Parse(beatmapHitObjects[beatmapHitObjects.Count - 1].Split(',')[2]); - List timingPoints = this.GetTimingPoints(beatmap); + List timingPoints = GetTimingPoints(beatmap); int num1 = 0; int num2 = 0; int num3 = 0; - int num4 = this.CalculateDrainTime(beatmap, startTime, endTime) / 1000; - double num5 = (double)(int)System.Math.Round((hp + od + cs + (double)this.Clamp((float)((double)beatmapHitObjects.Count / (double)num4 * 8.0), 0.0f, 16f)) / 38.0 * 5.0) * this.CalculateModMultiplier(mods); + int num4 = CalculateDrainTime(beatmap, startTime, endTime) / 1000; + double num5 = (int)Math.Round((hp + od + cs + (double)Clamp((float)(beatmapHitObjects.Count / (double)num4 * 8.0), 0.0f, 16f)) / 38.0 * 5.0) * CalculateModMultiplier(mods); int num6 = 0; foreach (string str in beatmapHitObjects) { char[] chArray = new char[1] { ',' }; string[] strArray = str.Split(chArray); - int objectType = this.GetObjectType(int.Parse(strArray[3])); + int objectType = GetObjectType(int.Parse(strArray[3])); if (objectType == 0) { ++num6; - num1 += 300 + (int)((double)System.Math.Max(0, num2 - 1) * (12.0 * num5)); + num1 += 300 + (int)(Math.Max(0, num2 - 1) * (12.0 * num5)); ++num2; } if (objectType == 1) { - double length = double.Parse(strArray[7], (IFormatProvider)CultureInfo.InvariantCulture); + double length = double.Parse(strArray[7], CultureInfo.InvariantCulture); int slides = int.Parse(strArray[6]); - double[] beatLengthAt = this.GetBeatLengthAt(int.Parse(strArray[2]), timingPoints); - int tickCount = this.CalculateTickCount(length, slides, sliderMult, sliderTrate, beatLengthAt[0], beatLengthAt[1], beatmapVersion); + double[] beatLengthAt = GetBeatLengthAt(int.Parse(strArray[2]), timingPoints); + int tickCount = CalculateTickCount(length, slides, sliderMult, sliderTrate, beatLengthAt[0], beatLengthAt[1], beatmapVersion); num3 += tickCount * 10 + (slides + 1) * 30; num2 += tickCount + slides + 1; - num1 += 300 + (int)((double)System.Math.Max(0, num2 - 1) * (12.0 * num5)); + num1 += 300 + (int)(Math.Max(0, num2 - 1) * (12.0 * num5)); } else if (objectType == 3) { - num1 += 300 + (int)((double)System.Math.Max(0, num2 - 1) * (12.0 * num5)); + num1 += 300 + (int)(Math.Max(0, num2 - 1) * (12.0 * num5)); int length = int.Parse(strArray[5]) - int.Parse(strArray[2]); - num3 += this.CalcSpinBonus(length, od, adjustTime, difficultyModifier); + num3 += CalcSpinBonus(length, od, adjustTime, difficultyModifier); ++num2; } } @@ -273,10 +266,10 @@ public int CalculateTickCount( double sliderVMult, int beatmapVersion) { - double num1 = this.Clamp(System.Math.Abs(sliderVMult), 10.0, 1000.0) * length * beatLength / (sliderMult * 10000.0); + double num1 = Clamp(Math.Abs(sliderVMult), 10.0, 1000.0) * length * beatLength / (sliderMult * 10000.0); double num2 = beatLength / sliderTRate; if (beatmapVersion < 8) - num2 *= this.Clamp(System.Math.Abs(sliderVMult), 10.0, 1000.0) / 100.0; + num2 *= Clamp(Math.Abs(sliderVMult), 10.0, 1000.0) / 100.0; double num3 = num1 - num2; int num4 = 0; for (; num3 >= 10.0; num3 -= num2) @@ -322,8 +315,8 @@ public List GetTimingPoints(string beatmap) string[] strArray2 = strArray1[index2].Split(','); if (strArray2.Length > 1) { - double num1 = double.Parse(strArray2[0], (IFormatProvider)CultureInfo.InvariantCulture); - double num2 = double.Parse(strArray2[1], (IFormatProvider)CultureInfo.InvariantCulture); + double num1 = double.Parse(strArray2[0], CultureInfo.InvariantCulture); + double num2 = double.Parse(strArray2[1], CultureInfo.InvariantCulture); timingPoints.Add(new double[2] { num1, num2 }); } else @@ -355,7 +348,7 @@ public double[] GetBeatLengthAt(int time, List timingPoints) double num2 = -100.0; for (int index = 0; index < timingPoints.Count; ++index) { - if ((double)time >= timingPoints[index][0]) + if (time >= timingPoints[index][0]) { if (timingPoints[index][1] > 0.0) { @@ -404,135 +397,127 @@ public string[] GetMods(string mods) public bool IsValidModCombo(string[] mods) { - if (mods == null) + if (mods == null || mods.Length < 1) return false; - int num; - if (!mods.Equals((object)new string[4] - { - "HD", - "DT", - "HR", - "FL" - })) - num = mods.Equals((object)new string[4] - { - "HD", - "NC", - "HR", - "FL" - }) ? 1 : 0; - else - num = 1; - if (num != 0) + + // Check for specific valid combinations + if (mods.SequenceEqual(new[] { "HD", "DT", "HR", "FL" }) || mods.SequenceEqual(new[] { "HD", "NC", "HR", "FL" })) return true; - for (int index1 = 0; index1 < mods.Length; ++index1) + + // Check individual mods and their combinations + for (int i = 0; i < mods.Length; ++i) { - if (!this.IsValidMod(mods[index1]) || mods[index1].Equals("NM") && mods.Length > 2) + if (!IsValidMod(mods[i]) || (mods[i] == "NM" && mods.Length > 2)) return false; - if (index1 + 1 < mods.Length) + + for (int j = i + 1; j < mods.Length; ++j) { - if (mods[index1].Equals("DT")) - { - for (int index2 = index1 + 1; index2 < mods.Length; ++index2) - { - if (mods[index2].Equals("NC") || mods[index2].Equals("HT")) - return false; - } - } - else if (mods[index1].Equals("NC")) - { - for (int index3 = index1 + 1; index3 < mods.Length; ++index3) - { - if (mods[index3].Equals("DT") || mods[index3].Equals("HT")) - return false; - } - } - else if (mods[index1].Equals("HT")) - { - for (int index4 = index1 + 1; index4 < mods.Length; ++index4) - { - if (mods[index4].Equals("DT") || mods[index4].Equals("NC")) - return false; - } - } - else if (mods[index1].Equals("HR")) - { - for (int index5 = index1 + 1; index5 < mods.Length; ++index5) - { - if (mods[index5].Equals("EZ")) - return false; - } - } - else if (mods[index1].Equals("EZ")) - { - for (int index6 = index1 + 1; index6 < mods.Length; ++index6) - { - if (mods[index6].Equals("HR")) - return false; - } - } + if (!IsValidCombination(mods[i], mods[j])) + return false; } } + return true; } - public bool IsValidMod(string mod) => mod.Equals("EZ") || mod.Equals("HT") || mod.Equals("HD") || mod.Equals("HR") || mod.Equals("DT") || mod.Equals("NC") || mod.Equals("FL") || mod.Equals("NM"); + private bool IsValidCombination(string mod1, string mod2) + { + switch (mod1) + { + case "DT": + return !((mod2 == "NC") || (mod2 == "HT")); + case "NC": + return !((mod2 == "DT") || (mod2 == "HT")); + case "HT": + return !((mod2 == "DT") || (mod2 == "NC")); + case "HR": + return !(mod2 == "EZ"); + case "EZ": + return !(mod2 == "HR"); + default: + return true; + } + } + + private bool IsValidMod(string mod) + { + return mod == "HD" || mod == "DT" || mod == "HR" || mod == "FL" || mod == "NC" || mod == "HT" || mod == "EZ"; + } public string RemoveUselessMods(string mods) { if (mods.Equals("None") || mods.Equals("SD") || mods.Equals("PF") || mods.Equals("TD") || mods.Equals("SO")) + { return "NM"; + } + if (mods.Length == 2) + { return mods; - string str1 = ""; - string str2 = mods; - char[] chArray = new char[1] { ',' }; - foreach (string str3 in str2.Split(chArray)) + } + + string usefulMods = ""; + string[] modArray = mods.Split(','); + + foreach (string mod in modArray) { - if (str3.Equals("HD") || str3.Equals("DT") || str3.Equals("NC") || str3.Equals("HR") || str3.Equals("FL") || str3.Equals("EZ") || str3.Equals("HT")) - str1 += str3; + if (mod.Equals("HD") || mod.Equals("DT") || mod.Equals("NC") || mod.Equals("HR") || mod.Equals("FL") || mod.Equals("EZ") || mod.Equals("HT")) + { + usefulMods += mod; + } } - return string.IsNullOrEmpty(str1) ? "NM" : str1; + + return string.IsNullOrEmpty(usefulMods) ? "NM" : usefulMods; } public string ReorderMods(string mods) { if (mods.Length <= 2) return mods; - string str = ""; - for (int startIndex = 0; startIndex < mods.Length - 1; startIndex += 2) + + string reorderedMods = ""; + + // Check for HD + for (int i = 0; i < mods.Length - 1; i += 2) { - if (mods.Substring(startIndex, 2).Equals("HD")) + if (mods.Substring(i, 2).Equals("HD")) { - str += mods.Substring(startIndex, 2); + reorderedMods += mods.Substring(i, 2); break; } } - for (int startIndex = 0; startIndex < mods.Length - 1; startIndex += 2) + + // Check for DT, NC, HT + for (int i = 0; i < mods.Length - 1; i += 2) { - if (mods.Substring(startIndex, 2).Equals("DT") || mods.Substring(startIndex, 2).Equals("NC") || mods.Substring(startIndex, 2).Equals("HT")) + if (mods.Substring(i, 2).Equals("DT") || mods.Substring(i, 2).Equals("NC") || mods.Substring(i, 2).Equals("HT")) { - str += mods.Substring(startIndex, 2); + reorderedMods += mods.Substring(i, 2); break; } } - for (int startIndex = 0; startIndex < mods.Length - 1; startIndex += 2) + + // Check for HR, EZ + for (int i = 0; i < mods.Length - 1; i += 2) { - if (mods.Substring(startIndex, 2).Equals("HR") || mods.Substring(startIndex, 2).Equals("EZ")) + if (mods.Substring(i, 2).Equals("HR") || mods.Substring(i, 2).Equals("EZ")) { - str += mods.Substring(startIndex, 2); + reorderedMods += mods.Substring(i, 2); break; } } - for (int startIndex = 0; startIndex < mods.Length - 1; startIndex += 2) + + // Check for FL + for (int i = 0; i < mods.Length - 1; i += 2) { - if (mods.Substring(startIndex, 2).Equals("FL")) + if (mods.Substring(i, 2).Equals("FL")) { - str += mods.Substring(startIndex, 2); + reorderedMods += mods.Substring(i, 2); break; } } - return str; + + return reorderedMods; } public bool HasLeaderboard(string beatmapPage) => !string.IsNullOrEmpty(beatmapPage) && Regex.IsMatch(beatmapPage, "(.*?)"); @@ -540,37 +525,44 @@ public string ReorderMods(string mods) public double CalculateModMultiplier(string[] mods) { double modMultiplier = 1.0; + foreach (string mod in mods) { - if (mod.Equals("NF") || mod.Equals("EZ")) - { - modMultiplier *= 0.5; - } - else + switch (mod) { - int num; - switch (mod) - { - case "HT": - modMultiplier *= 0.3; - continue; - case "HD": - num = 1; - break; - default: - num = mod.Equals("HR") ? 1 : 0; - break; - } - if (num != 0) + case "NF": + case "EZ": + modMultiplier *= 0.5; + break; + + case "HT": + modMultiplier *= 0.3; + break; + + case "HD": + modMultiplier *= 1.06; + break; + + case "HR": modMultiplier *= 1.06; - else if (mod.Equals("DT") || mod.Equals("NC") || mod.Equals("FL")) + break; + + case "DT": + case "NC": + case "FL": modMultiplier *= 1.12; - else if (mod.Equals("SO")) + break; + + case "SO": modMultiplier *= 0.9; - else + break; + + default: modMultiplier *= 0.0; + break; } } + return modMultiplier; } @@ -581,9 +573,9 @@ public double CalculateModMultiplier(string[] mods) int index = 0; foreach (Match match in matchCollection) { - top50[index, 0] = match.Groups[2].Value.Replace(",", (string)null); + top50[index, 0] = match.Groups[2].Value.Replace(",", null); top50[index, 1] = match.Groups[3].Value; - top50[index, 2] = this.ReorderMods(this.RemoveUselessMods(match.Groups[4].Value)); + top50[index, 2] = ReorderMods(RemoveUselessMods(match.Groups[4].Value)); top50[index, 3] = match.Groups[1].Value; ++index; } @@ -594,7 +586,7 @@ public int GetBestScoreIndex(string[,] scores, string[] mods) { for (int bestScoreIndex = 0; bestScoreIndex < scores.GetLength(0); ++bestScoreIndex) { - if (this.IsSameMods(mods, this.GetMods(scores[bestScoreIndex, 2]))) + if (IsSameMods(mods, GetMods(scores[bestScoreIndex, 2]))) return bestScoreIndex; } return -1; @@ -608,16 +600,16 @@ public bool IsSameMods(string[] mods1, string[] mods2) { if (mods1[index].Equals("DT") || mods1[index].Equals("NC")) { - if (!((IEnumerable)mods2).Contains("DT") && !((IEnumerable)mods2).Contains("NC")) + if (!mods2.Contains("DT") && !mods2.Contains("NC")) return false; } - else if (!((IEnumerable)mods2).Contains(mods1[index])) + else if (!mods2.Contains(mods1[index])) return false; } return true; } - public string GetBeatmapPage(int mapID) => this.wc.DownloadString("https://old.ppy.sh/b/" + (object)mapID); + public string GetBeatmapPage(int mapID) => _webClient.DownloadString("https://old.ppy.sh/b/" + mapID); public string GetNumberOneOnBeatmapPage(string beatmapPage) { @@ -644,198 +636,211 @@ public string GetNumberOneOnBeatmapPage(string beatmapPage) public string[] CalculateBeatmapMaxScore(string beatmap) { - int maxScore = this.CalculateMaxScore(beatmap, this.GetMods("HDNCHRFL")); - string str = "HDNCHRFL"; - if (this.CalculateMaxScore(beatmap, this.GetMods("HDNCFL")) > maxScore) + string[] modCombinations = new string[] + { + "HDNCHRFL", "HDNCFL", "HDHRFL", "HDFL", "EZHDNCFL", + "EZHDFL", "EZHDHTFL", "HDHTFL", "HDHTHRFL" + }; + + int maxScore = 0; + string maxScoreMods = ""; + + foreach (string mods in modCombinations) { - maxScore = this.CalculateMaxScore(beatmap, this.GetMods("HDNCFL")); - str = "HDNCFL"; + int currentScore = CalculateMaxScore(beatmap, GetMods(mods)); + + if (currentScore > maxScore) + { + maxScore = currentScore; + maxScoreMods = mods; + } } - if (this.CalculateMaxScore(beatmap, this.GetMods("HDHRFL")) > maxScore) + + return new string[] { maxScore.ToString(), maxScoreMods }; + } + private void PrintLeaderboardInfo(int num3, int maxScore, bool youAreNumberOne, string str, string numberOne, double num4) + { + if (num3 == maxScore) { - maxScore = this.CalculateMaxScore(beatmap, this.GetMods("HDHRFL")); - str = "HDHRFL"; + PrintCappedInfo(youAreNumberOne, str, numberOne); } - if (this.CalculateMaxScore(beatmap, this.GetMods("HDFL")) > maxScore) + else if (num3 < maxScore) { - maxScore = this.CalculateMaxScore(beatmap, this.GetMods("HDFL")); - str = "HDFL"; + PrintNotCappedInfo(youAreNumberOne, str, numberOne, maxScore - num3); } - if (this.CalculateMaxScore(beatmap, this.GetMods("EZHDNCFL")) > maxScore) + else { - maxScore = this.CalculateMaxScore(beatmap, this.GetMods("EZHDNCFL")); - str = "EZHDNCFL"; + PrintOverCapInfo(youAreNumberOne, num3, maxScore, str, numberOne, num3 - maxScore, num4); } - if (this.CalculateMaxScore(beatmap, this.GetMods("EZHDFL")) > maxScore) + } + + private void PrintCappedInfo(bool youAreNumberOne, string str, string numberOne) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Write(" Capped"); + Console.ForegroundColor = ConsoleColor.Gray; + + if (youAreNumberOne) + { + Console.Write($": ( {str} ) #1: {numberOne} "); + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("(That's you!)\n"); + Console.ForegroundColor = ConsoleColor.Gray; + } + else + { + Console.WriteLine($": ({str}) #1: {numberOne}"); + } + } + + private void PrintNotCappedInfo(bool youAreNumberOne, string str, string numberOne, int scoreDifference) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.Write(" Not Capped"); + Console.ForegroundColor = ConsoleColor.Gray; + + if (youAreNumberOne) + { + Console.Write($": +{string.Format("{0:n0}", scoreDifference)} ({str}) #1: {numberOne} "); + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("(That's you!)\n"); + Console.ForegroundColor = ConsoleColor.Gray; + } + else + { + Console.WriteLine($": +{string.Format("{0:n0}", scoreDifference)} ({str}) #1: {numberOne}"); + } + } + + private void PrintOverCapInfo(bool youAreNumberOne, int num3, int maxScore, string str, string numberOne, int scoreDifference, double num4) + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.Write(" Over Cap"); + Console.ForegroundColor = ConsoleColor.Gray; + + Console.Write($": +{string.Format("{0:n0}", scoreDifference)} ({str}) #1: {numberOne} "); + + if (youAreNumberOne) { - maxScore = this.CalculateMaxScore(beatmap, this.GetMods("EZHDFL")); - str = "EZHDFL"; + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("(That's you!)\n"); + Console.ForegroundColor = ConsoleColor.Gray; } - if (this.CalculateMaxScore(beatmap, this.GetMods("EZHDHTFL")) > maxScore) + + if (num3 % 100 == maxScore % 100) { - maxScore = this.CalculateMaxScore(beatmap, this.GetMods("EZHDHTFL")); - str = "EZHDHTFL"; + PrintReworkInfo(num4); } - if (this.CalculateMaxScore(beatmap, this.GetMods("HDHTFL")) > maxScore) + + Console.WriteLine(); + } + + private void PrintReworkInfo(double num4) + { + if (num4 < 2801770131.0) { - maxScore = this.CalculateMaxScore(beatmap, this.GetMods("HDHTFL")); - str = "HDHTFL"; + Console.ForegroundColor = ConsoleColor.Green; + Console.Write(" Pre-Spin Rework"); + Console.ForegroundColor = ConsoleColor.Gray; } - if (this.CalculateMaxScore(beatmap, this.GetMods("HDHTHRFL")) > maxScore) + else { - maxScore = this.CalculateMaxScore(beatmap, this.GetMods("HDHTHRFL")); - str = "HDHTHRFL"; + Console.ForegroundColor = ConsoleColor.Red; + Console.Write(" Post-Spin Rework"); + Console.ForegroundColor = ConsoleColor.Gray; } - return new string[2] { maxScore.ToString(), str }; } public void PrintTable(int beatmapID, string beatmap, string[] mods, bool leaderboardLookups) { - string beatmapPage = (string)null; + string beatmapPage = null; if (beatmapID > 0 && leaderboardLookups) - beatmapPage = this.GetBeatmapPage(beatmapID); + beatmapPage = GetBeatmapPage(beatmapID); bool flag = false; int maxScore; if (mods == null) { - string[] beatmapMaxScore = this.CalculateBeatmapMaxScore(beatmap); + string[] beatmapMaxScore = CalculateBeatmapMaxScore(beatmap); maxScore = int.Parse(beatmapMaxScore[0]); - mods = this.GetMods(beatmapMaxScore[1]); - if (!this.IsSameMods(mods, this.GetMods("HDNCHRFL"))) + mods = GetMods(beatmapMaxScore[1]); + if (!IsSameMods(mods, GetMods("HDNCHRFL"))) flag = true; } else - maxScore = this.CalculateMaxScore(beatmap, mods); - this.GetModsString(mods); - List spinners = this.GetSpinners(beatmap); - float adjustTime = this.GetAdjustTime(mods); - float od = this.GetOD(beatmap); - int difficultyModifier = this.GetDifficultyModifier(mods); + maxScore = CalculateMaxScore(beatmap, mods); + GetModsString(mods); + List spinners = GetSpinners(beatmap); + float adjustTime = GetAdjustTime(mods); + float od = GetOD(beatmap); + int difficultyModifier = GetDifficultyModifier(mods); ConsoleTable consoleTable = new ConsoleTable(new string[6] { - "#", - "Length", - "Combo", - "Amount (+100)", - "Rotations", - "Leeway" + "#", + "Length", + "Combo", + "Amount (+100)", + "Rotations", + "Leeway" }); for (int index = 0; index < spinners.Count; ++index) { int length = spinners[index][1]; int num1 = spinners[index][0]; - float rotations = this.CalcRotations(length, adjustTime); - int rotReq = this.CalcRotReq(length, (double)od, difficultyModifier); - string str = this.CalcAmount((int)rotations, rotReq); - double num2 = this.CalcLeeway(length, adjustTime, (double)od, difficultyModifier); - consoleTable.AddRow((object)(index + 1), (object)length, (object)num1, (object)str, (object)string.Format("{0:0.00000}", (object)rotations), (object)string.Format("{0:0.00000}", (object)num2)); - } - Console.WriteLine(" " + this.GetArtist(beatmap) + " - " + this.GetTitle(beatmap) + " (" + this.GetDifficultyName(beatmap) + ")"); - Console.Write(" Max Score: " + string.Format("{0:n0}", (object)maxScore) + " ("); + float rotations = CalcRotations(length, adjustTime); + int rotReq = CalcRotReq(length, (double)od, difficultyModifier); + string str = CalcAmount((int)rotations, rotReq); + double num2 = CalcLeeway(length, adjustTime, (double)od, difficultyModifier); + consoleTable.AddRow(index + 1, length, num1, str, string.Format("{0:0.00000}", rotations), string.Format("{0:0.00000}", num2)); + } + Console.WriteLine($" {GetArtist(beatmap)} - {GetTitle(beatmap)} ({GetDifficultyName(beatmap)})"); + Console.Write($" Max Score: {string.Format("{0:n0}", maxScore)} ("); if (flag) { Console.ForegroundColor = ConsoleColor.Magenta; - Console.Write(this.GetModsString(mods)); + Console.Write(GetModsString(mods)); Console.ForegroundColor = ConsoleColor.Gray; } else - Console.Write(this.GetModsString(mods)); + Console.Write(GetModsString(mods)); Console.WriteLine(")"); Console.WriteLine($" Best Mods: {BestModCombination(beatmap)}"); - if (this.HasLeaderboard(beatmapPage) && leaderboardLookups) + if (HasLeaderboard(beatmapPage) && leaderboardLookups) { string numberOne = GetNumberOneOnBeatmapPage(beatmapPage); - bool youAreNumberOne = numberOne == username; - int num3 = -1; - string str = (string)null; - double num4 = 2801770131.0; + bool youAreNumberOne = numberOne == _userName; + int firstPlaceScore = -1; + string modsFromTop50 = null; + double beatmapUnixTimestamp = 2801770131.0; + if (flag) { - string[,] top50 = this.GetTop50(beatmapPage); - num3 = int.Parse(top50[0, 0]); - str = top50[0, 2]; - num4 = double.Parse(top50[0, 3], (IFormatProvider)CultureInfo.InvariantCulture); + string[,] top50 = GetTop50(beatmapPage); + firstPlaceScore = int.Parse(top50[0, 0]); + modsFromTop50 = top50[0, 2]; + beatmapUnixTimestamp = double.Parse(top50[0, 3], CultureInfo.InvariantCulture); } else { - string[,] top50 = this.GetTop50(beatmapPage); - int bestScoreIndex = this.GetBestScoreIndex(top50, mods); + string[,] top50 = GetTop50(beatmapPage); + int bestScoreIndex = GetBestScoreIndex(top50, mods); + if (bestScoreIndex >= 0) { - num3 = int.Parse(top50[bestScoreIndex, 0]); - str = top50[bestScoreIndex, 2]; - num4 = double.Parse(top50[bestScoreIndex, 3], (IFormatProvider)CultureInfo.InvariantCulture); + firstPlaceScore = int.Parse(top50[bestScoreIndex, 0]); + modsFromTop50 = top50[bestScoreIndex, 2]; + beatmapUnixTimestamp = double.Parse(top50[bestScoreIndex, 3], CultureInfo.InvariantCulture); } } - if (num3 >= 0) + + if (firstPlaceScore >= 0) { - if (num3 == maxScore) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Write(" Capped"); - Console.ForegroundColor = ConsoleColor.Gray; - if (youAreNumberOne) - { - Console.Write($": ( {str} ) #1: {numberOne} "); - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("(That's you!)\n"); - Console.ForegroundColor = ConsoleColor.Gray; - } - else - { - Console.WriteLine(": (" + str + ") #1: " + numberOne); - } - } - else if (num3 < maxScore) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.Write(" Not Capped"); - Console.ForegroundColor = ConsoleColor.Gray; - if (youAreNumberOne) - { - Console.Write($": + {string.Format("{0:n0}", (object)(maxScore - num3))} ({str}) #1: {numberOne} "); - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("(That's you!)\n"); - Console.ForegroundColor = ConsoleColor.Gray; - } - else - { - Console.WriteLine(": +" + string.Format("{0:n0}", (object)(maxScore - num3)) + " (" + str + ") #1: " + numberOne); - } - } - else - { - Console.ForegroundColor = ConsoleColor.Yellow; - Console.Write(" Over Cap"); - Console.ForegroundColor = ConsoleColor.Gray; - Console.Write(": +" + string.Format("{0:n0}", (object)(num3 - maxScore)) + " (" + str + ") #1: " + numberOne + " "); - if (youAreNumberOne) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("(That's you!)\n"); - Console.ForegroundColor = ConsoleColor.Gray; - } - if (num3 % 100 == maxScore % 100) - { - if (num4 < 2801770131.0) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.Write(" Pre-Spin Rework"); - Console.ForegroundColor = ConsoleColor.Gray; - } - else - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Write(" Post-Spin Rework"); - Console.ForegroundColor = ConsoleColor.Gray; - } - } - Console.WriteLine(); - } + PrintLeaderboardInfo(firstPlaceScore, maxScore, youAreNumberOne, modsFromTop50, numberOne, beatmapUnixTimestamp); } } + consoleTable.Options.EnableCount = false; consoleTable.Write(); + } } }