コード例 #1
0
        public void Read(Stream inputStream)
        {
            BinaryReader reader = new BinaryReader(inputStream, Encoding.UTF8, true);
            int magicNumber = reader.ReadInt32();
            int version = reader.ReadInt32(); // GZ 2, TPP 3
            int endianess = reader.ReadInt32(); // LE, BE
            int entryCount = reader.ReadInt32();
            int valuesOffset = reader.ReadInt32();
            int keysOffset = reader.ReadInt32();

            inputStream.Position = valuesOffset;
            Dictionary<int, LangEntry> offsetEntryDictionary = new Dictionary<int, LangEntry>();
            for (int i = 0; i < entryCount; i++)
            {
                int valuePosition = (int)inputStream.Position - valuesOffset;
                short valueConstant = reader.ReadInt16();
                Debug.Assert(valueConstant == 1);
                string value = reader.ReadNullTerminatedString();
                offsetEntryDictionary.Add(valuePosition, new LangEntry
                {
                    Value = value
                });
            }
            
            inputStream.Position = keysOffset;
            for (int i = 0; i < entryCount; i++)
            {
                uint key = reader.ReadUInt32();
                int offset = reader.ReadInt32();

                offsetEntryDictionary[offset].Key = key;
            }

            Entries = offsetEntryDictionary.Values.ToList();
        }
コード例 #2
0
ファイル: ArcFileSystem.cs プロジェクト: JokieW/ShiningHill
        public void ReadAll()
        {
            CustomPostprocessor.DoImports = false;
            try
            {
                BinaryReader reader = new BinaryReader(new MemoryStream(data));
                reader.SkipBytes(16);
                reader.SkipBytes(12);

                Archive arc = null;

                while (reader.BaseStream.Position <= 90000)
                {
                    short entryType = reader.ReadInt16();
                    short subType = reader.ReadInt16();
                    short entryCount = reader.ReadInt16();
                    short entryIndex = reader.ReadInt16();
                    string name = reader.ReadNullTerminatedString();

                    if (reader.PeekChar() == 0)
                    {
                        reader.SkipByte();
                    }

                    if (entryType == 2)
                    {
                        arc = new Archive(name, AssetDatabase.LoadAssetAtPath("Assets/SilentHill3/Archives/" + name + ".arc", typeof(UnityEngine.Object)));
                        arc.OpenArchive();
                    }

                    if (entryType == 3)
                    {
                        try
                        {
                            name = name.Replace("tmp", arc.NameAsPath());
                            string path = "Assets/SilentHill3/Resources/" + name;
                            path = Path.GetDirectoryName(path);
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }
                            File.WriteAllBytes("Assets/SilentHill3/Resources/" + name, arc.AllFiles[entryCount].data);
                        }
                        catch (Exception)
                        {
                            Debug.LogError("Problem at " + name + " [" + entryIndex + "](" + arc.AllFiles.Count + ") sub " + subType.ToString("X"));
                        }
                    }
                }
                AssetDatabase.Refresh();
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            CustomPostprocessor.DoImports = true;
        }
コード例 #3
0
ファイル: TerrainModels.cs プロジェクト: Nihlus/libwarcraft
 public void LoadBinaryData(byte[] inData)
 {
     using (MemoryStream ms = new MemoryStream(inData))
     {
         using (BinaryReader br = new BinaryReader(ms))
         {
             this.Filenames.Add(br.ReadNullTerminatedString());
         }
     }
 }
コード例 #4
0
ファイル: ModelSkybox.cs プロジェクト: Nihlus/libwarcraft
 public void LoadBinaryData(byte[] inData)
 {
     using (MemoryStream ms = new MemoryStream(inData))
     {
         using (BinaryReader br = new BinaryReader(ms))
         {
             this.SkyboxName = br.ReadNullTerminatedString();
         }
     }
 }
コード例 #5
0
ファイル: ddrPTH.cs プロジェクト: DevilboxGames/ToxicRagers
        public static PTH Load(string path)
        {
            FileInfo fi = new FileInfo(path);
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            PTH pth = new PTH();

            using (var br = new BinaryReader(new FileStream(path, FileMode.Open)))
            {
                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    pth.contents.Add(new PTHEntry { Name = br.ReadNullTerminatedString(), Size = (int)br.ReadUInt32(), Offset = (int)br.ReadUInt32() });
                }
            }

            return pth;
        }
