Exemplo n.º 1
0
        public static GameMaterial Read(Reader reader, Pointer offset)
        {
            MapLoader    l  = MapLoader.Loader;
            GameMaterial gm = new GameMaterial(offset);

            if (Settings.s.game == Settings.Game.R2Revolution)
            {
                gm.soundMaterial   = reader.ReadUInt32();
                gm.collideMaterial = CollideMaterial.Read(reader, Pointer.Current(reader));
                // Maybe the first uint16 of collidematerial in Revolution is actually sound material, but eh
            }
            else
            {
                if (Settings.s.engineVersion < Settings.EngineVersion.R3)
                {
                    gm.off_visualMaterial    = Pointer.Read(reader);
                    gm.off_mechanicsMaterial = Pointer.Read(reader);
                }
                gm.soundMaterial       = reader.ReadUInt32();
                gm.off_collideMaterial = Pointer.Read(reader, allowMinusOne: true);

                if (gm.off_visualMaterial != null)
                {
                    gm.visualMaterial = VisualMaterial.FromOffsetOrRead(gm.off_visualMaterial, reader);
                }
                if (gm.off_collideMaterial != null)
                {
                    gm.collideMaterial = CollideMaterial.FromOffsetOrRead(gm.off_collideMaterial, reader);
                }
            }
            return(gm);
        }
Exemplo n.º 2
0
        public static VisualMaterial FromOffset(Pointer offset, bool createIfNull = false)
        {
            MapLoader l = MapLoader.Loader;

            for (int i = 0; i < l.materials.Length; i++)
            {
                if (offset == l.materials[i].offset)
                {
                    return(l.materials[i]);
                }
            }
            if (createIfNull)
            {
                Array.Resize(ref l.materials, l.materials.Length + 1);
                l.materials[l.materials.Length - 1] = VisualMaterial.Read(offset.file.reader, offset);
                return(l.materials[l.materials.Length - 1]);
            }
            l.print("Material was null!");
            return(null);
        }
Exemplo n.º 3
0
        public static VisualMaterial Read(EndianBinaryReader reader, Pointer offset)
        {
            MapLoader      l = MapLoader.Loader;
            VisualMaterial m = new VisualMaterial(offset);

            // Material struct = 0x188
            m.flags        = reader.ReadUInt32();
            m.ambientCoef  = new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            m.diffuseCoef  = new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            m.specularCoef = new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            m.color        = new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            reader.ReadUInt32(); // some specular parameter
            if (l.mode == MapLoader.Mode.Rayman2PC)
            {
                Pointer off_texture = Pointer.Read(reader);
                //Pointer off_texture2 = Pointer.Read(reader);
                int type_texture = reader.ReadInt32();
                m.off_textures.Add(off_texture);
                m.textureTypes.Add(type_texture);
            }
            else
            {
                Pointer off_animTextures = Pointer.Read(reader);
                reader.ReadUInt32(); // a repeat of last offset?
                ushort num_animTextures = reader.ReadUInt16();
                reader.ReadUInt16();
                reader.ReadUInt32();
                reader.ReadByte();
                reader.ReadByte();
                m.properties = reader.ReadByte();
                reader.ReadByte();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                Pointer off_texture1 = Pointer.Read(reader);
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                int type_texture1 = reader.ReadInt32();
                reader.ReadBytes(0x3C);
                Pointer off_texture2 = Pointer.Read(reader);
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                int  type_texture2 = reader.ReadInt32();
                uint num_textures  = 0;
                if (off_texture1 != null)
                {
                    m.off_textures.Add(off_texture1);
                    m.textureTypes.Add(type_texture1);
                }
                if (off_texture2 != null)
                {
                    m.off_textures.Add(off_texture2);
                    m.textureTypes.Add(type_texture2);
                }

                /*if (off_texture2 != null) num_textures++;
                 * R3Pointer[] off_textures = new R3Pointer[num_textures];
                 * int[] textureTypes = new int[num_textures];
                 * if (off_texture1 != null) {
                 *  off_textures[0] = off_texture1;
                 *  textureTypes[0] = type_texture1;
                 * }
                 * if (off_texture2 != null) {
                 *  off_textures[num_textures - 1] = off_texture2;
                 *  textureTypes[num_textures - 1] = type_texture2;
                 * }*/

                /*uint num_textures = Math.Min(reader.ReadUInt32(), 2);
                 * R3Pointer[] off_textures = new R3Pointer[num_textures];
                 * int[] textureTypes = new int[num_textures];
                 * for (uint i = 0; i < num_textures; i++) {
                 *  off_textures[i] = R3Pointer.Read(reader);
                 *  reader.ReadByte();
                 *  reader.ReadByte();
                 *  reader.ReadByte();
                 *  reader.ReadByte();
                 *  textureTypes[i] = reader.ReadInt32();
                 *  if (num_textures > i + 1) reader.ReadBytes(0x3C);
                 * }*/
                if (num_animTextures > 0 && off_animTextures != null)
                {
                    Pointer.Goto(ref reader, off_animTextures);
                    for (int i = 0; i < num_animTextures; i++)
                    {
                        Pointer off_animTexture = Pointer.Read(reader);
                        m.off_animTextures.Add(off_animTexture);
                        reader.ReadUInt32();
                        Pointer off_nextAnimTexture = Pointer.Read(reader);
                        if (off_nextAnimTexture != null)
                        {
                            Pointer.Goto(ref reader, off_nextAnimTexture);
                        }
                    }
                }
            }

            return(m);
        }