Esempio n. 1
0
        public static WwiseIndex Load(Stream input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            uint magic = input.ReadValueU32(Endian.Little);

            if (magic != 0x58444957 &&
                magic.Swap() != 0x58444957)
            {
                throw new FormatException("invalid magic");
            }
            Endian endian = magic == 0x58444957 ? Endian.Little : Endian.Big;

            uint version = input.ReadValueU32(endian);

            if (version != 1)
            {
                throw new FormatException("unexpected version");
            }

            var reader = new FileReader(input, version, endian);

            var index = new WwiseIndex();

            index.Serialize(reader);
            return(index);
        }
Esempio n. 2
0
        private void OnLoad(object sender, EventArgs e)
        {
            string exePath = GetExecutablePath();

            string path =
                (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\BioWare\Mass Effect 3", "Install Dir", null) ??
                (string)
                Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\BioWare\Mass Effect 3", "Install Dir", null);

            if (path != null)
            {
                path         = Path.Combine(path, "BioGame");
                path         = Path.Combine(path, "CookedPCConsole");
                _PackagePath = path;
            }
            else
            {
                _PackagePath = null;
            }

            string converterPath = Path.Combine(exePath, "ww2ogg.exe");

            if (File.Exists(converterPath) == false)
            {
                convertCheckBox.Checked = false;
                convertCheckBox.Enabled = false;
                LogError("ww2ogg.exe is not present in \"{0}\"!", exePath);
            }
            else
            {
                _ConverterPath = converterPath;
            }

            string revorbPath = Path.Combine(exePath, "revorb.exe");

            if (File.Exists(revorbPath) == false)
            {
                revorbCheckBox.Checked = false;
                revorbCheckBox.Enabled = false;
            }
            else
            {
                _RevorbPath = revorbPath;
            }

            ToggleControls(false);

            string indexPath = Path.Combine(exePath, "Wwise.idx");

            if (File.Exists(indexPath) == false)
            {
                LogError("Wwise.idx is not present in \"{0}\"!", exePath);
            }
            else
            {
                LogMessage("Loading Wwise index...");

                TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();

                DateTime startTime = DateTime.Now;

                Task <List <WwiseLocation> > task = Task <List <WwiseLocation> > .Factory.StartNew(
                    () =>
                {
                    using (FileStream input = File.OpenRead(indexPath))
                    {
                        WwiseIndex index = WwiseIndex.Load(input);
                        if (input.Position != input.Length)
                        {
                            throw new FormatException("did not consume entire file");
                        }

                        var locations = new List <WwiseLocation>();
                        foreach (var resource in index.Resources)
                        {
                            WwiseIndex.Instance firstInstance = resource.Instances
                                                                .OrderByDescending(i => i.IsPackage == false)
                                                                .First();

                            var location = new WwiseLocation
                            {
                                Hash      = resource.Hash,
                                Path      = index.Strings[firstInstance.PathIndex],
                                Name      = index.Strings[firstInstance.NameIndex],
                                Actor     = index.Strings[firstInstance.ActorIndex],
                                Group     = index.Strings[firstInstance.GroupIndex],
                                Locale    = index.Strings[firstInstance.LocaleIndex],
                                File      = index.Strings[firstInstance.FileIndex],
                                IsPackage = firstInstance.IsPackage,
                                Offset    = firstInstance.Offset,
                                Size      = firstInstance.Size,
                            };

                            foreach (var instance in resource.Instances.Except(new[]
                            {
                                firstInstance
                            }))
                            {
                                location.Duplicates.Add(new WwiseLocation
                                {
                                    Hash      = resource.Hash,
                                    Path      = index.Strings[instance.PathIndex],
                                    Name      = index.Strings[instance.NameIndex],
                                    Actor     = index.Strings[instance.ActorIndex],
                                    Group     = index.Strings[instance.GroupIndex],
                                    Locale    = index.Strings[instance.LocaleIndex],
                                    File      = index.Strings[instance.FileIndex],
                                    IsPackage = instance.IsPackage,
                                    Offset    = instance.Offset,
                                    Size      = instance.Size,
                                });
                            }

                            locations.Add(location);
                        }

                        return(locations);
                    }
                });

                task.ContinueWith(
                    t =>
                {
                    TimeSpan elapsed = DateTime.Now.Subtract(startTime);
                    LogSuccess("Loaded Wwise index in {0}m {1}s {2}ms",
                               elapsed.Minutes,
                               elapsed.Seconds,
                               elapsed.Milliseconds);
                    LogMessage("{0} entries ({1} duplicates)",
                               t.Result.Count,
                               t.Result.Sum(i => i.Duplicates.Count));
                    OnWwiseIndexLoaded(t.Result);
                },
                    CancellationToken.None,
                    TaskContinuationOptions.OnlyOnRanToCompletion,
                    uiScheduler);

                task.ContinueWith(
                    t =>
                {
                    LogError("Failed to load Wwise index.");
                    if (t.Exception != null)
                    {
                        if (t.Exception.InnerException != null)
                        {
                            LogError(t.Exception.InnerException.ToString());
                        }
                        else
                        {
                            LogError(t.Exception.ToString());
                        }
                    }
                },
                    CancellationToken.None,
                    TaskContinuationOptions.OnlyOnFaulted,
                    uiScheduler);
            }
        }