Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAddSound_Click(object sender, EventArgs e)
        {
            mxListBox1.DataSource = null;

            var newScript = new SEMBankScript();

            newScript.Name = "SFXNew_Script";
            newScript.Codes.Add(new SEMCode(SEM_CODE.SET_SFXID));
            newScript.Codes.Add(new SEMCode(SEM_CODE.PLAY)
            {
                Value = 128
            });
            newScript.Codes.Add(new SEMCode(SEM_CODE.END_PLAYBACK));

            var scripts = _semBank.Scripts;

            Array.Resize(ref scripts, scripts.Length + 1);
            _semBank.Scripts = scripts;
            _semBank.Scripts[_semBank.Scripts.Length - 1] = newScript;

            mxListBox1.DataSource   = _semBank.Scripts;
            mxListBox1.SelectedItem = newScript;
        }
Example #2
0
        /// <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);
            }
        }