public NpcDialogueDefinition( System.IO.Stream stream, uint refStringStart )
        {
            Unknown1 = stream.ReadUInt32().SwapEndian();
            Unknown2 = stream.ReadUInt32().SwapEndian();
            StringDicId = stream.ReadUInt32().SwapEndian();
            Unknown4 = stream.ReadUInt32().SwapEndian();

            Unknown5a1 = (byte)stream.ReadByte();
            Unknown5a2 = (byte)stream.ReadByte();
            Unknown5b1 = (byte)stream.ReadByte();
            Unknown5b2 = (byte)stream.ReadByte();
            Unknown6a = (short)stream.ReadUInt16().SwapEndian();
            Unknown6b = (short)stream.ReadUInt16().SwapEndian();
            Unknown7a1 = (byte)stream.ReadByte();
            Unknown7a2 = (byte)stream.ReadByte();
            Unknown7b = stream.ReadUInt16().SwapEndian();
            Unknown8 = stream.ReadUInt32().SwapEndian();

            RefStringLocation1 = stream.ReadUInt32().SwapEndian();
            RefStringLocation2 = stream.ReadUInt32().SwapEndian();
            Unknown11 = stream.ReadUInt32().SwapEndian();
            Unknown12 = stream.ReadUInt32().SwapEndian();

            Unknown13 = stream.ReadUInt32().SwapEndian();
            Unknown14 = stream.ReadUInt32().SwapEndian();
            Unknown15 = stream.ReadUInt32().SwapEndian();
            Unknown16 = stream.ReadUInt32().SwapEndian();

            long pos = stream.Position;
            stream.Position = refStringStart + RefStringLocation1;
            RefString1 = stream.ReadAsciiNullterm();
            stream.Position = refStringStart + RefStringLocation2;
            RefString2 = stream.ReadAsciiNullterm();
            stream.Position = pos;
        }
 public SkitCondition( System.IO.Stream stream )
 {
     Type = (SkitConditionType)stream.ReadUInt16().SwapEndian();
     MathOp = stream.ReadUInt16().SwapEndian();
     Value1 = (int)stream.ReadUInt32().SwapEndian();
     Value2 = (int)stream.ReadUInt32().SwapEndian();
     Value3 = (int)stream.ReadUInt32().SwapEndian();
 }
Example #3
0
        public uint planenum; // index of the splitting plane (in the plane array)

        #endregion Fields

        #region Methods

        public void Read(System.IO.BinaryReader source)
        {
            planenum = source.ReadUInt32();
            front = source.ReadInt32();
            back = source.ReadInt32();
            box.Read(source);
            first_face = source.ReadUInt16();
            num_faces = source.ReadUInt16();
        }
 public UnknownSkitData4( System.IO.Stream stream )
 {
     Unknown1a = stream.ReadUInt16().SwapEndian();
     Unknown1b = stream.ReadUInt16().SwapEndian();
     Unknown2a = stream.ReadUInt16().SwapEndian();
     Unknown2b = stream.ReadUInt16().SwapEndian();
     Unknown3 = stream.ReadUInt32().SwapEndian();
     Unknown4 = stream.ReadUInt32().SwapEndian();
 }
Example #5
0
 public void Read(System.IO.BinaryReader br)
 {
     XOrigin = br.ReadUInt16();
     YOrigin = br.ReadUInt16();
     Width = br.ReadUInt16();
     Height = br.ReadUInt16();
     PixelDepth = br.ReadByte();
     Descriptor = br.ReadByte();
 }
Example #6
0
        public int planenum; // The plane that splits the node

        #endregion Fields

        #region Methods

        public void Read(System.IO.BinaryReader source)
        {
            planenum = source.ReadInt32();
            front = source.ReadUInt16();
            back = source.ReadUInt16();

            box.Read(source);
            face_id = source.ReadUInt16();
            face_num = source.ReadUInt16();
        }
Example #7
0
        public ushort texture_info; // index of the texture info structure

        #endregion Fields

        #region Methods

        public void Read(System.IO.BinaryReader source)
        {
            plane = source.ReadUInt16();
                    plane_side = source.ReadUInt16();
                    ledge_id = source.ReadUInt32();
                    ledge_num = source.ReadUInt16();
                    texture_info = source.ReadUInt16();
                    lightmap_syles = source.ReadBytes(4);
                    lightmap = source.ReadInt32();
        }
Example #8
0
        public int vislist; // Beginning of visibility lists

        #endregion Fields

        #region Methods

        public void Read(System.IO.BinaryReader source)
        {
            type = source.ReadInt32();
            vislist = source.ReadInt32();
            box.Read(source);
            lface_id = source.ReadUInt16();
            lface_num = source.ReadUInt16();
            sndwater = source.ReadByte();
            sndsky = source.ReadByte();
            sndslime = source.ReadByte();
            sndlava = source.ReadByte();
        }
