private BGMEntry ParseProperty(BinaryReader b, int songId) { BGMEntry bEntry = new BGMEntry(songId); bEntry.BGMTitle = new string(b.ReadChars(0x3c)); if (bEntry.BGMTitle.StartsWith("\0")) { bEntry.BGMTitle = BGMFilesDB.BGMs[songId]; } else { bEntry.BGMTitle = bEntry.BGMTitle.TrimEnd('\0'); } bEntry.BGMUnk1 = b.ReadInt32(); bEntry.BGMUnk2 = b.ReadInt32(); bEntry.BGMUnk3 = b.ReadInt32(); bEntry.BGMUnk4 = b.ReadInt32(); bEntry.MenuCheckPoint1 = b.ReadInt32(); bEntry.MenuCheckPoint2 = b.ReadInt32(); bEntry.MenuCheckPoint3 = b.ReadInt32(); bEntry.MenuCheckPoint4 = b.ReadInt32(); bEntry.LoopStartTime = b.ReadInt32(); bEntry.LoopEndTime = b.ReadInt32(); bEntry.LoopStartSample = b.ReadInt32(); bEntry.LoopEndSample = b.ReadInt32(); bEntry.StreamTotalDuration = b.ReadInt32(); bEntry.StreamTotalSamples = b.ReadInt32(); return(bEntry); }
private void WriteBGMEntry(BGMEntry bEntry, BinaryWriter writerPackage) { int titleSize = bEntry.BGMTitle.Length; if (titleSize > 0x3c) { throw new Exception(string.Format("Title of BGMEntry too long! : {0}", bEntry.BGMTitle)); } writerPackage.Write(Encoding.ASCII.GetBytes(bEntry.BGMTitle)); while (titleSize < 0x3c) { writerPackage.Write((byte)0x00); titleSize++; } writerPackage.Write(bEntry.BGMUnk1); writerPackage.Write(bEntry.BGMUnk2); writerPackage.Write(bEntry.BGMUnk3); writerPackage.Write(bEntry.BGMUnk4); writerPackage.Write(bEntry.MenuCheckPoint1); writerPackage.Write(bEntry.MenuCheckPoint2); writerPackage.Write(bEntry.MenuCheckPoint3); writerPackage.Write(bEntry.MenuCheckPoint4); writerPackage.Write(bEntry.LoopStartTime); writerPackage.Write(bEntry.LoopEndTime); writerPackage.Write(bEntry.LoopStartSample); writerPackage.Write(bEntry.LoopEndSample); writerPackage.Write(bEntry.StreamTotalDuration); writerPackage.Write(bEntry.StreamTotalSamples); }
public void RemoveBGMEntry(int bgmID) { BGMEntry bEntry = _SoundEntriesBGMsPerID[bgmID]; _SoundEntriesBGMsPerID.Remove(bEntry.BGMID); _SoundEntriesBGMsPerName.Remove(bEntry.BGMTitle); _SoundEntriesBGMs.Remove(bEntry); }
private BGMEntry GetBGMEntry() { if (SoundEntryCollection.SoundEntriesBGMsPerID.ContainsKey(BGMID)) { return(SoundEntryCollection.SoundEntriesBGMsPerID[BGMID]); } BGMEntry newEntry = SoundEntryCollection.SoundEntriesBGMs.First(); LogHelper.Error(string.Format("BGM ID {0} was not found for Sound '{1}', reverting to '{2}'. Please check this Sound ID and fix it if needed.", BGMID, SoundEntry.ListTitle, newEntry.BGMTitle)); BGMID = newEntry.BGMID; return(GetBGMEntry()); }
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); }
public PropertyFile(SmashProjectManager projectManager, SoundEntryCollection sEntryCollection, string path) { string propertyFile; propertyFile = PathHelper.FolderEditorMods + path; if (!File.Exists(propertyFile)) { propertyFile = projectManager.ExtractResource(path, PathHelper.FolderTemp); } SoundEntryCollection = sEntryCollection; _Path = path; using (FileStream fileStream = File.Open(propertyFile, FileMode.Open)) { using (BinaryReader b = new BinaryReader(fileStream)) { if (new string(b.ReadChars(3)) != "MPB") { throw new Exception(string.Format("Can't load '{0}', the file is either compressed or its not a MPB file", propertyFile)); } //Keep header b.BaseStream.Position = 0; _Header = b.ReadBytes(HEADER_LEN); //Nbr BGM b.BaseStream.Position = HEADER_LEN; uint nbrBgm = b.ReadUInt32(); //Songtable uint songTableOffset = HEADER_LEN + 0x4 + (nbrBgm * 0x4); uint[] songIds = new uint[nbrBgm]; b.BaseStream.Position = HEADER_LEN + 0x4; for (int i = 0; i < nbrBgm; i++) { songIds[i] = b.ReadUInt32(); } //Parsing for (int i = 0; i < nbrBgm; i++) { if (songIds[i] != 0xffffffff) { b.BaseStream.Position = songTableOffset + songIds[i]; BGMEntry sEntry = ParseProperty(b, i); SoundEntryCollection.SoundEntriesBGMs.Add(sEntry); } } } } }
public BGMEntry CreateBGMEntry(string bgmName) { string file = GetBGMFullPath("snd_bgm_" + bgmName + ".nus3bank"); VGMStreamReader reader = new VGMStreamReader(file); int lastId = GetNewBGMEntryID(); BGMEntry sEntryBGM = new BGMEntry(lastId); sEntryBGM.BGMTitle = bgmName; sEntryBGM.BGMUnk1 = 1; // Most common value is 1 sEntryBGM.BGMUnk2 = -1; sEntryBGM.BGMUnk3 = 0x190; //Most common value sEntryBGM.BGMUnk4 = -1; //Most common value is null sEntryBGM.MenuCheckPoint1 = -1; sEntryBGM.MenuCheckPoint2 = -1; sEntryBGM.MenuCheckPoint3 = -1; sEntryBGM.MenuCheckPoint4 = -1; if (reader.FileLoaded) { sEntryBGM.LoopStartTime = reader.LoopStartMilliseconds; sEntryBGM.LoopEndTime = reader.LoopEndMilliseconds; sEntryBGM.LoopStartSample = reader.LoopStartSample; sEntryBGM.LoopEndSample = reader.LoopEndSample; sEntryBGM.StreamTotalDuration = reader.TotalMilliseconds; sEntryBGM.StreamTotalSamples = reader.TotalSamples; reader.Dispose(); } else { LogHelper.Warning(string.Format(Strings.WARNING_VGMSTREAM_CREATE_BGMENTRY, file)); } _SoundEntriesBGMs.Add(sEntryBGM); _SoundEntriesBGMsPerID.Add(lastId, sEntryBGM); _SoundEntriesBGMsPerName.Add(bgmName, sEntryBGM); return(sEntryBGM); }