コード例 #6
0
        /// <summary>
        /// Loads this SBM model
        /// </summary>
        /// <returns></returns>
        public bool Load(out string err)
        {
            // Check the file exists
            if (!File.Exists(filename))
            {
                err = "File not found";
                return false;
            }

            // Load it
            using (FileStream strm = File.OpenRead(filename))
            {
                // Create reader
                BinaryReader rdr = new BinaryReader(strm);

                // Read header
                string magic = new string(rdr.ReadChars(4));
                if (magic != "SBM\0")
                {
                    err = "Specified file is not an SBM file";
                    return false;
                }
                int version = rdr.ReadInt32();
                if (version != 1)
                {
                    err = "Unsupported SBM version";
                    return false;
                }
                int num_materials = rdr.ReadInt32();
                int num_meshes = rdr.ReadInt32();

                // Read all materials
                string[] materials = new string[num_materials];
                for (int i = 0; i < num_materials; i++)
                    materials[i] = rdr.ReadNullTerminatedString();

                // Read all meshes
                meshes = new SBMMesh[num_meshes];
                for (int i = 0; i < num_meshes; i++)
                {
                    // Read mesh header
                    int num_vertices = rdr.ReadInt32();
                    int num_submeshes = rdr.ReadInt32();

                    // Create mesh builder
                    MeshBuilder builder = new MeshBuilder();
                    builder.UseNormals = true;
                    builder.UseTexCoords = true;
                    builder.UseTangents = true;

                    // Read all vertices
                    for (int j = 0; j < num_vertices; j++)
                    {
                        builder.AddPosition(new Vector3(rdr.ReadSingle(), rdr.ReadSingle(), rdr.ReadSingle()));
                        builder.AddNormal(new Vector3(rdr.ReadSingle(), rdr.ReadSingle(), rdr.ReadSingle()));
                        builder.AddTextureCoord(new Vector2(rdr.ReadSingle(), rdr.ReadSingle()));
                        builder.AddTangent(new Vector3(rdr.ReadSingle(), rdr.ReadSingle(), rdr.ReadSingle()));
                    }

                    // Loop each submesh
                    string[] meshmats = new string[num_submeshes];
                    for (int j = 0; j < num_submeshes; j++)
                    {
                        // Read submesh header
                        int num_indices = rdr.ReadInt32();
                        int material_index = rdr.ReadInt32();
                        meshmats[j] = materials[material_index];

                        // Read all indices
                        for (int k = 0; k < num_indices; k++)
                            builder.AddIndex(j, rdr.ReadUInt32());
                    }

                    // Add element to mesh array
                    SBMMesh sbmmesh = new SBMMesh();
                    sbmmesh.Mesh = builder.Build();
                    sbmmesh.Materials = meshmats;
                    meshes[i] = sbmmesh;
                }
            }

            // Success
            err = null;
            return true;
        }