Example #9
0
        public ushort num_leaf_faces; // number of consecutive edges (in the face leaf array)

        #endregion Fields

        #region Methods

        public void Read(System.IO.BinaryReader source)
        {
            brush_or = source.ReadUInt32();
            cluster = source.ReadInt16();           // -1 for cluster indicates no visibility information
            area = source.ReadUInt16();              // ?

            box.Read(source);

            first_leaf_face = source.ReadUInt16();   // index of the first face (in the face leaf array)
            num_leaf_faces = source.ReadUInt16();    // number of consecutive edges (in the face leaf array)

            first_leaf_brush = source.ReadUInt16();  // ?
            num_leaf_brushes = source.ReadUInt16();  // ?
        }
Example #10
0
        protected override void ReadFromStream(System.IO.BinaryReader reader)
        {
            base.ReadFromStream(reader);

            Chunks = reader.ReadUInt16();
            Delay = reader.ReadUInt16();
            Reserved = reader.ReadInt16();
            Width = reader.ReadUInt16();
            Height = reader.ReadUInt16();

            if (Width != 0 || Height != 0)
                throw new NotImplementedException("Overlay width or height is not supported yet.");

            ReadSubChunks(reader, Chunks);
        }
Example #11
0
 private static Chunk ReadChunk(System.IO.BinaryReader reader)
 {
     var id = reader.ReadUInt16();
     var length = reader.ReadUInt32();
     var result = new Chunk(id, length);
     return result;
 }
Example #12
0
 public void ReadFrom(System.IO.BinaryReader reader)
 {
     Size = reader.ReadUInt16();
     if (Size > Marshal.SizeOf(Size))
     {
         Item.Data = reader.ReadBytes(Size - Marshal.SizeOf(Size));
     }
 }
Example #13
0
 public override object Deserialize(System.IO.BinaryReader binaryReader)
 {
     bool hasValue = binaryReader.ReadBoolean ();
     if (!hasValue)
         return null;
     int typeID = binaryReader.ReadByte ();
     switch (typeID) {
     case 1:
         return binaryReader.ReadBoolean ();
     case 2:
         return binaryReader.ReadByte ();
     case 128:
         return binaryReader.ReadSByte ();
     case 3:
         return binaryReader.ReadInt16 ();
     case 129:
         return binaryReader.ReadUInt16 ();
     case 4:
         return binaryReader.ReadInt32 ();
     case 130:
         return binaryReader.ReadUInt32 ();
     case 5:
         return binaryReader.ReadInt64 ();
     case 131:
         return binaryReader.ReadUInt64 ();
     case 9:
         return binaryReader.ReadDouble ();
     case 16:
         return binaryReader.ReadString ();
     case 144:
         return binaryReader.ReadChar ();
     case 24:
         return new DateTime (binaryReader.ReadInt64 ());
     case 32:
         return new Guid (binaryReader.ReadBytes (16));
     case 36:
         return binaryReader.ReadBytes (binaryReader.ReadInt32 ());
     case 37:
         {
             int count = binaryReader.ReadInt32 ();
             string[] r = new string[count];
             for (int n = 0; n != count; n++)
                 r [n] = binaryReader.ReadString ();
             return r;
         }
     case 38:
         {
             int count = binaryReader.ReadInt32 ();
             long[] r = new long[count];
             for (int n = 0; n != count; n++)
                 r [n] = binaryReader.ReadInt64 ();
             return r;
         }
     default:
         throw new Exception (string.Format ("Serialization for type <{0}> is not supported", typeID));
     }
 }
Example #14
0
        public static Chunk Parse(System.IO.BinaryReader reader)
        {
            var id = reader.ReadUInt16();
            if (id != ChunkID.MAIN_CHUNK) { return null; }

            var length = reader.ReadUInt32();
            var mainChunk = new Chunk(id, length);
            ReadSubChunk(mainChunk, reader);

            return mainChunk;
        }
Example #15
0
        public override Resource Load(System.IO.BinaryReader reader, string name, LoaderFileOpener opener, Resource context)
        {
            reader.Require(Magic);
            var contentSize = reader.ReadInt32(); // total size - header size
            reader.Require(1);
            reader.Require(0);
            reader.Require(0x80); // headerSize
            if (contentSize + 0x80 != reader.BaseStream.Length)
                throw new Exception();
            reader.Require(contentSize); // contentSize2
            reader.Require(0x85040201);
            reader.Require(0xAAE4);
            int width = reader.ReadUInt16();
            int height = reader.ReadUInt16();
            reader.Require((ushort)1);
            reader.RequireZeroes(90);

            if (width != height)
                throw new InvalidDataException("Width and height must be equal for a cube map.");

            TextureCube cube = new TextureCube();
            //cube.Storage(
                //cube., width, TextureFormats.Vector4nb);
            throw new NotImplementedException();
            /*
            byte[] data = new byte[width * height * 4];

            foreach (CubeFace face in TextureCube.Faces) {
                int lod = 0;

                for (int size = width; size >= 8; size /= 2, lod++) {
                    reader.Read(data, 0, size * size * 4);
                    cube.SetData(face, lod, Box2i.CreateSize(size, size), data);
                }

                cube.MaxLod = lod - 1;
            }

            return new TextureResource(Manager, cube, name);*/
        }
