示例#1
0
        /// <summary>
        /// Create a parameter object from a file and address
        /// </summary>
        /// <param name="file">The file contents</param>
        /// <param name="address">The address at which the parameter is located</param>
        /// <returns>Any of the parameter types</returns>
        public static GCParameter Read(byte[] file, int address)
        {
            GCParameter   result    = null;
            ParameterType paramType = (ParameterType)BitConverter.ToUInt32(file, address);

            switch (paramType)
            {
            case ParameterType.VtxAttrFmt:
                result = new VtxAttrFmtParameter(GCVertexAttribute.Null);
                break;

            case ParameterType.IndexAttributeFlags:
                result = new IndexAttributeParameter();
                break;

            case ParameterType.Lighting:
                result = new LightingParameter();
                break;

            case ParameterType.BlendAlpha:
                result = new BlendAlphaParameter();
                break;

            case ParameterType.AmbientColor:
                result = new AmbientColorParameter();
                break;

            case ParameterType.Texture:
                result = new TextureParameter();
                break;

            case ParameterType.Unknown_9:
                result = new Unknown9Parameter();
                break;

            case ParameterType.TexCoordGen:
                result = new TexCoordGenParameter();
                break;
            }

            result.data = ByteConverter.ToUInt32(file, address + 4);

            return(result);
        }
示例#2
0
        /// <summary>
        /// Read a mesh from a file
        /// </summary>
        /// <param name="file">The files contents</param>
        /// <param name="address">The address at which the mesh is located</param>
        /// <param name="imageBase">The imagebase (used for when reading from an exe)</param>
        /// <param name="index">Indexattribute parameter of the previous mesh</param>
        public GCMesh(byte[] file, int address, uint imageBase, GCIndexAttributeFlags indexFlags)
        {
            // getting the addresses and sizes
            int parameters_offset = (int)(ByteConverter.ToInt32(file, address) - imageBase);
            int parameters_count  = ByteConverter.ToInt32(file, address + 4);

            int primitives_offset = (int)(ByteConverter.ToInt32(file, address + 8) - imageBase);
            int primitives_size   = ByteConverter.ToInt32(file, address + 12);

            // reading the parameters
            parameters = new List <GCParameter>();
            for (int i = 0; i < parameters_count; i++)
            {
                parameters.Add(GCParameter.Read(file, parameters_offset));
                parameters_offset += 8;
            }

            // getting the index attribute parameter
            GCIndexAttributeFlags?flags = IndexFlags;

            if (flags.HasValue)
            {
                indexFlags = flags.Value;
            }

            // reading the primitives
            primitives = new List <GCPrimitive>();
            int end_pos = primitives_offset + primitives_size;

            while (primitives_offset < end_pos)
            {
                // if the primitive isnt valid
                if (file[primitives_offset] == 0)
                {
                    break;
                }
                primitives.Add(new GCPrimitive(file, primitives_offset, indexFlags, out primitives_offset));
            }
        }