Exemple #1
0
        public GameModel(string meshPath, string texturePath = "null")
        {
            using (BinaryReader reader = new BinaryReader((Stream)File.OpenRead(meshPath)))
            {
                this.Header = Encoding.ASCII.GetString(reader.ReadBytes(16));
                C3PartType type = C3PartType.START;
                while (type != C3PartType.EXIT && reader.BaseStream.Position + 4L <= reader.BaseStream.Length)
                {
                    type = (C3PartType)reader.ReadInt32();
                    Console.WriteLine("Loading: " + (object)type);
                    switch (type)
                    {
                    case C3PartType.PHY4:
                    case C3PartType.PHY:
                    case C3PartType.PHY3:
                        this.PhysicalObjects.Add(Physics.ReadPhysics(reader, type));
                        break;

                    case C3PartType.MOTI:
                        this.Motions.Add(Motion.ReadMotion(reader));
                        break;

                    case C3PartType.SHAP:
                        this.Shapes.Add(Shape.ReadShape(reader));
                        break;

                    default:
                        reader.BaseStream.Position -= 4L;
                        int num = (int)MessageBox.Show("Warning: This file was not completely loaded. Please avoid exporting this model or it may become corrupted.");
                        type = C3PartType.EXIT;
                        break;
                    }
                }
                reader.Close();
            }
            meshPath = meshPath.Replace('\\', '/');
            int    num1 = meshPath.LastIndexOf('/');
            string s    = meshPath.Substring(num1 + 1, meshPath.Length - num1 - 4);

            int.TryParse(s, out this.ID);
            if (File.Exists(meshPath.Substring(0, meshPath.Length - 3) + ".dds"))
            {
                DDSLib.DDSFromFile(meshPath.Substring(0, meshPath.Length - 3) + ".dds", Settings.Graphics, false, out this.Texture);
            }
            else if (File.Exists(Settings.Conquer_Path + "c3/texture/" + s + ".dds"))
            {
                DDSLib.DDSFromFile(Settings.Conquer_Path + "c3/texture/" + s + ".dds", Settings.Graphics, false, out this.Texture);
            }
            else if (File.Exists(Settings.Conquer_Path + "c3/texture/" + (object)(this.ID / 10 * 10) + ".dds"))
            {
                DDSLib.DDSFromFile(Settings.Conquer_Path + "c3/texture/" + (object)(this.ID / 10 * 10) + ".dds", Settings.Graphics, false, out this.Texture);
            }
            this.Name = this.ID.ToString();
            foreach (Physics physicalObject in this.PhysicalObjects)
            {
                Settings.GUI.AddPhysicalObject(this.Name, physicalObject);
            }
            foreach (Shape shape in this.Shapes)
            {
                Settings.GUI.AddShape(this.Name, shape);
            }
        }
