protected override void Load(BEBinaryReader cb)
 {
     _info.ConsistencyLevel = (ConsistencyLevel)cb.ReadInt16();
     _info.Received         = cb.ReadInt32();
     _info.BlockFor         = cb.ReadInt32();
     _info.IsDataPresent    = cb.ReadByte() != 0;
 }
Exemplo n.º 2
0
 protected override void Load(BEBinaryReader cb)
 {
     _info.ConsistencyLevel = (ConsistencyLevel) cb.ReadInt16();
     _info.Received = cb.ReadInt32();
     _info.BlockFor = cb.ReadInt32();
     _info.IsDataPresent = cb.ReadByte() != 0;
 }
 protected override void Load(BEBinaryReader reader)
 {
     _consistency = (ConsistencyLevel) reader.ReadInt16();
     _received = reader.ReadInt32();
     _blockFor = reader.ReadInt32();
     if (_isFailure)
     {
         _failures = reader.ReadInt32();
     }
     _dataPresent = reader.ReadByte() != 0;
 }
Exemplo n.º 4
0
 protected override void Load(BEBinaryReader reader)
 {
     _consistency = (ConsistencyLevel)reader.ReadInt16();
     _received    = reader.ReadInt32();
     _blockFor    = reader.ReadInt32();
     if (_isFailure)
     {
         _failures = reader.ReadInt32();
     }
     _dataPresent = reader.ReadByte() != 0;
 }
Exemplo n.º 5
0
        int readVarLengthValue(BEBinaryReader stream)
        {
            int  value = 0;
            byte b     = 128;

            while ((b & 128) == 128)
            {
                b = stream.ReadByte();
                chunkBytesRead++;
                value <<= 7;
                value  |= (b & 127);
            }
            return(value);
        }
Exemplo n.º 6
0
 internal void Load(CassandraErrorType code, string message, BEBinaryReader cb)
 {
     _info.ConsistencyLevel = (ConsistencyLevel)cb.ReadInt16();
     _info.Received = cb.ReadInt32();
     _info.BlockFor = cb.ReadInt32();
     _info.IsDataPresent = cb.ReadByte() != 0;
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        void readEvent(Track track, ref int absoluteTime, BEBinaryReader stream, int chunkSize, Uri fileUri)
        {
            int deltaTime = readVarLengthValue(stream);

            absoluteTime += deltaTime;

            byte firstByte = stream.ReadByte();             //First byte in event

            chunkBytesRead++;
            if (firstByte == 0xff)             //meta or sysex event
            {
                MetaEvent e    = new MetaEvent();
                int       time = absoluteTime;
                e.Type = stream.ReadByte();
                chunkBytesRead++;
                int length = readVarLengthValue(stream);
                if (e.Type == 0x2f && length != 0)
                {
                    throw (new FileFormatException(fileUri, "End-of-track event has data length of " + length + ". Should be 0."));
                }
                e.Data          = stream.ReadBytes(length);
                chunkBytesRead += length;
                if (e.Type == 0x51)                 //Tempo event
                {
                    TempoEvent te = new TempoEvent(absoluteTime, e.Data);
                    if (!double.IsInfinity(te.Tempo))
                    {
                        if (tempoEvents.Count > 0 && te.Time == tempoEvents.Last().Time)
                        {
                            tempoEvents[tempoEvents.Count - 1] = te;
                        }
                        else
                        {
                            tempoEvents.Add(te);
                        }
                    }
                }
                else if (e.Type == 0x03)
                {
                    track.Name = ASCIIEncoding.ASCII.GetString(e.Data);
                }

                if (e.Type == 0x2f && chunkBytesRead != chunkSize)
                {
                    throw (new FileFormatException(fileUri, "End-of-track event at byte " + chunkBytesRead + " of " + chunkSize + "."));
                }
                if (e.Type != 0x2f && chunkBytesRead >= chunkSize)
                {
                    throw (new FileFormatException(fileUri, "End-of-track event missing at end of track."));
                }
            }
            else if (firstByte == 0xf0 || firstByte == 0xf7)             //sysex
            {
                byte b;
                do
                {
                    b = stream.ReadByte();
                    chunkBytesRead++;
                } while (b != 0xf7);
            }
            else             //Channel event
            {
                ChannelEvent chnEvent = new ChannelEvent
                {
                };
                int time = absoluteTime;
                if (firstByte > 127)                 //Status information present
                {
                    chnEvent.Channel = runningStatus.Channel = (byte)(firstByte & 0xf);
                    chnEvent.Type    = runningStatus.EventType = (byte)((firstByte >> 4) & 0xf);
                    chnEvent.Param1  = stream.ReadByte();
                    chunkBytesRead++;
                }
                else                 //Running status
                {
                    chnEvent.Type    = runningStatus.EventType;
                    chnEvent.Channel = runningStatus.Channel;
                    chnEvent.Param1  = firstByte;
                }
                if (chnEvent.Type != 0xc && chnEvent.Type != 0xd)
                {
                    chnEvent.Param2 = stream.ReadByte();
                    chunkBytesRead++;
                }

                if (chnEvent.Type == 0x9)                  //Note on/off
                {
                    //param1 = pitch, param2 = velocity

                    //Note off if velocity is 0
                    if (chnEvent.Param2 == 0)
                    {
                        chnEvent.Type = 0x8;
                    }
                    else                     //Note on
                    {
                        startOfPlayingNotes[chnEvent.Channel, chnEvent.Param1].AddLast(absoluteTime);
                        if (minPitch > chnEvent.Param1)
                        {
                            minPitch = chnEvent.Param1;
                        }
                        if (maxPitch < chnEvent.Param1)
                        {
                            maxPitch = chnEvent.Param1;
                        }
                    }
                }
                if (chnEvent.Type == 0x8)                  //note off
                {
                    //param1 = pitch, param2 = velocity
                    if (startOfPlayingNotes[chnEvent.Channel, chnEvent.Param1].Count == 0)
                    {
                        return;
                    }

                    Note note = new Note();
                    note.start    = startOfPlayingNotes[chnEvent.Channel, chnEvent.Param1].First();
                    note.stop     = absoluteTime;
                    note.channel  = chnEvent.Channel;
                    note.pitch    = chnEvent.Param1;
                    note.velocity = chnEvent.Param2;
                    for (int i = 0; i <= track.Notes.Count; i++)
                    {
                        if (i == track.Notes.Count || track.Notes[i].start > note.start)
                        {
                            track.Notes.Insert(i, note);
                            break;
                        }
                    }
                    startOfPlayingNotes[chnEvent.Channel, chnEvent.Param1].RemoveFirst();
                }

                if (chunkBytesRead >= chunkSize)
                {
                    throw (new FileFormatException(fileUri, "Error at chunk byte " + chunkBytesRead + " of " + chunkSize + ". Last track event is a channel event. Should be meta event."));
                }
            }
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }