Ejemplo n.º 1
0
        public void ReadMatFile(string name)
        {
            materials = new Dictionary <ulong, IMaterial>();
            this.name = name;

            using (BinaryReader reader = new BinaryReader(File.Open(name, FileMode.Open)))
            {
                string header = new string(reader.ReadChars(4));
                version = (VersionsEnumerator)reader.ReadInt32();
                int numMats = reader.ReadInt32();
                unk2 = reader.ReadInt32();

                for (int i = 0; i != numMats; i++)
                {
                    IMaterial mat = MaterialFactory.ReadMaterialFromFile(reader, version);
                    materials.Add(mat.MaterialName.Hash, mat);
                }
            }
        }
Ejemplo n.º 2
0
        public void WriteMatFile(string name)
        {
            this.name = name;

            // Validate Materials (TODO: Maybe move to validate function?)
            for (int i = 0; i != materials.Count; i++)
            {
                IMaterial Material = materials.ElementAt(i).Value;
                if (Version == VersionsEnumerator.V_57 || Version == VersionsEnumerator.V_58)
                {
                    if (Material.GetMTLVersion() == VersionsEnumerator.V_63)
                    {
                        MessageBox.Show("Detected v63 (M1DE/M3 Material). Cannot save this file. Support will be added soon.", "Toolkit");
                        return;
                    }
                }
            }

            using (BinaryWriter writer = new BinaryWriter(File.Open(name, FileMode.Create)))
            {
                writer.Write("MTLB".ToCharArray());
                writer.Write((int)version);
                writer.Write(materials.Count);
                writer.Write(unk2);

                // Write Materials
                for (int i = 0; i != materials.Count; i++)
                {
                    // Convert material if required.
                    IMaterial Material = materials.ElementAt(i).Value;
                    if (Material.GetMTLVersion() != Version)
                    {
                        Material = MaterialFactory.ConvertMaterial(Version, Material);
                    }

                    Material.WriteToFile(writer, version);
                }
            }
        }