コード例 #7
0
ファイル: ModelGroupNames.cs プロジェクト: Nihlus/libwarcraft
        public void LoadBinaryData(byte[] inData)
        {
            using (MemoryStream ms = new MemoryStream(inData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    // Skip the first two bytes, since they're always zero
                    ms.Position += 2;

                    while (ms.Position < ms.Length)
                    {
                        this.GroupNames.Add(ms.Position, br.ReadNullTerminatedString());
                    }
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Deserialzes the provided binary data of the object. This is the full data block which follows the data
        /// signature and data block length.
        /// </summary>
        /// <param name="inData">The binary data containing the object.</param>
        public void LoadBinaryData(byte[] inData)
        {
            using (MemoryStream ms = new MemoryStream(inData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    while (ms.Position < ms.Length)
                    {
                        this.DoodadNames.Add(new KeyValuePair<long, string>(ms.Position, br.ReadNullTerminatedString()));
                    }
                }
            }

            // Remove null entries from the doodad list
            this.DoodadNames.RemoveAll(s => s.Value.Equals("\0"));
        }
コード例 #9
0
ファイル: VpkDirectory.cs プロジェクト: silky/sledge
 private void ReadDirectoryEntries(BinaryReader br)
 {
     String extension, path, filename;
     while ((extension = br.ReadNullTerminatedString()).Length > 0)
     {
         while ((path = br.ReadNullTerminatedString()).Length > 0)
         {
             // Single space = root directory
             path = path == " " ? "" : path.Replace('\\', '/').Trim('/');
             while ((filename = br.ReadNullTerminatedString()).Length > 0)
             {
                 // get me some file information
                 var entry = ReadEntry(br, path + "/" + filename + "." + extension);
                 Entries.Add(entry.FullName, entry);
             }
         }
     }
 }
コード例 #10
0
ファイル: ModelListFile.cs プロジェクト: Jiwan/Revise
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));

            short modelFileCount = reader.ReadInt16();

            for (int i = 0; i < modelFileCount; i++) {
                string modelFile = reader.ReadNullTerminatedString();

                ModelFiles.Add(modelFile);
            }

            short textureFileCount = reader.ReadInt16();

            for (int i = 0; i < textureFileCount; i++) {
                TextureFile texture = new TextureFile();
                texture.FilePath = reader.ReadNullTerminatedString();
                texture.UseSkinShader = reader.ReadInt16() != 0;
                texture.AlphaEnabled = reader.ReadInt16() != 0;
                texture.TwoSided = reader.ReadInt16() != 0;
                texture.AlphaTestEnabled = reader.ReadInt16() != 0;
                texture.AlphaReference = reader.ReadInt16();
                texture.DepthTestEnabled = reader.ReadInt16() != 0;
                texture.DepthWriteEnabled = reader.ReadInt16() != 0;
                texture.BlendType = (BlendType)reader.ReadInt16();
                texture.UseSpecularShader = reader.ReadInt16() != 0;
                texture.Alpha = reader.ReadSingle();
                texture.GlowType = (GlowType)reader.ReadInt16();
                texture.GlowColour = reader.ReadColour3();

                TextureFiles.Add(texture);
            }

            short effectFileCount = reader.ReadInt16();

            for (int i = 0; i < effectFileCount; i++) {
                string effectFile = reader.ReadNullTerminatedString();

                EffectFiles.Add(effectFile);
            }

            short objectCount = reader.ReadInt16();

            for (int i = 0; i < objectCount; i++) {
                ModelListObject @object = new ModelListObject();

                int cylinderRadius = reader.ReadInt32();
                @object.BoundingCylinder = new BoundingCylinder(new Vector2(reader.ReadInt32(), reader.ReadInt32()), cylinderRadius);

                int partCount = reader.ReadInt16();

                if (partCount > 0) {
                    for (int j = 0; j < partCount; j++) {
                        ModelListPart part = new ModelListPart();
                        part.Model = reader.ReadInt16();
                        part.Texture = reader.ReadInt16();

                        byte propertyType = 0;

                        while ((propertyType = reader.ReadByte()) != 0) {
                            byte size = reader.ReadByte();

                            switch ((ModelListPropertyType)propertyType) {
                                case ModelListPropertyType.Position:
                                    part.Position = reader.ReadVector3();
                                    break;
                                case ModelListPropertyType.Rotation:
                                    part.Rotation = reader.ReadQuaternion(true);
                                    break;
                                case ModelListPropertyType.Scale:
                                    part.Scale = reader.ReadVector3();
                                    break;
                                case ModelListPropertyType.AxisRotation:
                                    part.AxisRotation = reader.ReadQuaternion(true);
                                    break;
                                case ModelListPropertyType.Parent:
                                    part.Parent = reader.ReadInt16();
                                    break;
                                case ModelListPropertyType.Collision:
                                    part.Collision = (CollisionType)reader.ReadInt16();
                                    break;
                                case ModelListPropertyType.ConstantAnimation:
                                    part.AnimationFilePath = reader.ReadString(size);
                                    break;
                                case ModelListPropertyType.VisibleRangeSet:
                                    part.VisibleRangeSet = reader.ReadInt16();
                                    break;
                                case ModelListPropertyType.UseLightmap:
                                    part.UseLightmap = reader.ReadInt16() != 0;
                                    break;
                                case ModelListPropertyType.BoneIndex:
                                    part.BoneIndex = reader.ReadInt16();
                                    break;
                                case ModelListPropertyType.DummyIndex:
                                    part.DummyIndex = reader.ReadInt16();
                                    break;
                                default:
                                    if (propertyType >= (int)ModelListPropertyType.Animation && propertyType < (int)ModelListPropertyType.Animation + ModelListPart.ANIMATION_COUNT) {
                                        propertyType -= (int)ModelListPropertyType.Animation;

                                        if (propertyType < ModelListPart.MONSTER_ANIMATION_COUNT) {
                                            part.MonsterAnimations[propertyType] = reader.ReadString(size);
                                        } else {
                                            propertyType -= ModelListPart.MONSTER_ANIMATION_COUNT;
                                            part.AvatarAnimations[propertyType] = reader.ReadString(size);
                                        }
                                    } else {
                                        stream.Seek(size, SeekOrigin.Current);
                                    }
                                    break;
                            }
                        }

                        @object.Parts.Add(part);
                    }

                    int effectCount = reader.ReadInt16();

                    for (int j = 0; j < effectCount; j++) {
                        ModelListEffect effect = new ModelListEffect();
                        effect.EffectType = (EffectType)reader.ReadInt16();
                        effect.Effect = reader.ReadInt16();

                        byte propertyType = 0;

                        while ((propertyType = reader.ReadByte()) != 0) {
                            byte size = reader.ReadByte();

                            switch ((ModelListPropertyType)propertyType) {
                                case ModelListPropertyType.Position:
                                    effect.Position = reader.ReadVector3();
                                    break;
                                case ModelListPropertyType.Rotation:
                                    effect.Rotation = reader.ReadQuaternion(true);
                                    break;
                                case ModelListPropertyType.Scale:
                                    effect.Scale = reader.ReadVector3();
                                    break;
                                case ModelListPropertyType.Parent:
                                    effect.Parent = reader.ReadInt16();
                                    break;
                                default:
                                    stream.Seek(size, SeekOrigin.Current);
                                    break;
                            }
                        }

                        @object.Effects.Add(effect);
                    }

                    @object.BoundingBox = new BoundingBox(reader.ReadVector3(), reader.ReadVector3());
                }

                Objects.Add(@object);
            }
        }
コード例 #11
0
        public MW2PartystatePlayer(BinaryReader binaryReader)
        {
            //Наркобарон!
            playerID = binaryReader.ReadByte();
            unknown2 = binaryReader.ReadBytes(3);
            playerName = binaryReader.ReadNullTerminatedString(Encoding.UTF8); //Is the encoding right?
            unknown4 = binaryReader.ReadUInt32();
            steamID = binaryReader.ReadUInt64();
            internalIP = new IPAddress(binaryReader.ReadBytes(4));
            externalIP = new IPAddress(binaryReader.ReadBytes(4));
            internalPort = binaryReader.ReadUInt16();
            externalPort = binaryReader.ReadUInt16();
            unknown10 = binaryReader.ReadBytes(24);
            unknown11 = binaryReader.ReadUInt32();
            unknown12 = binaryReader.ReadUInt32();
            unknown13 = binaryReader.ReadUInt16();
            unknown14 = binaryReader.ReadByte();
            unknown15 = binaryReader.ReadByte();
            unknown16 = binaryReader.ReadUInt32();
            unknown17 = binaryReader.ReadUInt32();
            unknown18 = binaryReader.ReadByte();
            if (unknown18 != Convert.ToByte("0C", 16))
                unknown19 = binaryReader.ReadByte();

            Regex regex = new Regex("\\^[0-9]");

            IsHost = false;
            StrippedPlayerName = regex.Replace(playerName, "");
        }
