internal ErrorResponse(ResponseFrame frame) : base(frame)
        {
            var ctype   = (CassandraErrorType)BEBinaryReader.ReadInt32();
            var message = BEBinaryReader.ReadString();

            Output = OutputError.CreateOutputError(ctype, message, BEBinaryReader);
        }
Пример #2
0
 protected override void Load(BEBinaryReader cb)
 {
     _info.ConsistencyLevel = (ConsistencyLevel)cb.ReadInt16();
     _info.Received         = cb.ReadInt32();
     _info.BlockFor         = cb.ReadInt32();
     _info.WriteType        = cb.ReadString();
 }
        internal ResultResponse(ResponseFrame frame) : base(frame)
        {
            Kind = (ResultResponseKind)BEBinaryReader.ReadInt32();
            switch (Kind)
            {
            case ResultResponseKind.Void:
                Output = new OutputVoid(TraceID);
                break;

            case ResultResponseKind.Rows:
                Output = new OutputRows(BEBinaryReader, frame.RawStream is BufferedProtoBuf, TraceID);
                break;

            case ResultResponseKind.SetKeyspace:
                Output = new OutputSetKeyspace(BEBinaryReader.ReadString());
                break;

            case ResultResponseKind.Prepared:
                Output = new OutputPrepared(BEBinaryReader);
                break;

            case ResultResponseKind.SchemaChange:
                Output = new OutputSchemaChange(BEBinaryReader, TraceID);
                break;

            default:
                throw new DriverInternalError("Unknown ResultResponseKind Type");
            }
        }
Пример #4
0
 protected override void Load(BEBinaryReader cb)
 {
     _info.ConsistencyLevel = (ConsistencyLevel) cb.ReadInt16();
     _info.Received = cb.ReadInt32();
     _info.BlockFor = cb.ReadInt32();
     _info.WriteType = cb.ReadString();
 }
Пример #5
0
 protected override void Load(BEBinaryReader reader)
 {
     _consistencyLevel = (ConsistencyLevel)reader.ReadInt16();
     _received         = reader.ReadInt32();
     _blockFor         = reader.ReadInt32();
     if (_isFailure)
     {
         _failures = reader.ReadInt32();
     }
     _writeType = reader.ReadString();
 }
 protected override void Load(BEBinaryReader reader)
 {
     _consistencyLevel = (ConsistencyLevel) reader.ReadInt16();
     _received = reader.ReadInt32();
     _blockFor = reader.ReadInt32();
     if (_isFailure)
     {
         _failures = reader.ReadInt32();
     }
     _writeType = reader.ReadString();
 }
Пример #7
0
        internal EventResponse(ResponseFrame frame)
            : base(frame)
        {
            var eventTypeString = BEBinaryReader.ReadString();

            if (eventTypeString == "TOPOLOGY_CHANGE")
            {
                var ce = new TopologyChangeEventArgs();
                ce.What = BEBinaryReader.ReadString() == "NEW_NODE"
                              ? TopologyChangeEventArgs.Reason.NewNode
                              : TopologyChangeEventArgs.Reason.RemovedNode;
                ce.Address         = BEBinaryReader.ReadInet().Address;
                CassandraEventArgs = ce;
                return;
            }
            else if (eventTypeString == "STATUS_CHANGE")
            {
                var ce = new StatusChangeEventArgs();
                ce.What = BEBinaryReader.ReadString() == "UP"
                              ? StatusChangeEventArgs.Reason.Up
                              : StatusChangeEventArgs.Reason.Down;
                ce.Address         = BEBinaryReader.ReadInet().Address;
                CassandraEventArgs = ce;
                return;
            }
            else if (eventTypeString == "SCHEMA_CHANGE")
            {
                var ce = new SchemaChangeEventArgs();
                var m  = BEBinaryReader.ReadString();
                ce.What = m == "CREATED"
                              ? SchemaChangeEventArgs.Reason.Created
                              : (m == "UPDATED"
                                     ? SchemaChangeEventArgs.Reason.Updated
                                     : SchemaChangeEventArgs.Reason.Dropped);
                ce.Keyspace        = BEBinaryReader.ReadString();
                ce.Table           = BEBinaryReader.ReadString();
                CassandraEventArgs = ce;
                return;
            }

            var ex = new DriverInternalError("Unknown Event Type");

            _logger.Error(ex);
            throw ex;
        }
