public DIDXSection ReadDIDXSection(Stream input) { DIDXSection retVar = new DIDXSection(); List <WEMFile> WEMFileList = new List <WEMFile>(); uint SectionSize = input.ReadValueU32(); retVar.SectionSize = SectionSize; long EndOfDIDXSection = input.Position + SectionSize; Console.WriteLine("section='{0}' {1}", "DIDX", SectionSize); long zeroPos = 0L; if (_ZeroWrite) { _Zero.Clear(); } while (input.Position != EndOfDIDXSection) { uint id = input.ReadValueU32(); long offset = input.ReadValueS32(); uint size = input.ReadValueU32(); retVar.ObjCount++; WEMFile tempWEM = new WEMFile(); tempWEM.Num = retVar.ObjCount; tempWEM.Id = id; tempWEM.Offset = offset; tempWEM.Length = size; WEMFileList.Add(tempWEM); if (_ZeroWrite) { if (zeroPos != offset) { int num = (int)retVar.ObjCount - 2; long zero = offset - zeroPos; _Zero.Add(num, zero); //Console.WriteLine("> " + zero); } zeroPos = offset + size; } // Console.WriteLine("[" + tempWEM.Num + "]" + " Position:" + offset + " Size:" + size + " ID:" + tempWEM.Id); } retVar.DIDXFiles = WEMFileList; return(retVar); }
private void OnContextMenuReplaceWem(object sender, EventArgs e) { WEMFile wem = _EntryListView.SelectedItems[0].Tag as WEMFile; if (wem == null || wem == default(WEMFile)) { return; } if (string.IsNullOrEmpty(_LastWemPath)) { _OpenFileWem.InitialDirectory = Properties.Settings.Default.BnkViewer_InputWem; } else { _OpenFileWem.InitialDirectory = Path.GetDirectoryName(_LastWemPath) + Path.DirectorySeparatorChar; Properties.Settings.Default.BnkViewer_InputWem = _OpenFileWem.InitialDirectory; Properties.Settings.Default.Save(); } if (_OpenFileWem.ShowDialog() != DialogResult.OK) { return; } _LastWemPath = _OpenFileWem.FileName; byte[] buffer = File.ReadAllBytes(_OpenFileWem.FileName); _DIDXData.Seek(0, SeekOrigin.End); wem.Offset = _DIDXData.Position; wem.Length = (uint)buffer.Length; _DIDXData.Write(buffer, 0, buffer.Length); buffer = null; //_DIDXSection.DIDXFiles[wem.Num - 1].Position = 0; //_DIDXSection.DIDXFiles[wem.Num - 1].Size = 0; _AudioPlaybackPanel.FreeStream(); _LastPlaySound = 0; }
private string ConvertWemToWav(WEMFile wemFile, bool convertOgg = false, int msTimeout = 0) { if (_DIDXData == null || (wemFile.Offset + wemFile.Length) > _DIDXData.Length) { return(null); } bool error = false; string returnPath = null; bool findImaAdpcm = File.Exists(_PathImaAdpcm); bool findWw2Ogg = File.Exists(_PathWw2Ogg); bool findRevorb = File.Exists(_PathRevorb); bool findOggDec = File.Exists(_PathOggDec); _DIDXData.Seek(wemFile.Offset, SeekOrigin.Begin); byte[] buffer = _DIDXData.ReadBytes(wemFile.Length); _DIDXData.Seek(wemFile.Offset, SeekOrigin.Begin); var header = WaveFile.ReadHeader(_DIDXData, false); Console.WriteLine("ID " + wemFile.Id.ToString() + " " + header.ToString()); // Create Wem file using (var fs = new FileStream(_TempWemFile, FileMode.Create)) { fs.Write(buffer, 0, buffer.Length); } // ADPCM 105,2 if (header.AudioFormat == WavFormatId.WWISE_ADPCM || header.AudioFormat == WavFormatId.VOXWARE_BYTE_ALIGNED) { if (findImaAdpcm && ProcessStart(_PathImaAdpcm, string.Format("-d \"{0}\" \"{1}\"", _TempWemFile, _TempWavFile), msTimeout) == 0) { returnPath = _TempWavFile; convertOgg = true; } } // XMA 357,358 // else if ((ushort)header.AudioFormat == 357 || (ushort)header.AudioFormat == 358) // { // System.Diagnostics.Debugger.Break(); // } // PCM else if (header.AudioFormat == WavFormatId.WWISE_PCM) { try { WaveFile.Create(buffer, _TempWavFile, header); returnPath = _TempWavFile; convertOgg = true; } catch { returnPath = null; } } // Vorbis else if (header.AudioFormat == WavFormatId.WWISE_VORBIS) { string args = string.Format("{0} --pcb \"{1}\"", string.Format("\"{0}\" -o \"{1}\"", _TempWemFile, _TempOggFile), Path.Combine(Program.BinaryPath, "packed_codebooks_aoTuV_603.bin")); // Ww2Ogg (ww2ogg имяФайла.ogg (для стереофайлов с опцией --full-setup) ) if (findWw2Ogg && ProcessStart(_PathWw2Ogg, args, msTimeout) != 0) { error = true; Console.WriteLine("error ww2ogg"); } else if (findRevorb && ProcessStart(_PathRevorb, string.Format("\"{0}\"", _TempOggFile), msTimeout) != 0) { Console.WriteLine("error revorb"); } if (!error) { if (convertOgg) { if (findOggDec && ProcessStart(_PathOggDec, string.Format("\"{0}\"", _TempOggFile), msTimeout) != 0) { Console.WriteLine("error oggdec"); } else { returnPath = _TempWavFile; } } else { returnPath = _TempOggFile; } } } // Wav File ? else { using (var output = File.Create(_TempWavFile)) { output.Write(buffer, 0, buffer.Length); } } buffer = null; header = null; try { if (File.Exists(_TempWemFile)) { File.Delete(_TempWemFile); } if (convertOgg) { if (File.Exists(_TempOggFile)) { File.Delete(_TempOggFile); } } else { if (File.Exists(_TempWavFile)) { File.Delete(_TempWavFile); } } } catch { } return(returnPath); }