Esempio n. 1
0
        public static VisualMaterial Read(Reader reader, Pointer offset)
        {
            MapLoader      l = MapLoader.Loader;
            VisualMaterial m = new VisualMaterial(offset);

            // Material struct = 0x188
            //l.print("Material @ " + offset);
            m.flags = reader.ReadUInt32(); // After this: 0x4
            if (Settings.s.game != Settings.Game.R2Revolution && Settings.s.game != Settings.Game.LargoWinch)
            {
                if (Settings.s.platform == Settings.Platform.DC)
                {
                    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());          // 0x44
            }
            else if (Settings.s.game == Settings.Game.R2Revolution)
            {
                // Fill in light info for Revolution
                m.ambientCoef = new Vector4(0, 0, 0, 1f);
                m.diffuseCoef = new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                //m.diffuseCoef = new Vector4(1, 1, 1, 1);
                reader.ReadInt32();                 // current refresh number for scrolling/animated textures
                m.off_animTextures_first   = Pointer.Read(reader);
                m.off_animTextures_current = Pointer.Read(reader);
                reader.ReadInt32();
                m.num_animTextures = reader.ReadUInt16();
                reader.ReadUInt16();                 // 0x70
            }
            else if (Settings.s.game == Settings.Game.LargoWinch)
            {
                m.ambientCoef = new Vector4(0, 0, 0, 1f);
                m.color       = new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());           // 0x44
                m.diffuseCoef = new Vector4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                //m.ambientCoef = m.diffuseCoef;
                reader.ReadInt32();                 // current refresh number for scrolling/animated textures
                m.off_animTextures_first   = Pointer.Read(reader);
                m.off_animTextures_current = Pointer.Read(reader);
                reader.ReadInt32();
                m.num_animTextures = reader.ReadUInt16();
                reader.ReadUInt16();
            }
            if (Settings.s.game == Settings.Game.LargoWinch)
            {
                m.num_textures = 1;
                VisualMaterialTexture t = new VisualMaterialTexture();
                t.offset      = Pointer.Current(reader);
                t.off_texture = Pointer.Read(reader);                 // 0x4c
                t.texture     = TextureInfo.FromOffset(t.off_texture);
                t.textureOp   = reader.ReadByte();
                t.shadingMode = reader.ReadByte();
                t.uvFunction  = reader.ReadByte();
                t.scrollByte  = reader.ReadByte();
                t.scrollX     = reader.ReadSingle();
                t.scrollY     = reader.ReadSingle();
                reader.ReadSingle();

                new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                m.textures.Add(t);
            }
            else if (Settings.s.game == Settings.Game.R2Revolution)
            {
                m.num_textures = 1;
                VisualMaterialTexture t = new VisualMaterialTexture();
                t.offset         = Pointer.Current(reader);
                t.off_texture    = Pointer.Read(reader);              // 0x4c
                t.texture        = TextureInfo.FromOffset(t.off_texture);
                t.scrollMode     = reader.ReadUInt32();
                t.scrollX        = reader.ReadSingle();
                t.scrollY        = reader.ReadSingle();
                t.currentScrollX = reader.ReadSingle();
                t.currentScrollY = reader.ReadSingle();
                m.textures.Add(t);

                /*reader.ReadInt32(); // current refresh number for scrolling/animated textures, 0x64
                 * m.off_animTextures_first = Pointer.Read(reader); // 0x68
                 * m.off_animTextures_current = Pointer.Read(reader); // 0x6c
                 * m.num_animTextures = reader.ReadUInt16();
                 * reader.ReadUInt16(); // 0x70
                 * reader.ReadUInt32();
                 * reader.ReadByte();
                 * reader.ReadByte();
                 * m.properties = reader.ReadByte();
                 * reader.ReadByte();
                 * reader.ReadUInt32();
                 * reader.ReadUInt32();*/
            }
            else if (Settings.s.engineVersion < Settings.EngineVersion.R3)
            {
                m.num_textures = 1;
                reader.ReadUInt32(); // 0x48
                VisualMaterialTexture t = new VisualMaterialTexture();
                t.offset      = Pointer.Current(reader);
                t.off_texture = Pointer.Read(reader); // 0x4c
                t.texture     = TextureInfo.FromOffset(t.off_texture);
                if (Settings.s.game == Settings.Game.TT)
                {
                    /*m.off_animTextures_first = Pointer.Read(reader); // 0x68
                     * m.off_animTextures_current = Pointer.Read(reader); // 0x6c
                     * m.num_animTextures = reader.ReadUInt16();*/
                    Pointer.Read(reader); // detail texture
                    t.currentScrollX = reader.ReadSingle();
                    t.currentScrollY = reader.ReadSingle();
                    t.scrollX        = reader.ReadSingle(); // 0x58
                    t.scrollY        = reader.ReadSingle(); // 0x5c
                    t.scrollMode     = reader.ReadUInt32(); //0x60
                    m.textures.Add(t);

                    reader.ReadInt32(); // current refresh number for scrolling/animated textures, 0x64
                }
                else
                {
                    if (Settings.s.platform == Settings.Platform.DC)
                    {
                        // For some reason there's a huge gap here
                        reader.ReadBytes(0xD0);
                    }
                    t.currentScrollX = reader.ReadSingle();
                    t.currentScrollY = reader.ReadSingle();
                    t.scrollX        = reader.ReadSingle();            // 0x58
                    t.scrollY        = reader.ReadSingle();            // 0x5c
                    t.scrollMode     = reader.ReadUInt32();            //0x60
                    m.textures.Add(t);
                    reader.ReadInt32();                                // current refresh number for scrolling/animated textures, 0x64
                    m.off_animTextures_first   = Pointer.Read(reader); // 0x68
                    m.off_animTextures_current = Pointer.Read(reader); // 0x6c
                    m.num_animTextures         = reader.ReadUInt16();
                    reader.ReadUInt16();                               // 0x70
                }
                reader.ReadUInt32();                                   // 0x74
                m.properties = reader.ReadByte();                      // whole byte for texture scroll lock in R2, no bitmasks
                reader.ReadByte();
                reader.ReadByte();                                     // padding, not in DC
                reader.ReadByte();                                     // padding, not in DC
            }
            else                                                       // EngineVersion >= R3
            {
                reader.ReadUInt32();                                   // current refresh number for scrolling/animated textures, 0x48
                if (Settings.s.game == Settings.Game.Dinosaur)
                {
                    reader.ReadBytes(0x1C);
                }
                m.off_animTextures_first   = Pointer.Read(reader);
                m.off_animTextures_current = Pointer.Read(reader);
                m.num_animTextures         = reader.ReadUInt16();
                reader.ReadUInt16();
                reader.ReadUInt32();
                reader.ReadByte();
                reader.ReadByte();
                m.properties = reader.ReadByte();
                reader.ReadByte();
                reader.ReadUInt32();
                reader.ReadUInt32();
                /* m.num_textures = */ reader.ReadUInt32();
                for (int i = 0; i < 4; i++)
                {
                    VisualMaterialTexture t = new VisualMaterialTexture();
                    t.offset      = Pointer.Current(reader);
                    t.off_texture = Pointer.Read(reader);
                    if (t.off_texture == null)
                    {
                        break;
                    }

                    /*if (Settings.s.game == Settings.Game.Dinosaur) {
                     *      Pointer.DoAt(ref reader, t.off_texture, () => {
                     *              Pointer off_tex = Pointer.Read(reader);
                     *              t.texture = TextureInfo.FromOffset(off_tex);
                     *      });
                     * } else {*/
                    t.texture = TextureInfo.FromOffset(t.off_texture);
                    //}

                    t.textureOp   = reader.ReadByte();
                    t.shadingMode = reader.ReadByte();
                    t.uvFunction  = reader.ReadByte();
                    t.scrollByte  = reader.ReadByte();

                    if (Settings.s.game == Settings.Game.Dinosaur)
                    {
                        t.properties = reader.ReadInt32();
                        new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        t.currentScrollX = reader.ReadSingle();
                        t.currentScrollY = reader.ReadSingle();
                        t.scrollX        = reader.ReadSingle();
                        t.scrollY        = reader.ReadSingle();
                        new Vector2(reader.ReadSingle(), reader.ReadSingle());
                        new Vector2(reader.ReadSingle(), reader.ReadSingle());
                        new Vector2(reader.ReadSingle(), reader.ReadSingle());
                        new Vector2(reader.ReadSingle(), reader.ReadSingle());
                        new Vector2(reader.ReadSingle(), reader.ReadSingle());
                    }
                    else
                    {
                        t.properties = reader.ReadInt32();
                        reader.ReadInt32();
                        reader.ReadInt32();
                        t.scrollX         = reader.ReadSingle();
                        t.scrollY         = reader.ReadSingle();
                        t.rotateSpeed     = reader.ReadSingle();
                        t.rotateDirection = reader.ReadSingle();
                        reader.ReadInt32();
                        reader.ReadInt32();
                        t.currentScrollX = reader.ReadSingle();
                        t.currentScrollY = reader.ReadSingle();
                        reader.ReadInt32();
                        reader.ReadInt32();
                        reader.ReadInt32();
                        reader.ReadInt32();
                        t.blendIndex = reader.ReadUInt32();
                    }

                    m.textures.Add(t);
                }
                m.num_textures = (uint)m.textures.Count;
            }
            if (m.num_animTextures > 0 && m.off_animTextures_first != null)
            {
                Pointer off_currentAnimTexture = m.off_animTextures_first;
                Pointer.Goto(ref reader, m.off_animTextures_first);
                for (int i = 0; i < m.num_animTextures; i++)
                {
                    if (off_currentAnimTexture == m.off_animTextures_current)
                    {
                        m.currentAnimTexture = i;
                    }
                    Pointer off_animTexture = Pointer.Read(reader);
                    float   time            = reader.ReadSingle();
                    m.animTextures.Add(new AnimatedTexture(off_animTexture, time));
                    Pointer off_nextAnimTexture = Pointer.Read(reader);
                    if (off_nextAnimTexture != null)
                    {
                        off_currentAnimTexture = off_nextAnimTexture;
                        Pointer.Goto(ref reader, off_nextAnimTexture);
                    }
                }
            }

            return(m);
        }
Esempio n. 2
0
 public AnimatedTexture(Pointer off_texture, float time)
 {
     this.off_texture = off_texture;
     this.time        = time;
     texture          = TextureInfo.FromOffset(off_texture);
 }