Пример #8
0
        public PackFile(string filename)
        {
            this.filename = filename;
            int files = 5;
            int subpacks = 2;

            using (FileStream s = File.Open(filename, FileMode.Open, FileAccess.Read))
            using (BinaryReader reader = new BEBinaryReader(s))
            {
                while (true)
                {
                    header = reader.ReadInt32();
                    if (header == 0) break;
                    filesInPack = reader.ReadInt32();
                    //packData.header.i3 = reader.ReadInt32();

                   files = filesInPack;

                    for (int i = 0; i < files; i++)
                    {
                        string readName = reader.ReadString();
                        filenames.Add(readName);

                        FileData fileDat = new FileData();
                        fileDat.offset = reader.ReadInt32();
                        fileDat.size = reader.ReadInt32();
                        fileDat.i3 = reader.ReadInt32();
                        fileData.Add(fileDat);

                        this.files++;
                    }

                    s.Seek(header, SeekOrigin.Begin);
                }

            }
        }
Пример #9
0
 internal void Load(CassandraErrorType code, string message, BEBinaryReader cb)
 {
     _info.ConsistencyLevel = (ConsistencyLevel)cb.ReadInt16();
     _info.Received = cb.ReadInt32();
     _info.BlockFor = cb.ReadInt32();
     _info.WriteType = cb.ReadString();
 }
Пример #10
0
 internal void Load(CassandraErrorType code, string message, BEBinaryReader cb)
 {
     _info.Ks = cb.ReadString();
     _info.Table = cb.ReadString();
 }
Пример #11
0
 protected override void Load(BEBinaryReader cb)
 {
     _info.Ks = cb.ReadString();
     _info.Table = cb.ReadString();
 }
Пример #12
0
        public static EXP Load(string path)
        {
            FileInfo fi = new FileInfo(path);

            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            EXP exp = new EXP()
            {
                name     = Path.GetFileNameWithoutExtension(path),
                location = Path.GetDirectoryName(path) + "\\"
            };

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead()))
            {
                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    string section = br.ReadString(4);
                    int    length  = 0;

                    switch (section)
                    {
                    case "FORM":
                        length = (int)br.ReadUInt32();
                        break;

                    case "TERR":
                    case "XOBF":
                        break;

                    case "TITL":
                        length = (int)br.ReadUInt32();
                        if (length > 0)
                        {
                            throw new NotImplementedException(string.Format("TITL section has a length ({0}), don't know what to do!", length));
                        }
                        break;

                    case "TEXT":
                        length = (int)br.ReadUInt32();
                        if (length > 0)
                        {
                            throw new NotImplementedException(string.Format("TEXT section has a length ({0}), don't know what to do!", length));
                        }
                        break;

                    case "HEAD":
                        length = (int)br.ReadUInt32();
                        Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt16());
                        Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt32());
                        exp.entryCount = br.ReadUInt16();
                        Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt32());
                        Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt16());
                        Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt16());
                        Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt16());
                        Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt32());
                        Logger.LogToFile(Logger.LogLevel.Debug, "U: {0}", br.ReadUInt32());
                        break;

                    case "BIN ":
                        length = (int)br.ReadUInt32();
                        exp.contents.Add(new EXPEntry {
                            Size = length, Offset = (int)br.BaseStream.Position, EntryType = EXPEntryType.Binary
                        });
                        br.ReadBytes(length);
                        break;

                    case "ANM ":
                        length = (int)br.ReadUInt32();
                        exp.contents.Add(new EXPEntry {
                            Size = length, Offset = (int)br.BaseStream.Position, EntryType = EXPEntryType.Animation
                        });
                        br.ReadBytes(length);
                        break;

                    case "PLTX":
                        length = (int)br.ReadUInt32();
                        if (length > 0)
                        {
                            throw new NotImplementedException(string.Format("PLTX section has a length ({0}), don't know what to do!", length));
                        }
                        break;

                    default:
                        throw new NotImplementedException(string.Format("Unexpected section \"{0}\" at {1,0:X0}", section, br.BaseStream.Position - 4));
                    }
                }
            }

            return(exp);
        }
Пример #13
0
        public static ACT Load(string path)
        {
            FileInfo fi = new FileInfo(path);

            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            ACT act = new ACT();

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                if (br.ReadUInt32() != 0x12 ||
                    br.ReadUInt32() != 0x8 ||
                    br.ReadUInt32() != 0x1 ||
                    br.ReadUInt32() != 0x2)
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid ACT file", path);
                    return(null);
                }

                ACTNode a;

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    Section tag = (Section)br.ReadUInt32();
                    int     _   = (int)br.ReadUInt32();

                    a = new ACTNode(tag);

                    switch (tag)
                    {
                    case Section.Name:      // 00 00 00 23
                        a.ActorType   = (ActorType)br.ReadByte();
                        a.RenderStyle = (RenderStyle)br.ReadByte();
                        a.Identifier  = br.ReadString();
                        if (a.Identifier.Length == 0)
                        {
                            a.Identifier = "NO_IDENTIFIER";
                        }
                        break;

                    case Section.Model:
                        a.Model = br.ReadString();
                        break;

                    case Section.Section37:     // 00 00 00 25
                        break;

                    case Section.Material:
                        a.Material = br.ReadString();
                        break;

                    case Section.SubLevelBegin:     // 00 00 00 29
                        break;

                    case Section.SubLevelEnd:
                        break;

                    case Section.Matrix:     // 00 00 00 2B
                        a.Transform = new Matrix3D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        break;

                    case Section.BoundingBox:     // 00 00 00 32
                        a.Bounds = new MeshExtents(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
                        break;

                    case Section.EOF:
                        break;

                    default:
                        Console.WriteLine("Unknown ACT tag: {0} ({1} of {2})", tag, br.BaseStream.Position, br.BaseStream.Length);
                        return(null);
                    }

                    act.Sections.Add(a);
                }
            }

            return(act);
        }