Exemple #2
0
        public static Physics ReadPhysics(BinaryReader reader, C3PartType type)
        {
            Physics physics = new Physics();

            physics.Type    = type;
            physics.Unknown = reader.ReadInt32();
            physics.Name    = Encoding.ASCII.GetString(reader.ReadBytes(reader.ReadInt32()));
            switch (physics.Type)
            {
            case C3PartType.PHY:
                physics.BlendCount     = reader.ReadInt32();
                physics.NormalVertexes = new Vertex[reader.ReadInt32()];
                physics.AlphaVertexes  = new Vertex[reader.ReadInt32()];
                for (int index = 0; index < physics.NormalVertexes.Length; ++index)
                {
                    physics.NormalVertexes[index] = Vertex.ReadVertex2(reader);
                }
                for (int index = 0; index < physics.AlphaVertexes.Length; ++index)
                {
                    physics.AlphaVertexes[index] = Vertex.ReadVertex2(reader);
                }
                physics.NormalIndexes = new short[reader.ReadInt32() * 3];
                physics.AlphaIndexes  = new short[reader.ReadInt32() * 3];
                for (int index = 0; index < physics.NormalIndexes.Length; ++index)
                {
                    physics.NormalIndexes[index] = reader.ReadInt16();
                }
                for (int index = 0; index < physics.AlphaIndexes.Length; ++index)
                {
                    physics.AlphaIndexes[index] = reader.ReadInt16();
                }
                physics.TextureName     = Encoding.ASCII.GetString(reader.ReadBytes(reader.ReadInt32()));
                physics.Min_Bound       = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                physics.Max_Bound       = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                physics.World           = new Matrix(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                physics.TextureRowCount = reader.ReadInt32();
                physics.Alphas          = new Frame[reader.ReadInt32()];
                for (int index = 0; index < ((IEnumerable <Frame>)physics.Alphas).Count <Frame>(); ++index)
                {
                    physics.Alphas[index] = Frame.ReadFrame(reader);
                }
                physics.Draws = new Frame[reader.ReadInt32()];
                for (int index = 0; index < ((IEnumerable <Frame>)physics.Draws).Count <Frame>(); ++index)
                {
                    physics.Draws[index] = Frame.ReadFrame(reader);
                }
                physics.Teks = new Frame[reader.ReadInt32()];
                for (int index = 0; index < ((IEnumerable <Frame>)physics.Teks).Count <Frame>(); ++index)
                {
                    physics.Teks[index] = Frame.ReadFrame(reader);
                }
                if (reader.BaseStream.Position + 11L < reader.BaseStream.Length)
                {
                    physics.Step = reader.ReadInt32();
                    if (physics.Step == 1346720851)
                    {
                        physics.UV_Step = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                    }
                }
                if (reader.BaseStream.Position + 4L < reader.BaseStream.Length)
                {
                    int num = reader.ReadInt32();
                    physics.WriteSID = num == 1145656114;
                    if (!physics.WriteSID)
                    {
                        reader.BaseStream.Position -= 4L;
                    }
                    break;
                }
                break;

            case C3PartType.PHY3:
                throw new NotImplementedException("PHY3 not yet implemented");

            case C3PartType.PHY4:
                physics.BlendCount     = reader.ReadInt32();
                physics.NormalVertexes = new Vertex[reader.ReadInt32()];
                physics.AlphaVertexes  = new Vertex[reader.ReadInt32()];
                for (int index = 0; index < physics.NormalVertexes.Length; ++index)
                {
                    physics.NormalVertexes[index] = Vertex.ReadVertex3(reader);
                }
                for (int index = 0; index < physics.AlphaVertexes.Length; ++index)
                {
                    physics.AlphaVertexes[index] = Vertex.ReadVertex3(reader);
                }
                physics.NormalIndexes = new short[reader.ReadInt32() * 3];
                physics.AlphaIndexes  = new short[reader.ReadInt32() * 3];
                for (int index = 0; index < physics.NormalIndexes.Length; ++index)
                {
                    physics.NormalIndexes[index] = reader.ReadInt16();
                }
                for (int index = 0; index < physics.AlphaIndexes.Length; ++index)
                {
                    physics.AlphaIndexes[index] = reader.ReadInt16();
                }
                physics.TextureName     = Encoding.ASCII.GetString(reader.ReadBytes(reader.ReadInt32()));
                physics.Min_Bound       = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                physics.Max_Bound       = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                physics.World           = new Matrix(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                physics.TextureRowCount = reader.ReadInt32();
                physics.Alphas          = new Frame[reader.ReadInt32()];
                for (int index = 0; index < ((IEnumerable <Frame>)physics.Alphas).Count <Frame>(); ++index)
                {
                    physics.Alphas[index] = Frame.ReadFrame(reader);
                }
                physics.Draws = new Frame[reader.ReadInt32()];
                for (int index = 0; index < ((IEnumerable <Frame>)physics.Draws).Count <Frame>(); ++index)
                {
                    physics.Draws[index] = Frame.ReadFrame(reader);
                }
                physics.Teks = new Frame[reader.ReadInt32()];
                for (int index = 0; index < ((IEnumerable <Frame>)physics.Teks).Count <Frame>(); ++index)
                {
                    physics.Teks[index] = Frame.ReadFrame(reader);
                }
                if (reader.BaseStream.Position + 11L < reader.BaseStream.Length)
                {
                    physics.Step = reader.ReadInt32();
                    if (physics.Step == 1346720851)
                    {
                        physics.UV_Step = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                    }
                }
                if (reader.BaseStream.Position + 4L < reader.BaseStream.Length)
                {
                    int num = reader.ReadInt32();
                    physics.WriteSID = num == 1145656114;
                    if (!physics.WriteSID)
                    {
                        reader.BaseStream.Position -= 4L;
                    }
                    break;
                }
                break;
            }
            if (reader.ReadInt32() == 1230262093)
            {
                if (reader.BaseStream.Position + 16L < reader.BaseStream.Length)
                {
                    physics.Motion = Motion.ReadMotion(reader);
                }
            }
            else
            {
                reader.BaseStream.Position -= 4L;
            }
            return(physics);
        }