public override void Unload()
 {
     tMPConfig            = null;
     HidePlayerHotkey     = null;
     PlayStopHotkey       = null;
     PrevSongHotkey       = null;
     NextSongHotkey       = null;
     MP_UserInterface     = null;
     MusicPlayerUI        = null;
     AllMusic             = null;
     itemToMusicReference = null;
 }
        public override void Load()
        {
            // Setup hotkeys and the configs instance.
            tMPConfig        = ModContent.GetInstance <TMPConfig>();
            HidePlayerHotkey = RegisterHotKey("Hide Music Player", "Up");
            PlayStopHotkey   = RegisterHotKey("Play/Stop Music", "Down");
            PrevSongHotkey   = RegisterHotKey("Previous Song", "Left");
            NextSongHotkey   = RegisterHotKey("Next Song", "Right");

            // Register this mods music boxes.
            // TODO: [1.4] Remove music boxes. The 1.4 update reimplements the console music.
            if (!Main.dedServ)
            {
                AddMusicBox(GetSoundSlot(SoundType.Music, "Sounds/Music/ConsoleSpace"), ModContent.ItemType <Items.MusicBoxConsoleSpace>(), ModContent.TileType <Tiles.MusicBoxConsoleSpace>());
                AddMusicBox(GetSoundSlot(SoundType.Music, "Sounds/Music/ConsoleOcean"), ModContent.ItemType <Items.MusicBoxConsoleOcean>(), ModContent.TileType <Tiles.MusicBoxConsoleOcean>());
                AddMusicBox(GetSoundSlot(SoundType.Music, "Sounds/Music/ConsoleTitle"), ModContent.ItemType <Items.MusicBoxConsoleTitle>(), ModContent.TileType <Tiles.MusicBoxConsoleTitle>());
                AddMusicBox(GetSoundSlot(SoundType.Music, "Sounds/Music/ConsoleTutorial"), ModContent.ItemType <Items.MusicBoxConsoleTutorial>(), ModContent.TileType <Tiles.MusicBoxConsoleTutorial>());
            }

            // A list that contains all the MusicData we need, including mod and name.
            // TODO: [1.4] Reorder boxes based on progression? Maybe grab info from bosschecklist in the future?
            AllMusic = new List <MusicData>
            {
                new MusicData(MusicID.OverworldDay, ItemID.MusicBoxOverworldDay),
                new MusicData(MusicID.AltOverworldDay, ItemID.MusicBoxAltOverworldDay),
                new MusicData(MusicID.Night, ItemID.MusicBoxNight),
                new MusicData(MusicID.Rain, ItemID.MusicBoxRain),
                new MusicData(MusicID.Snow, ItemID.MusicBoxSnow),
                new MusicData(MusicID.Ice, ItemID.MusicBoxIce),
                new MusicData(MusicID.Desert, ItemID.MusicBoxDesert),
                new MusicData(MusicID.Ocean, ItemID.MusicBoxOcean),
                new MusicData(MusicID.Space, ItemID.MusicBoxSpace),
                new MusicData(MusicID.Underground, ItemID.MusicBoxUnderground),
                new MusicData(MusicID.AltUnderground, ItemID.MusicBoxAltUnderground),
                new MusicData(MusicID.Mushrooms, ItemID.MusicBoxMushrooms),
                new MusicData(MusicID.Jungle, ItemID.MusicBoxJungle),
                new MusicData(MusicID.Corruption, ItemID.MusicBoxCorruption),
                new MusicData(MusicID.UndergroundCorruption, ItemID.MusicBoxUndergroundCorruption),
                new MusicData(MusicID.Crimson, ItemID.MusicBoxCrimson),
                new MusicData(MusicID.UndergroundCrimson, ItemID.MusicBoxUndergroundCrimson),
                new MusicData(MusicID.TheHallow, ItemID.MusicBoxTheHallow),
                new MusicData(MusicID.UndergroundHallow, ItemID.MusicBoxUndergroundHallow),
                new MusicData(MusicID.Hell, ItemID.MusicBoxHell),
                new MusicData(MusicID.Dungeon, ItemID.MusicBoxDungeon),
                new MusicData(MusicID.Temple, ItemID.MusicBoxTemple),
                new MusicData(MusicID.Boss1, ItemID.MusicBoxBoss1),
                new MusicData(MusicID.Boss2, ItemID.MusicBoxBoss2),
                new MusicData(MusicID.Boss3, ItemID.MusicBoxBoss3),
                new MusicData(MusicID.Boss4, ItemID.MusicBoxBoss4),
                new MusicData(MusicID.Boss5, ItemID.MusicBoxBoss5),
                new MusicData(MusicID.Plantera, ItemID.MusicBoxPlantera),
                new MusicData(MusicID.Eerie, ItemID.MusicBoxEerie),
                new MusicData(MusicID.Eclipse, ItemID.MusicBoxEclipse),
                new MusicData(MusicID.GoblinInvasion, ItemID.MusicBoxGoblins),
                new MusicData(MusicID.PirateInvasion, ItemID.MusicBoxPirates),
                new MusicData(MusicID.MartianMadness, ItemID.MusicBoxMartians),
                new MusicData(MusicID.PumpkinMoon, ItemID.MusicBoxPumpkinMoon),
                new MusicData(MusicID.FrostMoon, ItemID.MusicBoxFrostMoon),
                new MusicData(MusicID.TheTowers, ItemID.MusicBoxTowers),
                new MusicData(MusicID.LunarBoss, ItemID.MusicBoxLunarBoss),
                new MusicData(MusicID.Sandstorm, ItemID.MusicBoxSandstorm),
                new MusicData(MusicID.OldOnesArmy, ItemID.MusicBoxDD2),
                new MusicData(MusicID.Title, ItemID.MusicBoxTitle)
            };

            // Code provided by Jopojelly. Thank you, Jopo!
            // This grabs the entire dictionary of MODDED music-to-musicbox correlations.
            FieldInfo field = typeof(SoundLoader).GetField("itemToMusic", BindingFlags.Static | BindingFlags.NonPublic);

            itemToMusicReference = (Dictionary <int, int>)field.GetValue(null);

            // Setup the Music Player UI.
            if (!Main.dedServ)
            {
                MusicPlayerUI = new MusicPlayerUI();
                MusicPlayerUI.Activate();
                MP_UserInterface = new UserInterface();
                MP_UserInterface.SetState(MusicPlayerUI);
            }
        }