Exemplo n.º 1
0
        /// <summary>
        ///     Load a single bundle
        /// </summary>
        /// <param name="filename"></param>
        public void LoadBundle(string filename)
        {
            try
            {
                if (Speeches.ContainsKey(filename))
                {
                    return;
                }

                var speech = Coder.Decode(new W3Speech(filename), new System.IO.BinaryReader(new FileStream(filename, FileMode.Open)));

                foreach (var item in speech.item_infos)
                {
                    if (!Items.ContainsKey(item.Name))
                    {
                        Items.Add(item.Name, new List <IWitcherFile>());
                    }

                    Items[item.Name].Add(item);
                }

                Speeches.Add(filename, speech);
            }
            catch (Exception e)
            {
                //TODO: Log
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Load a single bundle
        /// </summary>
        /// <param name="filename"></param>
        private void LoadBundle(string filename)
        {
            try
            {
                if (Speeches.ContainsKey(filename))
                {
                    return;
                }

                var speech = Coder.Decode(new W3Speech(filename), new System.IO.BinaryReader(new FileStream(filename, FileMode.Open)));

                foreach (var item in speech.item_infos)
                {
                    if (!Items.ContainsKey(item.Name))
                    {
                        Items.Add(item.Name, new List <IWitcherFile>());
                    }

                    Items[item.Name].Add(item);
                }

                Speeches.Add(filename, speech);
            }
#pragma warning disable CS0169 // ~~~[[maybe_unused]] c++ compiler attribute
#pragma warning disable CS0168
#pragma warning disable IDE0051
            catch (Exception ex)
#pragma warning restore CS0169 // ~~~[[maybe_unused]] c++ compiler attribute
#pragma warning restore CS0168
#pragma warning restore IDE0051
            {
                //TODO: Log
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parse the w3speech file to input pairs.
        /// </summary>
        /// <param name="w3speech_file_path">The path to the w3speech file.</param>
        /// <returns>All wem and cr2w pairs found in the file.</returns>
        /// <exception cref="Exception">Something happened.</exception>
        public static IEnumerable <WemCr2wInputPair> CollectW3SpeechFile(String w3speech_file_path)
        {
            var w3speech_stream = new BinaryReader(new FileStream(w3speech_file_path, FileMode.Open));
            var info            = Coder.Decode(new W3Speech(w3speech_file_path), w3speech_stream);

            w3speech_stream.Close();
            return(info.item_infos.Select(item_info =>
                                          new WemCr2wInputPair(item_info.id, item_info.id_high, () =>
            {
                var reader = new BinaryReader(new FileStream(w3speech_file_path, FileMode.Open));
                reader.BaseStream.Seek(item_info.wem_offs, SeekOrigin.Begin);
                return reader.BaseStream;
            }, item_info.wem_size, item_info.duration, () =>
            {
                var reader = new BinaryReader(new FileStream(w3speech_file_path, FileMode.Open));
                reader.BaseStream.Seek(item_info.cr2w_offs, SeekOrigin.Begin);
                return reader.BaseStream;
            }, item_info.cr2w_size)
                                          ).ToList().AsReadOnly());
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Load a single mod bundle
        /// </summary>
        /// <param name="filename">
        ///     file to process
        /// </param>
        public void LoadModBundle(string filename)
        {
            if (Speeches.ContainsKey(filename))
            {
                return;
            }

            var speech = Coder.Decode(new W3Speech(filename), new System.IO.BinaryReader(new FileStream(filename, FileMode.Open)));

            foreach (var item in speech.item_infos)
            {
                if (!Items.ContainsKey(GetModFolder(filename) + "\\" + item.Name))
                {
                    Items.Add(GetModFolder(filename) + "\\" + item.Name, new List <IWitcherFile>());
                }

                Items[GetModFolder(filename) + "\\" + item.Name].Add(item);
            }

            Speeches.Add(filename, speech);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Unpacks the w3speech file into the directory.
        /// </summary>
        /// <param name="directory">The directory where the new wem and cr2w files will be unpacked into.</param>
        /// <param name="w3speech_file">The w3speech file to unpack.</param>
        /// <param name="languages">Information about the known languages. The right one will be selected automatically.</param>
        /// <exception cref="Exception">Something happened.</exception>
        public static void UnpackW3SpeechFile(String directory, String w3speech_file, IEnumerable <W3Language> languages)
        {
            var input    = new BinaryReader(new FileStream(w3speech_file, FileMode.Open));
            var info     = Coder.Decode(new W3Speech(w3speech_file), input);
            var language = languages.First(lang => lang.Key.value == info.language_key.value);
            var dir      = directory.EndsWith("\\") ? directory : directory + "\\";

            info.item_infos.ToList().ForEach(item =>
            {
                var neutral_id    = LanguageTools.Convert(item.id, language);
                var wem_file_name = neutral_id.value.ToString("D10") + "[" + item.duration.ToString("R", CultureInfo.InvariantCulture) + "](" + item.id_high.ToString("D10") + ").wem";
                var wem_output    = new BinaryWriter(new FileStream(dir + wem_file_name, FileMode.Create));
                input.BaseStream.Seek((int)item.wem_offs, SeekOrigin.Begin);
                StreamTools.Transfer(item.wem_size, input.BaseStream, wem_output.BaseStream);
                wem_output.Close();

                var cr2w_file_name = neutral_id.value.ToString("D10") + "(" + item.id_high.ToString("D10") + ").cr2w";
                var cr2w_output    = new BinaryWriter(new FileStream(dir + cr2w_file_name, FileMode.Create));
                input.BaseStream.Seek((int)item.cr2w_offs, SeekOrigin.Begin);
                StreamTools.Transfer(item.cr2w_size, input.BaseStream, cr2w_output.BaseStream);
                cr2w_output.Close();
            });
            input.Close();
        }