Please note that this is very dodgy code (it works great tho!), so things might be a bit hard to read sometimes, although I tried to comment the most important stuff.
Edit: btw, don't hesitate to ask me stuff, I've kinda become sort of an "expert" on osu specific files :p