Beispiel #1
0
        public MyMusicFile(Sm4shProject projectManager, SoundEntryCollection sEntryCollection, string path)
        {
            string mymusicFile = projectManager.ExtractResource(path, PathHelper.FolderTemp);

            SoundEntryCollection = sEntryCollection;
            _Path = path;

            using (FileStream fileStream = File.Open(mymusicFile, FileMode.Open))
            {
                using (BinaryReader b = new BinaryReader(fileStream))
                {
                    if (new string(b.ReadChars(3)) != "MMB")
                    {
                        throw new Exception(string.Format("Can't load '{0}', the file is either compressed or its not a MMB file.", mymusicFile));
                    }

                    //Keep header
                    b.BaseStream.Position = 0;
                    _Header = b.ReadBytes(HEADER_LEN);

                    //Number of elements
                    b.BaseStream.Position = HEADER_LEN;
                    int nbrStages = b.ReadInt32();

                    //Offsets per element
                    int[] offsetsPerElement = new int[nbrStages];
                    for (int i = 0; i < nbrStages; i++)
                    {
                        offsetsPerElement[i] = b.ReadInt32();
                    }

                    //Stage offset
                    int stageStartOffset = HEADER_LEN + 0x4 + (nbrStages * 0x4) + 0x20; //0x20 = Magic Padding

                    for (int i = 0; i < nbrStages; i++)
                    {
                        MyMusicStage myMusicStage       = new MyMusicStage(i);
                        int          currentStageOffset = stageStartOffset + offsetsPerElement[i];

                        b.BaseStream.Position = currentStageOffset;
                        uint nbrBGMs = b.ReadUInt32();

                        currentStageOffset += 0x4;
                        for (int j = 0; j < nbrBGMs; j++)
                        {
                            b.BaseStream.Position = currentStageOffset + (j * 0x3c);
                            myMusicStage.BGMs.Add(ParseBGMEntry(b));
                        }
                        SoundEntryCollection.MyMusicStages.Add(myMusicStage);
                    }
                }
            }
        }
        public object Clone()
        {
            SoundEntryCollection sCollection = new SoundEntryCollection();

            foreach (BGMEntry sEntryBGM in _SoundEntriesBGMs)
            {
                BGMEntry newSEntryBGM = (BGMEntry)sEntryBGM.Clone();
                sCollection._SoundEntriesBGMs.Add(newSEntryBGM);
            }
            sCollection.GenerateSoundEntriesBGMDictionary();

            foreach (SoundEntry sEntry in _SoundEntries)
            {
                SoundEntry newSEntry = (SoundEntry)sEntry.Clone();
                newSEntry.BGMFiles = new List <SoundEntryBGM>();
                foreach (SoundEntryBGM sEntryBGM in sEntry.BGMFiles)
                {
                    newSEntry.BGMFiles.Add(new SoundEntryBGM(sCollection, newSEntry, sEntryBGM.BGMID));
                }
                newSEntry.SoundEntryCollection = sCollection;
                sCollection._SoundEntries.Add(newSEntry);
            }
            sCollection.GenerateSoundEntriesDictionary();

            foreach (MyMusicStage myMusicStage in _MyMusicStages)
            {
                MyMusicStage nMyMusicStage = new MyMusicStage(myMusicStage.MyMusicStageID);
                foreach (MyMusicStageBGM sMusicStageBGM in myMusicStage.BGMs)
                {
                    MyMusicStageBGM nMyMusicStageBGM = (MyMusicStageBGM)sMusicStageBGM.Clone();
                    nMyMusicStageBGM.SoundEntryCollection = sCollection;
                    nMyMusicStage.BGMs.Add(nMyMusicStageBGM);
                }
                sCollection._MyMusicStages.Add(nMyMusicStage);
            }

            foreach (SoundDBStage soundDBStage in _SoundDBStages)
            {
                List <SoundDBStageSoundEntry> sEntries = new List <SoundDBStageSoundEntry>();
                foreach (SoundDBStageSoundEntry sSoundDBStageSoundEntry in soundDBStage.SoundEntries)
                {
                    sEntries.Add(new SoundDBStageSoundEntry(sCollection, sSoundDBStageSoundEntry.SoundID));
                }
                SoundDBStage nSoundDBStage = new SoundDBStage(sCollection, soundDBStage.SoundDBStageID);
                nSoundDBStage.SoundEntries = sEntries;
                sCollection._SoundDBStages.Add(nSoundDBStage);
            }

            sCollection.GenerateStagesDictionaries();

            return(sCollection);
        }
Beispiel #3
0
        public void BuildFile()
        {
            string savePath = PathHelper.GetWorkplaceFolder(PathHelperEnum.FOLDER_PATCH) + _Path.Replace('/', Path.DirectorySeparatorChar);

            using (MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter w = new BinaryWriter(stream))
                {
                    w.Write(_Header);

                    //NbrStage
                    w.Write(SoundEntryCollection.MyMusicStages.Count);

                    uint offSet = 0;
                    foreach (MyMusicStage myMusicStage in SoundEntryCollection.MyMusicStages)
                    {
                        w.Write(offSet);
                        offSet += ((uint)myMusicStage.BGMs.Count * 0x3c) + 0x24; //0x24 = Padding + Count
                    }

                    while ((w.BaseStream.Position) % 0x3c != 0) //Magic?
                    {
                        w.Write((byte)0x0);
                    }

                    for (int i = 0; i < SoundEntryCollection.MyMusicStages.Count; i++)
                    {
                        MyMusicStage myMusicStage = SoundEntryCollection.MyMusicStages[i];
                        w.Write(myMusicStage.BGMs.Count);
                        foreach (MyMusicStageBGM myMusicStageBGM in myMusicStage.BGMs)
                        {
                            WriteBGMEntry(w, myMusicStageBGM);
                        }
                        if (i + 1 != SoundEntryCollection.MyMusicStages.Count)
                        {
                            for (int j = 0; j < 0x20; j++)  //Padding
                            {
                                w.Write((byte)0x0);
                            }
                        }
                    }
                }

                Directory.CreateDirectory(Path.GetDirectoryName(savePath));
                File.WriteAllBytes(savePath, stream.ToArray());
            }
        }