Example #16
0
        public ExportedLevel(System.IO.BinaryReader br)
        {
            string Header = br.ReadString();
            if (Header != fileHeader)
            {
                throw new Exception(LanguageManager.Get("NSMBLevel", "InvalidFile"));
            }

            ushort FileVersion = br.ReadUInt16();
            if (FileVersion > version)
            {
                throw new Exception(LanguageManager.Get("NSMBLevel", "OldVersion"));
            }

            LevelFileID = br.ReadUInt16();
            BGDatFileID = br.ReadUInt16();
            int LevelFileLength = br.ReadInt32();
            LevelFile = br.ReadBytes(LevelFileLength);

            int BGFileLength = br.ReadInt32();
            BGDatFile = br.ReadBytes(BGFileLength);
        }
Example #17
0
        public ExportedLevel(System.IO.BinaryReader br)
        {
            string Header = br.ReadString();
            if (Header != "NSMBe4 Exported Level")
            {
                ErrorMessage = LanguageManager.Get("NSMBLevel", "InvalidFile");
                ErrorTitle = LanguageManager.Get("NSMBLevel", "Unreadable");
                return;
            }

            ushort FileVersion = br.ReadUInt16();
            if (FileVersion > 1)
            {
                ErrorMessage = LanguageManager.Get("NSMBLevel", "OldVersion");
                ErrorTitle = LanguageManager.Get("NSMBLevel", "Unusable");
            }

            // This message conflitcs with the auto-backup and I think it's unecessary ~Piranhaplant
            LevelFileID = br.ReadUInt16();
            BGFileID = br.ReadUInt16();
            //if (SavedLevelFileID != destLevelFile.id) {
            //    DialogResult dr = MessageBox.Show(
            //        LanguageManager.Get("NSMBLevel", "Mismatch"),
            //        LanguageManager.Get("General", "Warning"),
            //        MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            //    if (dr == DialogResult.No) {
            //        return;
            //    }
            //}

            int LevelFileLength = br.ReadInt32();
            LevelFile = br.ReadBytes(LevelFileLength);

            int BGFileLength = br.ReadInt32();
            BGFile = br.ReadBytes(BGFileLength);
        }
Example #18
0
 public PaletteImage(System.IO.BinaryReader br, bool compressed)
 {
     try
     {
         this.Width = br.ReadInt16();
         this.Height = br.ReadInt16();
         this.Size = Convert.ToInt32(this.Width) * Convert.ToInt32(this.Height);
         if (compressed)
         {
             this.Size = br.ReadUInt16();
         }
         this.Data = br.ReadBytes(this.Size);
     }
     catch (Exception ex)
     {
     }
 }
Example #19
0
        protected override void ReadFromStream(System.IO.BinaryReader reader)
        {
            base.ReadFromStream(reader);

            ushort nrPackets = reader.ReadUInt16();
            for (int i = 0; i < nrPackets; i++)
            {
                byte skipCount = reader.ReadByte();
                byte copyCount = reader.ReadByte();

                if (copyCount == 0)
                {
                    byte[] rgbData = reader.ReadBytes(256 * 3);
                    for (int j = 0; j < 256; j++)
                    {
                        Colors[j] = new FLCColor(rgbData[j * 3 + 0], rgbData[j * 3 + 1], rgbData[j * 3 + 2], 255);
                    }
                }
                else
                {
                }
            }
        }
Example #20
0
 public override void LoadState(System.IO.BinaryReader stream)
 {
     base.LoadState(stream);
     ram_protectA = stream.ReadInt32();
     ram_protectB = stream.ReadInt32();
     ExRAM_mode = stream.ReadInt32();
     for (int i = 0; i < CHROffset_spr.Length; i++)
         CHROffset_spr[i] = stream.ReadInt32();
     for (int i = 0; i < CHROffsetEX.Length; i++)
         CHROffsetEX[i] = stream.ReadInt32();
     for (int i = 0; i < CHROffsetSP.Length; i++)
         CHROffsetSP[i] = stream.ReadInt32();
     for (int i = 0; i < chrRegA.Length; i++)
         chrRegA[i] = stream.ReadInt32();
     for (int i = 0; i < chrRegB.Length; i++)
         chrRegB[i] = stream.ReadInt32();
     for (int i = 0; i < prgReg.Length; i++)
         prgReg[i] = stream.ReadInt32();
     useSRAMmirroring = stream.ReadBoolean();
     chr_high = stream.ReadInt32();
     chr_mode = stream.ReadInt32();
     prg_mode = stream.ReadInt32();
     chr_setB_last = stream.ReadBoolean();
     temp_val = stream.ReadByte();
     temp_fill = stream.ReadByte();
     lastAccessVRAM = stream.ReadInt32();
     paletteNo = stream.ReadInt32();
     shift = stream.ReadInt32();
     EXtilenumber = stream.ReadInt32();
     multiplicand = stream.ReadByte();
     multiplier = stream.ReadByte();
     product = stream.ReadUInt16();
     split_enable = stream.ReadBoolean();
     split_right = stream.ReadBoolean();
     split_tile = stream.ReadInt32();
     split_yscroll = stream.ReadInt32();
     split_doit = stream.ReadBoolean();
     split_watch_tile = stream.ReadInt32();
     irq_line = stream.ReadByte();
     irq_enable = stream.ReadByte();
     irq_pending = stream.ReadInt32();
     irq_current_counter = stream.ReadInt32();
     irq_current_inframe = stream.ReadInt32();
     sound_seq_curr = stream.ReadInt32();
     sound_seq_cyc = stream.ReadInt32();
     channel_sq1.LoadState(stream);
     channel_sq2.LoadState(stream);
     channel_pcm.LoadState(stream);
 }
