public BNKFile(string fileLocation, bool isAudioBank = false, bool isEventBank = false, bool isChampionBank = false, bool extractAudio = false) { fileLoc = fileLocation; br = new BinaryReader(File.Open(fileLocation, FileMode.Open)); if (isAudioBank == true) { bkhd = new BKHD(br); if (isChampionBank == true) { br.ReadBytes(12); } didx = new DIDX(br); data = new DATA(br, didx, bkhd); if (extractAudio == true) { foreach (var a in didx.Files) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Extracting " + a.ID.ToString() + ".wem"); DIDXEmbeddedWEMFile.ExportAudio(a.ID.ToString() + ".wem", a.Data, this); } } } else if (isEventBank == true) { bkhd = new BKHD(br); } }
public DATA(BinaryReader br, DIDX didx, BKHD bkhd) { Magic = Encoding.ASCII.GetString(br.ReadBytes(4)); Length = br.ReadUInt32(); foreach (var f in didx.Files) { br.BaseStream.Seek(CalculateOffsetBNK(didx.WEMCount) + f.OffsetDataSection, SeekOrigin.Begin); f.Data = br.ReadBytes((int)f.DataLength); } }
//imported constructor public NBNKFile(BinaryReader br, SupportedGames mode) { holding = new List <byte[]>(); while (br.BaseStream.Position < br.BaseStream.Length) { byte[] magicArr = br.ReadBytes(4); string magic = Encoding.UTF8.GetString(magicArr); switch (magic) { case "BKHD": uint SLength = br.ReadUInt32(); BankHeader = new BKHD(SLength, br); uint bnkId = BankHeader.dwSoundbankID; string path = Directory.GetCurrentDirectory() + "/" + mode.ToString() + "/BNK/" + bnkId.ToString() + ".lbl"; if (File.Exists(path)) { MessageBoxResult labelRead = MessageBox.Show("Label file found. Read labels?", "Labels", MessageBoxButton.YesNo); if (labelRead == MessageBoxResult.Yes) { labels = new Labels(XmlReader.Create(path)); } else { labels = new Labels(); } } else { labels = new Labels(); } break; case "DIDX": DataIndex = new DIDX(br, labels); break; /*case "HIRC": * ObjectHierarchy = new HIRC(br); * break;*/ default: //this adds support to not-immediately-interpreted versions of WWise, assuming that the main 3 (BKHD, DIDX, DATA) do not change in structure SLength = br.ReadUInt32(); byte[] tLength = BitConverter.GetBytes(SLength); byte[] data = br.ReadBytes((int)SLength); byte[] section = HelperFunctions.Combine(HelperFunctions.Combine(magicArr, tLength), data); holding.Add(section); break; } } br.Close(); }
public void LoadBNK(Stream instream) { instream.Position = 0; using (BinaryReader br = new BinaryReader(instream)) { while (instream.Position < instream.Length) { this.ProgressMutex.WaitOne(); this.loadPercent = (float)((100 * instream.Position) / instream.Length); this.ProgressMutex.ReleaseMutex(); //Find all sections uint section_tag = br.ReadUInt32(); //long offset = fs.Position+4; object section = new object(); if (section_tag == this.BKHD_tag) { section = new BKHD(br); } else if (section_tag == this.DIDX_tag) { section = new DIDX(br); } else if (section_tag == this.DATA_tag) { section = new DATA(br); } else if (section_tag == this.STID_tag) { section = new STID(br); } else if (section_tag == this.HIRC_tag) { section = new HIRC(br); } else { section = new Unknown(br); } //Console.WriteLine(section); this.sections.Add(section); } } /* * foreach(KeyValuePair<byte, HashSet<object>> kvp in StaticStorage.parameters) * { * Console.WriteLine(kvp.Key); * foreach(object val in kvp.Value) * Console.WriteLine("\t"+val); * } */ //organize DATA section and compile a list of sound files DIDX didx_section = this.sections.FirstOrDefault(e => e is DIDX) as DIDX; DATA data_section = this.sections.FirstOrDefault(e => e is DATA) as DATA; HIRC hirc_section = this.sections.FirstOrDefault(e => e is HIRC) as HIRC; Dictionary <uint, uint> fileOffsets = new Dictionary <uint, uint>(); if (didx_section != null && data_section != null) { foreach (var obj in didx_section.objects) { data_section.files.Add(obj.id, data_section.remaining_data.Skip((int)obj.data_offset).Take((int)obj.data_length).ToArray()); } fileOffsets = data_section.GenerateFileData(); } if (hirc_section != null) { for (int x = 0; x < hirc_section.objects.Count; x++) { object section = hirc_section.objects[x]; SoundFile sf = new SoundFile(); if (section is HIRC_SoundSFX) { sf.id = (section as HIRC_SoundSFX).soundid; sf.streamed = ((section as HIRC_SoundSFX).soundincluded == 0 ? false : true); sf.length_object = section; } else if (section is HIRC_MusicTrack) { sf.id = (section as HIRC_MusicTrack).soundID; sf.streamed = ((section as HIRC_MusicTrack).streamed == 0 ? false : true); sf.length_object = section; sf.loop_object = hirc_section.objects[x + 1]; if ((sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParameters_count > 0) { sf.effects = "Additional parameters:\r\n"; for (int y = 0; y < (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParameters_count; y++) { byte type = (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersType[y]; if (type == 0x00) { sf.effects += "General Settings: Voice: Volume - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x02) { sf.effects += "General Settings: Voice: Pitch - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x03) { sf.effects += "General Settings: Voice: Low-pass filter - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x05) { sf.effects += "Advanced Settings: Playback Priority: Priority - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x06) { sf.effects += "Advanced Settings: Playback Priority: Offset priority - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x07) { sf.effects += "Loop count (0 = infinite) - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x08) { sf.effects += " Motion: Audio to Motion Settings: Motion Volume Offset - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x0B) { sf.effects += "Positioning: 2D: Panner X-coordinate - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x0C) { sf.effects += "Positioning: 2D: Panner Y-coordinate - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x0D) { sf.effects += "Positioning: Center % - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x12) { sf.effects += "General Settings: User-Defined Auxiliary Sends: Bus #0 Volume - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x13) { sf.effects += "General Settings: User-Defined Auxiliary Sends: Bus #1 Volume - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x14) { sf.effects += "General Settings: User-Defined Auxiliary Sends: Bus #2 Volume - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x15) { sf.effects += "General Settings: User-Defined Auxiliary Sends: Bus #3 Volume - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x16) { sf.effects += "General Settings: Game-Defined Auxiliary Sends: Volume - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x17) { sf.effects += "General Settings: Output Bus: Volume - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else if (type == 0x18) { sf.effects += "General Settings: Output Bus: Low-pass filter - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } else { sf.effects += "Unknown - " + (sf.loop_object as HIRC_MusicSegment).soundstructure.additionalParametersValue[y]; } sf.effects += "\r\n"; } } else { sf.effects = "This sound does not have any additional parameters."; } x++; } else { continue; } if (!StaticStorage.soundfiles.ContainsKey(sf.id)) { StaticStorage.soundfiles.Add(sf.id, sf); } } } foreach (var sf in StaticStorage.soundfiles.Values) { if (fileOffsets.ContainsKey(sf.id)) { sf.data_offset = fileOffsets[sf.id]; } else { sf.data_offset = 0; } } this.isLoaded = true; }
//created constructor, this really shouldn't be used very often public NBNKFile() { BankHeader = new BKHD(); }