Beispiel #1
0
        private void SaveMessageData()
        {
            VirtualFilesystemFile text_bank = m_MessageArchive.GetFileAtPath("zel_00.bmg");

            Encoding enc = Encoding.ASCII;

            switch (m_OriginalEncoding)
            {
            case TextEncoding.CP1252:
                enc = Encoding.GetEncoding(1252);
                break;

            case TextEncoding.Shift_JIS:
                enc = Encoding.GetEncoding(932);
                break;

            case TextEncoding.UTF_16:
                enc = Encoding.BigEndianUnicode;
                break;

            case TextEncoding.UTF_8:
                enc = Encoding.UTF8;
                break;
            }

            using (MemoryStream new_bmg_strm = new MemoryStream())
            {
                EndianBinaryWriter bmg_writer = new EndianBinaryWriter(new_bmg_strm, Endian.Big);
                bmg_writer.Write("MESGbmg1".ToCharArray());
                bmg_writer.Write(0);
                bmg_writer.Write(2);
                bmg_writer.Write((byte)m_OriginalEncoding);
                bmg_writer.Write(new byte[15]);

                using (MemoryStream text_data_strm = new MemoryStream())
                {
                    EndianBinaryWriter text_data_writer = new EndianBinaryWriter(text_data_strm, Endian.Big);
                    text_data_writer.Write((byte)0);

                    using (MemoryStream message_data_strm = new MemoryStream())
                    {
                        EndianBinaryWriter message_data_writer = new EndianBinaryWriter(message_data_strm, Endian.Big);

                        foreach (Message m in m_Messages)
                        {
                            m.Save(message_data_writer, text_data_writer, enc);
                        }

                        int delta = WMath.Pad16Delta(message_data_strm.Length);

                        bmg_writer.Write("INF1".ToCharArray());
                        bmg_writer.Write((uint)(message_data_strm.Length + 16 + delta));
                        bmg_writer.Write((ushort)m_Messages.Count);
                        bmg_writer.Write((ushort)0x18);
                        bmg_writer.Write(0);

                        bmg_writer.Write(message_data_strm.ToArray());

                        for (int i = 0; i < delta; i++)
                        {
                            bmg_writer.Write((byte)0);
                        }
                    }

                    // Seek to the end of the stream, and then pad us to 32-byte alignment.
                    text_data_strm.Seek(0, SeekOrigin.End);
                    int pad32delta = WMath.Pad32Delta(text_data_strm.Position + 8);
                    for (int i = 0; i < pad32delta; i++)
                    {
                        text_data_writer.Write((byte)0x00);
                    }

                    bmg_writer.Write("DAT1".ToCharArray());
                    bmg_writer.Write((uint)text_data_strm.Length + 8);

                    bmg_writer.Write(text_data_strm.ToArray());
                }

                text_bank.Data = new_bmg_strm.ToArray();
            }

            m_IsDataDirty = false;
            OnPropertyChanged("WindowTitle");
        }