Пример #14
0
        public static DAT Load(string path)
        {
            FileInfo fi = new FileInfo(path);

            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            DAT dat = new DAT();

            DatMesh D = new DatMesh();
            int     count;

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                if (br.ReadUInt32() != 0x12 ||
                    br.ReadUInt32() != 0x8 ||
                    br.ReadUInt32() != 0xFACE ||
                    br.ReadUInt32() != 0x2)
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid DAT file", path);
                    return(null);
                }

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    int tag    = (int)br.ReadUInt32();
                    int length = (int)br.ReadUInt32();

                    switch (tag)
                    {
                    case 54:     // 00 00 00 36
                        D = new DatMesh()
                        {
                            UnknownAttribute = br.ReadUInt16(),       // I think this is actually two byte values
                            Name             = br.ReadString()
                        };
                        break;

                    case 23:     // 00 00 00 17 : vertex data
                        count = (int)br.ReadUInt32();

                        for (int i = 0; i < count; i++)
                        {
                            D.Mesh.AddListVertex(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        }
                        break;

                    case 24:     // 00 00 00 18 : UV co-ordinates
                        count = (int)br.ReadUInt32();

                        for (int i = 0; i < count; i++)
                        {
                            D.Mesh.AddListUV(br.ReadSingle(), br.ReadSingle());
                        }
                        break;

                    case 53:        // 00 00 00 35 : faces
                        count = (int)br.ReadUInt32();

                        for (int i = 0; i < count; i++)
                        {
                            int faceID = D.Mesh.AddFace(br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16());

                            D.Mesh.Faces[faceID].SmoothingGroup = br.ReadUInt16();

                            br.ReadByte();     // number of edges, 0 and 3 = tri.  4 = quad.
                        }
                        break;

                    case 22:     // 00 00 00 16 : material list
                        D.Mesh.Materials.AddRange(br.ReadStrings((int)br.ReadUInt32()));
                        break;

                    case 26:             // 00 00 00 1A : face textures
                        count = (int)br.ReadUInt32();
                        br.ReadBytes(4); // f**k knows what this is
                        for (int i = 0; i < count; i++)
                        {
                            D.Mesh.SetMaterialForFace(i, br.ReadUInt16() - 1);
                        }
                        break;

                    case 0:
                        // EndOfFile
                        D.Mesh.ProcessMesh();
                        dat.DatMeshes.Add(D);
                        break;

                    default:
                        Logger.LogToFile(Logger.LogLevel.Error, "Unknown DAT tag: {0} ({1:x2})", tag, br.BaseStream.Position);
                        return(null);
                    }
                }
            }

            return(dat);
        }