コード例 #12
0
ファイル: Reader.cs プロジェクト: JohnnyCrazy/SharpGMad
        /// <summary>
        /// Parses the read addon stream into the instance properties.
        /// </summary>
        /// <exception cref="ReaderException">Parsing errors.</exception>
        private void Parse()
        {
            if (Buffer.Length == 0)
            {
                throw new ReaderException("Attempted to read from empty buffer.");
            }

            Buffer.Seek(0, SeekOrigin.Begin);
            BinaryReader reader = new BinaryReader(Buffer);

            // Ident
            if (String.Join(String.Empty, reader.ReadChars(Addon.Ident.Length)) != Addon.Ident)
            {
                throw new ReaderException("Header mismatch.");
            }

            FormatVersion = reader.ReadChar();
            if (FormatVersion > Addon.Version)
            {
                throw new ReaderException("Can't parse version " + Convert.ToString(FormatVersion) + " addons.");
            }

            SteamID = (ulong)reader.ReadInt64(); // SteamID (long)
            Timestamp = new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime().
                AddSeconds((double)reader.ReadInt64()); // Timestamp (long)

            // Required content (not used at the moment, just read out)
            if (FormatVersion > 1)
            {
                string content = reader.ReadNullTerminatedString();

                while (content != String.Empty)
                    content = reader.ReadNullTerminatedString();
            }

            Name = reader.ReadNullTerminatedString();
            Description = reader.ReadNullTerminatedString();
            Author = reader.ReadNullTerminatedString();
            Version = reader.ReadInt32(); // Addon version (unused)

            // File index
            int FileNumber = 1;
            int Offset = 0;

            while (reader.ReadInt32() != 0)
            {
                IndexEntry entry = new IndexEntry();
                entry.Path = reader.ReadNullTerminatedString();
                entry.Size = reader.ReadInt64(); // long long
                entry.CRC = reader.ReadUInt32(); // unsigned long
                entry.Offset = Offset;
                entry.FileNumber = (uint)FileNumber;

                Index.Add(entry);

                Offset += (int)entry.Size;
                FileNumber++;
            }

            Fileblock = (ulong)reader.BaseStream.Position;

            // Try to parse the description
            using (MemoryStream descStream = new MemoryStream(Encoding.ASCII.GetBytes(Description)))
            {
                DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(DescriptionJSON));
                try
                {
                    DescriptionJSON dJSON = (DescriptionJSON)jsonSerializer.ReadObject(descStream);

                    Description = dJSON.Description;
                    Type = dJSON.Type;
                    Tags = new List<string>(dJSON.Tags);
                }
                catch (SerializationException)
                {
                    // The description is a plaintext in the file.
                    Type = String.Empty;
                    Tags = new List<string>();
                }
            }
        }
コード例 #13
0
ファイル: ModelFile.cs プロジェクト: osROSE/UnityRose
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));

            string identifier = reader.ReadNullTerminatedString();

            int version;

            if (string.Compare(identifier, FILE_IDENTIFIER_7, false) == 0) {
                version = 7;
            } else if (string.Compare(identifier, FILE_IDENTIFIER_8, false) == 0) {
                version = 8;
            } else {
                throw new FileIdentifierMismatchException(FilePath, string.Format("{0} / {1}", FILE_IDENTIFIER_7, FILE_IDENTIFIER_8), identifier);
            }

            format = (VertexFormat)reader.ReadInt32();
            BoundingBox = new Bounds(reader.ReadVector3(), reader.ReadVector3());

            short boneCount = reader.ReadInt16();

            for (int i = 0; i < boneCount; i++) {
                BoneTable.Add(reader.ReadInt16());
            }

            short vertexCount = reader.ReadInt16();

            for (int i = 0; i < vertexCount; i++) {
                ModelVertex vertex = new ModelVertex();
                vertex.Position = reader.ReadVector3();

                Vertices.Add(vertex);
            }

            if (NormalsEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.Normal = reader.ReadVector3();
                }
            }

            if (ColoursEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    float a = reader.ReadSingle();
                    ModelVertex vertex = Vertices[i];
                    vertex.Colour = new Color(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), a);
                }
            }

            if (BonesEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.BoneWeights = reader.ReadVector4();
                    vertex.BoneIndices = reader.ReadShortVector4();
                }
            }

            if (TangentsEnabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.Tangent = reader.ReadVector3();
                }
            }

            if (TextureCoordinates1Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[0] = reader.ReadVector2();
                }
            }

            if (TextureCoordinates2Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[1] = reader.ReadVector2();
                }
            }

            if (TextureCoordinates3Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[2] = reader.ReadVector2();
                }
            }

            if (TextureCoordinates4Enabled) {
                for (int i = 0; i < vertexCount; i++) {
                    ModelVertex vertex = Vertices[i];
                    vertex.TextureCoordinates[3] = reader.ReadVector2();
                }
            }

            short indexCount = reader.ReadInt16();

            for (int i = 0; i < indexCount; i++) {
                Indices.Add(reader.ReadShortVector3());
            }

            short materialCount = reader.ReadInt16();

            for (int i = 0; i < materialCount; i++) {
                Materials.Add(reader.ReadInt16());
            }

            short stripCount = reader.ReadInt16();

            for (int i = 0; i < stripCount; i++) {
                Strips.Add(reader.ReadInt16());
            }

            if (version >= 8) {
                Pool = (PoolType)reader.ReadInt16();
            }
        }