Example #21
0
 public void Read(System.IO.BinaryReader br)
 {
     FirstEntryIndex = br.ReadUInt16();
     Length = br.ReadUInt16();
     EntrySize = br.ReadByte();
 }
Example #22
0
        private void Mod_LoadFaces(SDHeader header, ref CModel.SModel _SModel, ref System.IO.BinaryReader br)
        {
            List<SDFace> DFace = new List<SDFace>();
            List<CModel.SMSurface> MSurface = new List<CModel.SMSurface>();

            br.BaseStream.Seek(header.lumps[LUMP_FACES].fileofs, System.IO.SeekOrigin.Begin);
            while (br.BaseStream.Position < (header.lumps[LUMP_FACES].fileofs + header.lumps[LUMP_FACES].filelen))
            {
                SDFace _DFace;

                _DFace.planenum = br.ReadUInt16();
                _DFace.side = br.ReadInt16();

                _DFace.firstedge = br.ReadInt32();
                _DFace.numedges = br.ReadInt16();
                _DFace.texinfo = br.ReadInt16();

                _DFace.styles = br.ReadBytes(MAXLIGHTMAPS);
                _DFace.lightofs = br.ReadInt32();

                DFace.Add(_DFace);
            }

            CProgram.gQ2Game.gCMain.gCSurface.BeginBuildingLightmaps(ref _SModel);

            for (int i = 0; i < DFace.Count; i++)
            {
                CModel.SMSurface _MSurface;
                int side;
                short ti;

                _MSurface.firstedge = DFace[i].firstedge;
                _MSurface.numedges = DFace[i].numedges;
                _MSurface.flags = 0;
                _MSurface.polys = null;
                _MSurface.ibSurface = null;
                _MSurface.ibData = null;

                side = DFace[i].side;
                if (side != 0)
                    _MSurface.flags |= CModel.EMSurface.SURF_PLANEBACK;

                _MSurface.plane = DFace[i].planenum;

                _MSurface.plane2 = new Microsoft.Xna.Framework.Plane();

                ti = DFace[i].texinfo;
                if (ti < 0 || ti >= _SModel.numtexinfo)
                    CMain.Error(CMain.EErrorParm.ERR_WARNING, "MOD_LoadBmodel: bad texinfo number");
                _MSurface.texinfo = ti;

                _MSurface.bounds = CLocal.ClearBounds();

                _MSurface.boundsMid.X = 0.0f;
                _MSurface.boundsMid.Y = 0.0f;
                _MSurface.boundsMid.Z = 0.0f;

                _MSurface.lightIndex = null;
                _MSurface.lightLength = null;

                _MSurface.texturechain = 0;
                _MSurface.visframe = 0;

                // lighting info
                _MSurface.dlightframe = 0;
                _MSurface.dlightbits = 0;
                _MSurface.lightmaptexturenum = 0;
                _MSurface.styles = new byte[MAXLIGHTMAPS];
                for (int j = 0; j < MAXLIGHTMAPS; j++)
                {
                    _MSurface.styles[j] = DFace[i].styles[j];
                }

                _MSurface.cached_light = null;
                _MSurface.samples = DFace[i].lightofs;

                _MSurface.light_s = 0;
                _MSurface.light_t = 0;
                _MSurface.dlight_s = 0;
                _MSurface.dlight_t = 0;

                _MSurface.extents = null;
                _MSurface.texturemins = null;
                CModel.CalcSurfaceExtents(ref _SModel, ref _MSurface);

                // set the drawing flags
                if ((_SModel.texinfo[_MSurface.texinfo].flags & ESurface.SURF_WARP) == ESurface.SURF_WARP)
                {
                    _MSurface.flags |= CModel.EMSurface.SURF_DRAWTURB;

                    for (int j = 0; j < 2; j++)
                    {
                        _MSurface.extents[j] = 16384;
                        _MSurface.texturemins[j] = -8192;
                    }

                    // TODO
                    // cut up polygon for warps
                    //SubdivideSurface(i, ref _WorldModel.mfaces[i]);
                    //SubdivideSurface (out);
                }

                // create lightmaps and polygons
                if (
                    (_SModel.texinfo[_MSurface.texinfo].flags & ESurface.SURF_SKY) != ESurface.SURF_SKY
                    && (_SModel.texinfo[_MSurface.texinfo].flags & ESurface.SURF_TRANS33) != ESurface.SURF_TRANS33
                    && (_SModel.texinfo[_MSurface.texinfo].flags & ESurface.SURF_TRANS66) != ESurface.SURF_TRANS66
                    && (_SModel.texinfo[_MSurface.texinfo].flags & ESurface.SURF_WARP) != ESurface.SURF_WARP
                    )
                {
                    CProgram.gQ2Game.gCMain.gCSurface.CreateSurfaceLightmap(_SModel, ref _MSurface);
                }

                if ((_SModel.texinfo[_MSurface.texinfo].flags & ESurface.SURF_WARP) == ESurface.SURF_WARP)
                    CProgram.gQ2Game.gCMain.gCSurface.BuildPolygonFromSurface(ref _MSurface);

                MSurface.Add(_MSurface);
            }

            CProgram.gQ2Game.gCMain.gCSurface.EndBuildingLightmaps(ref _SModel);

            _SModel.numsurfaces = MSurface.Count;
            _SModel.surfaces = MSurface.ToArray();
        }