Пример #15
0
        public static MAT Load(string path)
        {
            FileInfo fi = new FileInfo(path);

            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            MAT mat = new MAT();

            MATMaterial M      = new MATMaterial();
            bool        bDebug = false;

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                br.ReadBytes(16); // Header

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    int tag    = (int)br.ReadUInt32();
                    int length = (int)br.ReadUInt32();

                    switch (tag)
                    {
                    case 0x4:
                        // C1 mat file
                        M = new MATMaterial();

                        M.DiffuseColour[0]    = br.ReadByte();  // R
                        M.DiffuseColour[1]    = br.ReadByte();  // G
                        M.DiffuseColour[2]    = br.ReadByte();  // B
                        M.DiffuseColour[3]    = br.ReadByte();  // A
                        M.AmbientLighting     = br.ReadSingle();
                        M.DirectionalLighting = br.ReadSingle();
                        M.SpecularLighting    = br.ReadSingle();
                        M.SpecularPower       = br.ReadSingle();
                        M.SetFlags((int)br.ReadUInt16());     // Flags
                        if (M.GetFlag(MATMaterial.Settings.UnknownSetting) || M.GetFlag(MATMaterial.Settings.IFromV) || M.GetFlag(MATMaterial.Settings.UFromI) || M.GetFlag(MATMaterial.Settings.VFromI))
                        {
                            bDebug = true;
                        }
                        M.UVMatrix = new Matrix2D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        byte x1 = br.ReadByte();     // ??
                        byte x2 = br.ReadByte();     // ??
                        M.Name = br.ReadString();

                        if (bDebug)
                        {
                            Console.WriteLine(path + " :: " + M.Name); bDebug = false;
                        }
                        break;

                    case 0x3c:
                        M = new MATMaterial();

                        M.DiffuseColour[0]    = br.ReadByte();  // R
                        M.DiffuseColour[1]    = br.ReadByte();  // G
                        M.DiffuseColour[2]    = br.ReadByte();  // B
                        M.DiffuseColour[3]    = br.ReadByte();  // A
                        M.AmbientLighting     = br.ReadSingle();
                        M.DirectionalLighting = br.ReadSingle();
                        M.SpecularLighting    = br.ReadSingle();
                        M.SpecularPower       = br.ReadSingle();
                        M.SetFlags((int)br.ReadUInt32());     // Flags
                        M.UVMatrix = new Matrix2D(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        if (br.ReadUInt32() != 169803776)
                        {
                            Console.WriteLine("Weird Beard! (" + path + ")");
                        }
                        br.ReadBytes(13);     // 13 bytes of nothing
                        M.Name = br.ReadString();
                        break;

                    case 0x1c:
                        M.Texture = br.ReadString();
                        break;

                    case 0x1f:
                        string _ = br.ReadString();     // shadetable
                        break;

                    case 0x0:
                        mat.Materials.Add(M);
                        break;

                    default:
                        Logger.LogToFile(Logger.LogLevel.Error, "Unknown MAT tag: {0} ({1})", tag, br.BaseStream.Position.ToString("X"));
                        return(null);
                    }
                }
            }

            return(mat);
        }
 internal AuthenticateResponse(ResponseFrame frame) : base(frame)
 {
     Authenticator = BEBinaryReader.ReadString();
 }
Пример #17
0
 protected override void Load(BEBinaryReader cb)
 {
     _info.Ks    = cb.ReadString();
     _info.Table = cb.ReadString();
 }
Пример #18
0
        public static PIX Load(string path)
        {
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            FileInfo fi  = new FileInfo(path);
            PIX      pix = new PIX();

            using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default))
            {
                if (br.ReadUInt32() != 0x12 ||
                    br.ReadUInt32() != 0x08 ||
                    br.ReadUInt32() != 0x02 ||
                    br.ReadUInt32() != 0x02)
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid PIX file", path);
                    return(null);
                }

                Stack <PIXIE> pixies = new Stack <PIXIE>();

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    if (br.BaseStream.Position + 8 > br.BaseStream.Length)
                    {
                        Logger.LogToFile(Logger.LogLevel.Error, $"{path} is malformed.  The last {br.BaseStream.Length - br.BaseStream.Position} bytes are redundant and should be removed");
                        break;
                    }

                    int tag = (int)br.ReadUInt32();
                    br.ReadUInt32();        // length

                    switch (tag)
                    {
                    case 0x03:      // 3
                        pixies.Push(new PIXIE()
                        {
                            Format     = (PIXIE.PixelmapFormat)br.ReadByte(),
                            RowSize    = br.ReadUInt16(),
                            Width      = br.ReadUInt16(),
                            Height     = br.ReadUInt16(),
                            HalfWidth  = br.ReadUInt16(),
                            HalfHeight = br.ReadUInt16(),
                            Name       = br.ReadString()
                        });
                        break;

                    case 0x21:      // 33
                        pixies.Peek().PixelCount = (int)br.ReadUInt32();
                        pixies.Peek().PixelSize  = (int)br.ReadUInt32();
                        pixies.Peek().SetData(br.ReadBytes(pixies.Peek().DataLength));
                        break;

                    case 0x22:      // 34
                    case 0x00:      // 0
                        pix.Pixies.Add(pixies.Pop());
                        break;

                    case 0x3d:
                        pixies.Push(new PIXIE
                        {
                            Format  = (PIXIE.PixelmapFormat)br.ReadByte(),
                            RowSize = br.ReadUInt16(),
                            Width   = br.ReadUInt16(),
                            Height  = br.ReadUInt16()
                        });
                        br.ReadBytes(6);
                        pixies.Peek().Name = br.ReadString();
                        break;

                    default:
                        Logger.LogToFile(Logger.LogLevel.Error, "Unknown PIX tag: {0} ({1:x2})", tag, br.BaseStream.Position);
                        return(null);
                    }
                }
            }

            return(pix);
        }