Beispiel #1
0
        public override void Write(ByteBuilder bb)
        {
            Address = (ushort)bb.Position;
            bb.AddByte(Type);
            foreach (object arg in Arguments)
            {
                switch (arg)
                {
                case byte b:
                    bb.AddByte(b);
                    break;

                case ushort s:
                    bb.AddShortBE(s);
                    break;

                case RefToElement r:
                    r.Write(bb);
                    break;

                case LinkToExport l:
                    l.Write(bb);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
Beispiel #2
0
        protected override void WriteExt(ByteBuilder bb)
        {
            bb.AddBytes(mapping);
            bb.AddIntBE(ts);

            foreach (var c in Colors)
            {
                bb.AddByte(c.Used);
                bb.AddByte(c.R);
                bb.AddByte(c.G);
                bb.AddByte(c.B);
            }
        }
Beispiel #3
0
        public override object WriteHeader(ByteBuilder bb)
        {
            bb.AddByte(Noun);
            bb.AddByte(Verb);
            bb.AddByte(Cond);
            bb.AddByte(Seq);
            bb.AddByte(Talker);
            var offsetPos = bb.Position;

            bb.AddShortBE(0); // Text offset
            bb.AddThreeBytesBE(Unknown);
            return(offsetPos);
        }
Beispiel #4
0
 private void WriteCode(ByteBuilder bb, int code, int count)
 {
     if (LOG)
     {
         Console.Write($"{code} x{count} ");
     }
     while (count > 0x3f)
     {
         bb.AddByte(0x40);
         count -= 64;
     }
     bb.AddByte((byte)((code << 6) | count));
 }
Beispiel #5
0
        public override void SetTranslate(string[] strings)
        {
            var oldStrings = GetStrings(true);

            if (strings.Length != oldStrings.Length)
            {
                throw new Exception("Line count mismatch");
            }

            ByteBuilder bb = new ByteBuilder();

            for (int r = 0; r < strings.Length; r++)
            {
                var tr = strings[r];
                if (tr == null)
                {
                    tr = oldStrings[r];
                }

                var bytes = GameEncoding.GetBytes(tr);
                bb.AddBytes(bytes);
                bb.AddByte(0);
            }

            SaveTranslate(bb.GetArray());
        }
Beispiel #6
0
        public override void WriteText(ByteBuilder bb, object data, GameEncoding encoding)
        {
            ushort textOffset = (ushort)bb.Position;

            var bytes = encoding.GetBytes(Text);

            bb.AddBytes(bytes);
            bb.AddByte(0);

            bb.SetShortBE((int)data, textOffset);
        }
        public override void Write(ByteBuilder bb)
        {
            IsWrited = true;
            Address  = (ushort)bb.Position;
            switch (Size)
            {
            case 1: bb.AddByte(0); break;

            case 2: bb.AddShortBE(0); break;

            default: throw new NotImplementedException();
            }
        }
Beispiel #8
0
        public void SetFont(SCIFont spr)
        {
            ushort cnt = (ushort)(spr.Frames.Count & 0xFFFF);

            ByteBuilder bb = new ByteBuilder();

            bb.AddByte(0);
            bb.AddShortLE(cnt);
            bb.AddShortLE(spr.FontHeight);
            bb.AddByte(0);

            for (int i = 0; i < cnt; i++)
            {
                bb.AddShortLE(0);
            }

            byte bit;
            byte bitMask;

            for (int i = 0; i < cnt; i++)
            {
                SpriteFrame frm    = spr[i];
                byte        w      = (byte)frm.Width;
                byte        h      = (byte)frm.Height;
                ushort      offset = (ushort)bb.Position;

                bb.SetShortBE(6 + i * 2, offset);

                bb.AddByte(w);
                bb.AddByte(h);
                for (int y = 0; y < frm.Height; y++)
                {
                    bit     = 0;
                    bitMask = 0;
                    for (int x = 0; x < frm.Width; x++)
                    {
                        if (frm[x, y] == 1)
                        {
                            bitMask |= (byte)(1 << (7 - bit));
                        }

                        bit++;
                        if (bit == 8)
                        {
                            bit = 0;
                            bb.AddByte(bitMask);
                            bitMask = 0;
                        }
                    }

                    if (bit != 0)
                    {
                        bb.AddByte(bitMask);
                    }
                }
            }

            SaveTranslate(bb.GetArray());
        }
Beispiel #9
0
        public override byte[] GetPatch()
        {
            ushort cnt = (ushort)(_font.Frames.Count & 0xFFFF);

            ByteBuilder bb = new ByteBuilder();

            bb.AddByte(0);
            bb.AddShortLE(cnt);
            bb.AddShortLE(_font.FontHeight);
            bb.AddByte(0);

            for (int i = 0; i < cnt; i++)
            {
                bb.AddShortLE(0);
            }

            byte bit;
            byte bitMask;

            for (int i = 0; i < cnt; i++)
            {
                SpriteFrame frm    = _font[i];
                byte        w      = (byte)frm.Width;
                byte        h      = (byte)frm.Height;
                ushort      offset = (ushort)bb.Position;

                bb.SetShortBE(6 + i * 2, offset);

                bb.AddByte(w);
                bb.AddByte(h);
                for (int y = 0; y < frm.Height; y++)
                {
                    bit     = 0;
                    bitMask = 0;
                    for (int x = 0; x < frm.Width; x++)
                    {
                        if (frm[x, y] == 1)
                        {
                            bitMask |= (byte)(1 << (7 - bit));
                        }

                        bit++;
                        if (bit == 8)
                        {
                            bit = 0;
                            bb.AddByte(bitMask);
                            bitMask = 0;
                        }
                    }

                    if (bit != 0)
                    {
                        bb.AddByte(bitMask);
                    }
                }
            }

            return(bb.GetArray());
        }
Beispiel #10
0
        public override byte[] GetPatch()
        {
            var strings = GetStrings();

            ByteBuilder bb = new ByteBuilder();

            for (int i = 0; i < strings.Length; i++)
            {
                var bytes = GameEncoding.GetBytes(strings[i]);
                bb.AddBytes(bytes);
                bb.AddByte(0);
            }

            return(bb.GetArray());
        }
Beispiel #11
0
        protected override void WriteExt(ByteBuilder bb)
        {
            bb.WritePicAbsCoord(ref _coord);
            var sizePos = bb.Position;

            bb.AddShortBE(0); // Потом вернемся, чтобы записать размер данных

            bb.AddShortBE(Width);
            bb.AddShortBE(Height);
            bb.AddShortBE(0);
            bb.AddByte(_transpCol);
            bb.AddByte(0);
            WriteImageData(bb);

            var endPos = bb.Position;
            var size   = endPos - sizePos - 2;

            if (size > 0xffff)
            {
                throw new FormatException("Too big image data");
            }

            bb.SetShortBE(sizePos, (ushort)size);
        }
Beispiel #12
0
        public byte[] GetBytes()
        {
            PicOpCode prev = 0;

            ByteBuilder bb = new ByteBuilder();

            foreach (var cmd in commands)
            {
                if (cmd.OpCode != prev || cmd.OpCode == PicOpCode.OPX)
                {
                    bb.AddByte((byte)cmd.OpCode);
                }

                cmd.Write(bb);

                prev = cmd.OpCode;
            }

            return(bb.GetArray());
        }
 public override void Write(ByteBuilder bb)
 {
     bb.AddByte(_extcode);
     WriteExt(bb);
 }
 public override void Write(ByteBuilder bb)
 {
     Address = (ushort)bb.Position;
     bb.AddBytes(Bytes);
     bb.AddByte(0);
 }
Beispiel #15
0
        private void WriteImageRow(ByteBuilder bb, byte[] row)
        {
            for (int i = 0; i < row.Length; i++) // Current pixel
            {
                var curr = row[i];

                if (i + 1 < row.Length)     // Это не последний пиксель
                {
                    if (row[i + 1] == curr) // ... и есть повторения
                    {
                        var end = i + 1;
                        while (end + 1 < row.Length && row[end + 1] == curr && (USE_ADD_COUNT || end - i + 1 < 0x3f))
                        {
                            end++;                                                                                           // Двигаемся вперед пока пиксели совпадают
                        }
                        // На выходе end - указатель на последний повторяющийся пиксель, который мы будем записывать

                        int cnt = end - i + 1;

                        if (end >= row.Length)
                        {
                            throw new Exception();
                        }

                        if (curr == _transpCol)
                        {
                            WriteCode(bb, 3, cnt);
                            if (LOG)
                            {
                                Console.WriteLine("T");
                            }
                        }
                        else
                        {
                            WriteCode(bb, 2, cnt);
                            bb.AddByte(curr);
                            if (LOG)
                            {
                                Console.WriteLine($"{curr:X}");
                            }
                        }

                        i = end;
                    }
                    else // ... пиксели разные
                    {
                        // Ищем количество неповторений
                        // Двигаемся вперед пока пиксели меняются
                        var end = i + 1;
                        int cnt = 2;
                        while (end + 1 < row.Length &&
                               (!IsEquals(row, end + 1, cnt < 3 ? 2 : 3)) &&
                               (USE_ADD_COUNT || end - i + 1 < 0x3f))
                        {
                            end++;
                            cnt++;
                        }

                        WriteCode(bb, 0, cnt);
                        if (LOG)
                        {
                            Console.Write("[");
                        }
                        for (int n = i; n <= end; n++)
                        {
                            bb.AddByte(row[n]);
                            if (LOG)
                            {
                                Console.Write($"{row[n]:X2} ");
                            }
                        }
                        if (LOG)
                        {
                            Console.WriteLine("]");
                        }

                        i = end;
                    }
                }
                else // Последний пиксель
                {
                    WriteCode(bb, 0, 1);
                    bb.AddByte(curr);
                }
            }
        }