Example #23
0
        /* The LZSS algorithm - http://wiki.xentax.com/index.php/LZSS
         *
         *   Compression
         *       Set up parameters
         *           N           Circular buffer size
         *           F           Length window size
         *           Threshold   Minimum compression size (minimum length for a match)
         *           BufPos      Initial buffer position.  Generally N - F
         *           BufVoid     Initial fill byte.
         *
         *       To compress
         *           Try to find longest sequence that is also in buffer
         *               If length >= Threshold, save offset and length in output file.  record literal to buffer
         *               If no match, copy literal byte to output and repeat
         *
         *           To record if compression or literal copy made, set special flag byte,
         *
         *
         *   Decompression
         *       Done in reverse order.  Parameters need to be known.
         *       Pseudo:
         *
         *           while InputPos < InputSize do
         *           begin
         *
         *               FlagByte := Input[InputPos++]
         *               for i := 1 to 8 do
         *               begin
         *
         *                  if (FlagByte and 1) = 0 then
         *                  begin
         *
         *                       OfsLen := Input[InputPos] + Input[InputPos + 1] shl 8
         *                       InputPos += 2
         *                       if OfsLen = 0 then
         *                           Exit;
         *
         *                       Length := OfsLen and LengthMask + Threshold
         *                       Offset := (BufPos - (OfsLen shr LengthBits)) and (N - 1)
         *                       copy Length bytes from Buffer[Offset] onwards
         *                       while increasing BufPos
         *
         *                   end
         *                   else
         *                   begin
         *
         *                       copy 1 byte from Input[InputPos]
         *                       InputPos += 1
         *
         *                  end
         *                  FlagByte := FlagByte shr 1
         *
         *               end
         *           end
         *
         *       Length bits descibes number of bits to find F.  Above assumes length of buffer reference
         *           in lower bit of the word.  lenght mask = (1 << lenbits) - 1
         *
         *       also assumed buffer offset relative to current write position.  if absolute, BufPos subtraction unneeded
         *
         *       Buffer is circular.  wrap offset.
         *
         *       mirror output writes to history buffer
         *
         *       in most cases, data from history buffer will be byte-wise.
         */
        private void decompress(System.IO.BinaryReader inStream, ref VDXChunkHeader header, out System.IO.MemoryStream stream)
        {
            stream = new System.IO.MemoryStream();

            uint i, j, N, F, initwrite;
            byte flagbyte, tempa;
            uint offsetlen, length, offset, bufpos;
            byte[] hisbuff;

            N = (uint)(1 << (16 - header.LengthBits));  // History buffer size
            hisbuff = new byte[N];              // History buffer
            F = (uint)(1 << header.LengthBits);         // Window size
            initwrite = N - F;                  // Initial history write pos
            bufpos = 0;

            for (i = 0; i < N; i++)
                hisbuff[i] = 0;                 // Init history buffer

            long final = header.DataSize + inStream.BaseStream.Position;
            while (inStream.BaseStream.Position < final)
            {
                flagbyte = inStream.ReadByte();
                for (i = 1; i <= 8; i++)
                {
                    if (inStream.BaseStream.Position < final)
                    {
                        if ((flagbyte & 1) == 0)
                        {
                            offsetlen = inStream.ReadUInt16();
                            if (offsetlen == 0)
                                break;

                            length = (offsetlen & header.LengthMask) + 3;
                            offset = (bufpos - (offsetlen >> header.LengthBits)) & (N - 1);
                            for (j = 0; j < length; j++)
                            {
                                tempa = hisbuff[(offset + j) & (N - 1)];
                                stream.WriteByte(tempa);
                                hisbuff[bufpos] = tempa;
                                bufpos = (bufpos + 1) & (N - 1);
                            }
                        }
                        else
                        {
                            tempa = inStream.ReadByte();
                            stream.WriteByte(tempa);
                            hisbuff[bufpos] = tempa;
                            bufpos = (bufpos + 1) & (N - 1);
                        }
                        flagbyte = (byte)(flagbyte >> 1);
                    }
                }
            }
        }
        private Boolean ReadValues(System.IO.BinaryReader r)
        {
            Int32 count;
              if(r.BaseStream.Length == 0) return false;
              count = Sql.Read7BitEncodedInt(r);

              if (count == 0) return true;

              for (Int32 i = 0; i < count; i++)
              {
            String    name  = r.ReadString();
            SqlDbType LType = (SqlDbType)r.ReadUInt16();
            Object    value = null;
            Int32 len;
            //Int32 lcid;
            //SqlCompareOptions co;

            switch (LType)
            {
              case SqlDbType.Bit      : value = new SqlBoolean(r.ReadBoolean()); break;
              case SqlDbType.TinyInt  : value = new SqlByte(r.ReadByte()); break;
              case SqlDbType.SmallInt : value = new SqlInt16((Int16)r.ReadInt16()); break;
              case SqlDbType.Int      : value = new SqlInt32((Int32)r.ReadInt32()); break;
              case SqlDbType.BigInt   : value = new SqlInt64(r.ReadInt64()); break;

              case SqlDbType.Binary   :
              case SqlDbType.VarBinary: len = r.ReadUInt16(); value = new SqlBytes(r.ReadBytes(len)); break;

              case SqlDbType.Char     :
              case SqlDbType.VarChar  : //value = new Sql.SqlAnsiString(r); break;
              case SqlDbType.NChar:
              case SqlDbType.NVarChar:
            //co = (SqlCompareOptions)r.ReadUInt16();
            //lcid = r.ReadInt32();
            //value = new SqlString(r.ReadString(), lcid, co);
            value = new SqlString(r.ReadString());
            break;

              case SqlDbType.DateTime     : value = new SqlDateTime(DateTime.FromBinary(r.ReadInt64())); break;
              case SqlDbType.SmallDateTime:
              case SqlDbType.Date         :
              case SqlDbType.DateTime2    : value = DateTime.FromBinary(r.ReadInt64()); break;
              case SqlDbType.Time         : value = TimeSpan.FromTicks(r.ReadInt64()); break;
              case SqlDbType.DateTimeOffset:
            DateTime LDateTime = DateTime.FromBinary(r.ReadInt64());
            value = new DateTimeOffset(LDateTime, TimeSpan.FromTicks(r.ReadInt64()));
            break;

              case SqlDbType.Decimal: value = new SqlDecimal(r.ReadDecimal()); break;
              case SqlDbType.Float  : value = new SqlDouble(r.ReadDouble()); break;
              // Not support SqlDbType.Image
              case SqlDbType.Money  : value = new SqlMoney(r.ReadDecimal()); break;
              case SqlDbType.Real   : value = new SqlSingle(r.ReadDouble()); break;
              case SqlDbType.SmallMoney: value = new SqlMoney(r.ReadDecimal()); break;
              // Not support SqlDbType.Structured
              // Not support SqlDbType.Text
              // Not support SqlDbType.Timestamp
              case SqlDbType.UniqueIdentifier: value = new SqlGuid(r.ReadString()); break;
              // Not support SqlDbType.Variant
              case SqlDbType.Xml:
            XmlReader rXml = XmlReader.Create(new System.IO.StringReader(r.ReadString()));
            value = new SqlXml(rXml);
            break;

              case SqlDbType.Udt:
            // TODO: Пока поддержа только TParams
            //String LTypeName = r.ReadString();
            //value = CreateUdtObject(LTypeName);
            //if (value is IBinarySerialize)
            //  (value as IBinarySerialize).Read(r);
            //else
            //  throw new Exception(String.Format("Невозможно прочитать данные типа UDT '{0}' - не поддерживается IBinarySerialize", LTypeName));
            value = new SqlUdt(r);
            break;

              default:
            throw new Exception(String.Format("Невозможно прочитать данные, тип '{0}' не поддерживается текущей версией {1}", LType.ToString(), this.GetType().Name));
              // Not support SqlDbType.NText
            }
            if (value != null) FData.Add(name, value);
              }

              return true;
        }