コード例 #14
0
ファイル: Event.cs プロジェクト: slluis/heap-shot
 public USymSampleEvent(BinaryReader reader)
 {
     Address = reader.ReadSLeb128 ();
     Size = reader.ReadULeb128 ();
     Name = reader.ReadNullTerminatedString ();
 }
コード例 #15
0
ファイル: Event.cs プロジェクト: yayanyang/monodevelop
		public MethodJitEvent (BinaryReader reader)
		{
			TimeDiff = reader.ReadULeb128 ();
			Method = reader.ReadSLeb128 ();
			CodeAddress = reader.ReadSLeb128 ();
			CodeSize = reader.ReadULeb128 ();
			Name = reader.ReadNullTerminatedString ();
		}
コード例 #16
0
ファイル: Event.cs プロジェクト: slluis/heap-shot
 public UBinSampleEvent(BinaryReader reader)
 {
     TimeDiff = reader.ReadULeb128 ();
     Address = reader.ReadSLeb128 ();
     Offset = reader.ReadULeb128 ();
     Size = reader.ReadULeb128 ();
     Name = reader.ReadNullTerminatedString ();
 }
コード例 #17
0
ファイル: Event.cs プロジェクト: slluis/heap-shot
 MethodEvent(BinaryReader reader, byte exinfo)
 {
     TimeDiff = reader.ReadULeb128 ();
     Method = reader.ReadSLeb128 ();
     Type = (MethodType)exinfo;
     if (Type == MethodType.Jit) {
         CodeAddress = reader.ReadSLeb128 ();
         CodeSize = reader.ReadULeb128 ();
         Name = reader.ReadNullTerminatedString ();
     }
 }
コード例 #18
0
ファイル: Event.cs プロジェクト: slluis/heap-shot
        public readonly long Pointer; // pointer of the metadata type depending on mtype

        #endregion Fields

        #region Constructors

        MetadataEvent(BinaryReader reader)
        {
            TimeDiff = reader.ReadULeb128 ();
            MType = (MetaDataType)reader.ReadByte ();
            Pointer = reader.ReadSLeb128 ();
            switch (MType) {
            case MetaDataType.Class:
                Image = reader.ReadSLeb128 ();
                Flags = reader.ReadULeb128 ();
                Name = reader.ReadNullTerminatedString ();
                break;
            case MetaDataType.Image:
                Flags = reader.ReadULeb128 ();
                Name = reader.ReadNullTerminatedString ();
                break;
            case MetaDataType.Thread:
                Flags = reader.ReadULeb128 ();
                Name = reader.ReadNullTerminatedString ();
                break;
            }
        }
コード例 #19
0
ファイル: MotionFile.cs プロジェクト: Jiwan/Revise
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));

            string identifier = reader.ReadNullTerminatedString();

            if (string.Compare(identifier, FILE_IDENTIFIER, false) != 0) {
                throw new FileIdentifierMismatchException(FilePath, FILE_IDENTIFIER, identifier);
            }

            FramesPerSecond = reader.ReadInt32();
            int frameCount = reader.ReadInt32();
            int channelCount = reader.ReadInt32();

            for (int i = 0; i < channelCount; i++) {
                ChannelType type = (ChannelType)reader.ReadInt32();

                if (!Enum.IsDefined(typeof(ChannelType), type)) {
                    throw new InvalidMotionChannelType((int)type);
                }

                MotionChannel channel = (MotionChannel)type.GetAttributeValue<MotionChannelTypeAttribute, object>(x => x.CreateInstance());
                channel.Index = reader.ReadInt32();
                channel.FrameCount = frameCount;

                channels.Add(channel);
            }

            for (int i = 0; i < frameCount; i++) {
                for (int j = 0; j < channelCount; j++) {
                    MotionChannel channel = channels[j];
                    channel.ReadFrame(reader, i);
                }
            }
        }
コード例 #20
0
ファイル: MdlProvider.cs プロジェクト: silky/sledge
        private static void ReadBodyPart(BinaryReader br, int bodyPartIndex, ModelData data, DataStructures.Models.Model model)
        {
            var startIndex = data.Version == MDLVersionGoldsource ? 0 : br.BaseStream.Position;
            var name = "";
            var nameIndex = 0;
            if (data.Version >= MDLVersionSource2006)
            {
                nameIndex = br.ReadInt32();
                var idx = br.BaseStream.Position;
                br.BaseStream.Position = startIndex + nameIndex;
                name = br.ReadNullTerminatedString();
                br.BaseStream.Position = idx;
            }
            else if (data.Version == MDLVersionGoldsource)
            {
                name = br.ReadFixedLengthString(Encoding.UTF8, 64);
            }
            var numModels = br.ReadInt32();
            var baseIndex = br.ReadInt32();
            var modelIndex = br.ReadInt32();

            var endIndex = br.BaseStream.Position;

            br.BaseStream.Position = modelIndex + startIndex;
            for (var i = 0; i < numModels; i++)
            {
                ReadStudioModel(br, name, bodyPartIndex, i, data, model);
            }

            br.BaseStream.Position = endIndex;
        }
