Пример #1
0
        /*
         * 4 bytes for id (String), usually CPSW
         * 4 bytes for version (Number), usually A2 00 00 00 or A3 00 00 00
         * 2 bytes for key1 (Number), part of the language key
         * variable amount of bytes for wavecr2w pair count
         * for each wemcr2w pair:
         *  4 bytes for language specific id (Number)
         *  4 bytes for some other id (Number)
         *  4 bytes for absolute offset (Number), points at (a) down below
         *  4 bytes of zeros
         *  4 bytes of (wem size + 12) (Number) (c)
         *  4 bytes of zeros
         *  4 bytes for absolute offset (Number), points at (b) down below
         *  4 bytes of zeros
         *  4 bytes of cr2w size (Number) (d)
         *  4 bytes of zeros
         * 2 bytes for key2 (Number), part of the language key
         * for each wemcr2w pair:
         *  4 bytes for wem size (Number) (a)
         *  c - 12 bytes for wem (raw data)
         *  4 bytes for duration in seconds (Float)
         *  4 bytes of 04 00 00 00
         *  d bytes for cr2w (raw data) (b)
         */

        /// <summary>
        /// Parse information about the w3speech format from the BinaryReader.
        /// </summary>
        /// <param name="br">The stream containing the w3speech format to read from.</param>
        /// <returns>All information found inside the stream.</returns>
        /// <exception cref="Exception">Something happened.</exception>
        public static W3Speech Decode(IGameArchive parent, BinaryReader br)
        {
            var str            = System.Text.Encoding.Default.GetString(br.ReadBytes(4));
            var version        = br.ReadUInt32();
            var key1           = br.ReadUInt16();
            var item_count     = br.ReadBit6();
            var raw_item_infos = new List <Tuple <uint, uint, uint, uint, uint, uint> >();

            for (var i = 0; i < item_count.value; i += 1)
            {
                var lang_specific_ID = br.ReadUInt32();
                var id_high          = br.ReadUInt32();
                var wave_offs        = br.ReadUInt32() + 4;
                br.ReadUInt32();
                var wave_size = br.ReadUInt32() - 12;
                br.ReadUInt32();
                var cr2w_offs = br.ReadUInt32();
                br.ReadUInt32();
                var cr2w_size = br.ReadUInt32();
                br.ReadUInt32();
                raw_item_infos.Add(Tuple.Create(lang_specific_ID, id_high, wave_offs, wave_size, cr2w_offs, cr2w_size));
            }
            var key2       = br.ReadUInt16(); //BUG: This break sometimes! "D:\\SteamLibrary\\steamapps\\common\\TW3\\bin\\x64\\..\\..\\DLC\\DLC1\\content\\brpc.w3speech"
            var key        = new W3LanguageKey((UInt32)(key1 << 16 | key2));
            var position   = 4 + 4 + 2 + ((UInt64)item_count.length) + ((UInt64)item_count.value * 10 * 4) + 2;
            var item_infos = raw_item_infos
                             .OrderBy(t => t.Item3)
                             .Select(t =>
            {
                var duration_offset = t.Item3 - position + t.Item4;
                StreamTools.Skip(duration_offset, br.BaseStream);
                position    += duration_offset;
                var duration = br.ReadSingle();
                position    += 4;
                return(new SpeechEntry(parent, new LanguageSpecificID(t.Item1), t.Item2, t.Item3, t.Item4, t.Item5, t.Item6, duration));
            })
                             .ToList()
                             .AsReadOnly();

            return(new W3Speech(parent.ArchiveAbsolutePath, str, version, key, item_infos));
        }
Пример #2
0
        /*
         * 4 bytes for id (String), usually CPSW
         * 4 bytes for version (Number), usually A2 00 00 00 or A3 00 00 00
         * 2 bytes for key1 (Number), part of the language key
         * variable amount of bytes for wavecr2w pair count
         * for each wemcr2w pair:
         *  4 bytes for language specific id (Number)
         *  4 bytes for some other id (Number)
         *  4 bytes for absolute offset (Number), points at (a) down below
         *  4 bytes of zeros
         *  4 bytes of (wem size + 12) (Number) (c)
         *  4 bytes of zeros
         *  4 bytes for absolute offset (Number), points at (b) down below
         *  4 bytes of zeros
         *  4 bytes of cr2w size (Number) (d)
         *  4 bytes of zeros
         * 2 bytes for key2 (Number), part of the language key
         * for each wemcr2w pair:
         *  4 bytes for wem size (Number) (a)
         *  c - 12 bytes for wem (raw data)
         *  4 bytes for duration in seconds (Float)
         *  4 bytes of 04 00 00 00
         *  d bytes for cr2w (raw data) (b)
         */

        /// <summary>
        /// Parse information about the w3speech format from the BinaryReader.
        /// </summary>
        /// <param name="br">The stream containing the w3speech format to read from.</param>
        /// <returns>All information found inside the stream.</returns>
        /// <exception cref="Exception">Something happened.</exception>
        public static Info Decode(BinaryReader br)
        {
            var str            = System.Text.Encoding.Default.GetString(br.ReadBytes(4));
            var version        = br.ReadUInt32();
            var key1           = br.ReadUInt16();
            var item_count     = br.ReadBit6();
            var raw_item_infos = new List <Tuple <uint, uint, uint, uint, uint, uint> >();

            for (var i = 0; i < item_count.value; i += 1)
            {
                var lang_specific_ID = br.ReadUInt32();
                var id_high          = br.ReadUInt32();
                var wave_offs        = br.ReadUInt32() + 4;
                br.ReadUInt32();
                var wave_size = br.ReadUInt32() - 12;
                br.ReadUInt32();
                var cr2w_offs = br.ReadUInt32();
                br.ReadUInt32();
                var cr2w_size = br.ReadUInt32();
                br.ReadUInt32();
                raw_item_infos.Add(Tuple.Create(lang_specific_ID, id_high, wave_offs, wave_size, cr2w_offs, cr2w_size));
            }
            var key2       = br.ReadUInt16();
            var key        = new W3LanguageKey((UInt32)(key1 << 16 | key2));
            var position   = 4 + 4 + 2 + ((UInt64)item_count.length) + ((UInt64)item_count.value * 10 * 4) + 2;
            var item_infos = raw_item_infos
                             .OrderBy(t => t.Item3)
                             .Select(t =>
            {
                var duration_offset = t.Item3 - position + t.Item4;
                StreamTools.Skip(duration_offset, br.BaseStream);
                position    += duration_offset;
                var duration = br.ReadSingle();
                position    += 4;
                return(new ItemInfo(new LanguageSpecificID(t.Item1), t.Item2, t.Item3, t.Item4, t.Item5, t.Item6, duration));
            })
                             .ToList()
                             .AsReadOnly();

            return(new Info(str, version, key, item_infos));
        }