Example #1
0
        public static SpecialBox[] ReadTable(Stream s, SpecialBoxType Type, int Levelscriptstart, int TabelStart)
        {
            var br      = new BinaryReader(s);
            var boxlist = new List <SpecialBox>();

            s.Position = TabelStart;

            if (SwapInts.SwapInt32(br.ReadInt32()) == 0x1010101)
            {
                return(Array.Empty <SpecialBox>());
            }
            else
            {
                s.Position -= 0x4;
            }

            while (SwapInts.SwapUInt16(br.ReadUInt16()) != 0xFFFF)
            {
                s.Position += 0x2;
                var tbox = new SpecialBox();
                tbox.Type = Type;
                int lastpos = (int)(s.Position + 0x4);
                s.Position = SwapInts.SwapInt32(br.ReadInt32()) - 0x19000000 + Levelscriptstart;

                if (Type == SpecialBoxType.Water)
                {
                    tbox.InvisibleWater = SwapInts.SwapInt32(br.ReadInt32()) == 0x0;
                }
                else
                {
                    s.Position += 0x4;
                }

                s.Position    += 0x2;
                tbox.Scale     = SwapInts.SwapInt16(br.ReadInt16());
                tbox.X1        = SwapInts.SwapInt16(br.ReadInt16());
                tbox.Z1        = SwapInts.SwapInt16(br.ReadInt16());
                tbox.X2        = SwapInts.SwapInt16(br.ReadInt16());
                s.Position    += 0x4;
                tbox.Z2        = SwapInts.SwapInt16(br.ReadInt16());
                s.Position    += 0x7;
                tbox.Alpha     = br.ReadByte();
                tbox.WaterType = (WaterType)SwapInts.SwapInt32(br.ReadInt32());
                s.Position     = lastpos;
                boxlist.Add(tbox);
            }

            return(boxlist.ToArray());
        }
Example #2
0
 private static void ConvertBlock(BinaryWriter bw, Bitmap map, uint address, int src_x, int src_y, int start_x, int start_y, int offset_x, int offset_y, int w, int h, int lineWidth)
 {
     for (int yy = start_y, loopTo = h - 1; yy <= loopTo; yy++)
     {
         for (int xx = start_x, loopTo1 = w - 1; xx <= loopTo1; xx++)
         {
             var pixel = map.GetPixel(src_x + xx, src_y + yy);
             int r     = pixel.R / 8;
             int g     = pixel.G / 8;
             int b     = pixel.B / 8;
             int a     = pixel.A == 0xFF ? 1 : 0;
             bw.BaseStream.Position = address + ((yy + offset_y) * lineWidth + xx + offset_x) * 2;
             bw.Write(SwapInts.SwapUInt16(Conversions.ToUShort(r << 11 | g << 6 | b << 1 | a)));
         }
     }
 }
Example #3
0
 private static void ParseBlock(BinaryReader br, Bitmap map, uint address, Rectangle rect)
 {
     for (int yy = 0, loopTo = rect.Height - 1; yy <= loopTo; yy++)
     {
         for (int xx = 0, loopTo1 = rect.Width - 1; xx <= loopTo1; xx++)
         {
             int offset = (int)(address + (yy * (rect.Width + 1) + xx) * 2);
             br.BaseStream.Position = offset;
             ushort pixel  = SwapInts.SwapUInt16(br.ReadUInt16());
             byte   red    = Conversions.ToByte((pixel >> 11 & 0x1F) * 8);
             byte   green  = Conversions.ToByte((pixel >> 6 & 0x1F) * 8);
             byte   blue   = Conversions.ToByte((pixel >> 1 & 0x1F) * 8);
             byte   alpha  = Conversions.ToByte((pixel & 1) > 0 ? 0xFF : 0);
             var    pixcol = Color.FromArgb(alpha, red, green, blue);
             map.SetPixel(rect.X + xx, rect.Y + yy, pixcol);
         }
     }
 }
Example #4
0
 public ushort ReadUInt16()
 {
     return(SwapInts.SwapUInt16(Reader.ReadUInt16()));
 }
Example #5
0
 public void Write(ushort value)
 {
     Writer.Write(SwapInts.SwapUInt16(value));
 }