Example #25
0
        public static void getImportLevel(out byte[] levelFile, out byte[] bgFile, out string[] error, System.IO.BinaryReader br)
        {
            string Header = br.ReadString();
            levelFile = null; bgFile = null; error = null;
            if (Header != "NSMBe4 Exported Level") {
                error = new string[] { LanguageManager.Get("NSMBLevel", "InvalidFile") , LanguageManager.Get("NSMBLevel", "Unreadable") };
                return;
            }

            ushort FileVersion = br.ReadUInt16();
            if (FileVersion > 1) {
                error = new string[] { LanguageManager.Get("NSMBLevel", "OldVersion"), LanguageManager.Get("NSMBLevel", "Unusable") };
                return;
            }

            // This message conflitcs with the auto-backup and I think it's unecessary ~Piranhaplant

            ushort SavedLevelFileID = br.ReadUInt16();
            ushort SavedBGFileID = br.ReadUInt16();
            //if (SavedLevelFileID != destLevelFile.id) {
            //    DialogResult dr = MessageBox.Show(
            //        LanguageManager.Get("NSMBLevel", "Mismatch"),
            //        LanguageManager.Get("General", "Warning"),
            //        MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            //    if (dr == DialogResult.No) {
            //        return;
            //    }
            //}

            int LevelFileLength = br.ReadInt32();
            levelFile = br.ReadBytes(LevelFileLength);

            int BGFileLength = br.ReadInt32();
            bgFile = br.ReadBytes(BGFileLength);
        }
 /// <summary>
 /// Reads the specified writer.
 /// </summary>
 /// <param name="reader">The reader.</param>
 public void Read(System.IO.BinaryReader reader)
 {
     Address = reader.ReadUInt16();
     Name = reader.ReadUInt32();
     Type = (Elf32SectionType)reader.ReadUInt16();
     Flags = (Elf32SectionAttribute)reader.ReadUInt16();
     Address = reader.ReadUInt32();
     Offset = reader.ReadUInt32();
     Size = reader.ReadUInt32();
     Link = reader.ReadUInt32();
     Info = reader.ReadUInt32();
     AddressAlignment = reader.ReadUInt32();
     EntrySize = reader.ReadUInt32();
 }
        /// <summary>
        /// Parses all neccessary information from a source stream
        /// </summary>
        /// <param name="sourceStream">The source stream</param>
        /// <param name="sourceVersion">The version</param>
        protected override void Parse( System.IO.BinaryReader sourceStream, byte sourceVersion )
        {
            _functionName = Helper.SwfStrings.SwfString( sourceVersion, sourceStream );
            _numParams = sourceStream.ReadUInt16();
            _numRegister = sourceStream.ReadByte();

            BitStream bits = new BitStream( sourceStream.BaseStream );
            _PreloadParentFlag = ( 0 != bits.GetBits( 1 ) );
            _PreloadRootFlag = ( 0 != bits.GetBits( 1 ) );
            _SuppressSuperFlag = ( 0 != bits.GetBits( 1 ) );
            _PreloadSuperFlag = ( 0 != bits.GetBits( 1 ) );
            _SuppressArgumentsFlag = ( 0 != bits.GetBits( 1 ) );
            _PreloadArgumentsFlag = ( 0 != bits.GetBits( 1 ) );
            _SuppressThisFlag = ( 0 != bits.GetBits( 1 ) );
            _PreloadThisFlag = ( 0 != bits.GetBits( 1 ) );
            uint reserved = bits.GetBits( 7 );
            _PreloadGlobalFlag = ( 0 != bits.GetBits( 1 ) );

            if ( 0 != reserved )
            {
                throw new AVM1ExceptionByteCodeFormat( "ActionDefineFunction2 with reserved flags used" );
            }

            if ( _SuppressArgumentsFlag && _PreloadArgumentsFlag )
            {
                throw new AVM1ExceptionByteCodeFormat( "ActionDefineFunction2 Supress+Preload Arguments flag" );
            }

            if ( _SuppressSuperFlag && _PreloadSuperFlag )
            {
                throw new AVM1ExceptionByteCodeFormat( "ActionDefineFunction2 Supress+Preload Super flag" );
            }

            if ( _SuppressThisFlag && _PreloadThisFlag )
            {
                throw new AVM1ExceptionByteCodeFormat( "ActionDefineFunction2 Supress+Preload This flag" );
            }

            // TODO: make sure this is correct
            _Parameters = new List<RegisterParam>();
            for ( int i = 0; i < _numParams; i++ )
            {
                RegisterParam rp = new RegisterParam();
                rp.Register = sourceStream.ReadByte();
                rp.ParamName = Helper.SwfStrings.SwfString( sourceVersion, sourceStream );
                _Parameters.Add( rp );
            }

            _codeSize = sourceStream.ReadUInt16();

            //
            // Please see comment at ActionDefineFunction
            //
            // _code = Helper.SwfCodeReader.GetCode( _codeSize, sourceStream, sourceTag, sourceFile );
        }
