static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Drag n' drop a WEM or any audio file onto this EXE to convert it. WEM will be converted to WAV no matter what."); Console.WriteLine("Press any key to quit..."); Console.ReadKey(true); return; } FileInfo file = new FileInfo(args[0]); if (file.Extension.ToLower() == ".wem") { Console.WriteLine("WARNING: WEM conversion is a bit busted right now! If your file is broken, sorry! A patch will be out ASAP."); WEMFile wem = new WEMFile(file.FullName); WAVFile wav = wem.ConvertToWAV(); wav.SaveToFile(file.FullName + ".wav"); } else { file = FFmpegWrapper.ConvertToWaveFile(file.FullName); WAVFile wav = new WAVFile(file.FullName); WEMFile wem = wav.ConvertToWEM(); wem.SaveToFile(args[0] + ".wem"); } }
private static FileInfo ConvertToWEM(FileInfo file) { DirectoryInfo dir; if (!Directory.Exists(@".\AUDIO_TEMP")) { dir = Directory.CreateDirectory(@".\AUDIO_TEMP"); dir.Attributes = FileAttributes.Directory | FileAttributes.Hidden; } else { dir = new DirectoryInfo(@".\AUDIO_TEMP"); } if (file.Extension.ToLower() == ".wav") { WAVFile wav = new WAVFile(file.FullName); WEMFile wem = wav.ConvertToWEM(); string newWemPath = @".\AUDIO_TEMP\" + file.Name + ".wem"; return(wem.SaveToFile(newWemPath)); } else { // Guarantees the extension is wav. return(ConvertToWEM(FFmpegWrapper.ConvertToWaveFile(file.FullName, dir))); } }
static void Main(string[] args) { if (args.Length != 3) { Console.WriteLine("Usage: wemsharp.exe <helper file> <input file> <output file>"); return; } WEMFile wem = new WEMFile(args[1], WEMForcePacketFormat.NoForcePacketFormat); wem.GenerateOGG(args[2], args[0], false, false); }
/// <summary> /// Patches all bnk files into the vanilla bnk file. /// </summary> public void PatchEverything() { // Set up a list of conflicting WEM files + their corresponding BNK files. List <WEMFile> conflictingWEMs = new List <WEMFile>(); List <string> conflictingPaths = new List <string>(); List <WEMFile> vanillaWEMFiles = VanillaFile.Marshaller.WEMFiles.ToList(); int currentFiles = 0; for (int idx = 0; idx < vanillaWEMFiles.Count; idx++) { // Reset the conflicting lists since we're reviewing a new WEM file. conflictingWEMs.Clear(); conflictingPaths.Clear(); WEMFile vanillaWEM = vanillaWEMFiles[idx]; for (int oidx = 0; oidx < Patches.Length; oidx++) { BNKFile otherBnk = Patches[oidx]; WEMFile other = GetWEMInOtherBNKFromID(vanillaWEM, otherBnk); // conflictingWEMs will contain every wem file that isn't the same as the vanilla one. // This means that if the list only has one element, there are no conflicts to resolve. // Surprisingly, this is far faster than I thought it was going to be. // I had initially anticipated it to take at least a minute to process all of this data, but my implementation proved sturdy. // It can process multiple BNKs in a matter of about a second. // I suppose this is the benefit of my storage method: Spend a lot of time constructing a representation once, Save time indexing the data later. // Given how I overloaded (in)equality in WEMFile, this is alarmingly fast. if (vanillaWEM != other) { conflictingWEMs.Add(other); conflictingPaths.Add(PatchPaths[oidx]); } } int targetReplacement = 0; if (conflictingPaths.Count > 1) { Console.WriteLine(); // Bump it down for the counter. targetReplacement = ResolveFileConflict(vanillaWEM.ID, conflictingPaths.ToArray()); } if (targetReplacement != -1 && conflictingWEMs.Count != 0) { VanillaFile.Marshaller.OverwriteWEMFile(conflictingWEMs[targetReplacement]); } currentFiles++; Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("Processed {0} files (of {1})", currentFiles, vanillaWEMFiles.Count); Console.CursorLeft = 0; } Console.WriteLine(); }
public static DIDXSection ReadDIDXSection(long position) { DIDXSection retVar = new DIDXSection(); using (Stream fs = File.OpenRead(filePath)) { retVar.DIDXSectionPosition = position; Console.WriteLine("DIDXSection Position:" + retVar.DIDXSectionPosition); fs.Seek(position, SeekOrigin.Begin); byte[] data = new byte[4]; fs.Read(data, 0, data.Length); uint DIDXSectionSize = BitConverter.ToUInt32(data, 0); retVar.DIDXSectionSize = DIDXSectionSize; Console.WriteLine("DIDXSectionSize:" + DIDXSectionSize); long EndOfDIDXSection = fs.Position + DIDXSectionSize; Console.WriteLine("End of DIDXSection:" + EndOfDIDXSection); List <WEMFile> WEMFileList = new List <WEMFile>(); while (fs.Position != EndOfDIDXSection) { data = new byte[4]; fs.Read(data, 0, data.Length); uint ID = BitConverter.ToUInt32(data, 0); data = new byte[4]; fs.Read(data, 0, data.Length); uint Position = BitConverter.ToUInt32(data, 0); data = new byte[4]; fs.Read(data, 0, data.Length); uint Size = BitConverter.ToUInt32(data, 0); retVar.DIDXFileCount++; WEMFile tempWEM = new WEMFile(); tempWEM.Num = retVar.DIDXFileCount; tempWEM.ID = ID; tempWEM.Position = Position; tempWEM.Size = Size; Console.WriteLine("[" + tempWEM.Num + "]" + " Position:" + Position + " Size:" + Size + " ID:" + tempWEM.ID); WEMFileList.Add(tempWEM); } retVar.DIDXFiles = WEMFileList.ToArray(); fs.Close(); } Console.WriteLine(retVar.DIDXFileCount + " files parsed."); return(retVar); }
/// <summary> /// Gets a WEM in another BNK archive via its ID. /// </summary> /// <param name="template">The template WEM file. This should have the ID you want to get inside of its data.</param> /// <param name="otherArchive">The other archive to search.</param> /// <returns></returns> private WEMFile GetWEMInOtherBNKFromID(WEMFile template, BNKFile otherArchive) { List <WEMFile> otherWemFiles = otherArchive.Marshaller.WEMFiles.ToList(); for (int idx = 0; idx < otherWemFiles.Count; idx++) { WEMFile wemFile = otherWemFiles[idx]; if (wemFile.ID == template.ID) { return(wemFile); } } return(null); }
/// <summary> /// Overwrite an existing WEM file with the specified new file. This uses the ID present in the new file to locate the old one that it will be replacing. It also updates the WEMFileIdentity list to reflect the change.<para/> /// Throws an InvalidOperationException if the ID cannot be found. /// </summary> /// <param name="newFile">The new WEM file.</param> public void OverwriteWEMFile(WEMFile newFile) { for (int idx = 0; idx < WEMFilesInternal.Length; idx++) { WEMFile file = WEMFilesInternal[idx]; if (file.ID == newFile.ID) { WEMFilesInternal[idx] = newFile; RecalculateAllIdentities(); RawNeedsUpdate = true; return; } } throw new InvalidOperationException("The specified new WEM file has an ID that does not already exist within this BNK!"); }
async Task Async_Wwise_Extract_To_Ogg_File(int Index, string To_Dir) { await Task.Run(() => { try { //.pck内のファイルが.ogg形式でないとファイルサイズが0バイトになる WEMFile wem = new WEMFile(To_Dir + "/" + Sounds[Index].id + ".wem", WEMForcePacketFormat.NoForcePacketFormat); wem.GenerateOGG(To_Dir + "/" + Sounds[Index].id + ".ogg", Voice_Set.Special_Path + "/Wwise/packed_codebooks_aoTuV_603.bin", false, false); wem.Close(); } catch { } }); }
/// <summary> /// Recalculates the information for all WEM identities. /// </summary> private void RecalculateAllIdentities() { uint currentOffset = 0; for (int idx = 0; idx < WEMFilesInternal.Length; idx++) { WEMFile file = WEMFilesInternal[idx]; IdentitiesInternal[idx] = new WEMFileIdentity { WemID = file.ID, Offset = currentOffset, Size = (uint)file.Data.Length }; currentOffset += (uint)file.Data.Length; // Offset seems to be bound to the closest multiple of 4 byte, (e.g. if the length is 7, offset will be bumped up to 8 and the remaining space assumed to be null.) currentOffset = RoundToNearestMultOf4(currentOffset); } }
public Viewer_WEM(WEMFile file) { InitializeComponent(); // Lets convert the wem file to wav real quick wavStream = new MemoryStream(); file.WriteWav(wavStream); wavStream.Seek(0, SeekOrigin.Begin); FileStream wavOUt = new FileStream("test.wav", FileMode.OpenOrCreate); byte[] data = wavStream.GetBuffer(); wavOUt.Write(data, 0, data.Length); wavOUt.Close(); wavStream.Seek(0, SeekOrigin.Begin); this.waveStream = new WaveFileReader(wavStream); }
/// <summary> /// Construct a new WEM Marshaller from a list of identities and the condensed byte array of every included WEM file. /// </summary> /// <param name="identities">The identity array.</param> /// <param name="condensedWEMFileArray">The WEM file identity.</param> public WEMMarshaller(WEMFileIdentity[] identities, byte[] condensedWEMFileArray) { IdentitiesInternal = identities; RawAllWEMFilesInternal = condensedWEMFileArray; WEMFilesInternal = new WEMFile[identities.Length]; // Convert the byte array to the list. List <byte> wemFileList = condensedWEMFileArray.ToList(); for (int idx = 0; idx < identities.Length; idx++) { WEMFileIdentity identity = identities[idx]; // FastSkip is a custom implementation of Skip optimized exclusively for List types. Compared to stock usage of Skip, FastSkip offers a >500% speed increase. // See ArrayUtil.FastSkip for credits. byte[] data = wemFileList.FastSkip((int)identity.Offset).Take((int)identity.Size).ToArray(); WEMFilesInternal[idx] = new WEMFile() { ID = identity.WemID, Data = data }; } }
static void Main(string[] args) { WEMFile wem = new WEMFile("LoL_MUSIC_TreelineINTRO.wem", WEMForcePacketFormat.NoForcePacketFormat); wem.GenerateOGG("LoL_MUSIC_TreelineINTRO.ogg", "packed_codebooks_aoTuV_603.bin", false, false); }
public static void ReplaceWEMFile(DIDXSection didx, string newFilePath) { WEMFile originWEM = null; //Get correct wem file foreach (WEMFile wem in didx.DIDXFiles) { if (wem.Num == indexNumber) { originWEM = wem; break; } } if (originWEM == null) { Console.WriteLine("Invalid index value"); Console.ReadKey(); Environment.Exit(1); } Console.WriteLine("Replacing " + "[" + originWEM.Num + "]" + " Position:" + originWEM.Position + " Size:" + originWEM.Size + " ID:" + originWEM.ID); //add 12 because 4 bytes => didxSize 8 bytes DataObject and Size long replacementOffset = didx.DIDXSectionPosition + 12 + didx.DIDXSectionSize + originWEM.Position; Console.WriteLine("Wem replacement offset:" + replacementOffset); byte[] data; using (Stream writeStream = File.OpenWrite(Path.GetFileNameWithoutExtension(filePath))) { using (Stream readStream = File.OpenRead(filePath)) { Console.WriteLine("Starting replacement..."); //Write BKHD and start of DIDX Section while (readStream.Position != didx.DIDXSectionPosition + 4) { data = new byte[4]; readStream.Read(data, 0, data.Length); writeStream.Write(data, 0, data.Length); } Console.WriteLine("Skipping..."); //Skip all unchanged files uint fileCount = 1; while (fileCount != originWEM.Num) { data = new byte[12]; readStream.Read(data, 0, data.Length); writeStream.Write(data, 0, data.Length); fileCount++; } Console.WriteLine("Creating entries..."); //Write our file size FileInfo newWemInfo = new FileInfo(wemPath); bool fileIsSmaller = false; long fileDifference = 0; if (newWemInfo.Length < originWEM.Size) { fileIsSmaller = true; fileDifference = originWEM.Size - newWemInfo.Length; } else { fileDifference = newWemInfo.Length - originWEM.Size; } //Copy ID data = new byte[4]; readStream.Read(data, 0, data.Length); writeStream.Write(data, 0, data.Length); //Copy Position data = new byte[4]; readStream.Read(data, 0, data.Length); writeStream.Write(data, 0, data.Length); //Write Size data = BitConverter.GetBytes((uint)newWemInfo.Length); writeStream.Write(data, 0, data.Length); //read stream to stay in sync readStream.Read(data, 0, data.Length); //Loop through DIDX files and arrange according files Console.WriteLine("Looping through DIDX"); long EndOfDIDXSection = readStream.Position + didx.DIDXSectionSize; while (readStream.Position < EndOfDIDXSection) { //Copy ID data = new byte[4]; readStream.Read(data, 0, data.Length); writeStream.Write(data, 0, data.Length); //Write Position data = new byte[4]; readStream.Read(data, 0, data.Length); uint oldPosition = BitConverter.ToUInt32(data, 0); //Calculate new position if (fileIsSmaller) { data = BitConverter.GetBytes(oldPosition - (uint)fileDifference); } else { data = BitConverter.GetBytes(oldPosition + (uint)fileDifference); } writeStream.Write(data, 0, data.Length); //Copy Size data = new byte[4]; readStream.Read(data, 0, data.Length); writeStream.Write(data, 0, data.Length); } Console.WriteLine("Writing DATA header..."); //Write DATA header data = new byte[4]; readStream.Read(data, 0, data.Length); writeStream.Write(data, 0, data.Length); //Change DATA Size data = new byte[4]; readStream.Read(data, 0, data.Length); uint oldSize = BitConverter.ToUInt32(data, 0); if (fileIsSmaller) { data = BitConverter.GetBytes(oldSize - (uint)fileDifference); } else { data = BitConverter.GetBytes(oldSize + (uint)fileDifference); } writeStream.Write(data, 0, data.Length); Console.WriteLine("Writing content..."); //Write content while (readStream.Position < replacementOffset) { data = new byte[1]; readStream.Read(data, 0, data.Length); writeStream.Write(data, 0, data.Length); } Console.WriteLine("Replacing .wem ..."); //Write our wem using (Stream readWEMStream = File.OpenRead(wemPath)) { while (readWEMStream.Position != newWemInfo.Length) { data = new byte[1]; readWEMStream.Read(data, 0, data.Length); writeStream.Write(data, 0, data.Length); } readWEMStream.Close(); } //Skip wem in readstream readStream.Position = readStream.Position + originWEM.Size; Console.WriteLine("Finnishing..."); //Write leftOver Content while (readStream.Position < readStream.Length) { data = new byte[1000]; int amount = readStream.Read(data, 0, data.Length); writeStream.Write(data, 0, amount); } readStream.Close(); } writeStream.Close(); Console.WriteLine("Done."); Console.ReadKey(); } }