示例#1
0
 public static string ReadSizedString(this Stream s, int count, GameTextEncoding encoding)
 {
     switch (encoding)
     {
     case GameTextEncoding.ASCII: return(ReadAscii(s, count));
     }
     throw new Exception("Reading sized string not implemented for encoding " + encoding.ToString());
 }
示例#2
0
 public static void WriteNulltermString(this Stream s, string str, GameTextEncoding encoding)
 {
     switch (encoding)
     {
     case GameTextEncoding.UTF8: WriteUTF8Nullterm(s, str); return;
     }
     throw new Exception("Writing nullterminated string not implemented for encoding " + encoding.ToString());
 }
示例#3
0
        public static string ReadNulltermString(this Stream s, GameTextEncoding encoding)
        {
            switch (encoding)
            {
            case GameTextEncoding.ASCII: return(ReadAsciiNullterm(s));

            case GameTextEncoding.ShiftJIS: return(ReadShiftJisNullterm(s));

            case GameTextEncoding.UTF8: return(ReadUTF8Nullterm(s));

            case GameTextEncoding.UTF16: return(ReadUTF16Nullterm(s));
            }
            throw new Exception("Reading nullterminated string not implemented for encoding " + encoding.ToString());
        }
示例#4
0
        public static string ReadNulltermStringFromLocationAndReset(this Stream s, long location, GameTextEncoding encoding)
        {
            long pos = s.Position;

            s.Position = location;
            string str = s.ReadNulltermString(encoding);

            s.Position = pos;
            return(str);
        }
示例#5
0
        public System.IO.Stream WriteToScs(Endianness endian = Endianness.BigEndian, Bitness bits = Bitness.B32, GameTextEncoding encoding = GameTextEncoding.ShiftJIS)
        {
            System.IO.Stream stream     = new System.IO.MemoryStream();
            uint             entryCount = (uint)Entries.Count;

            stream.WriteUInt32(entryCount.ToEndian(endian));
            for (uint i = 0; i < entryCount; ++i)
            {
                stream.WriteUInt32(0);                 // reserve space
            }
            List <long> positions = new List <long>();

            for (uint i = 0; i < entryCount; ++i)
            {
                string s = Entries[(int)i];
                if (s != null)
                {
                    positions.Add(stream.Position);
                    stream.WriteNulltermString(s, encoding);
                }
                else
                {
                    positions.Add(0);
                }
            }
            stream.Position = 4;
            for (uint i = 0; i < entryCount; ++i)
            {
                stream.WriteUInt32(((uint)positions[(int)i]).ToEndian(endian));
            }
            stream.Position = 0;
            return(stream);
        }
示例#6
0
        public SCS(DuplicatableStream stream, Endianness endian = Endianness.BigEndian, Bitness bits = Bitness.B32, GameTextEncoding encoding = GameTextEncoding.ShiftJIS)
        {
            ulong entryCount = stream.ReadUInt(bits, endian);

            Entries = new List <string>((int)entryCount);
            for (uint i = 0; i < entryCount; ++i)
            {
                ulong offset = stream.ReadUInt(bits, endian);
                if (offset != 0)
                {
                    Entries.Add(stream.ReadNulltermStringFromLocationAndReset(offset, encoding));
                }
                else
                {
                    Entries.Add(null);
                }
            }
        }
示例#7
0
 public SCS(string filename, Endianness endian = Endianness.BigEndian, Bitness bits = Bitness.B32, GameTextEncoding encoding = GameTextEncoding.ShiftJIS)
     : this(new DuplicatableFileStream(filename), endian, bits, encoding)
 {
 }