Files
  • main.cs
  • Beatmaps
  • main.exe
  • notes.txt
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using System.IO;

class MainClass {
	public static FileStream stream;
	public static List<string> lines;
	public const string beatmapFileName = "Hige Driver join. SELEN - Dadadadadadadadada (Dinocrit) [SixBeeps's Another].osu";
	public static int hitCircles, sliders, combos, spinners;
	public static int bezier, catmull, linear, passthrough;
  public static void Main (string[] args) {
		lines = new List<string>();
    stream = new FileStream(@"Beatmaps/" + beatmapFileName, FileMode.Open);
		byte[] buffer = new byte[stream.Length];
		stream.Read(buffer, 0, (int)stream.Length);
		lines.Add(string.Empty);
		foreach(byte b in buffer) {
        char c = Convert.ToChar(b);
				if (c != '\n')
						lines[lines.Count - 1] += c;
				else
						lines.Add(string.Empty);
    }
		Dictionary<string,string> formattedOsu = new Dictionary<string,string>();
		OsuJsonToDict(lines, ref formattedOsu);
		List<List<string>> hitObjects = OsuObjectsToList(lines);
		Console.WriteLine("----------------\nGENERAL\n----------------");
		Console.WriteLine("Song: \"" + formattedOsu["Title"] + "\" by " + formattedOsu["Artist"] + " (Mapped by " + formattedOsu["Creator"] + ")");
		Console.Write("This seems to be a");
		switch (formattedOsu["Mode"]) {
			case "0":
				Console.WriteLine("n osu!std map");
				break;
			case "1":
				Console.WriteLine(" Taiko map");
				break;
			case "2":
				Console.WriteLine("n osu!mania map");
				break;
			case "3":
				Console.WriteLine(" CTB map");
				break;
		}
		Console.WriteLine("\n----------------\nOBJECTS\n----------------");
		Console.WriteLine("There are " + hitObjects.Count + " total objects");
		foreach (List<string> hO in hitObjects) {
			switch (hO[3]) {
				case "1":
					hitCircles++;
					break;
				case "2":
					sliders++;
					break;
				case "5":
					combos++;
					break;
				case "12":
					spinners++;
					break;
			}
		}
		Console.WriteLine("Of the objects, there are {0} circles, {1} sliders, and {2} spinners for a total of {3} combo(s).", hitCircles, sliders, spinners, combos+1);
		float avgDist = 0;
		for(int i = 1; i < hitObjects.Count; i++) {
			float x1 = 0, x2 = 0, y1 = 0, y2 = 0;
			float.TryParse(hitObjects[i][0], out x1);
			float.TryParse(hitObjects[i][1], out y1);
			float.TryParse(hitObjects[i-1][0], out x2);
			float.TryParse(hitObjects[i-1][1], out y2);
			avgDist += GetDistance(x1, y1, x2, y2);
		}
		avgDist /= hitObjects.Count;
		Console.WriteLine("Average distance between HitObjects is " + avgDist);
		float avgTime = 0;
		for(int i = 1; i < hitObjects.Count; i++) {
			float t1, t2;
			float.TryParse(hitObjects[i][2], out t2);
			float.TryParse(hitObjects[i-1][2], out t1);
			avgTime += t2-t1;
		}
		avgTime /= hitObjects.Count;
		Console.WriteLine("Average time between HitObjects is " + avgTime);
		Console.WriteLine("Avg. Distance / Avg. Time is " + avgDist/avgTime);
		Console.WriteLine("\n----------------\nSLIDERS\n----------------");
		foreach(List<string> hitObject in hitObjects) {
			if (hitObject.Count >= 6) {
				if (hitObject[5].Contains("B")) {
					bezier++;
				}
				if (hitObject[5].Contains("C")) {
					catmull++;
				}
				if (hitObject[5].Contains("L")) {
					linear++;
				}
				if (hitObject[5].Contains("P")) {
					passthrough++;
				}
			}
		}
		Console.WriteLine("Bezier: {0}\tCatmull: {1}\tLinear: {2}\tPass-through: {3}", bezier, catmull, linear, passthrough);
		if (catmull != 0) Console.WriteLine("This is a very old beatmap!");
  }

	public static void OsuJsonToDict(List<string> inLines, ref Dictionary<string,string> outDict) {
		foreach(string s in inLines) {
			if (s == "[HitObjects]") break;
			if (s.Contains(":")) {
				int splitPoint = s.IndexOf(":");
				string key = s.Substring(0, splitPoint);
				string value = s.Substring(splitPoint+1).Trim();
				outDict.Add(key, value);
			}
		}
	}

	public static List<List<string>> OsuObjectsToList(List<string> inLines) {
		List<List<string>> hitObjProps = new List<List<string>>();
		bool startRec = false;
		for (int i = 0; i < inLines.Count-1; i++) { //TODO shorten using foreach
			if (startRec) {
				hitObjProps.Add(new List<string>(inLines[i].Split(new char[] {','})));
			} else {
				if (inLines[i] == "[HitObjects]") startRec = true;
			}
		}
		return hitObjProps;
	}

	public static float GetDistance(float x1, float y1, float x2, float y2) {
		return (float)Math.Sqrt(Math.Pow(x2-x1, 2) + Math.Pow(y2-y1, 2));
	}
}