Example #28
0
                public override object Read(object target, Package package, System.IO.BinaryReader reader, long end)
                {
                    LogicalAnd targetAnd = (LogicalAnd)target;
                    byte code;

                    targetAnd.ElseCount = 0;
                    while ((code = reader.ReadByte()) == 0x16)
                        targetAnd.ElseCount++;
                    if (code != 0x18)
                        throw new Exception();
                    return reader.ReadUInt16();
                }
Example #29
0
        private void Mod_LoadNodesAndLeafs(SDHeader header, ref CModel.SModel _SModel, ref System.IO.BinaryReader br)
        {
            List<SDNode> DNode = new List<SDNode>();
            List<SDLeaf> DLeaf = new List<SDLeaf>();
            List<CModel.SMNode> MNode = new List<CModel.SMNode>();

            // load nodes
            br.BaseStream.Seek(header.lumps[LUMP_NODES].fileofs, System.IO.SeekOrigin.Begin);
            while (br.BaseStream.Position < (header.lumps[LUMP_NODES].fileofs + header.lumps[LUMP_NODES].filelen))
            {
                SDNode _DNode;

                _DNode.planenum = br.ReadInt32();

                _DNode.children = new int[2];
                _DNode.children[0] = br.ReadInt32();
                _DNode.children[1] = br.ReadInt32();

                _DNode.mins = new short[3];
                _DNode.mins[0] = br.ReadInt16();
                _DNode.mins[1] = br.ReadInt16();
                _DNode.mins[2] = br.ReadInt16();

                _DNode.maxs = new short[3];
                _DNode.maxs[0] = br.ReadInt16();
                _DNode.maxs[1] = br.ReadInt16();
                _DNode.maxs[2] = br.ReadInt16();

                _DNode.firstface = br.ReadUInt16();
                _DNode.numfaces = br.ReadUInt16();

                DNode.Add(_DNode);
            }

            for (int i = 0; i < DNode.Count; i++)
            {
                CModel.SMNode _MNode;
                int p;

                _MNode.bounds.Min.X = DNode[i].mins[0];
                _MNode.bounds.Min.Y = DNode[i].mins[1];
                _MNode.bounds.Min.Z = DNode[i].mins[2];
                _MNode.bounds.Max.X = DNode[i].maxs[0];
                _MNode.bounds.Max.Y = DNode[i].maxs[1];
                _MNode.bounds.Max.Z = DNode[i].maxs[2];

                _MNode.plane = DNode[i].planenum;

                _MNode.firstsurface = DNode[i].firstface;
                _MNode.numsurfaces = DNode[i].numfaces;
                _MNode.contents = -1; // differentiate from leafs

                _MNode.children = new int[2];
                for (int j = 0; j < 2; j++)
                {
                    p = DNode[i].children[j];

                    if (p >= 0)
                        _MNode.children[j] = p;
                    else
                        _MNode.children[j] = DNode.Count + (-1 - p);
                }

                _MNode.parent = 0;
                _MNode.visframe = 0;

                // leaf specific
                _MNode.cluster = 0;
                _MNode.area = 0;
                _MNode.firstmarksurface = 0;
                _MNode.nummarksurfaces = 0;

                MNode.Add(_MNode);
            }

            // load leafs
            br.BaseStream.Seek(header.lumps[LUMP_LEAFS].fileofs, System.IO.SeekOrigin.Begin);
            while (br.BaseStream.Position < (header.lumps[LUMP_LEAFS].fileofs + header.lumps[LUMP_LEAFS].filelen))
            {
                SDLeaf _DLeaf;

                _DLeaf.contents = br.ReadInt32();

                _DLeaf.cluster = br.ReadInt16();
                _DLeaf.area = br.ReadInt16();

                _DLeaf.mins = new short[3];
                _DLeaf.mins[0] = br.ReadInt16();
                _DLeaf.mins[1] = br.ReadInt16();
                _DLeaf.mins[2] = br.ReadInt16();

                _DLeaf.maxs = new short[3];
                _DLeaf.maxs[0] = br.ReadInt16();
                _DLeaf.maxs[1] = br.ReadInt16();
                _DLeaf.maxs[2] = br.ReadInt16();

                _DLeaf.firstleafface = br.ReadUInt16();
                _DLeaf.numleaffaces = br.ReadUInt16();

                _DLeaf.firstleafbrush = br.ReadUInt16();
                _DLeaf.numleafbrushes = br.ReadUInt16();

                DLeaf.Add(_DLeaf);
            }

            for (int i = 0; i < DLeaf.Count; i++)
            {
                CModel.SMNode _MNode;

                _MNode.bounds.Min.X = DLeaf[i].mins[0];
                _MNode.bounds.Min.Y = DLeaf[i].mins[1];
                _MNode.bounds.Min.Z = DLeaf[i].mins[2];
                _MNode.bounds.Max.X = DLeaf[i].maxs[0];
                _MNode.bounds.Max.Y = DLeaf[i].maxs[1];
                _MNode.bounds.Max.Z = DLeaf[i].maxs[2];

                _MNode.contents = DLeaf[i].contents;

                _MNode.cluster = DLeaf[i].cluster;
                _MNode.area = DLeaf[i].area;

                _MNode.firstmarksurface = DLeaf[i].firstleafface;
                _MNode.nummarksurfaces = DLeaf[i].numleaffaces;

                _MNode.parent = 0;
                _MNode.visframe = 0;

                // node specific
                _MNode.plane = 0;
                _MNode.firstsurface = 0;
                _MNode.numsurfaces = 0;
                _MNode.children = null;

                MNode.Add(_MNode);
            }

            _SModel.numnodes = DNode.Count + DLeaf.Count;
            _SModel.numDecisionNodes = DNode.Count;
            _SModel.numleafs = DLeaf.Count;
            _SModel.nodes = MNode.ToArray();

            // chain decendants
            Mod_SetParent(ref _SModel, 0, -1);
        }
