public WwiseSoundbank(Stream s)
        {
            while (s.Position < s.Length)
            {
                SectionId sectionId = (SectionId)s.ReadUInt32();
                uint      length    = s.ReadUInt32();
                byte[]    data      = new byte[length];
                s.Read(data, 0, (int)length);

                switch (sectionId)
                {
                case SectionId.BKHD:
                    BKHDSection bkhd = new BKHDSection(data);
                    Sections.Add(bkhd);
                    break;

                case SectionId.ENVS:
                    ENVSSection envs = new ENVSSection(data);
                    Sections.Add(envs);
                    break;

                case SectionId.HIRC:
                    HIRCSection hirc = new HIRCSection(data);
                    Sections.Add(hirc);
                    break;

                case SectionId.STMG:
                    STMGSection stmg = new STMGSection(data);
                    Sections.Add(stmg);
                    break;

                default:
                    throw new NotImplementedException("Unknown section: " + sectionId.ToString());
                }
            }
        }
示例#2
0
        public WwiseReader(BinaryReader reader)
        {
            AKPKSection akpkSection = null;
            DIDXSection didxSection = null;
            DATASection dataSection = null;
            HIRCSection hircSection = null;
            STIDSection stidSection = null;
            //STMGSection stmgSection = null;
            PLATSection platSection = null;

            AudioFiles = new Dictionary <string, byte[]>();

            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                uint SectionIdentifier = reader.ReadUInt32();
                uint SectionLength     = reader.ReadUInt32();
                long Position          = reader.BaseStream.Position;
                switch (SectionIdentifier)
                {
                case _AKPK_ID:
                    akpkSection = new AKPKSection(reader);
                    break;

                case _BKHD_ID:
                    BKHDSection _A = new BKHDSection(reader);
                    break;

                case _INIT_ID:
                    INITSection _B = new INITSection(reader);
                    break;

                case _DIDX_ID:
                    didxSection = new DIDXSection(reader, Position + SectionLength);
                    break;

                case _DATA_ID:
                    if (didxSection != null)
                    {
                        dataSection = new DATASection(reader, Position, didxSection);
                    }
                    break;

                case _HIRC_ID:
                    hircSection = new HIRCSection(reader);
                    break;

                case _STID_ID:
                    stidSection = new STIDSection(reader);
                    break;

                case _STMG_ID:
                    //stmgSection = new STMGSection(reader); //broken
                    break;

                case _ENVS_ID:
                    break;

                case _PLAT_ID:
                    platSection = new PLATSection(reader);
                    break;

#if DEBUG
                default:
                    System.Diagnostics.Debug.WriteLine($"Unknown section 0x{SectionIdentifier:X} at {Position - sizeof(uint) - sizeof(uint)}");
                    break;
#endif
                }

                if (reader.BaseStream.Position != Position + SectionLength)
                {
#if DEBUG
                    System.Diagnostics.Debug.WriteLine($"Didn't read 0x{SectionIdentifier:X} correctly (at {reader.BaseStream.Position}, should be {Position + SectionLength})");
#endif
                    reader.BaseStream.Seek(Position + SectionLength, SeekOrigin.Begin);
                }
            }

            if (didxSection != null && dataSection != null && didxSection.WemFilesRef.Count == dataSection.WemFiles.Count)
            {
                for (int i = 0; i < didxSection.WemFilesRef.Count; i++)
                {
                    string key = $"{didxSection.WemFilesRef[i].Id}.wem";
                    if (stidSection != null && stidSection.SoundBanks.TryGetValue(didxSection.WemFilesRef[i].Id, out string name))
                    {
                        key = $"{name}.wem";
                    }
                    else if (FModel.Globals.Game.ActualGame == FModel.EGame.Valorant && ValoloWwiseDict.ValorantWemToName.TryGetValue(didxSection.WemFilesRef[i].Id, out string hardcodedname))
                    {
                        key = $"{hardcodedname}.wem";
                    }

                    AudioFiles[key] = dataSection.WemFiles[i];
                }
            }
            if (akpkSection != null)
            {
                foreach (var folder in akpkSection.Folders)
                {
                    foreach (var entry in folder.Entries)
                    {
                        if (!entry.IsSoundBank && entry.Data != null)
                        {
                            string key = $"{entry.Path.ToUpper()}_{entry.NameHash}.wem";
                            if (stidSection != null && stidSection.SoundBanks.TryGetValue(entry.NameHash, out string name))
                            {
                                key = $"{name}.wem";
                            }
                            else if (FModel.Globals.Game.ActualGame == FModel.EGame.Valorant && ValoloWwiseDict.ValorantWemToName.TryGetValue(entry.NameHash, out string hardcodedname))
                            {
                                key = $"{hardcodedname}.wem";
                            }

                            AudioFiles[key] = entry.Data;
                        }
                    }
                }
            }
            // valorant event sound uses the HIRCSection but i don't understand how to get the actual audio from it atm
        }