コード例 #21
0
ファイル: BMAP.cs プロジェクト: talberti/Breckfest
        public static BMAP Load(string path, bool bDump = false)
        {
            FileInfo fi = new FileInfo(path);
            BMAP bmap = new BMAP();

            byte[] buff = new byte[134217728];
            int size = 0;

            using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(path)))
            using (BinaryReader br = new BinaryReader(ms))
            {
                if (!IsBMAP(br)) { return null; }

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

                    using (var lzs = new MemoryStream(br.ReadBytes(length)))
                    using (var lz4 = new LZ4Decompress(lzs))
                    {
                        size += lz4.Read(buff, size, buff.Length);
                    }
                }
            }

            if (bDump)
            {
                using (BinaryWriter bw = new BinaryWriter(new FileStream(path.Replace(".bmap", ".raw"), FileMode.Create)))
                {
                    bw.Write(buff, 0, size);
                }
            }

            using (MemoryStream ms = new MemoryStream(buff, 0, size))
            using (BinaryReader br = new BinaryReader(ms))
            {
                bmap.mode = (int)br.ReadUInt32();
                bmap.path = br.ReadString((int)br.ReadUInt32());
                int dataSize = (int)br.ReadUInt32();

                switch (bmap.mode)
                {
                    case 0:
                        bmap.dds = DDS.Load(br.ReadBytes(dataSize));
                        break;

                    case 1:
                        br.ReadUInt16();
                        br.ReadUInt16();
                        br.ReadUInt32();
                        br.ReadUInt32();
                        bmap.raw = new Bitmap(br.ReadUInt16(), br.ReadUInt16(), PixelFormat.Format32bppArgb);
                        br.ReadNullTerminatedString();

                        BitmapData bmpdata = bmap.raw.LockBits(new Rectangle(0, 0, bmap.raw.Width, bmap.raw.Height), ImageLockMode.ReadWrite, bmap.raw.PixelFormat);
                        dataSize = (int)(br.BaseStream.Length - br.BaseStream.Position);
                        Marshal.Copy(br.ReadBytes(dataSize), 0, bmpdata.Scan0, dataSize);
                        break;
                }
            }

            return bmap;
        }
コード例 #22
0
        public static bool TryReadString(this MemoryVariable variable, BinaryReader reader, out string value)
        {
            value = null;

              try
              {
            var address = DereferenceValue(variable, reader, isStringType: true);

            if (address == 0)
              return false;

            reader.BaseStream.Position = address;

            value = reader.ReadNullTerminatedString(variable.MaxLength);
            return true;
              }
              catch { return false; }
        }
コード例 #23
0
ファイル: Reader.cs プロジェクト: sswires/GMAD.NET
        /// <summary>
        /// Loads a GMAD file with given path and extracts properties and files list
        /// </summary>
        /// <param name="path">Path to .gmad file</param>
        public void Parse(string path)
        {
            Reset();

            _filePath = path;

            using (var r = new BinaryReader(File.Open(path, FileMode.Open)))
            {
                var length = r.BaseStream.Length;
                _header.Ident = Encoding.ASCII.GetString(r.ReadBytes(4));

                if (_header.Ident != "GMAD")
                    throw new GmadReaderException("File is not a GMAD file. Got ident " + _header.Ident);

                _header.Version = r.ReadByte();

                if (_header.Version > FileFormat.Version)
                    throw new GmadReaderException("File is in a newer format than this version of GMAD.NET supports. Format version is " + _header.Version);

                _header.SteamId = BitConverter.ToUInt64(r.ReadBytes(8), 0);

                var timestamp = BitConverter.ToUInt64(r.ReadBytes(8), 0);
                _header.Timestamp = (new DateTime(1970, 1, 1, 0, 0, 0)).AddSeconds(Convert.ToDouble(timestamp));

                // Not used
                if (_header.Version > 1)
                {
                    var content = r.ReadNullTerminatedString();

                    while (!String.IsNullOrEmpty(content))
                    {
                        content = r.ReadNullTerminatedString();
                    }
                }

                _header.Name = r.ReadNullTerminatedString();
                _header.Description = r.ReadNullTerminatedString();
                _header.Author = r.ReadNullTerminatedString();

                _header.AddonVersion = r.ReadInt32();

                long offset = 0;
                uint fileno = 1;

                // Files block
                while (r.ReadUInt32() != 0)
                {
                    var entry = new FileFormat.FileEntry();

                    entry.StrName = r.ReadNullTerminatedString();
                    entry.Size = r.ReadInt64();
                    entry.CRC = r.ReadUInt32();
                    entry.Offset = offset;
                    entry.FileNumber = fileno;

                    offset += entry.Size;
                    fileno++;

                    _files.Add(entry);
                }

                if(_files.Count < 1)
                    throw new GmadReaderException("Got no files from GMAD package.");

                _header.FileBlock = r.BaseStream.Position;
            }
        }
コード例 #24
0
ファイル: Event.cs プロジェクト: yayanyang/monodevelop
		internal MetaDataThreadEvent (BinaryReader reader)
		{
			Flags = reader.ReadULeb128 ();
			Name = reader.ReadNullTerminatedString ();
		}