Example #30
0
        /// <summary>
        /// Reads the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public void Read(System.IO.BinaryReader reader)
        {
            Ident = reader.ReadBytes(16);

            // Check for magic number
            if (Ident[0] != MagicNumber[0] || Ident[1] != MagicNumber[1] || Ident[2] != MagicNumber[2] || Ident[3] != MagicNumber[3])
            {
                // Magic number not present, so it seems to be an invalid ELF file
                throw new NotSupportedException("This is not a valid ELF file");
            }

            Type = (Elf32FileType)reader.ReadUInt16();
            Machine = (Elf32MachineType)reader.ReadUInt16();
            Version = (Elf32Version)reader.ReadUInt32();
            EntryAddress = reader.ReadUInt32();
            ProgramHeaderOffset = reader.ReadUInt32();
            SectionHeaderOffset = reader.ReadUInt32();
            Flags = reader.ReadUInt32();
            ElfHeaderSize = reader.ReadUInt16();
            ProgramHeaderEntrySize = reader.ReadUInt16();
            ProgramHeaderNumber = reader.ReadUInt16();
            SectionHeaderEntrySize = reader.ReadUInt16();
            SectionHeaderNumber = reader.ReadUInt16();
            SectionHeaderStringIndex = reader.ReadUInt16();
        }