Пример #1
0
        private void ExtractBankToWav(SoundplorerExport spExport, string location = null)
        {
            if (spExport != null && spExport.Export.ClassName == "WwiseBank")
            {
                WwiseBank wb = new WwiseBank(spExport.Export);
                var       embeddedWEMFiles = wb.GetWEMFilesMetadata();
                if (embeddedWEMFiles.Count > 0)
                {
                    if (location == null)
                    {
                        var dlg = new CommonOpenFileDialog("Select output folder")
                        {
                            IsFolderPicker = true
                        };

                        if (dlg.ShowDialog() != CommonFileDialogResult.Ok)
                        {
                            return;
                        }
                        location = dlg.FileName;
                    }

                    var data = wb.GetChunk("DATA");
                    if (embeddedWEMFiles.Count > 0)
                    {
                        foreach (var singleWemMetadata in embeddedWEMFiles)
                        {
                            byte[] wemData = new byte[singleWemMetadata.Item3];
                            //copy WEM data to buffer. Add 0x8 to skip DATA and DATASIZE header for this block.
                            Buffer.BlockCopy(data, singleWemMetadata.Item2 + 0x8, wemData, 0, singleWemMetadata.Item3);
                            //check for RIFF header as some don't seem to have it and are not playable.
                            string wemHeader = "" + (char)wemData[0] + (char)wemData[1] + (char)wemData[2] + (char)wemData[3];
                            string wemName   = spExport.Export.ObjectName + "_0x" + singleWemMetadata.Item1.ToString("X8");

                            if (wemHeader == "RIFF")
                            {
                                EmbeddedWEMFile wem        = new EmbeddedWEMFile(wemData, wemName, spExport.Export.FileRef.Game); //will correct truncated stuff
                                Stream          waveStream = soundPanel.getPCMStream(forcedWemFile: wem);
                                if (waveStream != null && waveStream.Length > 0)
                                {
                                    string outputname = wemName + ".wav";
                                    string outpath    = System.IO.Path.Combine(location, outputname);
                                    using (var fileStream = File.Create(outpath))
                                    {
                                        waveStream.Seek(0, SeekOrigin.Begin);
                                        waveStream.CopyTo(fileStream);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
 public void LoadData()
 {
     if (Export.ClassName == "WwiseStream")
     {
         WwiseStream w       = new WwiseStream(Export);
         string      afcPath = w.getPathToAFC();
         if (afcPath == "")
         {
             SubText = "Could not find AFC";
         }
         else
         {
             TimeSpan?time = w.GetSoundLength();
             if (time != null)
             {
                 //here backslash must be present to tell that parser colon is
                 //not the part of format, it just a character that we want in output
                 SubText = time.Value.ToString(@"mm\:ss\:fff");
             }
             else
             {
                 SubText = "Error getting length, may be unsupported";
             }
         }
         NeedsLoading = false;
         Icon         = FontAwesomeIcon.VolumeUp;
     }
     if (Export.ClassName == "WwiseBank")
     {
         WwiseBank wb = new WwiseBank(Export);
         var       embeddedWEMFiles = wb.GetWEMFilesMetadata();
         SubText      = embeddedWEMFiles.Count() + " embedded WEM" + (embeddedWEMFiles.Count() != 1 ? "s" : "");
         NeedsLoading = false;
         Icon         = FontAwesomeIcon.University;
     }
 }
Пример #3
0
        public override void LoadExport(IExportEntry exportEntry)
        {
            ExportInformationList.Clear();
            AllWems.Clear();
            //Check if we need to first gather wwiseevents for wem IDing
            //Uncomment when HIRC stuff is implemented, if ever...

            /*if (exportEntry.FileRef != CurrentPackage)
             * {
             *  //update
             *  WemIdsToWwwiseEventIdMapping.Clear();
             *  List<IExportEntry> wwiseEventExports = exportEntry.FileRef.Exports.Where(x => x.ClassName == "WwiseEvent").ToList();
             *  foreach (IExportEntry wwiseEvent in wwiseEventExports)
             *  {
             *      StructProperty relationships = wwiseEvent.GetProperty<StructProperty>("Relationships");
             *      IntProperty id = wwiseEvent.GetProperty<IntProperty>("Id");
             *      FloatProperty DurationMilliseconds = wwiseEvent.GetProperty<FloatProperty>("DurationMilliseconds");
             *
             *      if (relationships != null)
             *      {
             *          ObjectProperty bank = relationships.GetProp<ObjectProperty>("Bank");
             *          if (bank != null && bank.Value > 0)
             *          {
             *              //export in this file
             *              List<Tuple<string, int, double>> bankWemInfosList;
             *              Tuple<string, int, double> newData = new Tuple<string, int, double>(wwiseEvent.ObjectName, id.Value, DurationMilliseconds.Value);
             *              if (WemIdsToWwwiseEventIdMapping.TryGetValue(exportEntry.FileRef.Exports[bank.Value - 1], out bankWemInfosList))
             *              {
             *                  bankWemInfosList.Add(newData);
             *              }
             *              else
             *              {
             *                  WemIdsToWwwiseEventIdMapping[exportEntry.FileRef.Exports[bank.Value - 1]] = new List<Tuple<string, int, double>>();
             *                  WemIdsToWwwiseEventIdMapping[exportEntry.FileRef.Exports[bank.Value - 1]].Add(newData);
             *              }
             *          }
             *      }
             *  }
             *
             * }
             * CurrentPackage = exportEntry.FileRef;*/
            ExportInformationList.Add("#" + exportEntry.Index + " " + exportEntry.ClassName + " : " + exportEntry.ObjectName);
            if (exportEntry.ClassName == "WwiseStream")
            {
                WwiseStream w = new WwiseStream(exportEntry);
                ExportInformationList.Add("Filename : " + (w.FileName ?? "Stored in this PCC"));
                ExportInformationList.Add("Data size: " + w.DataSize + " bytes");
                ExportInformationList.Add("Data offset: 0x" + w.DataOffset.ToString("X8"));
                string wemId = "ID: 0x" + w.Id.ToString("X8");
                if (Properties.Settings.Default.SoundplorerReverseIDDisplayEndianness)
                {
                    wemId += $" | 0x{ReverseBytes((uint)w.Id).ToString("X8")} (Reversed)";
                }
                ExportInformationList.Add(wemId);
                CurrentLoadedExport = exportEntry;
            }
            if (exportEntry.ClassName == "WwiseBank")
            {
                WwiseBank wb = new WwiseBank(exportEntry);
                var       embeddedWEMFiles = wb.GetWEMFilesMetadata();
                var       data             = wb.GetChunk("DATA");
                int       i = 0;
                if (embeddedWEMFiles.Count > 0)
                {
                    foreach (var singleWemMetadata in embeddedWEMFiles)
                    {
                        byte[] wemData = new byte[singleWemMetadata.Item3];
                        //copy WEM data to buffer. Add 0x8 to skip DATA and DATASIZE header for this block.
                        Buffer.BlockCopy(data, singleWemMetadata.Item2 + 0x8, wemData, 0, singleWemMetadata.Item3);
                        //check for RIFF header as some don't seem to have it and are not playable.
                        string wemHeader = "" + (char)wemData[0] + (char)wemData[1] + (char)wemData[2] + (char)wemData[3];

                        string wemId = singleWemMetadata.Item1.ToString("X8");
                        if (Properties.Settings.Default.SoundplorerReverseIDDisplayEndianness)
                        {
                            wemId = ReverseBytes(singleWemMetadata.Item1).ToString("X8") + " (Reversed)";
                        }
                        string wemName = "Embedded WEM 0x" + wemId;// + "(" + singleWemMetadata.Item1 + ")";

                        /* //HIRC lookup, if I ever get around to supporting HIRC
                         * List<Tuple<string, int, double>> wemInfo;
                         * if (WemIdsToWwwiseEventIdMapping.TryGetValue(exportEntry, out wemInfo))
                         * {
                         *  var info = wemInfo.FirstOrDefault(x => x.Item2 == singleWemMetadata.Item1); //item2 in x = ID, singleWemMetadata.Item1 = ID
                         *  if (info != null)
                         *  {
                         *      //have info
                         *      wemName = info.Item1;
                         *  }
                         * }*/
                        EmbeddedWEMFile wem = new EmbeddedWEMFile(wemData, i + ": " + wemName, exportEntry.FileRef.Game, singleWemMetadata.Item1);
                        if (wemHeader == "RIFF")
                        {
                            ExportInformationList.Add(wem);
                        }
                        else
                        {
                            ExportInformationList.Add(i + ": " + wemName + " - No RIFF header");
                        }
                        AllWems.Add(wem);
                        i++;
                    }
                }
                else
                {
                    ExportInformationList.Add("This soundbank has no embedded WEM files");
                }
                CurrentLoadedExport = exportEntry;
            }
        }