コード例 #25
0
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));

            short skeletonFileCount = reader.ReadInt16();

            for (int i = 0; i < skeletonFileCount; i++) {
                string skeletonFile = reader.ReadNullTerminatedString();

                SkeletonFiles.Add(skeletonFile);
            }

            short motionFileCount = reader.ReadInt16();

            for (int i = 0; i < motionFileCount; i++) {
                string motionFile = reader.ReadNullTerminatedString();

                MotionFiles.Add(motionFile);
            }

            short effectFileCount = reader.ReadInt16();

            for (int i = 0; i < effectFileCount; i++) {
                string effectFile = reader.ReadNullTerminatedString();

                EffectFiles.Add(effectFile);
            }

            short characterCount = reader.ReadInt16();

            for (int i = 0; i < characterCount; i++) {
                Character character = new Character();
                character.IsEnabled = reader.ReadBoolean();

                if (character.IsEnabled) {
                    character.ID = reader.ReadInt16();
                    character.Name = reader.ReadNullTerminatedString();

                    short objectCount = reader.ReadInt16();

                    for (int j = 0; j < objectCount; j++) {
                        CharacterObject @object = new CharacterObject();
                        @object.Object = reader.ReadInt16();

                        character.Objects.Add(@object);
                    }

                    short animationCount = reader.ReadInt16();

                    for (int j = 0; j < animationCount; j++) {
                        CharacterAnimation animation = new CharacterAnimation();
                        animation.Type = (AnimationType)reader.ReadInt16();
                        animation.Animation = reader.ReadInt16();

                        character.Animations.Add(animation);
                    }

                    short effectCount = reader.ReadInt16();

                    for (int j = 0; j < effectCount; j++) {
                        CharacterEffect effect = new CharacterEffect();
                        effect.Bone = reader.ReadInt16();
                        effect.Effect = reader.ReadInt16();

                        character.Effects.Add(effect);
                    }
                }

                Characters.Add(character);
            }
        }
コード例 #26
0
ファイル: Event.cs プロジェクト: yayanyang/monodevelop
		internal MetaDataClassEvent (BinaryReader reader)
		{
			Image = reader.ReadSLeb128 ();
			Flags = reader.ReadULeb128 ();
			Name = reader.ReadNullTerminatedString ();
		}
コード例 #27
0
        public MW2PacketHeader(BinaryReader binaryReader)
        {
            //Is this really something special to MW2? Can this be a generic header?

            //?????
            unknown1 = binaryReader.ReadUInt16(Endianness.Big);

            //Da_Fileserver identified this as the packet size including this header.
            //The problem is that this value may be different for packets of the same size. This is even 0x0000 in some packets.
            packetSize = binaryReader.ReadUInt16(Endianness.Big);

            //This is an unknown field. Example values are (little endian) these:
            //From fail packets: 0x4F360000, 0x4F050000, 0x071D0000, 0x07020000, 0x072F0000, 0x073A0000, 0x073D0000, 0x07440000, 0x07000000, 0x071D0000
            //From good packets: 0x045A0000, 0x4F030000, 0x4F2D0000, 0x4F040000, 0x4F000000, 0x07250000, 0x07280000, 0x07490000, 0x07070000, 0x07000000
            //As you can see, these values start with 0x04, 0x07 or 0x4F and ends with 0x0000.
            //I am not sure if these are enough to investigate this field.
            //Any resemblance might be a coincidince since the example packets are taken from the same game.
            unknown3 = binaryReader.ReadUInt32();

            //This is an unknown field. Looking at the example packets, this seems to always be 0x480B.
            //Still, I don't want to throw an exception if this is not 0x480B
            unknown4 = binaryReader.ReadUInt16();

            //This is an unknown field. Example values are (little endian) these:
            //From fail packets: 0x0847, 0x0843, 0x0804, 0x5900, 0x0800, 0x0800, 0x0800, 0x0800, 0x5900, 0x0804
            //From good packets: 0x002B, 0x5900, 0x5900, 0x5900, 0x0806, 0x5800, 0x5800, 0x5800, 0x5800, 0x5800
            //Again, there are some resemblance but I don't know if that's proof of anything.
            unknown5 = binaryReader.ReadUInt16();

            //These are the IP's and ports of source and desination.
            //Source is always the host for 0partystate packets and destination is always you.
            //Intrestingly, the port number is 18196 when read big endian and 5191 when read little endian.
            //We only watch 28960 so this is something else?
            sourceIP = new IPAddress(binaryReader.ReadBytes(4));
            destinationIP = new IPAddress(binaryReader.ReadBytes(4));
            sourcePort = binaryReader.ReadUInt16(Endianness.Big);
            destinationPort = binaryReader.ReadUInt16(Endianness.Big);

            //I have no idea what this is. Example values are (little endian) these:
            //From fail packets: 0x0103034D, 0x01030548, 0x005B0000, 0x01000900, 0x00000005, 0x00000700, 0x00000000, 0x00000200, 0x01310005, 0x005A001D
            //From good packets: 0x031F0209, 0x02005C00, 0x02000000, 0x02000200, 0x021F1600, 0x02000445, 0x02000000, 0x02600909, 0x02600062, 0x025D0700
            //All packets with this field starting with 0x00 or 0x01 failed. We migth have something here.
            unknown10 = binaryReader.ReadUInt32();

            //Looks like this is always 0x000000.
            //This maybe tells that the packet type is coming or maybe a field that was reserved for the Xbox 360 version.
            //Or, I don't know...
            unknown11 = binaryReader.ReadUInt32();

            //This is the packet time. Makes you happy when you see this in your hex editor. Something my eyes can read, at last!
            //There are different types like 0partystate, 0ping, 0pong, etc.
            //Sometimes there is something like an identifier or somthing after the packet type, seperated with a space.
            //Those might be used to identify 0ping packets.
            //Other than 0xxx packets, there are some others with wild names or probably with no names at all.
            //I won't be inspecting them until I'm done with the 0partystate type.
            packetType = binaryReader.ReadNullTerminatedString(Encoding.ASCII);
        }
