/// <summary> /// /// </summary> /// <param name="fighter"></param> /// <param name="archive"></param> /// <param name="bgm"></param> private static void InstallFighterMusic(MEXFighter fighter, ZipArchive archive, MEXMusic bgm) { var music = MEX.BackgroundMusic.FirstOrDefault(e => e.FileName == bgm.FileName); if (music != null) { bgm.FileName = music.FileName; bgm.Label = music.Label; } else { // find music in zip var musicFile = archive.GetFile(Path.GetFileName(bgm.FileName)); if (musicFile != null) { MEX.ImageResource.AddFile("audio\\" + Path.GetFileName(bgm.FileName), musicFile); // add music MEX.BackgroundMusic.Add(bgm); } } }
/// <summary> /// /// </summary> /// <param name="stream"></param> public static void InstallFighterFromStream(Stream stream) { // check filename conflicts using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Read)) { var stageEntry = archive.GetEntry("fighter.yml"); var serializer = new DeserializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) .WithTypeInspector(inspector => new MEXTypeInspector(inspector)) .Build(); MEXFighter fighter = null; using (StreamReader r = new StreamReader(stageEntry.Open())) fighter = serializer.Deserialize <MEXFighter>(r.ReadToEnd()); if (fighter == null) { return; } // effect file (as dat files) InstallFile(archive, fighter.EffectFile); InstallFile(archive, fighter.KirbyEffectFile); // pl + aj + result anim InstallFile(archive, fighter.FighterDataPath); InstallFile(archive, fighter.AnimFile); InstallFile(archive, fighter.RstAnimFile); // ViWaitAJ InstallFile(archive, fighter.DemoWait); // costumes foreach (var c in fighter.Costumes) { var costumeFile = archive.GetEntry(Path.GetFileNameWithoutExtension(c.FileName) + ".zip"); if (costumeFile != null) { using (var costumeStream = costumeFile.Open()) using (var cs = new MemoryStream()) { costumeStream.CopyTo(cs); using (ZipArchive costumeArchive = new ZipArchive(cs, ZipArchiveMode.Read)) { if (costumeArchive.GetEntry("csp.png") != null) { using (var en = costumeArchive.GetEntry("csp.png").Open()) using (var bmp = new Bitmap(en)) c.CSP = bmp.ToTOBJ(GXTexFmt.CI8, GXTlutFmt.RGB5A3); } if (costumeArchive.GetEntry("stc.png") != null) { using (var en = costumeArchive.GetEntry("stc.png").Open()) using (var bmp = new Bitmap(en)) c.Icon = bmp.ToTOBJ(GXTexFmt.CI4, GXTlutFmt.RGB5A3); } if (costumeArchive.GetEntry(c.FileName) != null) { InstallFile(costumeArchive, c.FileName); } } } } } // kirby hat InstallFile(archive, fighter.KirbyCapFileName); // movie InstallFile(archive, fighter.EndMovieFile); // images InstallFile(archive, fighter.EndAdventureFile); InstallFile(archive, fighter.EndAllStarFile); InstallFile(archive, fighter.EndClassicFile); // TODO: demo symbols (these are embedded in certain files) // announcer call (have to extract this dsp) var entry = archive.GetFile("namecall.wav"); if (entry != null) { var dsp = new DSP(); dsp.FromFormat(entry, "wav"); var announcerIndex = MEX.SoundBanks[51].SoundBank.Sounds.Length; MEX.SoundBanks[51].SoundBank.AddSound(dsp); var scripts = MEX.SoundBanks[51].ScriptBank.Scripts; Array.Resize(ref scripts, announcerIndex + 1); scripts[announcerIndex] = new SEMBankScript(); scripts[announcerIndex].Codes.Add(new SEMCode(SEM_CODE.SET_SFXID) { Value = announcerIndex }); scripts[announcerIndex].Codes.Add(new SEMCode(SEM_CODE.SET_REVERB1) { Value = 48 }); scripts[announcerIndex].Codes.Add(new SEMCode(SEM_CODE.SET_PRIORITY) { Value = 15 }); scripts[announcerIndex].Codes.Add(new SEMCode(SEM_CODE.PLAY) { Value = 229 }); scripts[announcerIndex].Codes.Add(new SEMCode(SEM_CODE.END_PLAYBACK)); MEX.SoundBanks[51].ScriptBank.Scripts = scripts; fighter.AnnouncerCall = 51000 + announcerIndex; } // install sound bank fighter.SoundBank = MEX.SoundBanks[55]; var soundFile = archive.GetFile("sound.spk"); if (soundFile != null) { using (MemoryStream soundStream = new MemoryStream(soundFile)) { var sf = new MEXSoundBank(soundStream); var soundBank = Core.MEX.SoundBanks.FirstOrDefault(e => e.SoundBank.Name == sf.SoundBank.Name); // don't add vanilla soundbanks if (soundBank != null) { MessageBox.Show($"Warning: Soundbank with name \"{soundBank.SoundBank.Name}\" already exists.\nUsing existing soundbank instead.", "Soundbank Already Exists", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); fighter.SoundBank = soundBank; } else { fighter.SoundBank = sf; MEX.SoundBanks.Add(sf); } } } // link and add missing music InstallFighterMusic(fighter, archive, fighter.VictoryTheme); InstallFighterMusic(fighter, archive, fighter.FighterSongID1); InstallFighterMusic(fighter, archive, fighter.FighterSongID2); // TODO: install target test stage // add stage file MEX.Fighters.Insert(MEX.FighterCount - 6, fighter); } }