Beispiel #1
0
        public override void Save(string fileName, byte[] originalContent, IList <TFString> strings,
                                  ExportOptions options)
        {
            File.WriteAllBytes(fileName, originalContent);

            var writeOffset = _firstStringOffset + _strings[0].RelativeOffset;

            using (var fs = new FileStream(fileName, FileMode.Open))
            {
                foreach (var item in _strings)
                {
                    fs.Seek(item.RelativeOffsetPosition, SeekOrigin.Begin);
                    fs.WriteValueS32(writeOffset - _firstStringOffset);

                    fs.Seek(writeOffset, SeekOrigin.Begin);
                    var str = item.Data.Translation;

                    if (item.Data.Visible && !string.IsNullOrEmpty(str))
                    {
                        if (options.CharReplacement != 0)
                        {
                            str = Utils.ReplaceChars(str, options.CharReplacementList);
                        }

                        str = SAOProject.WritingReplacements(str);

                        fs.WriteStringZ(str, options.SelectedEncoding);

                        writeOffset += str.GetLength(options.SelectedEncoding) + 1;
                    }
                    else
                    {
                        fs.WriteStringZ(item.Data.Original);
                        writeOffset = item.Data.Original.GetLength(options.SelectedEncoding) + 1;
                    }
                }

                var strSize = (uint)(fs.Position - _firstStringOffset);

                while (fs.Position % 4 != 0)
                {
                    fs.WriteValueU8(0);
                }

                fs.Seek(0x0C, SeekOrigin.Begin);
                fs.WriteValueU32(strSize, Endianness);
            }
        }
Beispiel #2
0
        private int WriteStrings(Stream s, IList <TFString> strings, ExportOptions options, Ofs3Data file)
        {
            int result   = 0;
            var tfString = strings.FirstOrDefault(x => x.Offset == file.StartOffset);

            if (tfString != null)
            {
                var str = tfString.Translation;

                if (tfString.Visible && !string.IsNullOrEmpty(str))
                {
                    if (options.CharReplacement != 0)
                    {
                        str = Utils.ReplaceChars(str, options.CharReplacementList);
                    }

                    str = SAOProject.WritingReplacements(str);

                    s.WriteStringZ(str, options.SelectedEncoding);

                    result = str.GetLength(options.SelectedEncoding) + 1;
                }
                else
                {
                    s.WriteStringZ(tfString.Original, options.SelectedEncoding);

                    result = tfString.Original.GetLength(options.SelectedEncoding) + 1;
                }

                while (s.Position % file.Padding != 0)
                {
                    s.WriteValueU8(0);

                    result++;
                }
            }

            return(result);
        }