コード例 #28
0
ファイル: vtMap.cs プロジェクト: DevilboxGames/ToxicRagers
        public VTMap(byte[] buff)
        {
            using (MemoryStream ms = new MemoryStream(buff))
            using (BinaryReader br = new BinaryReader(ms))
            {
                type = (VTMapType)br.ReadInt16();

                if (!IsDeadBeef(br))
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "OH F**K IT'S NOT DEADBEEF #1!\nPosition: {0:x2}", br.BaseStream.Position);
                    return;
                }

                width = br.ReadInt32();
                height = br.ReadInt32();
                pageCount = br.ReadInt32();
                tileSize = br.ReadInt32();
                tilePadding = br.ReadInt32();

                if (!IsDeadBeef(br))
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "OH F**K IT'S NOT DEADBEEF #2!\nPosition: {0:x2}", br.BaseStream.Position);
                    return;
                }

                textureCount = br.ReadInt32();

                for (int i = 0; i < textureCount; i++)
                {
                    VTMapEntry entry = new VTMapEntry();
                    entry.Row = br.ReadInt32();
                    entry.Column = br.ReadInt32();
                    entry.Width = br.ReadInt32();
                    entry.Height = br.ReadInt32();
                    entry.FileName = br.ReadNullTerminatedString();
                    br.ReadByte();

                    entries.Add(entry);
                }

                if (!IsDeadBeef(br))
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "OH F**K IT'S NOT DEADBEEF #3!\nPosition: {0:x2}", br.BaseStream.Position);
                    return;
                }

                numberOfTiles = br.ReadInt32();
                int j = 0;
                for (int i = 0; i < numberOfTiles; i++)
                {
                    VTMapTile tile = new VTMapTile();
                    tile.Column = br.ReadInt32();
                    tile.Row = br.ReadInt32();
                    tile.Page = br.ReadInt32();

                    tile.Hash = br.ReadUInt32();
                    tile.TileName = string.Format("{0:x8}", tile.Hash);
                    tile.ZadTileName = string.Format("{0}/{1}_{2}.tdx", tile.TileName.Substring(0, 2), tile.TileName, type.ToString().Substring(0, 1));

                    //Logger.LogToFile("\tTile {0}\n\t\t FileName: {1}\n\t\tUnknown1: {2}\n\t\tUnknown2: {3}\n\t\tUnknown3: {4}", j, BitConverter.ToString( tile.TileName), tile.Unknown1, tile.Unknown2, tile.Unknown3);
                    j++;
                    if (!TilesByName.ContainsKey(tile.TileName))
                    {
                        VTMapTileTDX tileTDX = new VTMapTileTDX();
                        tileTDX.TileName = tile.TileName;
                        tileTDX.Coords.Add(tile);
                        TilesByName.Add(tile.TileName, tileTDX);
                    }
                    else
                    {
                        //Logger.LogToFile("Tile #{0} \"{1}\" already in TilesByName", i, tile.TileNameString);
                        TilesByName[tile.TileName].Coords.Add(tile);
                    }
                    if (tile.Page >= TilesPages.Count)
                    {
                        for (int x = TilesPages.Count; x <= tile.Page; x++)
                        {
                            TilesPages.Add(new VTMapPage() { PageNumber = tile.Page });
                        }
                    }
                    TilesPages[tile.Page].AddTile(tile);
                }
                if (!IsDeadBeef(br))
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "OH F**K IT'S NOT DEADBEEF #4!\nPosition: {0}", br.BaseStream.Position);
                    return;
                }
                int anotherTextureCount = br.ReadInt32();
                List<int> unknownValues = new List<int>();
                for (int i = 0; i < anotherTextureCount; i++)
                {
                    string fileName = br.ReadNullTerminatedString();

                    if (entries[i].FileName == fileName)
                    {
                        entries[i].TimeStamp = br.ReadInt32();
                        entries[i].Unknown2 = br.ReadInt32();
                        if (!unknownValues.Contains(entries[i].TimeStamp)) unknownValues.Add(entries[i].TimeStamp);
                    }
                    else
                    {
                        for (int k = 0; k < entries.Count; k++)
                        {
                            if (entries[k].FileName == fileName)
                            {
                                entries[k].TimeStamp = br.ReadInt32();
                                entries[k].Unknown2 = br.ReadInt32();
                                if (!unknownValues.Contains(entries[k].TimeStamp)) unknownValues.Add(entries[k].TimeStamp);
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #29
0
ファイル: ModelTextures.cs プロジェクト: Nihlus/libwarcraft
 public void LoadBinaryData(byte[] inData)
 {
     using (MemoryStream ms = new MemoryStream(inData))
     {
         using (BinaryReader br = new BinaryReader(ms))
         {
             while (ms.Position < ms.Length)
             {
                 if (ms.Position % 4 == 0)
                 {
                     this.Textures.Add(ms.Position, br.ReadNullTerminatedString());
                 }
                 else
                 {
                     ms.Position += (4 - (ms.Position % 4));
                 }
             }
         }
     }
 }
コード例 #30
0
ファイル: LevelOfDetailFile.cs プロジェクト: Jiwan/Revise
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR"));

            Name = reader.ReadNullTerminatedString();

            for (int h = 0; h < DEFAULT_HEIGHT; h++) {
                for (int w = 0; w < DEFAULT_WIDTH; w++) {
                    values[h, w] = reader.ReadInt32();
                }
            }
        }